<?php
header ("Content-Type:text/xml");
include "start.php";
echo "<psync>";
//---------------------------------------------------------------------------------------------------------
  
//===========================Product================================================  
  
  
  
    $query_sync="INSERT INTO
                    t_".$key_table_prefix."_return_item
                    (
					
					
			 		rti_rti_id,
					device_id, 
					
			 		rti_doc_no ,
			 		rti_product_code, 
			 		rti_product_barcode, 
			 		rti_product_name,
			 		rti_serial_no, 
			 		rti_remark,

			 		rti_price,  
			 		rti_cost, 
			 		rti_quantity,
			 		rti_uom,
					
			 		rti_attribute,  
			 		rti_size,
					rti_color,
					rti_pattern,
					
			 		rti_total_addon,

			 		rti_discount_percentage,
			 		rti_discount_value,
		 			rti_discount_total,  
			 		rti_total_before_gst, 

			 		rti_gst_mode, 
			 		rti_gst_code,  
			 		rti_gst_percentage, 
			 		rti_gst_amount,  

			 		rti_total_amount,  
			 		rti_status,
					
					rti_salesperson,

					created_date ,					
					modified_date ,
					client_id 
                    )
                    VALUES
                    (
	                    
					'".$_REQUEST["rti_id"]."',
					'".$_REQUEST["device_id"]."', 
					
			 		'".$_REQUEST["rti_doc_no"]."' ,
			 		'".$_REQUEST["rti_product_code"]."', 
			 		'".$_REQUEST["rti_product_barcode"]."', 
			 		'".$_REQUEST["rti_product_name"]."',
			 		'".$_REQUEST["rti_serial_no"]."', 
			 		'".$_REQUEST["rti_remark"]."',

			 		'".$_REQUEST["rti_price"]."',  
			 		'".$_REQUEST["rti_cost"]."', 
			 		'".$_REQUEST["rti_quantity"]."',
			 		'".$_REQUEST["rti_uom"]."',
					
			 		'".$_REQUEST["rti_attribute"]."',  
			 		'".$_REQUEST["rti_size"]."',
					'".$_REQUEST["rti_color"]."',
					'".$_REQUEST["rti_pattern"]."',
					
					
			 		'".$_REQUEST["rti_total_addon"]."',

			 		'".$_REQUEST["rti_discount_percentage"]."',
			 		'".$_REQUEST["rti_discount_value"]."',
		 			'".$_REQUEST["rti_discount_total"]."',  
			 		'".$_REQUEST["rti_total_before_gst"]."', 

			 		'".$_REQUEST["rti_gst_mode"]."', 
			 		'".$_REQUEST["rti_gst_code"]."',  
			 		'".$_REQUEST["rti_gst_percentage"]."', 
			 		'".$_REQUEST["rti_gst_amount"]."',  

			 		'".$_REQUEST["rti_total_amount"]."',  
			 		'".$_REQUEST["rti_status"]."',
					
					'".$_REQUEST["rti_salesperson"]."',

					'".$_REQUEST["created_date"]."' ,					
					'".$_REQUEST["modified_date"]."' ,
					'".$client_id."' 
					
                    )
                    ON DUPLICATE KEY UPDATE
				
					rti_doc_no ='".$_REQUEST["rti_doc_no"]."',
					rti_product_code='".$_REQUEST["rti_product_code"]."', 
					rti_product_barcode='".$_REQUEST["rti_product_barcode"]."', 
					rti_product_name='".$_REQUEST["rti_product_name"]."',
					rti_serial_no='".$_REQUEST["rti_serial_no"]."', 
					rti_remark='".$_REQUEST["rti_remark"]."',

					rti_price='".$_REQUEST["rti_price"]."',  
					rti_cost='".$_REQUEST["rti_cost"]."', 
					rti_quantity='".$_REQUEST["rti_quantity"]."',
					rti_uom='".$_REQUEST["rti_uom"]."',
					rti_attribute='".$_REQUEST["rti_attribute"]."',  
					rti_size='".$_REQUEST["rti_size"]."',
					rti_total_addon='".$_REQUEST["rti_total_addon"]."',

					rti_discount_percentage='".$_REQUEST["rti_discount_percentage"]."',
					rti_discount_value='".$_REQUEST["rti_discount_value"]."',
					rti_discount_total='".$_REQUEST["rti_discount_total"]."',  
					rti_total_before_gst='".$_REQUEST["rti_total_before_gst"]."', 

					rti_gst_mode='".$_REQUEST["rti_gst_mode"]."', 
					rti_gst_code='".$_REQUEST["rti_gst_code"]."',  
					rti_gst_percentage='".$_REQUEST["rti_gst_percentage"]."', 
					rti_gst_amount='".$_REQUEST["rti_gst_amount"]."',  

					rti_total_amount='".$_REQUEST["rti_total_amount"]."',  
					rti_status='".$_REQUEST["rti_status"]."',
					
					rti_salesperson='".$_REQUEST["rti_salesperson"]."',

					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."_return_item i
		    set rti_header_id = (select rth_id 
						    from t_".$key_table_prefix."_return_header h
						    where rth_doc_no = '".$_REQUEST["rti_doc_no"]."'
						    and  h.device_id = '".$_REQUEST["device_id"]."'
						    ) 
		    where rti_doc_no ='".$_REQUEST["rti_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>";
?>