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

?>

<?php

//important================================
include "config_form.php"; //important
//important================================



$form_table_name="t_".$key_table_prefix."_invoice_header ";
$form_key_id="ivh_id";
$this_url_edit="mod/picking_list/generate_po.php";



$query_gst = "select * from t_".$key_table_prefix."_gst ";
$result_gst = mysqli_query($dbconn, $query_gst);
while($line_gst = mysqli_fetch_array($result_gst,MYSQLI_ASSOC))
{
	$gst_percentage[$line_gst["gst_code"]]=$line_gst["gst_percentage"]+0;
	
}

if ($_SERVER[REQUEST_METHOD] == 'POST') {

		
	$query_ivi = "select * 
				from t_".$key_table_prefix."_invoice_item
				where ivi_header_id ='".$_REQUEST["ivh_id"]."' 
				 ";
	$result_ivi = mysqli_query($dbconn,$query_ivi);

	while($line_ivi = mysqli_fetch_array($result_ivi,MYSQLI_ASSOC))
	{
		$this_price = $_REQUEST["ivi_price_".$line_ivi["ivi_id"]];
		$this_quantity = $_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]];
		
		$this_gst_mode = $_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]];
		$this_gst_code = $_REQUEST["ivi_gst_code_".$line_ivi["ivi_id"]];
		
		
		
		$this_gst_percentage = $gst_percentage[$this_gst_code];
		
		$this_product_amount = $this_price * $this_quantity;
		
		
		if($this_gst_percentage>0)
		{
			if($this_gst_mode=="INCLUSIVE")
			{
				
				
				$this_gst = round($this_product_amount / (100+$this_gst_percentage) * $this_gst_percentage,2);
				$this_before_gst = $this_product_amount - $this_gst;
				$this_total = $this_product_amount;
			}
			else {
				
				$this_before_gst = $this_product_amount;
				$this_gst = $this_product_amount * ($this_gst_percentage/100);
				$this_total = $this_before_gst + $this_gst;
				
				
			}	
			
		}
		else
		{
			$this_before_gst = $this_product_amount;
			$this_gst = 0;
			$this_total = $this_product_amount;
			
			
		}
		
		
		
		$display_data[$line_ivi["ivi_id"]]["GST_PERCENTAGE"] =$this_gst_percentage;
		$display_data[$line_ivi["ivi_id"]]["BEFORE_GST"] = number_format($this_before_gst,2,".",",");
		$display_data[$line_ivi["ivi_id"]]["GST"] = number_format($this_gst,2,".",",");
		$display_data[$line_ivi["ivi_id"]]["TOTAL"] = number_format($this_total,2,".",",");
		
		
		
	}
	
}







if (($_SERVER[REQUEST_METHOD] == 'POST') and ($_REQUEST["user_action"]=="SAVE")) {
$error_msg="";
$password_confirmation=false;
$password_temp="";

	
	$item_found=false;
	
	
	
	$query_ivi = "select * 
				from t_".$key_table_prefix."_invoice_item
				where ivi_header_id ='".$_REQUEST["ivh_id"]."' 
				 ";
	$result_ivi = mysqli_query($dbconn,$query_ivi);

	while($line_ivi = mysqli_fetch_array($result_ivi,MYSQLI_ASSOC))
	{
		
		if($_REQUEST["ivi_generate_po_".$line_ivi["ivi_id"]]=="YES")
		{
			if($_REQUEST["ivi_price_".$line_ivi["ivi_id"]]=="")
			{
				$error_msg=$error_msg."<li>Price is empty.</li>";	  	
			}
			else {
				if(!is_numeric($_REQUEST["ivi_price_".$line_ivi["ivi_id"]]))
				{
					$error_msg=$error_msg."<li>Price must be number value only.</li>";	  
				}
			}				
			
			
			if($_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]]=="")
			{
				$error_msg=$error_msg."<li>Quantity is empty.</li>";	  	
			}
			else {
				if(!is_numeric($_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]]))
				{
					$error_msg=$error_msg."<li>Quantity must be number value only.</li>";	  
				}
			}	
			
			
			$item_found=true;
			
			
			
			
			
			
			
			
			
			
		}
		
		
	}

	if(!$item_found)
	{
		
			$error_msg=$error_msg."<li>No item selected for PO Generation.</li>";	  
			
	}
	
	
	
	if($error_msg=="")
	{
		
		$this_doc_number_module_code="PO";
		$this_doc_prefix="PO";
		$this_module="PO";
		
		$this_doc_no="ERROR";
		$this_doc_no = mon_register_document_number($this_doc_number_module_code);
		
		//get info:
		$query_whs="select * from t_".$key_table_prefix."_warehouse 
			where whs_code  ='".$_REQUEST["warehouse_code"]."' ";
		$result_whs  = mysqli_query($dbconn,$query_whs);
		if($line_whs = mysqli_fetch_array($result_whs,MYSQLI_ASSOC))
		{
			$this_warehouse_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"];
		}
		
		
		
		$query="insert into t_".$key_table_prefix."_purchase_order_header 
				(
				poh_doc_prefix  ,
				poh_doc_no  ,
				poh_module  ,
				poh_date ,
				
				
				poh_vendor_code  ,
				poh_vendor_name  ,
				poh_reference_no  ,
				poh_remark  ,
				poh_status  ,
				poh_before_gst_amount ,
				poh_gst_amount  ,
				poh_total_amount  ,
				
				
				
				created_date  ,
				created_by  ,
				modified_date  ,
				modified_by  ,
				client_id  
				)
				values
				(
				'".$this_doc_prefix."'  ,
				'".$this_doc_no."'  ,
				'".$this_module."'  ,
				'".$_REQUEST["date"]."' ,
				
				
				
				'".$_REQUEST["vendor_code"]."' ,
				'".$this_vendor_name."'  ,
				'".$_REQUEST["refno"]."'  ,
				'".$_REQUEST["remark"]."'  ,
				'POSTED'  ,
				
				'".(0)."' ,
				'".(0)."' ,
				'".(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);
		
		
		
		
		
		$query_ivi = "select * 
					from t_".$key_table_prefix."_invoice_item
					where ivi_header_id ='".$_REQUEST["ivh_id"]."' 
					 ";
		$result_ivi = mysqli_query($dbconn,$query_ivi);
	
		while($line_ivi = mysqli_fetch_array($result_ivi,MYSQLI_ASSOC))
		{
			
			if($_REQUEST["ivi_generate_po_".$line_ivi["ivi_id"]]=="YES")
			{
				
			
			
				
					$this_price = $_REQUEST["ivi_price_".$line_ivi["ivi_id"]];
					$this_quantity = $_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]];
					
					$this_gst_mode = $_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]];
					$this_gst_code = $_REQUEST["ivi_gst_code_".$line_ivi["ivi_id"]];
					
					
					
					$this_gst_percentage = $gst_percentage[$this_gst_code];
					
					$this_product_amount = $this_price * $this_quantity;
					
					
					if($this_gst_percentage>0)
					{
						if($this_gst_mode=="INCLUSIVE")
						{
							
							
							$this_gst = round($this_product_amount / (100+$this_gst_percentage) * $this_gst_percentage,2);
							$this_before_gst = $this_product_amount - $this_gst;
							$this_total = $this_product_amount;
						}
						else {
							
							$this_before_gst = $this_product_amount;
							$this_gst = $this_product_amount * ($this_gst_percentage/100);
							$this_total = $this_before_gst + $this_gst;
							
							
						}	
						
					}
					else
					{
						$this_before_gst = $this_product_amount;
						$this_gst = 0;
						$this_total = $this_product_amount;
						
						
					}
					
					
					
					
					$query_item="insert into t_".$key_table_prefix."_purchase_order_item 
							(
								
							  poi_header_id  ,
							  poi_doc_prefix  ,
							  poi_doc_no  ,
							  poi_module  ,
							  poi_date  ,
							  poi_warehouse_code  ,
							  poi_warehouse_id  ,
							  poi_stock_code  ,
							  poi_barcode  ,
							  poi_factory_code  ,
							  poi_stock_name  ,
							  poi_color  ,
							  poi_size  ,
							  poi_pattern  ,
							  poi_uom  ,
							  poi_base_uom  ,
							  poi_quantity  ,
							  poi_base_quantity  ,
							  poi_conversion  ,
							  poi_unit_cost  ,
							  poi_base_unit_cost  ,
							  poi_total_cost  ,
							  poi_gst_mode  ,
							  poi_gst_code  ,
							  poi_gst_percentage  ,
							  poi_remark  ,
							  poi_status  ,
							  poi_before_gst_amount  ,
							  poi_gst_amount  ,
							  poi_total_amount  ,
							  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"]."' ,
							'".$this_warehouse_id."'  ,
							
							  '".$line_ivi["ivi_product_code"]."'  ,
							  '".$line_ivi["ivi_product_barcode"]."'  ,
							  ''  ,
							  '".$line_ivi["ivi_product_name"]."'  ,
							  '".$line_ivi["ivi_color"]."'  ,
							  '".$line_ivi["ivi_size"]."'  ,
							  '".$line_ivi["ivi_pattern"]."'  ,
							  '".$line_ivi["ivi_uom"]."'  ,
							  '".$line_ivi["ivi_uom"]."'  ,
							  '".($this_quantity+0)."'  ,
							  '".($this_quantity+0)."'  ,
							  '1'  ,
							  '".($this_price+0)."'  ,
							  '".($this_price+0)."'  ,
							  '".($this_product_amount+0)."'  ,
							  '".$this_gst_mode."'  ,
							  '".$this_gst_code."'  ,
							  '".($this_gst_percentage+0)."'  ,
							  ''  ,
							  'POSTED'  ,
							  '".($this_before_gst+0)."'  ,
							  '".($this_gst+0)."'  ,
							  '".($this_total+0)."'  ,
							  '".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));
					
					
					
					
					
					
					
					
					
					
					
	
			}
			
			
		}
		
		
		
	
		
		
		displaymessage("Saved","CREATED");
			
	}
	else 
	{
		displaymessage($error_msg,"FAIL");
	}
	
			
}










//------------------data display----------------------
echo "<div class='data_display_content'>";	
	
	
	
	
	
	
	
	
	
$query_display="SELECT * FROM $form_table_name ";
$query_display=$query_display." WHERE $form_key_id = '".$_REQUEST[$form_key_id]."';";
$result_display=mysqli_query($dbconn,$query_display)or die("Get Data failed- Err msg  ". mysqli_error($dbconn));
			
if($line_display=mysqli_fetch_array($result_display,MYSQLI_ASSOC))
{
	  	
			
	
	echo "<form name='po_generate_list_".$line_display["ivh_id"]."' >";
	echo "<input type=hidden name='ivh_id' value='".$line_display["ivh_id"]."'>";
	echo "<input type=hidden name='user_action' value=''>";
		
	//--------------------------------save button----------------------------------	
	//echo "<span class='fa-stack fa-lg' style='cursor:pointer;float:left;margin:10px;' onclick=\"mon_send_get('".$this_url_edit."','?ivh_id=".$_REQUEST["ivh_id"]."','div_display')\" >";
	echo "<span class='fa-stack fa-lg' style='cursor:pointer;float:left;margin:10px;' onclick=\"if(confirm('Are you sure want to generate a new PO ?')){document.po_generate_list_".$_REQUEST["ivh_id"].".user_action.value='SAVE';mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')}\" >";
		echo "<i class='fa fa-square fa-stack-2x' style='color:#1ABC9C;' ></i>";
		echo "<i class='fa fa-save fa-stack-1x'  style='color:#ffffff;'></i>";
	echo "</span>";
			
			
			
			
		$query_item="select count(ivi_id) as total 
					from t_".$key_table_prefix."_invoice_item
					where ivi_header_id = '".$line_display["ivh_id"]."' 
					and not ifnull(ivi_inventory_posting,'') = 'POSTED'
					";
		$result_item = mysqli_query($dbconn,$query_item);
		if($line_item = mysqli_fetch_array($result_item,MYSQLI_ASSOC))
		{
			if($line_item["total"]>0)
			{
				
			}
			else {
				echo "<div style='cursor:pointer;float:right;margin:10px;padding:5px;border:1px solid #BDC3C7;border-radius:5px;' >";
					echo "<span class='fa fa-cubes fa-lg'  ></span>";	
					echo " Inventory Posted";
					echo " <span class='fa fa-check fa-lg' style='color:#16A085;' ></span>";	
				echo "</div>";
				
			}
		}
		
		
	
		if($line_display["ivh_delivery_status"]=="DELIVERED")
		{
			echo "<div style='cursor:pointer;float:right;margin:10px;padding:5px;border:1px solid #BDC3C7;border-radius:5px;' >";
				echo "<span class='fa fa-truck fa-lg'  ></span>";	
				echo " Delivery Completed";
				echo " <span class='fa fa-check fa-lg' style='color:#16A085;' ></span>";	
			echo "</div>";	
		}
		
		
		
		
	
	echo "<div style='float:left;width:96%;padding:3px 2% 3px 2%;'>";
	
	
	
		//--------------Date------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' style='text-align:left;' >";
				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.po_generate_list_".$line_display["ivh_id"].".date);"."return false;\" HIDEFOCUS>";
				echo " <span class='fa fa-calendar fa-lg' style='color:#000;'></span>";
				echo "</a>"; 
				
			echo "</div>";	
		echo "</div>";	
		
	
		
		//--------------Vendor------------------------	
		echo "<div class='form_field_row' >";		
			echo "<div class='form_field_label' style='text-align:left;' >";
				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' style='text-align:left;'>";
				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' style='text-align:left;'>";
				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>";		
		
			
	echo "</div>";	

	
	
	//========================================================================================================================
	echo "<div class='data_display_separator' >";
	echo "<font size=3><b>Select Item for Purchase Order Creation</b></font>";
	echo "</div>";
	
		
		
		
		
	  //===Header Label =============
	  $listing_header[1]="Product Code";
	  $listing_header[2]="Product Name";
	  $listing_header[3]="Price";
	  $listing_header[4]="Quantity";
	  $listing_header[5]="Before GST";
	  $listing_header[6]="GST Mode";
	  $listing_header[7]="GST Code";
	  $listing_header[8]="GST %";
	  $listing_header[9]="GST Amount";
	  $listing_header[10]="Total Amount";
	  
	  
		  
	  //===Database Fields==========
	  $listing_content[1]="ivi_product_code";
	  $listing_content[2]="ivi_product_name";
	  $listing_content[3]="ivi_price";
	  $listing_content[4]="ivi_quantity";
	  $listing_content[5]="ivi_total_before_gst";
	  $listing_content[6]="ivi_gst_mode";
	  $listing_content[7]="ivi_gst_code";
	  $listing_content[8]="ivi_gst_percentage";
	  $listing_content[9]="ivi_gst_amount";
	  $listing_content[10]="ivi_total_amount";
	  
	  
	  
	  
	  //===Column width==========
	  $listing_width[1]="60";
	  $listing_width[2]="120";
	  $listing_width[3]="70";
	  $listing_width[4]="70";
	  $listing_width[5]="70";
	  $listing_width[6]="70";
	  $listing_width[7]="70";
	  $listing_width[8]="70";
	  $listing_width[9]="70";
	  $listing_width[10]="70";
	  
	  
	  
	  
	  
	  //===Column align==========
	  $listing_align[1]="left";
	  $listing_align[2]="left";
	  $listing_align[3]="left";
	  $listing_align[4]="left";
	  $listing_align[5]="right";
	  $listing_align[6]="right";
	  $listing_align[7]="right";
	  $listing_align[8]="right";
	  $listing_align[9]="right";
	  $listing_align[10]="right";
	  
	echo "<div class='view_list_title_row'>";
	
	
			echo "<div class='view_list_title_content'>";
				echo "<div style='min-width:20px;' class='view_list_title_row_count'  >";
					echo "#";
				echo "</div>";
				
				
				for($i=1;$i<=count($listing_header);$i++)
				{
					if($listing_content[$i]=="modified_date")
					{
						
					}
					else
					{
						echo "<div style='width:".$listing_width[$i]."px;' class='view_list_title_content_object'  >";
							echo "".$listing_header[$i]."<br>";
						echo "</div>";
					}
					
				}
				
				
				echo "<div style='min-width:20px;' class='view_list_title_content_object'  >";
					echo "Generate PO";
				echo "</div>";
				
			echo "</div>";
			
	echo "</div>";
			
			
			

	
	
	$count=1;
	$query_ivi = "select * 
				from t_".$key_table_prefix."_invoice_item
				where ivi_doc_no ='".$line_display["ivh_doc_no"]."' 
				and device_id  ='".$line_display["device_id"]."' ";
	$result_ivi = mysqli_query($dbconn,$query_ivi);
	
	while($line_ivi = mysqli_fetch_array($result_ivi,MYSQLI_ASSOC))
	{
		
		echo "<div class='view_row'>";
		
		
			echo "<div style='min-width:20px;' class='view_row_count'  >";
			echo "".$count."";
			echo "</div>";
		
			for($i=1;$i<=count($listing_header);$i++)
			{
				
				echo "<div style='width:".$listing_width[$i]."px;text-align:".$listing_align[$i].";' class='view_row_content_object'  >";
					echo "<font class='view_row_content_label'>".$listing_header[$i]."</font>";
				
				
					echo "<font class='view_row_content_text'>";
					
						if($listing_content[$i]=="ivi_price")
						{
							if($_REQUEST["ivi_price_".$line_ivi["ivi_id"]]=="")
							{
								//need to get last purchase price:
								$_REQUEST["ivi_price_".$line_ivi["ivi_id"]] = "0.00";
							}
							
							echo "<input type=text class='textbox textbox-s' name='ivi_price_".$line_ivi["ivi_id"]."' value='".$_REQUEST["ivi_price_".$line_ivi["ivi_id"]]."' onchange=\"mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')\" >";
						}
						elseif($listing_content[$i]=="ivi_quantity")
						{
							if($_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]]=="")
							{
								$_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]] = $line_ivi["ivi_quantity"];
							}
							
							echo "<input type=text class='textbox textbox-s' name='ivi_quantity_".$line_ivi["ivi_id"]."' value='".$_REQUEST["ivi_quantity_".$line_ivi["ivi_id"]]."' onchange=\"mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')\" >";
						}	
						elseif($listing_content[$i]=="ivi_gst_mode")
						{
							echo "<select type=text class='textbox textbox-s' name='ivi_gst_mode_".$line_ivi["ivi_id"]."' onchange=\"mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')\" >";
							//value='".$_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]]."' >";
								foreach($mon_keyword_list["key_gst_mode"] as $gst_mode_key => $gst_mode_value)
								{
									if($_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]]==$gst_mode_key)
									{
										echo "<option value='".$gst_mode_key."' selected >";	
									}
									else {
										echo "<option value='".$gst_mode_key."'>";	
											
									}
										echo $gst_mode_value;
									echo "</option>";
										
								}
							echo "</select>";
							
						}
						elseif($listing_content[$i]=="ivi_gst_code")
						{
							echo "<select type=text class='textbox textbox-s' name='ivi_gst_code_".$line_ivi["ivi_id"]."' onchange=\"mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')\" >";
							//value='".$_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]]."' >";
								
								echo "<option value='' ></option>";	
								
								$query_gst = "select * from t_".$key_table_prefix."_gst ";
								$result_gst = mysqli_query($dbconn, $query_gst);
								while($line_gst = mysqli_fetch_array($result_gst,MYSQLI_ASSOC))
								{
									if($_REQUEST["ivi_gst_code_".$line_ivi["ivi_id"]]==$line_gst["gst_code"])
									{
										echo "<option value='".$line_gst["gst_code"]."' selected >";	
									}
									else {
										echo "<option value='".$line_gst["gst_code"]."'>";	
									}
										echo $line_gst["gst_code"];
											echo " - ";
										echo $line_gst["gst_name"];
										
										
									echo "</option>";
										
								}
							echo "</select>";
							
						}
						elseif($listing_content[$i]=="ivi_total_before_gst")
						{
							
							echo $display_data[$line_ivi["ivi_id"]]["BEFORE_GST"];
							
						}
						elseif($listing_content[$i]=="ivi_gst_amount")
						{
							
							echo $display_data[$line_ivi["ivi_id"]]["GST"];
							
						}
						elseif($listing_content[$i]=="ivi_total_amount")
						{
						
							echo $display_data[$line_ivi["ivi_id"]]["TOTAL"];
							
						}
						elseif($listing_content[$i]=="ivi_gst_percentage")
						{
						
							echo $display_data[$line_ivi["ivi_id"]]["GST_PERCENTAGE"];
							
						}
						else {
							
						
							
							
							
							$this_text=$line_ivi[$listing_content[$i]];
							$this_text=str_replace(chr(10),"<br>",$this_text);
							$this_text = str_replace($search_word, "<span class='view_search_hightlight' >".$search_word."</span>", $this_text);
							echo "".$this_text."";
							
								
						}
					
					
						
						
						
					echo "</font><br>";
				
				echo "</div>";
			
			}
		
		
		
			echo "<div style='min-width:20px;' class='view_row_content_object'  >";
			
				echo "<select type=text class='textbox textbox-s' name='ivi_generate_po_".$line_ivi["ivi_id"]."' onchange=\"mon_submit_form_display('po_generate_list_".$_REQUEST["ivh_id"]."','mod/picking_list/generate_po.php')\" >";
				//value='".$_REQUEST["ivi_gst_mode_".$line_ivi["ivi_id"]]."' >";
					foreach($mon_keyword_list["key_yes_no"] as $yesno_key => $yesno_value)
					{
						if($_REQUEST["ivi_generate_po_".$line_ivi["ivi_id"]]==$yesno_key)
						{
							echo "<option value='".$yesno_key."' selected>";	
						}
						else {
							echo "<option value='".$yesno_key."'>";	
								
						}
							echo $yesno_value;
						echo "</option>";
							
					}
				echo "</select>";
			echo "</div>";
			
			
		echo "</div>";
	
		$count++;
	}
	
	
	echo "</form>";
	
	
		
		
						
}	
		
	
echo "</div>";
echo "<div style='float:left;height:200px;'></div>";





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

?>