<?php
use yii\helpers\Html;
use yii\helpers\Url;
use frontend\models\Users;
use frontend\models\Activities;


//->where('>=', 'sdate' $sdate)->andwhere('<=', 'edate', $edate)
$date = strtotime("05/06/2016 18:00");
$date0 = strtotime("05/06/2016 ");
$date1 = strtotime("+1 day", $date0);
$date2 = strtotime("+2 day", $date0);
$date3 = strtotime("+3 day", $date0);
$date4 = strtotime("+4 day", $date0);
$date5 = strtotime("+5 day", $date0);
$date6 = strtotime("+6 day", $date0);
$date7 = strtotime("+7 day", $date0);
$date8 = strtotime("+18 Hours", $date7);
?>
Start
<input type="datetime"/>

End
<input type="datetime">Start+7</input>

GRID
<?php $user = users::find()->where(['is', 'blocked_at', null])->andwhere(['<>', 'username', 'Admin'])->orderBy('username ASC')->all(); ?>
		<?php foreach ($user as $key => $utable) : ?>
<p style="font-weight: bold" align="center" class="DarkerBlueC Title"> <?= $utable->username ?> </p>


<table Class="Table">
<tr><th>Job No </th><th>Job Status</th><th>Date</th> 

<th><?= date('d/m/Y', $date) ?><br> Friday After 6PM</th>
<th><?= date('D', $date1) ?><br><?= date('d/m/Y', $date1) ?></th>
<th><?= date('D', $date2) ?><br><?=date('d/m/Y', $date2) ?></th>
<th><?= date('D', $date3) ?><br><?=date('d/m/Y', $date3) ?></th>
<th><?= date('D', $date4) ?><br><?=date('d/m/Y', $date4) ?></th>
<th><?= date('D', $date5) ?><br><?=date('d/m/Y', $date5) ?></th>
<th><?= date('D', $date6) ?><br><?=date('d/m/Y', $date6) ?></th>
<th><?= date('D', $date7) ?><br><?=date('d/m/Y', $date7) ?></th>
<th>Lodge</th><th>Expenses</th><th>Travel</th>
<th> Total Hours</th>
</tr>
	<?php $data = Activities::find()->where(['>=', 'starttime', $date])->andwhere(['<=', 'starttime', $date8])->andwhere(['like', 'welder', $utable->username])->orderby('starttime ASC')->all(); $sum = 0;?>
		<?php foreach ($data as $key => $row) : ?>
		
		
		<?php if ($row->starttime > $date and $row->starttime < $date1) {$d1 = $row->shiftlength;} else {$d1 = '';} ?><!-- Friday after 6 --> 
		<?php if ($row->starttime > $date1 and $row->starttime < $date2) {$d2 = $row->shiftlength;} else {$d2 = '';} ?><!-- Saturday - Sun -->
		<?php if ($row->starttime > $date2 and $row->starttime < $date3) {$d3 = $row->shiftlength;} else {$d3 = '';} ?><!-- Sunday - Mon -->
		<?php if ($row->starttime > $date3 and $row->starttime < $date4) {$d4 = $row->shiftlength;} else {$d4 = '';} ?><!-- Monday -->
		<?php if ($row->starttime > $date4 and $row->starttime < $date5) {$d5 = $row->shiftlength;} else {$d5 = '';} ?><!-- Tuesday -->
		<?php if ($row->starttime > $date5 and $row->starttime < $date6) {$d6 = $row->shiftlength;} else {$d6 = '';} ?><!-- Wednesday -->
		<?php if ($row->starttime > $date6 and $row->starttime < $date7) {$d7 = $row->shiftlength;} else {$d7 = '';} ?><!-- Thursday -->
		<?php if ($row->starttime > $date7 and $row->starttime < $date8) {$d8 = $row->shiftlength;} else {$d8 = '';} ?><!-- Friday before 6 -->
		
		
		<?php if ($welder = $utable->username) {
			 echo "
	<tr>
		<td>". $row->jobno ."</td>
		<td>". $row->jobstatus ."</td>
		<td>".date("d/m/Y - H:i", $row->starttime)."</td>
		
		<td>".$d1."</td>
		<td>".$d2."</td>
		<td>".$d3."</td>
		<td>".$d4."</td>
		<td>".$d5."</td>
		<td>".$d6."</td>
		<td>".$d7."</td>
		<td>".$d8."</td>
		
		
	</tr>
	";} else '' ?>
	<?php $sum += $row->shiftlength; ?>
	<?php endforeach; ?>
	<tr><td></td><td></td><th>Total Hours</th><td><?= $sum ?></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
	
	
</table>
	<?php endforeach; ?>