
<?php
	ob_start();




$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
	$ids = $_REQUEST['val'];	
	$_REQUEST['chk'];
	/*$ids =  $_REQUEST['val'];
 	$sq_arr=mysql_query("select * from cf_vehicle where id = '".$ids."' ");
	$row = mysql_fetch_array($sq_arr);
	*/
	
 ?>
<div class="viewEmployeeWrap" style="min-width:750px;" >
    <div class="viewEmployee">
  
    <h6 class="h6">Sales Details <?=$_REQUEST['chk']?></h6>
     <form name="dmgfrm" method="post" action="" >
      <table  border="0" cellspacing="0" cellpadding="0" class="tableList"  style="margin-left:20px;width:750px; ">
  <tr class="heading">
    <td width="55">No</td>    
    <?php 
    if($_REQUEST['chk'] == 'box')
	{?>
    <td width="86">Brand</td>
    <td width="40">Liter</td>  
    <td width="52">Kg (Liter)</td>    
    <td width="67">Box Quantity</td> 
    <?php } ?>
    
    <?php 
    if($_REQUEST['chk'] == 'tin')
	{?>
	<td width="45">Product</td>
    <td width="45">No of Tins</td>
    <?php } ?>
	
	<?php 
    if($_REQUEST['chk'] == 'jar')
	{?>
	<td width="45">Product</td>
    <td width="45">No of Jars</td>
    <?php } ?>
    
    <?php 
    if($_REQUEST['chk'] == 'kg')
	{?>
	<td width="45">Product</td>
    <td width="53">Quantity</td>
    <?php } ?>
    <td width="39">Rate</td>
    <?php 
    if($_REQUEST['chk'] != 'kg')
	{?>
    <td width="75">Damage Return</td>
    <td width="75">Damages</td>
    <?php } ?>
	<?php 
    if($_REQUEST['chk'] == 'tin')
	{?>
    <td width="45">Rate of Tins</td>
    <?php } ?>
	
	<?php 
    if($_REQUEST['chk'] == 'jar')
	{?>
    <td width="45">Rate of Jars</td>
    <?php } ?>
	
     <?php 
    if($_REQUEST['chk'] == 'box')
	{?>
	
    
    <?php } ?>
    <td width="36">Total</td>
    <td width="58">Date</td>
  </tr>
  
<?php
$master = '';
$notification = '';
$trip = '';
$accounting = '';
$accpay = '';
$report = '';

$i=1;
if($_REQUEST['chk'] == 'box')
{
	$sq_arr="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 = '$ids' ";
}
if($_REQUEST['chk'] == 'tin' || $_REQUEST['chk'] == 'kg' || $_REQUEST['chk'] == 'jar' )
{
	$sq_arr="select * from 	cf_sales_sub  where cf_sales_sub.sale_id = '$ids' ";
}

$sq_arr.=" order by cf_sales_sub.sale_sub_id desc ";
$query=$sq_arr;
//echo $query;
$function="Searchdate";
include("pagingserch.php");
$sq_arr.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=1;
}

$array=mysql_query($sq_arr);
if($array && mysql_num_rows($array)>0){
$pagecnt=$start;
$j=1;
while($res=mysql_fetch_array($array))
{
$pagecnt++;
  ?> 
  <tr>
    <td><?php echo $pagecnt;?></td>
    <?php 
    if($_REQUEST['chk'] == 'box')
	{
	?>
    <td><?php echo $res['brand_name'];?><input type="hidden" name="brand_id<?=$j?>" id="brand_id<?=$j?>" class="input1" value="<?=$res['branch_id'];?>" /></td>
    <td><?php echo $res['litreqty'];?><input type="hidden" name="liter_id<?=$j?>" id="liter_id<?=$j?>" class="input1" value="<?=$res['liter_id'];?>" /></td> 
    <td><?php echo $res['kgqty'];?></td> 
    <td><?php echo $res['sale_box'];?></td>
    <td><?php echo $res['sale_rate'];?></td>
    
    <?php } ?>
    
    <?php 
    if($_REQUEST['chk'] == 'tin' || $_REQUEST['chk'] == 'kg' || $_REQUEST['chk'] == 'jar')
	{
		$prdid = $res['prd_id'];
		$sq_product=mysql_query("select * from cf_open_oil where open_stock_id = '$prdid'");
	$resprd=mysql_fetch_array($sq_product);
	?>
	<td><?php echo $resprd['item_name'];?></td>
    <td><?php echo $res['sale_no_tin_kg'];?></td> 
    <td><?php echo $res['sale_rate'];?></td> 
    
    
    <?php } ?>
    
    <?php 
    if($_REQUEST['chk'] != 'kg')
	{?>
    	<td><?php echo $res['sale_damage_qty'];?></td>
		<td><input type="text" name="damages<?=$j?>" id="damages<?=$j?>" class="input1" value="<?=$res['sale_damages'];?>" /></td>
		<input type="hidden" name="sub_id<?=$j?>" id="sub_id<?=$j?>" class="input1" value="<?=$res['sale_sub_id'];?>" />
    <?php } ?>
	
	<?php 
    if($_REQUEST['chk'] == 'tin' || $_REQUEST['chk'] == 'jar')
	{
	?>
    <td><?php echo $res['sale_pertin_rs'];?></td> 
    <?php } ?>
    
    
    <td><?php echo $res['sale_line_tot'];?></td>
    
    <td><?php echo date(('d-m-Y'),strtotime($res['sale_date']));?></td>     
        
    
  </tr>
  <?php 
    $j++;
	}}else{?>
	 <tr>
    <td class="errorMessage"  style="border-right:0px;border-bottom:0px; "><font color="#FF0000">No Records Found</font></td></tr>
	<? }
  ?>
    <?php 
    if($_REQUEST['chk'] == 'box')
	{?>
  <tr><td colspan="10"><input type="hidden" name="dmgcnt" id="dmgcnt" value="<?=$j?>" /><input type="submit" name="damagesretrn" id="damagesretrn" value="Save" class="input1" style="float:right;margin-right:50px;" /></td></tr>
  
  <?php
  
  }
  ?>
  <?php 
    if($_REQUEST['chk'] == 'tin' || $_REQUEST['chk'] == 'jar')
	{?>
  <tr><td colspan="10"><input type="hidden" name="dmgcnt" id="dmgcnt" value="<?=$j?>" /><input type="submit" name="damagesretrntin" id="damagesretrntin" value="Save" class="input1" style="float:right;margin-right:50px;" /></td></tr>
  
  <?php
  
  }
  ?>
</table>
  </form>   
    
    
    
    <?php /*?> <div><p style="float:right;"><a href="vechicle-details-entry.php?id=<?php echo $row['id']; ?>" style="background-color:#0099FF; text-align:center; padding:3px 10px; color:#FFFFFF; border-radius:3px;">Edit</a></p></div><?php */?>
    
     
    </div>
     
     </div>