<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use kartik\widgets\ActiveField;
use kartik\widgets\SELECT2;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use modules\users\models\User;
use kartik\widgets\DateTimePicker;
use modules\custom\models\Accounts;
use frontend\models\Uploads;
use frontend\models\Jobnos;
use frontend\models\Dtpdfsearch;
use frontend\models\Uploadssearch;
use dosamigos\fileupload\FileUploadUI;
use yii\bootstrap4\Modal;
use yii\db\Query;
use yii\web\JsExpression;
use yii\helpers\Json;
use kartik\widgets\DepDrop;


/* @var $this yii\web\View */
/* @var $model frontend\models\Activities */
$users = ArrayHelper::map(User::find()->where("username != 'Admin'")->all(), 'username', 'personalemail');
$account =  $model->company != null ? $model->account->Account_Name : '';

?>
<style>
	#Attachments{
		width: 50%;
		height: auto
	}
</style>
<div class="activities-form">
<?php $form = ActiveForm::begin(['options' => ['id' => 'form', 'enctype' => 'multipart/form-data', 'onLoad' => 'event1())']]); ?>
<td></td>

<table class='Table'>
<tr>
	<th class="DarkerBlueC">Job Number</th>
<td><?= $model->jobno ?></td>
<th class="DarkerBlueC">Welders</th>
<td><?= $model->welder ?></td> 
<th class="DarkerBlueC">Company</th>
	<td><?= $account ?></td>
	
			<tr>
	<th class="DarkerBlueC" colspan="2">Time</th>
	<th class="DarkerBlueC" colspan="2">Travel</th>
	<th class="DarkerBlueC" colspan="2">Teams</th>
	</tr>	
	
	</tr>
	<tr>
	<th class="DarkerBlueC">Start</th>
	<td><?= date("d/m/Y - H:i", strtotime($model->sdate));?></td>
	<th class="DarkerBlueC">Location</th>
	<td><?= $model->location ?></td>
	</tr>
	<tr>
	<th class="DarkerBlueC">Shift Length</th>
	<td><?= $model->shiftlength ?></td>
	
	
	
	
	<th class="DarkerBlueC">Post Code</th>
	<td><div style="float: Left"><?= $model->postcode ?> </div>
	<div style="float: Right">
		
	<?= Html::a('Map','' , ['class' => 'btn btn-primary', 'onclick' => 'map()']); ?>	
	<script>
		function map() {
    window.open("https://www.google.co.uk/maps/place/"+"<?= $model->postcode ?> ", '', 'height='+screen.height,'width='+screen.width,'fullscreen=yes');	
    } 
		
	</script>
	<?= $form->field($model, 'postcode')->hiddenInput(['id' => 'postcode'])->label(false) ?>
	</div>
	</td>
	<th class="DarkerBlueC">Number of Shifts</th>
	<td><?= $model->noofshifts ?></td>
		
		
		
	</tr>
	<tr>
	<th class="DarkerBlueC">Finish</th>
	<td><?= date("d/m/Y - H:i", strtotime($model->edate));?></td>
	<th class="DarkerBlueC">Google Time</th>
	<td><?= $model->googletime ?></td>
	<th class="DarkerBlueC">Number of Teams</th>
	<td><?= $model->noofteams ?></td>
	
	
	
	</tr>
	<tr>
	<th class="DarkerBlueC">Day</th>
	<td><?= $model->day ?></td>
	<th class="DarkerBlueC">Google Distance</th>
	<td><?= $model->googledistance ?></td>
	<th class="DarkerBlueC"style="width: 15%">Number of Welds</th>
	<td><?= $model->noofwelds ?></td>
	
	</tr>
	<tr>
	<th class="DarkerBlueC" style="width: 10%">Week No</th>
	<td><?= $model->weekno ?></td>
	<th class="DarkerBlueC">Journey Type</th>
	<td><?= $model->journey ?></td>
	<th class="DarkerBlueC" style="width: 10%">Purchase Order No</th>
	<td><?= $model->customerpono ?></td>
	</tr>
	
	<tr>
		<th class="DarkerBlueC">Shift</th>
	<td><?= $model->shift ?></td>
	
		<th class="DarkerBlue">Access Point</th>
		<td><?= $model->accesspoint ?></td>
		<th class="DarkerBlue"></th>
		<td></td>
	</tr>
	
	<tr>
		<th colspan="6" class="DarkerBlueC">Comments / Job Details</th>
	</tr>	
	<tr style="text-align: Center">
		<td colspan="5"><?= $model->details ?></td>
	</tr>
	<tr class="DarkerBlueC">
		<th class="DarkerBlueC">Job Type</th>
		<th class="DarkerBlueC">Weld Type</th>
		<th class="DarkerBlueC">Rail Grade</th>
		<th class="DarkerBlueC">Rail Section</th>
	</tr>
	<tr style="text-align: Center">
	
		<td><?= $model->jobtype ?></td>
		<td><?= $model->weldtype ?></td>
		
	</tr>
	<tr class="DarkerBlueC">
		<th class="DarkerBlueC">Grade</th>
		<th class="DarkerBlueC">Section</th>
		<th class="DarkerBlueC">Support</th>
		<th class="DarkerBlueC">Diff Wear</th>
		<th class="DarkerBlueC">Track Type</th>
		<th class="DarkerBlueC">Weld</th>
		<th class="DarkerBlueC">No of Welds</th>
	</tr>
	
	<tr>
<td><?= $model->railgrade ?></td>
<td><?= $model->railsection ?></td>
<td><?= $model->railsupport ?></td>
<td></td>
<td><?= $model->railtrack ?></td>
<td><?= $model->weld ?></td>
<td><?= $model->noofwelds1 ?></td>

</tr>
<tr>
<td><?= $model->railgrade2 ?></td>
<td><?= $model->railsection2 ?></td>
<td><?= $model->railsupport2 ?></td>
<td><?= $model->railwear2 ?></td>
<td><?= $model->railtrack2 ?></td>
<td><?= $model->weld2 ?></td>
<td><?= $model->noofwelds2 ?></td>
</tr>
<tr>

<td><?= $model->railgrade3 ?></td>
<td><?= $model->railsection3 ?></td>
<td><?= $model->railsupport3 ?></td>
<td><?= $model->railwear3 ?></td>
<td><?= $model->railtrack3 ?></td>
<td><?= $model->weld3 ?></td>
<td><?= $model->noofwelds3 ?></td>
</tr>
	
	
	</table>
	
	<div style="float: left;">
		
	<table width=50%>
		<tr class="DarkerBlue">
			<th></th>
			<th>Process</th>
			<th>Fuel Gas</th>
			<th>Notes</th>
		</tr>
		<tr>
		<th class="DarkerBlueC">1</th>
		<td> <?= $model->dtwps1->process ?><br /></td>
		<td> <?= $model->fuelgas ?></td>
		<td> <?= $model->notes ?></td>
		</tr>
		<tr>
		<th class="DarkerBlueC">2</th>
		<td> <?= $model->dtwps2->process ?><br /></td>
		<td> <?= $model->fuelgas2 ?></td>
		<td> <?= $model->notes2 ?></td>
		</tr>
		<tr>
		<th class="DarkerBlueC">3</th>
		<td> <?= $model->dtwps3->process ?><br /></td>
		<td> <?= $model->fuelgas3 ?></td>
		<td> <?= $model->notes3 ?></td>
		</tr>
		
		
	</tables>
	</div>
	<div style="float: right;" valign="top" align="left">
	<p style="width: 100%" class="DarkerBlueC Title">Notes</p>
		<?= $model->jnotes ?>
	</div>	
	
	
	<table class="Table">
	<tr>
		<th class="DarkerBlueC">Contact Name</th><th class="DarkerBlueC">Contact Number</th><th class="DarkerBlueC">Contact E-mail</th>
	</tr>
	<tr style="text-align: Center">
		<td> <?= ($model->contact != null ? $model->contactl->Firstname : '');?></td>
		<td><?= $model->contactno ?></td>
		<td><?= $model->contactemail ?></td>
	</tr>
		<tr style="text-align: Center">
		<td> <?= ($model->contact2 != null ? $model->contact2l->Firstname : '');?></td>
		<td><?= $model->contactno2 ?></td>
		<td><?= $model->contactemail2 ?></td>
	</tr>	<tr style="text-align: Center">
		<td> <?= ($model->contact3 != null ? $model->contact3l->Firstname : '');?></td>
		<td><?= $model->contactno3 ?></td>
		<td><?= $model->contactemail3 ?></td>
	</tr>	<tr style="text-align: Center">
		<td> <?= ($model->contact4 != null ? $model->contact4l->Firstname : '');?></td>
		<td><?= $model->contactno4 ?></td>
		<td><?= $model->contactemail4 ?></td>
	</tr>
		<tr style="text-align: Center">
		<td> <?= ($model->contact5 != null ? $model->contact5l->Firstname : '');?></td>
		<td><?= $model->contactno5 ?></td>
		<td><?= $model->contactemail5 ?></td>
	</tr>
</table>
<table width="100%">
<tr>
	<td class="DarkerBlue Title" colspan="2">Files</td>
</tr>
<tr>
	<td valign="top">
	    	<?php
	    	if (Yii::$app->user->identity->role =='Oadmin') {
    		   $uploads = Uploads::find()->where(['actid' => $model->id])->all();}
    		   else {
    		   $uploads = Uploads::find()->where(['actid' => $model->id])->andwhere(['category' => 'TEF'])->all();
			   }
       // $dataProvider = 
    	?>
    		
    		<table  width="100%">
    		<tr >
    			<th class="DarkerBlue">Category</th>
    			<th class="DarkerBlue">Title</th>
    			<th class="DarkerBlue">Created</th>
    			<th class="DarkerBlue">Created By</th>
    			<th class="DarkerBlue">Dowload</th>
    		</tr>
    	<?php foreach ($uploads as $upload) : ?>
    		<tr>
 <td><?= $upload->category ?></td>   			
 <td><?= $upload->title ?></td>   			
 <td><?=  date("d/m/Y - H:i", $upload->created_at); ?></td>   			
 <td><?php if (isset($upload->createdby->username)) {echo $upload->createdby->username;} ?></td>
 <form method="post"></form>   			
 <td><a class="btn" download="<?= $upload->title ?>" href="<?= $upload->data ?>"   draggable="true" class="dragout">Download</a>
 <input type="submit" value=<?= $upload->id ?> href=/upload/delete&id=<?= $upload->id ?> method="post" draggable="true" class="dragout">Delete</input></td>   			
    		</tr>
    	<?php endforeach ?>
    		</table>
    		</td>
<td valign="top"><table width="100%">
	<tr>
		<th class="DarkerBlue">File Name</th>
		<th class="DarkerBlue">Received</th>
	</tr>
	<tr>
	<td>Enquiry</td>
<td><?= $model->fileenquiry ?></td>
</tr>
<tr>
<td>Quotation</td>
<td><?= $model->filequotation ?></td>
</tr>
<tr>
<td>Order</td>
<td><?= $model->fileorder ?></td>	
</tr>
<tr>
	<td>TEF</td>
<td><?= $model->filetef ?></td>
</tr>
<tr>
	<td>All completed documentation	</td>
<td><?= $model->filedocs ?></td>
</tr>
</table>
</td>
</tr>
	
</table>


<div name="Billing">

</div>
    <div >
    <table Class="Table">
    	<tr>
    		<th class="DarkerBlueC">
    		Work Forms 			
    		</th>
    		<th colspan="2" class="DarkerBlueC">Status</th>
    	</tr>
    	<tr>
    		<td width="50%">
    	<?php
        $searchModel = new dtpdfsearch();
        $dataProvider = $searchModel->actsearch(Yii::$app->request->queryParams);
        // $dataProvider = 
    	?>
    		
    		
    	<?= GridView::widget([
        'dataProvider' => $dataProvider,
        //s'filterModel' => $searchModel,
        'columns' => [
            //'id',
            //'formid',
            //'actid',
            //'jobno',
            'form',
            //'fullurl:url',
             ['label' => 'Update',
             'format' => 'raw',
     			'value'=>function ($model, $key, $index) {
        		return Html::a("Update",$model->updateurl);
    			},],
    			
            //'fullurl:url',
             ['label' => 'View',
             'format' => 'raw',
     			'value'=>function ($model, $key, $index) {
        		return Html::a("View",$model->viewurl);
    			},],
    			
            //'fullurl:url',
            ['label' => 'PDF',
             'format' => 'raw',
     			'value'=>function ($model, $key, $index) {
        		return Html::a("PDF",$model->pdfurl);
    			},],
            //'formid',
            'welder',
            [
            'attribute' => 'user.username',
            'label' => 'Created By',
            ],
             [            'attribute' => 'created_at',
            //'format' => ['raw', 'Y-m-d H:i:s'],
    'format' =>  ['date', 'php:d/m/Y - H:i'],
            'options' => ['width' => '175']
],
            
            //'created_at:datetime',         
            ['class' => 'common\widgets\ActionColumn', 
            'controller' => 'dtpdf',
            'header'=>'Actions',
        	'template' => '{delete}',
            ],
            // 'status',
        ],
    ]); ?>
    		</td>
    		<td valign="top">
    <table class="Table">
		<tr>
		<th class="DarkerBlueC">Job Status</th>	
		<th class="DarkerBlueC">Billing Status</th>
		</tr>
		<tr>
<td><?= $model->jobstatus ?></td>
<td><?= $model->billingstatus ?></td>
		</tr>
	</table>
    		</td>
    		
    		
    		
    	</tr>
    </table>
    

</div>
<br>
</div>

    <div id="mma"></div>
    <div id="thermic"></div>
    <div id="inspection">
    <?= Html::a('Vehicle Tool Check Form', ['/dt5/create', 
    'injobno' => $model->jobno, 
    'starttime' => $model->sdate,
    'actid' => $model->id,
    //'site' => $model->location,
    //'finishtime' => $model->edate,
    //'company' =>$model->company,
    //'contact' => $model->contact,
    //'contactno' => $model->contactno,
    //'contactemail' => $model->contactemail,
    //'noofwelds' => $model->noofwelds,
    //'weekno' => $model->weekno,
    //'po' => $model->customerpono,
    //'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?> 
    
    <?= Html::a('Thermic Weld Inspection Form', ['/dt122/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' =>$model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?> 
    <?= Html::a('Welders Work Return - Plane Line Repairs', ['/dt142/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>	
    </div>
    <div id="installation">
    
    <?= Html::a('Aluminothermic Welding Installation Form', ['/dt123/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>
    	
    <?= Html::a('Welders Work Return - Crossing Repair/Maintenance', ['/dt125/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>	
    	
    <?= Html::a('Electric Welding and Switch Repair & Timesheet Form', ['/dt126/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>	
    
    <?= Html::a('Conductor Rail Welding Installation & Timesheet Form', ['/dt130/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>
    </div>
    
    <div id="balfour">
    <div id="Installations">
    	    <?= Html::a('Balfour Beatty Weld Installation Form', ['/wel233/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'day' => $model->day,
    'noofwelds' => $model->noofwelds,
	'shift' => $model->shift,
	'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>
    </div>
    	
    </div>
    <div id="details">
    <?= Html::a('Site Report', ['/dt129/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>
    
    <?= Html::a('TimeSheet', ['/dt179/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>
    
    <?= Html::a('Welders Arangement Sheets', ['/was/create', 
    'injobno' => $model->jobno, 
    'day' => $model->day, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
	'noofwelds' => $model->noofwelds,
    'comments' => $model->details,
    'postcode' => $model->postcode,
    'railgrade' => $model->railgrade,
    'railsection' => $model->railsection,
    'welders' => $model->welder,
    'actid' => $model->id,
    'pcemail1' => $model->contactemail,
    'pcemail2' => $model->contactemail2,
    'pcemail3' => $model->contactemail3,
    'pcemail4' => $model->contactemail4,
    'pcemail5' => $model->contactemail5,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
], ['class' => 'btn btn-primary']); ?>

    <?= Html::a('Non Conformance', ['/dt128/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->sdate,
    'finishtime' => $model->edate,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    'welders' => $model->welder,
    ], ['class' => 'btn btn-primary']); ?>


</div>
    <div class="form-group">
   	<?php Modal::begin(['id' => 'modal']);
    echo "<div id='modalContent'></div>";
    Modal::end();
    ?>
    

<?= Html::a('Attended', ['/activities/siteattended', 'id' =>$model->id], [
    'class'=>'btn btn-primary', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Mark Job as attended'
]);
?>  
 

<?= Html::a('PDF Jobs', ['/activities/pdf', 'id' =>$model->id], [
    'class'=>'btn btn-primary', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Create PDF'
]);
?><br>
	
<?php if (Yii::$app->user->identity->role == 'Oadmin') { echo "<div style='border: solid 1px black;'>Admin <br>
".

	Html::a('Send all PDF Jobs', ['/activities/apdf', 'id' =>$model->id], [
    'class'=>'btn btn-primary', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Create PDF'
])."".
	 Html::a('PDF all Sheets', ['/activities/apdfview', 'id' =>$model->id], [
    'class'=>'btn btn-primary', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Create PDF'
])."".


Html::a('PDF my sheets', ['/activities/pdfview', 'id' =>$model->id], [
    'class'=>'btn btn-primary', 
    'target'=>'_blank', 
    'data-toggle'=>'tooltip', 
    'title'=>'Create PDF'
]);
}
?>
		
		
	</div>
	

<br>

<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>

    </div>
    <?php ActiveForm::end(); ?>



</div>