<?php
// array for JSON response
$response = array();

//check for required fields
if (isset($_POST['SalePur1ID']) && 
		isset($_POST['EntryType']) && 
		isset($_POST['SPDate']) &&   
		isset($_POST['AcNameID']) &&   
		isset($_POST['Remarks']) &&
		isset($_POST['ClientID']) &&   
		isset($_POST['ClientUserID']) &&
		isset($_POST['NetCode']) &&                                           
		isset($_POST['SysCode']) &&        
		isset($_POST['NameOfPerson']) &&                                                                                  
		isset($_POST['PayAfterDay'])) {

		$SalePur1ID= $_POST['SalePur1ID']; 
		$EntryType= $_POST['EntryType']; 
		$SPDate= $_POST['SPDate'];   
		$AcNameID= $_POST['AcNameID'];   
		$Remarks= $_POST['Remarks'];
		$ClientID= $_POST['ClientID'];   
		$ClientUserID= $_POST['ClientUserID'];
		$NetCode= $_POST['NetCode'];                                           
		$SysCode= $_POST['SysCode'];        
		$NameOfPerson= $_POST['NameOfPerson'];                                                                                 
		$PayAfterDay= $_POST['PayAfterDay']; 
		$BillAmount = $_POST['BillAmount'];
$BillStatus = $_POST['BillStatus'];
$ContactNo = $_POST['ContactNo'];

      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';

			    $UpdatedDate = date("Y-m-d H:i:s");

          $sql = "UPDATE SalePur1 SET BillAmount = '$BillAmount',BillStatus = '$BillStatus',ContactNo = '$ContactNo',EntryType = '$EntryType', SPDate = '$SPDate', AcNameID = '$AcNameID', Remarks = '$Remarks', ClientID = '$ClientID', ClientUserID = '$ClientUserID', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' ,NameOfPerson='$NameOfPerson',PayAfterDay='$PayAfterDay' WHERE SalePur1ID = $SalePur1ID AND ClientID=$ClientID AND EntryType='$EntryType'";
          $params = array();
		 
		try{	
			$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result= $stmt->rowCount();
		}
		catch(PDOException $e){
			echo $sql . "<br>" . $e->getMessage();
		}
		if ( $result != 0) {
				$rows_affected= "No information available.";
				$response["success"] = 1;
				$response["roweffected"] = $rows_affected;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "Update Successfully";
				// echoing JSON response
				echo json_encode($response);
		}else{
				$response["success"] = 0;
				$response["roweffected"] = $result;      
				$response["message"] = "Not updated row ".$result;
				// echoing JSON response
				echo json_encode($response);
		}
	
    }else{
      // success
      $response["success"] = 0;
      $response["message"] = "No Update";
      // echoing JSON response
      echo json_encode($response);
    }
?>
