<?php
	ob_start();


$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
	
	$salesid =  $_REQUEST['str'];
		
	//echo "select * from cf_sales join cf_sales_sub on cf_sales.sales_id = cf_sales_sub.sale_id where cf_sales.sales_id = '$salesid'";
	
	?>
    <table width="100%" border="0" cellspacing="2" cellpadding="0">
    <tr>
    	 <td width="20%" align="left" valign="top" class="display-border-1"><strong>Serial No</strong></td>
          <?php  
           
			$sq_arr=mysql_query("select * from 	cf_sales  where sales_id = '$salesid' ");
			$rw = mysql_fetch_array($sq_arr);
			if($rw['sales_type'] == 'box')
			{		 
		  ?>            
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Brand</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Liter</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Kg (Litre) </strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Box Qty </strong></td>
            <td width="5%" align="left" valign="top" class="display-border-1"><strong>Rates</strong></td>
            <td width="7%" align="left" valign="top" class="display-border-1"><strong>Damage Return</strong></td>
            <td width="8%" align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <td width="6%" align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <?php }
			if($rw['sales_type'] == 'tin')
			{		
			?>            
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>No Of Tins</strong></td>
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>Rate</strong></td>
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>Damage Return</strong></td>
            <td width="" align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <td width="" align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <?php }
			if($rw['sales_type'] == 'kg')
			{		
			?>            
            <td width="20%" align="left" valign="top" class="display-border-1"><strong>Qty</strong></td>
            <td width="20%" align="left" valign="top" class="display-border-1"><strong>Rate</strong></td>
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <td width="" align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <?php } 
			if($rw['sales_type'] == 'jar')
			{		
			?>            
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>No Of Jars</strong></td>
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>Rate</strong></td>
            <td width="10%" align="left" valign="top" class="display-border-1"><strong>Damage Return</strong></td>
            <td width="" align="left" valign="top" class="display-border-1"><strong>Total</strong></td>
            <td width="" align="left" valign="top" class="display-border-1"><strong>Date</strong></td>
            <?php } ?>
			
            
            
            
    
      </tr>
    
    	<?php  
		  if($rw['sales_type']== 'box')
		  {
          $resulbox= mysql_query("select *,(select kgqty from cf_liter_qty where cf_liter_qty.literids = `cf_sales_sub`.`liter_id` and cf_liter_qty.brandid =  `cf_sales_sub`.`branch_id`) as kgqty ,(select liter_qty from cf_liter where cf_liter.liter_id = `cf_sales_sub`.`liter_id`) as litreqty from 	cf_sales_sub join cf_brand on cf_sales_sub.branch_id = cf_brand.brand_id  where cf_sales_sub.sale_id = '$salesid'");
		  $i=1;
		  while($res_box = mysql_fetch_array($resulbox))
		  {
		  ?>		  
		  <tr>
            <td align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['brand_name'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['litreqty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['kgqty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_box'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_rate'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_damage_qty'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_box['sale_date']));?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_box['sale_line_tot'];?></td>
          </tr>
          <?php $i++;} }
		  if($rw['sales_type']== 'tin')
			{
				$resultin = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$salesid' ");
				 $i=1;
				 while($res_tin = mysql_fetch_array($resultin))
				 {			
		   ?>
           <tr>
         	<td align="left" width="20%" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_tin['sale_no_tin_kg'];?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_tin['sale_rate'];?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_tin['sale_damage_qty'];?></td>
            <td align="left" width="" valign="top" class="display-border-1"><?php echo $res_tin['sale_line_tot'];?></td>            
            <td align="left"  width="" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_tin['sale_date']));?></td>          
          <tr>
          <?php $i++;} }
		  if($rw['sales_type']== 'jar')
			{
				$resuljar = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$salesid' ");
				 $i=1;
				 
				 while($res_jar = mysql_fetch_array($resuljar))
				 {
				 //echo "<pre>";	
				 //print_r($res_jar);
				// exit;		
		   ?>
           <tr>
         	<td align="left" width="20%" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_jar['sale_no_tin_kg'];?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_jar['sale_rate'];?></td>
            <td align="left" width="20%" valign="top" class="display-border-1"><?php echo $res_jar['sale_damage_qty'];?></td>
            <td align="left" width="" valign="top" class="display-border-1"><?php echo $res_jar['sale_line_tot'];?></td>            
            <td align="left"  width="" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_jar['sale_date']));?></td>          
          <tr>
          <?php $i++;} }
		   if($rw['sales_type']== 'kg')
			{
				$resultkg = mysql_query("select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$salesid' ");
				 $i=1;
				 while($res_kg = mysql_fetch_array($resultkg))
				 {			
		   ?>
           <tr>
         	<td align="left" valign="top" class="display-border-1"><?=$i?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_no_tin_kg'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_rate'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo $res_kg['sale_line_tot'];?></td>
            <td align="left" valign="top" class="display-border-1"><?php echo date(('d-m-Y'),strtotime($res_kg['sale_date']));?></td>          
          <tr>
          <?php $i++;} }
		  ?>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
          </tr>
          <tr>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
            <td align="left" valign="top" class="display-border-1">&nbsp;</td>
          </tr>
          
          <tr>
         
        <td colspan="19" align="right" valign="top" class="trip-font-3">
         <input type="hidden" name="grd_tot" value="<?=$rw['sales_tot']?>" class="input1">
        Grand Total : <strong><?=$rw['sales_tot']?></strong> </td>
        </tr>
        </table>
            
 	
	
 