<?php
session_start();
header('Content-Type: application/json');

require_once realpath(dirname(__DIR__, 3) . '/services/Model.php');
$obj = new Model();

$acc_id = isset($_POST['acc_id']) ? (int)$_POST['acc_id'] : 0;
$acc_amount = isset($_POST['acc_amount']) ? trim($_POST['acc_amount']) : '';
$acc_description = isset($_POST['acc_description']) ? trim($_POST['acc_description']) : '';

if($acc_id <= 0){
  echo json_encode(['status'=>'error','message'=>'Invalid payment id']);
  exit;
}
if($acc_amount === '' || !is_numeric($acc_amount)){
  echo json_encode(['status'=>'error','message'=>'Amount must be numeric']);
  exit;
}

// update
try{
  $obj->Update_data('re_tbl_account',
    [
      'acc_amount' => $acc_amount,
      'acc_description' => $acc_description
    ],
    "acc_id='$acc_id'"
  );

  echo json_encode(['status'=>'success','message'=>'Payment updated successfully']);
}catch(Exception $e){
  echo json_encode(['status'=>'error','message'=>$e->getMessage()]);
}
