<?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';
	}

	function sum_the_time($tot_time=array()) 
	{
		if(count($tot_time)>0)
		{
			$seconds = 0;
			foreach ($tot_time as $time)
			{
				list($hour,$minute,$second) = explode(':', $time);
				$seconds += $hour*3600;
				$seconds += $minute*60;
				$seconds += $second;
			}
			$hours = floor($seconds/3600);
			$seconds -= $hours*3600;
			$minutes  = floor($seconds/60);
			$seconds -= $minutes*60;
			return "{$hours}:{$minutes}:{$seconds}";
		}
		else
		{
			return;
		}
	}
	
	$check_acc  = check_access('50');
?>
<!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/design_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>
<script type="text/javascript">
	function foms_validate()
	{
		var sel_date = $('#sel_date').val();
		if(sel_date=='')
		{
			alert('Please enter the delivery date');
			$('#sel_date').focus();
			return false;
		}
		$('#delivery').submit();
		
	}
</script> 
<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:">Courier List</a></li>

            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>
    </div>
    <!-- Main content -->
    <div class="wrapper">
	<?php if($check_acc==1){?>
    	<?php
    	   $sel_date = date('d/m/Y');
  			if(isset($_GET['fdate']) && $_GET['fdate']!='' ){ $fdate = $_GET['fdate'];	}else{ $fdate = ''; }
			if(isset($_GET['todate']) && $_GET['todate']!='' ){ $todate = $_GET['todate'];	}else{ $todate = ''; }
			if(isset($_GET['yea_r']) && $_GET['yea_r']!='' ){ $yea_r = 'checked="checked"'; $y_r = $_GET['yea_r'];}else{ $yea_r = ''; $y_r = '';}
			if(isset($_GET['mont_h']) && $_GET['mont_h']!='' ){ $mont_h = 'checked="checked"'; $m_h = $_GET['mont_h'];}else{ $mont_h = ''; $m_h = ''; }
			if(isset($_GET['da_y']) && $_GET['da_y']!='' ){ $da_y = 'checked="checked"'; $d_y = $_GET['da_y'];}else{ $da_y = ''; $d_y = ''; }

			$vie_url = "fdate=".$fdate."&todate=".$todate."&mont_h=".$m_h."&da_y=".$d_y."&yea_r=".$y_r;	
		?>
		<form method="get" action="<?php $_SERVER['PHP_SELF'];?>" id="delivery">
				<fieldset>
		    		<div class="widget">
							<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="yea_r" type="checkbox" value="y" <?php echo $yea_r; ?> /> <label for="yea_r">Year</label></td>
						<td width="8%"><input id="mont_h" name="mont_h" type="checkbox" value="m" <?php echo $mont_h; ?> /> <label for="mont_h">Month</label></td>
						<td width="11%"><input id="da_y" name="da_y" 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="foms_validate();" style="float: right; margin-left:20px;"/>
				<input type="button" value="Reset" class="buttonM bRed" style="float: right; margin-left:20px;" onclick="forms_rest();"/>
				<div class="clear"></div>
			 </div>
			<div class="clear"></div>
		    </div> 
			    </fieldset>
	     </form>
	    <?php
	    	if(isset($_GET['fdate']) && $_GET['fdate']!='' || isset($_GET['todate']) && $_GET['todate']!='')
				{
					$design_date = ''; 
					if($fdate!='' && $todate!='')
					{
						$dat_str = " STR_TO_DATE(del_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(del_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(del_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(del_date,'%d/%m/%Y')) = YEAR(STR_TO_DATE('$todate','%d/%m/%Y'))"; }

						if($yea_r=='' && $mont_h=='' && $da_y==''){ $dat_str = " STR_TO_DATE(del_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(del_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(del_date,'%d/%m/%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }

						if($yea_r!='' && $mont_h=='' && $da_y!=''){ $dat_str = " STR_TO_DATE(del_date,'%d/%m/%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }

						if($yea_r=='' && $mont_h!='' && $da_y!=''){ $dat_str = " STR_TO_DATE(del_date,'%d/%m/%Y') = STR_TO_DATE('$todate','%d/%m/%Y')"; }
					}
		?>
		<div class="widget">
        	<div class="whead">
        	<h6>Courier 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" id="dynamic">
		            <thead>
			            <tr>
				            <th width="26" align="center">S.No<span class="sorting" style="display: block;"></span></th>
				            <th width="92" align="left">Courier Name</th>
				            <th width="95" align="center">Courier Count</th>
				            <th width="98" align="center">Action</th>
			            </tr>
		            </thead>
		            <tbody>
			            <?php
							$count_of_cou = 0;
							$count_of_emp = 0;
							$SLCT_cor = "SELECT * FROM mas_cour_det where statu_s='active'";
							$QURY_cor = mysqli_query($connect,$SLCT_cor);
							$loop=1;
							while($FTCH_cor = mysqli_fetch_object($QURY_cor))
							{
								$SLCT_cor_cou = "SELECT count(mas_cour_det_id)as cnt FROM po_del_cour_det where mas_cour_det_id =".$FTCH_cor->mas_cour_det_id." AND ".$dat_str;
								$QURY_cor_cou = mysqli_query($connect,$SLCT_cor_cou);
								$FTCH_cor_cou = mysqli_fetch_object($QURY_cor_cou);
								$count_of_cou = $FTCH_cor_cou->cnt;
								if($count_of_cou == 0)
								{
									$count_of_cou = '-';
								}else{
									$count_of_cou = $count_of_cou;
								}

								$SLCT_emp_cou = "SELECT count(mas_cour_det_id)as cnt2 FROM po_del_cour_det where mas_cour_det_id = 0 AND emp_det_id !=0 AND ".$dat_str;
								$QURY_emp_cou = mysqli_query($connect,$SLCT_emp_cou);
								$FTCH_emp_cou = mysqli_fetch_object($QURY_emp_cou);
								$count_of_emp = $FTCH_emp_cou->cnt2;
								if($count_of_emp == 0)
								{
									$count_of_emp = '-';
								}else{
									$count_of_emp = $count_of_emp;
								}

								if($loop%2 != "0")
									$bg = "gradeX";
								else
									$bg = "class='gradeC'";
								$courier_id = base64_encode(base64_encode(base64_encode($FTCH_cor->mas_cour_det_id)));
						?>
			            <tr>
				            <td align="center" style="vertical-align:middle;"><?php echo $loop ?></td>
				            <td align="left" style="vertical-align:middle;"><?php echo $FTCH_cor->cour_name; ?></td>
				            <td align="center" style="vertical-align:middle;"><?php echo $count_of_cou; ?></td>
				            <td class="center" style="vertical-align:middle;">
				            	<?php if($count_of_cou != 0)
									{
								?>
									<a href="courier_list_view.php?courier_id=<?php echo $courier_id ?>&flag=1&<?php echo $vie_url; ?>">View</a>
								<?php 
									}else{
								?>
									-
								<?php
									}
								?>
							</td>
			            </tr>
			            <?php
							$loop ++;
							 }
						 $var_lo = $loop;
						 $courier_id1 = base64_encode(base64_encode(base64_encode(0)));
						?>
						<tr <?php echo $bg ?>>
				            <td align="center"><?php echo $var_lo ?></td>
				            <td align="center">By Hand Delivery</td>
				            <td align="center"><?php echo $count_of_emp; ?></td>
				            <td class="center">
				            	<?php if($count_of_emp != 0)
									{
								?>
									<a href="courier_list_view.php?courier_id=<?php echo $courier_id1?>&flag=2&<?php echo $vie_url; ?>">View</a>
								<?php 
									}else{
								?>
									-
								<?php
									}
								?>
				            </td>
			            </tr>
			        </tbody>
	            </table> 
	        </div>
        </div>
        <?php } ?>
     </div>
	 <?php } else {  echo ACCESS_MSG;} ?>

    <!-- Main content ends -->
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
