From d1deabca20b11fd33e454a167765e1712d494290 Mon Sep 17 00:00:00 2001 From: marina Date: Wed, 18 Dec 2024 13:03:55 +0300 Subject: [PATCH] =?utf8?q?ERP-256=20=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?utf8?q?=D1=8C=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D1=83=20?= =?utf8?q?=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20?= =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=86?= =?utf8?q?=D0=B0=20=D0=B2=201=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 39 +++++++++++-------- erp24/controllers/ShiftTransferController.php | 4 +- erp24/records/ReplacementInvoice.php | 10 ++--- erp24/views/replacement-invoice/view.php | 3 -- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 5428a424..34563df8 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -459,7 +459,7 @@ class DataController extends BaseController try { $replacementInvoice = ReplacementInvoice::find() - ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ']) + ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ_self_cost']) ->andWhere(['status' => WriteOffsErp::STATUS_CONFIRM]) ->indexBy('id') ->asArray() @@ -470,25 +470,34 @@ class DataController extends BaseController $shiftTransferIds = array_column($replacementInvoice, 'shift_transfer_id'); $products = EqualizationRemains::find() - ->where(['in', 'shift_transfer_id', $shiftTransferIds]) + ->alias('er') + ->select([ + 're.id as replacement_invoice_id', + 'er.product_id as product_id', + 'er.product_replacement_id as new_product_id', + 'er.product_replacement_count as quantity', + 'er.product_self_cost as price', + 'er.product_replacement_self_cost as new_price']) + ->where(['in', 'er.shift_transfer_id', $shiftTransferIds]) + ->leftJoin('replacement_invoice re', 're.shift_transfer_id = er.shift_transfer_id') ->asArray() ->all(); $replacementInvoiceProducts = []; foreach ($products as $product) { - $replacementInvoiceProducts[$product['']][] = [ - 'product_id' => $product->product_id, + $replacementInvoiceProducts[$product['replacement_invoice_id']][] = [ + 'product_id' => $product['product_id'], 'color' => Products1cAdditionalCharacteristics::findOne([ 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573', - 'product_id' => $product->product_id])->value ?? '', - 'price' => $product->product_price, - 'new_product_id' => $product->product_replacement_id, + 'product_id' => $product['product_id']])->value ?? '', + 'price' => $product['price'], + 'new_product_id' => $product['new_product_id'], 'new_color' => Products1cAdditionalCharacteristics::findOne([ 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573', - 'product_id' => $product->product_replacement_id])->value ?? '', - 'new_price' => $product->product_replacement_price, - 'quantity' => $product->product_replacement_count, + 'product_id' => $product['new_product_id']])->value ?? '', + 'new_price' => $product['new_price'], + 'quantity' => $product['quantity'], ]; } @@ -510,19 +519,17 @@ class DataController extends BaseController $replacementInvoiceResult[] = [ 'id' => $row['guid'], 'store_id' => $row['store_guid'], - 'type' => 'ревизия при передаче смены', - 'cause' => 'Документ пересортицы при передаче смены в ERP ' . $row['number'], - 'items' => $row['items'], - 'summ' => $row['summ'], + 'type' => 'ревизия пересортица при передаче смены', + 'cause' => 'Документ пересортица при передаче смены в ERP ' . $row['number'], 'comment' => $row['comment'], + 'items' => $row['items'], + ]; } } - } catch (Exception $e3) { file_put_contents(self::OUT_DIR . '/log_created_replacement_invoice_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND); } - return compact('replacementInvoice', 'replacementInvoicesIds', 'replacementInvoiceResult'); } diff --git a/erp24/controllers/ShiftTransferController.php b/erp24/controllers/ShiftTransferController.php index 63e7333f..faecd631 100644 --- a/erp24/controllers/ShiftTransferController.php +++ b/erp24/controllers/ShiftTransferController.php @@ -298,11 +298,11 @@ class ShiftTransferController extends Controller ShiftRemains::updateAll(['type' => ShiftRemains::ARCHIVE_RECORD], ['shift_transfer_id' => $id]); ReplacementInvoice::setData($model); StoreBalance::setData($model); - } elseif ($action === 'save') { - $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]); WaybillIncoming::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]); WaybillWriteOffs::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]); ReplacementInvoice::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]); + } elseif ($action === 'save') { + $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]); } elseif ($action == 'recalculate') { EqualizationRemains::setData($model); Yii::$app->session->setFlash('success', 'Таблица замен успешно перерасчитана'); diff --git a/erp24/records/ReplacementInvoice.php b/erp24/records/ReplacementInvoice.php index 7510c55e..6db5c212 100644 --- a/erp24/records/ReplacementInvoice.php +++ b/erp24/records/ReplacementInvoice.php @@ -100,12 +100,12 @@ class ReplacementInvoice extends \yii\db\ActiveRecord ReplacementInvoiceProducts::setData($model, $shiftTransfer); - $summaries = ReplacementInvoiceProducts::find() - ->andWhere(['replacement_invoice_id' => $model->id]) + $summaries = EqualizationRemains::find() + ->andWhere(['shift_transfer_id' => $model->shift_transfer_id]) ->select([ - 'total_product_count' => 'sum(product_count)', - 'total_summ' => 'sum(summ)', - 'total_summ_self_cost' => 'sum(summ_self_cost)' + 'total_product_count' => 'sum(product_replacement_count)', + 'total_summ' => 'sum(balance)', + 'total_summ_self_cost' => 'sum(balance_self_cost)' ]) ->asArray() ->one(); diff --git a/erp24/views/replacement-invoice/view.php b/erp24/views/replacement-invoice/view.php index 66c786fb..3a5939da 100644 --- a/erp24/views/replacement-invoice/view.php +++ b/erp24/views/replacement-invoice/view.php @@ -25,9 +25,6 @@ $this->params['breadcrumbs'][] = $this->title; [ 'format' => 'raw', 'attribute' => 'status', - 'value' => function ($model) { - return $model->status == \yii_app\records\ReplacementInvoice::REPLACEMENT_ACTIONS ? 'Действия по замене' : $model->status; - } ], [ 'format' => 'raw', -- 2.39.5