<link rel="stylesheet" href="css/font.css" type="text/css" />
<script>
function media_report_print(url)
{
onmouseover650= window.open(url,'onmouseover650','height=580,width=1200,scrollbars=yes,left=50,top=50,toolbar=no,location=no,directories=no,status=no,menubar=no');
}
function media_pending_report_overall_excel(from_date,to_date,job_card_no,buyer_name,type_1,jobtype,jobcard_from, jobcard_to)
{
	
window.location.href="report/media_report/pending_excel.php?from_date="+from_date+"&to_date="+to_date+"&job_card_no="+job_card_no+"&buyer_name="+buyer_name+"&type_1="+type_1+"&jobtype="+jobtype+"&jobcard_to=" + jobcard_to+"&jobcard_from=" + jobcard_from;
}
</script>
<?php error_reporting(0);
/*********************************Get Found Result And Pagination********************************************************/
include("../../include/db.php");

// Get filters
$type_1        = $_GET['type_1'];
$job_card_no   = $_GET['job_card_no'];
$jobcard_from  = $_GET['jobcard_from'];
$jobcard_to    = $_GET['jobcard_to'];
$buyer_name    = $_GET['buyer_name'];
$jobtype       = $_GET['jobtype'];
$from_date     = $_GET['from_date'];
$to_date       = $_GET['to_date'];
$cur_date      = date("Y-m-d");

// ------------------------
// Build Media Sublist Filter
// ------------------------
$mediaFilters = [];

if ($from_date != "") {
    $mediaFilters[] = "DATE_FORMAT(b.media_date,'%Y-%m-%d') >= '$from_date'";
} else {
    $mediaFilters[] = "DATE_FORMAT(b.media_date,'%Y-%m-%d') = '$cur_date'";
}

if ($to_date != "") {
    $mediaFilters[] = "DATE_FORMAT(b.media_date,'%Y-%m-%d') <= '$to_date'";
} else {
    $mediaFilters[] = "DATE_FORMAT(b.media_date,'%Y-%m-%d') = '$cur_date'";
}

if ($job_card_no != "") {
    $mediaFilters[] = "b.jobcard_no = '$job_card_no'";
}

if ($jobcard_from != "" && $jobcard_to != "") {
    $mediaFilters[] = "b.jobcard_no BETWEEN '$jobcard_from' AND '$jobcard_to'";
}

if ($buyer_name != "") {
    $mediaFilters[] = "b.in_cust_name = '$buyer_name'";
}

if ($jobtype != "") {
    $mediaFilters[] = "job_types = '$jobtype'";
}

$mediaWhere = implode(" AND ", $mediaFilters);

// ------------------------
// Build Jobcard Sublist Filter
// ------------------------
$jobcardFilters = [];

if ($from_date != "") {
    $jobcardFilters[] = "DATE_FORMAT(a.entry_time,'%Y-%m-%d') >= '$from_date'";
} else {
    $jobcardFilters[] = "DATE_FORMAT(a.entry_time,'%Y-%m-%d') = '$cur_date'";
}

if ($to_date != "") {
    $jobcardFilters[] = "DATE_FORMAT(a.entry_time,'%Y-%m-%d') <= '$to_date'";
} else {
    $jobcardFilters[] = "DATE_FORMAT(a.entry_time,'%Y-%m-%d') = '$cur_date'";
}

if ($job_card_no != "") {
    $jobcardFilters[] = "a.jobcard_no = '$job_card_no'";
}

if ($jobcard_from != "" && $jobcard_to != "") {
    $jobcardFilters[] = "a.jobcard_no BETWEEN '$jobcard_from' AND '$jobcard_to'";
}

if ($buyer_name != "") {
    $jobcardFilters[] = "a.customer_name = '$buyer_name'";
}

if ($jobtype != "") {
    $jobcardFilters[] = "job_types = '$jobtype'";
}

$jobcardWhere = implode(" AND ", $jobcardFilters);

?>

<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 onclick="javascript:media_pending_report_overall_excel('<?php echo $_GET['from_date']; ?>','<?php echo $_GET['to_date']; ?>','<?php echo $job_card_no; ?>','<?php echo $buyer_name; ?>','<?php echo $type_1; ?>','<?php echo $jobtype; ?>','<?php echo $jobcard_from; ?>','<?php echo $jobcard_to; ?>')" style="float:right"><img  align="right" src="img/excel-icon.png" width="30" height="30" border="0" title="click to export"></a>
        </td> 
<td width="7%" align="center"><a href="javascript:media_report_print('report/media_report/media_pending_report_print.php?from_date=<?php echo $_GET['from_date']; ?>&to_date=<?php echo $_GET['to_date']; ?>&job_card_no=<?php echo $job_card_no;?>&buyer_name=<?php echo $buyer_name; ?>&jobcard_from=<?php echo $jobcard_from; ?>&jobcard_to=<?php echo $jobcard_to; ?>&type_1=<?php echo $type_1; ?>');" 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="100%"  align="center" cellpadding="0" cellspacing="0"  >
<thead>
<tr>
 
 <th height="23" colspan="2"  valign="middle">Pending</th>


</tr>
<tr>   
   
 <th height="23" colspan="2" valign="middle">

<table border="0" width="99%"  align="center" cellpadding="0" cellspacing="0"  >
<tr>
    <th   align="left" >S.No</th>
    <th   align="left" >Date</th>
    <th  align="left" >Job Type</th>
	<th  align="left" >Jobcard No</th>
	<th   align="left" >Buyer Name</th>    
    <th   align="left" >Particulars</th>
	 <th   align="center" >Order Qty</th>
    <th   align="center" >Planed Qty</th>
	 <th   align="center" >Pending Qty</th>
	
 </tr>
 
 </td>
 
 <td colspan="2">
 
   <?php
$i=0;



//$sql="select *,sum(order_qty) as order_qty,sum(plan_qty) as plan_qty  from media_sub_list where $get_query105 id!='' group by  media_particular ASC ";

// $sql="select a.entry_time as media_date,a.particulars as media_particular,a.customer_name as in_cust_name,a.jobcard_no as jobcard_no,a.qty as order_qty,a.jobcard_no as plan_qty,sum(a.jobcard_no)  as totalplanqty from jobcard_sublist as a LEFT JOIN media_sub_list as b ON a.particulars=b.media_particular where $get_query1051 b.jobcard_no IS NULL group by a.particulars 

// UNION

// select b.media_date as media_date,b.media_particular as media_particular,b.in_cust_name as in_cust_name,b.jobcard_no as jobcard_no,b.order_qty as order_qty,b.plan_qty as plan_qty,sum(b.plan_qty)  as totalplanqty from  media_sub_list as b  where $get_query105 b.id!='' group by b.media_particular ";
$sql = "
SELECT 
    a.entry_time AS media_date,
    a.particulars AS media_particular,
    a.customer_name AS in_cust_name,
    a.jobcard_no AS jobcard_no,
    a.qty AS order_qty,
    0 AS plan_qty,
    0 AS totalplanqty
FROM 
    jobcard_sublist AS a
LEFT JOIN 
    media_sub_list AS b ON a.particulars = b.media_particular
WHERE 
    $jobcardWhere AND b.jobcard_no IS NULL
GROUP BY 
    a.particulars, a.entry_time, a.customer_name, a.jobcard_no, a.qty

UNION

SELECT 
    b.media_date AS media_date,
    b.media_particular AS media_particular,
    b.in_cust_name AS in_cust_name,
    b.jobcard_no AS jobcard_no,
    b.order_qty AS order_qty,
    b.plan_qty AS plan_qty,
    SUM(b.plan_qty) AS totalplanqty
FROM 
    media_sub_list AS b
WHERE 
    $mediaWhere 
GROUP BY 
    b.media_date, b.media_particular, b.in_cust_name, b.jobcard_no, b.order_qty, b.plan_qty
";

//echo $sql;

    $rs=mysql_query($sql);
     $rscount=mysql_num_rows($rs);
  if($rscount!='')
  {
  $s_no=0;
      while($rsdata=mysql_fetch_array($rs))
        {
        $jobtype=$rsdata['job_types'];
        $media_date=$rsdata['media_date'];
		$media_particular=$rsdata['media_particular'];
		$customer_name=$rsdata['in_cust_name'];
        $jobcard_no=$rsdata['jobcard_no'];
       
		$order_qty=$rsdata['order_qty'];
		$plan_qty=$rsdata['plan_qty'];
		$totalplanqty =$rsdata['totalplanqty']; 
		$pending_qty=$order_qty-$plan_qty;
        $newpendingqty = $order_qty - $rsdata['totalplanqty'];  

        $sql_3="select customer_name  from jobcard_sublist where jobcard_no='$jobcard_no' ";


        $rs_1=mysql_query($sql_3);
        while($rsdata_1=mysql_fetch_array($rs_1))
        {
          $customer_name_1=$rsdata_1['customer_name'];
        }


        
/********************Filtering F EMBOSS GEL********************************* */ 		
		 $is_f_embosss= 0; 
              $sql_user="select * from  jobcard_main where jobcard_no='$jobcard_no'";

		
              $rs_user=mysql_query($sql_user);
                    while($rsdata_user=mysql_fetch_object($rs_user))
                    { 
                    $fabrictype=$rsdata_user->fabric_type;
                    }
              
               if ($fabrictype == "F EMBOSS GEL   EMBOSING ") {
                 $is_f_embosss = 1;
               }		
          
 /*************************************************************************** */         
        
        if($newpendingqty > 0 && $newpendingqty!=0.00){ 
           $i=$i+1;
    ?>
        <tr>
           <td  align="left" style="border:1px solid #ddd;width: 50px;" ><?php  echo $i; ?>&nbsp;&nbsp;</td>
          <td  height="28" align="left" style="border:1px solid #ddd;width: 100px;" >&nbsp;&nbsp;&nbsp;<?php echo date("d-m-Y",strtotime($media_date)); ?></td>
          <td  align="left" style="border:1px solid #ddd;width: 200px;" ><?php  echo $jobtype; ?>&nbsp;&nbsp;</td>
		  <td  align="left" style="border:1px solid #ddd;width: 150px;" ><?php  echo $jobcard_no; ?>&nbsp;&nbsp;</td>
		   <td  align="left" style="border:1px solid #ddd;width: 200px;" ><?php  echo $customer_name_1; ?>&nbsp;&nbsp;</td> 
         <td  align="left" style="border:1px solid #ddd;width: 200px;" ><?php  echo $media_particular; ?>&nbsp;&nbsp;</td>
         
		  <td  align="right" style="border:1px solid #ddd;width: 100px;" ><?php  echo number_format($order_qty,2); ?>&nbsp;&nbsp;</td>
          <td  align="right" style="border:1px solid #ddd;width: 100px;" ><?php  echo number_format($totalplanqty,2); ?>&nbsp;&nbsp;</td>
		  <!--<td  align="right" style="border:1px solid #ddd;width: 100px;" ><?php  echo number_format($pending_qty,2); ?>&nbsp;&nbsp;</td>-->
		  <td  align="right" style="border:1px solid #ddd;width: 100px;" ><?php  echo number_format($newpendingqty ,2); ?>&nbsp;&nbsp;</td>
     </tr>
      <?php 
       
      $sum_tot1+=$order_qty;
	  $sum_tot2+=$totalplanqty;
// 	  $sum_tot3+=$pending_qty;
      $sum_tot3+=$newpendingqty;
       }
      }
  }
      ?>
         <tr>
       <th height="28" colspan="6" align="right" style="border:1px solid #ddd" ><strong>Total&nbsp;&nbsp;</strong></th>
          <th width="87" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot1,2); ?>&nbsp;&nbsp;</strong></th>
		  <th width="87" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot2,2); ?>&nbsp;&nbsp;</strong></th>
          <th width="87" align="right" style="border:1px solid #ddd" ><strong><?php  echo number_format($sum_tot3,2); ?>&nbsp;&nbsp;</strong></th>
    </tr>
    </table>
 </td>
  