<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
    body {
        height: 842px;
        width: 960px;
        /* to centre page on screen*/
        margin-left: auto;
        margin-right: auto;
    }
    </style>
	
</head>

<body>
<?php
	$po_id	=	base64_decode(base64_decode(base64_decode($_GET['po_id']))); 
	$flg	=	base64_decode(base64_decode(base64_decode($_GET['flg']))); 
	if(isset($_GET['inflg'])){ $inflg = 1; }else{ $inflg = 2; }
	//echo $flg; 

	$SLCTf = "SELECT  * FROM po_entry WHERE po_entry_id = '$po_id'";
	$QURYf = mysqli_query($connect,$SLCTf);		 
	$FTCHf = mysqli_fetch_object($QURYf);
	
	$SLCT_tp = "SELECT * FROM party_det WHERE party_det_id = '$FTCHf->party_det_id'";
	$QURY_tp = mysqli_query($connect,$SLCT_tp);
	$FTCH_tp = mysqli_fetch_object($QURY_tp);
	
	$tot_cnt = '';
	if($flg==1)
	{
		$SLCT = "SELECT  * FROM po_entry_det WHERE cancelled = 'no' AND po_entry_id = '$po_id' ORDER BY po_entry_det_id ASC";
	}
	else if($flg==2)
	{
		$SLCT_t = "SELECT  COUNT(po_entry_det_id) AS tot_cnt FROM po_entry_det WHERE cancelled = 'no' AND po_entry_id = '$po_id'";
		//echo $SLCT_t
		$QURY_t = mysqli_query($connect,$SLCT_t);
		$FTCH_t = mysqli_fetch_object($QURY_t);
		$tot_cnt = $FTCH_t->tot_cnt;
		
		$SLCT = "SELECT  * FROM po_entry_det WHERE po_entry_id = '$po_id' AND cancelled = 'no' AND del_status='yes' ORDER BY po_entry_det_id ASC";
		
	}
	else if($flg==3)
	{
		$po_del_id	=	base64_decode(base64_decode(base64_decode($_GET['po_del_id']))); 
		
		$SLCT_t = "SELECT  COUNT(po_entry_det_id) AS tot_cnt FROM po_entry_det WHERE cancelled = 'no' AND po_entry_id = '$po_id'";
		$QURY_t = mysqli_query($connect,$SLCT_t);
		$FTCH_t = mysqli_fetch_object($QURY_t);
		$tot_cnt = $FTCH_t->tot_cnt;
		
		$SLCT = "SELECT  * FROM po_delivery_det WHERE cancelled = 'no' AND po_delivery_id = '$po_del_id' ORDER BY po_delivery_det_id ASC";
	}
	//echo $SLCT;
	$QURY = mysqli_query($connect,$SLCT);
	
	$des_id = array();
	$des_det_id = array();
	$des_ext = array();
	$i=1;			
	$del_date = '';
	while($FTCH = mysqli_fetch_object($QURY))
	{
		$del_date = $FTCH->post_dt;
		$design_id	=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
		
		$SLCT_t = "SELECT * FROM design_det WHERE design_det_id = '$FTCH->design_det_id'";
		$QURY_t = mysqli_query($connect,$SLCT_t);
		$FTCH_t = mysqli_fetch_object($QURY_t);
		
		$SLCT_cat = "SELECT * FROM  master_cat WHERE  master_cat_id= '$FTCH->master_cat_id'";
		$QURY_cat = mysqli_query($connect,$SLCT_cat);
		$FTCH_cat = mysqli_fetch_object($QURY_cat);
		
		$SLCT_or = "SELECT COUNT(design_det_id) AS or_cnt FROM po_entry_det WHERE cancelled = 'no' AND design_det_id = '$FTCH->design_det_id' AND fin_status = 'no'"; 
		$QURY_or = mysqli_query($connect,$SLCT_or);
		$FTCH_or = mysqli_fetch_object($QURY_or);
		
		$SLCT_st = "SELECT COUNT(design_det_id) AS st_cnt FROM stock_det WHERE st_fin_status = 'no' AND design_det_id = '$FTCH->design_det_id'";
		$QURY_st = mysqli_query($connect,$SLCT_st);
		$FTCH_st = mysqli_fetch_object($QURY_st);
		
		$or_cnt[$i] = $FTCH_or->or_cnt;
		$st_cnt[$i] = $FTCH_st->st_cnt;
		
		$des_det_id[$i] = $FTCH_t->design_det_id;
		$des_id[$i] = $FTCH_cat->master_cat_name." ".$FTCH_t->design_no; 
		/*$des_ext[$i] = $FTCH_t->imag_ext; */
		if($FTCH_t->mas_fin_ext!=''){ $des_ext[$i] = "../mas_fin_images/M.".$FTCH_t->mas_fin_ext; }

		else if($FTCH_t->cad_fin_ext!=''){ $des_ext[$i] = "../cad_fin_images/M.".$FTCH_t->cad_fin_ext; }
		
		else if($FTCH_t->imag_ext!=''){ $des_ext[$i] = "../design_images/M.".$FTCH_t->imag_ext; }
		$i++;
	}
	$ro_vl = 5; //this is important when u change the table column u should change this
	$arr_len = sizeof($des_ext);
	
	if($flg!=1){ $po_die_qty = $tot_cnt; $pen_qty = $po_die_qty-$arr_len;  } else{ $po_die_qty = $arr_len; $pen_qty = '0'; } //this is for po entry qty
	//echo $flg;
	//echo $arr_len."<br/>";
	//echo $po_die_qty;
	if($arr_len > $ro_vl)
	{ 
		$cnt = $arr_len/$ro_vl;
		$cnt = floor($cnt+1);
	}
	else
	{
		$cnt =1;
	}
	//echo $cnt;
?>


            
<table width="960" border="0" align="center" cellspacing="0" style="outline:#000000 solid 1px;">
  <tr >
    <td width="17" >&nbsp;</td>
    <td width="162" >&nbsp;</td>
    <td width="89" >&nbsp;</td>
    <td width="17" >&nbsp;</td>
    <td width="180" >&nbsp;</td>
    <td width="251" >&nbsp;</td>
    <td width="9" >&nbsp;</td>
    <td width="15" >&nbsp;</td>
    <td width="68" >&nbsp;</td>
    <td width="54" >&nbsp;</td>
    <td width="76" >&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3" align="center"><strong>Purchase Order No : <?php echo $FTCHf->po_no; ?></strong></td>
    <td colspan="2" align="center"><strong>Company Code : <?php echo $FTCH_tp->party_code; ?></strong></td>
    <td colspan="1"><strong>Purchase Order Date : <?php echo str_replace("-", "/",$FTCHf->po_date); ?></strong></td>
    <td colspan="5" align="left"><strong>Order Die Quantity : <?php echo $po_die_qty; ?></strong></td>
  </tr>
  
 <?php if($flg!=1){ ?> 
  <tr>
    <td >&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
  </tr>
  <tr>
    <td align="left" style="border-bottom: solid 0px;"></td>
    <td colspan="2" align="left" style="border-bottom: solid 0px;"><strong>Delivery Date : <?php echo str_replace("-", "/",$del_date); ?></strong></td>
    <td style="border-bottom: solid 0px;" align="center">&nbsp;</td>
    <td  colspan="2" align="center" style=" border-bottom: solid 0px;"><strong>Delivery Die Quantity : <?php echo $arr_len; ?></strong></td>
    <!--<td style=" border-bottom: solid 0px;">&nbsp;</td>
    <td style=" border-bottom: solid 0px;"></td>
    <td style=" border-bottom: solid 0px;"></td>-->
    <td colspan="5" style=" border-bottom: solid 0px;"><strong>Pending Die Quantity : <?php echo $pen_qty; ?></strong></td>
  </tr>
   <?php } ?>
  <tr>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
	<td >&nbsp;</td>
  </tr>
 
</table>
  
  <table width="960" border="0" align="center" cellspacing="0" style="outline:#000000 solid 1px;">
	<?php $l=1; for($i=1;$i<=$cnt;$i++) {		
	?>  
	 <tr>
	<?php for($k=1;$k<=$ro_vl;$k++) { 
	
	?>  
	
   <?php /*?> <td align="center" width="96" height="110"><?php if(isset($des_ext[$l])){?>  <img src="design_images/S.<?php echo $des_ext[$l]; ?>" width="70" height="70"/><br /><font style="font-size:10px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif"><?php echo $des_id[$l]; ?></font><?php } ?></td><?php */?>
	 <td align="center" width="165" height="174"><?php if(isset($des_ext[$l])){?>  <img src="<?php echo $des_ext[$l]; ?>" width="138" height="138"/><br /><font style="font-size:12px; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif"><?php echo $des_id[$l]; ?><br /><?php if($flg==1 && $inflg==1){   echo $or_cnt[$l]. " / " .$st_cnt[$l] ; }?></font><?php } ?></td> 
	 <?php $tot_ro = $l % 30 ; if($tot_ro == 0){ ?>
	 <tr>
    <td colspan="10" height="174" style="border-top:solid 1px #000000; border-bottom:solid 1px #000000;">&nbsp;</td>
	</tr>
	
	 
	  <?php } ?>
	  
	<?php $l++; } ?>
	 </tr> 
	
	<?php } ?>
</table>
 
            
</body>
</html>
