From 18ccf4acbe1925459315ac5f966bda63f28cda17 Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 19 Dec 2024 11:22:04 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D0=BD=D0=B0=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D1=8B=20=D1=83?= =?utf8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/records/WaybillWriteOffs.php | 38 ++++++++++++---------- erp24/records/WaybillWriteOffsProducts.php | 7 ++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/erp24/records/WaybillWriteOffs.php b/erp24/records/WaybillWriteOffs.php index b93fb1d1..aa76001e 100644 --- a/erp24/records/WaybillWriteOffs.php +++ b/erp24/records/WaybillWriteOffs.php @@ -132,24 +132,26 @@ class WaybillWriteOffs extends \yii\db\ActiveRecord 'number' => 'ЕРП_РНС_' . date("Y-m-d_H-i") . '_' . $model->id ]); - WaybillWriteOffsProducts::setData($model, $shiftTransfer); - - $summaries = WaybillWriteOffsProducts::find() - ->andWhere(['waybill_write_offs_id' => $model->id]) - ->select([ - 'total_product_count' => 'sum(product_count)', - 'total_summ' => 'sum(summ)', - 'total_summ_self_cost' => 'sum(summ_self_cost)' - ]) - ->asArray() - ->one(); - - if ($summaries) { - $model->updateAttributes([ - 'quantity' => $summaries['total_product_count'], - 'summ' => $summaries['total_summ'], - 'summ_self_cost' => $summaries['total_summ_self_cost'] - ]); + if (!WaybillWriteOffsProducts::setData($model, $shiftTransfer)) { + $model->delete(); + } else { + $summaries = WaybillWriteOffsProducts::find() + ->andWhere(['waybill_write_offs_id' => $model->id]) + ->select([ + 'total_product_count' => 'sum(product_count)', + 'total_summ' => 'sum(summ)', + 'total_summ_self_cost' => 'sum(summ_self_cost)' + ]) + ->asArray() + ->one(); + + if ($summaries) { + $model->updateAttributes([ + 'quantity' => $summaries['total_product_count'], + 'summ' => $summaries['total_summ'], + 'summ_self_cost' => $summaries['total_summ_self_cost'] + ]); + } } } catch (\Exception $exception) { throw new \Exception($exception); diff --git a/erp24/records/WaybillWriteOffsProducts.php b/erp24/records/WaybillWriteOffsProducts.php index 8837719b..9c1563fc 100644 --- a/erp24/records/WaybillWriteOffsProducts.php +++ b/erp24/records/WaybillWriteOffsProducts.php @@ -69,7 +69,7 @@ class WaybillWriteOffsProducts extends \yii\db\ActiveRecord ->andWhere(['shift_transfer_id' => $shiftTransfer->id]) ->andWhere(['<', 'fact_and_1c_diff', 0]) ->all(); - + $isProductsSet = false; foreach ($items as $item) { $itemCount = abs($item->fact_and_1c_diff); $er = EqualizationRemains::find() @@ -108,11 +108,14 @@ class WaybillWriteOffsProducts extends \yii\db\ActiveRecord try { - $model->save(); + if (!$model->save()) { + $isProductsSet = true; + } } catch (\Exception $exception) { throw new \Exception($exception); } } + return $isProductsSet; } /** -- 2.39.5