<?php
session_start();
if(isset($_POST["paramValues"])){
    $paramObj= json_decode($_POST["paramValues"]);
    $paramObj->createdBy=$_SESSION["userId"].",".$_SESSION["userName"];
    $paramObj->createdDate=date("Y-m-d");
    $paramObj->advanceReleaseDate=date("Y-m-d");
    $paramObj->remarks="LAST YEAR ADJUSTMENT";
    $clsObj=new insertAdvanceDetails();
    $clsObj->insertAdvance($paramObj);
}else{
    echo "Result not found";
}

class insertAdvanceDetails{
    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 insertAdvance($paramObj){
        $mainArray=array();
        $stmt=$this->db_Pdo->prepare("INSERT INTO `fn_advances`(`EMP_ID`, `FORTNIGHT`, `TRANSACTION_ID`, `ADVANCE`, `ADVANCE_RELEASE_DATE`, `REMARKS`, `CREATED_BY`, `CREATED_DATE`) 
                                                VALUES('".$paramObj->empId."', '".$paramObj->fortnight."', '".$paramObj->transactionId."', '".$paramObj->advanceAmount."', '".$paramObj->advanceReleaseDate."', '".$paramObj->remarks."', '".$paramObj->createdBy."', '".$paramObj->createdDate."')");
        try{
            $this->db_Pdo->beginTransaction();
                if($stmt->execute()){
                    $mainArray["error"]=false;
                    $mainArray["message"]="Succesfully Inserted";
                }else{
                    $mainArray["error"]=true;
                    $mainArray["message"]="Unable to execute query"; 
                }
            $this->db_Pdo->commit();
        }catch(PDOException $e){
            $mainArray["error"]=true;
            $mainArray["message"]="Internal error 500!";
        }
        echo json_encode($mainArray);
    }
}

?>