From: marina Date: Fri, 5 Jul 2024 15:58:37 +0000 (+0300) Subject: скрипт для восстановления потерянных смен X-Git-Tag: 1.3~3^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=c001401a699cfabd255f1ddbb3cdcfb24816a642;p=erp24_rep%2Fyii-erp24%2F.git скрипт для восстановления потерянных смен --- diff --git a/erp24/controllers/TimetableFactController.php b/erp24/controllers/TimetableFactController.php index 9fe5cd85..20d4d915 100644 --- a/erp24/controllers/TimetableFactController.php +++ b/erp24/controllers/TimetableFactController.php @@ -350,4 +350,72 @@ class TimetableFactController extends Controller '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 + ]); + } } diff --git a/erp24/views/timetable-fact/add-lost-shifts.php b/erp24/views/timetable-fact/add-lost-shifts.php new file mode 100644 index 00000000..afa5d8d7 --- /dev/null +++ b/erp24/views/timetable-fact/add-lost-shifts.php @@ -0,0 +1,46 @@ + + + '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', +) +?> + + +
+ + + 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?> + + +
+         $dataProvider,
+            'columns' => $columns,
+        ]);; ?>
+        
+