<?php

session_start();

if (isset($_POST['imageRelatedValues'])) {
 
    $encodedImageRelatedValues=$_POST['imageRelatedValues'];
    $loggedInUserID = $_SESSION['userId'];
    $loggedInUserName = $_SESSION['userName'];
    $loggedInUserDepartment = $_SESSION['teamLeads'];
    $claimChangesUpdatedBy =$loggedInUserID.",".$loggedInUserName;
    $obj = new UpdateBill();
    $imageRelatedValues=json_decode($encodedImageRelatedValues);
    $obj->updatevalues($imageRelatedValues, $loggedInUserDepartment,$claimChangesUpdatedBy);// update the bills proof amount
  //  $obj->insertvalues($empId, $selectedDate);// show total and bills amount after update
} else {
echo "fail";
}

class UpdateBill
{

    function __construct()
    {
        require_once dirname(__DIR__).'../../php/DB_Connect.php';
        $objectOfDBClass=new DB_conncect();
        $this->db=$objectOfDBClass->connectToDB();
       
    }
    function updatevalues($imageRelatedValues, $loggedInUserDepartment,$claimChangesUpdatedBy)
    {
        $query = $this->db->prepare("CALL Image_bill_update(?,?,?,?,?,?,?,?,?)");
        $query->bind_param("sdsddssdd",$loggedInUserDepartment,$imageRelatedValues->billProofAmount, $imageRelatedValues->imageName, $imageRelatedValues->hotelbills, $imageRelatedValues->finalTotalAmount, $claimChangesUpdatedBy, $imageRelatedValues->uniqueId, $imageRelatedValues->loggedInUserDeductAmount, $imageRelatedValues->otherbills);
       $query->execute();
     $query->bind_result($tesf2_otherBillsAmount,$tesf2_hotelBillsAmount,$tesf2_finalamount);
                $query->store_result();
        
                if($query->num_rows()>0){
                 while($query->fetch()){
                        $empIdarry[] =array(
                            "otherBills"=>$tesf2_otherBillsAmount,
                            "hotelBill"=>$tesf2_hotelBillsAmount,
                            "total"=>$tesf2_finalamount
                        );
                    }
                }
                echo json_encode($empIdarry);
    }
}
?>