<?php
require_once('config.php');
require_once ('f_send_push_notification.php');


$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);

$site_cd = $data['site_cd'];
$EmpID = $data['EmpID'];
$dvc_id = $data['dvc_id'];
$mtr_mst_rowID = $data['mtr_mst_rowID'];
$LOGINID = $data['LOGINID'];

$sql_header ="Select	pur_mst.pur_mst_porqnnum,   
					pur_mst.pur_mst_requested_by,      
					pur_mst.pur_mst_req_date,    
					pur_mst.pur_mst_chg_costcenter,   
					pur_mst.pur_mst_chg_account,   
					pur_mst.pur_mst_tot_cost,
					pur_mst.pur_mst_purq_approve,   
					pur_mst.pur_mst_notes
			FROM 	pur_mst (NOLOCK)
			WHERE 	pur_mst.site_cd = '".$site_cd."'
			and		pur_mst.RowID = '".$mtr_mst_rowID."'";

$stmt_header = sqlsrv_query( $conn, $sql_header);

if( !$stmt_header ) {

 $error_message = "Error selecting pur_mst";
 returnError($error_message);
 die( print_r( sqlsrv_errors(), true));
 
}
do {

while ($row = sqlsrv_fetch_array($stmt_header, SQLSRV_FETCH_ASSOC)) {		

		$pur_mst_porqnnum = $row['pur_mst_porqnnum'];	
		$pur_mst_requested_by = $row['pur_mst_requested_by'];	
		$pur_mst_req_date = $row['pur_mst_req_date']->format('d/m/Y');	
		$pur_mst_chg_costcenter = $row['pur_mst_chg_costcenter'];	
		$pur_mst_chg_account = $row['pur_mst_chg_account'];	
		$pur_mst_tot_cost = $row['pur_mst_tot_cost'];	
		$pur_mst_notes = $row['pur_mst_notes'];	

}

} while ( sqlsrv_next_result($stmt_header) );
							

$title = "PR Require approval";
$body = "The Purchase Request ".$pur_mst_porqnnum." require your approval.";
$module = "Purchase Request";
$message ="PR No:".$pur_mst_porqnnum." 
\r\nPR Amount:".$pur_mst_tot_cost."
\r\nRequester:".$pur_mst_requested_by."
\r\nRequest Date:".$pur_mst_req_date.".
\r\nCost Center:".$pur_mst_chg_costcenter."
\r\nAccount:".$pur_mst_chg_account."
\r\nNotes:".$pur_mst_notes."";
							


insert_notification_log($site_cd, $EmpID, $EmpID, $pur_mst_porqnnum, $title, $body, $message, $module, $dvc_id, $LOGINID);
	

?>