<?php $__env->startSection('content'); ?>
	<?php 
		$timecards = \App\Timecard::where('date','=','2019-05-26 00:00:00')->orderBy('created_by')->get();	
		foreach($timecards as $timecard)
		{
			echo "<h3>" . $timecard->getName() . "</h3><br>";	
			
			$entries = \App\Entry::where('timecard', '=', $timecard->id)->where('type', '=', 'allocation')->get();
			
			$one = array();
			$two = array();
			$all = array();
			
			foreach($entries as $entry)
			{
				if($entry->day <= 6)
				{
					if(array_key_exists($entry->account, $one))
					{
						$one[$entry->account] += $entry->value;
					}
					else
					{
						$one[$entry->account] = $entry->value;
					}
				}
				else 
				{
					if(array_key_exists($entry->account, $two))
					{
						$two[$entry->account] += $entry->value;
					}
					else
					{
						$two[$entry->account] = $entry->value;
					}
				}
				
				if(array_key_exists($entry->account, $all))
				{
					$all[$entry->account] += $entry->value;
				}
				else
				{
					$all[$entry->account] = $entry->value;
				}
			}
			if(count($entries) > 0)
			{
				foreach($all as $k => $v)
				{
					$allocation = \App\Allocation::find($k);
					$may = array();
					$june = array();
					
					echo "<h4>".$allocation->description."</h4>";
					

					
					if(array_key_exists($k, $one))
					{
						echo "<strong>May</strong><br>";
							
						echo "<table>";
						echo "<tr>";
						echo "<th>Account</th><th>Company</th><th>Description</th><th>Value</td>";
						echo "</tr>";
							
						$may = $allocation->calculate($one[$k]);
						foreach($may as $key => $value)
						{
							$account = \App\Account::find($key);
							echo "<tr>";
							echo "<td>";
							echo $account->number;
							echo "<td>";
							echo $account->company;
							echo "<td>";
							echo $account->description;
							echo "<td>";
							echo $value;
							echo "</tr>";
							
						}
						echo "<tr>";
						echo "<td colspan='3'>&nbsp;</td>";
						echo "<td><strong>";
						echo array_key_exists($k, $one) ? $one[$k] : 0; 
						echo "</strong></td></tr>";
						echo "</table>";
					}
					
					if(array_key_exists($k, $two))
					{
						echo "<strong>June</strong><br>";
							
						echo "<table>";
						echo "<tr>";
						echo "<th>Account</th><th>Company</th><th>Description</th><th>Value</td>";
						echo "</tr>";
							
						$june = $allocation->calculate($two[$k]);
						foreach($june as $key => $value)
						{
							$account = \App\Account::find($key);
							echo "<tr>";
							echo "<td>";
							echo $account->number;
							echo "<td>";
							echo $account->company;
							echo "<td>";
							echo $account->description;
							echo "<td>";
							echo $value;
							echo "</tr>";
							
						}
						echo "<tr>";
						echo "<td colspan='3'>&nbsp;</td>";
						echo "<td><strong>";
						echo array_key_exists($k, $two) ? $two[$k] : 0; 
						echo "</strong></td></tr>";
						echo "</table>";
					}
					
					echo "<strong>Total</strong><br>";
						
					echo "<table>";
					echo "<tr>";
					echo "<th>Account</th><th>Company</th><th>Description</th><th>Value</td>";
					echo "</tr>";
						
					foreach($allocation->calculate($v) as $key => $value)
					{
						$account = \App\Account::find($key);
						echo "<tr>";
						echo "<td>";
						echo $account->number;
						echo "<td>";
						echo $account->company;
						echo "<td>";
						echo $account->description;
						echo "<td>";
						echo $value;
						
						$mt = array_key_exists($key, $may) ? $may[$key] : 0;
						$jt = array_key_exists($key, $june) ? $june[$key] : 0;
						if(($mt + $jt) != $value)
						{
							
							echo "&nbsp; <i class='fa fa-exclamation-triangle' style='color: red;'></i>";
						}
						echo "</tr>";
					}
					echo "<tr>";
					echo "<td colspan='3'>&nbsp;</td>";
					echo "<td><strong>";
					echo array_key_exists($k, $all) ? $all[$k] : 0;
					echo "</strong></td></tr>";

					echo "</table>";
					
					echo "<hr>";
				}
					
				
			}
			else
			{
				echo "<p style='padding: 10px;'>No Allocations</p><hr>";
			}
			
			
			echo "<br><br>";
		}
	?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>
	<style>
		td, th {
			padding: 10px;
		}
	</style>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>