<?php
session_start();
include("header.php");

if(trim($_SESSION['accountName'])=="" &&  trim($_SESSION['accountID'])=="" && trim($_SESSION['pgid'])!="i3g3e3nious7")
{
	echo '<script>';
	echo 'location.replace("index.php");';
	echo '</script>';
}
else
{

 
$dayAdd=0;
$sChoice=1;
if(trim($_POST['sChoice'])!="") 
	$sChoice=$_POST['sChoice'];
else if(trim($_GET['sc'])!="")
	$sChoice=$_GET['sc'];

$prv = "";
$nxt = "";
if(trim($_GET['da'])!="")
{
	$dayAdd = $_GET['da'];
}

if($dayAdd > 0)
{
	$Adday=$dayAdd-1;
	$prv="<a href='chefList.php?sc=".$sChoice."&da=".$Adday."'>prev</a>";
}
if($dayAdd<=28)
{
	$Adday=$dayAdd+1;
	$nxt="<a href='chefList.php?sc=".$sChoice."&da=".$Adday."'>next</a>";
}


	$fdate=strtotime(date('Y-m-d'));
	$odate=strtotime("+".$dayAdd." day",$fdate);
	$OrderDate=date("Y-m-d",$odate);
	
	$dayn=date("l",strtotime($OrderDate));

	$ccdate=explode("-",$OrderDate);

	$monthNum = $ccdate[1];
	$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));

	$sDate =$dayn.", ". $monthName ." ". $ccdate[2].", ".$ccdate[0];

?>
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
	<tr><td></td><td colspan="2" align="center" class="style2"><u><b>Chef's List</b></u></td></tr>
	<form action="chefList.php?sc=<?=$sChoice?>&da=<?=$dayAdd?>" method="post" name="frm">
	<tr><td rowspan="4" width="200" class="fs12" valign="top"><?php
			include("sidemenu.php");
		?></td>
		<td width="350" align="right" class="fs12"><b>SELECT:&nbsp;&nbsp;</b></td>
		<td width="300"><select name="sChoice" class="formSelect" onChange="javascript:{if(this.value!='') submit();}">
				
				<?php
					
					if($sChoice== 3) 
					{
						echo "<option value='1'>Daily</option>";
						echo "<option value='3' selected='selected'>Monthly</option>";
					}
					else
					{
						echo "<option value='1' selected='selected'>Daily</option>";
						echo "<option value='3'>Monthly</option>";
					}
				 ?> 
			</select></td></tr>
	</form>
	<?php
	if($sChoice==3)
	{
	?>
	<tr class="fs12"><td align="right"><b>Order Month:&nbsp;&nbsp;</b></td><td><b><?=$monthName?></b></td></tr>
	<?php
	}
 	else 
	{
	?>
	<tr class="fs12"><td align="right"><b>Order Date:&nbsp;&nbsp;</b></td><td><b><?=$sDate?></b></td></tr>
	<?php
	}
		?>
	<tr class="fs12"><td align="center" colspan="2"><?=$prv?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?=$nxt?></td></tr>
	<tr><td width="700" class="fs12" colspan="2">
			<table width="680" cellpadding="1" cellspacing="1" border="0">
				<tr valign="top"><td width="15%" height="10"></td><td width="50%"></td><td width="28%"></td><td width="7%" height="10"></td></tr>
				<tr valign="top"><td colspan="4"><hr /></td></tr>
				<tr><td><b>Menu CODE</b></td><td><b>Description</b></td><td><b>Notes</b></td><td align="center"><b>Orders</b></td></tr>
				<tr><td colspan="4" bgcolor="#000000" height="1"></td></tr>
			<?php
			$ordate1=$OrderDate." 00:01:01";
			if($sChoice==3)
			{
				$sord=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

					$strSql =@mysql_query("SELECT count(*) cnt,item_ordered FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id where a.service_date Like '".$sord."' and b.paid_status='1' group by a.item_ordered order by a.item_ordered");
			}
			else
			{
			
				$strSql =@mysql_query("SELECT count(*) cnt,service_date,item_ordered FROM tr_orderdetails  a left join tr_orders b on b.order_id=a.order_id where a.service_date='".$ordate1."' and b.paid_status='1' group by a.service_date,a.item_ordered order by a.item_ordered");
			}

			$cnt=@mysql_num_rows($strSql);
			if($cnt>0)
			{
				
					$tCnt = 0;
					$cCmplt = 0;
					$bDayDcnt=0;
					$birthd="%-".$ccdate[1]."-".$ccdate[2]." 00:00:00";

					if($sChoice==3)
					{
						
						$strSql1 =@mysql_query("SELECT distinct count(*) cCountBDAY FROM tr_orders b left join tr_student c on c.student_id=b.student_id where b.order_date Like '".$birthd."' and b.paid_status='1'");

					}
					else
					{
						
						$strSql1 =@mysql_query("SELECT count(*) cCountBDAY FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id left join tr_student c on c.student_id=b.student_id where a.service_date='".$ordate1."' and c.date_birth Like '".$birthd."' and b.paid_status='1'");

						
					}
					
			
				$cnt1=@mysql_num_rows($strSql1);
				if($cnt1>0)
				{
					$rs1=@mysql_fetch_array($strSql1);
					$bDayDcnt=$rs1["cCountBDAY"];
				}
		
				while($rs = @mysql_fetch_array($strSql))
				{//main while

							$tCnt=$tCnt+$rs["cnt"];
							$x=0;
							//set rs1 = server.createobject("adodb.recordset")
							if($sChoice==3)
							{
								//$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where MONTH(a.service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(a.service_date)=YEAR(CURDATE()) and a.item_ordered=".$rs["item_ordered"]." and item_type in(1,2) order by item_type");

								$sord1=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

								$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date Like '".$sord1."' and a.item_ordered=".$rs["item_ordered"]." and c.paid_status='1' and item_type in(1,2) order by item_type");

								//echo "SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where a.service_date='".$sord1."' and a.item_ordered=".$rs["item_ordered"]." and item_type in(1,2) order by item_type";
							}
							else
							{
								//$strSql1 = @mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where a.service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) and a.item_ordered=".$rs["item_ordered"]." and item_type in(1,2) order by item_type");

								$strSql1 = @mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date='".$ordate1."' and a.item_ordered=".$rs["item_ordered"]." and c.paid_status='1' and item_type in(1,2) order by item_type");
							}
						
							//end if
							//set rs1 = con.Execute(strSql1)
							$rscont=@mysql_num_rows($strSql1);

							//If not rs1.EOF then
							if($rscont>0)
							{
								//$rsf=@mysql_fetch_array($strSql1);

								
								//while not rs1.EOF 
								$i=1;
								while($rs1=@mysql_fetch_array($strSql1))
								{
									if($i==1)
									{
										echo "<tr valign='top'><td>".trim(strtoupper($rs1["menu_code"]))."</td><td>".trim($rs1["menu_name"])."</td><td>Regular & Complete</td>";
									}
									
									if($rs1["item_type"]==2 || $rs1["item_type"]==5)
									{
										$cCmplt=$cCmplt+1;
									}
									
									$x=$x+1;
									$i++;
									
								}
								
								echo "<td align='center'>".$x."</td></tr>";
							}
							
							if($sChoice==3)
							{
								//$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where MONTH(a.service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(a.service_date)=YEAR(CURDATE()) and item_ordered=".$rs["item_ordered"]." and item_type=3 group by item_ordered,item_type order by item_type");

								$sord2=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

								$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date Like '".$sord2."' and item_ordered=".$rs["item_ordered"]." and c.paid_status='1' and item_type=3 group by item_ordered,item_type order by item_type");
							}
							else
							{
								//$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) and item_ordered=".$rs["item_ordered"]." and item_type=3 group by service_date,item_ordered,item_type order by item_type");

								$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where service_date='".$ordate1."' and item_ordered=".$rs["item_ordered"]." and c.paid_status='1' and item_type=3 group by service_date,item_ordered,item_type order by item_type");
							}
							
							$cnt2=@mysql_num_rows($strSql1);
							if($cnt2>0)
							{
								$cCmplt=$cCmplt+$rs1["cnt"];
								echo "<tr valign='top'><td>".$rs1["menu_code"]."</td><td>".trim($rs1["menu_name"])."</td><td>Extra Large Complete</td><td align='center'>".$rs1["cnt"]."</td></tr>";
							}
							
							$x=0;
							if($sChoice==3)
							{

								$sord3=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

								//$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where MONTH(a.service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(a.service_date)=YEAR(CURDATE()) and a.item_ordered=".$rs["item_ordered"]." and item_type in(4,5) order by item_type");

								$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date Like '".$sord3."' and a.item_ordered=".$rs["item_ordered"]." and c.paid_status='1'and item_type in(4,5) order by item_type");
							}
							else
							{
								//$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where a.service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) and a.item_ordered=".$rs["item_ordered"]." and item_type in(4,5) order by item_type");

								$strSql1 =@mysql_query("SELECT a.item_type,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date='".$ordate1."' and a.item_ordered=".$rs["item_ordered"]." and c.paid_status='1' and item_type in(4,5) order by item_type");
							}
							
							$cnt3=@mysql_num_rows($strSql1);
							if($cnt3>0)
							{
							
								$j=1;
								while($rs1=@mysql_fetch_array($strSql1))
								{
									
										if($j==1)
										{
											echo "<tr valign='top'><td>".$rs1["menu_code"]."</td><td>".trim($rs1["menu_name"])."</td><td>Regular & Complete Halal</td>";
										}
										if($rs1["item_type"]==2 || $rs1["item_type"]==5)
										{
											$cCmplt=$cCmplt+1;
										}
										
										$x=$x+1;
										$j++;
								}
								echo "<td align='center'>".$x."</td></tr>";
							
							}
							if($sChoice==3)
							{
								//$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where MONTH(a.service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(a.service_date)=YEAR(CURDATE()) and item_ordered=".$rs["item_ordered"]." and item_type=6 group by item_ordered,item_type order by item_type");

								$sord4=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

								$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id where a.service_date Like '".$sord4."' and item_ordered='".$rs["item_ordered"]."' and c.paid_status='1' and item_type=6 group by item_ordered,item_type order by item_type");
							}
							else
							{

								//$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered where service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) and item_ordered=".$rs["item_ordered"]." and item_type=6 group by service_date,item_ordered,item_type order by item_type");

								$strSql1 =@mysql_query("SELECT count(*) cnt,b.menu_name,b.menu_code FROM tr_orderdetails a join tr_menu b on b.menu_id=a.item_ordered join tr_orders c on c.order_id=a.order_id  where service_date='".$ordate1."' and item_ordered='".$rs['item_ordered']."' and c.paid_status='1'  and item_type='6' group by service_date,item_ordered,item_type order by item_type");

							}
							//end if
							//set rs1 = con.Execute(strSql1)
							$cnt3=@mysql_num_rows($strSql1);
							if($cnt3>0)
							{
								//If not rs1.EOF then
								$cCmplt=$cCmplt+$rs1["cnt"];
								$rsf3=@mysql_fetch_array($strSql1);
								echo "<tr valign='top'><td>".$rsf3["menu_code"]."</td><td>".trim($rsf3["menu_name"])."</td><td>Extra Large Complete Halal</td><td align='center'>".$rsf3["cnt"]."</td></tr>";
								//end if
							}
							
						//wend
			}//mail while end
				if($sChoice==3)
				{
					//$strSqls =@mysql_query("SELECT count(*) cnts,item_snack FROM tr_orderdetails where MONTH(service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(service_date)=YEAR(CURDATE()) group by item_snack order by item_ordered");
					
					$sord5=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

					$strSqls =@mysql_query("SELECT count(*) cnts,item_snack FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id where a.service_date Like '".$sord5."' and  b.paid_status='1' group by item_snack order by item_ordered");
					
				}
				else
				{
					//$strSqls = @mysql_query("SELECT count(*) cnts,service_date,item_snack FROM tr_orderdetails where service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) group by service_date,item_snack order by item_ordered");

					$strSqls = @mysql_query("SELECT count(*) cnts,service_date,item_snack FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id where a.service_date='".$ordate1."' and b.paid_status='1' group by service_date,item_snack order by item_ordered");

					
				}
				
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr><td colspan='2'></><td colspan='2'><b>Snacks</b></td></tr>";
				echo "<tr><td colspan='4' bgcolor='#000000' height='1'></td></tr>";

				$rcont=@mysql_num_rows($strSqls);
				if($rcont>0)
				{
					while($rss=@mysql_fetch_array($strSqls))
					{
							echo "<tr valign='top'><td colspan='2'></td><td>".getSD($rss["item_snack"])."</td><td align='center'>".$rss["cnts"]."</td></tr>";
							
					}
				}
				
				if($sChoice==3) 
				{
					//$strSqld =@mysql_query("SELECT count(*) cnts,item_drink FROM tr_orderdetails where MONTH(service_date)=(MONTH(CURDATE())+".$dayAdd.") and YEAR(service_date)=YEAR(CURDATE()) group by item_drink order by item_ordered");
					
					$sord6=$ccdate[0]."-".$ccdate[1]."-% 00:01:01";

					$strSqld =@mysql_query("SELECT count(*) cnts,item_drink FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id where service_date Like '".$sord6."' and b.paid_status='1'  group by item_drink order by item_ordered");
				}
				else
				{
					//$strSqld = @mysql_query("SELECT count(*) cnts,service_date,item_drink FROM tr_orderdetails where service_date=DATE_ADD(CURDATE(),INTERVAL ".$dayAdd." DAY) group by service_date,item_drink order by item_ordered");

					$strSqld = @mysql_query("SELECT count(*) cnts,service_date,item_drink FROM tr_orderdetails a left join tr_orders b on b.order_id=a.order_id where service_date='".$ordate1."' and b.paid_status='1' group by service_date,item_drink order by item_ordered");

				}
				
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr><td colspan='2'></><td colspan='2'><b>Drinks</b></td></tr>";
				echo "<tr><td colspan='4' bgcolor='#000000' height='1'></td></tr>";
				$rsdcnt=@mysql_num_rows($strSqld);
				//set rsd = con.Execute(strSqld)
				if($rsdcnt>0)
				{
					
					while($rsdd=@mysql_fetch_array($strSqld))
					{
						echo "<tr valign='top'><td colspan='2'></td><td>".getSD($rsdd['item_drink'])."</td><td align='center'>".$rsdd["cnts"]."</td></tr>";
						
					}
					
				}
				
				echo "<tr><td colspan='4'><hr /></td></tr>";
				echo "<tr><td colspan='4' bgcolor='#000000' height='1'></td></tr>";
				echo "<tr valign='top'><td></td><td>";

				//echo "<a href='#' onclick='javascript:window.open('chefListReport.php?sc=".$sChoice."&da=".$dayAdd."');'>View Print Report</a></td>";

				echo "<a href='#' onClick='javascript:window.open(\"chefListReport.php?sc=".$sChoice."&da=".$dayAdd."\",\"Print Report\",\"menubar=1,resizable=1,width=800,height=800,scrollbars=1\");' >View Print Report</a>&nbsp;&nbsp;</td>";

				echo "<td align='right'><b>Total Menu Order(s):</b>&nbsp;&nbsp;</td><td align='center'><b>".$tCnt."</b></td></tr>";
				echo "<tr valign='top'><td colspan='2'></td><td align='right'><b>Total Complete Count:</b>&nbsp;&nbsp;</td><td align='center'><b>".$cCmplt ."</b></td></tr>";
				if($sChoice==1)
				{
					echo "<tr valign='top'><td colspan='2'></td><td align='right'><b>Total Birthday Count:</b>&nbsp;&nbsp;</td><td align='center'><b>".$bDayDcnt."</b></td></tr>";
				}
			}
			else
			{
				echo "<tr><td colspan='4' align='center' height='100'>There's no Order for this Date!</td></tr>";
				echo "<tr><td colspan='4' bgcolor='#000000' height='1'></td></tr>";
			}
				
			  ?>
			</table></td></tr>
</table>
<?php
include("footer.php");
}
?>
