foreach ($items as $item) {
$itemCount = abs($item->fact_and_1c_diff);
- $er = EqualizationRemains::findOne([
- 'shift_transfer_id' => $shiftTransfer->id,
- 'product_replacement_id' => $item->product_guid
- ]);
+ $er = EqualizationRemains::find()
+ ->andWhere(['shift_transfer_id' => $shiftTransfer->id])
+ ->andWhere(['product_id' => $item->product_replacement_guid])
+ ->select('SUM(product_replacement_count) as sum')
+ ->scalar();
+
$count = 0;
if ($er) {
- if ($er->product_count == $itemCount) {
+ if ($er == $itemCount) {
continue;
}
- if ($itemCount > $er->product_count) {
- $count = $itemCount - $er->product_count;
+ if ($itemCount > $er) {
+ $count = $itemCount - $er;
}
} else {
foreach ($items as $item) {
$itemCount = abs($item->fact_and_1c_diff);
- $er = EqualizationRemains::findOne([
- 'shift_transfer_id' => $shiftTransfer->id,
- 'product_id' => $item->product_guid
- ]);
-
+ $er = EqualizationRemains::find()
+ ->andWhere(['shift_transfer_id' => $shiftTransfer->id])
+ ->andWhere(['product_id' => $item->product_guid])
+ ->select('SUM(product_replacement_count) as sum')
+ ->scalar();
if ($er) {
- if ($er->product_count == $itemCount) {
+ if ($er == $itemCount) {
continue;
}
- if ($itemCount > $er->product_count) {
- $count = $itemCount - $er->product_count;
+ if ($itemCount > $er) {
+ $count = $itemCount - $er;
}
} else {