<?php
	include "db_connection/db_connection.php";
	include "config/config.php";

	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	
	$ot=1;
	if(isset($_GET['ot'])!=''){
		$ot = $_GET['ot'];
	}
	$check_acc  = check_access('40');
?>
<!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=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $PROJECT_TITLE ?></title>

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/po_delivery_add_JS.js"></script>
<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script>
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="js/files/bootstrap.js"></script>
<script type="text/javascript" src="js/files/functions.js"></script>
<script type="text/javascript" src="js/charts/chart.js"></script>
<script type="text/javascript" src="js/charts/hBar_side.js"></script>
</head>

<body onload="document.getElementById('searchlink').focus();">

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->

<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->

<!-- Content begins -->
<div id="content">

<?php include "menus/top_menu.php"; ?>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="#">Dashboard</a></li>
                <li><a href="javascript:;">Purchase Order Delivery</a></li>
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php if($check_acc==1){?>
        <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->  
          <!--<li><a href="po_delivery_add.php" title="Add Purchase Order Delivery" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>-->
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>
            <li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
    	</ul>
    	<!-- Chart --><!-- 6 + 6 -->

    	<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><h6>Purchase Order Delivery List </h6><div class="clear"></div></div>
        <div id="dyn" class="hiddenpars">
        	<a href="javascript:0" id="searchlink" onfocus="foc(this.id)" onblur="stnon(this.id)" class="tOptions" title="Options" ><img src="images/icons/options.png" alt="" /></a>
            <table cellpadding="0" cellspacing="0" border="0" class="dTable" id="dynamic">
            <thead>
            <tr>
            <th width="26">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="80" nowrap>PO No</th>
            <?php if($admin_flagg==1){ ?>
            <th width="180">Company Name</th>
            <?php } ?>
            <th width="104">Company Code</th>
            <th width="83">Order Date</th>
            <th width="67">No of Designs</th>
            <th width="96">No of Finished</th>
            <th width="57">No of Delivered</th>
            <th width="30">Update</th>
            <!--<th width="78">Image</th>-->
            <th width="80">Delivery</th>
			<th width="35">Image</th>
            <!--<th width="61">Status</th>-->
            </tr>
            </thead>
            <tbody>
            <?php
			$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for active inactive
			$flg= base64_encode(base64_encode(base64_encode(2))); 

			$SLCT = "SELECT * FROM po_entry ORDER BY po_entry_id DESC";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			if(mysqli_num_rows($QURY)>0)
			{			
			while($FTCH = mysqli_fetch_object($QURY))
			{

				$po_id	=	base64_encode(base64_encode(base64_encode($FTCH->po_entry_id)));

					$SLCT_t = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det_id) AS tot_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND cancelled = 'no' AND po_entry_id = '$FTCH->po_entry_id'";
					//echo $SLCT_t;
					$QURY_t = mysqli_query($connect,$SLCT_t);
					$FTCH_t = mysqli_fetch_object($QURY_t);

					$SLCT_d = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det_id) AS fin_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND cancelled = 'no' AND fin_status = 'yes' AND po_entry_id = '$FTCH->po_entry_id'";
					$QURY_d = mysqli_query($connect,$SLCT_d);
					$FTCH_d = mysqli_fetch_object($QURY_d);

					$SLCT_dd = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det_id) AS del_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND cancelled = 'no' AND del_status = 'yes' AND po_entry_id = '$FTCH->po_entry_id'";
					$QURY_dd = mysqli_query($connect,$SLCT_dd);
					$FTCH_dd = mysqli_fetch_object($QURY_dd);

					$SLCT_d1 = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det_id) AS fin_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND cancelled = 'no' AND fin_status = 'no' AND po_entry_id = '$FTCH->po_entry_id'";
					$QURY_d1 = mysqli_query($connect,$SLCT_d1);
					$FTCH_d1 = mysqli_fetch_object($QURY_d1);

					$SLCT_d2 = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det_id) AS del_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND cancelled = 'no' AND fin_status = 'yes' AND del_status = 'no' AND po_entry_id = '$FTCH->po_entry_id'";
					$QURY_d2 = mysqli_query($connect,$SLCT_d2);
					$FTCH_d2 = mysqli_fetch_object($QURY_d2);

					$SLCT_tp = "SELECT * FROM party_det WHERE party_det_id = '$FTCH->party_det_id'";
					$QURY_tp = mysqli_query($connect,$SLCT_tp);
					$FTCH_tp = mysqli_fetch_object($QURY_tp);

					$SLCT_tpd = "SELECT * FROM po_delivery WHERE po_entry_id = '$FTCH->po_entry_id'";
					$QURY_tpd = mysqli_query($connect,$SLCT_tpd);

					//$party_id	=base64_encode(base64_encode(base64_encode($FTCH_tp->party_det_id)));
			if($FTCH_d->fin_cnt>0)
			{
				$fin_pd = $FTCH_t->tot_cnt - $FTCH_d->fin_cnt;
				$dl_pd = $FTCH_d->fin_cnt - $FTCH_dd->del_cnt;
					
				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
			?>
            <tr <?php echo $bg ?>>
            <td align="left" style="vertical-align:middle;"><?php echo $loop ?></td>
            <td align="left" nowrap style="vertical-align:middle;"><?php echo $FTCH->po_no; ?></td>
             <?php if($admin_flagg==1){ ?>
            <td align="left" style="vertical-align:middle;">
			<?php //echo $FTCH_tp->cmp_name; ?>
			<?php 
			$name_count = strlen($FTCH_tp->cmp_name);
				$name='';
				if($name_count>15){
					$name = substr($FTCH_tp->cmp_name,0,15)."...";
				} else {
					$name = $FTCH_tp->cmp_name;
				}
				?>
				<?php if($name_count>15){?>
			<div class="tooltip1">
			<?php echo $name;?>
				<span class="tooltiptext1"><?php echo $FTCH_tp->cmp_name;?></span>
			</div>
			<?php } else { ?>
			<?php echo $name;?>
			<?php } ?>

			</td>
            <?php } ?>
            <td align="left" style="vertical-align:middle;"><?php echo $FTCH_tp->party_code; ?></td>
            <td align="left" style="vertical-align:middle;"><?php echo str_replace("-", "/",$FTCH->po_date); ?></td>
            <td align="center" style="vertical-align:middle;"><a id="viewlink1<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(1))) ?>&po_id=<?php echo $po_id ?>" class="an_own"><?php echo $FTCH_t->tot_cnt; ?></a><br><span title="No of Dies for Order Designs">(<?php echo $FTCH_t->tot_pic; ?>)</span></td>

            <td align="center"  style="vertical-align:middle;"><a id="viewlink2<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(2))) ?>&po_id=<?php echo $po_id ?>" class="an_own"><?php echo $FTCH_d->fin_cnt; ?></a>

			<?php if($fin_pd > 0){ ?>
			<a id="viewlink2a<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_pen_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(2))) ?>&po_id=<?php echo $po_id ?>" class="an_own">( <?php echo $fin_pd; ?> )</a>
			<br><span title="No of Dies for Finish Designs">(<?php echo $FTCH_d->tot_pic; ?>)</span>&nbsp;&nbsp;<span title="No of Dies for Finish Pending Designs">(<?php echo $FTCH_d1->tot_pic; ?>)</span>
			<?php } else {  ?>
				<br><span title="No of Dies for Finish Designs">(<?php echo $FTCH_d->tot_pic; ?>)</span>
			<?php } ?>
			</td>
            <td align="center"  style="vertical-align:middle;"><?php if($FTCH_dd->del_cnt>0){?><a id="viewlink3<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(3))) ?>&po_id=<?php echo $po_id ?>" class="an_own"><?php echo $FTCH_dd->del_cnt; ?></a><?php }else{ echo $FTCH_dd->del_cnt;}?>

			<?php if($dl_pd>0){?>
			<a id="viewlink3a<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_pen_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(3))) ?>&po_id=<?php echo $po_id ?>" class="an_own">( <?php echo $dl_pd ?> ) </a>
			<br><span title="No of Dies for Delivery Designs">(<?php echo $FTCH_dd->tot_pic; ?>)</span>&nbsp;&nbsp;<span title="No of Dies for Delivery Pending Designs">(<?php echo $FTCH_d2->tot_pic; ?>)</span>
			<?php } else {  ?>
				<br><span title="No of Dies for Delivery Designs">(<?php echo $FTCH_dd->tot_pic; ?>)</span>
			<?php } ?>
			</td>

			<td align="center"  style="vertical-align:middle;">
			<?php if($FTCH->cancelled == "no"){ ?>
			<?php if($FTCH_dd->del_cnt >0){ 
			$FTCH_tpd = mysqli_fetch_object($QURY_tpd);
			$po_del_id	=	base64_encode(base64_encode(base64_encode($FTCH_tpd->po_delivery_id)));
			if(mysqli_num_rows($QURY_tpd)>1){	?>		
			<a id="upd<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_img.php?po_id=<?php echo $po_id ?>&identy=upd" class="an_own">Cancel</a>
			 <?php }else{ ?>
			 <a id="upd<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_upd.php?po_del_id=<?php echo $po_del_id; ?>&po_id=<?php echo $po_id ?>" class="an_own">Cancel</a>
			 <?php } }else{ echo "----"; } ?>
			<?php }else{ echo "Cancelled"; } ?>
			</td>

            <?php /*?><td class="center"><a href=""><img src="design_images/S.<?php echo $FTCH->imag_ext; ?>" width="60" height="60"/></a></td><?php */?>
            <td class="center" align="center"  style="vertical-align:middle;"><?php if($FTCH_dd->del_cnt != $FTCH_d->fin_cnt){?><a id="viewlink4<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" href="po_delivery_add.php?po_id=<?php echo $po_id ?>" class="an_own">Delivery</a><?php }else{ echo "Delivered"; } ?></td>

			<?php if($FTCH_dd->del_cnt >0){ if(mysqli_num_rows($QURY_tpd)>1){ ?>
           <td align="center" class="center"  style="vertical-align:middle;"><a onfocus="foc(this.id)" onblur="stnon(this.id)" id="upd2<?php echo $loop ?>" href="po_delivery_img.php?po_id=<?php echo $po_id ?>&identy=img" class="an_own">Print</a></td>
            <?php }else{ ?>
			<td width="25" align="center" class="center"  style="vertical-align:middle;"><a onfocus="foc(this.id)" onblur="stnon(this.id)" id="upd2<?php echo $loop; ?>" href="po_delivery_img.php?po_id=<?php echo $po_id; ?>&identy=img" target="_blank" class="an_own">Print</a></td>
			<?php } } else{ ?>
			<td width="12" align="center" class="center">----</td>
			<?php } ?>
			</tr>

            <?php
			$loop ++;
			}
			 }
			 }
			 ?>
            </tbody>
            </table>
        </div>
        </div>
        <div class="fluid"><!-- Media table --></div>
<?php } else {  echo ACCESS_MSG;} ?>
    </div>
    <!-- Main content ends -->

</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
