Your IP : 216.73.216.124


Current Path : /var/www/html/chatbot/backend/models/
Upload File :
Current File : /var/www/html/chatbot/backend/models/StaffSearch.php

<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;

/**
 * StaffSearch represents the model behind the search form about `app\models\Staff`.
 */
class StaffSearch extends Staff
{
    /**
     * @inheritdoc
     */
    
    public function rules()
    {
        return [
            [['id', 'supervisor_id', 'sal_move_month', 'hod_id', 'sms_limit', 'ifas_transferred', 'reset_password'], 'integer'],
            [['job_title','projectnm','company_name','staff_no', 'staff_name', 'staff_ic', 'staff_army_no', 'title_code', 'gender', 'religion_code', 'marital_status', 'staff_dob', 'birth_state', 'nationality', 'race_code', 'date_joined', 'army_joined_date', 'appointment_code', 'staff_grade', 'addr1', 'addr2', 'addr3', 'post_code', 'district', 'city_code', 'state_code', 'country_code', 'phone_no', 'mobile_no', 'office_no', 'office_ext_no', 'company_email', 'personal_email', 'emer_name', 'emer_rel', 'emer_phone_no', 'emer_mobile_no', 'staff_photo', 'user_id', 'user_status', 'user_password', 'kwsp_no', 'kwsp_start_date', 'socso_no', 'socso_start_date', 'income_tax', 'taxcat', 'staff_ic_old', 'spouse_name', 'spouse_ic', 'spouse_ic_old', 'spouse_income_tax', 'retire_date', 'retire_age', 'retire_file_no', 'option_ind', 'gov_joined_date', 'is_retire_opt', 'pension_opt_given_date', 'privatization_ind', 'retire_section', 'perkeso_opt', 'personnel_file_no', 'hse_loan_no', 'theme', 'isstaff', 'peme_status', 'peme_report', 'passhint', 'created_by', 'created_at', 'updated_by', 'updated_at'], 'safe'],
            [['basic_salary'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function searchexcel($params) //fa add 20160928
    {
        $query = Staff::find()
                ->select('userid, staff_no, staff_name, staff_ic, c.job_title, d.company_name as projectnm')
                ->from('hr_staff_info a')
                ->innerJoin('hr_employment_info b', 'b.staff_info_id = a.id')
                ->innerJoin('hr_job_ref c', ' c.id=b.job_id')
                ->leftJoin('hr_company_info d', ' d.id=c.projectid')
                ->where('b.enggagement_active=1');
        
        $dataProviderexcel = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => 200,],
        ]);
        
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProviderexcel;
        }
        
        $query->andFilterWhere(['like', 'a.staff_no', $this->staff_no]);
        $query->andFilterWhere(['like', 'a.staff_name', $this->staff_name]);
        $query->andFilterWhere(['like', 'a.staff_ic', $this->staff_ic]);
        $query->andFilterWhere(['like', 'd.company_name', $this->projectnm]);
        
        return $dataProviderexcel;
    }
    
    public function search($params)
    {
        $query = Staff::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [ 'pageSize' => 200 ],
        ]);
        
        $dataProvider->setSort([
        'attributes' => [
            'staff_no',
            'staff_name',
            'staff_ic',
            'job_title' => [
                'asc' => ['hr_job_ref.job_title' => SORT_ASC],
                'desc' => ['hr_job_ref.job_title' => SORT_DESC],
                'label' => 'Position',
                //'default' => SORT_ASC
            ],
            'projectnm' => [
                'asc' => ['hr_company_info.company_name' => SORT_ASC],
                'desc' => ['hr_company_info.company_name' => SORT_DESC],
                'label' => 'Location',
                //'default' => SORT_ASC
            ],
            'supervisor_id',
            'hod_id',
        ]
    ]);
        
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            $query->joinWith(['job']);
            return $dataProvider;
        }
        $query->joinWith(['job','projectlocation']);
        //$query->joinWith(['projectlocation']);
        
        $query->andFilterWhere([
            'supervisor_id' => $this->supervisor_id,
            'hod_id' => $this->hod_id,
        ]);
        
        $query->andFilterWhere(['like', 'staff_no', $this->staff_no])
            ->andFilterWhere(['like', 'staff_name', $this->staff_name])
            ->andFilterWhere(['like', 'staff_ic', $this->staff_ic]);
        
        if (trim($this->company_name) !==''){
            $query->joinWith(['currcompany' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->company_name. '%"');
            }]);
        }
        
        if (trim($this->projectnm) !==''){
            $query->joinWith(['projectlocation' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->projectnm . '%"');
            }]);
        }
        
        
        return $dataProvider;
    }
    
    public function searchDob($params)
    {
        $query = Staff::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [ 'pageSize' => 200 ],
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'supervisor_id' => $this->supervisor_id,
            'hod_id' => $this->hod_id,
        ]);
        
        $query->andFilterWhere(['like', 'staff_no', $this->staff_no])
            ->andFilterWhere(['like', 'staff_name', $this->staff_name])
            ->andFilterWhere(['like', 'staff_dob', $this->staff_dob])
            ->andFilterWhere(['like', 'staff_ic', $this->staff_ic]);
        
        if (trim($this->company_name) !==''){
            $query->joinWith(['currcompany' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->company_name. '%"');
            }]);
        }
        
        if (trim($this->projectnm) !==''){
            $query->joinWith(['projectlocation' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->projectnm . '%"');
            }]);
        }
        
        
        return $dataProvider;
    }
    
    public function searchhr($params)
    {
        $query = Staff::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [ 'pageSize' => 200 ],
        ]);
        
        $dataProvider->setSort([
        'attributes' => [
            'staff_no',
            'staff_name',
            'staff_ic',
            'job_title' => [
                'asc' => ['hr_job_ref.job_title' => SORT_ASC],
                'desc' => ['hr_job_ref.job_title' => SORT_DESC],
                'label' => 'Position',
                //'default' => SORT_ASC
            ],
            'projectnm' => [
                'asc' => ['hr_company_info.company_name' => SORT_ASC],
                'desc' => ['hr_company_info.company_name' => SORT_DESC],
                'label' => 'Location',
                //'default' => SORT_ASC
            ],
            'supervisor_id',
            'hod_id',
        ]
    ]);
        
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            $query->joinWith(['job']);
            return $dataProvider;
        }
        $query->joinWith(['job','projectlocation']);
        //$query->joinWith(['projectlocation']);
        
        $query->andFilterWhere([
            'supervisor_id' => $this->supervisor_id,
            'hod_id' => $this->hod_id,
        ]);
        
        $query->andFilterWhere(['like', 'staff_no', $this->staff_no])
            ->andFilterWhere(['like', 'staff_name', $this->staff_name])
            ->andFilterWhere(['like', 'staff_ic', $this->staff_ic]);
        
        if (trim($this->company_name) !==''){
            $query->joinWith(['currcompany' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->company_name. '%"');
            }]);
        }
        
        if (trim($this->projectnm) !==''){
            $query->joinWith(['projectlocation' => function ($q) {
                $q->where('hr_company_info.company_name LIKE "%' . $this->projectnm . '%"');
            }]);
        }
        
        
        return $dataProvider;
    }
}