From: fomichev Date: Thu, 19 Dec 2024 08:22:04 +0000 (+0300) Subject: Проверка на товары у списания X-Git-Tag: 1.7~134^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=18ccf4acbe1925459315ac5f966bda63f28cda17;p=erp24_rep%2Fyii-erp24%2F.git Проверка на товары у списания --- 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; } /**