From ee25d7b0ca7e42fc43a81a4900f14cef64fa8afa Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 27 Dec 2024 09:51:08 +0300 Subject: [PATCH] =?utf8?q?[ERP-272]=20=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20?= =?utf8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=20?= =?utf8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?utf8?q?=D0=B0=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D0=BA=D1=82=D0=BE=20?= =?utf8?q?=D1=8D=D1=82=D0=BE=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../SalesWriteOffsPlanController.php | 4 +++ ...333_create_table_sales_write_offs_plan.php | 4 +++ erp24/records/SalesWriteOffsPlan.php | 29 +++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/erp24/controllers/SalesWriteOffsPlanController.php b/erp24/controllers/SalesWriteOffsPlanController.php index 0afdd718..8f693165 100644 --- a/erp24/controllers/SalesWriteOffsPlanController.php +++ b/erp24/controllers/SalesWriteOffsPlanController.php @@ -63,12 +63,16 @@ class SalesWriteOffsPlanController extends Controller $salesWriteOffsPlan->year = $year; $salesWriteOffsPlan->month = $month; $salesWriteOffsPlan->store_id = $storeId; + $salesWriteOffsPlan->created_by = Yii::$app->user->id; + $salesWriteOffsPlan->created_at = date('Y-m-d H:i:s'); } $salesWriteOffsPlan->total_sales_plan = $total_sales_plan; $salesWriteOffsPlan->write_offs_plan = $write_offs_plan; $salesWriteOffsPlan->offline_sales_plan = $offline_sales_plan; $salesWriteOffsPlan->online_sales_shop_plan = $online_sales_shop_plan; $salesWriteOffsPlan->online_sales_marketplace_plan = $online_sales_marketplace_plan; + $salesWriteOffsPlan->updated_by = Yii::$app->user->id; + $salesWriteOffsPlan->updated_at = date('Y-m-d H:i:s'); $salesWriteOffsPlan->save(); if ($salesWriteOffsPlan->getErrors()) { throw new \Exception(Json::encode($salesWriteOffsPlan->getErrors())); diff --git a/erp24/migrations/m241225_131333_create_table_sales_write_offs_plan.php b/erp24/migrations/m241225_131333_create_table_sales_write_offs_plan.php index 6d05f5f8..95f08867 100755 --- a/erp24/migrations/m241225_131333_create_table_sales_write_offs_plan.php +++ b/erp24/migrations/m241225_131333_create_table_sales_write_offs_plan.php @@ -23,6 +23,10 @@ class m241225_131333_create_table_sales_write_offs_plan extends Migration 'offline_sales_plan' => $this->float()->null()->comment('План продаж офлайн'), 'online_sales_shop_plan' => $this->float()->null()->comment('План online продаж магазина'), 'online_sales_marketplace_plan' => $this->float()->null()->comment('План online продаж маркетплейса'), + 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), + 'updated_at' => $this->dateTime()->notNull()->comment('Дата обновления'), + 'created_by' => $this->integer()->notNull()->comment('ID создателя записи'), + 'updated_by' => $this->integer()->notNull()->comment('ID обновителя записи'), ]); } diff --git a/erp24/records/SalesWriteOffsPlan.php b/erp24/records/SalesWriteOffsPlan.php index a48c94d6..6580092e 100644 --- a/erp24/records/SalesWriteOffsPlan.php +++ b/erp24/records/SalesWriteOffsPlan.php @@ -3,6 +3,8 @@ namespace yii_app\records; use Yii; +use yii\behaviors\TimestampBehavior; +use yii\db\Expression; /** * This is the model class for table "sales_write_offs_plan". @@ -16,6 +18,10 @@ use Yii; * @property float|null $offline_sales_plan План продаж офлайн * @property float|null $online_sales_shop_plan План online продаж магазина * @property float|null $online_sales_marketplace_plan План online продаж маркетплейса + * @property string $created_at Дата создания + * @property string $updated_at Дата обновления + * @property int $created_by ID создателя записи + * @property int $updated_by ID обновителя записи */ class SalesWriteOffsPlan extends \yii\db\ActiveRecord { @@ -33,10 +39,23 @@ class SalesWriteOffsPlan extends \yii\db\ActiveRecord public function rules() { return [ - [['year', 'month', 'store_id'], 'required'], - [['year', 'month', 'store_id'], 'default', 'value' => null], - [['year', 'month', 'store_id'], 'integer'], + [['year', 'month', 'store_id', 'created_at', 'updated_at', 'created_by', 'updated_by'], 'required'], + [['year', 'month', 'store_id', 'created_by', 'updated_by'], 'default', 'value' => null], + [['year', 'month', 'store_id', 'created_by', 'updated_by'], 'integer'], [['total_sales_plan', 'write_offs_plan', 'offline_sales_plan', 'online_sales_shop_plan', 'online_sales_marketplace_plan'], 'number'], + [['created_at', 'updated_at'], 'safe'], + ]; + } + + public function behaviors() + { + return [ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], ]; } @@ -55,6 +74,10 @@ class SalesWriteOffsPlan extends \yii\db\ActiveRecord 'offline_sales_plan' => 'Offline Sales Plan', 'online_sales_shop_plan' => 'Online Sales Shop Plan', 'online_sales_marketplace_plan' => 'Online Sales Marketplace Plan', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + 'created_by' => 'Created By', + 'updated_by' => 'Updated By', ]; } } -- 2.39.5