<?php 
namespace modules\forms\models;

use Yii;
use modules\activities\models\Activities;
use modules\users\models\User;
use modules\custom\models\Accounts;


class Sop023 extends \common\models\DynamicModel
{
    public $form = 'SOP023';
    public $viewLayout = '@modules/forms/views/sop023/_view.php';
    public $formLayout = '/sop023/_form.php';
    public $formType = 'Administration';
    public $createpath = '/forms/sop023/create';
    public $printlayout = 'Portrait';
    public $formname = 'SOP023 - Provision of Welfare Facilities for Operational Works:';

    public static function localAttributes()
    {
        return [
            'id' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "ID",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false ],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'actid' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Activity ID",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false ],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'jobno' => [
                'rules' => [
                    ['integer']
                ],
                'label' => Yii::t('app', "Job Number",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false, 'type' => 'number'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'location' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Location",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false ],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'employees_on_site' => [
                'rules' => [
                    ['integer']
                ],
                'label' => Yii::t('app', "Anticipated maximum number of employees on site",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false ],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'duration_of_works' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Duration of works",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false ],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'start_date' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Start Date",),
                'input' => [
                    'input' => 'widget',
                    'fieldclass' => \kartik\date\DatePicker::class,
                    'fieldlist' => null,
                    'options' => ['type' => 1, 'pluginOptions' => ['todayBtn' => true, 'format' => 'dd/mm/yyyy']],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'finish_date' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Finish Date",),
                'input' => [
                    'input' => 'widget',
                    'fieldclass' => \kartik\date\DatePicker::class,
                    'fieldlist' => null,
                    'options' => ['type' => 1, 'pluginOptions' => ['todayBtn' => true, 'format' => 'dd/mm/yyyy']],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'type_of_facilities' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Select type of facilities being provide",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Non-transient' => 'Non-transient',
                        'Transient' => 'Transient',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            
            't1_people_at_work' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of people at work",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 5',
                        1 => '6 - 25',
                        2 => '26 - 50',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_toilets' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of toilets (cubicles)",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_washbasins' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of washbasins",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],

            't2_people_at_work' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of people at work",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 15',
                        1 => '16 - 30',
                        2 => '31 - 45',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_toilets' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of toilets (cubicles)",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_urinals' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of urinals",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '1',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_washbasins' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "Number of washbasins",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_people_at_work1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1 - 5",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 5',
                        1 => '6 - 25',
                        2 => '26 - 50',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_toilets1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_washbasins1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],

            't2_people_at_work1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1 - 15",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 15',
                        1 => '16 - 30',
                        2 => '31 - 45',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_toilets1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_urinals1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '1',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_washbasins1' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "1",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_people_at_work2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "6 - 25",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 5',
                        1 => '6 - 25',
                        2 => '26 - 50',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_toilets2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_washbasins2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],

            't2_people_at_work2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "16 - 30",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 15',
                        1 => '16 - 30',
                        2 => '31 - 45',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_toilets2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_urinals2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '1',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_washbasins2' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_people_at_work3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', '26 - 50',),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 5',
                        1 => '6 - 25',
                        2 => '26 - 50',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_toilets3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "3",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't1_no_of_washbasins3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "3",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '3',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],

            't2_people_at_work3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "31 - 45",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1 - 15',
                        1 => '16 - 30',
                        2 => '31 - 45',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_toilets3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_urinals3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '1',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            't2_no_of_washbasins3' => [
                'rules' => [
                    ['safe']
                ],
                'label' => Yii::t('app', "2",),
                'input' => [
                    'input' => 'radioList',
                    'fieldclass' => null,
                    'fieldlist' => [
                        0 => '1',
                        1 => '2',
                        2 => '2',
                    ],
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'separate_facilities_disabled' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Are there separate toilet and washbasin facilities for the disabled",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'separate_facilities_disabled_no' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "If yes write in number",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => ['label' => false],
                    'width' => 'col-12',
                ],
                
                'search' => false,
            ],
            'water_supply' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "How is drinking water provided",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Mains Water' => 'Mains Water',
                        'Bottled Water' => 'Bottled Water',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'nutritional_facilities' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Facilities for making hot drinks & heating of food",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'changing_facilities' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Are separate changing facilities available for each gender",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'break_locations' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Is there an area where breaks can be taken away from the work area to eat meals",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'temperature_control' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Can temperature of facilities be controlled",),
                'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'lockers' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Are lockers and drying facilities available",),
                 'input' => [
                    'input' => 'dropdownlist',
                    'fieldclass' => null,
                    'fieldlist' => [
                        'Yes' => 'Yes',
                        'No' => 'No',
                    ],
                    'options' => ['label' => false, 'prompt' => 'Please Select'],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'explanation' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "Provide explanation if No is answered to the Yes & No questions.",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => [],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
            'comments' => [
                'rules' => [
                    ['string']
                ],
                'label' => Yii::t('app', "General comments.",),
                'input' => [
                    'input' => 'textInput',
                    'fieldclass' => null,
                    'fieldlist' => null,
                    'options' => [],
                    'width' => 'col-12',
                ],
                'search' => false,
            ],
        ];
    }

    public function Pdf($outputMode = 'I'){
        $html = Yii::$app->view->render('@modules/forms/views/sop023/_view', ['model' => $this]);
        $pdfContent = Yii::$app->pdf->fromPages($html, true);
        if ($outputMode == 'S') {
            return $pdfContent;
        } elseif ($outputMode == 'I') {
            Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
            Yii::$app->response->headers->add('Content-Type', 'application/pdf');
            return $pdfContent;
        } else {
            return Yii::$app->response->sendContentAsFile($pdfContent, 'SOP023-' . $this->id . '.pdf', [
                'mimeType' => 'application/pdf'
            ]);
        }
    }
    public function setData()
    {
        if(Yii::$app->controller->action->id == 'create' && $actid = (Yii::$app->request->get('actid', null)) !== null ){
           $act = Activities::find()->select(['jobno', 'relatedid', 'location', 'sdate','edate', 'elr', 'weekno', 'company'])->where(['id' => $actid])->asArray()->one();
           $this->jobno = $act['jobno'];
           $this->location = $act['location'];
           $this->start_date = date('d/m/Y', strtotime($act['sdate']));
           $this->finish_date = date('d/m/Y', strtotime($act['edate']));
        }
    }

    public function afterValidate(){
        parent::afterValidate();
        Yii::error($this->errors);
        return ;
    }
    public static function adminFormButtons($buttons, $model){
        $_this = new self();
        $buttons[$_this->formType]['items'][] = [
            'label' => $_this->formname,
            'url' => [$_this->createpath, 'actid' => $model->id],
            'linkOptions' =>  ['target'=>'_blank'],
        ];
        return $buttons;
    }
}