<style type="text/css">
.style20 {
	font-family: Verdana;
	font-size: 12px;
}
.style5 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
}
.style10{ border-top:solid 1px; border-top-color:#999;}
.style11{ border-left:solid 1px; border-left-color:#333333;}
.style12{ border-right:solid 1px; border-right-color:#333333;}

.style4 {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
}
.style23 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-weight: bold;
}
.style27 {font-size: 12px}
.style28 {
	font-size: 16px;
	font-weight: bold;
}
.text {font-family: Verdana; font-size:13px;}
.style29 {	font-family: Verdana;
	font-size: 14px;

}
.stylebottom
{
	

	
	border-bottom:1px solid #999;
}	

.prins {
  border: 1px solid black;
  border-collapse: collapse;
}

</style>  <?php
include("../../include/db.php"); 
error_reporting(0);

 $job_card_no=$_GET['job_card_no'];
 $jobcard_from = $_GET['jobcard_from'];
 $jobcard_to = $_GET['jobcard_to'];


 $buyer_name=$_GET['buyer_name'];
 $item_id4 = isset($_GET['item_name']) ? $_GET['item_name'] : '';
 $sum_tot1 = 0;
$sum_tot2 = 0;
$sum_tot3 = 0;
$get_query105 = "";
$get_query1051 = "";
$i = 0;
 $type_1=$_GET['type_1'];
 
?>
<table width="980" height="30" border="0" align="center"  cellpadding="0" cellspacing="0">
<tr style="height:60">
<td width="157" height="106" align="right" style="font-size:12px;"><img src="../../img/logo_image.png" width="126" height="130"/></td>
<td colspan="5" align="center" valign="top" style=""><strong style="font-size: 30px; color: #06F; padding-top: 5px; width: 80px; font-family: Verdana, sans-serif">SRI AMMAN DIGITAL PRINTS</strong><br />
        <span width="80%" class="title1" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b> DOOR No: 1/2,1/3  KOMBAI THOTTAM MAIN ROAD,</span><br />
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>SELLANDIAMMAN THURAI ROAD,</span><br />
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>TIRUPPUR-641604 TAMILNADU STATE INDIA,</span><br/>
       <span width="80%" class="title00" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Contact Office: 0421-4355333,+91 83442-33555,+91 83442-33888,</span><br/>
       <span width="80%" class="title0" style="font-size:14px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Email Id : sriammandigitalprints@gmail.com/yahoo.com.</span><br/>
    
    <span width="80%" class="title1" style="font-size:18px;font-family:Verdana, sans-serif; font-weight:bold"><b></b>Media Pending Report</span></p></td>
  </tr>
 
  <tr>
<td align="center" colspan="3" height="10px" style="font-family: Verdana, sans-serif; font-size: 14px; font-family: Verdana, sans-serif; font-weight: bold;"></td>
</tr>
<tr><td colspan="3"><table border="0" width="100%"  align="left" cellpadding="0" cellspacing="0"  >

<tr> <td width="250" align="left" class="style4 text" scope="col"><strong>&nbsp;From Date&nbsp;:&nbsp;</strong>
    <?php if($_GET['from_date']!=''){  echo $_GET['from_date'];} else { echo date("d-m-Y"); }?></td>
    <td width="200"  align="left" class="style4 text" scope="col"><strong>To Date&nbsp;:&nbsp;</strong>
    <?php if($_GET['to_date']!=''){  echo $_GET['to_date'];} else { echo date("d-m-Y"); }?>&nbsp;</td>
	 
    <td width="200" align="left" class="style4 text" scope="col">
    <?php 
    if (!empty($_GET['jobcard_from']) || !empty($_GET['jobcard_to'])) {
        echo "<strong>&nbsp;Jobcard From&nbsp;:&nbsp;</strong>";
        echo !empty($_GET['jobcard_from']) ? htmlspecialchars($_GET['jobcard_from']) : "All";
        echo "<strong>&nbsp;&nbsp;To&nbsp;:&nbsp;</strong>";
        echo !empty($_GET['jobcard_to']) ? htmlspecialchars($_GET['jobcard_to']) : "All";
    } else if (!empty($_GET['job_card_no'])) {
        echo "<strong>&nbsp;Jobcard&nbsp;:&nbsp;</strong>" . htmlspecialchars($_GET['job_card_no']);
    } else {
        echo "<strong>&nbsp;Jobcard&nbsp;:&nbsp;</strong>All";
    }
    ?>
</td> 

	</tr><tr>
	 <td width="200"  align="left" class="style4 text" scope="col"><strong>&nbsp;Buyer Name&nbsp;:&nbsp;</strong>
    <?php if($_GET['buyer_name']!=''){  echo $buyer_name;} else { echo "All"; }?></td>
	
    <td width="200"  align="left" class="style4 text" scope="col"><strong>&nbsp;Type&nbsp;:&nbsp;</strong>
    <?php if($_GET['type_1']!=''){  echo $type_1;} else { echo "Purchases"; }?></td>
  </tr>
  <tr>
<td align="center" colspan="3" height="10px" style="font-family: Verdana, sans-serif; font-size: 14px; font-family: Verdana, sans-serif; font-weight: bold;"></td>
</tr></table></td></tr>

  </table></td>
</tr></table>
<table class="prins" width="100%"  align="center" cellpadding="0" cellspacing="0"  >
<thead>
<tr >
 
 <td width="52%" height="23" class="stylebottom style10 text style11 style12" align="center" colspan="16" valign="middle"><strong>Pending</strong></td>
</tr>
<tr class="prins" >
    <td  height="23" colspan="16" valign="middle" class="stylebottom style11 style12">
    
    <tr class="prins">
	<td   width="2%"  align="left" class="text style11" ><strong>&nbsp;S.No</strong></td>
	
   <td  width="5%"  align="left" class="text style11" ><strong>&nbsp;Date</strong></td>
   
     <td  width="5%"  align="left" class="text style11"><strong>Jobcard No</strong></td>
  
  <td  width="15%"  align="left" class="text style11"><strong>Buyer Name</strong></td>
    <td  width="15%"  align="left" class="text style11"><strong>Particulars</strong></td>
   
  
<td width="7%"  align="left" class="text style11"><strong>Order Qty</strong></td>
<td width="7%"  align="left" class="text style11"><strong>Plan Qty</strong></td>
<td  width="7%"  align="left" class="text style11"><strong>Pending Qty</strong></td>
    </tr>
       </td>
    </tr>
<td colspan="8" class="stylebottom style11 style12"  valign="top">
      <?php 
 

$jobtype='';
// 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);

//   echo "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 from jobcard_sublist as a LEFT JOIN media_sub_list as b ON a.jobcard_no=b.jobcard_no where DATE_FORMAT(a.entry_time,'%Y-%m-%d')>='2024-04-01' AND DATE_FORMAT(a.entry_time,'%Y-%m-%d')<='2024-04-13' AND 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 from media_sub_list as b where DATE_FORMAT(b.media_date,'%Y-%m-%d')>='2024-04-01' AND DATE_FORMAT(b.media_date,'%Y-%m-%d')<='2024-04-13' AND 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))
  {
    if (isset($yourArray['job_types'])) {
      // Access the index safely
      $job_types = $yourArray['job_types'];
  } else {
      // Handle the case where 'job_types' is not set
      $job_types = ''; // Or some default value
  }
  
  $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 width="20" align="left" class="text style11" ><?php echo $i; ?> &nbsp;&nbsp;</td>
        <td width="75" height="29" align="left" class="text style11">&nbsp;<?php echo date("d-m-Y",strtotime($media_date)); ?></td>
		 <td width="75" align="left" class="text style11" ><?php echo $jobcard_no; ?> &nbsp;&nbsp;</td>
		 <td width="130" align="left" class="text style11" ><?php echo $customer_name; ?> </td>
		  
       
        <td width="110" align="left" class="text style11">&nbsp;&nbsp;<?php  echo $media_particular; ?>&nbsp;</td>
       
		 <td width="70" align="right" class="text style11" ><?php  echo number_format((float)$order_qty, 2); ?>&nbsp;</td>
        <td width="70" align="right" class="text style11" ><?php  echo number_format((float)$totalplanqty, 2); ?>&nbsp;</td>
		<td width="70" align="right" class="text style11"><?php echo number_format((float)$pending_qty, 2); ?> &nbsp;</td>
		

      </tr>
      <?php $sum_tot1+=$order_qty;
	  $sum_tot2+=$totalplanqty;
	  $sum_tot3+=$newpendingqty;
  			    
  			} 
	} else { ?>
      <tr>
        <td width="92" height="29" align="left" class="text"></td>
        <td width="129" align="left" class="text"   ></td>
        <td width="61" align="left" class="text"  ></td>
        <td width="161" align="left" class="text"  >No Pending</td>
        <td width="61" align="left" class="text" ></td>
      </tr>
      <?php }  ?>
    
   
 
 
    <tr>
         
         <td  align="left" class="text style10"></td>
         <td  align="left"  class="text style10"></td>
         <td  align="left"  class="text style10"></td>
        
          <td  align="left"  class="text style10"></td>
		  <td height="28"  align="right" class="text style10"><strong>Total&nbsp;&nbsp;</strong></td>
        <td height="28"  align="right" class="text style10"><strong><?php  echo number_format($sum_tot1,2); ?></strong></td>
        <td height="28"  align="right" class="text style10"><strong><?php  echo number_format($sum_tot2,2); ?></strong></td>
      
          
          <td width="76" align="right" class="text style10"><strong><?php  echo number_format($sum_tot3,2); ?>&nbsp;&nbsp;</strong></td>
    </tr>
    
  </td>
</table> 

