<?php $__env->startSection('content'); ?>
	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Timecard</h1> 
    	</div>
    </div>
        <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
	                    <?php if(session('status')): ?>
							<div class="alert alert-success">
								<?php echo e(session('status')); ?>

							</div>
						<?php endif; ?>
			
						<?php if(count($errors) > 0): ?>
							<div class="alert alert-danger">
								<strong>Whoops!</strong> There were some problems with your input.<br><br>
								<ul>
									<?php foreach($errors->all() as $error): ?>
										<li><?php echo e($error); ?></li>
									<?php endforeach; ?>
								</ul>
							</div>
						<?php endif; ?>
                        <div class="panel-heading">
                            Report
                        </div>
                        <!-- /.panel-heading -->
                        	<div class="panel-body">
                            	<?php foreach($timecards as $timecard): ?>
                            		<?php 
                            			$employee = \App\Employee::find($timecard->employee); 
                            			$user = \App\User::find($employee->user);
                            			$accounts = array();
                            		?>
                            		<strong>
                            		<?php echo e($user->name); ?> - #<?php echo e($employee->number); ?><br>
                            		<?php echo e(strtoupper(date('d-M-Y', strtotime($timecard->date)))); ?> through <?php echo e(strtoupper(date('d-M-Y', strtotime('+6 days', strtotime($timecard->date))))); ?><br>
                            		</strong>
                            		<span 
									<?php if($timecard->approve_self == '' || $timecard->approve_manager == ''): ?> 
									style="color: red;"
									<?php endif; ?>
									>
                            		Employee Approved: <?php echo e($timecard->approve_self); ?><br>
                            		Manager Approved: <?php echo e($timecard->approve_manager); ?> <?php echo e($timecard->manager ? " (" . \App\User::find(\App\Employee::find($timecard->manager)->user)->name . ")" : ''); ?><br>
                            		</span>
                            		Notes: <?php echo e($timecard->notes); ?><br><br>
                            		<?php 
                            		$week_total = 0; 
                            		$weekday_total = 0;
                            		$weekend_total = 0;
                            		$regular_total = 0;
                            		?>
                            		<table>
                            			<thead>
                            				<th>Account</th>
                            				<th>Company</th>
                            				<th>Description</th>
                            				<th>Weekday</th>
                            				<th>Weekend</th>
                            				<th>Total</th>
                            			</thead>
                            		<?php foreach($timecard->accounts as $key => $value): ?>
                            			<?php $account = \App\Account::find($key); ?>
                            			<tr>
                            				<td><?php echo e($account->number); ?></td><td><?php echo e($account->company); ?></td><td><?php echo e($account->description); ?></td>
                            			<td><?php echo e($value['weekday']); ?></td>
                            			<td><?php echo e($value['weekend']); ?></td>
                            			<td><?php echo e($value['weekday'] + $value['weekend']); ?></td>
                            			<tr>
                            			<?php 
                            			$weekday_total += $value['weekday'];
                            			$weekend_total += $value['weekend'];
                            			if($account->regular)
                            			{
                            				$regular_total += $value['weekday'] + $value['weekend'];
                            			}
                            			?>
                            		<?php endforeach; ?>
                            		<?php foreach($timecard->work_orders as $key => $value): ?>
                            			
                            			<tr>
                            				<td><?php echo e($value['number']); ?></td><td>&nbsp;</td><td><?php echo e($value['description']); ?></td>
                            			<td><?php echo e($value['weekday']); ?></td>
                            			<td><?php echo e($value['weekend']); ?></td>
                            			<td><?php echo e($value['weekday'] + $value['weekend']); ?></td>
                            			<tr>
                            			<?php 
                            			$weekday_total += $value['weekday'];
                            			$weekend_total += $value['weekend'];
                            			$regular_total += $value['weekday'] + $value['weekend'];
                            			?>
                            		<?php endforeach; ?>
                            		<?php foreach($timecard->allocations as $key => $value): ?>
                            			<?php $account = \App\Allocation::find($key); ?>
                            			<tr>
                            				<td>-</td><td>-</td><td><?php echo e($account->description); ?></td>
                            			<td><?php echo e($value['weekday']); ?></td>
                            			<td><?php echo e($value['weekend']); ?></td>
                            			<td><?php echo e($value['weekday'] + $value['weekend']); ?></td>
                            			<tr>
                            			<?php 
                            			$weekday_total += $value['weekday'];
                            			$weekend_total += $value['weekend'];
                            			
                            			$regular_total += $value['weekday'] + $value['weekend'];
                            			
                            			?>
                            		<?php endforeach; ?>
                            		</table>
                            		<br>
                            		
	                            		Weekday Total: <?php echo e($weekday_total); ?><br>
	                            		Weekend Total: <?php echo e($weekend_total); ?><br>
	                            	<strong
	                            	<?php if($weekday_total + $weekend_total > 40): ?>
	                            	style="color: red;"
	                            	<?php endif; ?>
	                            	>
	                            		Regular Total: <?php echo e($regular_total); ?><br>
	                            		Week Total: <?php echo e($weekday_total + $weekend_total); ?>

                            		</strong>
                            		<br>
                            		
                            		<?php if(\App\Entry::where('timecard','=',$timecard->id)->where('type','=','allocation')->exists()): ?>
                            		<br><strong style="text-decoration: underline;">Allocation Summary</strong><br>
                            			<?php foreach($timecard->allocations as $key => $value): ?>
                            				<?php if(\App\Entry::where('timecard','=',$timecard->id)->where('type','=','allocation')->where('account','=',$key)->exists()): ?>
                            					<?php $allocation = \App\Allocation::find($key);?> 
			             						<?php $a_total = 0;?>
			             						<?php $a_cal = array(); ?>
			             						<?php $a_time = \App\Allocation_link::where('allocation','=',$allocation->id)->where('time','!=',0.00)->exists() ? true : false;?>
			             						<?php foreach(\App\Entry::where('timecard','=',$timecard->id)->where('type','=','allocation')->where('account','=',$key)->get() as $a_entry): ?>
			             							<?php $a_total += $a_entry->value;?>
			             							<?php if($a_time): ?>
			             							<?php $a_temp = $allocation->calculate($a_entry->value); ?>
			             							<?php foreach($a_temp as $kk => $vv): ?>
			             								<?php if(array_key_exists($kk, $a_cal)): ?>
			             									<?php $a_cal[$kk] += $vv;	?>
			             								<?php else: ?>
			             									<?php $a_cal[$kk] = $vv; ?>
			             								<?php endif; ?>
			             							<?php endforeach; ?>
			             							<?php endif; ?>	
			             						<?php endforeach; ?>
			             						
			             						<?php if(!$a_time): ?>
			             						<?php $a_cal = $allocation->calculate($a_total); ?>
			             						<?php endif; ?>
			             						<strong><?php echo e($allocation->description); ?></strong>
			             						<?php foreach($a_cal as $k => $v): ?>
			             							<?php $ind_acc = \App\Account::find($k);?>
			             							<?php echo "<br>" . $ind_acc->number . " | " . $ind_acc->company . " | " . $ind_acc->description . ': ' . $v; ?>

			             						<?php endforeach; ?>
			             						<br>
			             						
			             					<?php endif; ?>
                            			<?php endforeach; ?>
                            		<?php endif; ?>
                            		
                            		<br><hr><br>
                            	<?php endforeach; ?>
                             </div>
                         </div>
                     </div>
               </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>

    <style>
    	a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}
    	th {
    		padding: 5px;
    	}
    	td {
    		padding: 5px;
    	}
		span, strong {
		-webkit-print-color-adjust: exact;
		}
		
    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>