<?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';
	}
	
	$flag = 0;
   	$sta_iden = '0';
   	// THIS IS FOR CHECKING THE STAGE NAME
	
	if(isset($_GET['flg']) && $_GET['flg']!='' ) 
	{
		$flg_id 	= 	$_GET['flg'];
		$flg_id1	=	base64_decode(base64_decode(base64_decode(base64_decode($_GET['flg'])))); // this is for getting the value from url				
	}
	else
	{
		$flg_id = '';
		$flg_id1 = '';
	}
	
	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'];
		$cat_enc_id = base64_decode(base64_decode(base64_decode(base64_decode($cat_id)))); 
		
		$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 = '';
		$cat_enc_id = ''; 
		$cat_nm =  '';
		$cat_ex =  '';
	}
	if(isset($_GET['des_yer']) && $_GET['des_yer']!='')
	{
		$des_yr = $_GET['des_yer'];
		$des_yer = base64_decode(base64_decode(base64_decode(base64_decode($des_yr)))); 
		
		$cat_tit = $cat_nm." - ".$des_yer;
	}
	else
	{
		$des_yr = '';
		$des_yer = '';
		$cat_tit = $cat_nm;
	}
	
	$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;
		}
	}
	if($flg_id1==1)
	{
		$tot_flg = 1;
	}
	else if($flg_id1==2 || $flg_id1==3)
	{
		$tot_flg = 2;
	}
	else if($flg_id1==4 || $flg_id1==5)
	{
		$tot_flg = 3;
	}
?>
<!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>Report</title>
		<script type="text/javascript" src="js/prod_analize_JS.js"></script>
		<style>
			.tet_bx{ border:none; background:#FFFFFF;}
		</style>
	</head>
	<body onload="tot_count(<?php echo $tot_flg; ?>);">
		<table width="960" border="0" align="center" style="outline:#000000 solid 1px;">
			<tr><th colspan="10" scope="col">Production/Selling Analize Report</th></tr>
			<tr>
				<td width="20%">&nbsp;</td>
				<td width="20%">&nbsp;</td>
				<td width="20%">&nbsp;</td>
				<td width="20%">&nbsp;</td>
				<td width="20%">&nbsp;</td>
			</tr>
			<?php
			if($flg_id1!=1)
			{
			?>
				<tr>
					<td style="display:table-cell; vertical-align:middle;"><b>Category:</b></td>
					<td style="display:table-cell; vertical-align:middle;"><b><?php echo $cat_tit; if($flg_id1==5){ echo " g"; } ?></b></td>		        
					<td colspan="3" style="display:table-cell; vertical-align:middle;">&nbsp;</td>		        
	  			</tr>
				<tr><td colspan="5">&nbsp;</td></tr>
			<?php
			}
			?>
			<tr>
				<td style="display:table-cell; vertical-align:middle;">From Date: </td>
				<td style="display:table-cell; vertical-align:middle;"><?php echo $fdate; ?></td>
				<td style="display:table-cell; vertical-align:middle;">To Date: </td>
				<td style="display:table-cell; vertical-align:middle;"><?php echo $todate; ?></td>
				<td style="display:table-cell; vertical-align:middle;">Filter:&nbsp;
					<?php if($yea_r!=''){ echo "Year"; } ?>&nbsp;-
					<?php if($mont_h!=''){ echo "Month"; } ?>&nbsp;-
					<?php if($da_y!=''){ echo "Day"; } ?>&nbsp;
				</td>
			</tr>			
			<tr><td colspan="5">&nbsp;</td></tr>
			<tr style="text-align:left">
				<td style="display:table-cell; vertical-align:middle;">Total Design Qty:</td>
				<td style="display:table-cell; vertical-align:middle;"><input type="text" class="tet_bx" id="tot_des" name="tot_des" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px;" />&nbsp;</td>
				<td style="display:table-cell; vertical-align:middle;">Total Billing Qty:</td>
				<td style="display:table-cell; vertical-align:middle;"><input type="text" class="tet_bx" id="tot_sel" name="tot_sel" value="" readonly="readonly" disabled="disabled" style="width:80px; font-size:12px;" />      &nbsp;</td>
				<td style="display:table-cell; vertical-align:middle;">&nbsp;</td>
			</tr>
			<tr><td colspan="5">&nbsp;</td></tr>
		</table>
		<?php
		$tot_des = 0;
		$tot_wgt = 0;
		$tot_sel = 0;
		if($flg_id1==1) // THIS IS PRINT SCREEN FLAGG VALUE FOR BILLING / COLLECTION MONTH WISE
		{
		?>
			<table width="960" border="0" cellspacing="0" align="center" style="outline:#000000 solid 1px;">
				<thead>
					<tr>
						<th width="8%" style="display:table-cell;vertical-align:middle;padding: 3px;">S.No</th>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">Category</th>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design Qty</th>
						<th width="13%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design Qty %</th>
						<th width="18%" style="display:table-cell;vertical-align:middle;padding: 3px;">Cumulative Design Qty</th>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty</th>
						<th width="13%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty %</th>
						<th width="18%" style="display:table-cell;vertical-align:middle;padding: 3px;">Cumulative Billing Qty</th>
					</tr>
				</thead>
				<tbody> 
					<?php
						$loop=1;
						$desCumulative = 0;
						$selCumulative = 0;
						$totDes = '0';
						$totCnt = '0';
						$totWgt = '0';
						$SLCT_BILL = "SELECT BPDD.`master_cat_id`, MC.`master_cat_name`, COUNT(DISTINCT BPDD.`design_det_id`) AS DES_CNT, COUNT(BPDD.`design_det_id`) AS TOT_CNT, 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' ".$dat_str_bill." 
										GROUP BY BPDD.`master_cat_id` ORDER BY COUNT(BPDD.`design_det_id`) DESC";
						$QURY_BILL = mysqli_query($connect,$SLCT_BILL);
						if(mysqli_num_rows($QURY_BILL)>0)
						{
							while($FTCH_BILL = mysqli_fetch_object($QURY_BILL))
							{
								$catNmArray[] = $FTCH_BILL->master_cat_name;
								$catIdArray[] = $FTCH_BILL->master_cat_id;
								$catDsArray[] = $FTCH_BILL->DES_CNT;
								$catTtArray[] = $FTCH_BILL->TOT_CNT;
								$catWtArray[] = $FTCH_BILL->TOT_WHT;
							}
							$totDes = array_sum($catDsArray);
							$totCnt = array_sum($catTtArray);
							$totWgt = array_sum($catWtArray);
							foreach($catIdArray AS $key=>$value)
							{
								$desPercentage = ($catDsArray[$key]/$totDes)*100;
								$desCumulative = $desCumulative+$desPercentage;
								$selPercentage = ($catTtArray[$key]/$totCnt)*100;
								$selCumulative = $selCumulative+$selPercentage;
					?>
    							<tr>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $loop; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $catNmArray[$key]; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $catDsArray[$key]; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo number_format($desPercentage,2); ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo number_format($desCumulative,2); ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $catTtArray[$key]; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo number_format($selPercentage,2); ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo number_format($selCumulative,2); ?></td>
								</tr>	    
					<?php
								$loop++;
							}
						}
					?> 
				</tbody>     
			</table> 
			<input name="tot_design" id="tot_design" type="hidden" value="<?php echo $totDes; ?>" />
			<input name="tot_selling" id="tot_selling" type="hidden" value="<?php echo $totCnt; ?>" />
			<input name="tot_weight" id="tot_weight" type="hidden" value="<?php echo number_format($totWgt,2); ?>" />
		<?php	
		}
		else if($flg_id1==2)
		{
		?>
			<table width="960" border="0" cellspacing="0" align="center" style="outline:#000000 solid 1px;">
				<thead>
					<tr>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">S.No</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design Year</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design Qty</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty</th>
					</tr>
				</thead>
				<tbody>  
					<?php
						$loop=1;
						$desCumulative = 0;
						$selCumulative = 0;
						$SLCT_BILL 	=  "SELECT COUNT(DISTINCT BPDD.`design_det_id`) AS DES_CNT, COUNT(BPDD.`design_det_id`) AS SEL_CNT, EXTRACT(YEAR FROM STR_TO_DATE(SC.show_date,'%d-%m-%Y')) AS DES_YEAR  
											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."' ".$dat_str_bill." GROUP BY EXTRACT(YEAR FROM STR_TO_DATE(SC.show_date,'%d-%m-%Y')) 
											ORDER BY EXTRACT(YEAR FROM STR_TO_DATE(SC.show_date,'%d-%m-%Y')) ASC";
						$QURY_BILL = mysqli_query($connect,$SLCT_BILL);
						if(mysqli_num_rows($QURY_BILL)>0)
						{
							while($FTCH_BILL = mysqli_fetch_object($QURY_BILL))
							{
					?>
    							<tr>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $loop; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->DES_YEAR; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->DES_CNT; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->SEL_CNT; ?></td>
								</tr>	    
					<?php
								$tot_des = $tot_des+$FTCH_BILL->DES_CNT;
								$tot_sel = $tot_sel+$FTCH_BILL->SEL_CNT;
								$loop++;
							}
						}
					?> 
				</tbody>     
			</table> 
			<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="1" />
		<?php
		}
		else if($flg_id1==3)
		{
		?>
			<table width="960" border="0" cellspacing="0" align="center" style="outline:#000000 solid 1px;">
				<thead>
					<tr>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">S.No</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Weight Range</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design Qty</th>
						<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty</th>												
					</tr>
				</thead>
				<tbody>  
					<?php
						$loop=1;
						$desCumulative = 0;
						$selCumulative = 0;
						for($i=1; $i<20; $i++)
						{
							$pre_val = $i-1;
							$cur_val = $i;				            								
							if($i==1)
							{
									$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(DISTINCT BPDD.`design_det_id`) AS DES_CNT, COUNT(BPDD.`design_det_id`) AS SEL_CNT, 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;
							$QURY_BILL = mysqli_query($connect,$SLCT_BILL);
							if(mysqli_num_rows($QURY_BILL)>0)
							{
								$FTCH_BILL = mysqli_fetch_object($QURY_BILL);
								if($FTCH_BILL->SEL_CNT!='0' && $FTCH_BILL->SEL_CNT!='')
								{
					?>
        							<tr>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $loop; ?></td>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $pre_val." - ".$cur_val." g"; ?></td>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->DES_CNT; ?></td>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->SEL_CNT; ?></td>
									</tr>	    
					<?php
									$tot_des = $tot_des+$FTCH_BILL->DES_CNT;
									$tot_sel = $tot_sel+$FTCH_BILL->SEL_CNT;
									$tot_wgt = $tot_wgt+$FTCH_BILL->TOT_WHT;
									$loop++;
								}
							}
						}
					?> 
				</tbody>    
			</table>
			<input name="tot_weight" id="tot_weight" type="hidden" value="<?php echo number_format($tot_wgt,2); ?>" />
			<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="2" />
		<?php
		}
		else if($flg_id1==4)
		{
		?>
			<table width="960" border="0" cellspacing="0" align="center" style="outline:#000000 solid 1px;">
				<thead>
					<tr>
						<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">S.No</th>
						<th width="20%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design No</th>
						<th width="20%" style="display:table-cell;vertical-align:middle;padding: 3px;">Release Date</th>
						<th width="20%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty</th>
						<th width="20%" style="display:table-cell;vertical-align:middle;padding: 3px;">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;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $loop; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $cat_nm." - ".$FTCH_DES->design_no; ?></td>
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->SC_DAT; ?></td>	
									<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->SEL_CNT; ?></td>																
									<td class="center" align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;">
										<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>
			<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="1" /> 
		<?php
		}
		else if($flg_id1==5)
		{
		?>
			<table width="960" border="0" cellspacing="0" align="center" style="outline:#000000 solid 1px;">
				<thead>
					<tr>
							<th width="10%" style="display:table-cell;vertical-align:middle;padding: 3px;">S.No</th>
							<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Design No</th>
							<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">Billing Qty</th>
							<th width="30%" style="display:table-cell;vertical-align:middle;padding: 3px;">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;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $loop; ?></td>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $cat_nm." - ".$FTCH_DES->design_no; ?></td>
										<td align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;"><?php echo $FTCH_BILL->SEL_CNT; ?></td>
										<td class="center" align="center" style="display:table-cell;vertical-align:middle;padding: 3px;border-bottom: 0.1px solid gray;">
											<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>
			<input name="tot_weight" id="tot_weight" type="hidden" value="<?php echo number_format($tot_wgt,2); ?>" />
			<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="2" /> 
		<?php
		}
		?>
	</body>
</html>
