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

<?php if($_GET['flg']=="can"){ ?><script type="text/javascript" src="js/po_entry_upd_JS.js"></script><?php }else{ ?>
<script type="text/javascript" src="js/po_entry_add_plus_JS.js"></script><?php } ?>
<!--<script type="text/javascript" src="js/cnt_chkbox_JS.js"></script>-->

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/paginatio_style.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_entry_list.php" id="listpage" title="List Purchase Order Entry" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>
    	</ul>            
  		<?php
	
		$po_id	=	base64_decode(base64_decode(base64_decode($_GET['po_id']))); //THIS IS PAGE ID  
		$po_id_url = $_GET['po_id'];
		$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for add
		
		$SLCTf = "SELECT  * FROM po_entry WHERE po_entry_id = '$po_id'";
		$QURYf = mysqli_query($connect,$SLCTf);		 
		$FTCHf = mysqli_fetch_object($QURYf);
		
		$SLCT_tp = "SELECT * FROM party_det WHERE party_det_id = '$FTCHf->party_det_id'";
		$QURY_tp = mysqli_query($connect,$SLCT_tp);
		$FTCH_tp = mysqli_fetch_object($QURY_tp);
		
		$party_id  = $FTCHf->party_det_id;
		
		$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 WHERE statu_s = 'active' 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;
		}
		
		if(isset($_GET['master_cat_id']))
		{
			$master_cat_id =	$_GET['master_cat_id'];	
			$mas_ct_id = base64_decode(base64_decode(base64_decode($_GET['master_cat_id'])));
		}
		else
		{
			$master_cat_id = '';
			$mas_ct_id = '';
		}
		$dno = (isset($_GET['dno'])?$_GET['dno']:'');
		
		$search_by ="";
			
		if(isset($_GET['master_cat_id']) && $_GET['master_cat_id']!='')
		{
			$search_by = $search_by."AND design_det.master_cat_id='$mas_ct_id'";
		}
		if(isset($_GET['dno']) && $_GET['dno']!='')
		{
			$search_by = $search_by. " AND design_det.design_no='$dno'";
		}
		
		if($_GET['flg']=="add"){
		
		/*PAGINATION STARTS HERE*/
		
			$tbl_name="mas_finishing,design_det";		//your table name
			// How many adjacent pages should be shown on each side?
			$adjacents = 3;
			
			/* 
			   First get total number of rows in data table. 
			   If you have a WHERE clause in your query, make sure you mirror it here.
			*/
						
			$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE design_det.design_det_id = mas_finishing.design_det_id ".$search_by."  AND mas_finishing.design_det_id NOT IN(SELECT po_entry_det.design_det_id FROM po_entry_det,po_entry WHERE po_entry.party_det_id = '$party_id' AND po_entry_det.po_entry_id = po_entry.po_entry_id AND po_entry_det.cancelled = 'no') AND design_det.statu_s = 'active' ORDER BY mas_finishing.design_det_id ASC";
			//echo $query;
			$total_pages = mysqli_fetch_array(mysqli_query($connect,$query));
			$total_pages = $total_pages['num'];
			
			/* Setup vars for query. */
			$targetpage = "po_entry_upd.php"; 	//your file name  (the name of this file)
			$limit = 100; 								//how many items to show per page
			$page = (isset($_GET['page'])?$_GET['page']:'');
			if($page) 
				$start = ($page - 1) * $limit; 			//first item to display on this page
			else
				$start = 0;								//if no page var is given, set start to 0
			
			/* Get data. */
			$sql = "SELECT * FROM $tbl_name WHERE design_det.design_det_id = mas_finishing.design_det_id ".$search_by."  AND mas_finishing.design_det_id NOT IN(SELECT po_entry_det.design_det_id FROM po_entry_det,po_entry WHERE po_entry.party_det_id = '$party_id' AND po_entry_det.po_entry_id = po_entry.po_entry_id AND po_entry_det.cancelled = 'no') AND design_det.statu_s = 'active' ORDER BY mas_finishing.design_det_id ASC LIMIT $start, $limit";
			$result = mysqli_query($connect,$sql);
			
			/* Setup page vars for display. */
			if ($page == 0) $page = 1;					//if no page var is given, default to 1.
			$prev = $page - 1;							//previous page is page - 1
			$next = $page + 1;							//next page is page + 1
			$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
			$lpm1 = $lastpage - 1;						//last page minus 1
			
			/* 
				Now we apply our rules and draw the pagination object. 
				We're actually saving the code to a variable in case we want to draw it more than once.
			*/
			$pagination = "";
			if($lastpage > 1)
			{	
				$pagination .= "<div class=\"pagination\">";
				//previous button
				if ($page > 1) 
					$pagination.= "<a href=\"$targetpage?page=$prev&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">  previous</a>";
				else
					$pagination.= "<span class=\"disabled\">  previous</span>";	
				
				//pages	
				if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
				{	
					for ($counter = 1; $counter <= $lastpage; $counter++)
					{
						if ($counter == $page)
							$pagination.= "<span class=\"current\">$counter</span>";
						else
							$pagination.= "<a href=\"$targetpage?page=$counter&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$counter</a>";					
					}
				}
				elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
				{
					//close to beginning; only hide later pages
					if($page < 1 + ($adjacents * 2))		
					{
						for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$counter</a>";					
						}
						$pagination.= "...";
						$pagination.= "<a href=\"$targetpage?page=$lpm1&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$lpm1</a>";
						$pagination.= "<a href=\"$targetpage?page=$lastpage&master_cat_id=$master_cat_id&dno=$dno\">$lastpage</a>";		
					}
					//in middle; hide some front and some back
					elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
					{
						$pagination.= "<a href=\"$targetpage?page=1&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">1</a>";
						$pagination.= "<a href=\"$targetpage?page=2&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">2</a>";
						$pagination.= "...";
						for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$counter</a>";					
						}
						$pagination.= "...";
						$pagination.= "<a href=\"$targetpage?page=$lpm1&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$lpm1</a>";
						$pagination.= "<a href=\"$targetpage?page=$lastpage&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$lastpage</a>";		
					}
					//close to end; only hide early pages
					else
					{
						$pagination.= "<a href=\"$targetpage?page=1&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">1</a>";
						$pagination.= "<a href=\"$targetpage?page=2&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">2</a>";
						$pagination.= "...";
						for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">$counter</a>";					
						}
					}
				}
				
				//next button
				if ($page < $counter - 1) 
					$pagination.= "<a href=\"$targetpage?page=$next&po_id=$po_id_url&flg=add&master_cat_id=$master_cat_id&dno=$dno\">next  </a>";
				else
					$pagination.= "<span class=\"disabled\">next</span>";
				$pagination.= "</div>\n";		
			}
		/*PAGINATION STARTS HERE*/			 
		}		 
		?>

    	<!-- Chart --><!-- 6 + 6 -->
        <form id="validate" name="checklist" class="main" method="post" action="bl/po_entry_BL.php?page_id=<?php echo $page_id; ?>" onsubmit="checkTheBox();">
         <fieldset>
		 <input name="po_id" id="po_id" type="hidden" value="<?php echo $_GET['po_id']; ?>" />
		 <input name="flg" id="flg" type="hidden" value="<?php echo $_GET['flg']; ?>" />
        <div class="fluid">
		<div class="widget">
        
        <div class="formRow">
            <div class="grid2"><label>PO No:<span class="req">*</span></label></div>
            <div class="grid4"><input type="text" value="<?php echo  $FTCHf->po_no; ?>" name="po_no" id="po_no" readonly="readonly"/></div><div class="clear"></div>
        </div>
        
        
        <div class="formRow">
            <div class="grid2"><label>Company Code:<span class="req">*</span></label></div>
            <div class="grid4 searchDrop">
                <?php if($admin_flagg==1){ echo $FTCH_tp->party_code . " / " . $FTCH_tp->cmp_name; } else if($admin_flagg==2){ echo $FTCH_tp->party_code; } ?>
				<input name="co_cod" id="co_cod" type="hidden" value="<?php echo base64_encode(base64_encode(base64_encode($FTCHf->party_det_id))); ?>" />
            </div>
            <div class="clear"></div>
        </div>
                        
        <div class="formRow">
            <div class="grid2"><label>Order Date:<span class="req">*</span></label></div>
            <div class="grid4"><input type="hidden" value="<?php echo str_replace("-", "/",$FTCHf->po_date); ?>" name="pod" id="pod" class="" /><?php echo str_replace("-", "/",$FTCHf->po_date); ?></div><div class="clear"></div>
            </div>
			
			<div class="formRow">
			<div class="grid2"><label>Update Type:<span class="req">*</span></label></div>
			<div class="grid4">
			  <table width="279">
				  <tr>
					<td width="127"><label><?php if($_GET['flg']=="can"){ ?>Cancel Designs<?php } ?> <?php if($_GET['flg']=="add"){ ?>Add Designs<?php } ?></label></td>
					<td width="140"><label></label></td>
				</tr>
			  </table>
			</div>
			<div class="clear"></div>
		</div>
		<div class="formRow" >
			<table width="100%">
				<tr>
					<td width="17%" style="display:table-cell; vertical-align:middle;">Select Category:</td>
					<td width="25%">
					<div class="searchDrop">
					 <select  data-placeholder="" class="select" name="cat_name" id="cat_name" style="width:200px;">
						 <option selected="selected" value="">Choose a Category...</option>
							 <?php
								$SLCT = "SELECT  * FROM master_cat ORDER BY master_cat_id ASC";
								//echo $SLCT;
								$QURY = mysqli_query($connect,$SLCT);
								while($FTCH = mysqli_fetch_object($QURY))
								{
								$cad_name= base64_encode(base64_encode(base64_encode($FTCH->master_cat_id)));	
							?>
							<option <?php if($cad_name == $master_cat_id){ ?> selected="selected" <?php }?> value="<?php echo $cad_name ?>"><?php echo $FTCH->master_cat_name." - ".$FTCH->cat_expantion; ?></option>
							<?php
								}
							?>
				</select>
			</div>			</td>
			        <td width="9%" style="display:table-cell; vertical-align:middle;">Design No :</td>
			        <td width="24%" style="display:table-cell; vertical-align:middle;"><input type="text" value="<?php echo $dno; ?>" name="dno" id="dno" style="width:100px;" /></td>
			        <td width="25%" style="display:table-cell; vertical-align:middle;"><input type="button" value="Submit" class="buttonM bBlack formSubmit" style="float: right; margin-left:20px;" onclick="ftl_reload_page()"/></td>
			  </tr>
			</table>
			</div>
        </div>
        </div>
       
	   <?php if($_GET['flg']=="add"){     	
		
		$ses_id = session_id();	
		
		$SLCT_aj = "SELECT COUNT(design_det_id) AS aj_cnt FROM po_temp_des WHERE party_det_id = '$party_id' AND ses_id='$ses_id'"; 
		$QURY_aj = mysqli_query($connect,$SLCT_aj);
		$FTCH_aj = mysqli_fetch_object($QURY_aj);
		
		?>
				
    	 <input name="party_id" id="party_id" type="hidden" value="<?php echo $party_id ?>" />
		 <input name="stat_cnt" id="stat_cnt" type="hidden" value="<?php echo $FTCH_aj->aj_cnt; ?>" />
		 <input name="flg" id="flg" type="hidden" value="<?php echo $_GET['flg']; ?>" />
		 
        <div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><span class="titleIcon check"><input type="checkbox" id="titleCheck" name="titleCheck" onclick="ckall(),check_all_cnt();" onfocus="foc(this.id)" onblur="stnon(this.id)"/></span>
		<h6>New Design List</h6>
		<h6 style="margin-left:100px;"><?=$pagination?></h6>
		
		<h6 style="float:right; margin-right:50px;"><input type="text" id="cnt_chk" name="cnt_chk" value="<?php echo $FTCH_aj->aj_cnt; ?>" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></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 width="793" border="0" cellpadding="0" cellspacing="0" class="dTable check" id="checkAll">
            <thead>
            <tr>
            <td width="62"><img src="images/elements/other/tableArrows.png" alt="" /></td>
            <th width="53">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="156">Design No</th>
            <th width="104">No. Of Dies </th>
            <th width="104">No. Of Order </th>
            <th width="103">No. Of Stock </th>
            <!--<th width="88">Design Status</th>-->
            <th width="129">Image</th>
            <th width="186">Remarks</th>
            </tr>
            </thead>
            <tbody>
            <?php					
			
			/*$SLCT = "SELECT  * FROM mas_finishing,design_det WHERE design_det.design_det_id = mas_finishing.design_det_id AND design_det.statu_s = 'active' ORDER BY mas_finishing.design_det_id ASC";*/
			//echo $SLCT;
			$QURY = mysqli_query($connect,$sql);
			$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_dt = "SELECT * FROM design_det WHERE design_det_id = '$FTCH->design_det_id'"; 
                $QURY_dt = mysqli_query($connect,$SLCT_dt);
                $FTCH_dt = mysqli_fetch_object($QURY_dt);*/
				
				$SLCT_d = "SELECT  master_cat_name FROM master_cat WHERE master_cat_id = '$FTCH->master_cat_id'";
				$QURY_d = mysqli_query($connect,$SLCT_d);
				$FTCH_d = mysqli_fetch_object($QURY_d);
				
				$SLCT_or = "SELECT COUNT(design_det_id) AS or_cnt FROM po_entry_det WHERE cancelled = 'no' AND design_det_id = '$FTCH->design_det_id' AND fin_status = 'no'"; 
                $QURY_or = mysqli_query($connect,$SLCT_or);
                $FTCH_or = mysqli_fetch_object($QURY_or);
				
				$SLCT_st = "SELECT COUNT(design_det_id) AS st_cnt FROM stock_det WHERE design_det_id = '$FTCH->design_det_id' AND st_fin_status = 'no'"; 
                $QURY_st = mysqli_query($connect,$SLCT_st);
                $FTCH_st = mysqli_fetch_object($QURY_st);
												
				
					/*$party_id		=	$FTCHf->party_det_id;
					$SLCT_po = "SELECT * FROM po_entry_det,po_entry WHERE po_entry.party_det_id = '$party_id' AND po_entry_det.po_entry_id = po_entry.po_entry_id AND po_entry_det.design_det_id = '$FTCH->design_det_id' AND po_entry_det.cancelled = 'no'"; 
					$QURY_po = mysqli_query($connect,$SLCT_po);
				
				
				if(mysqli_num_rows($QURY_po)< 1)
				{*/
				$SLCT_ajc = "SELECT * FROM po_temp_des WHERE design_det_id = '$FTCH->design_det_id' AND party_det_id = '$party_id' AND ses_id='$ses_id'"; 
				$QURY_ajc = mysqli_query($connect,$SLCT_ajc);					
				
			
				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
					
				if($FTCH->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH->mas_fin_ext;}

				else if($FTCH->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH->cad_fin_ext; }
				
				else if($FTCH->imag_ext!=''){ $imag = "../design_images/S.".$FTCH->imag_ext; $imag1 = "../design_images/L.".$FTCH->imag_ext; }
			?>
            <tr <?php echo $bg ?>>
            <td style="display:table-cell;vertical-align:middle;"><input type="checkbox" name="category[]" id="category<?php echo $loop ?>" onclick="cnt_chk_fn(<?php echo $loop ?>),check_ajax(<?php echo $loop ?>,this.value);" value="<?php echo $FTCH->design_det_id ?>" onfocus="foc(this.id)" onblur="stnon(this.id)" <?php if(mysqli_num_rows($QURY_ajc)>0){ ?> checked="checked" <?php } ?> /></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_d->master_cat_name." ".$FTCH->design_no; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->master_pieces; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_or->or_cnt; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_st->st_cnt; ?></td>
            <?php /*?><td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_c->design_status; ?></td>
            <td class="center" align="center"><a href=""><img src="design_images/S.<?php echo $FTCH_dt->imag_ext; ?>" width="60" height="60"/></a></td><?php */?>
            <td class="center" align="center">
            <div class="body" align="center">
                	<a href="<?php echo $imag1; ?>" title="<?php echo $FTCH_d->master_cat_name." ".$FTCH->design_no; ?>" class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a>
                </div></td>
            <td class="center" style="display:table-cell;vertical-align:middle"><input name="remak[<?php echo $FTCH->design_det_id ?>]" id="remak<?php echo $loop ?>" type="text" class="rem_tx"/></td>
            </tr>
            
            <?php
			$loop ++;
			 //}
			}
			 }
			 ?>
            </tbody>
            </table> 
			<input name="des_tot_cnt" id="des_tot_cnt" type="hidden" value="<?php echo $loop-1; ?>" />
        </div>
        </div>
        </div>   
	<?php  }else if($_GET['flg']=="can"){ ?>
       
	           <div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><span class="titleIcon check"><input type="checkbox" id="titleCheck" name="titleCheck" onclick="ckall()" onfocus="foc(this.id)" onblur="stnon(this.id)"/></span><h6>Ordered Design List</h6><h6 style="float:right; margin-right:50px;"><input type="text" id="cnt_chk" name="cnt_chk" value="0" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></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 width="793" border="0" cellpadding="0" cellspacing="0" class="dTable check" id="checkAll">
            <thead>
            <tr>
            <td width="20"><img src="images/elements/other/tableArrows.png" alt="" /></td>
            <th width="53">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="156">Design No</th>
            <th width="104">No. Of Masters </th>
            <th width="104">No. Of Order </th>
            <th width="103">No. Of Stock </th>
            <!--<th width="88">Design Status</th>-->
            <th width="129">Image</th>
            <th width="186">Remarks</th>
            </tr>
            </thead>
            <tbody>
            <?php					
			
			$SLCT = "SELECT design_det.design_det_id,master_cat.master_cat_id,master_cat.master_cat_name,design_no,master_pieces,mas_fin_ext,cad_fin_ext,imag_ext FROM po_entry_det,design_det,master_cat WHERE po_entry_id = '$po_id' AND po_entry_det.cancelled = 'no' AND po_entry_det.design_det_id = design_det.design_det_id AND master_cat.master_cat_id = design_det.master_cat_id ".$search_by." ORDER BY design_det.master_cat_id ASC, design_det.design_det_id ASC ";
			//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_or = "SELECT COUNT(design_det_id) AS or_cnt FROM po_entry_det WHERE cancelled = 'no' AND design_det_id = '$FTCH->design_det_id' AND fin_status = 'no'"; 
                $QURY_or = mysqli_query($connect,$SLCT_or);
                $FTCH_or = mysqli_fetch_object($QURY_or);
				
				$SLCT_st = "SELECT COUNT(design_det_id) AS st_cnt FROM stock_det WHERE design_det_id = '$FTCH->design_det_id' AND st_fin_status = 'no'"; 
                $QURY_st = mysqli_query($connect,$SLCT_st);
                $FTCH_st = mysqli_fetch_object($QURY_st);
			
				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
					
				if($FTCH->mas_fin_ext!=''){ $imag = "../mas_fin_images/S.".$FTCH->mas_fin_ext; $imag1 = "../mas_fin_images/L.".$FTCH->mas_fin_ext; }

				else if($FTCH->cad_fin_ext!=''){ $imag = "../cad_fin_images/S.".$FTCH->cad_fin_ext; $imag1 = "../cad_fin_images/L.".$FTCH->cad_fin_ext; }
				
				else if($FTCH->imag_ext!=''){ $imag = "../design_images/S.".$FTCH->imag_ext; $imag1 = "../design_images/L.".$FTCH->imag_ext; }
			?>
            <tr <?php echo $bg ?>>
            <td style="display:table-cell;vertical-align:middle;"><input type="checkbox" name="category[]" id="category<?php echo $loop ?>" onclick="cnt_chk_fn(<?php echo $loop ?>);" value="<?php echo $FTCH->design_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->master_cat_name." ".$FTCH->design_no; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->master_pieces; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_or->or_cnt; ?></td>
            <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_st->st_cnt; ?></td>
            <?php /*?><td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_c->design_status; ?></td>
            <td class="center" align="center"><a href=""><img src="design_images/S.<?php echo $FTCH_dt->imag_ext; ?>" width="60" height="60"/></a></td><?php */?>
            <td class="center" align="center"><div class="body" align="center">
                	<a href="<?php echo $imag1; ?>"  title="<?php echo $FTCH->master_cat_name." ".$FTCH->design_no; ?>"class="lightbox" rel="group"><img src="<?php echo $imag; ?>" width="60" height="60"/></a>
                </div></td>
            <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>
            </tr>
            
            <?php
			$loop ++;
			
			}
			 }
			 ?>
             
            </tbody>
            </table> 
            <input name="des_tot_cnt" id="des_tot_cnt" type="hidden" value="<?php echo $loop-1; ?>" />
        </div>
        </div>
        </div>   
	 <?php } ?>
         
        <div class="fluid">
		<div class="widget">
        
             
           <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>
        </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>
