<?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'";
		$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>
		<script type="text/javascript" src="js/prod_analize_JS.js"></script>
		<link href="css/styles.css" rel="stylesheet" type="text/css" />
		<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="tot_count(3)">
		<!-- 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:">Production/Selling Analyze</a></li>
		                    
		            </ul>
		        </div>
				<?php include "menus/top_left_menu.php"; ?>    
    		</div>
    		<!-- Main content -->
    		<div class="wrapper">    
			<?php
			   	$flag = 0;
			   	$sta_iden = '0';
			   	// THIS IS FOR CHECKING THE STAGE NAME
				if(isset($_GET['fdate']) && $_GET['fdate']!='' ){ $fdate = $_GET['fdate'];	}else{ $fdate = ''; }
				if(isset($_GET['todate']) && $_GET['todate']!='' ){ $todate = $_GET['todate'];	}else{ $todate = ''; }				
				if(isset($_GET['yea_r']) && $_GET['yea_r']!='' ){ $yea_r = 'checked="checked"'; $y_r = $_GET['yea_r'];}else{ $yea_r = ''; $y_r = '';}
				if(isset($_GET['mont_h']) && $_GET['mont_h']!='' ){ $mont_h = 'checked="checked"'; $m_h = $_GET['mont_h'];}else{ $mont_h = ''; $m_h = ''; }
				if(isset($_GET['da_y']) && $_GET['da_y']!='' ){ $da_y = 'checked="checked"'; $d_y = $_GET['da_y'];}else{ $da_y = ''; $d_y = ''; }				
				
				if(isset($_GET['cad_id']) && $_GET['cad_id']!='')
				{
					$cat_id = $_GET['cad_id'];
					$pg_flg = $_GET['pg_flag'];
					$des_yr = $_GET['des_yer'];
					$cat_enc_id = base64_decode(base64_decode(base64_decode(base64_decode($cat_id)))); 
					$pg_flag = base64_decode(base64_decode(base64_decode(base64_decode($pg_flg)))); 
					$des_yer = base64_decode(base64_decode(base64_decode(base64_decode($des_yr)))); 
					
					$SLCT_MAS = "SELECT master_cat_name, cat_expantion FROM master_cat WHERE master_cat_id='$cat_enc_id'";
					$QURY_MAS = mysqli_query($connect,$SLCT_MAS);
					$FTCH_MAS = mysqli_fetch_object($QURY_MAS);					
					$cat_nm =  $FTCH_MAS->master_cat_name;
					$cat_ex =  $FTCH_MAS->cat_expantion;
				}
				else
				{
					$cat_id = '';
					$pg_flg = '';
					$cat_enc_id = ''; 
					$des_yr = '';
					$pg_flag = ''; 
					$cat_nm =  '';
					$cat_ex =  '';
					$des_yer = '';
				}
			?>    
	        	<ul class="middleNavR">
		            <li><a href="prod_sell_analize_view.php?cad_id=<?php echo $cat_id; ?>&pg_flag=<?php echo $pg_flg; ?>&fdate=<?php echo $fdate; ?>&todate=<?php echo $todate; ?>&yea_r=<?php echo $y_r; ?>&mont_h=<?php echo $m_h; ?>&da_y=<?php echo $d_y; ?>" title="Analyze List" id="listpage" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
		        </ul>           
	    		<form id="acc_dat" name="acc_dat" class="main" method="post" action="acc_report.php" target="_blank">		
	            	<fieldset>
	    				<div class="widget">
	    					<div class="formRow" >
								<table width="100%">
									<tr>
										<td width="10%" style="display:table-cell; vertical-align:middle;"><b>Category:</b></td>
										<td width="90%"><b><?php echo $cat_nm." - ".$des_yer; if($pg_flag==2){ echo " g"; } ?></b></td>
								        
						  			</tr>
								</table>
								<div class="clear"></div>
							</div>
            				<div class="formRow" >	            				
								<table width="100%">
									<tr>
										<td width="9%" style="display:table-cell; vertical-align:middle;">From Date:</td>
										<td width="22%"><div class="grid6"><input type="text" name="fdate" id="fdate" value="<?php echo $fdate ?>" class="datepicker" disabled="" /></div></td>
								        <td width="9%" style="display:table-cell; vertical-align:middle;">To Date:</td>
								        <td width="23%"><div class="grid6"><input type="text" name="todate" id="todate" value="<?php echo $todate ?>" class="datepicker" disabled="" /></div></td>
								        <td width="10%" style="display:table-cell; vertical-align:middle;">Filter:</td>
								        <td width="8%"><input id="yea_r"  name="filter" type="checkbox" value="y" <?php echo $yea_r ?> disabled=""/> <label for="yea_r">Year</label></td>
								        <td width="8%"><input id="mont_h" name="filter2" type="checkbox" value="m" <?php echo $mont_h ?> disabled="" /> <label for="mont_h">Month</label></td>
								        <td width="11%"><input id="da_y" name="filter3" type="checkbox" value="d" <?php echo $da_y ?> disabled="" /> <label for="da_y">Day</label></td>
						  			</tr>
								</table>
								<div class="clear"></div>
							</div>					
                        	<div class="clear"></div>
                    	</div> 
                    	<?php if(isset($_GET['fdate']) && $_GET['fdate']!='' || isset($_GET['todate']) && $_GET['todate']!=''){ ?>	
	                    	<input type="hidden" value="<?php echo $_GET['fdate']; ?>" name="std" id="std" />
							<input type="hidden" value="<?php echo $_GET['todate']; ?>" name="edd" id="edd" />
							<input type="hidden" value="<?php echo $_GET['yea_r']; ?>" name="yr" id="yr" />
							<input type="hidden" value="<?php echo $_GET['mont_h']; ?>" name="mnt" id="mnt" />
							<input type="hidden" value="<?php echo $_GET['da_y']; ?>" name="dty" id="dty" />
							<input type="hidden" value="<?php echo $_GET['todate']; ?>" name="edd" id="edd" />
							<input type="hidden" value="" name="par_id" id="par_id" />
							<?php
								$billing_date = "REPLACE(BD.bill_date,'/','-')"; 
								$dat_str_bill = ''; //THIS IS FOR QUERY STRING								
								if($fdate!='' && $todate!='')
								{
									$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; 
									$flgg=1;				
								}
								else if($fdate=='' && $todate!='')
								{
									if($yea_r!='' && $mont_h!='' && $da_y!='')
									{ 
										$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$flgg = 1;				
									}									
									else if($yea_r!='' && $mont_h!='' && $da_y=='')
									{
										$vl = explode("/",$todate);
										$todat_vl = $vl[2]."-".$vl[1]."-".$vl[0];
									 	$dat_str_bill = "AND DATE_FORMAT(STR_TO_DATE(".$billing_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$flgg = 1;					
									}									
									else if($yea_r!='' && $mont_h=='' && $da_y=='')
									{ 
										$vl = explode("/",$todate);
										$todat_vl = ($vl[2]-1)."-12-31";
										$dat_str_bill = "AND YEAR(STR_TO_DATE(".$billing_date.",'%d-%m-%Y')) = YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; 				
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h=='' && $da_y=='')
									{ 
										$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') <= STR_TO_DATE('$todate','%d/%m/%Y')"; 				
										$flgg = 0;
									}									
									else if($yea_r=='' && $mont_h!='' && $da_y=='')
									{ 
										$vl = explode("/",$todate);
										$todat_vl = $vl[2]."-".$vl[1]."-".$vl[0];
										$dat_str_bill = "AND DATE_FORMAT(STR_TO_DATE(".$billing_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')";  
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h=='' && $da_y!='')
									{ 
										$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$flgg = 1;
									}									
									else if($yea_r!='' && $mont_h=='' && $da_y!='')
									{ 
										$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 
										$flgg = 1;
									}									
									else if($yea_r=='' && $mont_h!='' && $da_y!='')
									{ 
										$dat_str_bill = "AND STR_TO_DATE(".$billing_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; 				
										$flgg = 1;
									}
								}
								$tot_des = 0;
								$tot_wgt = 0;
								$tot_sel = 0;
								if($pg_flag==1)
								{										
							?>
			    					<div class="widget" style="display: block">
			        					<div class="whead">
			        						<h6>Production / Selling Report</h6>
			        						<ul class="titleToolbar">
									            <li><h6 style=" margin-right:0px; text-align:center;">Total Design Qty&nbsp;&nbsp;&nbsp;<input class="dataNumGrey" type="text" id="tot_des" name="tot_des" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:right; padding-right: 5px; margin: 0;" /></h6></li>									            
									        	<li><h6 style=" margin-right:0px; text-align:center;">Total Billing Qty&nbsp;&nbsp;&nbsp;<input class="dataNumGrey" type="text" id="tot_sel" name="tot_sel" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:right; padding-right: 5px; margin: 0;" /></h6></li>
							            		<li><h6 style=" margin-right:42px; text-align:center;"><a href="prod_sell_analize_print.php?des_yer=<?php echo $des_yr; ?>&cad_id=<?php echo $cat_id; ?>&flg=<?php echo base64_encode(base64_encode(base64_encode(base64_encode('4')))); ?>&fdate=<?php echo $fdate; ?>&todate=<?php echo $todate; ?>&yea_r=<?php echo $y_r; ?>&mont_h=<?php echo $m_h; ?>&da_y=<?php echo $d_y; ?>" target="_blank">Print</a></h6></li>									        	
									        </ul>
			        						<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 width="677" border="0" cellpadding="0" cellspacing="0" class="dTable" id="dynamic">
			            						<thead>
			            							<tr>
														<th width="10%">S.No<span class="sorting" style="display: block;"></span></th>
														<th width="20%">Design No</th>
														<th width="20%">Release Date</th>
														<th width="20%">Billing Qty</th>
														<th width="20%">Image</th>
													</tr>
			            						</thead>
			            						<tbody>  
			            							<?php
			            								$loop=1;
			            								$desCumulative = 0;
			            								$selCumulative = 0;
			            								$SLCT_BILL = "SELECT COUNT(BPDD.`design_det_id`) AS SEL_CNT, SC.`design_det_id`, REPLACE(SC.show_date,'-','/') AS SC_DAT 
															FROM `billing_det` BD INNER JOIN `billing_po_det` BPD ON BPD.`billing_det_id`=BD.`billing_det_id` 
															INNER JOIN `billing_po_design_det` BPDD ON BPDD.`billing_po_det_id`=BPD.`billing_po_det_id`
															INNER JOIN `show_case` SC ON SC.`design_det_id`=BPDD.`design_det_id` 
															INNER JOIN `mas_finishing` MF ON MF.`design_det_id`=BPDD.`design_det_id`
															WHERE BD.`cancelled`='no' AND BPD.`cancelled`='no' AND BPDD.`cancelled`='no' AND MF.`up_status`='no'
															AND BPDD.`master_cat_id` = '".$cat_enc_id."' 
															AND BPDD.`master_cat_id` = SC.`master_cat_id`
															AND EXTRACT(YEAR FROM STR_TO_DATE(SC.show_date,'%d-%m-%Y'))='".$des_yer."' ".$dat_str_bill."
															GROUP BY SC.design_det_id
															ORDER BY STR_TO_DATE(SC.show_date,'%d-%m-%Y'), SC.design_det_id ASC";
	            										$QURY_BILL = mysqli_query($connect,$SLCT_BILL);
			            								if(mysqli_num_rows($QURY_BILL)>0)
			            								{
			            									while($FTCH_BILL = mysqli_fetch_object($QURY_BILL))
			            									{
			            										$SLCT_DES = "SELECT design_no,mas_fin_ext,cad_fin_ext,imag_ext FROM design_det WHERE design_det_id='$FTCH_BILL->design_det_id'";
																$QURY_DES = mysqli_query($connect,$SLCT_DES);
																$FTCH_DES = mysqli_fetch_object($QURY_DES);
																
																if($FTCH_DES->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH_DES->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH_DES->mas_fin_ext;  }

																else if($FTCH_DES->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH_DES->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH_DES->cad_fin_ext; }
																
																else if($FTCH_DES->imag_ext!=''){ $imag = "../design_images/S.".$FTCH_DES->imag_ext; $imag1 = "../design_images/L.".$FTCH_DES->imag_ext; }
			            							?>
						            							<tr>
																	<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 $cat_nm." - ".$FTCH_DES->design_no; ?></td>
																	<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_BILL->SC_DAT; ?></td>	
																	<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_BILL->SEL_CNT; ?></td>																
																	<td class="center" align="center">
																		<div class="body" align="center">
													                		<a href="<?php echo $imag1; ?>" title="<h2><?php echo $cat_nm." ".$FTCH_DES->design_no; ?></h2>" class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a>
													                	</div>
													                </td>
																</tr>	    
													<?php
																$tot_des = $tot_des+1;
																$tot_sel = $tot_sel+$FTCH_BILL->SEL_CNT;
																$loop++;
															}
														}
													?> 
			            						</tbody>    
			            					</table> 
			        					</div>
			        				</div>
	        			<?php 
	        					}
	        					else if($pg_flag==2)
	        					{
	        			?>
	        						<div class="widget" style="display: block">
			        					<div class="whead">
			        						<h6>Production / Selling Report</h6>
			        						<ul class="titleToolbar">
									            <li><h6 style=" margin-right:0px; text-align:center;">Total Design Qty&nbsp;&nbsp;&nbsp;<input class="dataNumGrey" type="text" id="tot_des" name="tot_des" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:right; padding-right: 5px; margin: 0;" /></h6></li>									            
									        	<li><h6 style=" margin-right:0px; text-align:center;">Total Billing Qty&nbsp;&nbsp;&nbsp;<input class="dataNumGrey" type="text" id="tot_sel" name="tot_sel" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:right; padding-right: 5px; margin: 0;" /></h6></li>
							            		<li><h6 style=" margin-right:42px; text-align:center;"><a href="prod_sell_analize_print.php?des_yer=<?php echo $des_yr; ?>&cad_id=<?php echo $cat_id; ?>&flg=<?php echo base64_encode(base64_encode(base64_encode(base64_encode('5')))); ?>&fdate=<?php echo $fdate; ?>&todate=<?php echo $todate; ?>&yea_r=<?php echo $y_r; ?>&mont_h=<?php echo $m_h; ?>&da_y=<?php echo $d_y; ?>" target="_blank">Print</a></h6></li>
									        </ul>
			        						<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 width="677" border="0" cellpadding="0" cellspacing="0" class="dTable" id="dynamic">
			            						<thead>
			            							<tr>
														<th width="10%">S.No<span class="sorting" style="display: block;"></span></th>
														<th width="30%">Design No</th>
														<th width="30%">Billing Qty</th>
														<th width="30%">Image</th>
													</tr>
			            						</thead>
			            						<tbody>  
			            							<?php
			            								$loop=1;
			            								
			            								$var_rslt = explode("-",$des_yer);
			            								$pre_val = $var_rslt[0];
		            									$cur_val = $var_rslt[1];				            								
		            									if($pre_val==0)
		            									{
															$wt_rng = " AND MF.`mas_weight` < ".$cur_val;
														}
														else
														{
															$wt_rng = " AND MF.`mas_weight` >=".$pre_val." AND MF.`mas_weight` < ".$cur_val;
														}
			            								$SLCT_BILL = "SELECT COUNT(BPDD.`design_det_id`) AS SEL_CNT, BPDD.`design_det_id`, MF.`mas_weight`, SUM(MF.`mas_weight`) AS TOT_WHT
																	FROM `billing_det` BD INNER JOIN `billing_po_det` BPD ON BPD.`billing_det_id`=BD.`billing_det_id` 
																	INNER JOIN `billing_po_design_det` BPDD ON BPDD.`billing_po_det_id`=BPD.`billing_po_det_id`
																	INNER JOIN `master_cat` MC ON MC.`master_cat_id` = BPDD.`master_cat_id`
																	INNER JOIN `mas_finishing` MF ON MF.`design_det_id`=BPDD.`design_det_id`
																	WHERE BD.`cancelled`='no' AND BPD.`cancelled`='no' AND BPDD.`cancelled`='no' AND MF.`up_status`='no'
																	AND MC.`master_cat_id`='".$cat_enc_id."' ".$wt_rng." ".$dat_str_bill."
																	GROUP BY BPDD.`design_det_id` ORDER BY BPDD.`design_det_id` ASC";
		            									$QURY_BILL = mysqli_query($connect,$SLCT_BILL);
			            								if(mysqli_num_rows($QURY_BILL)>0)
			            								{
			            									while($FTCH_BILL = mysqli_fetch_object($QURY_BILL))
			            									{
			            										$SLCT_DES = "SELECT design_no,mas_fin_ext,cad_fin_ext,imag_ext FROM design_det WHERE design_det_id='$FTCH_BILL->design_det_id'";
																$QURY_DES = mysqli_query($connect,$SLCT_DES);
																$FTCH_DES = mysqli_fetch_object($QURY_DES);
																
																if($FTCH_DES->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH_DES->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH_DES->mas_fin_ext;  }

																else if($FTCH_DES->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH_DES->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH_DES->cad_fin_ext; }
																
																else if($FTCH_DES->imag_ext!=''){ $imag = "../design_images/S.".$FTCH_DES->imag_ext; $imag1 = "../design_images/L.".$FTCH_DES->imag_ext; }
			            							?>
						            							<tr>
																	<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 $cat_nm." - ".$FTCH_DES->design_no; ?></td>
																	<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_BILL->SEL_CNT; ?></td>
																	<td class="center" align="center">
																		<div class="body" align="center">
													                		<a href="<?php echo $imag1; ?>" title="<h2><?php echo $cat_nm." ".$FTCH_DES->design_no; ?></h2>" class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a>
													                	</div>
													                </td>
																</tr>	    
													<?php
																$tot_des = $tot_des+1;
																$tot_sel = $tot_sel+$FTCH_BILL->SEL_CNT;
																$tot_wgt = $tot_wgt+$FTCH_BILL->TOT_WHT;
																$loop++;
															}
														}
													?> 
			            						</tbody>    
			            					</table> 
			        					</div>
			        				</div>
	        			<?php
								} 
						?>
								<input name="tot_weight" id="tot_weight" type="hidden" value="<?php echo number_format($tot_wgt,2); ?>" />
						<?php		
							}
	        			?>	
	        			<input name="tot_design" id="tot_design" type="hidden" value="<?php echo $tot_des; ?>" /> 
	        			<input name="tot_selling" id="tot_selling" type="hidden" value="<?php echo $tot_sel; ?>" />
	        			<input name="flag_des" id="flag_des" type="hidden" value="<?php echo $pg_flag; ?>" /> 
        			</fieldset>
     			</form>
        		<div class="fluid"><!-- Media table --></div>       
    		</div>
    		<!-- Main content ends -->    
		</div>
		<!-- Content ends -->
	</body>
</html>
