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


/* @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>
</tr>
<tr><th class="DarkerBlueC">Welders</th>
<td><?= $model->welder ?></td> 
	</tr>
	
	<tr>
	<th class="DarkerBlueC">Company</th>
	<td><?= $account ?></td>
	</tr>
	</table>
	<table class='Table'>
	<tr class="DarkerBlueC">
	<th class="DarkerBlueC">Start</th><th class="DarkerBlueC">Finish</th><th class="DarkerBlueC">Day</th>
	<th class="DarkerBlueC">Shift</th>
	</tr>
	<tr>
	<td><?= $model->sdate ?></td>
	<td><?= $model->edate?></td>
	<td><?= $model->day ?></td>
	<td><?= $model->shift ?></td>
	</tr>	
	<tr class="DarkerBlueC">
	<th class="DarkerBlueC" colspan="5"> Travel</th>
	</tr>	
	<tr class="DarkerBlueC">
	<th class="DarkerBlueC">Location</th>
	<th class="DarkerBlueC">Post Code</th>
	<th class="DarkerBlueC">Google Time</th>
	<th class="DarkerBlueC">Google Distance</th>
	<th class="DarkerBlueC">Journey Type</th>
	
	
	</tr>
	<tr>
	<td><?= $model->location ?></td>
	<td><?= $model->postcode ?> 
	<?= 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) ?>
	</td>
	<td><?= $model->googletime ?></td>
	<td><?= $model->googledistance ?></td>
	<td><?= $model->journey ?></td>
	</tr>
	<tr class="DarkerBlueC"><th class="DarkerBlueC">Shift Length</th><th class="DarkerBlueC">Number of Shifts</th><th class="DarkerBlueC">Number of Teams</th>
		<th class="DarkerBlueC"style="width: 15%">Number of Welds</th><th class="DarkerBlueC" style="width: 10%">Week No</th><th class="DarkerBlueC" style="width: 10%">Purchase Order No</th>
	</tr>
	<tr style="text-align: Center">
	<td><?= $model->shiftlength ?></td>
	<td><?= $model->noofshifts ?></td>
	<td><?= $model->noofteams ?></td>
	<td><?= $model->noofwelds ?></td>
	<td><?= $model->weekno ?></td>
	<td><?= $model->customerpono ?></td>
	</tr>
	<tr>
		<th colspan="5" 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>
		<td><?= $model->railgrade ?></td>
		<td><?= $model->railsection ?></td>
		
	</tr>
	</table>
	<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 class="Table">
	<tr>
	<td width="40%"
	    	<?php
        $searchModel = new uploadssearch();
        $dataProvider = $searchModel->euploadsearch(Yii::$app->request->queryParams);
        // $dataProvider = 
    	?>
    		
    		
    	<?= GridView::widget([
        'dataProvider' => $dataProvider,
        //s'filterModel' => $searchModel,
        'columns' => [
        	'category',
            'title',
            'created_at:datetime',         
            ['class' => 'common\widgets\ActionColumn', 
            'controller' => 'upload',
            'header'=>'Actions',
        	'template' => '{view} {delete}',
            ],
            // 'status',
        ],
    ]); ?>
	
</td>
<td>
	<table class="Table">
	<tr>
		<td>File Name</td>
		<td>Received</td>
	</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',
            ],
            
            'created_at:datetime',         
            ['class' => 'common\widgets\ActionColumn', 
            'controller' => 'dtpdf',
            'header'=>'Actions',
        	'template' => '{delete}',
            ],
            // 'status',
        ],
    ]); ?>
    		</td>
    		<td>
    <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('Thermic Weld Inspection Form', ['/dt122/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' =>$model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?> 
    <?= Html::a('Welders Work Return - Plane Line Repairs', ['/dt142/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>	
    </div>
    <div id="installation">
    
    <?= Html::a('Aluminothermic Welding Installation Form', ['/dt123/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>
    	
    <?= Html::a('Welders Work Return - Crossing Repair/Maintenance', ['/dt125/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>	
    	
    <?= Html::a('Electric Welding and Switch Repair & Timesheet Form', ['/dt126/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>	
    
    <?= Html::a('Conductor Rail Welding Installation & Timesheet Form', ['/dt130/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['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->starttime,
    'finishtime' => $model->finishtime,
    '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,
    ], ['class' => 'btn btn-primary']); ?>
    </div>
    	
    </div>
    <div id="details">
    <?= Html::a('Site Report', ['/dt129/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>
    
    <?= Html::a('TimeSheet', ['/dt179/create', 
    'injobno' => $model->jobno, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    'company' => $model->company,
    'contact' => $model->contact,
    'contactno' => $model->contactno,
    'contactemail' => $model->contactemail,
    'noofwelds' => $model->noofwelds,
    'actid' => $model->id,
    'weekno' => $model->weekno,
    'po' => $model->customerpono,
    ], ['class' => 'btn btn-primary']); ?>
    
    <?= Html::a('Welders Arangement Sheets', ['/was/create', 
    'injobno' => $model->jobno, 
    'day' => $model->day, 
    'site' => $model->location,
    'starttime' => $model->starttime,
    'finishtime' => $model->finishtime,
    '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,
], ['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,
    ], ['class' => 'btn btn-primary']); ?>

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

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

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



</div>