<script src="js/jquery/jquery.js" type="text/javascript"></script>
<script src="js/jquery/jquery-1.8.2.js"></script>
<script src="js/jquery/jquery-ui.js"></script>
<?php
error_reporting(0);
include("../../include/db.php");
?>
<style type="text/css">
.txt{ font-family: Verdana, Arial, Helvetica, sans-serif; font-size:13px;}
.headings{ font-family:verdana; font-size:10px;}
.form-style-6 ul{
    font: 95% Arial, Helvetica, sans-serif;
    max-width: 200px;
    margin-left: 10px;
    padding: 36px;
}
.form-style-6 li h1{
    background: #777777;
    font-size: 140%;
    font-weight: 300;
    text-align: center;
    color: #fff;
	padding:20px;
}
.form-style-7{
    font: 95% Arial, Helvetica, sans-serif;
    max-width: 200px;
    padding: 36px;
}
.form-style-7 h2{
    background: #777777;
    font-size: 140%;
    font-weight: 300;
    text-align: center;
    color: #fff;
	padding:20px;
}
.pad{margin-right:2px}
.class_px{ font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold }
</style>
<script>
function process_jobcard_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>
<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:process_jobcard_report_print('report/inhouse_job_report_total/inhouse_job_print.php?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>
<table width="75%" height="100%"  style="border: 1px solid #CCC" cellpadding="0" cellspacing="0" >
<tr>
<td height="152" align="left" valign="top">
<table width="100%" border="0" align="center"  cellpadding="0" cellspacing="0" >
        <?php
	 function get_cust_address($cust_name)
{
$sql_query11="select * from party_creation where party_name='$cust_name' and delete_status!='1' and `party_type`='Customer'   order by party_name ASC ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $address=$rsdata11->address;
 } 
return $address;
}
  $sql="select * from  jobcard_main where jobcard_no='$_GET[job_card_no]' ";

    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$cust_name=$rsdata['cust_name'];
               $cust_address=get_cust_address($cust_name);
			  
				  }
			
			 $sql1="select sum(qty) as qty from  jobcard_sublist where jobcard_no='$_GET[job_card_no]' ";

    $rs1=mysql_query($sql1);
	$s_no=0;
   		while($rsdata1=mysql_fetch_array($rs1))
  			{
   				$job_qty=$rsdata1['qty'];
               } ?>
         <tr>
           <td width="106" height="27" colspan="2"  align="left" class="class_px" >&nbsp;Customer Details</td>
           <td width="419" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
           <td width="359" align="left" >&nbsp;</td>
         </tr>
         <tr>
           <td width="106" height="36"  align="center" class="class_px">&nbsp;</td>
           <td width="199" align="left" class="class_px">&nbsp;Customer Name</td>
           
           <td width="419" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;<?php echo $cust_name; ?></td>
           <td width="359" align="left" >&nbsp;</td>
         </tr>
         <tr>
           <td height="32"  align="center" >&nbsp;</td>
           <td width="199" align="left" class="class_px">&nbsp;Address</td>
           
           <td width="419" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;<?php echo $cust_address; ?></td>
           <td align="left" >&nbsp;</td>
          </tr>
         <tr>
           <td height="36"  align="center" class="class_px">&nbsp;</td>
           <td width="199" align="left" class="class_px">Quantity</td>
           
           <td width="419" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;<?php echo number_format($job_qty,2) ?></td>
           <td align="left" class="class_px">&nbsp;</td>
          </tr>
  </table>        
       <p>&nbsp; </p>
      <div style="border-bottom:1px solid #CCC; font-family:Verdana, sans-serif; font-size:14px; font-weight:bold; color:#87BB07;">Printing Report</div>
  <div style="height:150px; width:100%;padding-left:0px;overflow-x:hidden;overflow-y:scroll;white-space:nowrap;"><br/>
  <table width="100%" border="0" align="center"  cellpadding="0" cellspacing="0" >
    <tr>
      <td width="31" height="23"  align="center" class="class_px">&nbsp;S.No</td>
      <td width="31" height="23"  align="center" class="class_px">&nbsp;Date</td>
      <td width="97" align="left" class="class_px">&nbsp;Shift</td>
      <td width="104" align="left" class="class_px">&nbsp;Machine No</td>
      <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Operator</td>
      <td width="88" align="left" class="class_px">Particulars</td>
      <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">O.Qty</td>
      <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">P.Qty</td>
      <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Balance</td>
      </tr>
    <?php
	
	function get_order_qty($job_card_no,$prod_size)
{
	$sql_query="select * from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
    $rs=mysql_query($sql_query);
    $rscount=mysql_num_rows($rs);
	return $rscount;
 }
 
function get_max_order_qty($job_card_no,$prod_size)
{
$sql_query="select max(total_qty) as total_qty from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
$rs11=mysql_query($sql_query);
while($rsdata=mysql_fetch_array($rs11))
 {
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}

 function get_order_qty1($job_card_no,$prod_size,$pr_id)
{
$sql_query="select total_qty from printer_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' and pr_id='$pr_id'  ";
$rs11=mysql_query($sql_query);
while($rsdata=mysql_fetch_array($rs11))
{
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}	  	  
	   function get_shift_name_process($shift_time)
{
$sql_query11="select * from shift_creation where id='$shift_time' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
  $to_time=$rsdata11->to_time;
  $shift_name=$rsdata11->shift_name;
  $from_time=$rsdata11->from_time;
 } 
 $tot_shift=array($from_time,$to_time,$shift_name);
 return $tot_shift;
}

function get_machine_name_process($machine_no)
{
$sql_query11="select * from machine_creation where id='$machine_no'";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $machine_no=$rsdata11->machine_no;
 } 
return $machine_no;
}

function get_operator_name_process($operator_no)
{
$sql_query11="select * from operator_creation where id='$operator_no' ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $operator_name=$rsdata11->operator_name;
 } 
return $operator_name;
}
	  
$job_card_no=$_GET['job_card_no'];

if($job_card_no!=""){ $job_card_no1= "job_card_no='$job_card_no'"; }else{$job_card_no1=''; }

$all_value102 = $job_card_no1;

$all_array102 = explode(',',$all_value102);
foreach($all_array102 as $value102)
{ 
if($value102!='')
{
  $get_query103 .= $value102." AND ";
}
}	  

if($job_card_no!='')
{
 $sql="select * from  printer_production_sublist where $get_query103 pr_id!=''  and deliv_status='0' ";
}
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $id=$rsdata['pr_id'];
                  $shift_time=$rsdata['shift_time'];
				list($frm_time,$to_ti,$type)=get_shift_name_process($shift_time);
				 $print_date=$rsdata['production_time'];
				 $machine_no=$rsdata['machine_no'];
				 $machine_name=get_machine_name_process($machine_no);
				 $operator_no=$rsdata['operator_name'];
				 $operator_name=get_operator_name_process($operator_no);
				 $prod_size=$rsdata['prod_size'];
				
				 $prod_qty=$rsdata['prod_qty'];
				 $total_qty=$rsdata['total_qty'];
				 $balance_qty=$rsdata['balance_qty'];
				 $printed_qty=$rsdata['printed_qty'];
$count_order_qty = get_order_qty($job_card_no,$prod_size); 
	 $max_order_qty = get_max_order_qty($job_card_no,$prod_size);
	 $qty=  get_order_qty1($job_card_no,$prod_size,$pr_id);
	if($max_order_qty==$qty)
	{
		$qty=$max_order_qty;
	}
	else
	{
		$qty='';
	}
?>
    <tr height="27">
      <td align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $s_no;?></td>
      <td align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo date('d-m-Y',strtotime($print_date));?></td>
      <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $type."(".$frm_time."-".$to_ti.")";?></td>   
      <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $machine_name;?></td>
      
      <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $operator_name;?></td>
      <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $prod_size;?></td>
       <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $qty;?></td>
       <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $prod_qty;?></td>
        <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $balance_qty;?></td>
      </tr>
    <?php $total1+=$qty; 
	$total2+=$prod_qty; 
	$total3+=$balance_qty;}?>
        <tr>
         <td width="31" height="23"  align="center" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="97" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="104" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="88" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Total</td>
         <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total1,2); ?></td>
         <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total2,2); ?></td>
                  <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total1-$total2,2); ?></td>
       </tr>
    </table><br/></div>
  </a>
  <div style="border-bottom:1px solid #CCC; font-family:Verdana, sans-serif; font-size:14px; font-weight:bold; color:#87BB07;">Fusing Report</div>
       <div style="height:150px; width:100%;padding-left:0px;overflow-x:hidden;overflow-y:scroll;white-space:nowrap;">
         <table width="100%" border="0" align="center"  cellpadding="0" cellspacing="0" >
           <tr>
        <td width="31" height="23"  align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Sno</td>
        <td width="31" height="23"  align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Date</td>
        <td width="97" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Shift</td>
         <td width="104" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Machine No</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;Operator</td>
         <td width="88" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Particulars</td>
         <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">O.Qty</td>
         <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">P.Qty</td>
        <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Balance</td>
           </tr>
           <?php
 function get_operator_name10($ope_name)
{
$sql="select * from operator_creation where id='$ope_name'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$operator_namess=$rsdata['operator_name'];
}
return $operator_namess;
}


function get_shift_time10($shift_id)
{
$sql="select * from shift_creation where id='$shift_id'";
$rs11=mysql_query($sql);
while($rsdata=mysql_fetch_array($rs11))
{
$from_time[0]=$rsdata['from_time'];
$from_time[1]=$rsdata['to_time'];
$from_time[2]=$rsdata['shift_name'];
}
return $from_time;
}

function get_machine_no10($machine_no)
{
$sql="select * from machine_creation where id='$machine_no'";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$machine_no=$rsdata['machine_no'];
}
return $machine_no;
}

function get_order_qty_inhouse($job_card_no,$prod_size)
{
	$sql_query="select * from fusing_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
    $rs=mysql_query($sql_query);
    $rscount=mysql_num_rows($rs);
	return $rscount;
 }
 
function get_max_order_qty_inhouse($job_card_no,$prod_size)
{
$sql_query="select max(total_qty) as total_qty from fusing_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' ";
$rs11=mysql_query($sql_query);
while($rsdata=mysql_fetch_array($rs11))
 {
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}

 function get_order_qty1_inhouse($job_card_no,$prod_size,$pr_id)
{
$sql_query="select total_qty from fusing_production_sublist where job_card_no='$job_card_no' and prod_size='$prod_size' and pr_id='$pr_id'  ";
$rs11=mysql_query($sql_query);
while($rsdata=mysql_fetch_array($rs11))
{
$total_qty=$rsdata['total_qty'];
}
return $total_qty;
}	  	  
$job_card_no=$_GET['job_card_no'];

if($job_card_no!=""){ $job_card_no1= "job_card_no='$job_card_no'"; }else{$job_card_no1=''; }

$all_value102 = $job_card_no1;

$all_array102 = explode(',',$all_value102);
foreach($all_array102 as $value1022)
{ 
if($value1022!='')
{
  $get_query104 .= $value1022." AND ";
}
}	  

if($job_card_no!='')
{
  $sql="select *  from  fusing_production_sublist where $get_query104 pr_id!=''  and deliv_status='0' ";
}
    $rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $id=$rsdata['pr_id'];
                 $print_date=$rsdata['production_time'];
				 $shift_id=$rsdata['shift_time'];
				$shift_time=get_shift_time10($shift_id);
				$machine_id=$rsdata['machine_no'];
				$machine_no=get_machine_no10($machine_id);
				$operator_id=$rsdata['operator_name'];
				$operator_name=get_operator_name10($operator_id);
				$prod_size=$rsdata['prod_size'];
				$prod_qty=$rsdata['prod_qty'];
				$total_qty=$rsdata['total_qty'];
				$balance_qty=$rsdata['balance_qty'];
				$printed_qty=$rsdata['printed_qty'];
				
     $count_order_qty = get_order_qty_inhouse($job_card_no,$prod_size); 
	 $max_order_qty = get_max_order_qty_inhouse($job_card_no,$prod_size);
	 $qty=  get_order_qty1_inhouse($job_card_no,$prod_size,$pr_id);
	
	if($max_order_qty==$qty)
	{
	$qty=$max_order_qty;
	}
	else
	{
	$qty='';
	}

?>
           <tr height="27">
             <td align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $s_no;?></td>
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo date('d-m-Y',strtotime($print_date));?></td>    
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $shift_time[2]."(".$shift_time[0]."-".$shift_time[1].")";?></td>
             
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $machine_no;?></td>
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $operator_name;?></td>
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $prod_size;?></td>
              <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $qty;?></td>
       <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $prod_qty;?></td>
        <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $balance_qty;?></td>
  </tr>
           <?php 
    $total12+=$qty; 
	$total22+=$prod_qty; 
	$total32+=$balance_qty;
	} ?>
         <tr>
         <td width="31" height="23"  align="center" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="97" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="104" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
 <td width="104" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="88" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Total</td>
         <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total12,2); ?></td>
         <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total22,2); ?></td>
          <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($total12-$total22,2); ?></td>
       </tr>
  </table></div>
      <div style="border-bottom:1px solid #CCC; font-family:Verdana, sans-serif; font-size:14px; font-weight:bold; color:#87BB07;">Delivery Report</div>
       <div style="height:150px; width:100%;padding-left:0px;overflow-x:hidden;overflow-y:scroll;white-space:nowrap;">
         <table width="100%" border="0" align="center"  cellpadding="0" cellspacing="0" >
           <tr>
             <td width="67" height="23"  align="center" class="class_px">&nbsp;S.No</td>
             <td width="118" height="23"  align="left" class="class_px">&nbsp;Date</td>
             <td width="211" align="left" class="class_px">&nbsp;DC No</td>
             <td width="333" align="left" class="class_px">Particulars</td>
             <td width="185" align="right" class="class_px">Inward</td>
             <td width="169" align="right" class="class_px">Outward</td>
           </tr>
           <?php
	   
	
	function get_cust_dc_no($jobcard_no)
{
$sql="select * from inward_main where jobcard_no='$jobcard_no' union ";
$rs11=mysql_query($sql);
 while($rsdata=mysql_fetch_array($rs11))
 {
$customer_dc_no=$rsdata['customer_dc_no'];
}
return $customer_dc_no;
}

$job_card_no=$_GET['job_card_no'];

if($job_card_no!=""){ $job_card_no11 = "job_no='$job_card_no'";}else{$job_card_no11="";}

$all_value10 = $job_card_no11;
$all_array10 = explode(',',$all_value10);
foreach($all_array10 as $value11)
{ 
if($value11!='')
{
  $get_query105.=$value11." AND ";
}
}	
if($job_card_no!=""){ $job_card_no12 = "jobcard_no='$job_card_no'";}else{$job_card_no12="";}

$all_value102 = $job_card_no12;
$all_array102 = explode(',',$all_value102);
foreach($all_array102 as $value112)
{ 
if($value112!='')
{
  $get_query106.=$value112." AND ";
}
}	
if($job_card_no!='')
{
  $sql="select delivery_no as delivery_no,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_query105  sub_id!='' union  select invoice_no as delivery_no,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_query106  id!='' order by inward_particular asc ";
}
$rs=mysql_query($sql);
	$s_no=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				 $s_no=$s_no+1;
				 $from=$from+1;
                 $id=$rsdata['sub_id'];
                 $job_card_no=$rsdata['job_no'];
				 $print_date=$rsdata['date_time'];
				  $cust_dc_no=get_cust_dc_no($jobcard_no);
				 $delivery_no=$rsdata['delivery_no'];
				 $date_time=$rsdata['date_time'];
				 $a = explode("-",$delivery_no);
				 $particulars=$rsdata['inward_particular'];
				 $job_type=$rsdata['job_type'];
				 $qty=$rsdata['qty'];
				 $bal_qty=$tot_qty1-$qty;

?>
           <tr height="27">
             <td align="center" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $s_no;?></td>
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo date('d-m-Y',strtotime($print_date));?></td>       
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $delivery_no;?></td>
             <td align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php echo $particulars;?></td>
             <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php   
				 if($a[0]=='GRN')
				 {
				 $in_qty=$rsdata['total_qty'];
				 echo number_format($in_qty,2);
         $in_qtys+=$in_qty;
				 } ?></td>
             <td align="right" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;color:#666;">&nbsp;<?php if($a[0]=='DC')
				 {
				  $out_qty=$rsdata['total_qty'];
				 echo number_format($out_qty,2);
         $out_qtys+=$out_qty;
				 } ?></td>
           </tr>
            <?php 
			
	        
	        } ?>
         <tr>
         <td width="31" height="23"  align="center" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="88" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Total</td>
         <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($in_qtys,2); ?></td>
                  <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format($out_qtys,2); ?></td>
       </tr>
        <tr>
         <td width="31" height="23"  align="center" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="92" align="left" style="font-size: 12px;font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="88" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">&nbsp;</td>
         <td width="68" align="left" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold">Balance</td>
         <td width="58" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"><?php echo number_format(($in_qtys-$out_qtys),2); ?></td>
                  <td width="70" align="right" style="font-size: 12px;  font-family: Verdana, Arial, Helvetica, sans-serif;font-weight:bold"></td>
       </tr>
         </table>
    </div></td>
</tr>
 </table>