<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
?>
<div class="wrapper">
	<?php
        $page_id = base64_encode(base64_encode(base64_encode(base64_encode(1))));
        $des_no  = base64_decode(base64_decode(base64_decode(base64_decode($_GET['des_id']))));
        $emp_ad_id  = base64_decode(base64_decode(base64_decode(base64_decode($_GET['emp_ad_id']))));
        $emp_cur_id  = base64_decode(base64_decode(base64_decode(base64_decode($_GET['emp_cur_id']))));
        
        $SLCT_CAD = "SELECT * FROM emp_current_design,design_det WHERE design_det.design_det_id = emp_current_design.design_det_id AND emp_current_design.design_det_id = '$des_no' AND emp_current_design.emp_det_id='$emp_ad_id' AND emp_current_design.emp_current_design_id='$emp_cur_id'";
        $QURY_CAD = mysqli_query($connect,$SLCT_CAD);
        $FTCH_CAD = mysqli_fetch_object($QURY_CAD);
        
        $cur_ad_id  = base64_encode(base64_encode(base64_encode(base64_encode($FTCH_CAD->emp_current_design_id))));
        
        $SLCT_CURR_TIM = "SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time_taken` ) ) ) AS tot_time FROM emp_current_design_det WHERE emp_current_design_id = '$FTCH_CAD->emp_current_design_id'";
        $QURY_CURR_TIM = mysqli_query($connect,$SLCT_CURR_TIM);
        $FTCH_CURR_TIM = mysqli_fetch_object($QURY_CURR_TIM);
        
        $SLCT_t = "SELECT * FROM master_cad_cat WHERE master_cad_cat_id = '$FTCH_CAD->master_cad_cat_id'";
        $QURY_t = mysqli_query($connect,$SLCT_t);
        if(mysqli_num_rows($QURY_t )>0)
        {
            $FTCH_t = mysqli_fetch_object($QURY_t);
            $cad_cat_name = $FTCH_t->cad_cat_name;
            $cad_pnts = $FTCH_t->cad_points;
        }
        else
        { 
            $cad_cat_name = "------"; 
            $cad_pnts="----"; 
        }
        
        $SLCT_re = "SELECT * FROM emp_current_design_rework WHERE emp_det_id = '$emp_ad_id' AND design_det_id='$des_no'";
        $QURY_re = mysqli_query($connect,$SLCT_re);
        if(mysqli_num_rows($QURY_re)>0)
        {
            $FTCH_t = mysqli_fetch_object($QURY_re);
            $re_pnts = $FTCH_t->rework_pnts;
        }
        else
        {
            $re_pnts = $cad_pnts;
        }
        
        $SLCT_d = "SELECT * FROM master_cat WHERE master_cat_id = '$FTCH_CAD->master_cat_id'";
        //echo $SLCT_d;
        $QURY_d = mysqli_query($connect,$SLCT_d);
        $FTCH_d = mysqli_fetch_object($QURY_d);	
        
        $SLCT_em = "SELECT * FROM emp_det WHERE emp_det_id = '$emp_ad_id'";
        //echo $SLCT_d;
        $QURY_em = mysqli_query($connect,$SLCT_em);
        $FTCH_em = mysqli_fetch_object($QURY_em);		
        
        if($FTCH_CAD->curr_status=='finished' || $FTCH_CAD->curr_status=='waiting')
        {
            $imag_1 = "../cad_fin_images/M.".$FTCH_CAD->img_ext; 
            $imag_2 = "../cad_fin_images/L.".$FTCH_CAD->img_ext;
            $img_flagg = 1;
        }
        else
        {
            $img_flagg = 2;
			$imag_detM = "../design_images/M.".$FTCH_CAD->imag_ext; 
			$imag_detL = "../design_images/L.".$FTCH_CAD->imag_ext;
        }						
        
        if($FTCH_CAD->mas_fin_ext!='')
		{ 
			$imag_M1 = "../mas_fin_images/M.".$FTCH_CAD->mas_fin_ext; 
			$imag_L1 = "../mas_fin_images/L.".$FTCH_CAD->mas_fin_ext; 			
			$imag_N1 = "Master Finish Image";
		}
		else
		{
			$imag_M1 = "images/NoImg.png"; 
			$imag_L1 = "images/NoImg.png"; 
			$imag_N1 = "No Master Finish Image";
		}
		
		if($FTCH_CAD->cad_fin_ext!='')
		{ 
			$imag_M2 = "../cad_fin_images/M.".$FTCH_CAD->cad_fin_ext; 
			$imag_L2 = "../cad_fin_images/L.".$FTCH_CAD->cad_fin_ext;  
			$imag_N2 = "Cad Finish Image";
		}
		else
		{
			$imag_M2 = "images/NoImg.png"; 
			$imag_L2 = "images/NoImg.png"; 
			$imag_N2 = "No Cad Finish Image";
		}
		
		if($FTCH_CAD->imag_ext!='')
		{ 
			$imag_M3 = "../design_images/M.".$FTCH_CAD->imag_ext; 
			$imag_L3 = "../design_images/L.".$FTCH_CAD->imag_ext; 
			$imag_N3 = "Design Image";
		}
		else
		{
			$imag_M3 = "images/NoImg.png"; 
			$imag_L3 = "images/NoImg.png"; 
			$imag_N3 = "No Design Image";
		}
        
    ?>
    <form id="validate" name="cur_des" class="main" method="post" action="" enctype="multipart/form-data">
        <fieldset>
            <input type="hidden" name="des_no" id="des_no" value="<?php echo $_GET['des_no']; ?>" />
            <input type="hidden" name="emp_id" id="emp_id" value="<?php echo $_GET['emp_ad_id']; ?>" />
            <input type="hidden" name="cad_pnts" id="cad_pnts" value="<?php echo $cad_pnts; ?>" />
            <div class="fluid">
                <div class="widget">
                    <div class="formRow">
                        <table width="100%">
                            <tr>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>Designer Name</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_em->name; ?></td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>Design No</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_d->master_cat_name." ".$FTCH_CAD->design_no; ?></td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>Point</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $re_pnts; ?></td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>Approximate Weight</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_CAD->approximate_weight." g"; ?></td>
                            </tr>
                            	<td colspan="8">&nbsp;</td>
                            <tr>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>No. of Pieces</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_CAD->no_of_pieces; ?></td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>No. of Master</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_CAD->master_pieces; ?></td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;"><strong>Total Time</strong></td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">:&nbsp;&nbsp;<?php echo $FTCH_CURR_TIM->tot_time; ?> hrs</td>
                                <td width="15%" style="display:table-cell; vertical-align:middle;">&nbsp;</td>
                                <td width="10%" style="display:table-cell; vertical-align:middle;">&nbsp;</td>
                            </tr>
                        </table>
                    </div>
                    <div class="formRow">
                        <table width="100%">
                            <tr>
                                <td width="80%" style="vertical-align:top; text-align:center; display:table-cell;">
                                    <div class="widget" style="margin-top:0px;">
                                        <table cellpadding="0" cellspacing="0" width="100%" class="tDefault" id="resize2">
                                            <thead>
                                                <tr>
                                                    <td class="sortCol" width="8%"><div>S.no<span></span></div></td>
                                                    <td class="sortCol" width="15%"><div>W.app Date<span></span></div></td>
                                                    <td class="sortCol" width="15%"><div>App. Date<span></span></div></td>
                                                    <td class="sortCol" width="10%"><div>Admin<span></span></div></td>
                                                    <td class="sortCol" width="15%"><div>Cad Volume<span></span></div></td>
                                                    <td class="sortCol" width="15%"><div>Des. Height<span></span></div></td>
                                                    <td class="sortCol" width="15%"><div>Des. Width<span></span></div></td>
                                                    <td class="sortCol" width="20%"><div>Remarks<span></span></div></td>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                    $i=1;
                                                    $SLCT_CURR_APP  = "SELECT * FROM emp_current_design_det WHERE emp_current_design_id='$FTCH_CAD->emp_current_design_id' AND (waiting_app_dt!='' OR approved_dt!='')";
                                                    //echo $SLCT_CURR_DET;
                                                    $EXEC_CURR_APP 	= mysqli_query($connect,$SLCT_CURR_APP);
                                                    while($FTCH_CURR_APP	= mysqli_fetch_object($EXEC_CURR_APP))
                                                    {
                                                ?>
                                                        <tr>
                                                            <td class="sortCol"><div><?php echo $i; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->waiting_app_dt; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->approved_dt; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->appr_name; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->cad_vol; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->design_height; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->design_width; ?><span></span></div></td>
                                                            <td class="sortCol"><div><?php echo $FTCH_CURR_APP->remarks; ?><span></span></div></td>
                                                        </tr>
                                                <?php
                                                        $i++;
                                                    }
                                                    if($FTCH_CAD->curr_status=='stopped' || $FTCH_CAD->curr_status=='closed')
                                                    {
                                                ?>
                                                        <tr>
                                                            <td class="sortCol" colspan="8" align="center"><strong><div>Closed Date : <?php echo $FTCH_CAD->closed_dt; ?><span></span></div></strong></td>
                                                        </tr>
                                                <?php
                                                    }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div>                                                
                                </td>
                          	</tr>
                    	</table>
                  	</div>
                  	<div class="formRow">
                    	<table width="100%">
                    		<tr>
                                <td width="30%" style="vertical-align:top; text-align:left; display:table-cell;"><b>Images:</b></td>
                           	</tr>
                           	<tr>
                                <td width="30%" style="vertical-align:top; text-align:left; display:table-cell;">&nbsp;</td>
                           	</tr>
                           	<tr>
                                <td width="30%" style="vertical-align:top; text-align:center; display:table-cell;">
                                	<table width="100%">
                                		
		                            	<tr>
		                                	<td width="30%" align="center" style="vertical-align:top;">
		                                		<a href="<?php echo $imag_M3; ?>" title="<?php echo $imag_N3; ?>" class="lightbox" rel="group"><img src="<?php echo $imag_L3; ?>" width="220" height="220"/></a>
		                              		</td>
		                                    <td width="3%">&nbsp;</td>
		                                    <td width="30%" align="center" style="vertical-align:top;">
		                                    	<a href="<?php echo $imag_M2; ?>" title="<?php echo $imag_N2; ?>" class="lightbox" rel="group"><img src="<?php echo $imag_L2; ?>" width="220" height="220"/></a>	
		                                    </td>
		                                    <td width="3%">&nbsp;</td>
		                                    <td width="30%" align="center" style="vertical-align:top;">
		                                    	<a href="<?php echo $imag_M1; ?>" title="<?php echo $imag_N1; ?>" class="lightbox" rel="group"><img src="<?php echo $imag_L1; ?>" width="220" height="220"/></a>	
		                                    </td>
		                             	</tr>
		                             	<tr>
		                                	<td colspan="3" align="center" style="vertical-align:top;">&nbsp;</td>
		                             	</tr>
		                             	<tr>
		                                	<td width="30%" align="center" style="vertical-align:top;"><b>Design Image</b></td>
		                                    <td width="3%">&nbsp;</td>
		                                    <td width="30%" align="center" style="vertical-align:top;"><b>Cad Finish Image</b></td>
		                                    <td width="3%">&nbsp;</td>
		                                    <td width="30%" align="center" style="vertical-align:top;"><b>Master Finish Image</b></td>
		                             	</tr>
		                         	</table> 
                                </td>
                            </tr>
                        </table>
               	 	</div>
              	</div>
            </div>
            <div class="widget">
                <!--<div style="max-height:700px; overflow-y:auto;">-->
                    <table cellpadding="0" cellspacing="0" width="100%" class="tDefault" id="resize2">
                        <thead>
                            <tr>
                                <td class="sortCol" width="10%"><div>S.no<span></span></div></td>
                                <td class="sortCol" width="15%"><div>Date<span></span></div></td>
                                <td class="sortCol" width="15%"><div>Start Time<span></span></div></td>
                                <td class="sortCol" width="20%"><div>End Time<span></span></div></td>
                                <td class="sortCol" width="20%"><div>Time Taken<span></span></div></td>
                                <td class="sortCol" width="20%"><div>Total Design Time<span></span></div></td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $loop=1;
                                $SLCT_CURR = "SELECT * FROM emp_current_design_det WHERE emp_current_design_id = '$FTCH_CAD->emp_current_design_id'";
                                $QURY_CURR = mysqli_query($connect,$SLCT_CURR);
                                while($FTCH_CURR = mysqli_fetch_object($QURY_CURR))
                                {
                                    if($loop%2 != "0")
                                        $bg = "gradeX";
                                    else
                                        $bg = "class='gradeC'";
                            ?>
                                    <tr>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><?php echo $loop; ?></td>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><?php echo str_replace("-","/",$FTCH_CURR->work_dt); ?></td>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><?php echo $FTCH_CURR->start_time; ?></td>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><span id="out_div<?php echo $loop; ?>"><?php echo $FTCH_CURR->end_time; ?></span></td>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><span id="tak_div<?php echo $loop; ?>"><?php echo $FTCH_CURR->time_taken; ?></span></td>
                                        <td style="display:table-cell; vertical-align:middle;" align="center"><span id="tot_div<?php echo $loop; ?>"><?php echo $FTCH_CURR->tot_time; ?></span></td>
                                    </tr>
                            <?php
                                    $loop++;
                                }
                            ?>
                        </tbody>
                    </table> 
                    <input type="hidden" name="tot_loop" id="tot_loop" value="<?php echo $loop; ?>" />
                <!--</div>-->
            </div>
            <?php
                $loop2=1;
                //$SLCT_STN = "SELECT * FROM emp_current_design_stone WHERE design_det_id = '$des_no' AND emp_det_id='$emp_ad_id'";
                $SLCT_STN = "SELECT * FROM emp_current_design_stone WHERE design_det_id = '$des_no'";
                $QURY_STN = mysqli_query($connect,$SLCT_STN);
                if(mysqli_num_rows($QURY_STN)>0)
                {
            ?>
                    <div class="widget" >
                        <table width="100%" class="tDefault" id="resize2">
                            <thead>
                                <tr>
                                    <td align="center"  width="5%" style="display:table-cell; vertical-align:middle;"><strong>Sl No</strong></td>
                                    <td align="center" width="20%" style="display:table-cell; vertical-align:middle;"><strong>Stone Shape</strong></td>
                                    <td align="center" width="20%" style="display:table-cell; vertical-align:middle;"><strong>Stone Size</strong></td>
                                    <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><strong>Stone Weight</strong></td>
                                    <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><strong>Quantity</strong></td>
                                    <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><strong>Total Weight</strong></td>
                                </tr>
                            </thead>
                            <tbody>
                            <?php
                                while($FTCH_STN = mysqli_fetch_object($QURY_STN))
                                {
                                    $SLCT_STN1 = "SELECT * FROM mas_stone_cat WHERE mas_stone_cat_id = '$FTCH_STN->mas_stone_cat_id'";
                                    $QURY_STN1 = mysqli_query($connect,$SLCT_STN1);
                                    $FTCH_STN1 = mysqli_fetch_object($QURY_STN1);	
                                    
                                    $SLCT_STN2 = "SELECT * FROM mas_stone_type WHERE mas_stone_type_id = '$FTCH_STN->mas_stone_type_id'";
                                    $QURY_STN2 = mysqli_query($connect,$SLCT_STN2);
                                    $FTCH_STN2 = mysqli_fetch_object($QURY_STN2);
                            ?>
                                    <tr>
                                        <td align="center" width="5%" style="display:table-cell; vertical-align:middle;"><?php echo $loop2; ?></td>
                                        <td align="center" width="20%" style="display:table-cell; vertical-align:middle;"><?php echo $FTCH_STN1->cat_name; ?></td>
                                        <td align="center" width="20%" style="display:table-cell; vertical-align:middle;"><?php echo $FTCH_STN2->stone_name; ?></td>
                                        <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><?php echo number_format($FTCH_STN->stone_weight,4)." g"; ?></td>
                                        <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><?php echo $FTCH_STN->quantity; ?></td>
                                        <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><?php echo number_format($FTCH_STN->total_weight,4)." g"; ?></td>
                                    </tr>
                            <?php
                                    $loop2++;
                                }
                            ?>
                                    <tr>
                                        <td align="center" colspan="4" style="display:table-cell; vertical-align:middle;">&nbsp;</td>
                                        <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><strong>Total Stone Weight</strong></td>
                                        <td align="center" width="15%" style="display:table-cell; vertical-align:middle;"><?php echo number_format($FTCH_CAD->total_stone_weight,4)." g"; ?></td>
                                    </tr>
                            </tbody>
                        </table>
                        <div class="clear"></div>
                    </div>
            <?php
                }
            ?>
        </fieldset>
    </form>              
</div>