From: Alexander Smirnov Date: Thu, 21 Nov 2024 14:02:46 +0000 (+0300) Subject: [ERP-242] ввод фактических остатков X-Git-Tag: 1.7~223^2~2 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=dac97406c3a9ffa3274698e4c3b110558090ce99;p=erp24_rep%2Fyii-erp24%2F.git [ERP-242] ввод фактических остатков --- diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 18031e84..176b6c0f 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -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 +} diff --git a/erp24/views/shift-transfer/update.php b/erp24/views/shift-transfer/update.php index 17f71f56..d53be086 100644 --- a/erp24/views/shift-transfer/update.php +++ b/erp24/views/shift-transfer/update.php @@ -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) { diff --git a/erp24/views/shift-transfer/view.php b/erp24/views/shift-transfer/view.php index bda4cbf2..e120e47b 100644 --- a/erp24/views/shift-transfer/view.php +++ b/erp24/views/shift-transfer/view.php @@ -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' => 'Разница факт и по программе 1с, руб', + 'label' => 'Разница факт и по программе 1с, шт', 'value' => function($data) { return $data['fact_and_1c_diff'] ?? ''; }, ], [ 'attribute' => 'remains_1c', - 'label' => 'Остатки по 1с, руб', + 'label' => 'Остатки по 1с, шт', + 'value' => function($data) { + return $data['remains_1c'] ?? ''; + }, + ], + ], + ]); ?> + + + +
+
+ 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 index 00000000..636cc233 --- /dev/null +++ b/erp24/web/js/shift-transfer/update.js @@ -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); + }); +});