<?php



$query_user = "select * from t_".$key_table_prefix."_user ";
$result_user = mysqli_query($dbconn,$query_user);
while($line_user = mysqli_fetch_array($result_user,MYSQLI_ASSOC))
{

    $user_text[$line_user["usr_id"]]=$line_user["usr_full_name"];
    
}


echo "<font class='rpt_title'>Return Transaction Report</font><br>";
echo "<font class='rpt_criteria'>Date: ".$_REQUEST["start"]." ~ ".$_REQUEST["end"]."</font><br>";


echo "<table border='".$table_border."' class='rpt_table' cellspacing=1 >";




$query_get = "select * from t_".$key_table_prefix."_export_setting_return 
		where exp_status = 'YES'
		order by exp_sorting ";
$result_get = mysqli_query($dbconn,$query_get);

  
while($line_get = mysqli_fetch_array($result_get,MYSQLI_ASSOC))
{
    
    $header_col[$line_get["exp_field"]] = $line_get["exp_field"];
    $header_col_name[$line_get["exp_field"]]=$line_get["exp_name"];
  
}


    
    echo "<tr>";
        
	   foreach($header_col as $col_key=>$col_value )
	   {
		   	echo "<td class='rpt_header'>".$header_col_name[$col_key]."</td>";
	   }        
    echo "</tr>";
    
    
    $query="select * 
                from t_".$key_table_prefix."_return_header h, t_".$key_table_prefix."_return_item i
                where i.rti_doc_no  = h.rth_doc_no
			 and i.device_id  = h.device_id
                and h.rth_status='POSTED'
                and i.rti_status='POSTED'
                and h.rth_date >= '".$_REQUEST["start"]."'
                and h.rth_date <= '".$_REQUEST["end"]."' ";
    $result = mysqli_query($dbconn,$query);
    
    
    while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
    {
        echo "<tr>";
	   
	   	foreach($header_col as $col_key=>$col_value )
		{
			echo "<td class='rpt_box'>".$line[$col_key]."</td>";
		}      
		  
        
            
            
        echo "</tr>";
        
        /*
        $sum_qty=$sum_qty+$line["sai_quantity"];
        $sum_cost=$sum_cost+ number_format($line["sai_unit_cost"]*$line["sai_quantity"],2,".","");
        $sum_amount=$sum_amount+$line["sai_amount"];
        $sum_addon=$sum_addon+$line["sai_addon_amount"];
        
        $sum_gst_amount=$sum_gst_amount+$line["sai_gst_amount"];
        $sum_total_amount=$sum_total_amount+$line["sai_total_amount"];
        
        $sum_base_qty=$sum_base_qty+$line["sai_base_quantity"];
        */
        
    }
    
    /*
     echo "<tr>";
        echo "<td class='rpt_footer' colspan=6 align=right ><b>Total</b></td>";
        
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_qty,2,".",",")."</b></td>";
        echo "<td class='rpt_footer'><br></td>";
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_amount,2,".",",")."</b></td>";
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_addon,2,".",",")."</b></td>";
        echo "<td class='rpt_footer' colspan=2><br></td>";
        
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_gst_amount,2,".",",")."</b></td>";
        
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_total_amount,2,".",",")."</b></td>";
        echo "<td class='rpt_footer' colspan=3><br></td>";
        
        echo "<td class='rpt_footer' align=right ><b>".number_format($sum_base_qty,2,".",",")."</b></td>";
        echo "<td class='rpt_footer'><br></td>";
    echo "</tr>";
    */
    
echo "</table>";




?>