<?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/po_finishing_add_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="home.php">Dashboard</a></li>
                <li><a href="javascript:">Purchase Order Entry</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="po_finishing_list.php" id="listpage" title="List Purchase Order Finishing" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul>            
  		<?php
		if(isset($_GET['design_id']))
		{
			$design_id = $_GET['design_id'];
		}
		else
		{
			$design_id = '';
		}
		if(isset($_GET['dat']))
		{
			$dat = $_GET['dat'];
		}
		else
		{
			$dat = '';
		}
		$page_id= base64_encode(base64_encode(base64_encode(1))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for add		 
		
		$SLCT = "SELECT * FROM po_entry ORDER BY po_entry_id ASC";
		//echo $SLCT;
		$QURY = mysqli_query($connect,$SLCT);
		if(mysqli_num_rows($QURY)> 0)
		{
			$SLCT_sk = "SELECT COUNT(po_entry_id) as max_ids FROM po_entry ORDER BY po_entry_id ASC";
			$QURY_sk = mysqli_query($connect,$SLCT_sk);  
			$FTCH_sk = mysqli_fetch_object($QURY_sk);
			$max_id = $FTCH_sk->max_ids + 1;
		}
		else
		{
			$max_id = 1;
		}
			$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="bl/po_finishing_BL.php?pg_id=<?php echo $page_id?>" onsubmit="checkTheBox();">
         <fieldset>
        <div class="fluid">
		<div class="widget">
        
        <div class="formRow">
         
            <div class="grid2"><label>Design Code:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <select data-placeholder="Choose Design Code..." class="select" name="des_cd" id="des_cd" onchange="reload_page()" style="width:350px;" onfocus="foc(this.id)" onblur="stnon(this.id)">
                    <option value=""></option>
                    <?php
                    $SLCT_dt = "SELECT * FROM mas_finishing  ORDER BY design_det_id ASC"; 
                 	$QURY_dt = mysqli_query($connect,$SLCT_dt);
                    while($FTCH_dt = mysqli_fetch_object($QURY_dt))
                    {
						$SLCT_mdt = "SELECT * FROM design_det  WHERE design_det_id = '$FTCH_dt->design_det_id'"; 
                 		$QURY_mdt = mysqli_query($connect,$SLCT_mdt);
						$FTCH_mdt = mysqli_fetch_object($QURY_mdt);
						
						$SLCT_ct = "SELECT * FROM master_cat WHERE master_cat_id = '$FTCH_mdt->master_cat_id'"; 
						$QURY_ct = mysqli_query($connect,$SLCT_ct);
						$FTCH_ct = mysqli_fetch_object($QURY_ct);
						$design_det_id= base64_encode(base64_encode(base64_encode($FTCH_dt->design_det_id)));						
						
                    ?>
                    <option <?php if($design_id == $design_det_id){ ?> selected="selected" <?php } ?> value="<?php echo $design_det_id ?>"><?php echo $FTCH_ct->master_cat_name." ".$FTCH_mdt->design_no ?></option>
                    <?php
                    
					}
                    ?>
                        
                </select>
            </div>
            
             
            <div class="clear"></div>
        </div> 
        
        <?php //CONDITION 1 IF NO ORDER IN THE ORDER ENTRY TABLE
		if(isset($_GET['design_id']))
		{
			$design_id		=	base64_decode(base64_decode(base64_decode($_GET['design_id']))); //THIS IS PAGE ID  
			$tot_dis ="block";
		}//CLOSINGIN FOR GET METHOD DESIGN ID
		else
		{
			$tot_dis ="none";
		}
		$flsg = 0;
		
		$SLCT_st = "SELECT COUNT(design_det_id) AS cnt_stock FROM stock_det WHERE st_fin_status = 'no' AND design_det_id = '$design_id'";
		$QURY_st = mysqli_query($connect,$SLCT_st);
		$FTCH_st = mysqli_fetch_object($QURY_st);	
			
		$SLCT_dd = "SELECT * FROM po_entry_det WHERE fin_status = 'no' AND design_det_id = '$design_id'";
		$QURY_dd = mysqli_query($connect,$SLCT_dd);
		if(mysqli_num_rows($QURY_dd)>0)
		{
			$SLCT_s = "SELECT * FROM stock_det WHERE st_fin_status = 'no' AND  design_det_id = '$design_id'";
			$QURY_s = mysqli_query($connect,$SLCT_s);
			if(mysqli_num_rows($QURY_s)>0)
			{
				$FTCH_s = mysqli_fetch_object($QURY_s);
				$flsg = 2;
				$sel_disable = 'disabled="disabled"';
			}
			else
			{
				$flsg = 3;
				$sel_disable = '';
			}
		}
		else
		{
			$flsg = 1;
			$sel_disable = '';
		}
		//$FTCH_dd = mysqli_fetch_object($QURY_dd);
		// IF $flsg = 1; THERE IS NO PURCHASE ORDER EXIST FOR THE DESIGN
		// IF $flsg = 2; THEN THE PURCHASE ORDER EXIST FOR THE DESIGN AND ALSO THE PARTICULAR DESIGN EXIST IN STOCK
		// IF $flsg = 3; THEN THE PURCHASE ORDER EXIST FOR THE DESIGN AND ALSO NO STOCK FOR PARTICULAR DESIGN
		?>
        
        <div class="formRow" style="display:<?php echo $tot_dis ?>">
            <div class="grid2"><label>Packer Name:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <select data-placeholder="Choose an Employee..." class="select" name="pack_name" id="pack_name" style="width:350px;" <?php echo $sel_disable;?> >
                    <option value=""></option>
                    <?php
                    $SLCT_E = "SELECT * FROM emp_det WHERE master_dept_id REGEXP(CONCAT('(^|,)(',7,')(,|$)')) and statu_s='active'"; //HERE THE 1 IS REPRESENTS Packer ID 
                    //echo $SLCT;
                    $QURY_E = mysqli_query($connect,$SLCT_E);
                    while($FTCH_E = mysqli_fetch_object($QURY_E))
                    {
                    ?>
					<option <?php if($FTCH_E->name == 'Old'){  ?> selected="selected" <?php } ?> value="<?php echo $FTCH_E->emp_det_id ?>"><?php echo $FTCH_E->name ?></option>
                   <?php /*?> <option <?php if($flsg == 2){ if($FTCH_s->pack_emp_id == $FTCH_E->emp_det_id){ ?> selected="selected" <?php } } ?> value="<?php echo $FTCH_E->emp_det_id ?>"><?php echo $FTCH_E->name ?></option><?php */?>
                    <?php
                    }
                    ?>
                        
                </select>
            </div>
            <div class="grid2"><label>Packing Date:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="<?php if($flsg == 2){ echo $FTCH_s->cut_die_fin_date; }else{ echo $dat ;} ?>" name="cut_dt" id="cut_dt" class="datepicker" <?php echo $sel_disable;?>/></div>
            
            <div class="clear"></div>
        </div>
        
        <div class="formRow" style="display:<?php echo $tot_dis ?>">
            <div class="grid2"><label>Cutter Name:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <select data-placeholder="Choose an Employee..." class="select"  name="cut_name" id="cut_name" style="width:350px;" tabindex="2" <?php echo $sel_disable;?>>
                    <option value=""></option>
                    <?php
                    $SLCT_E = "SELECT * FROM emp_det WHERE master_dept_id REGEXP(CONCAT('(^|,)(',8,')(,|$)')) and statu_s='active'"; //HERE THE 1 IS REPRESENTS cutter  ID 
                    //echo $SLCT;
                    $QURY_E = mysqli_query($connect,$SLCT_E);
                    while($FTCH_E = mysqli_fetch_object($QURY_E))
                    {
                    ?>
					<option <?php if($FTCH_E->name == 'Old'){  ?> selected="selected" <?php } ?> value="<?php echo $FTCH_E->emp_det_id ?>"><?php echo $FTCH_E->name ?></option>
                   <?php /*?> <option <?php if($flsg == 2){ if($FTCH_s->cut_emp_id == $FTCH_E->emp_det_id){ ?> selected="selected" <?php } } ?> value="<?php echo $FTCH_E->emp_det_id ?>"><?php echo $FTCH_E->name ?></option><?php */?>
                    <?php
                    }
                    ?>
                        
                </select>
            </div>
            <div class="grid2"><label>Cutting Date:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="<?php if($flsg == 2){ echo $FTCH_s->die_fin_date; }else{ echo $dat ;} ?>" name="pfd" id="pfd" class="datepicker" <?php echo $sel_disable;?>/></div>
            <div class="clear"></div>
        </div>
        
        <?php if($flsg == 1){ ?>	
        
        <div class="formRow" style="display:<?php echo $tot_dis ?>">
            <div class="grid2"><label>Stock:<span class="req"></span></label></div>
            <div class="grid4"><span><?php echo $FTCH_st->cnt_stock; ?> + 1</span></div><div class="clear"></div>
        </div>
       <?php } ?>
       
       <?php if($flsg == 2){ ?>	
        
        <div class="formRow" style="display:<?php echo $tot_dis ?>">
            <div class="grid2"><label>Stock:<span class="req"></span></label></div>
            <div class="grid4"><span><?php echo $FTCH_st->cnt_stock; ?> - 1</span></div><div class="clear"></div>
        </div>       
        
        <input name="pfd" type="hidden" value="<?php echo $FTCH_s->die_fin_date; ?>" />
        <input name="cut_dt" type="hidden" value="<?php echo $FTCH_s->cut_die_fin_date; ?>" />
        <input name="pack_name" type="hidden" value="<?php echo $FTCH_s->pack_emp_id; ?>" />
        <input name="cut_name" type="hidden" value="<?php echo $FTCH_s->cut_emp_id; ?>" />
       <?php } ?>
        
        </div>
        </div>
        
    <?php if($flsg == 2 || $flsg == 3){ ?>	
    
        <div class="widget" style="display:<?php echo $tot_dis ?>"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><h6>Purchase Order List</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>
            <table cellpadding="0" cellspacing="0" border="0" class="dTable check" id="checkAll">
            <thead>
            <tr>
            <td width="30"><img src="images/elements/other/tableArrows.png" alt="" /></td>
            <th width="26">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="95">Purchase Order No</th>
            <th width="88">Order Date</th>
            <th width="78">Party Code</th>
            <th width="60">Over all Pending Designs</th>   
            <th width="60">Over all Pending Die</th> 
            </tr>
            </thead>
            <tbody>
            <?php
			
					
			
			$SLCT = "SELECT  * FROM po_entry_det WHERE fin_status = 'no' AND design_det_id = '$design_id'";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			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_c = "SELECT  * FROM po_entry WHERE po_entry_id = '$FTCH->po_entry_id'";
				$QURY_c = mysqli_query($connect,$SLCT_c);
				$FTCH_c = mysqli_fetch_object($QURY_c);
				
				$SLCT_p = "SELECT  * FROM party_det WHERE party_det_id = '$FTCH_c->party_det_id'";
				$QURY_p = mysqli_query($connect,$SLCT_p);
				$FTCH_p = mysqli_fetch_object($QURY_p);
				
				$SLCT_d = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(design_det_id) AS pen_cnt FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND fin_status = 'no' AND cancelled='no' AND po_entry_id = '$FTCH->po_entry_id'";
				$QURY_d = mysqli_query($connect,$SLCT_d);
				$FTCH_d = mysqli_fetch_object($QURY_d);
				
				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
			?>
            <tr <?php echo $bg ?>>
            <td align="center" style="display:table-cell;vertical-align:middle;"><input type="radio" name="category" id="<?php echo $loop ?>" value="<?php echo $FTCH->po_entry_det_id ?>" onfocus="foc(this.id)" onblur="stnon(this.id)"/></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $loop ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_c->po_no; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_c->po_date; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_p->party_code; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->pen_cnt; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->tot_pic; ?></td>
            <?php /*?><td class="center" style="display:table-cell;vertical-align:middle"><input name="remak[<?php echo $loop ?>]" id="remak<?php echo $loop ?>" type="text" class="rem_tx"/></td><?php */?>
            
            </tr>
            
            <?php
			$loop ++;
			 
			}
			 }
			 ?>
            </tbody>
            </table> 
        </div>
        </div>    
      <?php } ?>
       
         <?php if(mysqli_num_rows($QURY)>0){ ?>
         
        <div class="fluid" style="display:<?php echo $tot_dis ?>">
		<div class="widget">
        
        <input name="flsg" id="flsg" type="hidden" value="<?php echo $flsg; ?> " /><!--THIS IS FOR IDENTIFY WHICH FIELDS ARE ACTIVE-->
             
           <div class="formRow">
           		<input type="button" value="Submit" class="buttonM bBlack formSubmit" onclick="checkTheBox();" 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>
                <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>
