From cd6c9af76c56eafac97316b6369ae1c5701bb59e Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 11 Dec 2024 10:51:18 +0300 Subject: [PATCH] [ERP-261] waybill_incoming_products --- .../controllers/WaybillIncomingController.php | 38 ++++++++ ...create_table_waybill_incoming_products.php | 54 +++++++++++ erp24/records/WaybillIncoming.php | 92 +++++++++++++++++++ erp24/records/WaybillIncomingProducts.php | 80 ++++++++++++++++ erp24/views/waybill-incoming/index.php | 66 +++++++++++++ erp24/views/waybill-incoming/view.php | 71 ++++++++++++++ 6 files changed, 401 insertions(+) create mode 100644 erp24/controllers/WaybillIncomingController.php create mode 100755 erp24/migrations/m241211_073430_create_table_waybill_incoming_products.php create mode 100644 erp24/records/WaybillIncoming.php create mode 100644 erp24/records/WaybillIncomingProducts.php create mode 100644 erp24/views/waybill-incoming/index.php create mode 100644 erp24/views/waybill-incoming/view.php diff --git a/erp24/controllers/WaybillIncomingController.php b/erp24/controllers/WaybillIncomingController.php new file mode 100644 index 00000000..b727c2f8 --- /dev/null +++ b/erp24/controllers/WaybillIncomingController.php @@ -0,0 +1,38 @@ + WaybillIncoming::find(), + ]); + return $this->render('index', compact('dataProvider')); + } + + public function actionView($id) + { + $model = WaybillIncoming::findOne($id); + if (!$model) { + throw new \yii\web\NotFoundHttpException("Документ с ID {$id} не найден."); + } + + $productsDataProvider = new \yii\data\ActiveDataProvider([ + 'query' => WaybillIncomingProducts::find()->where(['waybill_incoming_id' => $model->id]), + 'pagination' => [ + 'pageSize' => 10, + ], + ]); + + return $this->render('view', [ + 'model' => $model, + 'productsDataProvider' => $productsDataProvider, + ]); + } +} diff --git a/erp24/migrations/m241211_073430_create_table_waybill_incoming_products.php b/erp24/migrations/m241211_073430_create_table_waybill_incoming_products.php new file mode 100755 index 00000000..661e22b8 --- /dev/null +++ b/erp24/migrations/m241211_073430_create_table_waybill_incoming_products.php @@ -0,0 +1,54 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey()->comment('ID'), + 'waybill_incoming_id' => $this->integer()->notNull()->comment('GUID документа из таблицы waybill_incoming'), + 'name' => $this->string(100)->notNull()->comment('Название товара'), + 'product_id' => $this->string()->comment('ID товара с недостатком'), + 'product_count' => $this->float()->comment('Количество товара с недостатком'), + 'product_price' => $this->float()->comment('Цена товара розничная'), + 'product_self_cost' => $this->float()->comment('Себестоимость товара'), + 'summ' => $this->float()->notNull()->comment('Сумма розничная'), + 'summ_self_cost' => $this->float()->null()->comment('Сумма себестоимости'), + 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), + 'updated_at' => $this->dateTime()->null()->comment('Дата обновления'), + ]); + + $this->addForeignKey( + 'fk-waybill_incoming_id', + self::TABLE_NAME, + 'waybill_incoming_id', + 'erp24.waybill_incoming', + 'id', + ); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } +} diff --git a/erp24/records/WaybillIncoming.php b/erp24/records/WaybillIncoming.php new file mode 100644 index 00000000..167227e6 --- /dev/null +++ b/erp24/records/WaybillIncoming.php @@ -0,0 +1,92 @@ + null], + [['shift_transfer_id', 'status', 'created_admin_id', 'updated_admin_id', 'store_id', 'active', 'deleted_admin_id'], 'integer'], + [['date', 'created_at', 'updated_at', 'deleted_at', 'send_at'], 'safe'], + [['comment'], 'string'], + [['quantity', 'summ', 'summ_self_cost'], 'number'], + [['guid', 'store_guid', 'number', 'number_1c'], 'string', 'max' => 100], + [['guid'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'guid' => 'Guid', + 'shift_transfer_id' => 'Shift Transfer ID', + 'status' => 'Status', + 'created_admin_id' => 'Created Admin ID', + 'updated_admin_id' => 'Updated Admin ID', + 'store_id' => 'Store ID', + 'store_guid' => 'Store Guid', + 'number' => 'Number', + 'number_1c' => 'Number 1c', + 'date' => 'Date', + 'comment' => 'Comment', + 'quantity' => 'Quantity', + 'summ' => 'Summ', + 'summ_self_cost' => 'Summ Self Cost', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + 'deleted_at' => 'Deleted At', + 'send_at' => 'Send At', + 'active' => 'Active', + 'deleted_admin_id' => 'Deleted Admin ID', + ]; + } + + public function getShiftTransfer() { + return $this->hasOne(ShiftTransfer::class, ['id' => 'shift_transfer_id']); + } +} diff --git a/erp24/records/WaybillIncomingProducts.php b/erp24/records/WaybillIncomingProducts.php new file mode 100644 index 00000000..889509ed --- /dev/null +++ b/erp24/records/WaybillIncomingProducts.php @@ -0,0 +1,80 @@ + null], + [['waybill_incoming_id'], 'integer'], + [['product_count', 'product_price', 'product_self_cost', 'summ', 'summ_self_cost'], 'number'], + [['created_at', 'updated_at'], 'safe'], + [['name'], 'string', 'max' => 100], + [['product_id'], 'string', 'max' => 255], + [['waybill_incoming_id'], 'exist', 'skipOnError' => true, 'targetClass' => WaybillIncoming::class, 'targetAttribute' => ['waybill_incoming_id' => 'id']], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'waybill_incoming_id' => 'Waybill Incoming ID', + 'name' => 'Name', + 'product_id' => 'Product ID', + 'product_count' => 'Product Count', + 'product_price' => 'Product Price', + 'product_self_cost' => 'Product Self Cost', + 'summ' => 'Summ', + 'summ_self_cost' => 'Summ Self Cost', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + ]; + } + + /** + * Gets query for [[WaybillIncoming]]. + * + * @return \yii\db\ActiveQuery + */ + public function getWaybillIncoming() + { + return $this->hasOne(WaybillIncoming::class, ['id' => 'waybill_incoming_id']); + } +} diff --git a/erp24/views/waybill-incoming/index.php b/erp24/views/waybill-incoming/index.php new file mode 100644 index 00000000..914fd6cb --- /dev/null +++ b/erp24/views/waybill-incoming/index.php @@ -0,0 +1,66 @@ + + +
+ +

Waybill Income

+ + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + [ + 'attribute' => 'guid', + 'value' => function ($model) { + return \yii\helpers\Html::a($model->guid, ['view', 'id' => $model->id]); + }, + 'format' => 'raw', + ], + 'shift_transfer_id', + 'status', + 'created_admin_id', + 'updated_admin_id', + [ + 'label' => 'Магазин', + 'attribute' => 'store_id', + 'value' => function ($model) { + return \yii_app\records\CityStore::findOne(\yii_app\records\ExportImportTable::findOne(['export_val' => $model->store_guid]) + ->entity_id)->name; + } + ], + 'number', + 'number_1c', + 'date', + 'comment', + 'quantity', + 'summ', + 'summ_self_cost', + 'created_at', + 'updated_at', + 'deleted_at', + 'send_at', + 'active', + 'deleted_admin_id', + [ + 'class' => ActionColumn::class, + 'template' => '{view}', + 'urlCreator' => function ($action, WaybillIncoming $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]) ?> + +
diff --git a/erp24/views/waybill-incoming/view.php b/erp24/views/waybill-incoming/view.php new file mode 100644 index 00000000..d3cc3c6f --- /dev/null +++ b/erp24/views/waybill-incoming/view.php @@ -0,0 +1,71 @@ +title = "Детали документа: {$model->number}"; +$this->params['breadcrumbs'][] = ['label' => 'Список документов', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + + $model, + 'attributes' => [ + 'id', + 'guid', + 'number', + 'date', + [ + 'label' => 'Магазин', + 'attribute' => 'store_id', + 'value' => function ($model) { + return CityStore::findOne(ExportImportTable::findOne(['export_val' => $model->store_guid]) + ->entity_id)->name; + } + ], + 'quantity', + 'summ', + 'status', + [ + 'label' => 'Создан пользователем', + 'attribute' => 'created_admin_id', + 'value' => function ($model) { + return Admin::findOne([$model->created_admin_id])->name; + } + ], + 'created_at', + 'updated_at', + 'deleted_at', + ], + ]) ?> + +

Списываемые товары

+ + + $productsDataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'name', + 'product_id', + 'product_count', + 'product_price', + 'product_self_cost', + 'summ', + 'summ_self_cost', + 'created_at', + ], + ]) ?> + +
\ No newline at end of file -- 2.39.5