<style>
.style15 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
</style>
<script>
function edit_book_dfetails(edit_id,book_no)
{
window.location.href="main_fram.php?file=booking_creation&edit_id=" + edit_id + "&book_no=" + book_no;
}
</script>

<?php error_reporting(0);
/***************************** PREVIOUS NEXT CODING ****************************************/
include ("../../include/db.php");
ob_start();
session_start();

function get_user_type($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_type($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=$_GET['branch_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$status=$_GET['paid_status'];
$current_date=date('Y-m-d');

if($branch_name!=""){ $branch_name1= "book_branch='$branch_name'"; }else{$branch_name1=''; }
if($from_date!=""){ $from_date1= "book_date>='$from_date'"; }else{$from_date1="book_date='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "book_date<='$to_date'";}else{$to_date1="book_date='$cur_dates'";}
if($status!=""){ $status1 = "pay_type='$status'";}else{$status1='';}

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

if($get_user_type=='1')
{
	if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  booking_main_list where  book_date='$current_date'  order by book_date ";
  } 
  else
  {
   $sql="select * from  booking_main_list where $get_query102 id!=''  order by book_date ";
  }
}
else
{
	if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  booking_main_list where  book_date='$current_date' and book_branch='$book_branch'  ";
  } 
  else
  {
   $sql="select * from  booking_main_list where $get_query102 id!='' and book_branch='$book_branch' ";
  }
}

$html_query = "main_fram.php?file=booking_creation_list";
$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%">&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:print_purchase('booking/booking_entry/booking_main_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&branch_name=<?php if($get_user_type=='1'){ echo $_GET['branch_name']; } else {  echo $book_branch; }?>&paid_status=<?php echo $_GET['paid_status'];?>&get_user_type=<?php echo $get_user_type; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="35" title="Print" value="Print"/></a></td>
  </tr>
</table>
<div class="row-fluid">
<div class="span12">
<div class="table-responsive">
<div class="CSSTableGenerator">  
<table width="99%" border="0" align="center"  cellpadding="0" cellspacing="0" style="border:2px solid #eaeaea;border:1px solid #ddd"  >
      <tr>
      <th align="center" style="border:1px solid #ddd" >S.No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >&nbsp;Date</th>
      <th width="164" align="left" style="border:1px solid #ddd" scope="col" >&nbsp;&nbsp;Booking No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >&nbsp;Consignor M/s</th>
      <th width="210" align="left" scope="col" style="border:1px solid #ddd" >Consignee M/s</th>
      <th width="172" align="left" scope="col" style="border:1px solid #ddd" >&nbsp;Place</th>
      <th width="106" align="center" style="border:1px solid #ddd" scope="col" >Paid/To Pay</th>
      <th width="89" align="center" style="border:1px solid #ddd" scope="col" >Items Count</th>
      <th width="86" align="right" scope="col" style="border:1px solid #ddd" >Amount&nbsp;</th>
      <th width="62" align="center" scope="col" style="border:1px solid #ddd" >Print</th>
      <th width="49" align="center" scope="col" style="border:1px solid #ddd" >Edit</th>
      <th width="47" align="center" scope="col" style="border:1px solid #ddd" >Delete</th>
      </tr>
  <?php
  include ("../../include/db.php");
  
  function place_branch_name($book_branch)
  {
	$sql_user="select * from branch_creation where branch_id='$book_branch' and delete_status!='1' ";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$branch_name=$rsdata_user->branch_name;
	}
	return $branch_name;
  }
 
  function book_place_names($book_place)
  {
	$sql_user="select * from place_creation where id='$book_place'";
	$rs_user=mysql_query($sql_user);
	while($rsdata_user=mysql_fetch_object($rs_user))
	{ 
	$location=$rsdata_user->location;
	}
	return $location;
  }
  
  function gets_book_count($booking_no)
  {
	  $sql_user="select * from booking_sub_list where book_no='$booking_no'";
	  $rs_user=mysql_query($sql_user);
	  $rs_count=mysql_num_rows($rs_user);
	  return $rs_count;
  }
  

$branch_name=$_GET['branch_name'];
$from_date=$_GET['from_date'];
$to_date=$_GET['to_date'];
$status=$_GET['paid_status'];
$current_date=date('Y-m-d');


if($branch_name!=""){ $branch_name1= "book_branch='$branch_name'"; }else{$branch_name1=''; }
if($from_date!=""){ $from_date1= "book_date>='$from_date'"; }else{$from_date1="book_date='$cur_dates'"; }
if($to_date!=""){ $to_date1 = "book_date<='$to_date'";}else{$to_date1="book_date='$cur_dates'";}
if($status!=""){ $status1 = "pay_type='$status'";}else{$status1='';}

$all_value10 = $branch_name1.",".$from_date1.",".$to_date1.",".$status1;
$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  booking_main_list where  book_date='$current_date' order by book_date LIMIT $from,20";
  } 
  else
  {
    $sql="select * from  booking_main_list where $get_query103 id!='' order by book_date  LIMIT $from,20 ";
  }
}
else
{
	if(($from_date=='')&&($to_date==''))
  {
   $sql="select * from  booking_main_list where  book_date='$current_date' and book_branch='$book_branch' order by book_date LIMIT $from,20";
  } 
  else
  {
   $sql="select * from  booking_main_list where $get_query103 id!=''and book_branch='$book_branch' order by book_date LIMIT $from,20";
  }
}

    $rs=mysql_query($sql);
	$sno=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$id=$rsdata['id'];
   				$booking_no=$rsdata['booking_no'];
				$book_count=gets_book_count($booking_no);
				$book_date=$rsdata['book_date'];
	   			$book_place=$rsdata['book_place'];
				$book_place_names=book_place_names($book_place);
	   			$book_branch=$rsdata['book_branch'];
				$book_branch_names=place_branch_name($book_branch);
				$pay_type=$rsdata['pay_type'];
	   			$from_party_name=$rsdata['from_party_name'];
	   			$from_party_address=$rsdata['from_party_address'];
				$from_party_mob=$rsdata['from_party_mob'];
	   			$to_party_name=$rsdata['to_party_name'];
	   			$to_party_addrs=$rsdata['to_party_addrs'];
				$to_party_mob=$rsdata['to_party_mob'];
	   			$unloading_st_charge=$rsdata['unloading_st_charge'];
	   			$tot_amt=$rsdata['tot_amt'];
	   			$remarks=$rsdata['reamarks'];
				$cr_date=$rsdata['cr_date'];
  ?>
  <tr>
    <td width="37"  align="center" style="border:1px solid #ddd"><?php echo $from; ?></td>
    <td width="91" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($book_date));?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $booking_no;?></td>
    <td width="208" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $from_party_name;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $to_party_name;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;<?php echo $book_place_names;?></td>
    <td align="center" style="border:1px solid #ddd"><?php echo $pay_type;?></td>
    <td align="center" style="border:1px solid #ddd"><?php echo $book_count; ?></td>
    <td align="right" style="border:1px solid #ddd"><?php echo number_format($tot_amt,2);?>&nbsp;</td>
    <td align="center" style="border:1px solid #ddd"><a href="javascript:print_purchase('booking/booking_entry/booking_print.php?tot_amt=<?php echo $tot_amt;?>&book_no=<?php echo $booking_no; ?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="35" title="Print" value="Print"/></a></td>
    <td align="center" style="cursor:pointer; border:1px solid #ddd"><img src="img/edit.png" width="17" height="20" title="EDIT" onclick="javascript:edit_book_dfetails('<?php echo $id;?>','<?php echo $booking_no;?>');"/></td>
    <td align="center" style="border:1px solid #ddd" ><img src="img/trash.png" style="cursor:pointer" onClick="del_book_main('<?php echo $id;?>','<?php echo  $booking_no;?>')" width="20px" height="22px">
   </td>
   </tr>
  <?php } ?>
</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("footer_links1.php");
			  }
	?></th>
 </tr>
</table>
</div>
</div>

