<?php
header ("Content-Type:text/xml");
include "start.php";
echo "<psync>";
//---------------------------------------------------------------------------------------------------------
  
//===========================Product================================================  
  
  
  
    $query_sync="INSERT INTO
                    t_".$key_table_prefix."_collection_item
                    (
					
					
			 		coi_coi_id,
					device_id, 
					
			 		coi_doc_no ,
			 		coi_pay_doc_no, 
			 		coi_pay_doc_amount, 
			 		
					
			 		coi_status,
					
					
					created_date ,					
					modified_date ,
					client_id 
                    )
                    VALUES
                    (
	                    
					'".$_REQUEST["coi_id"]."',
					'".$_REQUEST["device_id"]."', 
					
			 		'".$_REQUEST["coi_doc_no"]."' ,
			 		'".$_REQUEST["coi_pay_doc_no"]."', 
			 		'".$_REQUEST["coi_pay_doc_amount"]."', 
			 		
			 		'".$_REQUEST["coi_status"]."',
					
					
					'".$_REQUEST["created_date"]."' ,					
					'".$_REQUEST["modified_date"]."' ,
					'".$client_id."' 
					
                    )
                    ON DUPLICATE KEY UPDATE
				
					coi_doc_no ='".$_REQUEST["coi_doc_no"]."',
					coi_pay_doc_no='".$_REQUEST["coi_pay_doc_no"]."', 
					coi_pay_doc_amount='".$_REQUEST["coi_pay_doc_amount"]."', 
					
					coi_status='".$_REQUEST["coi_status"]."',
					
					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));
    
               
			
			
			
			
	$query_refresh="update t_".$key_table_prefix."_collection_item i
			set coi_header_id = (select coh_id 
							from t_".$key_table_prefix."_collection_header h
							where coh_doc_no = '".$_REQUEST["coi_doc_no"]."'
							and  h.device_id = '".$_REQUEST["device_id"]."'
							) 
			where coi_doc_no ='".$_REQUEST["coi_doc_no"]."' and i.device_id = '".$_REQUEST["device_id"]."'
			";
			
	$result_refresh = mysqli_query($dbconn,$query_refresh) or die("Error ".mysqli_error($dbconn));
			                     
echo "<upload>
";
echo "<status>SUCCESS</status>
";
echo "<message>".str_replace("&","&amp;","Upload Successful")."</message>
";
echo "</upload>
";

         


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