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

<?php


echo "<section class='view_toolbar'>";
               echo "<div class='view_toolbar_left' style='width:50%;'>";
					echo "<span class='fa fa-file-text-o'></span> Stock Transaction";
               echo "</div>";
               echo "<div class='view_toolbar_right'>";	

               echo "</div>";
echo "</section>";



//------------------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]."' ";

if($_REQUEST["sth_doc_no"]!="")
{
	$query_display=$query_display." OR sth_doc_no = '".$_REQUEST["sth_doc_no"]."' ;";	
}



$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))
{
	  	
	for($i=1;$i<=count($form_field);$i++)
	{
		
	
	
		if($form_field_separator[$i]!="")
		{
			echo "<div class='data_display_separator' >";
			echo "<font size=3><b>".$form_field_separator[$i]."</b></font>";
			echo "</div>";
		}

		
		
		
		
		echo "<div class='data_display_row'>";
		
			
			echo "<div class='data_display_label'>";
				echo $form_field_label[$i];
			echo "</div>";
		
			echo "<div class='data_display_value'>";
		
				if($form_field_type[$i]=="TEXT")
				{
					echo $line_display[$form_field[$i]]."";
				}
			
				if($form_field_type[$i]=="QUANTITY")
				{
					echo $line_display[$form_field[$i]]."";
				}
			
				if($form_field_type[$i]=="PRICE")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="TIME")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE_START")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="DATE_END")
				{
					echo $line_display[$form_field[$i]]."";
				}
				
				if($form_field_type[$i]=="PASSWORD")
				{
					echo "******";
				}
					
				if($form_field_type[$i]=="TEXTAREA")
				{
					echo str_replace(chr(10),"<br>",$line_display[$form_field[$i]])."";
				}
				
				if($form_field_type[$i]=="DROPDOWN")
				{
				
					if($form_field_dropdown_option[$i]=="KEYWORD")
					{
					 
						echo "".$mon_keyword_list[$form_field_dropdown_option_values[$i]][$line_display[$form_field[$i]]]."";
					 
					
						
					}
					if($form_field_dropdown_option[$i]=="SQL")
					{
					 
						$query_select=$form_field_dropdown_option_values[$i];
						$query_select=$query_select." where ".$form_field_dropdown_option_values_key[$i]."='".$line_display[$form_field[$i]]."';";
						$result_select=mysqli_query($dbconn,$query_select) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_select=mysqli_fetch_array($result_select,MYSQLI_ASSOC))
						{
							echo "".$line_select["text"].""; 
						}
														
					}
				
				
				
				
					}
					
					if($form_field_type[$i]=="FILE_PHOTO")
					{
						$query_file="select fil_id, fil_storage_method from t_".$key_table_prefix."_file 
							where fil_mod='".$form_key_id."' 
							and fil_mod_id='".$_REQUEST[$form_key_id]."'
							and fil_mod_field='".$form_field[$i]."'
							";
			
						$result_file=mysqli_query($dbconn,$query_file) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_file=mysqli_fetch_array($result_file,MYSQLI_ASSOC))
						{
							if($line_file["fil_storage_method"]=="OS")
							{
								echo "<img width=250 src='".$file_storage_folder.$line_file["fil_id"].".jpg' >";	
							}
							else
							{
								echo "<img width=250 src='mod/uploader/file.php?id=".$line_file["fil_id"]."' >";	
							}
							
						} 
					}
					
					if($form_field_type[$i]=="FILE")
					{
						$query_file="select fil_name, fil_id, fil_storage_method from t_".$key_table_prefix."_file 
										where fil_mod='".$form_key_id."' 
										and fil_mod_id='".$_REQUEST[$form_key_id]."'
										and fil_mod_field='".$form_field[$i]."'
										";
						
						$result_file=mysqli_query($dbconn,$query_file) or die("Retrieval failed- Err msg  ". mysqli_error($dbconn));
						if($line_file=mysqli_fetch_array($result_file,MYSQLI_ASSOC))
						{
							$fileName_array=explode(".",$line_file["fil_name"]);
							$ext=$fileName_array[count($fileName_array)-1];
							if($line_file["fil_storage_method"]=="OS")
							{
								echo "<a href='".$file_storage_folder.$line_file["fil_id"].".".$ext."' target=_blank >".$line_file["fil_name"]."</a>";	
							}
							else
							{
								echo "<a href='mod/fuploader/file.php?id=".$line_file["fil_id"]."' >".$line_file["fil_name"]."</a>";	
							}
						} 
					}
		
				echo "</div>"; // end value division
				
				
				
		echo "</div>"; //end row division
	 
	}
	
	
	
	
	
	//========================================================================================================================
	echo "<div class='data_display_separator' >";
	echo "<font size=3><b>Transaction Item</b></font>";
	echo "</div>";
	
		
		
	
	
	  //===Header Label =============
	  $listing_header[1]="Product Code";
	  $listing_header[2]="Barcode";
	  $listing_header[3]="Product Name";
	  $listing_header[4]="Additional Info";
	  $listing_header[5]="Price";
	  $listing_header[6]="Quantity";
	  $listing_header[7]="Before Tax";
	  $listing_header[8]="Tax";
	  $listing_header[9]="Tax Amount";
	  $listing_header[10]="Total Amount";
	  if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
	  	{
	  		$listing_header[11]="Storage Location";
  		}
	  
		  
	  //===Database Fields==========
	  $listing_content[1]="sti_stock_code";
	  $listing_content[2]="sti_barcode";
	  $listing_content[3]="sti_stock_name";
	  $listing_content[4]="additional_info";
	  $listing_content[5]="sti_unit_cost";
	  $listing_content[6]="sti_quantity";
	  $listing_content[7]="sti_before_gst_amount";
	  $listing_content[8]="gst_info";
	  $listing_content[9]="sti_gst_amount";
	  $listing_content[10]="sti_total_amount";
	  if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
	  {
	  	$listing_content[11]="sti_storage_location";
  		}
	  
	  
	  //===Column width==========
	  $listing_width[1]="80";
	  $listing_width[2]="80";
	  $listing_width[3]="120";
	  $listing_width[4]="80";
	  $listing_width[5]="60";
	  $listing_width[6]="40";
	  $listing_width[7]="40";
	  $listing_width[8]="80";
	  $listing_width[9]="40";
	  $listing_width[10]="40";
	  if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
	  {
		  $listing_width[11]="80";
	  }
	  
	  
	  
		//===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]="";
	  $listing_align[9]="right";
	  $listing_align[10]="right";
	  if($sys_system_master_setting_line["set_module_internal_inventory_management_with_stock_posting"]=="YES")
	  {
		  $listing_align[10]="left";
	  }
	  
	  
	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>";
	echo "</div>";
			
			
	//concat('Color: ',sti_color, '<br>Size: ',sti_size,'<br>Pattern: ', sti_pattern ) as additional_info
	$count=1;
	$query_ivi = "select *  ,
				concat(sti_color, ' ',sti_size,' ', sti_pattern ) as additional_info,
				concat(sti_gst_code, ' ',sti_gst_percentage,'% ', sti_gst_mode ) as gst_info
				
				from t_".$key_table_prefix."_stock_transaction_item
				where sti_doc_no ='".$line_display["sth_doc_no"]."' 
				and sti_header_id  ='".$line_display["sth_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'>";
						$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."";
						
						if($listing_content[$i]=="sti_storage_location")
						{
							if($line_ivi["sti_storage_location2"]!="")
							{
								echo " to ".$line_ivi["sti_storage_location2"];	
							}
							
						}
						
						
					echo "</font><br>";
				
				echo "</div>";
			
			}
		
		
		
		echo "</div>";
	
		$count++;
	}
		
		
						
}	
		
	
echo "</div>";
			echo "<div style='float:left;height:200px;'></div>";

?>




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