<?php
include('../include/auth.php');
include('../include/lskfjwfe.php');
header('Content-Type: application/json');

$id = (int)$_POST['id'];
$partner_id = (int)$_POST['partner_id'];
$location_id = (int)$_POST['location_id'];
$fee_type = mysqli_real_escape_string($db2, $_POST['fee_type']);
$fee_amount = (float)$_POST['fee_amount'];

$query = $db2->query("
  UPDATE api_pickup_dropoff_fees
  SET partner_id = $partner_id,
      location_id = $location_id,
      fee_type = '$fee_type',
      fee_amount = $fee_amount
  WHERE id = $id
");

if ($query) {
  $details = mysqli_real_escape_string($db2, json_encode($_POST));
  $db2->query("INSERT INTO action_logs (action, details, user) VALUES ('update_pickup_dropoff_fee', '$details', '$user')");
  echo json_encode(['success' => true]);
} else {
  echo json_encode(['success' => false, 'error' => mysqli_error($db2)]);
}
