'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);
->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()
try {
- $model->save();
+ if (!$model->save()) {
+ $isProductsSet = true;
+ }
} catch (\Exception $exception) {
throw new \Exception($exception);
}
}
+ return $isProductsSet;
}
/**