<?php
include("../include/session.php");
if(!$session->logged_in){
    header("Location: ../main.php");
}else{
//	include("../include/db.php");
	include("../productionHeader.php");
	
   

//$mm = date("m");
//$a = date("Y-m-d",mktime(0,0,0,$mm, 01, 2012));
//$b = date("Y-m-d");

$today = date("Y-m-d");

$start = date("Y-m-01");
$end = date("Y-m-31");

if (date("m")==2) {$end = date("Y-m-28");}
	
if ( (date("m")==4) OR (date("m")==6) OR (date("m")==9) OR (date("m")==11) ) {$end = date("Y-m-30");}
	


$query = "SELECT * FROM nam_productiondepalet WHERE date >= '$start' AND date <= '$end'  ORDER BY date DESC ";
	$result = execsql($query);
	$num = mysql_num_rows($result);

	$queryLate = "SELECT * FROM nam_production WHERE date >= '$start' AND date <= '$end'   ORDER BY date DESC  ";
	$resultLate = execsql($queryLate);
	$numLate = mysql_num_rows($resultLate);
	//echo $queryLate;

		$q = "SELECT recipieId, recipieName FROM nam_recipie";
	$resultPro = execsql($q);
	$numPro = mysql_num_rows($resultPro);
	$j = 0;
	$proArray = array();
	while($j < $numPro){
		$proArray[mysql_result($resultPro, $j, "recipieId")] = mysql_result($resultPro, $j, "recipieName");
		$j++;
	}
	
	$tCost = 0;
?>
<div class="headerbox2">Production this month </div>
<div align="right"><font size=2><a href="productionByDates.php?<?php echo "monthdisplay=0"; ?>">show full list</a></font></div>


<table id="test1" cellpadding="0" cellspacing="0" border="0" class="rowstyle-alt colstyle-alt no-arrow">
    <thead>
      <tr>
        <th width="90" class="sortable-date-ymd">Date</th>
        <th width="197" class="sortable-text">Recipie Id</th>
        <th width="91" class="sortable-numeric">Skips</th>
        <th width="100" class="sortable-numeric">Wet Tiles </th>
        <th width="113" class="sortable-numeric">Cost</th>
      </tr>
    </thead>
    <tbody>
<?php
    $i = 0;
    while($i < $numLate){

       $b2 = mysql_result($resultLate, $i, "date");
       $b3 = mysql_result($resultLate, $i, "skips");
       $b4 = mysql_result($resultLate, $i, "cost");
       $b5 = mysql_result($resultLate, $i, "wet");
       $b6 = mysql_result($resultLate, $i, "depalet");
       $b7 = mysql_result($resultLate, $i, "recipieId");
       $b8 = mysql_result($resultLate, $i, "depRecId");
		$tSkips += $b3;
		$tCost += $b4;
		$tWet += $b5;
      // echo "<tr><td class="sortable-numeric">$b1</td><td>$b2</td><td>$permission</td><td>$b4</td><td>$b5</td><td>$b6</td></tr>";
      // $i++;
   // }
?>

 <tr class="alt">
        <td><?php echo $b2?></td>
        <td><a href="../Production/viewRecipies.php?id=<?php echo $b7?>"><?php echo $proArray[$b7]?></a></td>
        <td align="right"><?php echo $b3?></td>
        <td align="right"><?php echo $b5?></td>
        <td align="right"><?php echo $b4?></td>
      </tr>
<?php
    $i++;
    }
?>
</tbody>
</table>

<br /><br />
<div class="headerbox2">Depalleted this month </div>
<div align="right"><font size=2><a href="depByDates.php?<?php echo "monthdisplay=0"; ?>">show full list</a></div>


<table id="test1" cellpadding="0" cellspacing="0" border="0" class="rowstyle-alt colstyle-alt no-arrow">
    <thead>
      <tr>
        <th width="90" class="sortable-date-ymd">Date</th>
        <th width="251" class="sortable-text">Recipie Id</th>
        <th width="135" class="sortable-numeric">Tiles</th>
        <th width="115" class="sortable-numeric">Cost</th>
      </tr>
    </thead>
    <tbody>
<?php
    $i = 0;
    while($i < $num){

       $b1 = mysql_result($result, $i, "date");
       $b2 = mysql_result($result, $i, "recipieId");
       $b3 = mysql_result($result, $i, "cost");
       $b4 = mysql_result($result, $i, "amountOfTiles");
       $tCostD += $b3;
       $tDep += $b4;


      // echo "<tr><td class="sortable-numeric">$b1</td><td>$b2</td><td>$permission</td><td>$b4</td><td>$b5</td><td>$b6</td></tr>";
      // $i++;
   // }
?>

 <tr class="alt">
        <td><?php echo $b1?></td>
        <td><a href="../Production/viewRecipies.php?id=<?php echo $b2?>"><?php echo $proArray[$b2]?></a></td>
        <td align="right"><?php echo $b4?></td>
        <td align="right"><?php echo $b3?></td>
      </tr>
<?php
    $i++;
    }
?>

</tbody>
</table>

</font>
<?php
include("../footer.php");
}?>