/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Timetable::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'start' => $this->start, 'end' => $this->end, 'week_day' => $this->week_day, 'group_id' => $this->group_id]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PaidEmployment::find()->joinWith(['pay.profile', 'pay', 'timetable', 'timetable.group']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]);
     $dataProvider->sort->attributes['pay.profile.fullName'] = ['asc' => [Profile::tableName() . '.name' => SORT_ASC, Profile::tableName() . '.surname' => SORT_ASC], 'desc' => [Profile::tableName() . '.name' => SORT_DESC, Profile::tableName() . '.surname' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.group.name'] = ['asc' => [Group::tableName() . '.name' => SORT_ASC], 'desc' => [Group::tableName() . '.name' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.start'] = ['asc' => [Timetable::tableName() . '.start' => SORT_ASC], 'desc' => [Timetable::tableName() . '.start' => SORT_DESC]];
     $dataProvider->sort->attributes['timetable.end'] = ['asc' => [Timetable::tableName() . '.end' => SORT_ASC], 'desc' => [Timetable::tableName() . '.end' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date' => $this->date, 'pay_id' => $this->pay_id, 'pay.user_id' => $this->userFullName, 'timetable.group_id' => $this->timetableGroupId]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTimetable()
 {
     return $this->hasOne(Timetable::className(), ['id' => 'timetable_id']);
 }
Esempio n. 4
0
 private function addPaidEmployment()
 {
     if (!$this->ticket_id) {
         return true;
     }
     $this->_ticketModel = SeasonTicket::findOne(['id' => $this->ticket_id]);
     if (!$this->_ticketModel) {
         return true;
     }
     $this->_currentDate = Carbon::createFromFormat('d.m.Y', $this->startdate);
     $this->_endDate = self::getEmploymentEndDate($this->_currentDate, $this->_ticketModel->limit_format, $this->_ticketModel->limit_value);
     $timeTableGroups = Timetable::find()->asArray()->where(['group_id' => $this->groups])->all();
     $cond = 'date >= :startdate AND pay.user_id = :user_id';
     $params = [':user_id' => $this->user_id, ':startdate' => $this->_currentDate->toDateString()];
     $existEmployments = PaidEmployment::find()->select(['date', 'timetable_id', 'group_id' => 'timetable.group_id'])->asArray()->joinWith(['pay', 'timetable'])->where($cond, $params)->andWhere(['timetable.group_id' => $this->groups])->all();
     $existLastEmployment = PaidEmployment::find()->select(['date', 'timetable_id', 'group_id' => 'timetable.group_id'])->asArray()->joinWith(['pay', 'timetable'])->where($cond, $params)->andWhere(['timetable.group_id' => $this->groups])->orderBy('date DESC')->one();
     $this->addInsertArrayTimeLimit($timeTableGroups, $existEmployments, $this->_currentDate, $this->_endDate);
     if ($existLastEmployment) {
         $lastEmploymentDate = Carbon::createFromFormat('Y-m-d', $existLastEmployment['date'])->addDay();
         $this->_endDate = self::getEmploymentEndDate($lastEmploymentDate, $this->_ticketModel->limit_format, $this->_ticketModel->limit_value);
     }
     if ($this->_ticketModel->amount > 0) {
         $this->addInsertArrayAmountLimit($timeTableGroups, $existEmployments, $this->_currentDate, $this->_endDate);
     }
     if (!empty($this->_insertArray)) {
         $command = Yii::$app->db->createCommand()->batchInsert('{{%paid_employment}}', ['date', 'pay_id', 'timetable_id'], $this->_insertArray);
         return is_int($command->execute());
     } else {
         return true;
     }
 }
 public function actionTimetableList()
 {
     $parents = Yii::$app->request->post('depdrop_parents');
     if ($parents !== null) {
         $out = [];
         $date = Carbon::createFromFormat('Y-m-d', $parents[0]);
         $condition = 'week_day = :week_day';
         $params = [':week_day' => $date->dayOfWeek];
         $groups = Timetable::find()->with('group')->where($condition, $params)->orderBy('start, end')->all();
         foreach ($groups as $row) {
             $out[] = ['id' => $row->id, 'name' => $row->group->name . ' ' . $row->start . ' - ' . $row->end];
         }
         echo Json::encode(['output' => $out, 'selected' => '']);
     }
     return;
 }
Esempio n. 6
0
                <?php 
echo Html::a('<i class="fa fa-eye"></i>', ['view'], ['class' => 'btn btn-default btn-sm', 'title' => Module::t('timetable-admin', 'View')]);
?>
                <?php 
echo Html::a('<i class="fa fa-leanpub"></i>', ['publish'], ['class' => 'btn btn-warning btn-sm', 'title' => Module::t('timetable-admin', 'Publish')]);
?>
                <?php 
echo Html::a('<i class="fa fa-plus"></i>', ['create'], ['class' => 'btn btn-primary btn-sm', 'title' => Module::t('timetable-admin', 'Create')]);
?>
                <?php 
echo Html::a('<i class="fa fa-ban"></i>', ['cancel-lessons'], ['class' => 'btn btn-danger btn-sm', 'title' => Module::t('timetable-admin', 'Cancel lessons')]);
?>
                <?php 
echo Html::a('<i class="fa fa-trash"></i>', ['batch-delete'], ['class' => 'btn btn-danger btn-sm', 'id' => 'batch-delete', 'title' => Module::t('timetable-admin', 'Delete selected')]);
?>
            </div>
        </div>
        <div class="box-body">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'id' => $gridId, 'filterModel' => $searchModel, 'export' => false, 'columns' => [['class' => CheckboxColumn::classname()], ['attribute' => 'week_day', 'pageSummary' => true, 'class' => 'kartik\\grid\\EditableColumn', 'editableOptions' => ['inputType' => 'dropDownList', 'type' => 'post', 'formOptions' => ['action' => Url::toRoute('edit'), 'id' => 'timetable-form'], 'data' => Timetable::getWeekArray()], 'value' => function ($model) {
    return $model->weekArray[$model->week_day];
}, 'filter' => Html::activeDropDownList($searchModel, 'week_day', Timetable::getWeekArray(), ['class' => 'form-control', 'prompt' => ''])], ['attribute' => 'start', 'filter' => false, 'class' => 'kartik\\grid\\EditableColumn', 'editableOptions' => ['inputType' => 'textInput', 'type' => 'post', 'formOptions' => ['action' => Url::toRoute('edit'), 'id' => 'timetable-form']]], ['attribute' => 'end', 'filter' => false, 'class' => 'kartik\\grid\\EditableColumn', 'editableOptions' => ['inputType' => 'textInput', 'type' => 'post', 'formOptions' => ['action' => Url::toRoute('edit'), 'id' => 'timetable-form']]], ['attribute' => 'group_id', 'class' => 'kartik\\grid\\EditableColumn', 'format' => 'html', 'editableOptions' => ['inputType' => 'dropDownList', 'data' => Group::getGroupArray(), 'type' => 'post', 'formOptions' => ['action' => Url::toRoute('edit'), 'id' => 'timetable-form']], 'value' => function ($model) {
    return Group::getGroupArray()[$model->group_id];
}, 'filter' => Html::activeDropDownList($searchModel, 'group_id', Group::getGroupArray(), ['class' => 'form-control', 'prompt' => ''])], ['class' => 'yii\\grid\\ActionColumn', 'buttons' => ['clone' => function ($url) {
    return Html::a('<i class="fa fa-files-o"></i>', $url, ['title' => Module::t('timetable-admin', 'Clone row'), 'class' => 'btn btn-default btn-xs']);
}], 'template' => '{clone} {update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default btn-xs'], 'headerOptions' => ['style' => 'width:100px;'], 'header' => Module::t('timetable-admin', 'Actions')]]]);
?>
        </div>
    </div>
</div>
 public function rules()
 {
     return [[['id', 'date'], 'required'], ['id', 'integer', 'min' => 1], ['id', 'exist', 'targetAttribute' => 'id', 'targetClass' => Timetable::className()], ['date', 'match', 'pattern' => '/^(20)\\d\\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/']];
 }
 /**
  * Cancel lessons on a date
  * @return string|void
  * @throws \yii\db\Exception
  */
 public function actionCancelLessons()
 {
     $model = new TimetableCancel();
     $parents = Yii::$app->request->post('depdrop_parents');
     if (is_array(Yii::$app->request->post('TimetableCancel')['ids']) && $model->load(Yii::$app->request->post()) && $model->validate()) {
         $date = Carbon::createFromFormat('d.m.Y', $model->date);
         $updatedCount = 0;
         $needUpdate = PaidEmployment::find()->asArray()->joinWith(['timetable', 'pay'])->where(['date' => "{$date->toDateString()}", 'timetable_id' => $model->ids])->all();
         foreach ($needUpdate as $needRow) {
             $maxPaidDateOnGroupForUser = PaidEmployment::find()->asArray()->select('MAX(date) as max_date')->joinWith(['timetable', 'pay'])->where(['pay.user_id' => $needRow['pay']['user_id'], 'timetable_id' => $needRow['timetable_id']])->one();
             if (!$maxPaidDateOnGroupForUser) {
                 continue;
             }
             $carbonMaxDate = Carbon::createFromFormat('Y-m-d', $maxPaidDateOnGroupForUser['max_date']);
             //Все элементы расписания для группы
             $allTimetableOnGroup = Timetable::find()->asArray()->where(['group_id' => $needRow['timetable']['group_id']])->all();
             $allTimetableWeekDaysOnGroup = ArrayHelper::getColumn($allTimetableOnGroup, function ($array) {
                 return ArrayHelper::getValue($array, 'week_day');
             });
             $i = 0;
             while (7 >= $i) {
                 ++$i;
                 $currDate = clone $carbonMaxDate;
                 $carbonMaxDate->addDay();
                 if (!in_array($currDate->dayOfWeek, $allTimetableWeekDaysOnGroup)) {
                     continue;
                 }
                 $notPaidTimetables = Timetable::find()->asArray()->where(['week_day' => $currDate->dayOfWeek, 'group_id' => $needRow['timetable']['group_id']])->andWhere('NOT EXISTS ' . '( ' . 'SELECT * FROM paid_employment pe ' . 'LEFT JOIN pay p ON p.id = pe.pay_id ' . 'WHERE p.user_id = ' . $needRow['pay']['user_id'] . ' ' . 'AND `pe`.`date` = "' . $currDate->toDateString() . '" ' . 'AND timetable_id = timetable.id' . ')')->orderBy('start, end')->all();
                 if ($notPaidTimetables) {
                     $command = Yii::$app->db->createCommand('UPDATE paid_employment SET `date` = "' . $currDate->toDateString() . '", ' . 'timetable_id = ' . $notPaidTimetables[0]['id'] . ' ' . 'WHERE id = ' . $needRow['id']);
                     if (is_int($command->execute())) {
                         ++$updatedCount;
                         break;
                     }
                 } else {
                 }
             }
         }
         if (0 < $updatedCount) {
             Yii::$app->session->setFlash('success', Module::t('timetable-admin', 'Moved training schedule clients: {sum}', ['sum' => $updatedCount]));
         } else {
             Yii::$app->session->setFlash('danger', Module::t('timetable-admin', Module::t('timetable-admin', 'No records found in the timetable of customers at that date.')));
         }
         return $this->render('cancellessons', ['model' => $model]);
     } elseif ($parents !== null) {
         $out = [];
         $date = Carbon::createFromFormat('d.m.Y', $parents[0]);
         $condition = 'week_day = :week_day';
         $params = [':week_day' => $date->dayOfWeek];
         $groups = Timetable::find()->with('group')->where($condition, $params)->orderBy('start, end')->all();
         foreach ($groups as $row) {
             $out[] = ['id' => $row->id, 'name' => $row->group->name . ' ' . $row->start . ' - ' . $row->end];
         }
         echo Json::encode(['output' => $out, 'selected' => '']);
         return;
     } else {
         return $this->render('cancellessons', ['model' => $model]);
     }
 }