Example #1
0
 public function searchByEmployee($params)
 {
     $employee_id = $params['id'];
     $wherelist1 = '';
     $wherelist2 = '';
     if (isset($params['from_date']) && !empty($params['from_date'])) {
         $from_date = $params['from_date'];
         $wherelist1 = 'job_date >= "' . $from_date . '"';
     }
     if (isset($params['to_date']) && !empty($params['to_date'])) {
         $to_date = $params['to_date'];
         $wherelist2 = 'job_date <= "' . $to_date . '"';
     }
     $query = JobSchedule::find();
     $query->joinWith(['job']);
     if ($wherelist1 != "") {
         $query->andWhere($wherelist1);
     }
     if ($wherelist2 != "") {
         $query->andWhere($wherelist2);
     }
     $query->orderBy('job_date DESC');
     // echo $query->createCommand()->getRawSql();exit;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['job_date' => ['asc' => ['job_date' => SORT_ASC], 'desc' => ['job_date' => SORT_DESC], 'default' => SORT_ASC, 'label' => 'Name']]]]);
     $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(['job_id' => $this->job_id, 'employee_id' => $this->employee_id, 'time_in' => $this->time_in, 'time_out' => $this->time_out, 'break_time' => $this->break_time]);
     return $dataProvider;
 }
Example #2
0
</h1>

    <p class="float-right">
        <?php 
echo Html::a('Create Job', ['create'], ['class' => 'btn btn-success']);
?>
    </p>
    
    <div class="clear"></div>

    <?php 
echo $this->render('_search', ['model' => $searchModel]);
?>

    <div class="clear"></div>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'company', 'value' => function ($dataProvider) {
    $company = Company::findOne($dataProvider->company_id);
    $company_name = $company->company_name;
    return $company_name;
}], 'job_order', 'job_date', ['attribute' => 'time_in', 'format' => ['time', 'php:H:i'], 'options' => ['style' => 'width:100px;']], ['attribute' => 'time_out', 'format' => ['time', 'php:H:i'], 'options' => ['style' => 'width:100px;']], ['attribute' => 'quota', 'value' => function ($dataProvider) {
    // print_r($dataProvider);exit;
    $total_assign = JobSchedule::find()->where('job_id=' . $dataProvider->job_id)->count();
    $quota_left = intval($dataProvider->quota - $total_assign);
    return $total_assign . '/' . $dataProvider->quota;
}, 'options' => ['style' => 'width:120px;']], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['style' => 'width:80px;']]]]);
?>

</div>