<?php
header ("Content-Type:text/xml");
include "start.php";
echo "<psync>";
//---------------------------------------------------------------------------------------------------------
  
//===========================Product================================================  
  
  
  	if(($_REQUEST["created_date"]=="")or($_REQUEST["created_date"]=="null"))
	{
		
		
		//get created date from header:
		
		
		
		$query_header="select * from t_".$key_table_prefix."_invoice_header 
					where ivh_ivh_id = '".$_REQUEST["ivp_ivh_id"]."' 
					and device_id = '".$_REQUEST["device_id"]."'
					
					";
			
			
		$result_header = mysqli_query($dbconn,$query_header) or die("Error ".mysqli_error($dbconn));
		if($line_header = mysqli_fetch_array($result_header,MYSQLI_ASSOC))
		{
			
			$_REQUEST["created_date"] = $line_header["created_date"];
			$_REQUEST["modified_date"] = $line_header["modified_date"];
			
			
			
		}
		
		if(($_REQUEST["created_date"]=="")or($_REQUEST["created_date"]=="null"))
		{
			$_REQUEST["created_date"] = date("Y-m-d H:i:s");
			$_REQUEST["modified_date"] = date("Y-m-d H:i:s");
			
		}
		
		
	}
  
  
  
    $query_sync="INSERT INTO
                    t_".$key_table_prefix."_invoice_payment
                    (
			 		ivp_ivp_id,
					device_id, 
					
					ivp_ivh_id, 
			 		ivp_doc_no ,
					
			 		ivp_payment_code, 
			 		ivp_payment_name,
					
					ivp_reference_no,
					ivp_approval_no,
					
			 		ivp_amount, 
			 		ivp_change,

					created_date ,					
					modified_date ,
					client_id 
                    )
                    VALUES
                    (
	                    
					'".$_REQUEST["ivp_id"]."',
					'".$_REQUEST["device_id"]."', 
					
			 		'".$_REQUEST["ivp_ivh_id"]."', 
					'".$_REQUEST["ivp_doc_no"]."' ,
					
			 		'".$_REQUEST["ivp_payment_code"]."', 
			 		'".$_REQUEST["ivp_payment_name"]."',
					
					'".$_REQUEST["ivp_reference_no"]."',
					'".$_REQUEST["ivp_approval_no"]."',
					
			 		'".$_REQUEST["ivp_amount"]."', 
			 		'".$_REQUEST["ivp_change"]."',

					'".$_REQUEST["created_date"]."' ,					
					'".$_REQUEST["modified_date"]."' ,
					'".$client_id."' 
					
                    )
                    ON DUPLICATE KEY UPDATE
				
				
					ivp_ivh_id ='".$_REQUEST["ivp_ivh_id"]."', 
					ivp_doc_no ='".$_REQUEST["ivi_doc_no"]."', 
					
					ivp_payment_code='".$_REQUEST["ivp_payment_code"]."', 
					ivp_payment_name='".$_REQUEST["ivp_payment_name"]."', 
					
					ivp_reference_no='".$_REQUEST["ivp_reference_no"]."', 
					ivp_approval_no='".$_REQUEST["ivp_approval_no"]."', 
					
					ivp_amount='".$_REQUEST["ivp_amount"]."', 
					ivp_change='".$_REQUEST["ivp_change"]."', 

					
					
					created_date ='".$_REQUEST["created_date"]."',					
					modified_date ='".$_REQUEST["modified_date"]."',
					client_id = '".$client_id."' 
					
                    ;
                    ";
    $result_sync = mysqli_query($dbconn,$query_sync) or die("Error ".mysqli_error($dbconn));
    
               
			
			
			
			
			                     
echo "<upload>
";
echo "<status>SUCCESS</status>
";
echo "<message>".str_replace("&","&amp;","Upload Successful")."</message>
";
echo "</upload>
";

         


//---------------------------------------------------------------------------------------------------------
echo "</psync>";
?>