<link rel="stylesheet" href="css/font.css" type="text/css" />

<script>function local_cnfrm_print(url)
{
onmouseover43= window.open(url,'onmouseover43','height=580,width=1100,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}</script>
<?php error_reporting(0);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");
ob_start();
session_start();

function get_user_typess1($login_user_name,$login_pass_word)
{
    $sql_user="select * from  user_creation where user_name='$login_user_name' and password='$login_pass_word'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$user_type=$rsdata_user->user_type;
	}
	return $user_type;
}

$login_user_name=$_SESSION['login_user_name'];
$login_pass_word=$_SESSION['login_pass_word'];
$book_branch=$_SESSION['branch'];
$get_user_type=get_user_typess1($login_user_name,$login_pass_word);


$show = 20;
$num_links = 19;
$from = $_GET['from'];
if (empty($from))
	 {
		$from = "0";
	 } 
else 
	{
	$html_query = $html_query. "&from=$from";
	}
	
	$branch_name=$_POST['branch_name'];
$from_date=$_POST['from_date'];
$to_date=$_POST['to_date'];
$current_date=date('Y-m-d');


if($branch_name!=""){ $branch_name1= "branch='$branch_name'"; }else{$branch_name1=''; }
if($from_date!=""){ $from_date1= "loading_date>='$from_date'"; }else{$from_date1="loading_date='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "loading_date<='$to_date'";}else{$to_date1="loading_date='$cur_dates'";}

$all_value10 = $branch_name1.",".$from_date1.",".$to_date1;
$all_array10 = explode(',',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query104 .= $value10." AND ";
}
}	  
	
if($get_user_type=='1')
{
	if(($from_date=='')&&($to_date==''))
  {
  $sql="select * from  delivery_conform where  loading_date='$current_date' order by loading_no ASC LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  delivery_conform where $get_query104 id!='' order by loading_no ASC LIMIT $from,20";
  }
}
else
{
	if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  delivery_conform where  loading_date='$current_date' and branch='$book_branch' order by loading_no ASC LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  delivery_conform where $get_query104 id!='' and branch='$book_branch' order by loading_no ASC LIMIT $from,20";
  }
}	$html_query = "main_fram.php?file=local_delivery_conform";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if ($num_results == 0) 
{
 $confirmation = "No Records!";
} 
elseif ($num_results == 1) 
{
$confirmation = "Found 1 Record.";
} 
else 
{
$confirmation = "Found $num_results Records.";
} 
?>
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
<table width="100%">
   <tr>
<td width="1%" height="38">&nbsp;</td>
<td width="7%" class="style15">&nbsp;</td> 
<td width="13%" align="center">&nbsp;</td>
<td width="1%">&nbsp;</td>
<td width="6%" class="style15">&nbsp;</td>
<td width="14%" align="center"  class="style15">&nbsp;</td>
<td width="2%">&nbsp;</td>
<td width="11%" class="style15">&nbsp;</td>
<td width="24%" align="left" >&nbsp;</td>
<td width="8%" align="center">&nbsp;</td>
<td width="2%"></td>
<td width="7%" align="center"><a href="javascript:local_cnfrm_print('booking/local_delivery_conform/local_delivery_confirm_print.php?from_date=<?php echo $_POST['from_date'];?>&to_date=<?php echo $_POST['to_date'];?>&branch_name=<?php echo $_POST['branch_name'];?>&get_user_type=<?php echo $get_user_type;?>&book_branch=<?php echo $book_branch;?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="35" title="Print" value="Print"/></a></td>
  </tr>
</table>
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  

<table border="0" width="96%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
<thead>
<tr>
    <th  align="center" width="60" style="border:1px solid #ddd" >S.No</th>
    <th  align="left" style="border:1px solid #ddd" >&nbsp;Loading Date</th>
    <th  align="left" style="border:1px solid #ddd" >&nbsp;Delivery No</th>
    <th  align="left" style="border:1px solid #ddd" >&nbsp;Loading No</th>
    <th  align="left" style="border:1px solid #ddd" >&nbsp;Branch Name</th>
    <th  align="center" style="border:1px solid #ddd" >Count</th>
    <th  align="right" style="border:1px solid #ddd" >Amount&nbsp;</th>
    <th  width="99" style="border:1px solid #ddd" >Edit</th>
    <th  width="81" style="border:1px solid #ddd" >Delete</th>
</tr>
  <?php
include("../../include/db.php");  

          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;
		} 

		 function get_unloading_amount($delivery_no)
		{
		 	$sql="select sum(amount) as amount from delivery_conform_sublist where delivery_no='$delivery_no'";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$amount=$rsdata->amount;
		    }
		  	return $amount;
		} 
		
		 function get_booking_no($delivery_no)
		{
		 	$sql="select booking_no from delivery_conform_sublist where delivery_no='$delivery_no' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
			while($rsdata=mysql_fetch_object($rs))
		    {
		   	$booking_no=$rsdata->booking_no;
		    }
		  	return $booking_no;
		} 
		
	/********************* Get Delivery Count **************************************************/	
		function get_delivery_count($delivery_no)
		{
		 	$sql="select booking_no from delivery_conform_sublist where delivery_no='$delivery_no' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
		  	return $rscount;
		} 
		 
        function get_items_count($get_booking_no)
		{
		 	$sql="select * from booking_sub_list where book_no='$get_booking_no' and unloading_status='1' ";
			$rs=mysql_query($sql);
			$rscount=mysql_num_rows($rs);
		  	return $rscount;
		} 
		
$branch_name=$_POST['branch_name'];
$from_date=$_POST['from_date'];
$to_date=$_POST['to_date'];
$current_date=date('Y-m-d');

if($branch_name!=""){ $branch_name1= "branch='$branch_name'"; }else{$branch_name1=''; }
if($from_date!=""){ $from_date1= "loading_date>='$from_date'"; }else{$from_date1="loading_date='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "loading_date<='$to_date'";}else{$to_date1="loading_date='$cur_dates'";}

$all_value10 = $branch_name1.",".$from_date1.",".$to_date1;
$all_array10 = explode(',',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query103 .= $value10." AND ";
}
}	  

 if($get_user_type=='1')
{
	if(($from_date=='')&&($to_date==''))
  {
  $sql="select * from  delivery_conform where  loading_date='$current_date' order by loading_no ASC LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  delivery_conform where $get_query103 id!='' order by loading_no ASC LIMIT $from,20";
  }
}
else
{
	if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  delivery_conform where  loading_date='$current_date' and branch='$book_branch' order by loading_no ASC LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  delivery_conform where $get_query103 id!='' and branch='$book_branch' order by loading_no ASC LIMIT $from,20";
  }
}	
	
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
                 $id=$rsdata['id'];
                 $loading_no=$rsdata['loading_no'];
				 $delivery_no=$rsdata['delivery_no'];
				 $get_delivery_count=get_delivery_count($delivery_no);
				 $loading_date=$rsdata['loading_date'];
				 $hidden_checkbox=$rsdata['hidden_checkbox'];
				 $hidden_checkboxs=explode("@",$hidden_checkbox);
                 $branch_name=$rsdata['branch'];
				 $branch=get_branchname($branch_name);
				 $tot_amt=get_unloading_amount($delivery_no);
				 $get_booking_no=get_booking_no($delivery_no);
				 $count=get_items_count($get_booking_no);

 ?>
  <tr>
    <td width="60"  align="center" style="border:1px solid #ddd">&nbsp;<?php echo $s_no; ?></td>
    <td width="146" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo date('d-m-Y',strtotime($loading_date)); ?></td>
    <td width="167" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo $delivery_no; ?></td>
    <td width="184" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo $loading_no; ?></td>
    <td width="267" align="left" style="border:1px solid #ddd" >&nbsp;<?php echo $branch; ?></td>
    <td width="115" align="center" style="border:1px solid #ddd" >&nbsp;<?php echo $get_delivery_count; ?></td>
    <td width="138" align="right" style="border:1px solid #ddd" ><?php echo number_format($tot_amt,2); ?>&nbsp;</td>
    <td align="center" style="border:1px solid #ddd"  ><img src="img/edit.png" style="cursor:pointer"width="13" height="16" title="EDIT" onclick="javascript:add_local_delivery_conform('booking/local_delivery_conform/local_delivery_conform_form_entry.php?edit_id=<?php echo $id;?>&hidden_checkbox=<?php echo $hidden_checkbox;?>&loading_no=<?php echo $loading_no;?>&delivery_no=<?php echo $delivery_no;?>&loading_date=<?php echo $loading_date;?>')"/></td>
    <td align="center" style="border:1px solid #ddd" ><a href="#" onClick="local_delivery_conform_delete('<?php echo $id;?>','<?php echo $loading_no;?>','<?php echo $delivery_no;?>');"><img src="img/trash.png" alt="delete" title="DELETE" border="0" width="17px;" height="20px;" /></a>   </td>
  </tr>
  <?php } ?>
  </thead>
</table>
</div>
<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0" >

 <tr>
    <th height="19" align="left" style="font-size:12px; font-family:sans-serif; padding-top:10px;" scope="col"><?php echo $confirmation;?></th>
	<th scope="cols" width="8%" align="right"><?php  
			  if ($num_results > $show) 
			  {
			  $show;
			include("include/footer_links.php");
			  }
	?></th>
 </tr>
</table>
</div>
</div>
</div>

