<?php
if(isset($_POST['paramValues'])){
    $paramValueObj=json_decode($_POST['paramValues']);
    $obj=new getAdvanceAmountStatement();
    $obj->getAdvanceDetails($paramValueObj);
}else{
    echo "No data found";
}

class getAdvanceAmountStatement{
    function __construct(){
            require_once dirname(__DIR__).'../../php/DB_Connect.php';
            $DBClassObject = new DB_conncect();
            $this->db=$DBClassObject->connectToDB();
            $this->db_Pdo =$DBClassObject->connectToDBVia_PDO();
            
    }
    function getAdvanceDetails($paramObj){
        $responseArray=array();
        $tempArray=array();
        $stmt=$this->db->prepare("SELECT * FROM `fn_advances` WHERE `EMP_ID`=? AND `ADVANCE_RELEASE_DATE`  BETWEEN ? AND ?");
         $stmt->bind_param('sss',$paramObj->empId,$paramObj->fromDate,$paramObj->toDate);
        try{
            $this->db_Pdo->beginTransaction();
                $executionStatus=$stmt->execute();
            $this->db_Pdo->commit();
            if(!$executionStatus){
                $responseArray["message"]="FAILURE";
            }else{
                $result=$stmt->get_result();
                while($data=$result->fetch_assoc()){
                    array_push($tempArray,$data);
                }
                $responseArray["message"]="SUCCESS";
                $responseArray["responseDataArray"]=$tempArray;
                
            }
            
        }catch(PDOException $e){
            $responseArray['message']="FAILURE";
        }
        
         echo json_encode($responseArray);
    }
    
}


?>