<?php
$customer_id = intval($_POST['customer_id']);
$amount = floatval($_POST['amount']);
$note = $_POST['note'];

if($customer_id<1){$error=fl(); setMessage(36,'customer');}
elseif($amount<=0){$error=fl(); setMessage(63,'amount');}
else{
    $c=$smt->customerInfoByID($customer_id);
    if(empty($c)){$error=fl(); setMessage(63,'custoemr');}
    elseif($userData['base_id']>0&&$c['base_id']!=$userData['base_id']){$error=fl(); setMessage(63,'customer');}
    else{
        $customer_head=$acc->getCustomerHead($c);
        if($customer_head==false){$error=fl();setMessage(66);}
        $cashHead=$acc->get_user_head($userData,$jArray);
        if($cashHead==false){$error=fl();setMessage(66);}
        if(!isset($error)){
            $db->transactionStart();
            $voucher_id=$acc->voucher_create(V_T_RECEIVE_FROM_CUSTOMER,$amount,$cashHead,$customer_head,TIME,$note,$customer_id);
            if($voucher_id==false){$error=fl(); setMessage(66);}
            $ac=false;
            if(!isset($error)){
                $data=[
                    'customer_id'   => $customer_id,
                    'voucher_id'    => $voucher_id,
                    'mpo_id'        => USER_ID,
                    'amount'        => $amount,
                    'time'          => TIME,
                    'note'          => $note
                ];
                $insert=$db->insert('customer_amount_receive',$data);
                if($insert==false){$error=fl();setMessage(66);}
            }
            if(!isset($error)){
                $ac=true;
                $jArray['status'] = 1;
                setMessage(2,'Customer transaction added successfully');
            }
            $db->transactionStop($ac);
            
        }
        
    }
}