From eb7c87d07903e2194e875a5e42c1e18d6b68aecc Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 27 Aug 2024 09:42:39 +0300 Subject: [PATCH] =?utf8?q?[ERP-165]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB=D0=B5=20active=20=D0=B4?= =?utf8?q?=D0=BB=D1=8F=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 3 ++- erp24/api3/core/services/ClaimService.php | 3 ++- .../v1/controllers/claim/WorkerController.php | 2 +- .../api3/modules/v1/requests/claim/Worker.php | 2 +- .../v1/requests/claim/WorkerControl.php | 2 +- ...le_employee_on_shift_add_column_active.php | 27 +++++++++++++++++++ erp24/records/EmployeeOnShift.php | 7 ++++- ...yee_for_1c_with_admins_with_empty_guid.php | 3 ++- 8 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 erp24/migrations/m240827_061358_alter_table_employee_on_shift_add_column_active.php diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 9c7d6ba0..cd0706bf 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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 = []; diff --git a/erp24/api3/core/services/ClaimService.php b/erp24/api3/core/services/ClaimService.php index 150ada58..adf2cd06 100644 --- a/erp24/api3/core/services/ClaimService.php +++ b/erp24/api3/core/services/ClaimService.php @@ -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 не найден'); diff --git a/erp24/api3/modules/v1/controllers/claim/WorkerController.php b/erp24/api3/modules/v1/controllers/claim/WorkerController.php index 057496cd..ef814c7a 100644 --- a/erp24/api3/modules/v1/controllers/claim/WorkerController.php +++ b/erp24/api3/modules/v1/controllers/claim/WorkerController.php @@ -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()))] diff --git a/erp24/api3/modules/v1/requests/claim/Worker.php b/erp24/api3/modules/v1/requests/claim/Worker.php index 18e3509e..05d391d8 100644 --- a/erp24/api3/modules/v1/requests/claim/Worker.php +++ b/erp24/api3/modules/v1/requests/claim/Worker.php @@ -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'] ]; diff --git a/erp24/api3/modules/v1/requests/claim/WorkerControl.php b/erp24/api3/modules/v1/requests/claim/WorkerControl.php index 389382fd..431af689 100644 --- a/erp24/api3/modules/v1/requests/claim/WorkerControl.php +++ b/erp24/api3/modules/v1/requests/claim/WorkerControl.php @@ -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 index 00000000..c9b343a0 --- /dev/null +++ b/erp24/migrations/m240827_061358_alter_table_employee_on_shift_add_column_active.php @@ -0,0 +1,27 @@ +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'); + } +} diff --git a/erp24/records/EmployeeOnShift.php b/erp24/records/EmployeeOnShift.php index 11dbe4fc..0be14777 100644 --- a/erp24/records/EmployeeOnShift.php +++ b/erp24/records/EmployeeOnShift.php @@ -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', ]; } diff --git a/erp24/scripts/tasks/task_22_create_employee_for_1c_with_admins_with_empty_guid.php b/erp24/scripts/tasks/task_22_create_employee_for_1c_with_admins_with_empty_guid.php index ef1f90f4..c3ed56ef 100644 --- a/erp24/scripts/tasks/task_22_create_employee_for_1c_with_admins_with_empty_guid.php +++ b/erp24/scripts/tasks/task_22_create_employee_for_1c_with_admins_with_empty_guid.php @@ -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); -- 2.39.5