<?php
if(isset($_POST["paramValues"])){
    $paramObj=json_decode($_POST["paramValues"]);
    $clsObj=new update_deleteTransactionDetails();
    $clsObj->doUpdate_delete_TransactionDetails($paramObj);
}else{
    echo "Result Not Found!";
}
class update_deleteTransactionDetails{
    function __construct(){
        require_once dirname(__DIR__).'../../../php/DB_Connect.php';
        $clsObj = new DB_conncect();
        $this->db=$clsObj->connectToDB();
        $this->db_Pdo=$clsObj->connectToDBVia_PDO();
    }
    function doUpdate_delete_TransactionDetails($paramObj){
        $mainArray=array();
        $mainArray["error"]=true;
        if($paramObj->queryType=="update"){
            $stmt=$this->getUpdateStmt($paramObj);
        }elseif($paramObj->queryType=="delete"){
            $stmt=$this->getDeleteStmt($paramObj);
        }
        try{
            $this->db_Pdo->beginTransaction();
                if($stmt->execute()){
                    if($stmt->rowCount() > 0){ //affected rows on delete or update
                        $mainArray["error"]=false;
                        $mainArray["message"]="Success";
                    }else{
                        $mainArray["message"]="No changes done";
                    }
                }else{
                    $mainArray["message"]="Unable to execute query";
                }
            $this->db_Pdo->commit();
        }catch(PDOException $e){
            $mainArray["message"]="Internal Error 500!";
        }
        echo json_encode($mainArray);
    }
    function getUpdateStmt($paramObj){
        $currentDate=Date('y-m-d');
        $stmt=$this->db_Pdo->prepare("UPDATE `fn_advances` SET `ADVANCE`='".$paramObj->transactionAmount."', `UPDATED_DATE`='".$currentDate."' WHERE TRANSACTION_ID='".$paramObj->transactionId."'");
        return $stmt;
    }
    function getDeleteStmt($paramObj){
        $stmt=$this->db_Pdo->prepare("DELETE FROM `fn_advances` WHERE `TRANSACTION_ID`='".$paramObj->transactionId."'");
        return $stmt;
    }
}



?>