]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-165] Добавлено поле active для заявок
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 27 Aug 2024 06:42:39 +0000 (09:42 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 27 Aug 2024 06:42:39 +0000 (09:42 +0300)
erp24/api2/controllers/DataController.php
erp24/api3/core/services/ClaimService.php
erp24/api3/modules/v1/controllers/claim/WorkerController.php
erp24/api3/modules/v1/requests/claim/Worker.php
erp24/api3/modules/v1/requests/claim/WorkerControl.php
erp24/migrations/m240827_061358_alter_table_employee_on_shift_add_column_active.php [new file with mode: 0755]
erp24/records/EmployeeOnShift.php
erp24/scripts/tasks/task_22_create_employee_for_1c_with_admins_with_empty_guid.php

index 9c7d6ba073c3d6402ca7f99accaa2aa5217f5c12..cd0706bf8281ddd564a26d1d1a34ae8aab86f985 100644 (file)
@@ -302,7 +302,8 @@ class DataController extends BaseController {
         $employeeOnShiftArray = EmployeeOnShift::find()
             ->where([
                 'status' => EmployeeOnShift::STATUS_ACCEPT,
-                'status_source' => EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C
+                'status_source' => EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C,
+                'active' => EmployeeOnShift::ACTIVE_ON,
             ])
             ->all();
         $result = [];
index 150ada58251e26c4608fa7038404463f5d922c4e..adf2cd06b9206763f317fee74c7d2af897ec3be5 100644 (file)
@@ -27,6 +27,7 @@ class ClaimService extends Model
         $model = new EmployeeOnShift($row);
         $model->guid = DataHelper::createGuidMy("06");
         $model->created_at = date(DATE_ATOM);
+        $model->active = EmployeeOnShift::ACTIVE_ON;
 
         if (!$model->save()) {
             throw new InvalidArgumentException(array_values($model->firstErrors)[0] ?? "");
@@ -36,7 +37,7 @@ class ClaimService extends Model
     }
 
     public function control(WorkerControl $row) {
-        $model = EmployeeOnShift::findOne(['guid' => $row->guid]);
+        $model = EmployeeOnShift::findOne(['guid' => $row->guid, 'active' => EmployeeOnShift::ACTIVE_ON]);
 
         if (!$model) {
             throw new InvalidArgumentException('guid не найден');
index 057496cdf60f5cc3dfb63d90e295557e81625a21..ef814c7acb52d8a783483b5467aa20f96039f768 100644 (file)
@@ -47,7 +47,7 @@ class WorkerController extends \yii_app\api3\controllers\ActiveController
     public function actionCreate()
     {
         // Удаляем старые заявки
-        EmployeeOnShift::deleteAll([
+        EmployeeOnShift::updateAll(['active' => EmployeeOnShift::ACTIVE_OFF], [
             'and',
             ['status' => [EmployeeOnShift::STATUS_INITIAL, EmployeeOnShift::STATUS_REJECT]],
             ['<=', 'created_at', date('Y-m-d H:i:s', strtotime('-30 minutes', time()))]
index 18e3509e14f4798288426f9cb27735bcad5a983a..05d391d81368358326b4069e71cda34f68ac6fd4 100644 (file)
@@ -40,7 +40,7 @@ class Worker extends Model
 //            [['guid'], 'unique'],
             ['created_by', 'exist', 'targetClass' => Admin::class, 'targetAttribute' => 'id', 'filter' => ['group_id' => [1, 7, 8, 10, 30, 35, 40, 50, 51, 71]]],
             ['store_id', 'exist', 'targetClass' => Products1c::class, 'targetAttribute' => 'id', 'filter' => ['tip' => 'city_store']],
-            ['phone', 'unique', 'targetClass' => EmployeeOnShift::class, 'targetAttribute' => ['phone', 'store_id'], 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL]],
+            ['phone', 'unique', 'targetClass' => EmployeeOnShift::class, 'targetAttribute' => ['phone', 'store_id'], 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL, 'active' => EmployeeOnShift::ACTIVE_ON]],
             ['phone', PhoneValidator::class],
             ['datetime_start', 'checkDateTimeStart']
         ];
index 389382fdd3867cb0b31253317de8eea44dba26ab..431af6898e7f677ab5c49ebb44ef3c13983d8780 100644 (file)
@@ -18,7 +18,7 @@ class WorkerControl extends Model
             ['guid', 'string', 'length' => 36],
             ['guid', 'exist', 'targetClass' => EmployeeOnShift::class,
                 'targetAttribute' => 'guid',
-                'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL],
+                'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL, 'active' => EmployeeOnShift::ACTIVE_ON],
                 'message' => 'Нет новой заявки с таким guid',
             ],
         ];
diff --git a/erp24/migrations/m240827_061358_alter_table_employee_on_shift_add_column_active.php b/erp24/migrations/m240827_061358_alter_table_employee_on_shift_add_column_active.php
new file mode 100755 (executable)
index 0000000..c9b343a
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240827_061358_alter_table_employee_on_shift_add_column_active
+ */
+class m240827_061358_alter_table_employee_on_shift_add_column_active extends Migration
+{
+    const TABLE_NAME = 'erp24.employee_on_shift';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->addColumn(self::TABLE_NAME, 'active', $this->tinyInteger()->notNull()->defaultValue(1)
+            ->after('status_source')->comment('0 - не активная заявка 1 - активная заявка, может использоваться в операциях'));
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropColumn(self::TABLE_NAME, 'active');
+    }
+}
index 11dbe4fc5ade9fd9ea759ada77b8c40f5165015f..0be1477785c33102d8ae48024c5fb94d208bb8f5 100644 (file)
@@ -22,9 +22,13 @@ use Yii;
  * @property int $salary_shift Ставка в рублях за смену
  * @property int $status 0 - в ожидании, 1 - подтверждено, 2 - отказано
  * @property int $status_source -1 - получена ошибка в системе, 0 - не создано, 1 - создано в 1С
+ * @property int $active 0 - не активная заявка 1 - активная заявка, может использоваться в операциях
  */
 class EmployeeOnShift extends \yii\db\ActiveRecord
 {
+    const ACTIVE_ON = 1;
+    const ACTIVE_OFF = 0;
+
     const STATUS_INITIAL = 0;
     const STATUS_ACCEPT = 1;
     const STATUS_REJECT = 2;
@@ -50,7 +54,7 @@ class EmployeeOnShift extends \yii\db\ActiveRecord
         return [
             [['guid', 'phone', 'created_at', 'shift_date', 'shift_type', 'datetime_start', 'datetime_end', 'created_by', 'store_id', 'price'], 'required'],
             [['created_at', 'shift_date', 'datetime_start', 'datetime_end'], 'safe'],
-            [['shift_type', 'created_by', 'price', 'status', 'status_source'], 'integer'],
+            [['shift_type', 'created_by', 'price', 'status', 'status_source', 'active'], 'integer'],
             [['salary_shift'], 'in', 'range' => Timetable::getSalariesDay(), 'skipOnEmpty' => false],
             [['guid', 'store_id'], 'string', 'max' => 36],
             [['phone'], 'string', 'max' => 16],
@@ -80,6 +84,7 @@ class EmployeeOnShift extends \yii\db\ActiveRecord
             'salary_shift' => 'Salary Shift',
             'status' => 'Status',
             'status_source' => 'status_source',
+            'active' => 'active',
         ];
     }
 
index ef1f90f41cc2cbeba65355a52b77b9c313b1b452..c3ed56ef6936e86e1c421ae542cb20d97f82027b 100644 (file)
@@ -81,7 +81,7 @@ try {
             ->all();
         $adminsIds = implode(',',ArrayHelper::getColumn($admins, 'id'));
 
-        $phones = ArrayHelper::getColumn(EmployeeOnShift::find()->all(), 'phone');
+        $phones = ArrayHelper::getColumn(EmployeeOnShift::find()->where(['active' => EmployeeOnShift::ACTIVE_ON])->all(), 'phone');
 
         foreach ($admins as $admin) {
             /** @var Admin $admin */
@@ -111,6 +111,7 @@ try {
             $model->created_at = date("Y-m-d H:i:s");
             $model->status = EmployeeOnShift::STATUS_ACCEPT;
             $model->status_source = EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C;
+            $model->active = EmployeeOnShift::ACTIVE_ON;
             $model->save();
             if ($model->getErrors()) {
                 $error .= json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE);