From 4612ec90abd49276e84e9f49a159cd9279d0d36e Mon Sep 17 00:00:00 2001 From: marina Date: Thu, 19 Dec 2024 11:43:16 +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/records/ReplacementInvoice.php | 7 +++ erp24/records/StoreBalance.php | 67 +++++++++++++++++++++ erp24/records/WaybillIncoming.php | 7 +++ erp24/records/WaybillWriteOffs.php | 7 +++ erp24/views/replacement-invoice/index.php | 6 ++ erp24/views/replacement-invoice/view.php | 13 ++++ erp24/views/shift-transfer/_replacement.php | 4 +- 7 files changed, 109 insertions(+), 2 deletions(-) diff --git a/erp24/records/ReplacementInvoice.php b/erp24/records/ReplacementInvoice.php index 7b5629fe..5e5f78a6 100644 --- a/erp24/records/ReplacementInvoice.php +++ b/erp24/records/ReplacementInvoice.php @@ -111,6 +111,13 @@ class ReplacementInvoice extends \yii\db\ActiveRecord ->asArray() ->one(); + if (!ReplacementInvoiceProducts::find() + ->andWhere(['replacement_invoice_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + if ($summaries) { $model->updateAttributes([ 'quantity' => $summaries['total_product_count'], diff --git a/erp24/records/StoreBalance.php b/erp24/records/StoreBalance.php index 30743061..10f5ef1b 100644 --- a/erp24/records/StoreBalance.php +++ b/erp24/records/StoreBalance.php @@ -79,8 +79,75 @@ class StoreBalance extends \yii\db\ActiveRecord 'type_id' => self::REPLACEMENT_ACTIONS, ]); + $incomingData = WaybillIncomingProducts::find() + ->alias('wip') + ->where(['waybill_incoming_id' => WaybillIncoming::findOne(['shift_transfer_id' => $shiftTransfer->id])->id ?? '']) + ->leftJoin('products_1c AS product', 'product.id = wip.product_id') + ->select([ + 'wip.product_id', + 'product.name AS product_name', + 'wip.product_count', + 'wip.product_price', + 'wip.product_self_cost', + 'wip.summ', + 'wip.summ_self_cost' + ]) + ->asArray() + ->all(); + + + $incoming = new self(); + $incoming->setAttributes([ + 'store_id' => $shiftTransfer->store_guid, + 'shift_transfer_id' => $shiftTransfer->id, + 'date' => $shiftTransfer->date, + 'amount' => WaybillIncoming::find() + ->where(['shift_transfer_id' => $shiftTransfer->id]) + ->select(['summ']) + ->scalar() ?? '', + 'status_id' => self::STATUS_NEW, + 'comment' => $shiftTransfer->comment, + 'json' => json_encode($incomingData, JSON_UNESCAPED_UNICODE), + 'type_id' => self::REPLACEMENT_ACTIONS, + ]); + + $writeOffsData = WaybillWriteOffsProducts::find() + ->alias('wwop') + ->where(['waybill_write_offs_id' => WaybillWriteOffs::findOne(['shift_transfer_id' => $shiftTransfer->id])->id ?? '']) + ->leftJoin('products_1c AS product', 'product.id = wwop.product_id') + ->select([ + 'wwop.product_id', + 'product.name AS product_name', + 'wwop.product_count', + 'wwop.product_price', + 'wwop.product_self_cost', + 'wwop.summ', + 'wwop.summ_self_cost' + ]) + ->asArray() + ->all(); + + + $writeOffs = new self(); + $writeOffs->setAttributes([ + 'store_id' => $shiftTransfer->store_guid, + 'shift_transfer_id' => $shiftTransfer->id, + 'date' => $shiftTransfer->date, + 'amount' => WaybillWriteOffs::find() + ->where(['shift_transfer_id' => $shiftTransfer->id]) + ->select(['summ']) + ->scalar() ?? '', + 'status_id' => self::STATUS_NEW, + 'comment' => $shiftTransfer->comment, + 'json' => json_encode($writeOffsData, JSON_UNESCAPED_UNICODE), + 'type_id' => self::REPLACEMENT_ACTIONS, + ]); + + try { $model->save(); + $incoming->save(); + $writeOffs->save(); } catch (\Exception $exception) { throw new Exception($exception); } diff --git a/erp24/records/WaybillIncoming.php b/erp24/records/WaybillIncoming.php index 3ef5dc50..ffef3e74 100644 --- a/erp24/records/WaybillIncoming.php +++ b/erp24/records/WaybillIncoming.php @@ -138,6 +138,13 @@ class WaybillIncoming extends \yii\db\ActiveRecord WaybillIncomingProducts::setData($model, $shiftTransfer); + if (!WaybillIncomingProducts::find() + ->andWhere(['waybill_incoming_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + $summaries = WaybillIncomingProducts::find() ->andWhere(['waybill_incoming_id' => $model->id]) ->select([ diff --git a/erp24/records/WaybillWriteOffs.php b/erp24/records/WaybillWriteOffs.php index b93fb1d1..00eca977 100644 --- a/erp24/records/WaybillWriteOffs.php +++ b/erp24/records/WaybillWriteOffs.php @@ -134,6 +134,13 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord WaybillWriteOffsProducts::setData($model, $shiftTransfer); + if (!WaybillWriteOffsProducts::find() + ->andWhere(['waybill_write_offs_id' => $model->id]) + ->exists()) { + $model->delete(); + return; + } + $summaries = WaybillWriteOffsProducts::find() ->andWhere(['waybill_write_offs_id' => $model->id]) ->select([ diff --git a/erp24/views/replacement-invoice/index.php b/erp24/views/replacement-invoice/index.php index 74ad3d41..38885ddd 100644 --- a/erp24/views/replacement-invoice/index.php +++ b/erp24/views/replacement-invoice/index.php @@ -33,6 +33,12 @@ $this->params['breadcrumbs'][] = $this->title; } ], 'number', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \yii_app\records\WriteOffsErp::STATUSES[$model->status]; + } + ], 'date', 'created_at', [ diff --git a/erp24/views/replacement-invoice/view.php b/erp24/views/replacement-invoice/view.php index 3a5939da..fea91ded 100644 --- a/erp24/views/replacement-invoice/view.php +++ b/erp24/views/replacement-invoice/view.php @@ -35,10 +35,23 @@ $this->params['breadcrumbs'][] = $this->title; ], 'number', 'number_1c', + [ + 'attribute' => 'status', + 'value' => function ($model) { + return \yii_app\records\WriteOffsErp::STATUSES[$model->status]; + } + ], [ 'attribute' => 'date', 'format' => 'datetime', ], + [ + 'label' => 'Текст ошибки', + 'attribute' => 'error_text', + 'value' => function ($model) { + return $model->status == 8 ? $model->error_text : 'Нет ошибки'; + } + ], 'comment', [ 'attribute' => 'created_at', diff --git a/erp24/views/shift-transfer/_replacement.php b/erp24/views/shift-transfer/_replacement.php index e429a6d3..45839726 100644 --- a/erp24/views/shift-transfer/_replacement.php +++ b/erp24/views/shift-transfer/_replacement.php @@ -320,7 +320,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'label' => 'Сумма', 'attribute' => 'summ', 'pageSummary' => true, - 'footer' => Html::tag('b', 'Недостача: ') . '  ' . $writeOffsBalance + 'footer' => $writeOffsBalance != 0 ? Html::tag('b', 'Недостача: ') . '  ' . $writeOffsBalance : '' ], ], 'showPageSummary' => true, @@ -363,7 +363,7 @@ if (in_array($shiftTransfer->status_id, [ShiftTransfer::STATUS_ID_TRANSFER_ACTIO 'label' => 'Сумма', 'attribute' => 'summ', 'pageSummary' => true, - 'footer' => Html::tag('b', 'Излишек: ') . '  ' . $incomingBalance, + 'footer' => $incomingBalance != 0 ? Html::tag('b', 'Излишек: ') . '  ' . $incomingBalance : '', ], ], 'showPageSummary' => true, -- 2.39.5