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

//check for required fields
if (isset($_POST['LocationID']) && isset($_POST['LocationName']) && isset($_POST['ClientID']) && isset($_POST['ClientUserID']))   {

      $LocationID = $_POST['LocationID'];
      $LocationName = $_POST['LocationName'];
      $ClientID = $_POST['ClientID'];
      $ClientUserID = $_POST['ClientUserID'];
      $NetCode = $_POST['NetCode'];
      $SysCode = $_POST['SysCode'];
    // include db connect class
       require_once __DIR__ . '/../DBConnect.php';

	// 		$sql = "SELECT AcGruopName FROM Account2Group WHERE AcGruopName = '$AcGruopName' AND ClientID = '$ClientID' AND AcGroupID != '$AcGroupID'";
	// 		$params = array();
	// 		$stmt = $conn->prepare($sql);
	// 		$stmt->execute();
    //         $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
            
	// if($result!=null &&  $result>0 && $AcGruopName!=''){
	// 		// success
	// 		$response["success"] = 0;
	// 		$response["message"] = "Login Number Already Register";
	// 		// echoing JSON response
    //         echo json_encode($response);

    //   }else{
	// 		$sql = "SELECT AcName FROM Account3Name WHERE ClientID = '$ClientID' AND AcName = '$AcName' AND AcNameID != '$AcNameID'";
	// 		$params = array();
	// 		$stmt = $conn->prepare($sql);
	// 		$stmt->execute();
	// 		$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	// 		if($result!=null &&  $result>0){
	// 		  // success
	// 		  $response["success"] = 0;
	// 		  $response["message"] = "Name Already Register";
	// 		  // echoing JSON response
	// 			echo json_encode($response);
	// 		}else{
				$UpdatedDate = date("Y-m-d H:i:s");
				$sql = "UPDATE SalePurLocation SET LocationName = '$LocationName', ClientUserID = '$ClientUserID',
                 NetCode = '$NetCode', SysCode = '$SysCode', UpdatedDate = '$UpdatedDate' WHERE LocationID = '$LocationID' AND 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{
      // success
      $response["success"] = 0;
      $response["message"] = "Send All Required Fields";
      // echoing JSON response
      echo json_encode($response);
    }
?>
