'action' => $action,
]);
}
+
+ public function actionMergeShifts() {
+ $action = \Yii::$app->request->post('action');
+
+ if ($action == 'applyPlus') {
+ $plans = Timetable::find()
+ ->andWhere(['>=', 'date', '2024-07-01'])
+ ->andWhere(['<=', 'date', '2024-07-05'])
+ ->all();
+
+ foreach ($plans as $plan) {
+ $facts = TimetableFactModel::find()
+ ->andWhere(['date_shift' => $plan->date])
+ ->andWhere(['admin_id' => $plan->admin_id])
+ ->andWhere(['store_id' => $plan->store_id])
+ ->all();
+
+ if (sizeof($facts) > 1) {
+ $start = $facts[0];
+ $end = $facts[1];
+
+ if ($start->id > $end->id) {
+ $temp = $start;
+ $start = $end;
+ $end = $temp;
+ }
+
+ $start->setAttribute('date_end', $end->date_start);
+ $start->setAttribute('time_end', $end->time_start);
+ $start->setAttribute('checkin_end_id', $end->checkin_start_id);
+ $start->setAttribute('autoclosed', 0);
+ $start->save();
+ $end->delete();
+ }
+ }
+ }
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => TimetableFactModel::find()
+ ->andWhere(['>=', 'date_shift', '2024-07-01'])
+ ->andWhere(['<=', 'date_shift', '2024-07-05'])
+ ->andWhere(['autoclosed' => 1])
+ ->orderBy('date_shift, admin_id,id, store_id'),
+ 'pagination' => [
+ 'pageSize' => false
+ ]
+ ]);
+
+
+ return $this->render('merge-shifts', [
+ 'dataProvider' => $dataProvider,
+ 'action' => $action
+ ]);
+ }
}
--- /dev/null
+<?php
+
+use yii\grid\GridView;
+use \yii\helpers\Html;
+use \yii\widgets\ActiveForm;
+
+/** @var $action string */
+/** @var $dataProvider */
+
+?>
+
+<?php $columns = array(
+ ['class' => 'yii\grid\SerialColumn'],
+ 'date_shift:datetime',
+ [
+ 'attribute' => 'admin_id',
+ 'value' => function ($data) {
+ return $data->admin->name;
+ }
+ ],
+ [
+ 'attribute' => 'store_id',
+ 'value' => function ($data) {
+ return $data->store->name;
+ }
+ ],
+ 'date_start:date',
+ 'time_start:time',
+ 'date_end:date',
+ 'time_end:time',
+)
+?>
+
+
+<div class="bonusAdd m-5">
+ <?php ActiveForm::begin() ?>
+
+ <?= Html::submitButton('Объединить', ['class' => 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?>
+
+ <?php ActiveForm::end() ?>
+ <pre>
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => $columns,
+ ]);; ?>
+ </pre>
+</div>