From: marina Date: Fri, 5 Jul 2024 06:16:58 +0000 (+0300) Subject: скрипт для объединения задублированных смен X-Git-Tag: 1.3~13^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=084e14f23d41a9ee7af21a5b29963b47a14aabe8;p=erp24_rep%2Fyii-erp24%2F.git скрипт для объединения задублированных смен --- diff --git a/erp24/controllers/TimetableFactController.php b/erp24/controllers/TimetableFactController.php index 62735d0e..bbde391f 100644 --- a/erp24/controllers/TimetableFactController.php +++ b/erp24/controllers/TimetableFactController.php @@ -234,4 +234,58 @@ class TimetableFactController extends Controller '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 + ]); + } } diff --git a/erp24/views/timetable-fact/merge-shifts.php b/erp24/views/timetable-fact/merge-shifts.php new file mode 100644 index 00000000..3d74e412 --- /dev/null +++ b/erp24/views/timetable-fact/merge-shifts.php @@ -0,0 +1,47 @@ + + + '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', +) +?> + + +
+ + + 'btn btn-warning btn-lg', 'name' => 'action', 'value' => 'applyPlus']) ?> + + +
+         $dataProvider,
+            'columns' => $columns,
+        ]);; ?>
+        
+