From 001518e9bae3551daffe2bd578c0cd207f57475c Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 6 Dec 2024 10:05:18 +0300 Subject: [PATCH] =?utf8?q?ERP-259=20=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?utf8?q?=D1=82=D0=BA=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B3=D0=BE?= =?utf8?q?=20=D1=88=D0=B0=D0=B3=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4?= =?utf8?q?=D0=B0=D1=87=D0=B8=20=D1=81=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ShiftTransferController.php | 14 +- erp24/records/EqualizationRemains.php | 47 +++- erp24/views/shift-transfer/_replacement.php | 247 +++++++++--------- 3 files changed, 181 insertions(+), 127 deletions(-) diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index cb8ed07f..fc4d378b 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -222,10 +222,16 @@ class ShiftTransferController extends Controller $shiftTransfer = ShiftTransfer::findOne($shiftTransferId); $storeId = array_flip(array_map('strval', CityStore::getAllActiveGuidId()))[$shiftTransfer->store_guid]; $productSelfCost = SelfCostProduct::findOne(['product_guid' => $productGuid, 'date' => $shiftTransfer->date, 'store_id' => $storeId]); - $productReplacement = ArrayHelper::map(Products1c::findAll(['id' => Product1cReplacement::find() - ->where(['guid' => $productGuid]) - ->select('guid_replacement') - ->column()]), 'id', 'name'); + $productReplacement = ArrayHelper::map( + Product1cReplacement::find() + ->andWhere(['in', 'guid_replacement', ShiftTransfer::find() + ->select('product_replacement_id') + ]) + ->andWhere(['guid' => $productGuid]) + ->select('guid_replacement') + ->column(), + 'id', 'name' + ); if (!$productPrice || !$productReplacement || !$productSelfCost) { throw new \Exception('У данного товара нет цены либо замен!'); diff --git a/erp24/records/EqualizationRemains.php b/erp24/records/EqualizationRemains.php index 2bf72474..218337f3 100644 --- a/erp24/records/EqualizationRemains.php +++ b/erp24/records/EqualizationRemains.php @@ -146,17 +146,60 @@ class EqualizationRemains extends \yii\db\ActiveRecord ->andWhere(['guid' => $m->product_guid]) ->select('guid_replacement') ->scalar(); + if (!$plus->andWhere(['product_guid' => $replacement])->exists()) { + continue; + } + $p = $plus->andWhere(['product_guid' => $replacement])->one(); + $model = new EqualizationRemains(); + $model->setAttributes([ + 'shift_id' => $shiftTransfer->id, + 'product_id' => $m->product_guid, + 'product_count' => min ($m->fact_and_1c_diff,$p->fact_and_1c_diff), + 'product_price' => $m->retail_price, + 'product_self_cost' => $m->self_cost, + 'product_replacement_id' => $p->product_guid, + 'product_replacement_count' => min ($m->fact_and_1c_diff,$p->fact_and_1c_diff), + 'product_replacement_price' => $p->retail_price, + 'product_replacement_self_cost' => $p->self_cost, + 'balance' => $m->fact_and_1c_diff * ($p->retail_price - $m->retail_price), + 'balance_self_cost' => $m->fact_and_1c_diff * ($p->self_cost - $m->self_cost) + ]); + if ($model->validate()) { + $model->save(); + } elseif ($model->getErrors()) { + var_dump($model->errors); + die(); + } + } + + $plus = ShiftRemains::find() + ->andWhere(['shift_transfer_id' => $shiftTransfer->id]) + ->andWhere(['!=', 'fact_and_1c_diff', 0]) + ->andWhere(['>', 'fact_and_1c_diff', 0]) + ->all(); + foreach ($plus as $p) { + if (EqualizationRemains::find() + ->andWhere(['shift_id' => $shiftTransfer->id]) + ->andWhere(['product_replacement_id' => $p->product_guid]) + ->exists()) { + continue; + } + + $replacement = Product1cReplacement::find() + ->andWhere(['guid' => $p->product_guid]) + ->select('guid_replacement') + ->scalar(); $model = new EqualizationRemains(); $model->setAttributes([ 'shift_id' => $shiftTransfer->id, 'product_id' => $m->product_guid, - 'product_count' => $m->fact_and_1c_diff, + 'product_count' => min ($m->fact_and_1c_diff,$p->fact_and_1c_diff), 'product_price' => $m->retail_price, 'product_self_cost' => $m->self_cost, 'product_replacement_id' => $p->product_guid, - 'product_replacement_count' => $m->fact_and_1c_diff, + 'product_replacement_count' => min ($m->fact_and_1c_diff,$p->fact_and_1c_diff), 'product_replacement_price' => $p->retail_price, 'product_replacement_self_cost' => $p->self_cost, 'balance' => $m->fact_and_1c_diff * ($p->retail_price - $m->retail_price), diff --git a/erp24/views/shift-transfer/_replacement.php b/erp24/views/shift-transfer/_replacement.php index 77382a2d..e397c15a 100644 --- a/erp24/views/shift-transfer/_replacement.php +++ b/erp24/views/shift-transfer/_replacement.php @@ -17,129 +17,131 @@ use yii\widgets\ActiveForm; $this->registerJsFile('/js/shift-transfer/replacement.js', ['position' => \yii\web\View::POS_END]); +$totalBalance = array_sum(array_column($shiftTransfer->equalizationRemains, 'balance')); + $form = \yii\widgets\ActiveForm::begin(); if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIONS, ShiftTransfer::STATUS_ID_INPUT_FACT_REMAINS]) && Yii::$app->user->id === $shiftTransfer->end_shift_admin_id) { -// echo $form->field($shiftTransfer, 'equalizationRemains')->widget(MultipleInput::class, [ -// 'min' => 0, -// 'max' => 100, -// 'columns' => [ -// [ -// 'name' => 'product_id', -// 'title' => 'Заменяемый товар', -// 'type' => Select2::class, -// 'options' => [ -// 'data' => array_merge( -// ['text' => 'Выберите товар'], -// $products -// ), -// 'pluginOptions' => [ -// 'allowClear' => true, -// ], -// 'pluginEvents' => [ -// 'change' => new \yii\web\JsExpression('function() { setProductData.call(this); }'), -// ], -// ], -// 'value' => function ($model) { -// return $model->product->id ?? ''; -// }, -// ], -// [ -// 'name' => 'product_price', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'title' => 'Цена товара', -// 'value' => function ($data) { -// return $data['product_price'] ?? ''; -// }, -// ], -// [ -// 'name' => 'product_self_cost', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'title' => 'Себестоимость товара', -// 'value' => function ($data) { -// return $data['product_self_cost'] ?? ''; -// }, -// ], -// [ -// 'name' => 'product_replacement_id', -// 'title' => 'Замещающий товар', -// 'type' => Select2::class, -// 'options' => [ -// 'data' => [], -// 'options' => [ -// 'placeholder' => 'Выберите товар', -// 'class' => 'form-control', -// ], -// 'pluginOptions' => [ -// 'allowClear' => true, -// ], -// 'pluginEvents' => [ -// 'select2:select' => new \yii\web\JsExpression('function() { -// setReplacementPriceData.call(this); -// }'), -// ], -// ], -// 'value' => function ($model) { -// return $model->productReplacement->name ?? ''; -// }, -// ], -// [ -// 'name' => 'product_replacement_price', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'title' => 'Цена замещающего товара', -// 'value' => function ($data) { -// return $data['product_replacement_price'] ?? ''; -// }, -// ], -// [ -// 'name' => 'product_replacement_self_cost', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'title' => 'Себестоимость замещаемого товара', -// 'value' => function ($data) { -// return $data['product_replacement_self_cost'] ?? ''; -// }, -// ], -// [ -// 'name' => 'product_replacement_count', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 1,], -// 'title' => 'Количество', -// 'value' => function ($data) { -// return $data['product_replacement_count'] ?? ''; -// } -// ], -// [ -// 'name' => 'balance', -// 'title' => 'Баланс', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'value' => function ($data) { -// return $data['balance'] ?? ''; -// }, -// ], -// [ -// 'name' => 'balance_self_cost', -// 'title' => 'Разница в сумме (Себестоиомость)', -// 'type' => BaseColumn::TYPE_TEXT_INPUT, -// 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], -// 'value' => function ($data) { -// return $data['balance_self_cost'] ?? ''; -// }, -// ], -// ], -// 'addButtonPosition' => MultipleInput::POS_FOOTER, -// 'addButtonOptions' => [ -// 'class' => 'btn btn-success visible', -// ], -// 'removeButtonOptions' => [ -// 'class' => 'btn btn-danger visible', -// ], -// 'iconSource' => 'fa', -// ])->label('Таблица возможных замен'); + echo $form->field($shiftTransfer, 'equalizationRemains')->widget(MultipleInput::class, [ + 'min' => 0, + 'max' => 100, + 'columns' => [ + [ + 'name' => 'product_id', + 'title' => 'Заменяемый товар', + 'type' => Select2::class, + 'options' => [ + 'data' => array_merge( + ['text' => 'Выберите товар'], + $products + ), + 'pluginOptions' => [ + 'allowClear' => true, + ], + 'pluginEvents' => [ + 'change' => new \yii\web\JsExpression('function() { setProductData.call(this); }'), + ], + ], + 'value' => function ($model) { + return $model->product->id ?? ''; + }, + ], + [ + 'name' => 'product_price', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'title' => 'Цена товара', + 'value' => function ($data) { + return $data['product_price'] ?? ''; + }, + ], + [ + 'name' => 'product_self_cost', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'title' => 'Себестоимость товара', + 'value' => function ($data) { + return $data['product_self_cost'] ?? ''; + }, + ], + [ + 'name' => 'product_replacement_id', + 'title' => 'Замещающий товар', + 'type' => Select2::class, + 'options' => [ + 'data' => [], + 'options' => [ + 'placeholder' => 'Выберите товар', + 'class' => 'form-control', + ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + 'pluginEvents' => [ + 'select2:select' => new \yii\web\JsExpression('function() { + setReplacementPriceData.call(this); + }'), + ], + ], + 'value' => function ($model) { + return $model->productReplacement->name ?? ''; + }, + ], + [ + 'name' => 'product_replacement_price', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'title' => 'Цена замещающего товара', + 'value' => function ($data) { + return $data['product_replacement_price'] ?? ''; + }, + ], + [ + 'name' => 'product_replacement_self_cost', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'title' => 'Себестоимость замещаемого товара', + 'value' => function ($data) { + return $data['product_replacement_self_cost'] ?? ''; + }, + ], + [ + 'name' => 'product_replacement_count', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 1,], + 'title' => 'Количество', + 'value' => function ($data) { + return $data['product_replacement_count'] ?? ''; + } + ], + [ + 'name' => 'balance', + 'title' => 'Баланс', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'value' => function ($data) { + return $data['balance'] ?? ''; + }, + ], + [ + 'name' => 'balance_self_cost', + 'title' => 'Разница в сумме (Себестоиомость)', + 'type' => BaseColumn::TYPE_TEXT_INPUT, + 'options' => ['type' => 'number', 'step' => 0.01, 'readonly' => true,], + 'value' => function ($data) { + return $data['balance_self_cost'] ?? ''; + }, + ], + ], + 'addButtonPosition' => MultipleInput::POS_FOOTER, + 'addButtonOptions' => [ + 'class' => 'btn btn-success visible', + ], + 'removeButtonOptions' => [ + 'class' => 'btn btn-danger visible', + ], + 'iconSource' => 'fa', + ])->label('Таблица возможных замен'); echo $btn = Html::submitButton('Сохранить', [ 'class' => 'btn btn-primary float-right', @@ -152,6 +154,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'dataProvider' => new ArrayDataProvider([ 'allModels' => $shiftTransfer->equalizationRemains, ]), + 'showFooter' => true, 'columns' => [ [ 'attribute' => 'product_id', @@ -192,12 +195,14 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'label' => 'Количество товара', 'format' => 'raw', 'pageSummary' => true, + 'footer' => Html::tag('b', $totalBalance < 0 ? 'Недосдача: ' : 'Избыток: ' ) // Выводим итог в футере для данного столбца ], [ 'attribute' => 'balance', 'label' => 'Разница в сумме', 'format' => 'raw', 'pageSummary' => true, + 'footer' => Html::tag('b', number_format($totalBalance, 2, '.', ' ')), // Показываем итог по балансу ], [ 'attribute' => 'balance_self_cost', @@ -219,7 +224,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO ], ], 'showPageSummary' => true, - 'layout' => '{items}', + 'layout' => '{items}{summary}', ]); if ( -- 2.39.5