<?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>

<script type="text/javascript" src="js/design_analize_JS.js"></script>
<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="tot_count();">

<!-- 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:">New Design Entry</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['sta_name']) && $_GET['sta_name']!='' ) 
				{
					$mas_stage_id = $_GET['sta_name'];
					$mas_stage_id1 =	base64_decode(base64_decode(base64_decode($_GET['sta_name']))); // this is for getting the value from url
					
					$SLCTs = "SELECT * FROM mas_stage WHERE mas_stage_id ='$mas_stage_id1'";
					$QURYs = mysqli_query($connect,$SLCTs);
					$FTCHs = mysqli_fetch_object($QURYs);
					if($FTCHs->stage_identity =='1') // this is for checking the finishing stage only
					{
						$sta_iden = $FTCHs->stage_identity;
						$empl_name = $FTCHs->emp_lable;								
						
						$flag = 1;
					}	
					
				}
				else
				{
					$mas_stage_id = '';
				}
				
				$emp_qur_str = '';
				//THIS IS FOR CHECKING THE EMPLOYEE NAME
				if(isset($_GET['em_name']) && $_GET['em_name']!='' )
				{
					$emp_id_url = $_GET['em_name'];
					$emp_id_dec = base64_decode(base64_decode(base64_decode($_GET['em_name'])));  
					$emp_qur_str = "AND emp_det_id='$emp_id_dec'";
				}
				else
				{
					$emp_id_url = '';
					$emp_qur_str = '';
				}
				
				
				if(isset($_GET['fdate']) && $_GET['fdate']!='' ){ $fdate = $_GET['fdate'];	}else{ $fdate = ''; }
				//echo $fdate;
				if(isset($_GET['todate']) && $_GET['todate']!='' ){ $todate = $_GET['todate'];	}else{ $todate = ''; }
				
				/*if(isset($_GET['yea_r']) && $_GET['yea_r']!='' ){ $yea_r = 'checked="checked"';	}else{ $yea_r = ''; }
				if(isset($_GET['mont_h']) && $_GET['mont_h']!='' ){ $mont_h = 'checked="checked"';	}else{ $mont_h = ''; }
				if(isset($_GET['da_y']) && $_GET['da_y']!='' ){ $da_y = 'checked="checked"';	}else{ $da_y = ''; }*/
				
				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 = ''; }
				
		?>
    
        <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>-->
           <?php /*?><li><a href="design_cat_add.php?id=<?php echo base64_encode(base64_encode(base64_encode(2)));?>" title="Add Cad Finishing Design" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>   <?php */?>         
          <?php /*?> <li><a href="design_cat_add.php?id=<?php echo base64_encode(base64_encode(base64_encode(1)));?>" title="Add Master Finishing Design" class="tipN"><img src="images/icons/middlenav/upload_color.png" alt="" /></a></li><?php */?>
           <!--<li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
    		<li><a href="design_analize.php?sta_name=<?php echo $mas_stage_id; ?>&em_name=<?php echo ""; ?>&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="Po Ananlize" id="listpage" 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 Stage:</td>
									<td width="75%">
                            		<div class="searchDrop">
                               		 <select  data-placeholder="" disabled="disabled" class="select" name="sta_name" id="sta_name" style="width:350px;" onchange="reload_page()" onfocus="foc(this.id)" onblur="stnon(this.id)">
                                   		 <option selected="selected" value="">Choose a Stage...</option>
                                   			 <?php
												$SLCT = "SELECT  * FROM mas_stage WHERE statu_s='active' ORDER BY mas_stage_id ASC";
												//echo $SLCT;
												$QURY = mysqli_query($connect,$SLCT);
												while($FTCH = mysqli_fetch_object($QURY))
												{
												$ma_st_id = base64_encode(base64_encode(base64_encode($FTCH->mas_stage_id)));	
											?>
                                            <option <?php if($ma_st_id == $mas_stage_id){ ?> selected="selected" <?php }?> value="<?php echo $ma_st_id ?>"><?php echo $FTCH->stage_name; ?></option>
                                            <?php
                                            	}
                                            ?>
                                        
                                </select>
                                
                            </div> 
							</td>
							</tr>
							</table>
							</div>
				<?php if(isset($_GET['sta_name'])){ ?> 
					<input name="flag_js" id="flag_js" type="hidden" value="<?php echo $sta_iden; ?>" /> <!--THIS IS FOR JS FUNCTIONALITY-->
							
							<?php if($flag==1){ ?>
							
							<input name="emp_lable" id="emp_lable" type="hidden" value="<?php echo $FTCHs->emp_lable; ?>" /> <!--THIS IS FOR JS EMPLOYEE LABLE-->
							<div class="formRow" >
							<table width="100%">
								<tr>
									<td width="25%" style="display:table-cell; vertical-align:top;"><?php echo $empl_name; ?>:</td>
									<td width="75%">
                            		<div class="searchDrop">
                               		 <select  data-placeholder="" class="select" name="em_name" id="em_name" style="width:350px;" >
                                   		 <option selected="selected" value="">Choose a <?php echo $empl_name; ?> ...</option>
                                   			 <?php
												$SLCTse = "SELECT * FROM emp_det WHERE histry_mas_dept_id REGEXP(CONCAT('(^|,)(',$FTCHs->master_dept_id,')(,|$)'))";
												$QURYse = mysqli_query($connect,$SLCTse);
												while($FTCHse = mysqli_fetch_object($QURYse))
												{
													$emp_id = base64_encode(base64_encode(base64_encode($FTCHse->emp_det_id)));	
											?>
                                            <option <?php if($emp_id_url == $emp_id){ ?> selected="selected" <?php }?>  value="<?php echo $emp_id ?>"><?php echo $FTCHse->name; ?></option>
                                            <?php
                                            	}
                                            ?>
                                        
                                </select>
                                
                            </div> 
							</td>
							</tr>
							</table>
							</div>
							<?php } ?>
							
							<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" /></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" /></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 ?> /> <label for="yea_r">Year</label></td>
							        <td width="8%"><input id="mont_h" name="filter2" type="checkbox" value="m" <?php echo $mont_h ?> /> <label for="mont_h">Month</label></td>
							        <td width="11%"><input id="da_y" name="filter3" type="checkbox" value="d" <?php echo $da_y ?> /> <label for="da_y">Day</label></td>
							  </tr>
							</table>
							</div>
							
							 <div class="formRow">
           						<input type="button" value="Submit" class="buttonM bBlack formSubmit" onclick="fom_validate1();" style="float: right; margin-left:20px;"/>
                 				<input type="button" value="Reset" class="buttonM bRed" style="float: right; margin-left:20px;" onclick="form_rest();"/>
                			<div class="clear"></div></div>
                            
							<?php } ?>
							
                        <div class="clear"></div>
                    </div> 
					
                                                                         
                            
                       
    	<!-- Chart --><!-- 6 + 6 -->
		<?php if(isset($_GET['fdate']) && $_GET['fdate']!='' || isset($_GET['todate']) && $_GET['todate']!=''){ ?>
		
		 <?php
		 	$design_date = ''; // THIS IS FOR ASIGNING THE COLUMN NAME DYNAMICALLY
		 	if(isset($_GET['des_dt']) && $_GET['des_dt']!='')
			{
		 		$des_st = $_GET['des_dt'];
				if($mas_stage_id1==1){ 
					$design_date = "hand_design_date";  
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==2){ 
					$design_date = "loading_date"; 
					$dat_qr = " AND STR_TO_DATE(loading_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==3){ 
					$design_date = "finishing_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==4){ 
					$design_date = "loading_date"; 
					$dat_qr = " AND STR_TO_DATE(loading_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==5){ 
					$design_date = "finishing_date"; 
					$dat_qr = " AND STR_TO_DATE(finishing_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==6){ 
					$design_date = "loading_date"; 
					$dat_qr = " AND STR_TO_DATE(loading_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==7){ 
					$design_date = "finishing_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==8){ 
					$design_date = "finishing_date"; 
					$dat_qr = " AND STR_TO_DATE(finishing_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==9){ 
					$design_date = "finishing_date";
					$dat_qr = " AND STR_TO_DATE(finishing_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')";  
				}
				else if($mas_stage_id1==10){ 
					$design_date = "finishing_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==11){ 
					$design_date = "finishing_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==12){ 
					$design_date = "finishing_date"; 
					$dat_qr = " AND STR_TO_DATE(finishing_date,'%d-%m-%Y')=STR_TO_DATE('".$des_st."','%d-%m-%Y')"; 
				}
				else if($mas_stage_id1==13)
				{
					$design_date = "loading_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==14)
				{
					$design_date = "finishing_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==15)
				{
					$design_date = "loading_date"; 
					$dat_qr = ""; 
				}
				else if($mas_stage_id1==16)
				{
					$design_date = "loading_date"; 
					$dat_qr = ""; 
				}
			}
			else
			{
				if($mas_stage_id1==1){ $design_date = "hand_design_date";  }else if($mas_stage_id1==2){ $design_date = "loading_date"; }else if($mas_stage_id1==3){ $design_date = "finishing_date"; }else if($mas_stage_id1==4){ $design_date = "loading_date"; }else if($mas_stage_id1==5){ $design_date = "finishing_date"; }else if($mas_stage_id1==6){ $design_date = "loading_date"; }else if($mas_stage_id1==7){ $design_date = "finishing_date"; }else if($mas_stage_id1==8){ $design_date = "finishing_date"; }else if($mas_stage_id1==9){ $design_date = "finishing_date"; }else if($mas_stage_id1==10){ $design_date = "finishing_date"; }else if($mas_stage_id1==11){ $design_date = "finishing_date"; }else if($mas_stage_id1==12){ $design_date = "finishing_date"; }
				else if($mas_stage_id1==13){ $design_date = "loading_date"; }else if($mas_stage_id1==14){ $design_date = "finishing_date"; }else if($mas_stage_id1==15){ $design_date = "loading_date"; }else if($mas_stage_id1==16){ $design_date = "loading_date"; }
				$dat_qr = '';
			}
			
			$dat_str = ''; //THIS IS FOR QUERY STRING
						
			if($fdate!='' && $todate!='')
			{
				if($yea_r!='' && $mont_h!='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r!='' && $mont_h!='' && $da_y==''){ $dat_str = "MONTH(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) BETWEEN MONTH(STR_TO_DATE('$fdate','%d/%m/%Y')) AND MONTH(STR_TO_DATE('$todate','%d/%m/%Y')) AND YEAR(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) BETWEEN YEAR(STR_TO_DATE('$fdate','%d/%m/%Y')) AND YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; }
				
				if($yea_r!='' && $mont_h=='' && $da_y==''){ $dat_str = "YEAR(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) BETWEEN YEAR(STR_TO_DATE('$fdate','%d/%m/%Y')) AND YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; }
				
				if($yea_r=='' && $mont_h=='' && $da_y==''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r=='' && $mont_h!='' && $da_y==''){ $dat_str = "MONTH(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) BETWEEN MONTH(STR_TO_DATE('$fdate','%d/%m/%Y')) AND MONTH(STR_TO_DATE('$todate','%d/%m/%Y')) AND YEAR(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) BETWEEN YEAR(STR_TO_DATE('$fdate','%d/%m/%Y')) AND YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; }
				
				if($yea_r=='' && $mont_h=='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r!='' && $mont_h=='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r=='' && $mont_h!='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') BETWEEN STR_TO_DATE('$fdate','%d/%m/%Y') AND STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
			}
			else if($fdate=='' && $todate!='')
			{
				if($yea_r!='' && $mont_h!='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r!='' && $mont_h!='' && $da_y==''){ $dat_str = "DATE_FORMAT(STR_TO_DATE(".$design_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')"; }
				
				if($yea_r!='' && $mont_h=='' && $da_y==''){ $dat_str = "YEAR(STR_TO_DATE(".$design_date.",'%d-%m-%Y')) = YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; }
				
				if($yea_r=='' && $mont_h=='' && $da_y==''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') <= STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r=='' && $mont_h!='' && $da_y==''){ $dat_str = "DATE_FORMAT(STR_TO_DATE(".$design_date.",'%d-%m-%Y'),'%m-%Y') = DATE_FORMAT(STR_TO_DATE('$todate','%d/%m/%Y'),'%m-%Y')"; }
				if($yea_r=='' && $mont_h=='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r!='' && $mont_h=='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }
				
				if($yea_r=='' && $mont_h!='' && $da_y!=''){ $dat_str = "STR_TO_DATE(".$design_date.",'%d-%m-%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }
			}
			$mass_flg = 1;
			$flgg = 0;
			if($mas_stage_id1==1)
			{
				$SLCT = "SELECT * FROM design_det WHERE ".$dat_str.$emp_qur_str. " ORDER BY STR_TO_DATE(design_date,'%d-%m-%Y'),`design_det_id` ASC";
				$mass_flg = 0;
			}
			else if($mas_stage_id1==2)
			{
				$SLCT = "SELECT * FROM cad_loading WHERE ".$dat_str.$dat_qr.$emp_qur_str." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y'),design_det_id ASC";
				$mass_flg = 0;
			}
			else if($mas_stage_id1==3)
			{
				$SLCT = "SELECT * FROM cad_finishing_des,cad_finishing WHERE cad_finishing_des.cad_finishing_id IN(SELECT cad_finishing_id FROM cad_finishing WHERE ".$dat_str.$emp_qur_str.") AND cad_finishing.cad_finishing_id = cad_finishing_des.cad_finishing_id ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$SLCT_tim = "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`cad_time`))) AS tm_to FROM cad_finishing_des,cad_finishing WHERE cad_finishing_des.cad_finishing_id IN(SELECT cad_finishing_id FROM cad_finishing WHERE ".$dat_str.$emp_qur_str.") AND cad_finishing.cad_finishing_id = cad_finishing_des.cad_finishing_id ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$QURY_tim = mysqli_query($connect,$SLCT_tim);
				$FTCH_tim = mysqli_fetch_object($QURY_tim);
				$tot_tm = $FTCH_tim->tm_to;
				$flgg = 1;
			}
			else if($mas_stage_id1==4)
			{
				$SLCT = "SELECT * FROM cam_loading WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y'),design_det_id ASC";
			}
			else if($mas_stage_id1==5)
			{
				$SLCT = "SELECT * FROM cam_finishing WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$weigh_t = 'Cam Weight';
			}
			else if($mas_stage_id1==6)
			{
				$SLCT = "SELECT * FROM rtv_loading WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y'),design_det_id ASC";
			}
			else if($mas_stage_id1==7)
			{
				$SLCT = "SELECT * FROM rtv_finishing_des,rtv_finishing WHERE rtv_finishing_des.rtv_finishing_id IN(SELECT rtv_finishing_id FROM rtv_finishing WHERE ".$dat_str.$emp_qur_str.") AND rtv_finishing.rtv_finishing_id = rtv_finishing_des.rtv_finishing_id ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
			}
			else if($mas_stage_id1==8)
			{
				$SLCT = "SELECT * FROM wax_finishing WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
			}
			else if($mas_stage_id1==9)
			{
				$SLCT = "SELECT * FROM casting_finishing WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
			}
			else if($mas_stage_id1==10)
			{
				$SLCT = "SELECT * FROM sol_finishing_des,sol_finishing WHERE sol_finishing_des.sol_finishing_id IN(SELECT sol_finishing_id FROM sol_finishing WHERE ".$dat_str.$emp_qur_str.") AND sol_finishing.sol_finishing_id = sol_finishing_des.sol_finishing_id ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$weigh_t = 'Silver Weight';
				$mass_flg = 2;
				$flgg = 0;
			}
			else if($mas_stage_id1==11)
			{
				$SLCT = "SELECT * FROM buf_finishing_des,buf_finishing WHERE buf_finishing_des.buf_finishing_id IN(SELECT buf_finishing_id FROM buf_finishing WHERE ".$dat_str.$emp_qur_str.") AND buf_finishing.buf_finishing_id = buf_finishing_des.buf_finishing_id ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$mass_flg = 2;
			}
			else if($mas_stage_id1==12)
			{
				$SLCT = "SELECT * FROM mas_finishing WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y'),design_det_id ASC";
				$weigh_t = 'Master Weight';
				$mass_flg = 2;
			}
			else if($mas_stage_id1==13)
			{
				$SLCT = "SELECT * FROM silver_loading WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y') ASC";
				$flgg = 0;
			}
			else if($mas_stage_id1==14)
			{
				$SLCT = "SELECT * FROM silver_finishing WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y') ASC";
				$weigh_t = 'Silver Weight';
				$flgg = 0;
			}
			else if($mas_stage_id1==15)
			{
				$SLCT = "SELECT * FROM soldering_loading WHERE ".$dat_str.$dat_qr.$emp_qur_str." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y') ASC";
				$weigh_t = 'Solder Weight';
				$flgg = 1;
			}
			else if($mas_stage_id1==16)
			{
				$SLCT = "SELECT * FROM buf_loading WHERE ".$dat_str.$dat_qr." ORDER BY STR_TO_DATE(loading_date,'%d-%m-%Y') ASC";
				$weigh_t = 'Buffing Weight';
				$mass_flg = 2;
				$flgg = 0;
			}
			//echo $mas_stage_id1;
			//echo $SLCT;
			?>
		
    	<div class="widget" style="display: block"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead">
		
		<h6>Design List</h6>
		
		<h6 style="float:right; margin-right:50px; text-decoration:underline;"><a href="design_analize_print.php?sta_name=<?php echo $_GET['sta_name'] ?>&em_name=<?php echo $_GET['em_name'] ?>&fdate=<?php echo $_GET['fdate'] ?>&todate=<?php echo $_GET['todate'] ?>&yea_r=<?php echo $_GET['yea_r'] ?>&mont_h=<?php echo $_GET['mont_h'] ?>&da_y=<?php echo $_GET['da_y'] ?>&flg=wimg&des_dt=<?php echo $des_st; ?>" target="_blank">With Image</a></h6>
		
		<h6 style="float:right; margin-right:0px;text-decoration:underline;"><a href="design_analize_print.php?sta_name=<?php echo $_GET['sta_name'] ?>&em_name=<?php echo $_GET['em_name'] ?>&fdate=<?php echo $_GET['fdate'] ?>&todate=<?php echo $_GET['todate'] ?>&yea_r=<?php echo $_GET['yea_r'] ?>&mont_h=<?php echo $_GET['mont_h'] ?>&da_y=<?php echo $_GET['da_y'] ?>&flg=womg&des_dt=<?php echo $des_st; ?>" target="_blank">Print</a></h6>
		<?php if($mass_flg!=0){ ?>
		<h6 style="float:right; margin-right:0px"><?php if($mass_flg == 1){ echo "Total No of Pieces"; }else { echo "Total No of Masters"; } ?> : <input type="text" id="tot_die" name="tot_die" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></h6>
        <?php } ?>
        <h6 style="float:right; margin-right:0px">Total Quantity : <input type="text" id="tot_qty" name="tot_qty" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></h6>
		<?php if($mas_stage_id1 == 10) { ?><h6 style="float:right; margin-right:0px">Total Weights : <input type="text" id="tot_wgts" name="tot_wgts" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></h6>
		<?php } ?>
		<?php if($mas_stage_id1 == 3) { ?><h6 style="float:right; margin-right:0px">Total Points : <input type="text" id="tot_pnts" name="tot_pnts" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></h6>
			<h6 style="float:right; margin-right:0px">Total Time : <input type="text" id="tot_tims" name="tot_tims" value="" readonly="readonly" disabled="disabled" style="width:100px; font-size:12px; text-align:center;" /></h6>
		<?php } ?>
		<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</th>
            <th width="100">Design No</th>
            <?php
            if($mass_flg == 1) 
			{
			?>
			<th width="100">No of Pieces</th>
			<?php
			}
			else if($mass_flg == 2) 
			{
			?>
			<th width="100">No of Masters</th>
			<?php
			}
				if($mas_stage_id1 == 3) 
				{
					if($flgg==1)
					{ 
			?>
            			<th width="134"><?php echo $empl_name; ?></th>
			<?php 
					} 
			?>    
                    <th width="92" style="text-transform:capitalize">Points</th>
                    <th width="92" style="text-transform:capitalize"><?php echo  str_replace("_", " ",$design_date); ?> </th>
           			<th width="151">Design Time</th>                   
            <?php 
				} 
				else 
				{ 
			?>
                    <th width="92" style="text-transform:capitalize"><?php echo  str_replace("_", " ",$design_date); ?> </th>
                    <?php if($mas_stage_id1==2){ ?><th width="134">Designer Name</th><?php } ?> 
                    <?php if($mas_stage_id1==5 || $mas_stage_id1==10 || $mas_stage_id1==12 || $mas_stage_id1==14 || $mas_stage_id1==15 || $mas_stage_id1==16){ ?><th width="134"><?php echo $weigh_t; ?></th><?php } ?> 
                    <?php if($flgg==1){ ?><th width="134"><?php echo $empl_name; ?></th><?php } ?>   
            		<th width="151">Design Status</th>
            <?php 
				} 
			?> 
            <th width="140">Image</th>
          	<!--  <th width="138">View/Update</th>-->
           	<!-- <th width="146">Status</th>-->
            </tr>
            </thead>
            <tbody>

			<?php 
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			$pnts = 0;
			$tot_pic=0;
			$wgts = 0;
			if(mysqli_num_rows($QURY)>0)
			{			
			while($FTCH = mysqli_fetch_object($QURY))
			{
				$design_id	=	base64_encode(base64_encode(base64_encode($FTCH->design_det_id)));
				
				$SLCT_dm = "SELECT  * FROM design_det WHERE design_det_id = '$FTCH->design_det_id'";
				$QURY_dm = mysqli_query($connect,$SLCT_dm);
				$FTCH_dm = mysqli_fetch_object($QURY_dm);
				
				if($mass_flg == 1) 
				{
					$mas_pic = $FTCH_dm->no_of_pieces;
				}
				else  if($mass_flg == 2) 
				{
					$mas_pic = $FTCH_dm->master_pieces;
				}
				
				$SLCT_d = "SELECT  * FROM master_cat WHERE master_cat_id = '$FTCH_dm->master_cat_id'";
				$QURY_d = mysqli_query($connect,$SLCT_d);
				$FTCH_d = mysqli_fetch_object($QURY_d);
				
				if($mas_stage_id1 == 3) 
				{
					$SLCT_ds = "SELECT * FROM master_cad_cat WHERE master_cad_cat_id = '$FTCH_dm->master_cad_cat_id'";
					$QURY_ds = mysqli_query($connect,$SLCT_ds);
					$FTCH_ds = mysqli_fetch_object($QURY_ds);
					$pnts = $pnts+$FTCH_ds->cad_points;	
					
					$SLCT_CUR = "SELECT start_dt FROM emp_current_design WHERE emp_det_id = '$FTCH->emp_det_id' AND design_det_id = '$FTCH->design_det_id'";
					$QURY_CUR = mysqli_query($connect,$SLCT_CUR);
					$FTCH_CUR = mysqli_fetch_object($QURY_CUR);
					
					$cat_hrs="";
					$SLCT_cd1 = "SELECT fm_date,to_date,cat_hrs FROM emp_cad_det WHERE master_cad_cat_id='$FTCH_dm->master_cad_cat_id' AND emp_det_id = '$FTCH->emp_det_id'"; 
					//echo $SLCT_cd1."<br>";
					$QURY_cd1 = mysqli_query($connect,$SLCT_cd1);
					$num_rows=mysqli_num_rows($QURY_cd1); 
					if($num_rows>0)
					{
						while($FTCH_cd1= mysqli_fetch_object($QURY_cd1))
						{																							
							if($FTCH_cd1->to_date!="")
							{
								$fm_date = strtotime($FTCH_cd1->fm_date);
								$to_date = strtotime($FTCH_cd1->to_date);
								$po_date = strtotime($FTCH_CUR->start_dt);
								
								if(($fm_date <= $po_date) && ($po_date <= $to_date))
								{
									$cat_hrs = $FTCH_cd1->cat_hrs;
								}
								else
								{
									$cat_hrs = $FTCH_ds->cat_hrs;
								}
							}
							else
							{
								if($FTCH_cd1->fm_date!="")
								{
									$cur_date1 = date("d-m-Y", strtotime($cur_date));
									$fm_date = strtotime($FTCH_cd1->fm_date);
									$po_date = strtotime($FTCH_CUR->start_dt);
									$toddate = strtotime($cur_date1);
									if(($fm_date <= $po_date) && ($po_date <= $toddate))
									{											
										$cat_hrs = $FTCH_cd1->cat_hrs;
									}
									else
									{
										$cat_hrs = $FTCH_ds->cat_hrs;
									}
								}
								else
								{									
									$cat_hrs = $FTCH_ds->cat_hrs;
								}
							}
						}
					}
					else
					{
						$cat_hrs = $FTCH_ds->cat_hrs;
					}
				}
				//echo $cat_hrs."<br>";
							
				if($mas_stage_id1==1){ $dat_e = $FTCH->hand_design_date; }else if($mas_stage_id1==2){ $dat_e = $FTCH->loading_date;  }else if($mas_stage_id1==3){ $dat_e = $FTCH->finishing_date;  }else if($mas_stage_id1==4){ $dat_e = $FTCH->loading_date; }else if($mas_stage_id1==5){ $dat_e = $FTCH->finishing_date; $we_ight = $FTCH->cam_weight;}else if($mas_stage_id1==6){ $dat_e = $FTCH->loading_date; }else if($mas_stage_id1==7){ $dat_e = $FTCH->finishing_date; }else if($mas_stage_id1==8){ $dat_e = $FTCH->finishing_date; }else if($mas_stage_id1==9){ $dat_e = $FTCH->finishing_date; }else if($mas_stage_id1==10){ $dat_e = $FTCH->finishing_date; $we_ight = $FTCH->sil_weight; }else if($mas_stage_id1==11){ $dat_e = $FTCH->finishing_date; }else if($mas_stage_id1==12){ $dat_e = $FTCH->finishing_date; $we_ight = $FTCH->mas_weight;}
				else if($mas_stage_id1==13){ $dat_e = $FTCH->loading_date;}else if($mas_stage_id1==14){ $dat_e = $FTCH->finishing_date; $we_ight = $FTCH->silver_weight;}else if($mas_stage_id1==15){ $dat_e = $FTCH->loading_date; $we_ight = $FTCH->solder_weight;}else if($mas_stage_id1==16){ $dat_e = $FTCH->loading_date; $we_ight = $FTCH->buf_weight;}	
				if($flag==1)
				{
					$SLCT_e = "SELECT * FROM emp_det WHERE emp_det_id = '$FTCH->emp_det_id'";
					$QURY_e = mysqli_query($connect,$SLCT_e);
					$FTCH_e = mysqli_fetch_object($QURY_e);
				}
				if($mas_stage_id1==2)
				{
					if($FTCH->emp_det_id!=0)
					{
						$SLCTse = "SELECT * FROM emp_det WHERE emp_det_id ='$emp_id_dec'";
						$QURYse = mysqli_query($connect,$SLCTse);
						$FTCHse = mysqli_fetch_object($QURYse);
						$emp_nam = $FTCHse->name;
					}
					else
					{
						$emp_nam = 'CAD';
					}
				}
				//echo $FTCH->emp_det_id."<br/>";
										
				
				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
					
				if($FTCH_dm->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH_dm->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH_dm->mas_fin_ext; }

				else if($FTCH_dm->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH_dm->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH_dm->cad_fin_ext; }
				
				else if($FTCH_dm->imag_ext!=''){ $imag = "../design_images/S.".$FTCH_dm->imag_ext; $imag1 = "../design_images/L.".$FTCH_dm->imag_ext; }
			?>
            <tr <?php echo $bg ?>>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $loop ?>
            
            </td>
            <input name="mas_stg_id" id="mas_stg_id" type="hidden" value="<?php echo $mas_stage_id1.",".$mass_flg; ?>" />
            
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->master_cat_name." ".$FTCH_dm->design_no; ?><?php if($FTCH_dm->up_status=="yes"){ echo " ( Old ".$FTCH_dm->no_of_tm_alt." )"; } ?></td>
			<?php 
				if($mass_flg!=0)
				{
			?>
					<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $mas_pic; ?></td>
			<?php
					$tot_pic = $tot_pic+$mas_pic;					
				}
			?>
			<?php
				if($mas_stage_id1 == 3) 
				{
					if($FTCH->cad_time != '' || $FTCH->cad_time != 0)
					{
						$cat_tm = $FTCH->cad_time." / ".$cat_hrs;
					}
					else
					{
						$cat_tm = "00:00 / ".$cat_hrs;
					}
					if($flgg==1)
					{ 
			?> 	
            			<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_e->name; ?></td>
			<?php 
					} 
			?>            
                    <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_ds->cad_points;?></td>
                    <td align="center" style="display:table-cell;vertical-align:middle"><?php echo str_replace("-", "/",$dat_e);?></td>
                    <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $cat_tm; ?></td>
           	<?php
				}
				else
				{
			?>
					<td align="center" style="display:table-cell;vertical-align:middle"><?php echo str_replace("-", "/",$dat_e);?></td>
                    <?php if($mas_stage_id1==2){ ?> <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $emp_nam; ?></td><?php } ?>
					<?php if($mas_stage_id1==5 || $mas_stage_id1==10 || $mas_stage_id1==12 || $mas_stage_id1==14 || $mas_stage_id1==15 || $mas_stage_id1==16){ ?><td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($we_ight,2)." g"; $wgts = $wgts+$we_ight; ?></td><?php } ?>
                    <?php if($flgg==1){ ?> <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_e->name; ?></td><?php } ?>
            		<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_dm->design_status; ?></td>
			<?php				
                }
			?>           
            <td class="center">
                <div class="body" align="center">
                	<a href="<?php echo $imag1; ?>" title="<h2><?php echo $FTCH_d->master_cat_name." ".$FTCH_dm->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 } ?>
    <?php 
		if($mass_flg!=0)
		{
	?>
			<input name="mas_die" id="mas_die" type="hidden" value="<?php echo $tot_pic; ?>" />
	<?php
		}
	?>	
	<input name="tot_cnt" id="tot_cnt" type="hidden" value="<?php echo $loop-1; ?>" />	
    <input name="tot_pn_cnt" id="tot_pn_cnt" type="hidden" value="<?php echo $pnts; ?>" />
    <?php if(isset($mas_stage_id1) && $mas_stage_id1 == 10) { ?>
    <input name="tot_wgt_cnt" id="tot_wgt_cnt" type="hidden" value="<?php echo number_format($wgts,2)." g"; ?>" />   
    <?php } if(isset($mas_stage_id1) && $mas_stage_id1 == 3) { ?>
    <input name="tot_tm_cnt" id="tot_tm_cnt" type="hidden" value="<?php echo $tot_tm; ?>" />	
    <?php } ?>
        </fieldset>
     </form>
        <div class="fluid"><!-- Media table --></div>
        
        
        
    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
