<?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';
	}
	
	$check_acc  = check_access('47');
?>
<!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/party_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 if($check_acc==1){?>
    	   <?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_po_stage WHERE mas_po_stage_id ='$mas_stage_id1'";

					$QURYs = mysqli_query($connect,$SLCTs);
					if(mysqli_num_rows($QURYs)>0)
					{
						$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
					{
						$sta_iden = '';
						$empl_name = '';
						$flag = 0;
					}
				}
				else
				{
					$mas_stage_id = '';
					$mas_stage_id1 = '';
				}

				$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'])));  
					if($FTCHs->mas_po_stage_id =='6'){	$emp_qur_str = "AND pack_emp_id='$emp_id_dec'";	}else if($FTCHs->mas_po_stage_id =='7'){ $emp_qur_str = "AND cut_emp_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 = ''; }

		?>
    
        <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>-->
    	</ul>
    		<form>

            <fieldset>
    		<div class="widget">
                			<div class="formRow" >
							<table width="100%">
								<tr>
									<td width="25%" style="display:table-cell; vertical-align:top;">Select Party:</td>
									<td width="75%">
                            		<div class="searchDrop">
                               		 <select  data-placeholder="" 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 Party...</option>
                                   			 <?php
												$SLCT = "SELECT  * FROM party_det WHERE statu_s='active' ORDER BY party_det_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->party_det_id)));	
											?>
                                            <option <?php if($ma_st_id == $mas_stage_id){ ?> selected="selected" <?php }?> value="<?php echo $ma_st_id ?>"><?php echo $FTCH->party_code." - ".$FTCH->cmp_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-->
						<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_validate();" 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

			$design_date = "po_entry.po_date"; 

			$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')"; }
			}

			?>

    	<div class="widget" style="display: block"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead">

		<h6>Po List</h6>

		<?php /*?><h6 style="float:right; margin-right:50px; text-decoration:underline;">
		<?php if($flag==1){ ?>
		<a href="po_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" target="_blank">With Image</a>
			
		<?php } ?>
		</h6><?php */?>

		<h6 style="float:right; margin-right:40px;text-decoration:underline;">
		<a href="party_analize_print.php?sta_name=<?php echo $_GET['sta_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" target="_blank">Print</a>
		</h6>
		<h6 style="float:right; margin-right:20px">Total Dies : <input type="text" id="tot_die" name="tot_die" value="" readonly="readonly" disabled="disabled" style="width:50px; font-size:12px; text-align:center;" /></h6>
		<h6 style="float:right; margin-right:20px">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>
		<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 width="677" border="0" cellpadding="0" cellspacing="0" class="dTable" id="dynamic">
            <thead>
            <?php 
				if(isset($_GET['sta_name']) && $_GET['sta_name']!='')
				{
			?> 
                    <tr>
                        <th width="47" align="center">S.No<span class="sorting" style="display: block;"></span></th>
                        <th width="280" align="center">Po No</th>
                        <th width="280" align="center">Po Date</th>
                        <th width="280" align="center">Order Qty</th>
                        <th width="280" align="center">Finished Qty</th>
                        <th width="280" align="center">Delivered Qty</th>
                        <th width="248" align="center">View</th>                               
                    </tr>
           	<?php
				}
				else if(isset($_GET['sta_name']) && $_GET['sta_name']=='')
				{
			?>
            		<tr>
                        <th width="47"  align="center">S.No<span class="sorting" style="display: block;"></span></th>
                        <th width="280"  align="left">Party Code</th>
                        <th width="280"  align="left">Party Name</th>
                        <th width="280" align="center">Selected Qty</th>
                        <th width="280" align="center">No of Dies</th>
                        <th width="248" align="center">View</th>
                    </tr>
            <?php
				}
			?>
            </thead>
            <tbody>
				<?php
                if(isset($_GET['sta_name']) && $_GET['sta_name']!='')
                {
					$SLCT = "SELECT * FROM party_det,po_entry WHERE ".$dat_str." AND party_det.party_det_id='$mas_stage_id1' AND party_det.party_det_id = po_entry.party_det_id GROUP BY po_entry.po_entry_id ASC ";
					//echo $SLCT;
					$sum_qty = 0;
					$tot_pic = 0;
					$QURY = mysqli_query($connect,$SLCT);
					$loop=1;
					if(mysqli_num_rows($QURY)>0)
					{			
						while($FTCH = mysqli_fetch_object($QURY))
						{
							$po_id = base64_encode(base64_encode(base64_encode($FTCH->po_entry_id)));
							
							$SLCT_d = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det.design_det_id) as cnt_des FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND po_entry_id = '$FTCH->po_entry_id' AND cancelled='no'";
							$QURY_d = mysqli_query($connect,$SLCT_d);
							$FTCH_d = mysqli_fetch_object($QURY_d);
							
							$SLCT_dc = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det.design_det_id) as cnt_des_c FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND po_entry_id = '$FTCH->po_entry_id' AND cancelled='yes'";
							$QURY_dc = mysqli_query($connect,$SLCT_dc);
							$FTCH_dc = mysqli_fetch_object($QURY_dc);
							
							$SLCT_df = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det.design_det_id) as cnt_des_f FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND po_entry_id = '$FTCH->po_entry_id' AND fin_status='yes' AND cancelled='no'";
							$QURY_df = mysqli_query($connect,$SLCT_df);
							$FTCH_df = mysqli_fetch_object($QURY_df);
							
							$SLCT_dd = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det.design_det_id) as cnt_des_d FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND po_entry_id = '$FTCH->po_entry_id' AND fin_status='yes' AND del_status='yes' AND cancelled='no'";
							$QURY_dd = mysqli_query($connect,$SLCT_dd);
							$FTCH_dd = mysqli_fetch_object($QURY_dd);
							
							if($loop%2 != "0")
							$bg = "gradeX";
							else
							$bg = "class='gradeC'";
                
                
                ?>
                            <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"><?php echo $FTCH->po_no; ?></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo str_replace("-","/",$FTCH->po_date); ?></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->cnt_des; ?>( <?php echo $FTCH_dc->cnt_des_c; ?> )<br><span title="No of Dies for Order Designs">(<?php echo $FTCH_d->tot_pic; ?>)</span>&nbsp;<span title="No of Dies for Order Cancel Designs">(<?php echo $FTCH_dc->tot_pic; ?>)</span></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_df->cnt_des_f; ?><br><span title="No of Dies for Finish Designs">(<?php echo $FTCH_df->tot_pic; ?>)</span></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_dd->cnt_des_d; ?><br><span title="No of Dies for Delivery Designs">(<?php echo $FTCH_dd->tot_pic; ?>)</span></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><a href="po_delivery_view.php?code_no=<?php echo base64_encode(base64_encode(base64_encode(3))); ?>&po_id=<?php echo $po_id ?>" target="_blank">View</a></td>                            
                            </tr>
                <?php
                			$loop ++;
                			$tot_pic = $tot_pic+$FTCH_d->tot_pic;
                			$sum_qty = $sum_qty+$FTCH_d->cnt_des; 
                		}
                	}
				}
				else if(isset($_GET['sta_name']) && $_GET['sta_name']=='')
				{
					$SLCT = "SELECT *,GROUP_CONCAT(po_entry_id) AS po_entry_id FROM party_det,po_entry WHERE ".$dat_str." AND party_det.party_det_id = po_entry.party_det_id GROUP BY po_entry.party_det_id ASC";
					//echo $SLCT;
					$sum_qty = 0;
					$tot_pic = 0;
					$QURY = mysqli_query($connect,$SLCT);
					$loop=1;
					if(mysqli_num_rows($QURY)>0)
					{			
						while($FTCH = mysqli_fetch_object($QURY))
						{
							$po_id = base64_encode(base64_encode(base64_encode($FTCH->po_entry_id)));	
							$st_id = base64_encode(base64_encode(base64_encode($FTCH->party_det_id)));	

							$SLCT_d = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic, COUNT(po_entry_det.design_det_id) as cnt_des FROM po_entry_det,design_det WHERE design_det.design_det_id=po_entry_det.design_det_id AND po_entry_id IN($FTCH->po_entry_id)";
							//echo $SLCT_d."<br>";
							$QURY_d = mysqli_query($connect,$SLCT_d);
							$FTCH_d = mysqli_fetch_object($QURY_d);

							/*$SLCT_dc = "SELECT  COUNT(design_det_id) as cnt_des_c FROM po_entry_det WHERE po_entry_id = '$FTCH->po_entry_id' AND cancelled='yes'";
							$QURY_dc = mysqli_query($connect,$SLCT_dc);
							$FTCH_dc = mysqli_fetch_object($QURY_dc);

							$SLCT_df = "SELECT  COUNT(design_det_id) as cnt_des_f FROM po_entry_det WHERE po_entry_id = '$FTCH->po_entry_id' AND fin_status='yes' AND cancelled='no'";
							$QURY_df = mysqli_query($connect,$SLCT_df);
							$FTCH_df = mysqli_fetch_object($QURY_df);

							$SLCT_dd = "SELECT  COUNT(design_det_id) as cnt_des_d FROM po_entry_det WHERE po_entry_id = '$FTCH->po_entry_id' AND fin_status='yes' AND del_status='yes' AND cancelled='no'";
							$QURY_dd = mysqli_query($connect,$SLCT_dd);
							$FTCH_dd = mysqli_fetch_object($QURY_dd);*/	

							if($loop%2 != "0")
							$bg = "gradeX";
							else
							$bg = "class='gradeC'";

							$pg_url ="party_analize.php?sta_name=".$st_id."&fdate=".$fdate."&todate=".$todate."&yea_r=".$yea_r."&mont_h=".$mont_h."&da_y=".$da_y;

                ?>
                            <tr <?php echo $bg ?>>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $loop ?></td>
                                <td align="left" style="display:table-cell;vertical-align:middle"><?php echo $FTCH->party_code; ?></td>
                                <td align="left" style="display:table-cell;vertical-align:middle">

								<?php //echo $FTCH->cmp_name; ?>
								<?php  
				$name_count = strlen($FTCH->cmp_name);
				$name='';
				if($name_count>15){
					$name = substr($FTCH->cmp_name,0,15)."...";
				} else {
					$name = $FTCH->cmp_name;
				} ?>
			<?php if($name_count>15){?>
			<div class="tooltip1">
			<?php echo $name;?>
				<span class="tooltiptext1"><?php echo $FTCH->cmp_name;?></span>
			</div>
			<?php } else { ?>
			<?php echo $name;?>
			<?php } ?>
								
								</td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->cnt_des; ?></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><?php echo $FTCH_d->tot_pic; ?></td>
                                <td align="center" style="display:table-cell;vertical-align:middle"><a href="<?php echo $pg_url; ?>" target="_blank">View</a></td>                            
                            </tr>
                <?php
                			$loop ++;
                			$tot_pic = $tot_pic+$FTCH_d->tot_pic;
                			$sum_qty = $sum_qty+$FTCH_d->cnt_des; 
                		}
                	}
				}
                ?>
            </tbody>
            </table> 
        </div>
        </div>   
	<?php } ?>
	<input name="tot_cnt" id="tot_cnt" type="hidden" value="<?php echo $sum_qty; ?>" />	
	<input name="mas_die" id="mas_die" type="hidden" value="<?php echo $tot_pic;  ?>" /> 
        </fieldset>
     </form>
        <div class="fluid"><!-- Media table --></div>
<?php } else {  echo ACCESS_MSG;} ?>	
    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->

</body>
</html>
