<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	else // THIS IS FOR GETTING PARTY DET ID ROM LOAGIN DET AND PARTY DET TABLE
	{
		$admin_id = $_SESSION['admin_login_id'];
		
		$SLCT_log = "SELECT * FROM login_details,ac_party_det WHERE ac_party_det.party_det_id = login_details.party_det_id AND login_details.admin_id = '$admin_id'";
		//echo $SLCT_log;
		$QURY_log = mysqli_query($connect,$SLCT_log);
		$FTCH_log = mysqli_fetch_object($QURY_log);
		$party_id = '$FTCH_log->party_det_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>

<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body onload="document.getElementById('addpage').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:">Design Reload</a></li>
                    
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>            
        
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
    
    	   <?php
				if(isset($_GET['master_cat_id']))
				{
					$master_cat_id =	$_GET['master_cat_id'];	
					$cat_id		=	base64_decode(base64_decode(base64_decode($_GET['master_cat_id']))); //THIS IS PAGE ID  
					$dis_flagg 	=	1;
				}
				else
				{
					$master_cat_id = '';
					$dis_flagg 	=	2;
					$cat_id		=	'';
				}
			?>
    
        <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="design_add.php" title="Add Design" id="addpage" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>-->
           <li><a href="po_finishing_list.php" title="PO Finishing List" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul>            
    		<form>
            <fieldset>
    		<div class="widget">
				<div class="formRow" >
					<table width="100%">
						<tr>
							<td width="25%" style="display:table-cell; vertical-align:top;">Select Category:</td>
							<td width="75%">
								<div class="searchDrop">
									<select  data-placeholder="" class="select" name="cat_name" id="cat_name" style="width:350px;" onchange="reload_page()" onfocus="foc(this.id)" onblur="stnon(this.id)">
										<option selected="selected" value="">Choose a Category...</option>
										<?php
										$SLCT = "SELECT  * FROM master_cat ORDER BY master_cat_id ASC";
										//echo $SLCT;
										$QURY = mysqli_query($connect,$SLCT);
										while($FTCH = mysqli_fetch_object($QURY))
										{
											$cad_name= base64_encode(base64_encode(base64_encode($FTCH->master_cat_id)));	
											?>
											<option <?php if($cad_name == $master_cat_id){ ?> selected="selected" <?php }?> value="<?php echo $cad_name ?>"><?php echo $FTCH->master_cat_name." - ".$FTCH->cat_expantion; ?></option>
											<?php
										}
										?>
									</select>
								</div> 
							</td>
						</tr>
					</table>
				</div>                            
	            <div class="clear"></div>
	        </div> 
			<?php 
				if($dis_flagg==1)
				{
			?>    		
					<div class="widget" style="display: <?php echo $tot_dis ?>"> <!--style="width:600px; margin-left:150px;"-->
						<div class="whead"><h6>Design 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" width="100%" cellspacing="0" border="0" class="dTable" id="dynamic">
								<thead>
								<tr>
									<th width="5%">S.No<span class="sorting" style="display: block;"></span></th>
									<th width="10%">Design No</th>
									<th width="10%">No of Masters</th>
									<th width="10%">Design Status</th>
									<th width="10%">Stock / Po</th>
									<th width="45%">Party Code</th>
									<th width="10%">View</th>
									<th width="10%">Image</th>
									</tr>
								</thead>
								<tbody>
        						<?php
									//$SLCT = "SELECT piece_loading_id,design_det.design_det_id,design_det.master_cat_id,piece_status,mas_fin_ext,cad_fin_ext,imag_ext,design_no FROM piece_loading,design_det WHERE piece_loading.master_cat_id='$cat_id' AND design_det.design_det_id=piece_loading.design_det_id GROUP BY design_det.design_det_id ORDER BY design_det.design_det_id ASC, piece_loading_id DESC";
									
									//echo
									$SLCT = "SELECT * FROM (SELECT piece_loading_id,design_det.design_det_id, design_det.master_pieces, design_det.master_cat_id,piece_status,mas_fin_ext,cad_fin_ext,imag_ext,design_no FROM piece_loading,design_det WHERE piece_loading.master_cat_id='$cat_id' AND design_det.design_det_id=piece_loading.design_det_id ORDER BY piece_loading_id DESC) AS TBL1 GROUP BY design_det_id ORDER BY master_cat_id ASC,design_det_id ASC";
									//echo "<br>";
									$QURY = mysqli_query($connect,$SLCT);
									$loop=1;
									if(mysqli_num_rows($QURY)>0)
									{			
										while($FTCH = mysqli_fetch_object($QURY))
										{
											$piece_id	=	base64_encode(base64_encode(base64_encode($FTCH->piece_loading_id)));
											$des_id		=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
											//echo 
											$SLCT_d 	= 	"SELECT  * FROM master_cat WHERE master_cat_id = '$FTCH->master_cat_id'";
											//echo "<br>";
											$QURY_d 	= 	mysqli_query($connect,$SLCT_d);
											$FTCH_d 	= 	mysqli_fetch_object($QURY_d);
											//echo
    											$SLCTpcST = "SELECT * FROM `piece_loading` WHERE `master_cat_id` = '$cat_id' AND `design_det_id`='$FTCH->design_det_id' ORDER BY `piece_loading_id` DESC LIMIT 0,1";
											$QURYpcST = mysqli_query($connect,$SLCTpcST);
											$FTCHpcST = 	mysqli_fetch_object($QURYpcST);
											//echo "<br>";
											//if($FTCH->piece_status=='loading')
											if($FTCHpcST->piece_status=='loading')
											{
												$pcs_sts = "Loading";
												//echo
												$SLCT_HIS = "SELECT * FROM piece_loading_history WHERE piece_loading_id='$FTCH->piece_loading_id' ORDER BY piece_loading_history_id DESC";
												//echo "<br>";
												$QURY_HIS = mysqli_query($connect,$SLCT_HIS);
												$FTCH_HIS = mysqli_fetch_object($QURY_HIS);
												if($FTCH_HIS->loading_type=='PO')
												{
													//echo
													$SLCT_HIS2 = "SELECT po_no,party_code,cmp_name FROM po_entry,party_det WHERE po_entry_id='$FTCH_HIS->po_entry_id' AND po_entry.party_det_id=party_det.party_det_id";
													//echo "<br>";
													$QURY_HIS2 = mysqli_query($connect,$SLCT_HIS2);
													$FTCH_HIS2 = mysqli_fetch_object($QURY_HIS2);
													
													$pcs_type = $FTCH_HIS2->po_no;
													if($admin_flagg==1)
					                                {                                
					                                	$party_nm = $FTCH_HIS2->party_code." - ".$FTCH_HIS2->cmp_name;
					                                }
					                                else 
					                                {
					                                	$party_nm = $FTCH_HIS2->party_code;
					                                }													
												}
												else
												{
													$pcs_type = "Stock";
													$party_nm = "--";	
												}
											}
											else
											{
												$pcs_sts = "Box";
												$pcs_type = "--";
												$party_nm = "--";
											}
											
											if($loop%2 != "0")
												$bg = "gradeX";
											else
												$bg = "class='gradeC'";
												
											if($FTCH->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH->mas_fin_ext; }

											else if($FTCH->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH->cad_fin_ext; }
											
											else if($FTCH->imag_ext!=''){ $imag = "../design_images/S.".$FTCH->imag_ext; $imag1 = "../design_images/L.".$FTCH->imag_ext; }
								?>
								            <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_d->master_cat_name." ".$FTCH->design_no; ?></td>
									            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->master_pieces; ?></td>
									            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $pcs_sts; ?></td>
									            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $pcs_type; ?></td>
									            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $party_nm; ?></td>
									           	<td class="center" style="display:table-cell;vertical-align:middle">
									            	<a href="piece_loading_view.php?piece_id=<?php echo $piece_id ?>&des_id=<?php echo $des_id ?>&mas_cat=<?php echo $master_cat_id; ?>" id="viewlink<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)">View</a>
									            </td>
									            <td class="center">
									                <div class="body" align="center">
									                	<a href="<?php echo $imag1; ?>" title="<h2><?php echo $FTCH_d->master_cat_name." ".$FTCH->design_no; ?></h2>" class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a>                
									               </div>             
									            </td>
								            </tr>
        						<?php
											$loop ++;
		 								}
		 							}
								?>
        						</tbody>
        					</table> 
    					</div>
    				</div>  
    		<?php
    			}
    		?>  
			</fieldset>
		</form>
		<div class="fluid"><!-- Media table --></div>
        
        
        
    		</div>
    <!-- Main content ends -->
    
</div>
<script>
	function reload_page() //this is for reloadin the page when selecting the comapny code
	{
		var des_cd = document.getElementById('cat_name').value;
		window.location = 'piece_loading_list.php?master_cat_id='+ des_cd;
	}

	function foc(ids)
	{
		document.getElementById(ids+"_div").style.border="2px solid #0099FF";	
	}

	function stnon(ids)
	{
		document.getElementById(ids+"_div").style.border="thin solid #EFFFFF";
	}
	
</script>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
