]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
скрипт для объединения задублированных смен
authormarina <m.zozirova@gmail.com>
Fri, 5 Jul 2024 06:16:58 +0000 (09:16 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 5 Jul 2024 06:16:58 +0000 (09:16 +0300)
erp24/controllers/TimetableFactController.php
erp24/views/timetable-fact/merge-shifts.php [new file with mode: 0644]

index 62735d0e349d919ee1793cd010e59fe123f05372..bbde391fc1214df2c39e4dad351cb1bbe16a3622 100644 (file)
@@ -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 (file)
index 0000000..3d74e41
--- /dev/null
@@ -0,0 +1,47 @@
+<?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>