| Current Path : /var/www/html/ebookingdbkl/frontend/modules/services/controllers/ |
| Current File : /var/www/html/ebookingdbkl/frontend/modules/services/controllers/ServicesReportController.php |
<?php
namespace frontend\modules\services\controllers;
use Yii;
use yii\helpers\Url;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use kartik\mpdf\Pdf;
use backend\modules\serviceApplication\models\ServiceApplication;
use backend\modules\serviceApplication\models\ServiceTask;
use backend\modules\serviceApplication\models\ServicePic;
use backend\modules\fruserdynav2\models\FrontendUser;
use \backend\modules\refdynawebv2\models\Ref;
/**
* ServicesReportController implements the CRUD actions for ServicesRoomReport model.
*/
class ServicesReportController extends Controller {
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'only' => ['*'],
'rules' => [
[
'allow' => false,
'actions' => ['*'],
'roles' => ['?'],
],
[
'allow' => true,
'actions' => [
'services-application',
'services-application-id',
'services-application-total',
''
],
'roles' => ['@'],
],
],
],
];
}
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public function actionServicesApplicationId() {
$model = ServiceApplication::find()->where(['service_id' => Yii::$app->getRequest()->getQueryParam('service_id')])->with(['serviceTask'])->one();
$content = '';
if(!empty($model)){
$task = $model['serviceTask'];
$name ='';
// $email ='';
$check = false;
if(!empty($model['created_by']) && ($model['created_user_type'] == 'frontend_user')){
if (($staff = \backend\modules\fruserdynav2\models\FrontendUser::findOne($model['created_by'])) !== null) {
$name = $staff['fullname'];
// $email = $staff['email'];
}
if($model['created_by'] == $model['service_coordinator'])
$check = true;
}
if(!empty($model['created_by']) && ($model['created_user_type'] == 'backend_user')){
if (($staff = \backend\modules\mimin\models\User::findOne($model['created_by'])) !== null) {
$name = $staff['fullname'];
// $email = $staff['email'];
}
}
$coordinator = $name;
if($check == false){
if (($staff = \backend\modules\fruserdynav2\models\FrontendUser::findOne($model['service_coordinator'])) !== null){
$coordinator = $staff['fullname'];
}
}
$filename = '';
if(!empty($model->service_file)){
$files = explode('/', $model->service_file);
$filename = '<a href="'. Url::home(true) . '/admin/' .$model->service_file.'" target="_blank"><i class="mdi mdi-book-edit-outline"></i> '.$files[2].'</a>';
}
$category = '';
if(($model->service_photo == 1) && ($model->service_video == 0)){
$category = 'Jurufoto';
} else if(($model->service_photo == 0) && $model->service_video == 1){
$category = 'Juruvideo';
} else {
$category = 'Jurufoto & Juruvideo';
}
$end = $model->service_date_end;
if(!empty($model->service_date_end) && !empty($model->service_time_end)) // kalau ada tarikh dan masa akhir
$end = $model->service_date_end .' ['.$model->service_time_end. ']';
if(empty($model->service_date_end) && empty($model->service_time_end)) // kalau xda masa akhir
$end = ' - ';
$content = '<table width="100%">
<tr>
<td style="width:15%;"><img src="https://ebookingdbkl.blunetdev.com/assets/img/dbkl-logo.png" style="height:80px;"></td>
<td stle="text-align: right;">
<h4> Maklumat Permohonan Jurufoto & Juruvideo bagi '.$model['service_programme'].'</h4>
<p>Tarikh Dijana: '.date('d-m-Y').'</p>
</td>
</tr>
</table>';
$content .= '
<div class="row" style="margin-top:20px;margin-bottom:20px;">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2" style="text-align:center;">Maklumat Permohonan</th>
</tr>
</thead>
<tbody>
<tr>
<th style="width: 40%">Nama Pemohon</th>
<td>'.$name.'</td>
</tr>
<tr>
<th style="width: 40%">Tarikh Permohonan</th>
<td>'.$model['created_at'].'</td>
</tr>
<tr>
<th style="width: 40%">Kategori</th>
<td>'.$category.'</td>
</tr>
<tr>
<th style="width: 40%">Nama Program</th>
<td>'.$model['service_programme'].'</td>
</tr>
<tr>
<th style="width: 40%">Lokasi Program</th>
<td>'.$model['service_location'].'</td>
</tr>
<tr>
<th style="width: 40%">Tarikh & Masa Mula</th>
<td>'.$model['service_date_start'].' ['.$model['service_time_start'].']</td>
</tr>
<tr>
<th style="width: 40%">Tarikh & Masa Akhir</th>
<td>'.$end.'</td>
</tr>
<tr>
<th style="width: 40%">VVIP</th>
<td>'.Ref::getDesc('SERVICEVVIP', $model['service_vvip'], 'descr').'</td>
</tr>
<tr>
<th style="width: 40%">Lampiran File</th>
<td>'.$filename.'</td>
</tr>
<tr>
<th style="width: 40%">Jabatan</th>
<td>'.Ref::getDesc('SERVICESDEPARTMENT', $model['service_department'], 'descr').'</td>
</tr>
<tr>
<th style="width: 40%">Nama Penyelaras</th>
<td>'.$coordinator.'</td>
</tr>
<tr>
<th style="width: 40%">No Telefon Penyelaras</th>
<td>'.$model['service_phone'].'</td>
</tr>
<tr>
<th style="width: 40%">Alamat Pejabat</th>
<td>'.$model['service_office_address'].'</td>
</tr>
<tr>
<th style="width: 40%">No Telefon Pejabat</th>
<td>'.$model['service_office_phone'].'</td>
</tr>
<tr>
<th style="width: 40%">No Faks Pejabat</th>
<td>'.$model['service_office_fax'].'</td>
</tr>
<tr>
<th style="width: 40%">Status</th>
<td>'.Ref::getDesc('SERVICESTATUS', $model['service_status'], 'descr').'</td>
</tr>
<tr>
<th style="width: 40%">Catatan</th>
<td>'.$model['service_remarks'].'</td>
</tr>
</tbody>
</table>
</div>';
}
$pdf = new Pdf([
'mode' => Pdf::MODE_BLANK,
'filename' => 'Maklumat Permohonan Jurufoto & Juruvideo.pdf',
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_DOWNLOAD,
'content' => $content,
]);
return $pdf->render();
}
public function actionServicesApplication() {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// $query = '';
$sheet->setCellValue('A1', 'Nama Program');
$sheet->setCellValue('B1', 'Lokasi Program');
$sheet->setCellValue('C1', 'VVIP');
$sheet->setCellValue('D1', 'Tarikh Mula');
$sheet->setCellValue('E1', 'Masa Mula');
$sheet->setCellValue('F1', 'Tarikh Akhir');
$sheet->setCellValue('G1', 'Masa Akhir');
$sheet->setCellValue('H1', 'Nama Penyelaras');
$sheet->setCellValue('I1', 'No Telefon Penyelaras');
$sheet->setCellValue('J1', 'Jabatan');
$sheet->setCellValue('K1', 'Status');
$sheet->setCellValue('L1', 'Jurufoto & Juruvideo');
$sheet->setCellValue('M1', 'Catatan');
$sheet->setCellValue('N1', 'Nama Pemohon');
$sheet->setCellValue('O1', 'Tarikh Permohonan');
$query = ServiceApplication::find();
$query->andFilterWhere(['MONTH(service_date_start)' => Yii::$app->getRequest()->getQueryParam('month')]);
$query->andFilterWhere(['YEAR(service_date_start)' => Yii::$app->getRequest()->getQueryParam('year')]);
$query->andFilterWhere(['service_department' => Yii::$app->getRequest()->getQueryParam('department')]);
$query->andFilterWhere(['service_status' => Yii::$app->getRequest()->getQueryParam('status')]);
if(!empty(Yii::$app->getRequest()->getQueryParam('category'))){
if(Yii::$app->getRequest()->getQueryParam('category') == 'photo'){
$query->andFilterWhere(['service_photo' => 1, 'service_video' => 0]);
} else if(Yii::$app->getRequest()->getQueryParam('category') == 'video'){
$query->andFilterWhere(['service_photo' => 0, 'service_video' => 1]);
} else {
$query->andFilterWhere(['service_photo' => 1, 'service_video' => 1]);
}
}
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => false],]);
$dataProvider->setSort(['defaultOrder' => ['service_date_start' => SORT_DESC]]);
$count1 = 1;
foreach ($dataProvider->models as $row) {
$name ='';
// $email ='';
$check = false;
if(!empty($row['created_by']) && ($row['created_user_type'] == 'frontend_user')){
if (($staff = \backend\modules\fruserdynav2\models\FrontendUser::findOne($row['created_by'])) !== null) {
$name = $staff['fullname'];
// $email = $staff['email'];
}
if($row['created_by'] == $row['service_coordinator'])
$check = true;
}
if(!empty($row['created_by']) && ($row['created_user_type'] == 'backend_user')){
if (($staff = \backend\modules\mimin\models\User::findOne($row['created_by'])) !== null) {
$name = $staff['fullname'];
// $email = $staff['email'];
}
}
$coordinator = $name;
if($check == false){
if (($staff = \backend\modules\fruserdynav2\models\FrontendUser::findOne($row['service_coordinator'])) !== null){
$coordinator = $staff['fullname'];
}
}
$staff = '';
if (($lists = ServiceTask::find()->where(['service_id' => $row['service_id']])->all()) !== null){
foreach ($lists as $list){
if(!empty(ServicePic::getName ($list->pic_id)))
$staff .= ServicePic::getName ($list->pic_id);
}
}
$count1++;
$sheet->setCellValue('A' . $count1, $row['service_programme']);
$sheet->setCellValue('B' . $count1, $row['service_location']);
$sheet->setCellValue('C' . $count1, $row['service_vvip']);
$sheet->setCellValue('D' . $count1, $row['service_date_start']);
$sheet->setCellValue('E' . $count1, $row['service_time_start']);
$sheet->setCellValue('F' . $count1, $row['service_date_end']);
$sheet->setCellValue('G' . $count1, $row['service_time_end']);
$sheet->setCellValue('H' . $count1, $coordinator);
$sheet->setCellValue('I' . $count1, $row['service_phone']);
$sheet->setCellValue('J' . $count1, Ref::getDesc('SERVICESDEPARTMENT', $row['service_department'], 'descr'));
$sheet->setCellValue('K' . $count1, Ref::getDesc('APPLICATIONSTATUS', $row['service_status'], 'descr'));
$sheet->setCellValue('L' . $count1, $row['service_remarks']);
$sheet->setCellValue('M' . $count1, $staff);
$sheet->setCellValue('N' . $count1, $name);
$sheet->setCellValue('O' . $count1, $row['created_at']);
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Laporan Permohonan Jurufoto & Juruvideo.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
exit();
}
public function actionServicesApplicationTotal() {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$type = Yii::$app->getRequest()->getQueryParam('type');
$year = empty(Yii::$app->getRequest()->getQueryParam('year')) ? date('Y') : Yii::$app->getRequest()->getQueryParam('year');
switch($type){
case 'pic':
$model = ServicePic::find()->all();
$nColumn = 'Pegawai Bertugas';
break;
case 'category':
$model = ['Jurufoto', 'JuruVideo', 'Jurufoto & Juruvideo'];;
$nColumn = 'Keperluan Jurufoto & Juruvideo';
break;
case 'department':
$model = Ref::find()->where(['=', 'cat', 'SERVICESDEPARTMENT'])->orderBy(['sort' => SORT_ASC])->all();
$nColumn = 'Jabatan';
break;
case 'status':
$model = Ref::find()->where(['=', 'cat', 'SERVICESTATUS'])->orderBy(['sort' => SORT_ASC])->all();
$nColumn = 'Status';
break;
default:
$model = [];
break;
}
$sheet->setCellValue('A1', 'Bil');
$sheet->setCellValue('B1', $nColumn);
$sheet->setCellValue('C1', 'Januari');
$sheet->setCellValue('D1', 'Februari');
$sheet->setCellValue('E1', 'Mac');
$sheet->setCellValue('F1', 'April');
$sheet->setCellValue('G1', 'Mei');
$sheet->setCellValue('H1', 'Jun');
$sheet->setCellValue('I1', 'Julai');
$sheet->setCellValue('J1', 'Ogos');
$sheet->setCellValue('K1', 'September');
$sheet->setCellValue('L1', 'Oktober');
$sheet->setCellValue('M1', 'November');
$sheet->setCellValue('N1', 'Disember');
$sheet->setCellValue('O1', 'Jumlah');
$count1 = 1;
$index = 1;
if(!empty($model)){
foreach($model as $row){
$count1++;
$sheet->setCellValue('A' . $count1, $index);
switch($type){
case 'department':
$name = $row['descr'];
$Id = 'service_department';
$valueId = $row['code'];
break;
case 'status':
$name = $row['descr'];
$Id = 'service_status';
$valueId = $row['code'];
break;
default:
break;
}
if($type == 'category'){
for ($i = 1; $i <=3; $i++){
switch($row){
case '1';
$category = 'Jurufoto';
$condition = ['service_photo' => 1, 'service_video' => 0];
break;
case '2':
$category = 'JuruVideo';
$condition = ['service_photo' => 0, 'service_video' => 1];
break;
default:
$category = 'Jurufoto & JuruVideo';
$condition = ['service_photo' => 1, 'service_video' => 1];
break;
}
$sheet->setCellValue('B' . $count1, $category);
$sheet->setCellValue('C' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 1, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('D' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 2, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('E' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 3, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('F' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 4, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('G' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 5, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('H' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 6, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('I' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 7, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('J' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 8, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('K' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 9, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('L' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 10, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('M' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 11, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('N' . $count1, ServiceApplication::find()->where(['MONTH(service_date_start)' => 12, 'YEAR(service_date_start)' => $year])->andWhere($condition)->count());
$sheet->setCellValue('O' . $count1, ServiceApplication::find()->where(['YEAR(service_date_start)' => $year])->andWhere($condition)->count());
}
} else if($type == 'pic'){
$staff = FrontendUser::findOne($row['staff_id']);
$sheet->setCellValue('B' . $count1, $staff['fullname']);
$sheet->setCellValue('C' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 1, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('D' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 2, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('E' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 3, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('F' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 4, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('G' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 5, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('H' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 6, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('I' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 7, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('J' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 8, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('K' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 9, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('L' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 10, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('M' . $cunto1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 11, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('N' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'MONTH(t2.service_date_start)' => 12, 'YEAR(t2.service_date_start)' => $year])->count());
$sheet->setCellValue('O' . $count1, ServiceTask::find()->leftJoin('service_application t2', 't2.service_id=service_task.service_id')->where(['service_task.pic_id' => $row['pic_id'], 'YEAR(t2.service_date_start)' => $year])->count());
} else {
$sheet->setCellValue('B' . $count1, $name);
$sheet->setCellValue('C' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 1, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('D' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 2, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('E' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 3, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('F' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 4, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('G' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 5, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('H' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 6, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('I' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 7, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('J' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 8, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('K' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 9, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('L' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 10, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('M' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 11, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('N' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'MONTH(service_date_start)' => 12, 'YEAR(service_date_start)' => $year])->count());
$sheet->setCellValue('O' . $count1, ServiceApplication::find()->where([$Id => $valueId, 'YEAR(service_date_start)' => $year])->count());
}
$index++;
}
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Laporan Jumlah Permohonan Jurufoto & Juruvideo Berdasarkan '.$nColumn.' Bagi Tahun '.$year.'.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
exit();
}
}