<?php include "../../includes/start_ajax.php";?>
<?php

$this_module_title="Stock Transfer";

$this_form_name="form_stock_transfer";
$this_url="mod/stock_transfer/index.php";

$this_doc_prefix="ST";
$this_doc_number_module_code="ST";
$this_module="STOCK_TRANSFER";
$this_inventory_posting_type="MINUS";
$this_inventory_posting_type2="PLUS";
 

if($_REQUEST["load_document_id"]!="")
{
	$_SESSION["st_load_document_id"] = $_REQUEST["load_document_id"];
}


echo "<div  align=left >";
echo "<form name='".$this_form_name."'  >";

	echo "<input type='hidden' name='ui_action' value=''>";
	echo "<input type='hidden' name='add_item_id' value=''>";
	echo "<input type='hidden' name='remove_item_ts' value=''>";
	echo "<input type='hidden' name='edit_item_ts' value=''>";

	echo "<input type='hidden' name='load_document_id' value=''>";

	if(($_REQUEST["ui_action"]=="REMOVE_ITEM")and($_REQUEST["remove_item_ts"]!=""))
	{
		unset($_SESSION["STOCK_TRANSFER_ITEM"][$_REQUEST["remove_item_ts"]]);
		
	}

	if(($_REQUEST["ui_action"]=="EDIT_ITEM")and($_REQUEST["edit_item_ts"]!=""))
	{
		$ts_edit = $_REQUEST["edit_item_ts"];
		$this_edit_product_id = $_SESSION["STOCK_TRANSFER_ITEM"][$ts_edit]["ID"];
		include "form_edit.php";
	}
	
	
	
	
	
	
	
	
	
		
		
		if($_REQUEST["ui_action"]=="PICK_REVERSE")
		{
			include "search_reversed.php";
		}
		
		
		if($_REQUEST["ui_action"]=="PICK_REVERSE_DONE")
		{
		
			$query_draft_selected = " select * from t_".$key_table_prefix."_stock_transaction_header
					where sth_id ='".$_SESSION["st_load_document_id"]."'  ";
			$result_draft_selected = mysqli_query($dbconn,$query_draft_selected);
			if($line_draft_selected = mysqli_fetch_array($result_draft_selected,MYSQLI_ASSOC))
			{
				
				$reversal_date = $line_draft_selected["sth_date"];
			
				$_REQUEST["date"] = $line_draft_selected["sth_date"];
				$_REQUEST["warehouse_code_from"] = $line_draft_selected["sth_warehouse_code"];
				$_REQUEST["warehouse_code_to"] = $line_draft_selected["sth_warehouse_code2"];
				
				
				$_REQUEST["customer_code"]  = $line_draft_selected["sth_customer_code"];
				$_REQUEST["vendor_code"]  = $line_draft_selected["sth_vendor_code"];
				
				$_REQUEST["category_code"]  = $line_draft_selected["sth_category_code"];
				
				$_REQUEST["refno"] = $line_draft_selected["sth_reference_no"];
				$_REQUEST["remark"] = $line_draft_selected["sth_remark"];
				
				for($prj=1;$prj<=1;$prj++)
				{
					
					$_REQUEST["project_".$prj.""] = "";
					
					$query_get_project = "select * from   t_".$key_table_prefix."_project_link
								where plk_module = 'STOCK_TRANSFER'
								and plk_object_id = '".$_SESSION["st_load_document_id"]."' ;
								";
								
					
					$result_get_project = mysqli_query($dbconn,$query_get_project);
					if($line_get_project = mysqli_fetch_array($result_get_project,MYSQLI_ASSOC))
					{
						$_REQUEST["project_".$prj.""] = $line_get_project["plk_project_id"];			
					}
								
					
				}
				
				
				
				
				
				
				
				unset($_SESSION["STOCK_TRANSFER_ITEM"]);
				//get all PO item:
				
				$query_draft_item_selected = " select * from t_".$key_table_prefix."_stock_transaction_item
						where sti_header_id ='".$_SESSION["st_load_document_id"]."'  ";
				$result_draft_item_selected = mysqli_query($dbconn,$query_draft_item_selected);
				while($line_draft_item_selected = mysqli_fetch_array($result_draft_item_selected,MYSQLI_ASSOC))
				{
					$ts=date("YmdHis").rand(1000,9999);
					
					//get product:
					
					//get product info:
					$query_product="select * from t_".$key_table_prefix."_product 
						where pdt_code = '".$line_draft_item_selected["sti_stock_code"]."' ";
					$result_product = mysqli_query($dbconn,$query_product);
					if($line_product = mysqli_fetch_array($result_product,MYSQLI_ASSOC))
					{
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["ID"] = $line_product["pdt_id"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["CODE"]=$line_draft_item_selected["sti_stock_code"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["BARCODE"]=$line_draft_item_selected["sti_barcode"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["NAME"]=$line_draft_item_selected["sti_stock_name"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["PRICE"]=$line_draft_item_selected["sti_unit_cost"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["QTY"]=$line_draft_item_selected["sti_quantity"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["UOM"]=$line_draft_item_selected["sti_uom"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["GST_CODE"]=$line_draft_item_selected["sti_gst_code"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["GST_MODE"]=$line_draft_item_selected["sti_gst_mode"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["GST_PERCENTAGE"]=$line_draft_item_selected["sti_gst_percentage"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["BEFORE_GST"]=$line_draft_item_selected["sti_before_gst_amount"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["GST_AMOUNT"]=$line_draft_item_selected["sti_gst_amount"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["TOTAL_AMOUNT"]=$line_draft_item_selected["sti_total_amount"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["COLOR"]=$line_draft_item_selected["sti_color"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["SIZE"]=$line_draft_item_selected["sti_size"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["PATTERN"]=$line_draft_item_selected["sti_pattern"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["STORAGE_LOCATION_FROM"]=$line_draft_item_selected["sti_storage_location"];
						$_SESSION["STOCK_TRANSFER_ITEM"]["TS".$ts]["STORAGE_LOCATION_TO"]=$line_draft_item_selected["sti_storage_location2"];
						
						
						
						
						
						
						
					}
					
					
					
					
					
					
					
				}
					
				
				
				
				
				
				
				
			}
		
		}
		
		
		
		if($_REQUEST["ui_action"]=="CLEAR_DRAFT")
		{
			
			$_REQUEST["date"] = date("Y-m-d");
			$_REQUEST["warehouse_code_from"] = "";
			$_REQUEST["warehouse_code_to"] = "";
			
			$_REQUEST["customer_code"]  = "";
			$_REQUEST["vendor_code"]  = "";
			
			$_REQUEST["category_code"]  = "";
			
			$_REQUEST["refno"] = "";
			$_REQUEST["remark"] = "";
			
			for($prj=1;$prj<=1;$prj++)
			{
				$_REQUEST["project_".$prj.""] = "";
			}
		
			
			$_SESSION["st_load_document_id"]="";
			unset($_SESSION["STOCK_TRANSFER_ITEM"]);
		}
		
		
	
	
	






	if($_REQUEST["ui_action"]=="ADD_ITEM1")
	{
		include "search.php";
	}
	
	
	if($_REQUEST["ui_action"]=="ADD_ITEM2")
	{
		
	     include "form.php";
	}
	
	
	if(($_REQUEST["ui_action"]=="ADD_ITEM_OK")or($_REQUEST["ui_action"]=="EDIT_ITEM_OK"))
	{
		
		//$_REQUEST["add_item_unit_price"];
		//$_REQUEST["add_item_quantity"];
		//$_REQUEST["add_item_gst_code"];
		//$_REQUEST["add_item_gst_mode"];
		//
		
		$query_product = " select * from t_".$key_table_prefix."_product 
				where pdt_id ='".$_REQUEST["add_item_id"]."'  ";
		$result_product = mysqli_query($dbconn,$query_product);
		if($line_product = mysqli_fetch_array($result_product,MYSQLI_ASSOC))
		{
			
				$error_msg="";
				
				if($_REQUEST["add_item_unit_price"]=="")
				{
					$error_msg=$error_msg."<li>Unit Cost</li>";
				}
				else {
					if(!is_numeric($_REQUEST["add_item_unit_price"]))
					{
			
						$error_msg=$error_msg."<li>Unit Cost must be numeric value only.</li>";	  
					}
				}
				if($_REQUEST["add_item_quantity"]=="")
				{
					$error_msg=$error_msg."<li>Quantity</li>";
				}
				else {
					if(!is_numeric($_REQUEST["add_item_quantity"]))
					{
			
						$error_msg=$error_msg."<li>Quantity must be numeric value only.</li>";	  
					}
				}
				
				if($_REQUEST["add_item_gst_code"]=="")
				{
					//$error_msg=$error_msg."<li>Tax Code</li>";
				}
				else {
					
					if($_REQUEST["add_item_gst_mode"]=="")
					{
						$error_msg=$error_msg."<li>GST Mode</li>";
					}
				}
				
				if($line_product["pdt_select_pattern"]=="YES")
				{
					if($_REQUEST["add_item_pattern"]=="")
					{
						$error_msg=$error_msg."<li>Pattern</li>";
					}
				}
				
				if($line_product["pdt_select_color"]=="YES")
				{
					if($_REQUEST["add_item_color"]=="")
					{
						$error_msg=$error_msg."<li>Color</li>";
					}
				}
				
				if($line_product["pdt_select_size"]=="YES")
				{
					if($_REQUEST["add_item_size"]=="")
					{
						$error_msg=$error_msg."<li>Size</li>";
					}
				}
				
				
				
				
				
				if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
				{
				
					if($_REQUEST["add_item_storage_location_from"]=="")
					{
						$error_msg=$error_msg."<li>Storage Location (From)</li>";
					}
					if($_REQUEST["add_item_storage_location_to"]=="")
					{
						$error_msg=$error_msg."<li>Storage Location (To)</li>";
					}
					 
				}
				 
				
				
				
				
			
				if($error_msg=="")
				{


					
					
					
						
						$this_item_gst_percentage=0;
						$query_gst="select * from t_".$key_table_prefix."_gst 
								where gst_code = '".$_REQUEST["add_item_gst_code"]."' ";
						$result_gst = mysqli_query($dbconn,$query_gst);
						if($line_gst = mysqli_fetch_array($result_gst,MYSQLI_ASSOC))
						{
							$this_item_gst_percentage=$line_gst["gst_percentage"];
						}
						
						
						
						if($_REQUEST["add_item_gst_mode"]=="EXCLUSIVE")
						{
							
							$this_item_before_gst_amount = $_REQUEST["add_item_unit_price"]*$_REQUEST["add_item_quantity"];
							$this_item_gst_amount = number_format($this_item_before_gst_amount*($this_item_gst_percentage/100),2,".","");
							$this_item_total_amount = $this_item_before_gst_amount + $this_item_gst_amount;
							
						}
						
						if($_REQUEST["add_item_gst_mode"]=="INCLUSIVE")
						{
							
							$this_item_total_amount = $_REQUEST["add_item_unit_price"]*$_REQUEST["add_item_quantity"];
							
							$this_item_gst_amount = number_format($this_item_total_amount/(100+$this_item_gst_percentage)*$this_item_gst_percentage,2,".","");
							
							$this_item_before_gst_amount = $this_item_total_amount-$this_item_gst_amount;
							
							
						}
						
						
						
						if($_REQUEST["add_item_gst_mode"]=="")
						{
							
							$this_item_before_gst_amount = $_REQUEST["add_item_unit_price"]*$_REQUEST["add_item_quantity"];
							$this_item_gst_amount = "0.00";
							$this_item_total_amount = $this_item_before_gst_amount + $this_item_gst_amount;
							
						}
						
						
						
						
						
						if($_REQUEST["edit_item_ts"]!="")
						{
							
							$ts=$_REQUEST["edit_item_ts"];
						}
						else {
							
							$ts="TS".date("YmdHis");
						}
						
						
						
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["ID"]=$_REQUEST["add_item_id"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["CODE"]=$line_product["pdt_code"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["BARCODE"]=$line_product["pdt_barcode"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["NAME"]=$line_product["pdt_name"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["PRICE"]=$_REQUEST["add_item_unit_price"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["QTY"]=$_REQUEST["add_item_quantity"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["UOM"]=$line_product["pdt_uom"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["GST_CODE"]=$_REQUEST["add_item_gst_code"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["GST_MODE"]=$_REQUEST["add_item_gst_mode"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["GST_PERCENTAGE"]=$this_item_gst_percentage;
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["BEFORE_GST"]=$this_item_before_gst_amount;
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["GST_AMOUNT"]=$this_item_gst_amount;
						
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["TOTAL_AMOUNT"]=$this_item_total_amount;
						
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["COLOR"]=$_REQUEST["add_item_color"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["SIZE"]=$_REQUEST["add_item_size"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["PATTERN"]=$_REQUEST["add_item_pattern"];
						
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["STORAGE_LOCATION_FROM"]=$_REQUEST["add_item_storage_location_from"];
						$_SESSION["STOCK_TRANSFER_ITEM"][$ts]["STORAGE_LOCATION_TO"]=$_REQUEST["add_item_storage_location_to"];
						
						
						
					
					
					
					//displaymessage("test","CREATED");
					
				}
				else {
					displaymessage($error_msg,"FAIL");
					
					
					
					if($_REQUEST["ui_action"]=="ADD_ITEM_OK")
					{
						include "form.php";
					}
					if($_REQUEST["ui_action"]=="EDIT_ITEM_OK")
					{
						$ts_edit = $_REQUEST["edit_item_ts"];
						$this_edit_product_id = $_SESSION["STOCK_TRANSFER_ITEM"][$ts_edit]["ID"];
						include "form_edit.php";	
					}
					
					
					
					$error_msg="";
				}
			
				
	     
		}
		
		
	}



	if ($_SERVER[REQUEST_METHOD] == 'POST') {
		
		
		$_SESSION["STOCK_TRANSFER_HEADER"]["DATE"]=$_REQUEST["date"];
		$_SESSION["STOCK_TRANSFER_HEADER"]["WAREHOUSE_FROM"]=$_REQUEST["warehouse_code_from"];
		$_SESSION["STOCK_TRANSFER_HEADER"]["WAREHOUSE_TO"]=$_REQUEST["warehouse_code_to"];
		
		$_SESSION["STOCK_TRANSFER_HEADER"]["CUSTOMER"]=$_REQUEST["customer_code"];
		$_SESSION["STOCK_TRANSFER_HEADER"]["VENDOR"]=$_REQUEST["vendor_code"];
		
		$_SESSION["STOCK_TRANSFER_HEADER"]["REFNO"]=$_REQUEST["refno"];
		$_SESSION["STOCK_TRANSFER_HEADER"]["REMARK"]=$_REQUEST["remark"];
		
		
		
		if($_REQUEST["ui_action"]=="POST")
		{
			
			$item_found=false;
			
			$error_msg="";
			
			
			
			foreach($_SESSION["STOCK_TRANSFER_ITEM"] as $ts=>$ts_data)
			{
				$item_found=true;
			}
			
			
			
			if(!$item_found)
			{
				$error_msg=$error_msg."<li>No Item Input</li>";
			}
			
			
			if($_REQUEST["date"]=="")
			{
				$error_msg=$error_msg."<li>Date not specified</li>";
			}
			
			
			
			if($_REQUEST["warehouse_code_from"]=="")
			{
				$error_msg=$error_msg."<li>Warehouse (From) not specified</li>";
			}
			
			if($_REQUEST["warehouse_code_to"]=="")
			{
				$error_msg=$error_msg."<li>Warehouse (To) not specified</li>";
			}
			
			
			if($_REQUEST["refno"]=="")
			{
				$error_msg=$error_msg."<li>Reference No. not specified</li>";
			}
			
			
			
			//-------------------Project Checking---------------------------------------------------
			
			if($sys_system_master_setting_line["set_module_project"]=="YES")
			{	
				$accum_project_percentage=0;
				
				for($prj=1;$prj<=1;$prj++)
				{
					
					if($_REQUEST["project_".$prj]!="")
					{
						
						if($_REQUEST["project_percentage_".$prj]=="")
						{
						//	$error_msg=$error_msg."<li>Percentage not specified for Project ".$prj."</li>";
							
						}
						else {
							$accum_project_percentage = $accum_project_percentage + $_REQUEST["project_percentage_".$prj];	
						}
						
						
					}
				}
				
				
				if($accum_project_percentage==100)
				{
					
					
				}
				else {
					
				//	$error_msg=$error_msg."<li>Total percentage for all project(s) must be equal to 100%</li>";
				}
			}
			//-------------------Project Checking---------------------------------------------------
			
			
			
			
			
			
			if($error_msg=="")
			{
				
					//calculate amt:
					foreach($_SESSION["STOCK_TRANSFER_ITEM"] as $ts=>$ts_data)
					{
						$header_before_gst_amount = $header_before_gst_amount + $ts_data["BEFORE_GST"];
						$header_gst_amount = $header_gst_amount + $ts_data["GST_AMOUNT"];
						$header_total_amount = $header_total_amount + $ts_data["TOTAL_AMOUNT"];
						
							
					}
					
					
					
					//get info:
					$query_whs="select * from t_".$key_table_prefix."_warehouse 
						where whs_code  ='".$_REQUEST["warehouse_code_from"]."' ";
					$result_whs  = mysqli_query($dbconn,$query_whs);
					if($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
					{
						$this_warehouse_from_id = $line_whs["whs_id"];
					}
					
					//get info:
					$query_whs="select * from t_".$key_table_prefix."_warehouse 
						where whs_code  ='".$_REQUEST["warehouse_code_to"]."' ";
					$result_whs  = mysqli_query($dbconn,$query_whs);
					if($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
					{
						$this_warehouse_to_id = $line_whs["whs_id"];
					}
					
					
					
					
					//get info:
					$query_cus="select * from t_".$key_table_prefix."_customer
						where cus_code  ='".$_REQUEST["customer_code"]."' ";
					$result_cus  = mysqli_query($dbconn,$query_cus);
					if($line_cus = mysqli_fetch_array($result_cus,MYSQLI_ASSOC))
					{
						$this_customer_name = $line_cus["cus_name"];
					}
					
					
					//get info:
					$query_vdr="select * from t_".$key_table_prefix."_vendor
						where vdr_code  ='".$_REQUEST["vendor_code"]."' ";
					$result_vdr  = mysqli_query($dbconn,$query_vdr);
					if($line_vdr = mysqli_fetch_array($result_vdr,MYSQLI_ASSOC))
					{
						$this_vendor_name = $line_vdr["vdr_name"];
					}
					
					
					
					$this_doc_no="ERROR";
					
					
					
					
					$query_draft_selected = " select * from t_".$key_table_prefix."_stock_transaction_header
							where sth_id ='".$_SESSION["st_load_document_id"]."'  ";
					$result_draft_selected = mysqli_query($dbconn,$query_draft_selected);
					if($line_draft_selected = mysqli_fetch_array($result_draft_selected,MYSQLI_ASSOC))
					{
						
						//is amending an existing draft document:
						$this_doc_no = $line_draft_selected["sth_doc_no"];
						
						
						$query="update t_".$key_table_prefix."_stock_transaction_header 
								set 
								
								sth_date = '".$_REQUEST["date"]."' ,
								sth_warehouse_code = '".$_REQUEST["warehouse_code_from"]."' ,
								sth_warehouse_id  = '".$this_warehouse_from_id."'  ,
								
								sth_warehouse_code2 = '".$_REQUEST["warehouse_code_to"]."' , 
								sth_warehouse_id2 = '".$this_warehouse_to_id."'  , 
								
								
								sth_customer_code  = '".$_REQUEST["customer_code"]."' ,
								sth_customer_name  = '".$this_customer_name."'  ,
								sth_vendor_code  = '".$_REQUEST["vendor_code"]."' ,
								sth_vendor_name  = '".$this_vendor_name."'  ,
								sth_reference_no  = '".$_REQUEST["refno"]."'  ,
								sth_remark  = '".$_REQUEST["remark"]."'  ,
								sth_status  = 'POSTED'  ,
								sth_before_gst_amount = '".($header_before_gst_amount+0)."' ,
								sth_gst_amount = '".($header_gst_amount+0)."' ,
								sth_total_amount = '".($header_total_amount+0)."' ,
								
								sth_category_code = '".$_REQUEST["category_code"]."',
							
							
								modified_date  = '".date("Y-m-d H:i:s")."'  ,
								modified_by =  '".$CurrentUserID."'  
								
								
								
								where sth_id = '".$_SESSION["st_load_document_id"]."'
							"; 
						$result = mysqli_query($dbconn,$query) or die("Error update Header".mysqli_error($dbconn));
						
						$header_id  = $_SESSION["st_load_document_id"];
						
						
						
						
						//clear the item in database:
						$query_clear_item="delete from t_".$key_table_prefix."_stock_transaction_item 
								where sti_header_id = '".$header_id."'   ;
								";
						$result_clear_item = mysqli_query($dbconn,$query_clear_item) or die("Error Insert ITEM".mysqli_error($dbconn));
						
						
					}
					else {
						
						$this_doc_no = mon_register_document_number($this_doc_number_module_code);
						
						
						$query="insert into t_".$key_table_prefix."_stock_transaction_header 
								(
								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  ,
								created_date  ,
								created_by  ,
								modified_date  ,
								modified_by  ,
								client_id  
								)
								values
								(
								'".$this_doc_prefix."'  ,
								'".$this_doc_no."'  ,
								'".$this_module."'  ,
								'".$_REQUEST["date"]."' ,
								
								'".$_REQUEST["warehouse_code_from"]."' ,
								'".$this_warehouse_from_id."'  ,
								
								'".$_REQUEST["warehouse_code_to"]."' ,
								'".$this_warehouse_to_id."'  ,
								
								
								'".$_REQUEST["customer_code"]."' ,
								'".$this_customer_name."'  ,
								'".$_REQUEST["vendor_code"]."' ,
								'".$this_vendor_name."'  ,
								'".$_REQUEST["refno"]."'  ,
								'".$_REQUEST["remark"]."'  ,
								'POSTED'  ,
								'".($header_before_gst_amount+0)."' ,
								'".($header_gst_amount+0)."' ,
								'".($header_total_amount+0)."' ,
								'".date("Y-m-d H:i:s")."'  ,
								'".$CurrentUserID."'  ,
								'".date("Y-m-d H:i:s")."'  ,
								'".$CurrentUserID."'  ,
								'0'  	
								)
						
							"; 
						$result = mysqli_query($dbconn,$query) or die("Error insert Header".mysqli_error($dbconn));
						$header_id  = mysqli_insert_id($dbconn);
						
						
					}
					
					
					
					
					
						foreach($_SESSION["STOCK_TRANSFER_ITEM"] as $ts=>$ts_data)
						{
							$query_product = "select * 
										from t_".$key_table_prefix."_product 
										where pdt_id = '".$ts_data["ID"]."' ";
							$result_product = mysqli_query($dbconn,$query_product);
							if($line_product = mysqli_fetch_array($result_product,MYSQLI_ASSOC))
							{
								
								
								$query_item="insert into t_".$key_table_prefix."_stock_transaction_item 
								 		(
											
										  sti_header_id  ,
										  sti_doc_prefix  ,
										  sti_doc_no  ,
										  sti_module  ,
										  sti_date  ,
										  sti_warehouse_code  ,
										  sti_warehouse_id  ,
										  
										  sti_warehouse_code2  ,
										  sti_warehouse_id2  ,
										  
										  
										  sti_stock_code  ,
										  sti_barcode  ,
										  sti_factory_code  ,
										  sti_stock_name  ,
										  sti_color  ,
										  sti_size  ,
										  sti_pattern  ,
										  sti_uom  ,
										  sti_base_uom  ,
										  sti_quantity  ,
										  sti_base_quantity  ,
										  sti_conversion  ,
										  sti_unit_cost  ,
										  sti_base_unit_cost  ,
										  sti_total_cost  ,
										  sti_gst_mode  ,
										  sti_gst_code  ,
										  sti_gst_percentage  ,
										  sti_remark  ,
										  sti_status  ,
										  sti_before_gst_amount  ,
										  sti_gst_amount  ,
										  sti_total_amount  ,
										  
										  sti_storage_location  ,
										  sti_storage_location2  ,
										  
										  
										  created_date  ,
										  created_by  ,
										  modified_date  ,
										  modified_by  ,
										  client_id  
										)
										values
										(
										'".$header_id."'  ,
										
										'".$this_doc_prefix."'  ,
										'".$this_doc_no."'  ,
										'".$this_module."'  ,
										'".$_REQUEST["date"]."' ,
										'".$_REQUEST["warehouse_code_from"]."' ,
										'".$this_warehouse_from_id."'  ,
										
										'".$_REQUEST["warehouse_code_to"]."' ,
										'".$this_warehouse_to_id."'  ,
										
										
										  '".$ts_data["CODE"]."'  ,
			   							  '".$line_product["pdt_barcode"]."'  ,
			   							  ''  ,
			   							  '".$ts_data["NAME"]."'  ,
			   							  '".$ts_data["COLOR"]."'  ,
			   							  '".$ts_data["SIZE"]."'  ,
			   							  '".$ts_data["PATTERN"]."'  ,
			   							  '".$ts_data["UOM"]."'  ,
			   							  '".$ts_data["UOM"]."'  ,
			   							  '".($ts_data["QTY"]+0)."'  ,
			   							  '".($ts_data["QTY"]+0)."'  ,
			   							  '1'  ,
			   							  '".($ts_data["PRICE"]+0)."'  ,
			   							  '".($ts_data["PRICE"]+0)."'  ,
			   							  '".(($ts_data["PRICE"]*$ts_data["QTY"])+0)."'  ,
			   							  '".$ts_data["GST_MODE"]."'  ,
			   							  '".$ts_data["GST_CODE"]."'  ,
			   							  '".($ts_data["GST_PERCENTAGE"]+0)."'  ,
			   							  ''  ,
			   							  'POSTED'  ,
			   							  '".($ts_data["BEFORE_GST"]+0)."'  ,
			   							  '".($ts_data["GST_AMOUNT"]+0)."'  ,
			   							  '".($ts_data["TOTAL_AMOUNT"]+0)."'  ,
										  
										  
										  '".$ts_data["STORAGE_LOCATION_FROM"]."'  ,
										  '".$ts_data["STORAGE_LOCATION_TO"]."'  ,
										  
										  '".date("Y-m-d H:i:s")."'  ,
										  
				  						  '".$CurrentUserID."'  ,
					  					  '".date("Y-m-d H:i:s")."'  ,
					  					  '".$CurrentUserID."'  ,
					  					  '0'  	
											
										);
										";
								
								$result_item = mysqli_query($dbconn,$query_item) or die("Error Insert ITEM".mysqli_error($dbconn));
								$last_item_id = mysqli_insert_id($dbconn);
								
								
								//------------------------Part 1: minus:-------------------------
								post_inventory_balance(
										'SERVER',
										$_REQUEST["date"],
										$this_doc_no, 
										$last_item_id,
										
										$this_module, 
										
										$this_inventory_posting_type, 
										$_REQUEST["warehouse_code_from"], 
										$ts_data["CODE"], 
										$ts_data["UOM"], 
										$ts_data["QTY"], 
										$ts_data["COLOR"],
										$ts_data["SIZE"], 
										$ts_data["PATTERN"]
										);
												
												
								if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
							     {
								    
								    $query_internal_transaction ="INSERT INTO
													t_".$key_table_prefix."_internal_inventory_transaction
													(
													    device_id  ,
													    iit_device_iit_id  ,
													    iit_date  ,
													    iit_location_code  ,
													    iit_product_code  ,
													    
													    iit_type  ,
													    iit_user  ,
													    iit_quantity  ,
												    
													    created_date ,
													    modified_date ,
													    client_id 
													)
													VALUES
													(
													    
													    
													    'SERVER',
													    '".$header_id."-".$last_item_id."OUT',
													    
													    '".$_REQUEST["date"]."',
													    
													    
													    '".$ts_data["STORAGE_LOCATION_FROM"]."',
													    '".$ts_data["CODE"]."',
													    
													    'CHECK_OUT',
													    '".$CurrentUserFullName."',
													    '".abs(($ts_data["QTY"]+0))."',
													    
													    
													    '".date("Y-m-d H:i:s")."',
													    '".date("Y-m-d H:i:s")."',
													    
													    '0'
													)
												;
												";
								    $result_internal_transaction = mysqli_query($dbconn,$query_internal_transaction) or die("Error ".mysqli_error($dbconn));
								    
											
										    
								    
									
									
							    }				
												
												
												
								//------------------------Part 2: plus:-------------------------
								post_inventory_balance(
										'SERVER',
										$_REQUEST["date"],
										$this_doc_no, 
										$last_item_id,
										
										$this_module, 
										
										$this_inventory_posting_type2, 
										$_REQUEST["warehouse_code_to"], 
										$ts_data["CODE"], 
										$ts_data["UOM"], 
										$ts_data["QTY"], 
										$ts_data["COLOR"],
										$ts_data["SIZE"], 
										$ts_data["PATTERN"]
										);
								
										
								if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
							    	{
								    
								    $query_internal_transaction ="INSERT INTO
													t_".$key_table_prefix."_internal_inventory_transaction
													(
													    device_id  ,
													    iit_device_iit_id  ,
													    iit_date  ,
													    iit_location_code  ,
													    iit_product_code  ,
													    
													    iit_type  ,
													    iit_user  ,
													    iit_quantity  ,
												    
													    created_date ,
													    modified_date ,
													    client_id 
													)
													VALUES
													(
													    
													    
													    'SERVER',
													    
													    '".$header_id."-".$last_item_id."IN',
													    
													    '".$_REQUEST["date"]."',
													    
													    
													    '".$ts_data["STORAGE_LOCATION_TO"]."',
													    '".$ts_data["CODE"]."',
													    
													    'CHECK_IN',
													    '".$CurrentUserFullName."',
													    '".abs(($ts_data["QTY"]+0))."',
													    
													    
													    '".date("Y-m-d H:i:s")."',
													    '".date("Y-m-d H:i:s")."',
													    
													    '0'
													)
												;
												";
								    $result_internal_transaction = mysqli_query($dbconn,$query_internal_transaction) or die("Error ".mysqli_error($dbconn));
								    
											
										    
								    
									
									
							    	}				
									
							
								
								
							}
							
						}
						
						
						//------------------------Project Module-------------------------------------------
						
						if($sys_system_master_setting_line["set_module_project"]=="YES")
						{	
							
							//clear all
							
							$query_clear = "delete from  t_".$key_table_prefix."_project_link
										where plk_module = 'STOCK_TRANSFER'
										and plk_object_id = '".$header_id."' ;
										";
										
							$result_clear = mysqli_query($dbconn,$query_clear) or die("Error Insert ITEM".mysqli_error($dbconn));		
							
							
							
							for($prj=1;$prj<=1;$prj++)
							{
								
								if($_REQUEST["project_".$prj]!="")
								{
									
									$query_insert = "insert into t_".$key_table_prefix."_project_link
												(
												plk_project_id, 
												plk_module,
												plk_object_id,
												plk_percentage ,
												created_by,
												modified_by,
												
												created_date,
												modified_date,
												client_id
												)
												values
												(
												'".$_REQUEST["project_".$prj]."',
												'STOCK_TRANSFER',
												'".$header_id."',
												'".($_REQUEST["project_percentage_".$prj]+0)."',
												
												'".$CurrentUserID."',
												'".$CurrentUserID."',
												
												'".date("Y-m-d H:i:s")."',
												'".date("Y-m-d H:i:s")."',
												'0'	
												)
												";
												
									$result_insert = mysqli_query($dbconn,$query_insert) or die("Error Insert ITEM".mysqli_error($dbconn));		
									
									
												
									$_REQUEST["project_".$prj]="";
									$_REQUEST["project_percentage_".$prj]="";
									
								}
							
							
								
							}
						}
					
					displaymessage("POSTED","CREATED");
					
					unset($_SESSION["STOCK_TRANSFER_HEADER"]);
					unset($_SESSION["STOCK_TRANSFER_ITEM"]);
					
					
					$_REQUEST["date"] = date("Y-m-d");
					$_REQUEST["warehouse_code_from"]="";
					$_REQUEST["warehouse_code_to"]="";
					
					$_REQUEST["customer_code"]="";
					$_REQUEST["vendor_code"]="";
					
					$_REQUEST["refno"] = "";
					$_REQUEST["remark"] = "";
			
					$_SESSION["st_load_document_id"]="";
			
			}
			else {
				
				displaymessage($error_msg,"FAIL");
			}
			
		}
		
		
		
		
		
	}
	else {
		
		$_REQUEST["date"] = $_SESSION["STOCK_TRANSFER_HEADER"]["DATE"];
		$_REQUEST["warehouse_code_from"]=$_SESSION["STOCK_TRANSFER_HEADER"]["WAREHOUSE_FROM"];
		$_REQUEST["warehouse_code_to"]=$_SESSION["STOCK_TRANSFER_HEADER"]["WAREHOUSE_TO"];
		$_REQUEST["customer_code"]=$_SESSION["STOCK_TRANSFER_HEADER"]["CUSTOMER"];
		$_REQUEST["vendor_code"]=$_SESSION["STOCK_TRANSFER_HEADER"]["VENDOR"];
		$_REQUEST["refno"] = $_SESSION["STOCK_TRANSFER_HEADER"]["REFNO"];
		$_REQUEST["remark"] = $_SESSION["STOCK_TRANSFER_HEADER"]["REMARK"];
	}

	//============================================================================================

	echo "<div style='float:left;width:96%;padding:3px 2% 3px 2%;'>";
		//echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:left;'  onclick=\"mon_submit_form('".$this_form_name."','".$this_url."')\" >";
			//echo "<i class='fa fa-square fa-stack-2x color_grey'  ></i><i class='fa fa-save fa-stack-1x color_white' ></i>";
		//echo "</div>";
		
		echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:left;'  onclick=\"if(confirm('Are you sure?')){document.".$this_form_name.".ui_action.value='POST';mon_submit_form('".$this_form_name."','".$this_url."')}\" >";
			echo "<i class='fa fa-square fa-stack-2x color_blue'  ></i><i class='fa fa-bolt fa-stack-1x color_white' ></i>";
		echo "</div>";
		
		//echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;'  onclick=\"mon_refresh_tab(mon_current_selected_tab);\" >";
			//echo "<i class='fa fa-square fa-stack-2x color_red'   ></i><i class='fa fa-refresh fa-stack-1x color_white' ></i>";
		//echo "</div>";


		echo "<div style='cursor:pointer;float:right;line-height:30px;' >";
			echo "Select Reversed Document";
		echo "</div>";
		
		echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;margin-left:30px;' onclick=\"document.".$this_form_name.".ui_action.value='PICK_REVERSE';mon_submit_form('".$this_form_name."','".$this_url."')\" >";
			echo "<i class='fa fa-square fa-stack-2x ' style='color:#F39C12;'  ></i><i class='fa fa-reply fa-stack-1x color_white' ></i> ";
		echo "</div>";
		
		
		
	echo "</div>";
	
	
	
	
	
	if($_SESSION["st_load_document_id"]!="")
	{
		$query_draft_selected = " select * from t_".$key_table_prefix."_stock_transaction_header
				where sth_id ='".$_SESSION["st_load_document_id"]."'  ";
		$result_draft_selected = mysqli_query($dbconn,$query_draft_selected);
		if($line_draft_selected = mysqli_fetch_array($result_draft_selected,MYSQLI_ASSOC))
		{
			
			echo "<div style='float:left;width:96%;padding:3px 2% 3px 2%;'>";
		
				echo "<div class='form_field_separator' >";
					echo "<div style='background:#F1C40F;color:#000;border-radius:10px;padding:10px;text-align:center;'>";
						echo "<font size=2 >Reversed Document: <b>".$line_draft_selected["sth_doc_no"]."</b> Loaded for Edit/Amendment. </font>";
						echo " <input type=button class='button button-red' value='Cancel' onclick=\"document.".$this_form_name.".load_document_id.value='';document.".$this_form_name.".ui_action.value='CLEAR_DRAFT';mon_submit_form('".$this_form_name."','".$this_url."')\" >";
					echo "</div>";
				echo "</div>";
				
			echo "</div>";
			
			
		
		
		
		}
		
		
		
	}
	
	
	
	
	
	//============================================================================================
	echo "<div style='float:left;width:96%;padding:3px 2% 3px 2%;'>";
	
		echo "<div class='form_field_separator' >";
			echo "<font size=3><b>".$this_module_title."</b></font><br><br>";
		echo "</div>";
			
		//--------------Date------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Date</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				echo "<input type=\"text\" class=\"textbox textbox-s\" name=\"date\"  value=\"".$_REQUEST["date"]."\"  >";		
				
				echo "<a href=\"javascript:void(0)\" onclick=\"if(self.gfPop)gfPop.fPopCalendar(document.".$this_form_name.".date);"."return false;\" HIDEFOCUS>";
				echo " <span class='fa fa-calendar fa-lg' style='color:#000;'></span>";
				echo "</a>"; 
				
			echo "</div>";	
		echo "</div>";	
		
		//--------------Warehouse from------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>From Warehouse</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				
				echo "<select class='dropdown dropdown-auto' name='warehouse_code_from'>";
				
					
					$query_whs = "select * from 
							t_".$key_table_prefix."_warehouse , t_".$key_table_prefix."_user_group_warehouse_link 
							where whs_id = gwl_warehouse_id 
							and gwl_group_id = '".$_SESSION[$sys_session_prefix.'_user_group']."'
							order by whs_code
							 ";
							 
					$result_whs = mysqli_query($dbconn,$query_whs);
					while($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
					{
						
						if($_REQUEST["warehouse_code_from"]==$line_whs["whs_code"])
						{
							echo "<option value='".$line_whs["whs_code"]."' selected >";
						}
						else {
							echo "<option value='".$line_whs["whs_code"]."'>";
						}
						
						echo $line_whs["whs_code"];
						echo " ";
						echo $line_whs["whs_name"];
						
						echo "</option>";
						
						
					}
					
				
				echo "</select>";
				
				
			echo "</div>";	
		echo "</div>";		
		
		//--------------Warehouse to------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>To Warehouse</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				
				echo "<select class='dropdown dropdown-auto' name='warehouse_code_to'>";
				
					$query_whs = "select * from t_".$key_table_prefix."_warehouse";
					$result_whs = mysqli_query($dbconn,$query_whs);
					while($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
					{
						
						if($_REQUEST["warehouse_code_to"]==$line_whs["whs_code"])
						{
							echo "<option value='".$line_whs["whs_code"]."' selected >";
						}
						else {
							echo "<option value='".$line_whs["whs_code"]."'>";
						}
						
						echo $line_whs["whs_code"];
						echo " ";
						echo $line_whs["whs_name"];
						
						echo "</option>";
						
						
					}
					
				
				echo "</select>";
				
				
			echo "</div>";	
		echo "</div>";		
		
		
		
		if($sys_system_master_setting_line["set_stock_transfer_use_customer"]=="YES")
		{
		
		//--------------Customer------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Customer</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				
				echo "<select class='dropdown dropdown-auto' name='customer_code'>";
					echo "<option value=''></option>";
					$query_cus = "select * from t_".$key_table_prefix."_customer";
					$result_cus = mysqli_query($dbconn,$query_cus);
					while($line_cus = mysqli_fetch_array($result_cus,MYSQLI_ASSOC))
					{
						
						if($_REQUEST["customer_code"]==$line_cus["cus_code"])
						{
							echo "<option value='".$line_cus["cus_code"]."' selected >";
						}
						else {
							echo "<option value='".$line_cus["cus_code"]."'>";
						}
						
						echo $line_cus["cus_code"];
						echo " ";
						echo $line_cus["cus_name"];
						
						echo "</option>";
						
						
					}
					
				
				echo "</select>";
				
				
			echo "</div>";	
		echo "</div>";		
		
		}
	
		
		
		if($sys_system_master_setting_line["set_stock_transfer_use_vendor"]=="YES")
		{
			
		//--------------Vendor------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Vendor</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				
				echo "<select class='dropdown dropdown-auto' name='vendor_code'>";
					echo "<option value=''></option>";
					$query_vdr = "select * from t_".$key_table_prefix."_vendor";
					$result_vdr = mysqli_query($dbconn,$query_vdr);
					while($line_vdr = mysqli_fetch_array($result_vdr,MYSQLI_ASSOC))
					{
						
						if($_REQUEST["vendor_code"]==$line_vdr["vdr_code"])
						{
							echo "<option value='".$line_vdr["vdr_code"]."' selected >";
						}
						else {
							echo "<option value='".$line_vdr["vdr_code"]."'>";
						}
						
						echo $line_vdr["vdr_code"];
						echo " ";
						echo $line_vdr["vdr_name"];
						
						echo "</option>";
						
						
					}
					
				
				echo "</select>";
				
				
			echo "</div>";	
		echo "</div>";		
		
		
		}
	
	
	
		//--------------Reference No.------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Reference No.</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				echo "<input type=\"text\" class=\"textbox textbox-l\" name=\"refno\"  value=\"".$_REQUEST["refno"]."\"  >";		
			echo "</div>";	
		echo "</div>";		
		
		//--------------Remark------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Remark</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
				echo "<textarea  class=\"textarea textarea-l\" name=\"remark\"  >".$_REQUEST["remark"]."</textarea>";		
			echo "</div>";	
		echo "</div>";		
		
			
			
			
			
			
		
		
//==================Start: Project Module=====================================================================================
		
if($sys_system_master_setting_line["set_module_project"]=="YES")
{
	
	
	echo "<div class='form_field_separator' >";
		echo "<font size=3><b>Project Info</b></font><br><br>";
	echo "</div>";
	
	
	for($prj=1;$prj<=1;$prj++)
	{
		
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' >";
				echo "<b>Project ".$prj."</b>";			
			echo "</div>";
			
			echo "<div class='form_field_input' >";
			echo "<select class='dropdown dropdown-auto' name='project_".$prj."' >";
				echo "<option value=''></option>";
				$query_prj = "select * from t_".$key_table_prefix."_project";
				$result_prj = mysqli_query($dbconn,$query_prj);
				while($line_prj = mysqli_fetch_array($result_prj,MYSQLI_ASSOC))
				{
					
					if($_REQUEST["project_".$prj.""]==$line_prj["prj_id"])
					{
						echo "<option value='".$line_prj["prj_id"]."' selected >";
					}
					else {
						echo "<option value='".$line_prj["prj_id"]."'>";
					}
					
					echo $line_prj["prj_code"];
					echo " ";
					echo $line_prj["prj_name"];
					
					echo "</option>";
					
					
				}
				
			
			echo "</select>";
			
			
			
			
				//echo " Percentage (%): <input type=\"text\" class=\"textbox textbox-s\" name=\"project_percentage_".$prj."\"  value=\"".$_REQUEST["project_percentage_".$prj.""]."\"  >";		
				
				
				
				
				
			echo "</div>";
		echo "</div>";		
		
		
		
			
		
	}
	
}			
//==================End: Project Module=====================================================================================
		
		
		
		
		
		
			
	//==================Item Level======================================	
			
		echo "<div class='data_display_separator' >";
			echo "<font size=3><b>Transaction Item</b></font>";
			
			//add item button
			echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;' onclick=\"document.".$this_form_name.".ui_action.value='ADD_ITEM1';mon_submit_form('".$this_form_name."','".$this_url."')\" >";
				echo "<i class='fa fa-square fa-stack-2x color_green'   ></i><i class='fa fa-plus fa-stack-1x color_white' ></i>";
			echo "</div>";
			
		echo "</div>";	
	 
	 
	 
		
       //===Header Label =============
       $f_label[1]="Product Code";
       $f_label[2]="Name";
       $f_label[3]="Additional Info";
       $f_label[4]="Unit Cost";
       $f_label[5]="Quantity";
       $f_label[6]="Tax";
       $f_label[7]="Before Tax";
       $f_label[8]="Tax Amount";
       $f_label[9]="Total Amount";
	  $f_label[10]="Action";
       
	  
	 
		//===Column width==========
   	  $f_width[1]="100";
   	  $f_width[2]="200";
   	  $f_width[3]="100";
   	  $f_width[4]="80";
   	  $f_width[5]="80";
   	  $f_width[6]="80";
   	  $f_width[7]="80";
   	  $f_width[8]="80";
	  $f_width[9]="80";
	  $f_width[10]="40";

   	  //===Column align==========
	  $f_align[1]="left";
   	  $f_align[2]="left";
   	  $f_align[3]="left";
   	  $f_align[4]="right";
   	  $f_align[5]="left";
   	  $f_align[6]="left";
   	  $f_align[7]="right";
   	  $f_align[8]="right";
	  $f_align[9]="right";
	  $f_align[10]="center";
	  
	 	//--------------Header Labels------------------------
		echo "<div class='view_list_title_row' style='margin-top:20px;'>";
     	
     		
     			echo "<div class='view_list_title_content'>";
				
					$f=1;
				
     				echo "<div style='min-width:20px;' class='view_list_title_row_count'  >";
     					echo "#";
     				echo "</div>";
     				
     				
					foreach($f_label as $key_f=>$value_f)
					{
						echo "<div style='width:".$f_width[$key_f]."px;text-align:".$f_align[$f]."' class='view_list_title_content_object'  >";
								echo "".$f_label[$key_f]."<br>";
						echo "</div>";
						$f++;
						
					}
					
					
     					
     			echo "</div>";
     	echo "</div>";
		
		
		
		
		
		
		
		
		$row_counter=1;
		foreach($_SESSION["STOCK_TRANSFER_ITEM"] as $ts=>$item_data)
		{
			echo "<div class='view_row'>";
		
				$f=1;
				echo "<div style='min-width:20px;' class='view_row_count'  >";
					echo "".$row_counter."";
				echo "</div>";
			
			
			
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo $item_data["CODE"]."<br>";
						echo $item_data["BARCODE"];
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo $item_data["NAME"];
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						if($item_data["COLOR"]!="")
						{
							echo "Color: ".$item_data["COLOR"]."<br>";
						}
						if($item_data["SIZE"]!="")
						{
							echo "Size: ".$item_data["SIZE"]."<br>";
						}
						if($item_data["PATTERN"]!="")
						{
							echo "Pattern: ".$item_data["PATTERN"]."<br>";
						}
						
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text' >";
						echo $item_data["PRICE"];
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo $item_data["QTY"];
						echo " ".$item_data["UOM"];
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						if($item_data["GST_CODE"]!="")
						{
							echo $item_data["GST_CODE"]." ";
							echo "(".$item_data["GST_PERCENTAGE"]."%)<br>";
							echo "<i>".$item_data["GST_MODE"]."</i>";
						}
						
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($item_data["BEFORE_GST"],2,".",",");
					echo "</font><br>";
				echo "</div>";
				
				$sum_before_gst = $sum_before_gst + $item_data["BEFORE_GST"];
				$f++;
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($item_data["GST_AMOUNT"],2,".",",");
					echo "</font><br>";
				echo "</div>";
				
				$sum_gst = $sum_gst + $item_data["GST_AMOUNT"];
				$f++;
				
				
				echo "<div style='width:".$f_width[$f]."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						echo number_format($item_data["TOTAL_AMOUNT"],2,".",",");
					echo "</font><br>";
				echo "</div>";
				
				$sum_after_gst = $sum_after_gst + $item_data["TOTAL_AMOUNT"];
				$f++;
				
				
				
				echo "<div style='width:".($f_width[$f]+20)."px;text-align:".$f_align[$f].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$f_label[$f]."</font>";
					echo "<font class='view_row_content_text'>";
						
						
					
					
						//remove button
						echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;' onclick=\"document.".$this_form_name.".ui_action.value='REMOVE_ITEM';
																						document.".$this_form_name.".remove_item_ts.value='".$ts."';
																						
																						mon_submit_form('".$this_form_name."','".$this_url."')\" >";
							echo "<i class='fa fa-square fa-stack-2x color_red'   ></i><i class='fa fa-times fa-stack-1x color_white' ></i>";
						echo "</div>";
						
						
						
						//edit button
						echo "<div class='fa-stack fa-lg'  style='cursor:pointer;float:right;' onclick=\"document.".$this_form_name.".ui_action.value='EDIT_ITEM';
																						document.".$this_form_name.".edit_item_ts.value='".$ts."';
																						
																						mon_submit_form('".$this_form_name."','".$this_url."')\" >";
							echo "<i class='fa fa-square fa-stack-2x color_grey'   ></i><i class='fa fa-pencil fa-stack-1x color_white' ></i>";
						echo "</div>";
						
						
					echo "</font><br>";
				echo "</div>";
				$f++;
				
				$row_counter++;
				
				
			echo "</div>";
		}
			
		
		
		
		//--------------footer total------------------------
		
		echo "<div class='view_list_title_row' style='margin-top:20px;'>";
		
			
				echo "<div class='view_list_title_content'>";
					$f=1;
					echo "<div style='min-width:20px;' class='view_list_title_row_count'  >";
						echo "";
					echo "</div>";
					
					foreach($f_label as $key_f=>$value_f)
					{
						echo "<div style='width:".$f_width[$key_f]."px;text-align:".$f_align[$f]."' class='view_list_title_content_object'  >";		
							if($key_f==6)	
							{
								echo "<b>Total</b>";
							}
							if($key_f==7)	
							{
								echo "<b>".number_format($sum_before_gst,2,".",",")."</b>";
							}
							if($key_f==8)	
							{
								echo "<b>".number_format($sum_gst,2,".",",")."</b>";
							}
							
							if($key_f==9)	
							{
								echo "<b>".number_format($sum_after_gst,2,".",",")."</b>";
							}	
							echo "<br>";
						echo "</div>";
						$f++;
					}	
				echo "</div>";
		echo "</div>";
		
		
		
		
	
	echo "</div>";
echo "</form>";
echo "</div>";


?>


<?php include "../../includes/end_ajax.php";?>