<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function delivery_report_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);
include("../../include/db.php");
?>
<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:delivery_report_print('report/delivery_report/delivery_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&job_card_no=<?php echo $_GET['job_card_no'];?>');" style="text-decoration:none;"><img src="img/PrinterBlack.png" width="35" height="30" 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="90%"  align="center" cellpadding="0" cellspacing="0" style="border:1px solid #ddd" >
<thead>
<tr>
    <th  height="23"  align="center" style="border:1px solid #ddd" >S.No</th>
    <th  align="center" style="border:1px solid #ddd" >Date</th>
    <th  align="center" style="border:1px solid #ddd" >Job Card No</th>
    <th  align="center" style="border:1px solid #ddd" >Customer Name</th>
    <th  align="center" style="border:1px solid #ddd" >Delivery No</th>
    <th  align="center" style="border:1px solid #ddd" >DC No</th>
     <th  align="left" style="border:1px solid #ddd" >Particulars</th>
    <th  align="right" style="border:1px solid #ddd" >Inward Qty</th>
    <th  align="right" style="border:1px solid #ddd" >Outward Qty</th>

    </tr>
  <?php
include("../../include/db.php"); 

function get_cust_dc_no($jobcard_no)
{
$sql="select * from inward_main where jobcard_no='$jobcard_no'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$customer_dc_no=$rsdata['customer_dc_no'];
}
return $customer_dc_no;
}

$from_date11=$_GET['from_date'];
$to_date11=$_GET['to_date'];
$job_card_no=$_GET['job_card_no'];

$current_date=date('Y-m-d');
if($from_date11!=""){ $from_date12="DATE_FORMAT(date_time,'%Y-%m-%d')>='$from_date11'"; }else{$from_date12="DATE_FORMAT(date_time,'%Y-%m-%d')='$current_date'"; }
if($to_date11!=""){ $to_date12 = "DATE_FORMAT(date_time,'%Y-%m-%d')<='$to_date11'"; }else{ $to_date12="DATE_FORMAT(date_time,'%Y-%m-%d')='$current_date'"; }
if($job_card_no!=""){ $job_card_no1 = "job_no='$job_card_no'";}else{$job_card_no1="";}

$all_value10 = $from_date12."@".$to_date12."@".$job_card_no1;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value11)
{ 
if($value11!='')
{
  $get_query104.=$value11." AND ";
}
}	

if($from_date11!=""){ $from_date122="DATE_FORMAT(inward_date,'%Y-%m-%d')>='$from_date11'"; }else{$from_date122="DATE_FORMAT(inward_date,'%Y-%m-%d')='$current_date'"; }
if($to_date11!=""){ $to_date122 = "DATE_FORMAT(inward_date,'%Y-%m-%d')<='$to_date11'"; }else{ $to_date122="DATE_FORMAT(inward_date,'%Y-%m-%d')='$current_date'"; }
if($job_card_no!=""){ $job_card_no1 = "jobcard_no='$job_card_no'";}else{$job_card_no1="";}

$all_value102 = $from_date122."@".$to_date122."@".$job_card_no1;
$all_array102 = explode('@',$all_value102);
foreach($all_array102 as $value112)
{ 
if($value112!='')
{
  $get_query1042.=$value112." AND ";
}
}	
 $sql="select cust_name as cust_name,job_no as jobcard_no,delivery_no as delivery_no,date_time as date_time,qty as total_qty,particulars as inward_particular from  delivery_challan_sub where $get_query104  sub_id!='' union  select in_cust_name as cust_name,jobcard_no as jobcard_no,invoice_no as delivery_no,inward_date as date_time,inward_qty as total_qty,inward_particular as inward_particular from  inward_sub_list where $get_query1042  id!='' order by inward_particular asc ";
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
 				 $s_no=$s_no+1;
				 $jobcard_no=$rsdata['jobcard_no'];
				  $cust_dc_no=get_cust_dc_no($jobcard_no);
				  $cust_name=$rsdata['cust_name'];
				 $delivery_no=$rsdata['delivery_no'];
				 $date_time=$rsdata['date_time'];
				 $a = explode("-",$delivery_no);
				
				 $inward_particular=$rsdata['inward_particular'];
 ?>
    <tr>
    <td width="49"  align="center" style="border:1px solid #ddd">&nbsp;<?php echo $s_no; ?></td>
    <td width="105" align="center" style="border:1px solid #ddd">&nbsp;<?php echo date("d-m-Y",strtotime($date_time));?></td>
    <td width="128" align="center" style="border:1px solid #ddd">&nbsp;<?php echo $jobcard_no; ?></td>
    <td width="145" align="center" style="border:1px solid #ddd">&nbsp;<?php echo $cust_name; ?></td>
    <td width="130" align="center" style="border:1px solid #ddd">&nbsp;<?php echo $delivery_no; ?></td>
    <td width="145" align="center" style="border:1px solid #ddd">&nbsp;<?php echo $cust_dc_no; ?></td>
     <td width="237" align="left" style="border:1px solid #ddd">&nbsp;<?php echo $inward_particular; ?></td>
    <td width="132" align="right" style="border:1px solid #ddd">&nbsp;<?php   
				 if($a[0]=='GRN')
				 {
				 $in_qty=$rsdata['total_qty'];
				 echo number_format($in_qty,2);
				 } ?></td>
    <td width="122" align="right" style="border:1px solid #ddd">&nbsp;<?php if($a[0]=='DC')
				 {
				  $out_qty=$rsdata['total_qty'];
				 echo number_format($out_qty,2);
				 } ?></td>
</tr>
  <?php $in_qtys+=$in_qty;
        $out_qtys+=$out_qty;
        } ?>
  
  <tr>
    <td colspan="7"  align="right" style="border: 1px solid #ddd; font-weight: bold;">Total</td>
    <td width="132" align="right" style="border:1px solid #ddd">&nbsp;<?php echo number_format($in_qtys,2); ?></td>
    <td width="122" align="right" style="border:1px solid #ddd">&nbsp;<?php echo number_format($out_qtys,2); ?></td>
</tr>
  <tr>
    <td colspan="7"  align="right" style="border: 1px solid #ddd; font-weight: bold;">Balance</td>
    <td width="132" align="right" style="border:1px solid #ddd">&nbsp;<?php echo number_format($in_qtys-$out_qtys,2); ?></td>
    <td width="122" align="right" style="border:1px solid #ddd">&nbsp;</td>
</tr>
  </thead>
</table>
</div>
</div>
</div>
</div>