<?php
// session_start();
    if(isset($_POST['paramValues'])){
        $paramObj=json_decode($_POST['paramValues']);
        $obj=new DeductedClaims();
        $obj->getDeductedAmountClaimsDetails($paramObj);
    }else{
        echo "no result Found";
    }
    
    class DeductedClaims{
        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 getDeductedAmountClaimsDetails($paramObj){
            $returnResponseArray=array();
            $tempArray=array();
            $stmt=$this->db->prepare("SELECT ENGINEER_EMP_ID as empId, SITE_VISIT_DATE as siteVisitDate,
                                    CLAIM_STATUS as claimStatus,
                                    ENGINEER_FINAL_AMOUNT as engFinalAmount,TL_APPROVED_FINAL_AMOUNT as TLFinalAmount,
                                    FINANCE_APPROVED_FINAL_AMOUNT as fncnFinalAmount, TL_DEDUCTED_AMOUNT as TLDeductAmount,
                                    FINANCE_DEDUCTED_AMOUNT as fncnDeductAmount, TL_DEDUCTED_REASON as TLDeductReason,
                                    FINANCE_DEDUCTED_REASON as fncnDeductReason, REJECT_REASON as rejectReason, TOTAL_DEDUCTED_AMOUNT as totDeductAmount
                                    FROM `tesf-2` WHERE (TL_DEDUCTED_AMOUNT!=0 OR FINANCE_DEDUCTED_AMOUNT!=0 OR TL_DEDUCTED_REASON !='' OR FINANCE_DEDUCTED_REASON !='' OR REJECT_REASON !='') AND ENGINEER_EMP_ID = ? AND SITE_VISIT_DATE BETWEEN ? AND ?");
            $stmt->bind_param('sss',$paramObj->empId,$paramObj->fromDate,$paramObj->toDate);
            try{
                $this->db_Pdo->beginTransaction();
                    $queryExecutionResult=$stmt->execute();
                $this->db_Pdo->commit();
                if(!$queryExecutionResult){
                    $returnResponseArray['message']="FAILURE";
                }else{
                    $result = $stmt->get_result();
                    while($row=$result->fetch_assoc()){
                        array_push($tempArray,$row);
                    }
                    $returnResponseArray['message']="SUCCESS";
                    $returnResponseArray['responseDataArray']=$tempArray;
                }
                 
                  
            }
            catch(PDOException $e){
                $this->db_Pdo->rollback();
                $returnResponseArray['message']="FAILURE";
            }
           
           echo json_encode($returnResponseArray); 
           
            
        }
        
    }



?>