<?php
if(isset($_POST['paramValues'])){
    $paramObj=json_decode($_POST['paramValues']);
    $classObj=new InvoiceDetails();
    $classObj->getInvoiceDetails($paramObj);
}else{
    echo "Result No Found";
}

class InvoiceDetails{
    function __construct(){
        require_once dirname(__DIR__).'../../../../php/DB_Connect.php';
        $obj=new DB_conncect();
        $this->db=$obj->connectToDB();
        $this->db_Pdo=$obj->connectToDBVia_PDO();
    }
    function getInvoiceDetails($paramObj){
        $returnResponseArray=array();
        $stmt=$this->db->prepare("SELECT * FROM `invoices` WHERE `INVOICE_NUMBER`=?");
        $stmt->bind_param('s',$paramObj->invoiceNo);
        try{
            $this->db_Pdo->beginTransaction();
                $executionResult=$stmt->execute();
            $this->db_Pdo->commit();
            if(!$executionResult){
                $returnResponseArray['message']='FAILURE';
            }else{
                $returnResponseArray['message']='SUCCESS';
                $result=$stmt->get_result();
                // because only one result we get , if multiple we use while
                $data=$result->fetch_assoc();
                $returnResponseArray['responseDataArray']=$data ? $data : []; 
            }
            
        }
        catch(PDOException $e){
            $this->db_Pdo->rollback();
            $returnResponseArray['message']='FAILURE';
        }
        echo json_encode($returnResponseArray);
    }
}
?>