]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-261] waybill_incoming_products feature_smirnov_erp-261_waybill_incoming
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 11 Dec 2024 07:51:18 +0000 (10:51 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 11 Dec 2024 07:51:18 +0000 (10:51 +0300)
erp24/controllers/WaybillIncomingController.php [new file with mode: 0644]
erp24/migrations/m241211_073430_create_table_waybill_incoming_products.php [new file with mode: 0755]
erp24/records/WaybillIncoming.php [new file with mode: 0644]
erp24/records/WaybillIncomingProducts.php [new file with mode: 0644]
erp24/views/waybill-incoming/index.php [new file with mode: 0644]
erp24/views/waybill-incoming/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/WaybillIncomingController.php b/erp24/controllers/WaybillIncomingController.php
new file mode 100644 (file)
index 0000000..b727c2f
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+
+namespace app\controllers;
+
+use yii\data\ActiveDataProvider;
+use yii\web\Controller;
+use yii_app\records\WaybillIncoming;
+use yii_app\records\WaybillIncomingProducts;
+
+class WaybillIncomingController extends Controller
+{
+    public function actionIndex() {
+        $dataProvider = new ActiveDataProvider([
+            'query' => 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 (executable)
index 0000000..661e22b
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m241211_073430_create_table_waybill_incoming_products
+ */
+class m241211_073430_create_table_waybill_incoming_products extends Migration
+{
+    const TABLE_NAME = 'erp24.waybill_incoming_products';
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $tableSchema = $this->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 (file)
index 0000000..167227e
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "waybill_incoming".
+ *
+ * @property int $id
+ * @property string $guid GUID документа для 1c
+ * @property int|null $shift_transfer_id ID записи передачи смены
+ * @property int $status Статус документа
+ * @property int $created_admin_id Создан пользователем
+ * @property int|null $updated_admin_id Изменён пользователем
+ * @property int $store_id id магазина в ERP
+ * @property string $store_guid GUID магазина из 1с
+ * @property string $number Название документа
+ * @property string|null $number_1c Название документа в 1с
+ * @property string $date Дата документа
+ * @property string|null $comment Комментарий
+ * @property float $quantity Количество
+ * @property float $summ Сумма розничная
+ * @property float|null $summ_self_cost Сумма себестоимости
+ * @property string $created_at Дата создания
+ * @property string|null $updated_at Дата обновления
+ * @property string|null $deleted_at Дата удаление
+ * @property string|null $send_at Дата отправления в 1с
+ * @property int $active Активность
+ * @property int|null $deleted_admin_id Удален пользователем
+ */
+class WaybillIncoming extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'waybill_incoming';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['guid', 'created_admin_id', 'store_id', 'store_guid', 'number', 'date', 'quantity', 'summ', 'created_at'], 'required'],
+            [['shift_transfer_id', 'status', 'created_admin_id', 'updated_admin_id', 'store_id', 'active', 'deleted_admin_id'], 'default', 'value' => 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 (file)
index 0000000..889509e
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "waybill_incoming_products".
+ *
+ * @property int $id ID
+ * @property int $waybill_incoming_id GUID документа из таблицы waybill_incoming
+ * @property string $name Название товара
+ * @property string|null $product_id ID товара с недостатком
+ * @property float|null $product_count Количество товара с недостатком
+ * @property float|null $product_price Цена товара розничная
+ * @property float|null $product_self_cost Себестоимость товара
+ * @property float $summ Сумма розничная
+ * @property float|null $summ_self_cost Сумма себестоимости
+ * @property string $created_at Дата создания
+ * @property string|null $updated_at Дата обновления
+ *
+ * @property WaybillIncoming $waybillIncoming
+ */
+class WaybillIncomingProducts extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'waybill_incoming_products';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['waybill_incoming_id', 'name', 'summ', 'created_at'], 'required'],
+            [['waybill_incoming_id'], 'default', 'value' => 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 (file)
index 0000000..914fd6c
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+use yii\data\ActiveDataProvider;
+use yii\helpers\Url;
+use yii\helpers\Html;
+
+use kartik\grid\ActionColumn;
+use kartik\grid\GridView;
+
+use yii_app\records\WaybillIncoming;
+
+/* @var $dataProvider ActiveDataProvider */
+
+?>
+
+<div class="waybillIncomingIndex m-5">
+
+    <h1>Waybill Income</h1>
+
+    <?= GridView::widget([
+        'dataProvider' => $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]);
+                }
+            ],
+        ],
+    ]) ?>
+
+</div>
diff --git a/erp24/views/waybill-incoming/view.php b/erp24/views/waybill-incoming/view.php
new file mode 100644 (file)
index 0000000..d3cc3c6
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+use yii\widgets\DetailView;
+use yii\grid\GridView;
+use yii\helpers\Html;
+use yii_app\records\Admin;
+use yii_app\records\CityStore;
+use yii_app\records\ExportImportTable;
+
+/** @var yii_app\records\WaybillIncoming $model */
+/** @var yii\data\ActiveDataProvider $productsDataProvider */
+
+$this->title = "Детали документа: {$model->number}";
+$this->params['breadcrumbs'][] = ['label' => 'Список документов', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="waybill-write-offs-view p-4">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <!-- Детали документа -->
+    <?= DetailView::widget([
+        'model' => $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',
+        ],
+    ]) ?>
+
+    <h2>Списываемые товары</h2>
+
+    <!-- Таблица с товарами -->
+    <?= GridView::widget([
+        'dataProvider' => $productsDataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+            'name',
+            'product_id',
+            'product_count',
+            'product_price',
+            'product_self_cost',
+            'summ',
+            'summ_self_cost',
+            'created_at',
+        ],
+    ]) ?>
+
+</div>
\ No newline at end of file