try {
$replacementInvoice = ReplacementInvoice::find()
- ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ'])
+ ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ_self_cost'])
->andWhere(['status' => WriteOffsErp::STATUS_CONFIRM])
->indexBy('id')
->asArray()
$shiftTransferIds = array_column($replacementInvoice, 'shift_transfer_id');
$products = EqualizationRemains::find()
- ->where(['in', 'shift_transfer_id', $shiftTransferIds])
+ ->alias('er')
+ ->select([
+ 're.id as replacement_invoice_id',
+ 'er.product_id as product_id',
+ 'er.product_replacement_id as new_product_id',
+ 'er.product_replacement_count as quantity',
+ 'er.product_self_cost as price',
+ 'er.product_replacement_self_cost as new_price'])
+ ->where(['in', 'er.shift_transfer_id', $shiftTransferIds])
+ ->leftJoin('replacement_invoice re', 're.shift_transfer_id = er.shift_transfer_id')
->asArray()
->all();
$replacementInvoiceProducts = [];
foreach ($products as $product) {
- $replacementInvoiceProducts[$product['']][] = [
- 'product_id' => $product->product_id,
+ $replacementInvoiceProducts[$product['replacement_invoice_id']][] = [
+ 'product_id' => $product['product_id'],
'color' => Products1cAdditionalCharacteristics::findOne([
'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
- 'product_id' => $product->product_id])->value ?? '',
- 'price' => $product->product_price,
- 'new_product_id' => $product->product_replacement_id,
+ 'product_id' => $product['product_id']])->value ?? '',
+ 'price' => $product['price'],
+ 'new_product_id' => $product['new_product_id'],
'new_color' => Products1cAdditionalCharacteristics::findOne([
'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
- 'product_id' => $product->product_replacement_id])->value ?? '',
- 'new_price' => $product->product_replacement_price,
- 'quantity' => $product->product_replacement_count,
+ 'product_id' => $product['new_product_id']])->value ?? '',
+ 'new_price' => $product['new_price'],
+ 'quantity' => $product['quantity'],
];
}
$replacementInvoiceResult[] = [
'id' => $row['guid'],
'store_id' => $row['store_guid'],
- 'type' => 'ревизия при передаче смены',
- 'cause' => 'Документ пересортицы при передаче смены в ERP ' . $row['number'],
- 'items' => $row['items'],
- 'summ' => $row['summ'],
+ 'type' => 'ревизия пересортица при передаче смены',
+ 'cause' => 'Документ пересортица при передаче смены в ERP ' . $row['number'],
'comment' => $row['comment'],
+ 'items' => $row['items'],
+
];
}
}
-
} catch (Exception $e3) {
file_put_contents(self::OUT_DIR . '/log_created_replacement_invoice_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND);
}
-
return compact('replacementInvoice', 'replacementInvoicesIds', 'replacementInvoiceResult');
}
ShiftRemains::updateAll(['type' => ShiftRemains::ARCHIVE_RECORD], ['shift_transfer_id' => $id]);
ReplacementInvoice::setData($model);
StoreBalance::setData($model);
- } elseif ($action === 'save') {
- $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]);
WaybillIncoming::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
WaybillWriteOffs::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
ReplacementInvoice::updateAll(['status' => WriteOffsErp::STATUS_CONFIRM], ['shift_transfer_id' => $id]);
+ } elseif ($action === 'save') {
+ $model->updateAttributes(['status_id' => ShiftTransfer::STATUS_ID_READY_TO_ACCEPT]);
} elseif ($action == 'recalculate') {
EqualizationRemains::setData($model);
Yii::$app->session->setFlash('success', 'Таблица замен успешно перерасчитана');