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

//check for required fields
if (isset($_POST['CashBookID']) && isset($_POST['CBDate']) && isset($_POST['DebitAccount']) && isset($_POST['CreditAccount']) && isset($_POST['CBRemarks']) && isset($_POST['Amount'])
    && isset($_POST['ClientID']) && isset($_POST['ClientUserID']) && isset($_POST['NetCode']) && isset($_POST['SysCode']) && isset($_POST['SerialNo'])) {

      $CashBookID = $_POST['CashBookID'];
      $CB_Date = $_POST['CBDate'];
      $CBDate = date("Y-m-d", strtotime($CB_Date));
      $DebitAccount = $_POST['DebitAccount'];
      $CreditAccount = $_POST['CreditAccount'];
      $CBRemarks = $_POST['CBRemarks'];
      $Amount = $_POST['Amount'];
      $ClientID = $_POST['ClientID'];
      $ClientUserID = $_POST['ClientUserID'];
      $NetCode = $_POST['NetCode'];
      $SysCode = $_POST['SysCode'];
	  $SerialNo = $_POST['SerialNo'];

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

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

      $sql = "UPDATE CashBook SET CBDate = '$CBDate', DebitAccount = '$DebitAccount', CreditAccount = '$CreditAccount', CBRemarks = '$CBRemarks', Amount = '$Amount', ClientID = '$ClientID', ClientUserID = '$ClientUserID', NetCode = '$NetCode', SysCode = '$SysCode', UpdatedDate = '$UpdatedDate', SerialNo = '$SerialNo' WHERE CashBookID = $CashBookID && ClientID = '$ClientID'";
      $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{
		$response["success"] = 0;
        $response["message"] = "No Update";
        // echo no users JSON
        echo json_encode($response);
	}
?>
