<?php
header ("Content-Type:text/xml");
include "start.php";
echo "<psync>";
//---------------------------------------------------------------------------------------------------------
  

  
  
  $query_warehouse_lib="select * from t_".$key_table_prefix."_warehouse ";
  $result_warehouse_lib = mysqli_query($dbconn,$query_warehouse_lib);
  while($line_warehouse_lib = mysqli_fetch_array($result_warehouse_lib,MYSQLI_ASSOC))
  {
     $lib_warehouse[$line_warehouse_lib["whs_code"]] = $line_warehouse_lib["whs_id"];
     
     
  }
  
  
  
  
    $query_sync="INSERT INTO
                    t_".$key_table_prefix."_stock_transaction_header
                    (
					
					device_id  ,
					
					sth_doc_prefix  ,
					sth_doc_no  ,
					sth_module  ,
					sth_date  ,
					sth_warehouse_code  ,
					sth_warehouse_id  ,
					
					sth_warehouse_code2  ,
					sth_warehouse_id2  ,
					
					sth_customer_code  ,
					sth_customer_name ,
					
					sth_vendor_code  ,
					sth_vendor_name ,
					
					sth_reference_no ,
					sth_remark ,
					
					sth_status ,
					
					sth_before_gst_amount ,
					sth_gst_amount ,
					sth_total_amount ,
					
					sth_category_code ,
					
					
					created_date ,
					modified_date ,
					client_id 
                    )
                    VALUES
                    (
	                    
					
					'".$_REQUEST["device_id"]."',
					'".$_REQUEST["sth_doc_prefix"]."',
					'".$_REQUEST["sth_doc_no"]."',
					'".$_REQUEST["sth_module"]."',
					
					'".$_REQUEST["sth_date"]."',
					
					'".$_REQUEST["sth_warehouse_code"]."',
					'".($lib_warehouse[$_REQUEST["sth_warehouse_code"]]+0)."' ,
					'".$_REQUEST["sth_warehouse_code2"]."',
					'".($lib_warehouse[$_REQUEST["sth_warehouse_code2"]]+0)."' ,
					
					
					'".$_REQUEST["sth_customer_code"]."',
					'".$_REQUEST["sth_customer_name"]."',
					
					'".$_REQUEST["sth_vendor_code"]."',
					'".$_REQUEST["sth_vendor_name"]."',
					
					'".$_REQUEST["sth_reference_no"]."',
					'".$_REQUEST["sth_remark"]."',
					
					'".$_REQUEST["sth_status"]."',
					
					'".abs($_REQUEST["sth_before_gst_amount"])."',
					'".abs($_REQUEST["sth_gst_amount"])."',
					'".abs($_REQUEST["sth_total_amount"])."',
					
					'".$_REQUEST["sth_category_code"]."',
					
					
					'".$_REQUEST["created_date"]."',
					
					'".$_REQUEST["modified_date"]."',
					
	                    '".$client_id."'
                    )
                    ON DUPLICATE KEY UPDATE
				
					
					
					
					sth_doc_prefix='".$_REQUEST["sth_doc_prefix"]."',
					sth_module='".$_REQUEST["sth_module"]."',
					
					
					
					
					sth_warehouse_code='".$_REQUEST["sth_warehouse_code"]."',
					sth_warehouse_id='".($lib_warehouse[$_REQUEST["sth_warehouse_code"]]+0)."' ,
					
					sth_warehouse_code2='".$_REQUEST["sth_warehouse_code2"]."',
					sth_warehouse_id2='".($lib_warehouse[$_REQUEST["sth_warehouse_code2"]]+0)."' ,
					
					
					
					sth_customer_code='".$_REQUEST["sth_customer_code"]."',
					sth_customer_name='".$_REQUEST["sth_customer_name"]."',
					
					sth_vendor_code='".$_REQUEST["sth_vendor_code"]."',
					sth_vendor_name='".$_REQUEST["sth_vendor_name"]."',
					
					sth_reference_no='".$_REQUEST["sth_reference_no"]."',
					sth_remark='".$_REQUEST["sth_remark"]."',
					
					sth_status='".$_REQUEST["sth_status"]."',
					
					sth_before_gst_amount='".abs($_REQUEST["sth_before_gst_amount"])."',
					sth_gst_amount='".abs($_REQUEST["sth_gst_amount"])."',
					sth_total_amount='".abs($_REQUEST["sth_total_amount"])."',
					
					sth_category_code='".$_REQUEST["sth_category_code"]."',
					
					
					
					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>";
?>