<?php
session_start();
if(isset($_POST['paramValues'])){
    $paramValuesObj=json_decode($_POST['paramValues']);
    $paramValuesObj->currentDate = date('Y-m-d'); 
    $clsObj = new UpdateAdvanceAmountDetails();
    $clsObj->updateDetails($paramValuesObj);
}else{
    echo "result not found5";
}

class UpdateAdvanceAmountDetails{
    function __construct(){
        require_once dirname(__DIR__).'../../php/DB_Connect.php';
        $dbClsObj=new DB_conncect();
        $this->db=$dbClsObj->connectToDB();
        $this->db_Pdo=$dbClsObj->connectToDBVia_PDO();
    }
    function updateDetails($paramObj){
        $responseArray=array();
        $stmt=$this->db->prepare("UPDATE `fn_advances` SET `ADVANCE`= ?, `REMARKS`=?, `UPDATED_DATE`=?  WHERE `ID`=?");
        $stmt->bind_param('ssss', $paramObj->advanceAmount,  $paramObj->remarks, $paramObj->currentDate, $paramObj->db_tableIndex);
        try{
            $this->db_Pdo->beginTransaction();
                $executionStatus=$stmt->execute();
            $this->db_Pdo->commit();
            if(!$executionStatus){
                $responseArray["error"]=true;
                $responseArray["message"]="Unable to execute";
            }else{
                $stmt->store_result();
                if(($stmt->affected_rows)>0){
                    $responseArray["error"]=false;
                    $responseArray["message"]="Succesfully Updated";
                }else{
                    $responseArray["error"]=true;
                    $responseArray["message"]="No changes done.";
                }
            }
            
        }catch(PDOException $e){
            $responseArray["error"]=true;
            $responseArray["message"]="Internal error 500!";
        }
        echo json_encode($responseArray);
    }
}


?>