fixed kilo in metals 4
This commit is contained in:
@@ -355,23 +355,61 @@ class BalanceReportService
|
||||
return null;
|
||||
}
|
||||
|
||||
public function enrichOrderTableRow(mixed &$row): void
|
||||
public function resolveOrderMetalId(mixed $order): int
|
||||
{
|
||||
$product = $this->resolveOrderProduct($order);
|
||||
if ($product !== null) {
|
||||
$metalId = (int) ($product->metal_id ?? 0);
|
||||
|
||||
return $metalId > 0 ? $metalId : 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $catalogMetalIds
|
||||
*/
|
||||
public function enrichOrderTableRow(mixed &$row, array $catalogMetalIds = []): void
|
||||
{
|
||||
$product = $this->resolveOrderProduct($row);
|
||||
$unit = $this->resolveOrderAmountUnit($product);
|
||||
$amount = (float) ($this->lineValue($row, 'amount') ?? 0);
|
||||
$displayAmount = $this->resolveOrderDisplayAmount($amount, $product);
|
||||
$metalId = $this->resolveOrderMetalId($row);
|
||||
$metalLabel = $this->metalLabel($metalId);
|
||||
$price = (float) ($this->lineValue($row, 'price') ?? 0);
|
||||
|
||||
$metalPrices = [];
|
||||
foreach ($catalogMetalIds as $mid) {
|
||||
$mid = (int) $mid;
|
||||
$metalPrices[(string) $mid] = $mid === $metalId ? $price : 0.0;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'amount_unit' => $unit,
|
||||
'amount_display' => $displayAmount,
|
||||
'order_metal_id' => $metalId,
|
||||
'order_metal_label' => $metalLabel,
|
||||
'metal_prices' => $metalPrices,
|
||||
];
|
||||
|
||||
foreach ($catalogMetalIds as $mid) {
|
||||
$payload['metal_price_' . (int) $mid] = $metalPrices[(string) (int) $mid] ?? 0.0;
|
||||
}
|
||||
|
||||
if (is_array($row)) {
|
||||
$row['amount_unit'] = $unit;
|
||||
$row['amount_display'] = $displayAmount;
|
||||
foreach ($payload as $key => $value) {
|
||||
$row[$key] = $value;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_object($row)) {
|
||||
$row->amount_unit = $unit;
|
||||
$row->amount_display = $displayAmount;
|
||||
foreach ($payload as $key => $value) {
|
||||
$row->{$key} = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user