<style>
.style15 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
</style>
<script>
function print_Billing_production(url)
{	
onmouseover10= window.open(url,'onmouseover10','height=700,width=1200,scrollbars=no,resizable=no,left=50,top=50,toolbar=no,location=no,directories=no,status=no');	
}
function print_function311(url)
{//alert();
onmouseover= window.open(url,'','height=580,width=1000,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%">&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_Billing_production('production/unbilling/unbilling_print.php?from_date=<?php echo $_GET['from_date'];?>&to_date=<?php echo $_GET['to_date'];?>&cus_name=<?php echo $_GET['cus_name'];?>&job_card_num=<?php echo $_GET['job_card_num'];?>&status=<?php echo $_GET['status'];?>');" 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 height="25" 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="154" align="left" style="border:1px solid #ddd" scope="col">&nbsp;&nbsp;Jobcard No</th>
      <th scope="col" align="left" style="border:1px solid #ddd" >Customer Name</th>
      <th width="154" align="left" scope="col" style="border:1px solid #ddd" >Job Created</th>
      <th width="162" align="left" scope="col" style="border:1px solid #ddd" >Style No</th>
      <th width="152" align="left" scope="col" style="border:1px solid #ddd" >Style Name&nbsp;</th>
      <th width="136" align="right" scope="col" style="border:1px solid #ddd" >Printed Qty</th>
     <?php if($_GET['status']!=1) { ?> <th width="108" style="border:1px solid #ddd" scope="col" >Bill/unbill</th><?php } ?>
      </tr>
  <?php
 include ("../../include/db.php");
 
 function get_invoice_function3($invoice_nos)
{
$sql_query="select MAX(jobcard_number) AS `jobcard_number` from fusing_production_main  ";
$rs=mysql_query($sql_query);
 while($rsdata=mysql_fetch_object($rs))
 {
 $jobcard_number=$rsdata->jobcard_number;
 } 
return $jobcard_number;
}

function get_invoice_function4($invoice_nos)
{
$sql_query11="select MAX(jobcard_number) AS `jobcard_number` from printer_production_main ";
$rs11=mysql_query($sql_query11);
 while($rsdata11=mysql_fetch_object($rs11))
 {
 $jobcard_number=$rsdata11->jobcard_number;
 } 
return $jobcard_number;
}


$c=get_invoice_function3($invoice_nos);	
$d=get_invoice_function4($invoice_nos);
	 
	if($c>$d)
	{ 
		 if($c==0)
		 {
		 $values=1; 
		 }
		 if($c!=0)
		 {
		 $values=$c+1;
		 }
	}
	else
	{
		 if($d==0)
		 {
		 $values=1; 
		 }
		 if($d!=0)
		 {
		 $values=$d+1;
		 }
	}		
 
 $from_date=$_GET['from_date'];
 $to_date=$_GET['to_date'];
 $cus_name=$_GET['cus_name'];
 $job_card_num=$_GET['job_card_num'];
 $jobtype1=$_GET['jobtype'];
 $status=$_GET['status'];
 $current_date=date('Y-m-d');
 
 if($from_date!=""){ $from_date1= "DATE_FORMAT(print_date,'%Y-%m-%d')>='$from_date'"; }else{$from_date1="DATE_FORMAT(print_date,'%Y-%m-%d')='$current_date'"; }
 if($to_date!=""){ $to_date1 = "DATE_FORMAT(print_date,'%Y-%m-%d')<='$to_date'";}else{$to_date1="DATE_FORMAT(print_date,'%Y-%m-%d')='$current_date'";}
 if($cus_name!=""){ $cus_name1= "cust_name='$cus_name'"; }else{$cus_name1=''; }
 if($job_card_num!=""){ $job_card_nums= "job_card_no='$job_card_num'"; }else{$job_card_nums=''; }
 if($jobtype1!=""){ $jobtype= "job_type='$jobtype1'"; }else{$jobtype=''; }

$all_value10 = $from_date1."@".$to_date1."@".$cus_name1."@".$jobtype."@".$job_card_nums;
$all_array10 = explode('@',$all_value10);
foreach($all_array10 as $value10)
{ 
if($value10!='')
{
$get_query103 .= $value10." AND ";
}
}	  
// (v1 21-06-2022)
// if($status==0 || $status==''){
//  $sql="select * from printer_production_main where deliv_status='1' and billed_status='0' and job_type='sticker' and $get_query103 p_id!=''   union select * from fusing_production_main where printer_status='1' and billed_status='0'  and $get_query103 p_id!='' order by job_card_no ASC";
//  $sql = "SELECT * FROM (
//     SELECT * FROM printer_production_main 
//     WHERE deliv_status='1' AND billed_status='0' AND {$get_query103} p_id!=''
//     UNION DISTINCT
//     SELECT * FROM fusing_production_main 
//     WHERE printer_status='1' AND billed_status='0' AND {$get_query103} p_id!=''
// ) AS combined_data GROUP BY job_card_no ORDER BY job_card_no ASC";
// }
// else if($status==1)
// {
//  $sql="select * from printer_production_main where deliv_status='1' and billed_status='1'  and job_type='sticker' and $get_query103 p_id!=''   union select * from fusing_production_main where printer_status='1' and billed_status='1'  and $get_query103 p_id!='' order by job_card_no ASC";
// $sql = "SELECT * FROM (
//     SELECT * FROM printer_production_main 
//     WHERE deliv_status='1' AND billed_status='1' AND {$get_query103} p_id!=''
//     UNION DISTINCT
//     SELECT * FROM fusing_production_main 
//     WHERE printer_status='1' AND billed_status='1' AND {$get_query103} p_id!=''
// ) AS combined_data GROUP BY job_card_no ORDER BY job_card_no ASC";

// }

if($status==0 || $status==''){
$sql = "SELECT * FROM (
            SELECT * FROM printer_production_main AS ppm WHERE ppm.deliv_status='1' AND ppm.billed_status='0' AND {$get_query103} ppm.p_id!='' AND NOT EXISTS ( SELECT 1 FROM fusing_production_main AS fpm
                WHERE fpm.job_card_no = ppm.job_card_no AND fpm.billed_status = '1' )

            UNION DISTINCT

            SELECT * FROM fusing_production_main AS fpm WHERE fpm.printer_status='1' AND fpm.billed_status='0' AND {$get_query103} fpm.p_id!='' AND NOT EXISTS ( SELECT 1 FROM printer_production_main AS ppm WHERE ppm.job_card_no = fpm.job_card_no AND ppm.billed_status = '1' )
        ) AS combined_data GROUP BY job_card_no ORDER BY job_card_no ASC";

}
else if($status==1){  
$sql = "SELECT * FROM (
            SELECT * FROM printer_production_main AS ppm WHERE ppm.deliv_status='1' AND ppm.billed_status='1' AND {$get_query103} ppm.p_id!='' AND NOT EXISTS ( SELECT 1 FROM fusing_production_main AS fpm
                WHERE fpm.job_card_no = ppm.job_card_no AND fpm.billed_status = '1' )

            UNION DISTINCT

            SELECT * FROM fusing_production_main AS fpm WHERE fpm.printer_status='1' AND fpm.billed_status='1' AND {$get_query103} fpm.p_id!='' AND NOT EXISTS ( SELECT 1 FROM printer_production_main AS ppm WHERE ppm.job_card_no = fpm.job_card_no AND ppm.billed_status = '1' )
        ) AS combined_data GROUP BY job_card_no ORDER BY job_card_no ASC";
}

//echo $sql;
    $rs=mysql_query($sql);
	$sno=0;
	$from=0;
   		while($rsdata=mysql_fetch_array($rs))
  			{
   				$sno=$sno+1;
				$from=$from+1;
   				$p_id=$rsdata['p_id'];
   				$job_card_no=$rsdata['job_card_no'];
				$print_date=$rsdata['print_date'];
	   			$cust_name=$rsdata['cust_name'];
	   			$job_created=$rsdata['job_created'];
				$cust_po=$rsdata['cust_po'];
	   			$style_no=$rsdata['style_no'];
	   			$style_name=$rsdata['style_name'];
				$combo=$rsdata['combo'];
	   			$printed_qty=$rsdata['printed_qty'];
				$billed_status=$rsdata['billed_status'];
			    $refer=$rsdata['refer'];
?>
<tr>
    <td width="55"  align="center" style="border:1px solid #ddd"><?php echo $from; ?></td>
    <td width="131" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($print_date));?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $job_card_no;?></td>
    <td width="261" align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $cust_name;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;&nbsp;<?php echo $job_created;?></td>
    <td align="left" style="border:1px solid #ddd">&nbsp;<?php echo $style_no;?></td>
    <td align="left" style="border:1px solid #ddd"><?php echo $style_name;?>dfhrj&nbsp;</td>
    <td align="right" style="border:1px solid #ddd"><?php echo number_format($printed_qty,3);?></td>
  <?php if($_GET['status']!=1) { ?>  <td align="center" style="cursor:pointer; border:1px solid #ddd"><a href="javascript:print_Billing_production('production/unbilling/billing_conform.php?jobcard_no=<?php echo $job_card_no;?>&customer_name=<?php echo $cust_name;?>&refer=<?php echo $refer;?>&jobcard_number=<?php echo $values;?>');" style="text-decoration:none;"><?php if($billed_status==1){?><img src="img/billing.png" style="cursor:pointer"  width="20px" height="22px">
      <?php } else {?>
      <img src="img/unbilling.png" style="cursor:pointer"  width="30px" height="25px"><?php }?> </a> </td><?php } ?>
    </tr>
  <?php $tot_print_qty+=$printed_qty; } ?>
  <tr>
    <td align="right" colspan="7" style="border:1px solid #ddd"><strong>Total&nbsp;</strong></td>
    <td align="right" style="border:1px solid #ddd"><strong><?php echo number_format($tot_print_qty,3);?></strong></td> <?php if($_GET['status']!=1) { ?><td style="border:1px solid #ddd"></td><?php } ?>
  </tr>
</table>
</div>
</div>
</div>
</div>
