]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-70] Автоматическое закрытие смен через 14 часов после их открытия
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Jun 2024 14:37:40 +0000 (17:37 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 28 Jun 2024 14:37:40 +0000 (17:37 +0300)
erp24/commands/TimetableController.php [new file with mode: 0644]
erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php [new file with mode: 0755]
erp24/records/TimetableFactModel.php

diff --git a/erp24/commands/TimetableController.php b/erp24/commands/TimetableController.php
new file mode 100644 (file)
index 0000000..5653f94
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+namespace yii_app\commands;
+
+use app\records\TimetableFactModel;
+use yii\console\Controller;
+use yii\helpers\Json;
+use yii_app\records\AdminCheckin;
+
+class TimetableController extends Controller
+{
+    public function actionAutocloseShifts() {
+        $timetableFactModels = TimetableFactModel::find()->with(['checkinStart'])->where(['status' => AdminCheckin::TYPE_START])
+            ->andWhere(['<=', 'date_start', date('Y-m-d H:i:s', strtotime('-14 hours', time()))])->all();
+
+        foreach ($timetableFactModels as $timetableFactModel) {
+            /** @var $timetableFactModel TimetableFactModel */
+            $checkIn = new AdminCheckin;
+            $checkIn->admin_id = $timetableFactModel->admin_id;
+            $checkIn->plan_id = $timetableFactModel->checkinStart->plan_id ?? 0;
+            $checkIn->store_id = $timetableFactModel->store_id;
+            $checkIn->ball = 5;
+            $checkIn->comment = "Закрыта автоматически";
+            $checkIn->d_id = $timetableFactModel->d_id;
+            $checkIn->date = date('Y-m-d');
+            $checkIn->time = date('Y-m-d H:i:s');
+            $checkIn->lat = 0;
+            $checkIn->lon = 0;
+            $checkIn->photo = 'images/avatar-empty.png';
+            $checkIn->device_id = 0;
+            $checkIn->type_id = AdminCheckin::TYPE_END;
+            $checkIn->status = 0;
+            $checkIn->save();
+            if ($checkIn->getErrors()) {
+                throw new \Exception(Json::encode($checkIn->getErrors()));
+            }
+            $timetableFactModel->checkin_end_id = $checkIn->id;
+
+            $timetableFactModel->date_end = date('Y-m-d', strtotime($checkIn->time));
+            $timetableFactModel->is_opening = false;
+            $timetableFactModel->is_close = true;
+            $timetableFactModel->time_end = date("H:i:s", strtotime($checkIn->time));
+            $timetableFactModel->work_time = 12;
+            $timetableFactModel->autoclosed = 1;
+            $timetableFactModel->comment = 'Закрыта автоматически';
+
+            $timetableFactModel->save();
+            if ($timetableFactModel->getErrors()) {
+                throw new \Exception(Json::encode($timetableFactModel->getErrors()));
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php b/erp24/migrations/m240628_141321_alter_table_timetable_fact_add_column_autoclosed.php
new file mode 100755 (executable)
index 0000000..090f9ff
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240628_141321_alter_table_timetable_fact_add_column_autoclosed
+ */
+class m240628_141321_alter_table_timetable_fact_add_column_autoclosed extends Migration
+{
+    const TABLE_NAME = 'timetable_fact';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->addColumn(self::TABLE_NAME, 'autoclosed', $this->tinyInteger()->defaultValue(0)
+            ->notNull()->after('is_close')->comment('0 - ничего особенного, 1 - автоматически закрыта'));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropColumn(self::TABLE_NAME, 'autoclosed');
+    }
+}
index f36cb792eb65b2869bff42107bb065b6aedbd1cb..709fed2d608e769a22b438603fd58934656190c7 100644 (file)
@@ -27,6 +27,7 @@ use yii_app\records\Shift;
  * @property $date_end дата время закрытия смены
  * @property bool $is_opening на открытие смены
  * @property bool $is_close на закрытие смены
+ * @property bool $autoclosed 0 - ничего особенного, 1 - автоматически закрыта
  * @property int $tabel табель
  * @property int $plan_id ID табеля если смена поставлена
  * @property int $shift_id тип смены
@@ -66,6 +67,7 @@ class TimetableFactModel extends ActiveRecord
             'date_end' => 'дата закрытия смены',
             'is_opening' => 'смена открыта?',
             'is_close' => 'смена закрыта?',
+            'autoclosed' => 'если смена закрыта, то автоматически?',
             'tabel' => 'табель',
             'plan_id' => 'Табель, если смена поставлена',
             'shift_id' => 'тип смены',
@@ -95,7 +97,7 @@ class TimetableFactModel extends ActiveRecord
 //            [['work_time'], 'number', 'min' => 0, 'max' => 24],
             [['comment'], 'string'],
             [['comment'], 'default', 'value' => null],
-            [['slot_type_id', 'date_add', 'date_end', 'time_end', 'salary_shift', 'price_hour', 'work_time'], 'safe'],
+            [['slot_type_id', 'date_add', 'date_end', 'time_end', 'salary_shift', 'price_hour', 'work_time', 'autoclosed'], 'safe'],
             [['date_shift'], 'date', 'format' => 'yyyy-M-d'],
             [['time_start', 'shift_id'], 'required'],
         ];