From: Alexander Smirnov Date: Fri, 27 Dec 2024 06:51:08 +0000 (+0300) Subject: [ERP-272] время создания и обновления а также кто это сделал X-Git-Tag: 1.7~105^2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ee25d7b0ca7e42fc43a81a4900f14cef64fa8afa;p=erp24_rep%2Fyii-erp24%2F.git [ERP-272] время создания и обновления а также кто это сделал --- 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', ]; } }