mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-06-13 14:11:37 +00:00
Upgraded brick/math to latest version
This commit is contained in:
parent
506d5f8173
commit
527c42c227
11 changed files with 58 additions and 56 deletions
|
|
@ -286,7 +286,7 @@ class PKPartImporter
|
|||
//Partkeepr stores the price per item, we need to convert it to the price per packaging unit
|
||||
$price_per_item = BigDecimal::of($partdistributor['price']);
|
||||
$packaging_unit = (float) ($partdistributor['packagingUnit'] ?? 1);
|
||||
$pricedetail->setPrice($price_per_item->multipliedBy($packaging_unit));
|
||||
$pricedetail->setPrice($price_per_item->multipliedBy(BigDecimal::fromFloatShortest($packaging_unit)));
|
||||
$pricedetail->setPriceRelatedQuantity($packaging_unit);
|
||||
//We have to set the minimum discount quantity to the packaging unit (PartKeepr does not know this concept)
|
||||
//But in Part-DB the minimum discount qty have to be unique across a orderdetail
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ class TimeTravel
|
|||
if (isset($metadata->fieldMappings[$field])) {
|
||||
//We need to convert the string to a BigDecimal first
|
||||
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) {
|
||||
$data = BigDecimal::of($data);
|
||||
$data = is_float($data) ? BigDecimal::fromFloatShortest($data) : BigDecimal::of($data);
|
||||
}
|
||||
|
||||
if (!$data instanceof \DateTimeInterface
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ class PricedetailHelper
|
|||
return null;
|
||||
}
|
||||
|
||||
return $avg->dividedBy($count, Pricedetail::PRICE_PRECISION, RoundingMode::HALF_UP);
|
||||
return $avg->dividedBy($count, Pricedetail::PRICE_PRECISION, RoundingMode::HalfUp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,6 +213,6 @@ class PricedetailHelper
|
|||
$val_target = $val_base->multipliedBy($targetCurrency->getInverseExchangeRate());
|
||||
}
|
||||
|
||||
return $val_target->toScale(Pricedetail::PRICE_PRECISION, RoundingMode::HALF_UP);
|
||||
return $val_target->toScale(Pricedetail::PRICE_PRECISION, RoundingMode::HalfUp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ final readonly class ProjectBuildHelper
|
|||
continue;
|
||||
}
|
||||
$has_price = true;
|
||||
$total = $total->plus($unit_price->multipliedBy($entry->getQuantity())->multipliedBy($number_of_builds));
|
||||
$total = $total->plus($unit_price->multipliedBy(BigDecimal::fromFloatShortest($entry->getQuantity()))->multipliedBy($number_of_builds));
|
||||
}
|
||||
|
||||
return $has_price ? $total : null;
|
||||
|
|
@ -206,7 +206,7 @@ final readonly class ProjectBuildHelper
|
|||
if ($total === null) {
|
||||
return null;
|
||||
}
|
||||
return $total->dividedBy($number_of_builds, 10, RoundingMode::HALF_UP);
|
||||
return $total->dividedBy($number_of_builds, 10, RoundingMode::HalfUp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -215,7 +215,7 @@ final readonly class ProjectBuildHelper
|
|||
public function roundedTotalBuildPrice(Project $project, int $number_of_builds = 1, ?Currency $currency = null): ?BigDecimal
|
||||
{
|
||||
return $this->calculateTotalBuildPrice($project, $number_of_builds, $currency)
|
||||
?->toScale(2, RoundingMode::UP);
|
||||
?->toScale(2, RoundingMode::Up);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -224,7 +224,7 @@ final readonly class ProjectBuildHelper
|
|||
public function roundedUnitBuildPrice(Project $project, int $number_of_builds = 1, ?Currency $currency = null): ?BigDecimal
|
||||
{
|
||||
return $this->calculateUnitBuildPrice($project, $number_of_builds, $currency)
|
||||
?->toScale(2, RoundingMode::UP);
|
||||
?->toScale(2, RoundingMode::Up);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -44,15 +44,15 @@ class ExchangeRateUpdater
|
|||
try {
|
||||
//Try it in the direction QUOTE/BASE first, as most providers provide rates in this direction
|
||||
$rate = $this->swap->latest($currency->getIsoCode().'/'.$this->localizationSettings->baseCurrency);
|
||||
$effective_rate = BigDecimal::of($rate->getValue());
|
||||
$effective_rate = BigDecimal::fromFloatShortest($rate->getValue());
|
||||
} catch (UnsupportedCurrencyPairException|UnsupportedExchangeQueryException $exception) {
|
||||
//Otherwise try to get it inverse and calculate it ourselfes, from the format "BASE/QUOTE"
|
||||
$rate = $this->swap->latest($this->localizationSettings->baseCurrency.'/'.$currency->getIsoCode());
|
||||
//The rate says how many quote units are worth one base unit
|
||||
//So we need to invert it to get the exchange rate
|
||||
|
||||
$rate_bd = BigDecimal::of($rate->getValue());
|
||||
$effective_rate = BigDecimal::one()->dividedBy($rate_bd, Currency::PRICE_SCALE, RoundingMode::HALF_UP);
|
||||
$rate_bd = BigDecimal::fromFloatShortest($rate->getValue());
|
||||
$effective_rate = BigDecimal::one()->dividedBy($rate_bd, Currency::PRICE_SCALE, RoundingMode::HalfUp);
|
||||
}
|
||||
|
||||
$currency->setExchangeRate($effective_rate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue