<?php include "../../includes/start_ajax.php";?>
<?php include "config_form.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> Return 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["rth_doc_no"]!="")
{
	$query_display=$query_display." OR rth_doc_no = '".$_REQUEST["rth_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_row'>";
	
		
		echo "<div class='data_display_label'>";
			echo "Payment Mode";
		echo "</div>";
	
		echo "<div class='data_display_value'>";
		/*
			$query_ivp = "select * 
						from t_".$key_table_prefix."_invoice_payment 
						where ivp_rth_id ='".$line_display["rth_rth_id"]."' 
						and device_id  ='".$line_display["device_id"]."' ";
			$result_ivp = mysqli_query($dbconn,$query_ivp);
			while($line_ivp = mysqli_fetch_array($result_ivp,MYSQLI_ASSOC))
			{
				echo "<b>".$line_ivp["ivp_payment_code"]."</b> ";
				echo $line_ivp["ivp_payment_name"];
				
				echo ": ".number_format($line_ivp["ivp_amount"]-$line_ivp["ivp_change"],2,".",",");
				
				echo "<br>";
			
			}
			*/
		
		
		
		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]="Serial No.";
	  $listing_header[5]="Remark";
	  $listing_header[6]="Price";
	  $listing_header[7]="Quantity";
	  $listing_header[8]="Addon Amount";
	  $listing_header[9]="Discount";
	  $listing_header[10]="Before Tax";
	  $listing_header[11]="Tax Mode";
	  $listing_header[12]="Tax Code";
	  $listing_header[13]="Tax %";
	  $listing_header[14]="Tax Amount";
	  $listing_header[15]="Total Amount";
	  
	  
		  
	  //===Database Fields==========
	  $listing_content[1]="rti_product_code";
	  $listing_content[2]="rti_product_barcode";
	  $listing_content[3]="rti_product_name";
	  $listing_content[4]="rti_serial_no";
	  $listing_content[5]="rti_remark";
	  $listing_content[6]="rti_price";
	  $listing_content[7]="rti_quantity";
	  $listing_content[8]="rti_total_addon";
	  $listing_content[9]="rti_discount_total";
	  $listing_content[10]="rti_total_before_gst";
	  $listing_content[11]="rti_gst_mode";
	  $listing_content[12]="rti_gst_code";
	  $listing_content[13]="rti_gst_percentage";
	  $listing_content[14]="rti_gst_amount";
	  $listing_content[15]="rti_total_amount";
	  
	  
	  
	  
	  //===Column width==========
	  $listing_width[1]="60";
	  $listing_width[2]="60";
	  $listing_width[3]="120";
	  $listing_width[4]="60";
	  $listing_width[5]="60";
	  $listing_width[6]="40";
	  $listing_width[7]="40";
	  $listing_width[8]="40";
	  $listing_width[9]="40";
	  $listing_width[10]="40";
	  $listing_width[11]="40";
	  $listing_width[12]="40";
	  $listing_width[13]="40";
	  $listing_width[14]="40";
	  $listing_width[15]="40";
	  
	  
	  
	  
		//===Column align==========
	  $listing_align[1]="left";
	  $listing_align[2]="left";
	  $listing_align[3]="left";
	  $listing_align[4]="left";
	  $listing_align[5]="left";
	  $listing_align[6]="right";
	  $listing_align[7]="right";
	  $listing_align[8]="right";
	  $listing_align[9]="right";
	  $listing_align[10]="right";
	  $listing_align[11]="left";
	  $listing_align[12]="left";
	  $listing_align[13]="right";
	  $listing_align[14]="right";
	  $listing_align[15]="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>";
	echo "</div>";
			
			
	
	$count=1;
	$query_ivi = "select * 
				from t_".$key_table_prefix."_return_item
				where rti_doc_no ='".$line_display["rth_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'>";
						$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>";
	
		$count++;
	}
		
		
						
}	
		
	
echo "</div>";
			echo "<div style='float:left;height:200px;'></div>";

?>




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