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




// push_notification_android( 'dHwxO4RRb0Tnip_B4p2_rB:APA91bEOHjfdmSzLSGoDuWAh9r2ItKHFbcj97UBXo8XwVb0epZaCf6tzC6N1EsxKdPDXN61Nd9ldACX83JGNBDb2ARxhiqUDjxTB9tgEWV87AHn0iSDeP08T4C2TLEgZjnXpdTNs4iZf','The work order (ABCD123) had been assigned to you',"Work Order Assigned","MSW","","","","","");	



//Header
$site_cd;
$itm_mst_rowid;
$mtr_mst_rowid;
$mtr_no;
$wo_no;
$asset_no;
$mst_costcenter;
$mst_account;
$audit_user;
$isu_empl_id;
$mr_status;
$remark;
$issue_date = date("Y-m-d h:i:s");
$doc_no = '';

//details
$mst_RowID;
$stock_no;
$mtr_ls1_desc;
$stock_location;
$cost_center;
$account;
$issue_qty;
$mtr_ls1_mtr_lineno;
$serial;
$lslRow_ID;

//After 
$ttl_oh_qty;
$itm_oh_qty;
$itm_RowID;
$itm_lockout;
$latest_itm_cost;
$latest_issue_price;
$surcharge = 0;
$raw_cost;
$ext_cost;
$p_issue_qty;
$fifo_avg;
$wko_mst_rowid;
$ast_mst_rowid;
$current_datetime = date("Y-m-d h:i:s");
$stock_cost_flag;

$itm_rsv_rsv_qty;
$itm_rsv_short_qty;

// Takes raw data from the request
$json = file_get_contents('php://input');
$result = json_decode($json);
 $loopCounterH = 0; 
  $loopCounter = 0; 
foreach($result->Header as $Heade){
	
	$site_cd 			= $Heade->site_cd;
	$itm_mst_rowid   	= $Heade->itm_mst_rowid;
	$mtr_no  			= $Heade->mtr_no;
	$wo_no 				= $Heade->wo_no;
	$asset_no			= $Heade->mtr_mst_assetno;
	$mst_costcenter		= $Heade->mst_costcenter;
	$mst_account		= $Heade->mst_account;
	$audit_user			= $Heade->mst_empl_id;
	$isu_empl_id		= $Heade->isu_empl_id;
	$mr_status			= $Heade->mr_status;
	$remark				= $Heade->remark;
	$issue_date			= $Heade->issue_date;
	//echo $issue_date;
	
$loopCounterH ++;
	echo $loopCounterH;
foreach($result->Details as $Detail){
	
	$stock_no 			= $Detail->mtr_ls1_stockno;
	$mtr_ls1_desc 		= $Detail->mtr_ls1_desc;
	$stock_location 	= $Detail->mtr_ls1_stk_locn;
	$cost_center 		= $Detail->crd_costcenter;
	$account 			= $Detail->crd_account;
	$issue_qty 			= $Detail->issue_qty;
	$mtr_ls1_mtr_lineno = $Detail->mtr_ls1_mtr_lineno;	
	$serial				= $Detail->mtr_ls1_varchar1;
	$lslRow_ID			= $Detail->LslRow_ID;
	$p_issue_qty 		= $issue_qty;
	
	//echo $wo_no 		;
	
	echo "Loop {$loopCounter}:{$site_cd} {$itm_mst_rowid } {$mtr_no} {$wo_no} {$asset_no} {$mst_costcenter} {$mst_account} {$audit_user} {$isu_empl_id} {$mr_status} {$remark} {$issue_date}\n"; // Print the loop number and stock number
    $loopCounter++;
	if($loopCounter === 3 ){
		die();
	}
	
	
}

}
?>