<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
?>
<!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/tally_JS.js"></script>
<script type="text/javascript" src="js/cnt_chkbox_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.dataTables1.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('listpage').focus();">

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->
    
    
<!-- Content begins -->
<div id="content">
    
<?php include "menus/top_menu.php"; ?>    
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="#">Dashboard</a></li>
                <li><a href="javascript:">Dust Tally</a></li>
                    
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>            
        
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
    
        <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->  
          <!--<li><a href="design_add.php" title="Add Design" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>-->
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>-->
            <li><a href="dust_tally_list.php" id="listpage" title="List Dust Tally" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul>            
  		<?php
		if(isset($_GET['des_name']))
		{
			$des_name = $_GET['des_name'];	
			$des_nm   = base64_decode(base64_decode(base64_decode($des_name)));	
			$flgg=1;
		}
		else
		{
			$des_name = '';
			$des_nm   = '';
			$flgg=0;
		}
		if(isset($_GET['fin_dt']))
		{
			$dt_name = $_GET['fin_dt'];	
			$fin_dt   = base64_decode(base64_decode(base64_decode($dt_name)));	
			$flgg1=1;
		}
		else
		{
			$dt_name = '';
			$fin_dt   = '';
			$flgg1=0;
		}
		
		$page_id= base64_encode(base64_encode(base64_encode(1))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for add		 
					 
		?>

    	<!-- Chart --><!-- 6 + 6 -->
        <form id="validate" name="checklist" class="main" method="post" action="" onsubmit="checkTheBox();">
         <fieldset>
        <div class="fluid">
		<div class="widget">
        
        <div class="formRow">
            <div class="grid3"><label>Soldering Worker:<span class="req">*</span></label></div>
            <div class="grid6 searchDrop ">
                <select data-placeholder="Choose an Employee..." class="select" name="hdes_name" id="hdes_name" style="width:350px;" onchange="reload_page();" onfocus="foc(this.id)" onblur="stnon(this.id)" disabled="disabled">
                    <option value=""></option>
                    <?php
                    $SLCT_E = "SELECT  * FROM emp_det WHERE master_dept_id REGEXP(CONCAT('(^|,)(',5,')(,|$)')) and statu_s='active'"; //HERE THE 5 IS REPRESENTS Soldering DESIGNER ID 
                    //echo $SLCT;
                    $QURY_E = mysqli_query($connect,$SLCT_E);
                    while($FTCH_E = mysqli_fetch_object($QURY_E))
                    {
						$des_id= base64_encode(base64_encode(base64_encode($FTCH_E->emp_det_id)));
                    ?>
                    <option <?php if($des_name == $des_id){ ?> selected="selected" <?php } ?> value="<?php echo $des_id ?>"><?php echo $FTCH_E->name ?></option>
                    <?php
                    }
                    ?>
                        
                </select>
            </div>
            <div class="clear"></div>
        </div>
        </div>
        </div>
        
        <?php
		if($flgg==1)
		{
		?>
    	 	<div class="widget">
            	<div class="whead"><h6>Dust Tally </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>
            		<div style="max-height:700px; overflow-y:auto;">
            			<table cellpadding="0" cellspacing="0" width="100%" class="dTable check" id="checkAll">
							<thead>
								<tr>
									<th width="5%">S.No<span class="sorting" style="display: block;"></span></th>
									<th width="7%">Quanitity</th>
									<th width="10%">Loading Date</th>
									<th width="10%">Loading KDM Weight</th>
									<th width="10%">Loading Weight</th>
									<th width="10%">Finish Date</th>
									<th width="10%">Finish Silver Weight</th>
									<th width="10%">Total Weight</th>
									<th width="10%">Return KDM Weight</th>
									<th width="10%">Runner Weight</th>
									<th width="8%">Wastage</th>							   
								</tr>
							</thead>
            				<tbody>
            				<?php
								$loop=1;
								$tot_wes =0;	
								$tot_load=0;
								$SLCT_TALY = "SELECT * FROM dust_tally WHERE emp_det_id = '$des_nm' AND STR_TO_DATE(tally_date,'%d-%m-%Y')= STR_TO_DATE('$fin_dt','%d-%m-%Y')";	
								//echo $SLCT_TALY;
								$QURY_TALY = mysqli_query($connect,$SLCT_TALY);
								$NUM_TALY  = mysqli_num_rows($QURY_TALY);
								$FTCH_TALY = mysqli_fetch_object($QURY_TALY);
								
								$SLCT_FINN = "SELECT * FROM sol_finishing WHERE emp_det_id = '$des_nm' AND STR_TO_DATE(finishing_date,'%d-%m-%Y')>STR_TO_DATE('$FTCH_TALY->pre_tally_date','%d-%m-%Y') AND STR_TO_DATE(finishing_date,'%d-%m-%Y') <= STR_TO_DATE('$FTCH_TALY->tally_date','%d-%m-%Y') ORDER BY STR_TO_DATE(finishing_date,'%d-%m-%Y') ASC";
								//echo $SLCT_FINN; 
								$QURY_FINN = mysqli_query($connect,$SLCT_FINN);	
								if(mysqli_num_rows($QURY_FINN)>0)
								{
									while($FTCH_FINN = mysqli_fetch_object($QURY_FINN))
									{
										$SLCT_FIN = "SELECT COUNT(design_det_id) AS sol_cnt, SUM(tot_weight) AS fin_wght, SUM(sil_weight) AS sil_wght, SUM(run_weight) AS run_wght, GROUP_CONCAT(design_det_id) AS des_id FROM sol_finishing_des WHERE sol_finishing_id = '$FTCH_FINN->sol_finishing_id'";	
										$QURY_FIN = mysqli_query($connect,$SLCT_FIN);	
										if(mysqli_num_rows($QURY_FIN)>0)
										{
											$FTCH_FIN = mysqli_fetch_object($QURY_FIN);
																							
											$SLCT = "SELECT *,COUNT(design_det_id) AS sol_cnt, SUM(solder_weight) AS load_wght FROM soldering_loading WHERE emp_det_id='$des_nm' AND design_det_id IN($FTCH_FIN->des_id)";
											$QURY = mysqli_query($connect,$SLCT);
											$FTCH = mysqli_fetch_object($QURY);
											
											$SLCT_KDM = "SELECT SUM(kdm_loading_weight) AS lod_wght FROM sol_loading_kdm WHERE sol_loading_kdm_id ='$FTCH->sol_loading_kdm_id'";	
											$QURY_KDM = mysqli_query($connect,$SLCT_KDM);
											if(mysqli_num_rows($QURY_KDM)>0)
											{
												$FTCH_KDM = mysqli_fetch_object($QURY_KDM);
												$lod_kdm = $FTCH_KDM->lod_wght;
											}
											else
											{
												$lod_kdm = 0;
											}
											
															
											if($loop%2 != "0")
												$bg = "gradeX";
											else
												$bg = "class='gradeC'";
												
											$west = $FTCH->load_wght - $FTCH_FIN->sil_wght;
											
											$ddt	=	base64_encode(base64_encode(base64_encode($FTCH_FINN->finishing_date)));
							?>            
											<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"><a href="sol_finishing_view.php?em_id=<?php echo $des_name ?>&fin_dt=<?php echo $ddt; ?>&lod_tim=<?php echo base64_encode(base64_encode(base64_encode(1))); ?>" class="an_own" id="viewlink<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)"><?php echo $FTCH->sol_cnt; ?></a></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->loading_date; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($lod_kdm,2)." g"; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH->load_wght,2)." g"; ?></td>	
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_FINN->finishing_date; ?></td>											
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH_FIN->sil_wght,2)." g"; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH_FIN->fin_wght,2)." g"; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH_FINN->kdm_return_weight,2)." g"; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($FTCH_FIN->run_wght-($FTCH->load_wght - $FTCH_FINN->kdm_return_weight),2)." g"; ?></td>
												<td align="center" style="display:table-cell;vertical-align:middle"><?php echo number_format($west,2)." g"; ?></td>            
											</tr>
            
							<?php
											$tot_wes = $tot_wes+$west;
											$tot_load = $tot_load+$FTCH->load_wght;
											$loop ++;
										}							
									}
								 }
							?>				
            				</tbody>
            			</table> 
            		</div>
				</div>
			</div> 
			<div class="fluid" >
				<div class="widget">
				   <div class="formRow">
						<span class="grid2" style="display:table-cell;vertical-align:middle">Total Wastage Weight&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="tot_wgt" id="tot_wgt" value="<?php echo number_format($FTCH_TALY->was_weight,2); ?>" readonly="" style="width:100px;" /></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle">Recovery Weight&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="dust_wgt" id="dust_wgt" readonly="" style="width:100px;" value="<?php echo number_format($FTCH_TALY->return_weight,2); ?>" /></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle">Final Wastage Weight&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="fin_wgt" id="fin_wgt" readonly="" value="<?php echo number_format($FTCH_TALY->final_weight,2); ?>" style="width:100px;" /></span>
						<div class="clear"></div>
					</div>
				   <div class="formRow">
						<span class="grid2" style="display:table-cell;vertical-align:middle">Total Load Weight&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="tot_lod" id="tot_lod" value="<?php echo number_format($FTCH_TALY->tot_load_weight,2); ?>" readonly="" style="width:100px;" /></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle">Final Wastage Weight&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="tot_wes" value="<?php echo number_format($FTCH_TALY->final_weight,2); ?>" id="tot_wes" readonly="" style="width:100px;"/></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle">Wastage Percentage&nbsp;:&nbsp;&nbsp;<span style="color:#FF0000">*</span></span>
						<span class="grid2" style="display:table-cell;vertical-align:middle"><input type="text" name="wes_per" id="wes_per" value="<?php echo number_format($FTCH_TALY->wastage_percentage,2); ?>" readonly="" style="width:100px;" /></span>
						<div class="clear"></div>
					</div>
					<div class="clear"></div>
				</div>
			</div> 
       
       <?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>
