'action' => $action
]);
}
+
+ public function actionAddLostCheckins() {
+
+ $action = \Yii::$app->request->post('action');
+
+ if ($action == 'applyPlus') {
+ $plans = Timetable::find()
+ ->andWhere(['>=', 'date', '2024-07-01'])
+ ->andWhere(['<=', 'date', '2024-07-05'])
+// ->andWhere(['=', 'id', 111309])
+ ->all();
+
+
+ foreach ($plans as $plan) {
+ $adminCheckins = AdminCheckin::find()
+ ->andWhere(['=', 'plan_id', $plan->id])
+ ->andWhere(['is not', 'plan_id', null])
+ ->orderBy('id asc')
+ ->all();
+
+ if (sizeof($adminCheckins) > 1) {
+ $start = $adminCheckins[0];
+ $end = end($adminCheckins);
+
+
+ if ($start->id > $end->id) {
+ $temp = $start;
+ $start = $end;
+ $end = $temp;
+ }
+
+ $fact = TimetableFactModel::find()
+ ->andWhere(['date_shift' => $plan->date])
+ ->andWhere(['admin_id' => $plan->admin_id])
+ ->andWhere(['store_id' => $plan->store_id])
+ ->one();
+
+ if ($fact) {
+ $fact->setAttribute('date_start', date('Y-m-d', strtotime($start->time)));
+ $fact->setAttribute('time_start', date('H:i:s', strtotime($start->time)));
+ $fact->setAttribute('checkin_start_id', $start->id);
+ $fact->setAttribute('date_end', date('Y-m-d', strtotime($end->time)));
+ $fact->setAttribute('time_end', date('H:i:s', strtotime($end->time)));
+ $fact->setAttribute('checkin_end_id', $end->id);
+ $fact->setAttribute('status', $fact->d->id == AdminGroup::GROUP_ADMINISTRATORS ? AdminCheckin::TYPE_APPEAR : AdminCheckin::TYPE_END);
+ $fact->setAttribute('work_time', min(abs(strtotime($end->time) + 600 - strtotime($start->time)) / 3600, TimetableFactModel::WORK_HOURS_TIME));
+ $fact->save();
+ }
+ }
+ }
+ }
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => TimetableFactModel::find()
+ ->andWhere(['>=', 'date_shift', '2024-07-01'])
+ ->andWhere(['<=', 'date_shift', '2024-07-05'])
+ ->orderBy('date_shift, admin_id,id, store_id'),
+ 'pagination' => [
+ 'pageSize' => false
+ ]
+ ]);
+
+
+ return $this->render('add-lost-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'],
+ [
+ '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>