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

//check for required fields
if (isset($_POST['SalePur1ID']) && 
isset($_POST['ItemSerial']) && 
isset($_POST['EntryType']) &&                                         
isset($_POST['Item3NameID']) &&
isset($_POST['ItemDescription'])&&
isset($_POST['QtyAdd']) &&                                 
isset($_POST['QtyLess']) &&                                                                  
isset($_POST['Price']) &&                                                                  
isset($_POST['Location']) &&                                          
isset($_POST['ClientID']) &&   
isset($_POST['ClientUserID']) &&
isset($_POST['NetCode']) &&                                           
isset($_POST['SysCode']) ){

$SalePur1ID = $_POST['SalePur1ID']; 
 $ItemSerial = $_POST['ItemSerial']; 
 $EntryType = $_POST['EntryType'];                                         
 $Item3NameID = $_POST['Item3NameID']; 
 $ItemDescription = $_POST['ItemDescription'];
 $QtyAdd = $_POST['QtyAdd'];                                 
 $QtyLess = $_POST['QtyLess'];                                                                  
 $Price = $_POST['Price'];                                                                  
 $Location = $_POST['Location'];                                          
 $ClientID = $_POST['ClientID'];   
 $ClientUserID = $_POST['ClientUserID']; 
 $NetCode = $_POST['NetCode'];                                           
 $SysCode = $_POST['SysCode'];  
 $Total = $_POST['Total'];  
      
      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';

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

          $sql = "UPDATE SalePur2 SET Total = '$Total',SalePur1ID = '$SalePur1ID', ItemSerial = '$ItemSerial', Item3NameID = '$Item3NameID', ItemDescription = '$ItemDescription', QtyAdd = '$QtyAdd', QtyLess = '$QtyLess',
          Price = '$Price', Location = '$Location',ClientUserID = '$ClientUserID', NetCode = '$NetCode',
          SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' WHERE ClientID = $ClientID AND EntryType = '$EntryType' AND SalePur1ID = $SalePur1ID AND ItemSerial = $ItemSerial";
          $params = array();
      $result=0;
		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"] = $result;
				$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);
    }
?>
