<?php
// include db connect class
	require_once __DIR__ . '/../DBConnect.php';
	if (isset($_POST['ClientID']) && isset($_POST['SessionDate'])) {
    $ClientID = $_POST['ClientID'];
    $SessionDate = $_POST['SessionDate'];

			$sql = "SELECT * FROM SalePur1 WHERE ClientID = $ClientID AND  UpdatedDate > '$SessionDate'";

			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			   

		   if($result!=null &&  $result>0){
					  $response["Salepur1"] = array();
			 foreach($result as $row) { 
					
				 $Salepur1["ID"] = $row["ID"];          
				$Salepur1["SalePur1ID"] = $row["SalePur1ID"];  
				$Salepur1["EntryType"] = $row["EntryType"];  
				$Salepur1["SPDate"] = $row["SPDate"];     
				$Salepur1["AcNameID"] = $row["AcNameID"];    
				$Salepur1["Remarks"]=$row["Remarks"];                
								
				$Salepur1["ClientID"] = $row["ClientID"];    
				$Salepur1["ClientUserID"] = $row["ClientUserID"]; 
				$Salepur1["NetCode"] = $row["NetCode"];                                            
				$Salepur1["SysCode"] = $row["SysCode"];                                            
				$Salepur1["UpdatedDate"] = $row["UpdatedDate"];             
				$Salepur1["NameOfPerson"]=$row["NameOfPerson"];          
				$Salepur1["PayAfterDay"] = $row["PayAfterDay"];
				$Salepur1["BillAmount"] = $row["BillAmount"];
$Salepur1["BillStatus"] = $row["BillStatus"];
$Salepur1["ContactNo"] = $row["ContactNo"];
				  // push single product into final response array
				  array_push($response["Salepur1"], $Salepur1);
			  }
			  // success
			  $response["success"] = 1;
			  // echoing JSON response
			  echo json_encode($response);
		}else {
		  // success
		  $response["success"] = 0;
		  $response["message"] = "No Data Availaible";
		  // echoing JSON response
		  echo json_encode($response);
		}
  }else if (isset($_POST['ClientID']) && isset($_POST['MaxID'])&& isset($_POST['EntryType']))
	  {
      $ClientID = $_POST['ClientID'];
      $MaxID = $_POST['MaxID'];
      $EntryType = $_POST['EntryType'];
		$sql = "SELECT * FROM SalePur1 WHERE ClientID = $ClientID AND EntryType='$EntryType' AND SalePur1ID >= $MaxID";

		$params = array();
		$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			   

		if($result!=null &&  $result>0){
			  $response["Salepur1"] = array();
			 foreach($result as $row) { 
				 $Salepur1["ID"] = $row["ID"];          
				$Salepur1["SalePur1ID"] = $row["SalePur1ID"];  
				$Salepur1["EntryType"] = $row["EntryType"];  
				$Salepur1["SPDate"] = $row["SPDate"];     
				$Salepur1["AcNameID"] = $row["AcNameID"];    
				$Salepur1["Remarks"]=$row["Remarks"];                                                                                              
				$Salepur1["ClientID"] = $row["ClientID"];    
				$Salepur1["ClientUserID"] = $row["ClientUserID"]; 
				$Salepur1["NetCode"] = $row["NetCode"];                                            
				$Salepur1["SysCode"] = $row["SysCode"];                                            
				$Salepur1["UpdatedDate"] = $row["UpdatedDate"];             
				$Salepur1["NameOfPerson"]=$row["NameOfPerson"];          
				$Salepur1["PayAfterDay"] = $row["PayAfterDay"];	
				$Salepur1["BillAmount"] = $row["BillAmount"];
                $Salepur1["BillStatus"] = $row["BillStatus"];
                $Salepur1["ContactNo"] = $row["ContactNo"];
						  // push single product into final response array
				  array_push($response["Salepur1"], $Salepur1);
				}
			
				// success
				 $response["success"] = 1;
			  
				// echoing JSON response
				echo json_encode($response);
      }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
      }
	}
	else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
	}

?>
