]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-242] ввод фактических остатков
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 21 Nov 2024 14:02:46 +0000 (17:02 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 21 Nov 2024 14:02:46 +0000 (17:02 +0300)
erp24/controllers/ShiftTransferController.php
erp24/views/shift-transfer/update.php
erp24/views/shift-transfer/view.php
erp24/web/js/shift-transfer/update.js [new file with mode: 0644]

index 18031e84cdabf2368902211cd9c3967722d6a7de..176b6c0f7abe558bbae29d4c1ead8df463f62f95 100644 (file)
@@ -5,8 +5,15 @@ namespace app\controllers;
 use Yii;
 use yii\helpers\ArrayHelper;
 use yii\web\Controller;
+use yii\web\Response;
 use yii_app\records\Admin;
+use yii_app\records\Balances;
+use yii_app\records\ExportImportTable;
 use yii_app\records\MultipleModel;
+use yii_app\records\Prices;
+use yii_app\records\Products1c;
+use yii_app\records\ProductsClass;
+use yii_app\records\SelfCostProduct;
 use yii_app\records\ShiftRemains;
 use yii_app\records\ShiftTransfer;
 use yii_app\services\TaskService;
@@ -90,6 +97,33 @@ class ShiftTransferController extends Controller
             'admins'));
     }
 
+    public function actionGetProductsByGroupLabel() {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $productsClass = ProductsClass::find()->select('category_id')
+            ->where(['tip' => Yii::$app->request->post('groupLabel')])->column();
+
+        return ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+            ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+    }
+
+    public function actionGetProductPriceSelfCostAndRemains() {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+
+        $productGuid = Yii::$app->request->post('productGuid');
+        $storeGuid = Yii::$app->request->post('storeGuid');
+
+        $price = Prices::find()->select(['price'])->where(['product_id' => $productGuid])->one();
+
+        $storeEIT = ExportImportTable::find()->select(['entity_id'])->where(['entity' => 'city_store', 'export_val' => $storeGuid, 'export_id' => 1])->one();
+
+        $selfCost = SelfCostProduct::find()->select(['price'])->where(['product_guid' => $productGuid, 'store_id' => $storeEIT->entity_id])->one();
+
+        $balance = Balances::find()->select(['quantity'])->where(['store_id' => $storeGuid, 'product_id' => $productGuid])->one();
+
+        return ['price' => $price->price ?? 0, 'selfCost' => $selfCost->price ?? 0, 'quantity' => $balance->quantity ?? 0];
+    }
+
     public function actionView($id) {
         $shiftTransfer = ShiftTransfer::findOne($id);
 
@@ -106,4 +140,4 @@ class ShiftTransferController extends Controller
 
         return $this->redirect(['/shift-transfer']);
     }
-}
\ No newline at end of file
+}
index 17f71f566381369aab52de6ba77db2709cdf2bde..d53be08652ab92572cf6bd08dc9f5047478379ec 100644 (file)
@@ -3,11 +3,13 @@
 use unclead\multipleinput\components\BaseColumn;
 use unclead\multipleinput\MultipleInput;
 
+use yii\helpers\ArrayHelper;
 use yii\helpers\Html;
 use yii\widgets\ActiveForm;
 
 use kartik\select2\Select2;
 use dosamigos\datetimepicker\DateTimePicker;
+use yii_app\records\Products1c;
 use yii_app\records\ShiftTransfer;
 use yii_app\records\ProductsClass;
 
@@ -16,6 +18,7 @@ use yii_app\records\ProductsClass;
 /* @var $storeNameById array */
 /* @var $admins array */
 
+$this->registerJsFile('/js/shift-transfer/update.js', ['position' => \yii\web\View::POS_END]);
 
 $this->registerCss('
     .multiple-input-list__btn.js-input-plus.btn.btn-success {
@@ -138,20 +141,6 @@ $this->registerCss('
             'min' => 0,
             'max' => 100,
             'columns' => [
-//                [
-//                    'name'  => 'id',
-//                    'type'  => BaseColumn::TYPE_HIDDEN_INPUT,
-//                    'value' => function($data) {
-//                        return $data['id'] ?? '';
-//                    },
-//                ],
-//                [
-//                    'name'  => 'shift_transfer_id',
-//                    'type'  => BaseColumn::TYPE_HIDDEN_INPUT,
-//                    'value' => function($data) {
-//                        return $data['shift_transfer_id'] ?? '';
-//                    },
-//                ],
                 [
                     'name'  => 'group_label',
                     'title' => 'Название группы',
@@ -166,8 +155,15 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'product_guid',
-                    'title' => 'GUID продукта',
-                    'type'  => BaseColumn::TYPE_TEXT_INPUT,
+                    'title' => 'Продукт',
+                    'type'  => BaseColumn::TYPE_DROPDOWN,
+                    'items' => function($data) {
+                        $productsClass = ProductsClass::find()->select('category_id')
+                            ->where(['tip' => $data['group_label'] ?? null])->column();
+
+                        return ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+                            ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+                    },
                     'value' => function($data) {
                         return $data['product_guid'] ?? '';
                     },
@@ -177,7 +173,7 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'retail_price',
-                    'title' => 'Розничная цена',
+                    'title' => 'Розничная цена, руб',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
                     'options' => ['type' => 'number', 'step' => 0.01],
                     'value' => function($data) {
@@ -189,7 +185,7 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'self_cost',
-                    'title' => 'Себестоимость',
+                    'title' => 'Себестоимость, руб',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
                     'options' => ['type' => 'number', 'step' => 0.01],
                     'value' => function($data) {
@@ -201,7 +197,7 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'remains_summ',
-                    'title' => 'Сумма остатков (недостача или излишек)',
+                    'title' => 'Сумма остатков (недостача или излишек), руб',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
                     'options' => ['type' => 'number', 'step' => 0.01],
                     'value' => function($data) {
@@ -213,9 +209,9 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'remains_count',
-                    'title' => 'Фактические остатки кол-во',
+                    'title' => 'Фактические остатки кол-во, шт',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
-                    'options' => ['type' => 'number', 'step' => 0.01],
+                    'options' => ['type' => 'number', 'step' => 0.01, 'min' => 0],
                     'value' => function($data) {
                         return $data['remains_count'] ?? '';
                     },
@@ -225,7 +221,7 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'fact_and_1c_diff',
-                    'title' => 'Разница факт и по программе 1с',
+                    'title' => 'Разница факт и по программе 1с, шт',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
                     'options' => ['type' => 'number', 'step' => 0.01],
                     'value' => function($data) {
@@ -237,7 +233,7 @@ $this->registerCss('
                 ],
                 [
                     'name'  => 'remains_1c',
-                    'title' => 'Остатки по 1с',
+                    'title' => 'Остатки по 1с, шт',
                     'type'  => BaseColumn::TYPE_TEXT_INPUT,
                     'options' => ['type' => 'number', 'step' => 0.01],
                     'value' => function($data) {
index bda4cbf24c32f9b6fb955ccc7d016483a96d4eeb..e120e47b757170730cebc36feda0966423a46d57 100644 (file)
@@ -2,7 +2,10 @@
 
 use yii\helpers\Html;
 use yii\widgets\DetailView;
+use yii\helpers\ArrayHelper;
 use yii_app\records\ShiftTransfer;
+use yii_app\records\ProductsClass;
+use yii_app\records\Products1c;
 
 /* @var $shiftTransfer ShiftTransfer */
 /* @var $storeNameById array */
@@ -67,14 +70,20 @@ use yii_app\records\ShiftTransfer;
                         'attribute'  => 'group_label',
                         'label' => 'Название группы',
                         'value' => function($data) {
-                            return $data['group_label'] ?? '';
+                            return ProductsClass::getHints()[$data['group_label']] ?? '';
                         },
                     ],
                     [
                         'attribute'  => 'product_guid',
-                        'label' => 'GUID продукта',
+                        'label' => 'Продукт',
                         'value' => function($data) {
-                            return $data['product_guid'] ?? '';
+                            $productsClass = ProductsClass::find()->select('category_id')
+                                ->where(['tip' => $data['group_label'] ?? null])->column();
+
+                            $products = ArrayHelper::map(Products1c::find()->select(['id', 'name'])
+                                ->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+
+                            return $products[$data['product_guid']] ?? '';
                         },
                     ],
                     [
@@ -100,21 +109,74 @@ use yii_app\records\ShiftTransfer;
                     ],
                     [
                         'attribute'  => 'remains_count',
-                        'label' => 'Фактические остатки кол-во',
+                        'label' => 'Фактические остатки кол-во, шт',
                         'value' => function($data) {
                             return $data['remains_count'] ?? '';
                         },
                     ],
                     [
                         'attribute'  => 'fact_and_1c_diff',
-                        'label' => 'РазниÑ\86а Ñ\84акÑ\82 Ð¸ Ð¿Ð¾ Ð¿Ñ\80огÑ\80амме 1Ñ\81, Ñ\80Ñ\83б',
+                        'label' => 'РазниÑ\86а Ñ\84акÑ\82 Ð¸ Ð¿Ð¾ Ð¿Ñ\80огÑ\80амме 1Ñ\81, Ñ\88Ñ\82',
                         'value' => function($data) {
                             return $data['fact_and_1c_diff'] ?? '';
                         },
                     ],
                     [
                         'attribute'  => 'remains_1c',
-                        'label' => 'Остатки по 1с, руб',
+                        'label' => 'Остатки по 1с, шт',
+                        'value' => function($data) {
+                            return $data['remains_1c'] ?? '';
+                        },
+                    ],
+                ],
+            ]); ?>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="col-12">
+            <?= \yii\grid\GridView::widget([
+                'dataProvider' => new \yii\data\ArrayDataProvider([
+                    'allModels' => [
+                        [
+                            'remains_summ' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_summ')),
+                            'remains_count' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_count')),
+                            'remains_diff' => array_sum(array_column($shiftTransfer->shiftRemains, 'fact_and_1c_diff')),
+                            'remains_1c' => array_sum(array_column($shiftTransfer->shiftRemains, 'remains_1c')),
+                        ]
+                    ],
+                ]),
+                'columns' => [
+                    [
+                        'label' => '',
+                        'value' => function () {
+                            return 'Итого:';
+                        }
+                    ],
+                    [
+                        'attribute'  => 'remains_summ',
+                        'label' => 'Сумма остатков (недостача или излишек), руб',
+                        'value' => function($data) {
+                            return $data['remains_summ'] ?? '';
+                        },
+                    ],
+                    [
+                        'attribute'  => 'remains_count',
+                        'label' => 'Фактические остатки кол-во, шт',
+                        'value' => function($data) {
+                            return $data['remains_count'] ?? '';
+                        },
+                    ],
+                    [
+                        'attribute'  => 'remains_diff',
+                        'label' => 'Разница факт и по программе 1с, шт',
+                        'value' => function($data) {
+                            return $data['remains_diff'] ?? '';
+                        },
+                    ],
+                    [
+                        'attribute'  => 'remains_1c',
+                        'label' => 'Остатки по 1с, шт',
                         'value' => function($data) {
                             return $data['remains_1c'] ?? '';
                         },
diff --git a/erp24/web/js/shift-transfer/update.js b/erp24/web/js/shift-transfer/update.js
new file mode 100644 (file)
index 0000000..636cc23
--- /dev/null
@@ -0,0 +1,55 @@
+/* jshint esversion: 6 */
+
+const param24 = $('meta[name=csrf-param]').attr('content');
+const token24 = $('meta[name=csrf-token]').attr('content');
+
+$(document).ready(() => {
+    $('.multiple-input').on('afterAddRow', function(e, row, currentIndex) {
+        var store = $('#shifttransfer-store_guid');
+        var groupLabel = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-group_label');
+        var productGuid = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-product_guid');
+        var retailPrice = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-retail_price');
+        var selfCost = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-self_cost');
+        var remains1c = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_1c');
+        var remains_summ = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_summ');
+        var remains_count = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-remains_count');
+        var fact_and_1c_diff = $(row).find('#shifttransfer-shiftremains-' + currentIndex + '-fact_and_1c_diff');
+
+        function onChangeTarget() {
+            fact_and_1c_diff.val(remains_count.val() - remains1c.val());
+            remains_summ.val(remains_count.val() * retailPrice.val())
+        }
+
+        groupLabel.on('change', (e) => {
+            $.ajax({
+                type: 'POST',
+                url: '/shift-transfer/get-products-by-group-label',
+                data: { groupLabel: e.target.value, [param24]: token24 },
+                dataType: 'json',
+                success: (data) => {
+                    productGuid.empty();
+                    $.each(data, (guid, name) => {
+                        var option = document.createElement('option');
+                        option.text = name;
+                        option.value = guid;
+                        productGuid.append(option);
+                    })
+                }
+            });
+        });
+        productGuid.on('change', (e) => {
+            $.ajax({
+                type: 'POST',
+                url: '/shift-transfer/get-product-price-self-cost-and-remains',
+                data: { productGuid: e.target.value, storeGuid: store.val(), [param24]: token24 },
+                dataType: 'json',
+                success: (data) => {
+                    if (data.price) { retailPrice.val(data.price); }
+                    if (data.selfCost) { selfCost.val(data.selfCost); }
+                    if (data.quantity) { remains1c.val(data.quantity); }
+                }
+            });
+        });
+        remains_count.on('change', onChangeTarget);
+    });
+});