<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	$code_no = $_GET['code_no'];
	$page_id = base64_decode(base64_decode(base64_decode(base64_decode($code_no))));
	$po_id = base64_decode(base64_decode(base64_decode(base64_decode($_GET['po_id']))));
?>
<!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" />
<!--[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>
<script type="text/javascript">
function foc(ids)
{
	document.getElementById(ids).style.border="2px solid #0099FF";
	
}

function stnon(ids)
{
	document.getElementById(ids).style.border="thin solid #CCCCCC";
}
</script>
<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body onload="document.getElementById('listpage').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:">Pending List</a></li>
                    
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>            
        
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
    
    	<!-- Chart --><!-- 6 + 6 -->
		<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="design_add.php" title="Add Design" 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="pending_list.php?pg_id=<?php echo $code_no; ?>" id="listpage" title="<?php if($page_id == 1){ echo "Order Finishing Pending List"; } else if($page_id == 2){ echo "Order Delivery Pending List";  }  else if($page_id == 4){ echo "Pending Bill List";  }?>" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul> 
		<?php
		if($page_id != 4)
		{
			$SLCT_E = "SELECT * FROM po_entry,party_det WHERE party_det.party_det_id = po_entry.party_det_id AND po_entry.po_entry_id = '$po_id'"; 
			//echo $SLCT_E."<br/>";
			$QURY_E = mysqli_query($connect,$SLCT_E);
			$FTCH_E = mysqli_fetch_object($QURY_E);
		?>
			<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
			<div class="whead"><h6><?php if($page_id == 1){ echo "Order Finish Pending List View"; } else if($page_id == 2){ echo "Order Delivery Pending List View";  } ?> &nbsp;&nbsp;&nbsp;PO.No&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $FTCH_E->po_no?>&nbsp;&nbsp;&nbsp;PO.Date&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo str_replace("-","/",$FTCH_E->po_date)?>&nbsp;&nbsp;&nbsp;Party Code&nbsp;&nbsp;:&nbsp;&nbsp;<?php if($admin_flagg==1){ echo $FTCH_E->party_code."  /  ".$FTCH_E->cmp_name; } else if($admin_flagg==2){ echo $FTCH_E->party_code; } ?></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="90">Design No</th>
				<th width="95" align="center">No of Master</th>
				<th width="68">Image</th>
				<?php
				if($admin_flagg==1)
				{
				?>
				<th width="68">Cost</th>
				<?php
				}
				?>
				</tr>
				</thead>
				<tbody>
				<?php
				$loop = 1;
				if($page_id==1) // THIS IS FOR FINISHED PENDING VIEW 
				{			
					$SLCT = "SELECT * FROM po_entry_det WHERE fin_status ='no' AND cancelled='no' AND po_entry_id = '$po_id'";
				}
				else if($page_id==2) // THIS IS FOR DELIVERED PENDING VIEW 
				{
					$SLCT = "SELECT * FROM po_entry_det WHERE fin_status ='yes' AND del_status= 'no' AND cancelled='no' AND po_entry_id = $po_id";
				}
					$QURY = mysqli_query($connect,$SLCT);
					while($FTCH = mysqli_fetch_object($QURY))
					{
						$SLCT_cd = "SELECT master_cat.master_cat_name,master_cat.cost_vl,design_det.* FROM `master_cat`,`design_det` WHERE design_det.design_det_id = '$FTCH->design_det_id' AND master_cat.master_cat_id = '$FTCH->master_cat_id'"; 
						//echo $SLCT_cd."<br/>";
						$QURY_cd = mysqli_query($connect,$SLCT_cd);
						$FTCH_cd = mysqli_fetch_object($QURY_cd);
						
						$SLCT_E1 = "SELECT * FROM party_cost_det WHERE party_det_id = '$FTCH_E->party_det_id' AND master_cat_id = '$FTCH->master_cat_id' AND updated = 'no'"; 
						$QURY_E1 = mysqli_query($connect,$SLCT_E1);
						$FTCH_E1 = mysqli_fetch_object($QURY_E1);
					
						if($FTCH_cd->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH_cd->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH_cd->mas_fin_ext; }
		
						else if($FTCH_cd->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH_cd->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH_cd->cad_fin_ext; }
					
						else if($FTCH_cd->imag_ext!=''){ $imag = "../design_images/S.".$FTCH_cd->imag_ext; $imag1 = "../design_images/L.".$FTCH_cd->imag_ext; }
											
						
						if($loop%2 != "0")
							$bg = "gradeX";
						else
							$bg = "class='gradeC'";
				?>
			   
							<tr <?php echo $bg ?>>
							<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $loop ?></td>
							<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_cd->master_cat_name." ".$FTCH_cd->design_no; ?></td>
							<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_cd->master_pieces; ?></td>
							<td class="center" align="center"><a href="<?php echo $imag1; ?>" title="<?php echo $FTCH_cd->master_cat_name." ".$FTCH_cd->design_no; ?>" class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a></td> 
							<?php
							if($admin_flagg==1)
							{
							?>
							<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_E1->cost_val; ?></td>
							<?php
							}
							?>
							</tr>            
				<?php
							$loop ++;
						}
				?>
				</tbody>
				</table> 
			</div>
			</div>    
        <?php
		}
		else if($page_id == 4)
		{
			$SLCT_E = "SELECT * FROM party_det WHERE party_det_id = '$po_id'"; 
			//echo $SLCT_E."<br/>";
			$QURY_E = mysqli_query($connect,$SLCT_E);
			$FTCH_E = mysqli_fetch_object($QURY_E);
		?>
			<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
			<div class="whead">
				<h6>Bill Pending List View&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Party Code&nbsp;&nbsp;:&nbsp;&nbsp;<?php echo $FTCH_E->party_code."  /  ".$FTCH_E->cmp_name; ?></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="45">S.No<span class="sorting" style="display: block;"></span></th>
			<th width="118">Delivery Date</th>
            <th width="66">PO No</th>
            <th width="98">Order Date</th>           
            <th width="83">No of Die</th>
            <th width="134">No of Finished</th>
            <th width="99">No of Delivered</th>
            </tr>
            </thead>
            <tbody>
            <?php
			$SLCT = "SELECT * FROM po_delivery,po_entry WHERE po_delivery.po_entry_id = po_entry.po_entry_id AND po_entry.party_det_id='$po_id' ORDER BY po_delivery.po_delivery_id ASC";
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			$i=0;
			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 po_entry_id = '$FTCH->po_entry_id' AND bill_status = 'no' AND po_entry_det.cancelled='no'";
				$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 fin_status = 'yes' AND po_entry_id = '$FTCH->po_entry_id' AND bill_status = 'no' AND po_entry_det.cancelled='no'";
				$QURY_d = mysqli_query($connect,$SLCT_d);
				$FTCH_d = mysqli_fetch_object($QURY_d);
				$SLCT_dd1 = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_delivery_det.design_det_id) AS del_cnt FROM po_entry_det,po_delivery_det,design_det WHERE design_det.design_det_id=po_delivery_det.design_det_id AND po_entry_det.design_det_id = po_delivery_det.design_det_id AND po_delivery_det.cancelled = 'no' AND po_delivery_det.po_delivery_id = '$FTCH->po_delivery_id' AND po_entry_det.bill_status = 'no' AND po_entry_det.po_entry_id = '$FTCH->po_entry_id'";
				$QURY_dd1 = mysqli_query($connect,$SLCT_dd1);
				$FTCH_dd1 = mysqli_fetch_object($QURY_dd1);	
				if($FTCH_dd1->del_cnt > 0)
				{	
					if($loop%2 != "0")
						$bg = "gradeX";
					else
						$bg = "class='gradeC'";
			?>
           
					<tr <?php echo $bg ?>>
						<td align="center"><?php echo $loop ?></td>
						<td align="center"><?php echo str_replace("-","/",$FTCH->delivery_date); ?></td>
						<td align="center"><?php echo $FTCH->po_no; ?></td>
						<td align="center"><?php echo str_replace("-","/",$FTCH->po_date); ?></td>           
						<td align="center"><?php echo $FTCH_t->tot_cnt; ?><br><span title="No of Master Pieces for PO Designs">(<?php echo $FTCH_t->tot_pic; ?>)</span></td>
						<td align="center"><?php echo $FTCH_d->fin_cnt; ?><br><span title="No of Master Pieces for Finish Designs">(<?php echo $FTCH_d->tot_pic; ?>)</span></td>
						<td align="center"><?php echo $FTCH_dd1->del_cnt; ?><br><span title="No of Master Pieces for Delivery Designs">(<?php echo $FTCH_dd1->tot_pic; ?>)</span></td>            
					</tr>
            
            <?php
			$loop ++;
			 }
			}
			 }
			 else
			 {
			 ?>
			  <tr>
              <td align="center" style="display:table-cell;vertical-align:middle;">&nbsp;</td>
              <td align="center">&nbsp;</td>
              <td align="center">&nbsp;</td>
              <td colspan="5" align="center"><font color="#FF0000"><b>Sorry No Po for this Party</b></font> </td>
              <td align="center">&nbsp;</td>
              <td align="center">&nbsp;</td>
            </tr>
			<?php } ?>
            </tbody>
            </table> 
        </div>
        </div>  
			   
		<?php
		}
		?>
        <div class="fluid"><!-- Media table --></div>
        
        
        
    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
