<link href="../../css/pop_up style.css" rel="stylesheet">
<script src="../../js/local_delivery_conform_ajax.js" type="text/javascript"></script>
<style>
.style1 {border-bottom: solid 1px;border-bottom-color: #CCCCCC;}
.style21 {border-top: solid 1px;border-top-color: #CCCCCC;}
.style5 {border-left: solid 1px;border-left-color: #CCCCCC;}
.style3{ border-right: solid 1px;border-right-color: #CCCCCC; }
.text{ font-family: Verdana; font-size:13px;font-weight:500px;}
.txt{ font-family: Verdana; font-size:14px;}
</style>

<div style="height:200px; width:98%;padding-left:0px;  overflow-x:hidden;overflow-y:scroll;white-space:nowrap;" class="style3 style5 style1">
<table width="100%" height="43" border="0" cellpadding="0" cellspacing="0" >
  <tr  bgcolor="#f7f7f7" >
    <td width="43" height="22" align="center" class="style5 style3 style1 txt style21">#</td>
    <td width="139" align="left"  class=" style3 style1 txt style21">&nbsp;Date</td>
    <td width="163" align="left"  class=" style3 style1 txt style21">&nbsp;Booking No</td>
    <td width="191" align="left"  class=" style3 style1 txt style21">&nbsp;Consignor M/s</td>
    <td width="208" align="left"  class=" style3 style1 txt style21">&nbsp;Consignee M/s</td>
    <td width="221" align="left"  class=" style3 style1 txt style21">&nbsp;Place</td>
    <td width="89" align="center"  class=" style3 style1 txt style21">Count</td>
    <td width="122" align="center"  class=" style3 style1 txt style21">Paid / To Pay&nbsp;</td>
    <td width="110" align="right" class=" style3 style1 txt style21">Amount&nbsp;</td>
 </tr>
   <?php
  include("../../include/db.php");
  
   function get_checked($id,$loading_no)
		{
	        $sql="select * from delivery_conform_sublist where insert_id='$id' and loading_no='$loading_no'  ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
		  	return $rscount;
		} 
		
   function get_branchname($branch_name)
		{
		 	$sql="select branch_name from branch_creation where branch_id='$branch_name' and delete_status!='1' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$branch_name=$rsdata->branch_name;
		    }
		  	return $branch_name;
		} 
		
  $loading_date=$_POST['loading_date'];
  $loading_no=$_POST['loading_no']; 

  $loading_dates=$_GET['loading_date'];
  $loading_nos=$_GET['loading_no']; 
  
  $hidden_checkbox=$_GET['hidden_checkbox']; 
  $hidden_checkbox_explode=explode("@",$hidden_checkbox);
  $hidden_checkbox_explodes=explode(",",$hidden_checkbox_explode[0]);
  
  
        if($edit_id!='') 
			{
		  $delivery_number=$_GET['delivery_no'];

			} 
		else
		   {
		$delivery_number=$_POST['delivery_no']; 
           } 
		   
		   
		    if($edit_id!='') 
			{
		    $loading_numbers=$_GET['loading_no']; 
			} 
		   else
		   {
		   $loading_numbers=$_POST['loading_no']; 
           } 
		   
		   
		    if($edit_id!='') 
			{
		 	$hiddenbox=$_GET['hidden_checkbox']; 
			} 
		  else
		   {
		    $hiddenbox=$_POST['hidden_checkbox']; 
           } 
        function get_unloadplace($place)
		{
		 	$sql="select location from place_creation where id='$place' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$location=$rsdata->location;
		    }
		  	return $location;
		} 
		
		function get_item_counts($booking_no)
		{
		 	$sql="select sum(weight_kg) as weight_kg from booking_sub_list where book_no='$booking_no' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$weight_kg=$rsdata->weight_kg;
		    }
		  	return $weight_kg;
		} 	
			function get_paid_total($booking_no)
		{
		 	$sql="select sum(tot_amt) as tot_amt from booking_main_list where pay_type='Paid' and booking_no='$booking_no'";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$tot_amt=$rsdata->tot_amt;
		    }
		  	return $tot_amt;
		} 
		function get_pay_total($booking_no)
		{
		 	$sql="select sum(tot_amt) as tot_amt from booking_main_list where pay_type='To Pay' and booking_no='$booking_no'";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$tot_amt=$rsdata->tot_amt;
		    }
		  	return $tot_amt;
		} 
if(($_GET['edit_id']!='')&&($_POST['delivery_no']==''))
 {
 $sql="select * from  transport_delivery_sublist where (date='$loading_date' or date='$loading_dates') and (loading_no='$loading_no' or loading_no='$loading_nos') and loading_status='1' and delivery_no='$_GET[delivery_no]'";	
 }
else if(($_POST['delivery_no']!=''))
 {
  $sql="select * from  transport_delivery_sublist where (date='$loading_date' or date='$loading_dates') and (loading_no='$loading_no' or loading_no='$loading_nos')  and ((delivery_no='') or (delivery_no='$_POST[delivery_no]')) ";	
 }
 else
{
  $sql="select * from  transport_delivery_sublist where (date='$loading_date' or date='$loading_dates') and (loading_no='$loading_no' or loading_no='$loading_nos')  and loading_status!='1' ";	
 } 
 	
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
                 $id=$rsdata['id'];
				 $date=$rsdata['date'];
				 $check_id=get_checked($id,$loading_numbers);
                 $branch_name=$rsdata['branch_name'];
				 $branch=get_branchname($branch_name);
                 $from_party=$rsdata['from_party'];
                 $from_party_name=$rsdata['from_party_name'];
				 $to_party_name=$rsdata['to_party_name'];
				 $to_party=$rsdata['to_party'];
				 $amount=$rsdata['amount'];
                 $paid_to_pay=$rsdata['paid_to_pay'];
				 $booking_no=$rsdata['booking_no'];
				 $loading_nos=$rsdata['loading_no'];
				 $place=$rsdata['place'];
				 $unload_place1=get_unloadplace($place);
				 $count=get_item_counts($booking_no);
				 $paid_total=get_paid_total($booking_no);
				 $pay_total=get_pay_total($booking_no);

			
  ?>
<tr>
<td height="21"  align="center" class="txt style1 style3 style5 "><input type="checkbox" tabindex="6" class="text_field" name="unload_checked<?php echo $id."@".$loading_nos;?>" id="unload_checked<?php echo $id."@".$loading_nos;?>"  onclick="get_checkbox_values('<?php echo $loading_nos; ?>')" value="<?php echo $id;?>"  <?php if($check_id!='0') {?> checked <?php } ?>/></td>
   <td  width="139" align="left" class="txt style1 style3 ">&nbsp;<?php echo date('d-m-Y',strtotime($date)); ?></td>
   <td  width="163" align="left" class="txt style1 style3 ">&nbsp;<?php echo $booking_no; ?></td>
   <td  width="191" align="left" class="txt style1 style3 ">&nbsp;<?php echo $from_party_name; ?></td>
   <td  width="208" align="left" class="txt style1 style3 ">&nbsp;<?php echo $to_party_name; ?></td>
   <td  width="221" align="left" class="txt style1 style3 ">&nbsp;<?php echo $unload_place1; ?></td>
   <td  width="89" align="center" class="txt style1 style3 "><?php echo $count; ?>&nbsp;</td>
   <td  width="122" align="center" class="txt style1 style3 "><?php echo $paid_to_pay; ?></td>
   <td colspan="2" align="right" class="txt style1 style3 "><?php echo $amount; ?>&nbsp;</td>
  </tr>
<?php 
$paidtotal+=$paid_total;
$paytotal+=$pay_total;
} ?><input type="hidden" id="hidden_checkbox" name="hidden_checkbox" value="<?php  echo $hiddenbox; ?>"/>
</table>
</div>
<table width="1308">
<tr>
          <td width="787"  align="right" class="style7 txt"><strong><span style="color:#993300">PAID TOTAL : </span><span style="color:#006600"><?php echo number_format($paidtotal,2); ?></span>
          </strong></td>
    <td width="509" colspan="3"  align="center" class="style20 style7 txt"><strong><span style="color:#993300">TO PAY TOTAL : </span><span style="color:#006600"><?php echo number_format($paytotal,2); ?></span></strong></td>
  </tr>
</table>
