Skip to content

Commit 527c42c

Browse files
committed
Upgraded brick/math to latest version
1 parent 506d5f8 commit 527c42c

11 files changed

Lines changed: 58 additions & 56 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"api-platform/json-api": "^4.0.0",
1818
"api-platform/symfony": "^4.0.0",
1919
"beberlei/doctrineextensions": "^1.2",
20-
"brick/math": "^0.14.8",
20+
"brick/math": "^0.17.0",
2121
"brick/schema": "^0.2.0",
2222
"composer/ca-bundle": "^1.5",
2323
"composer/package-versions-deprecated": "^1.11.99.5",

composer.lock

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DataTables/ProjectBomEntriesDataTable.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use App\Services\Formatters\AmountFormatter;
3838
use App\Services\Formatters\MoneyFormatter;
3939
use App\Services\ProjectSystem\ProjectBuildHelper;
40+
use Brick\Math\BigDecimal;
4041
use Brick\Math\RoundingMode;
4142
use Doctrine\ORM\AbstractQuery;
4243
use Doctrine\ORM\Query;
@@ -93,14 +94,14 @@ public function configure(DataTable $dataTable, array $options): void
9394
return htmlspecialchars($this->amountFormatter->format($context->getQuantity(), $context->getPart()->getPartUnit()));
9495
},
9596
])
96-
->add('partId', TextColumn::class, [
97-
'label' => $this->translator->trans('project.bom.part_id'),
98-
'visible' => true,
99-
'orderField' => 'part.id',
100-
'render' => function ($value, ProjectBOMEntry $context) {
101-
return $context->getPart() instanceof Part ? (string) $context->getPart()->getId() : '';
102-
},
103-
])
97+
->add('partId', TextColumn::class, [
98+
'label' => $this->translator->trans('project.bom.part_id'),
99+
'visible' => true,
100+
'orderField' => 'part.id',
101+
'render' => function ($value, ProjectBOMEntry $context) {
102+
return $context->getPart() instanceof Part ? (string) $context->getPart()->getId() : '';
103+
},
104+
])
104105
->add('name', TextColumn::class, [
105106
'label' => $this->translator->trans('part.table.name'),
106107
'orderField' => 'NATSORT(part.name)',
@@ -161,7 +162,7 @@ public function configure(DataTable $dataTable, array $options): void
161162
'label' => $this->translator->trans('part.table.manufacturingStatus'),
162163
'data' => static fn(ProjectBOMEntry $context): ?ManufacturingStatus => $context->getPart()?->getManufacturingStatus(),
163164
'orderField' => 'part.manufacturing_status',
164-
'class' => ManufacturingStatus::class,
165+
'class' => ManufacturingStatus::class,
165166
'render' => function (?ManufacturingStatus $status, ProjectBOMEntry $context): string {
166167
if ($status === null) {
167168
return '';
@@ -212,7 +213,7 @@ public function configure(DataTable $dataTable, array $options): void
212213
'visible' => false,
213214
'render' => function ($value, ProjectBOMEntry $context) {
214215
$price = $this->projectBuildHelper->getEntryUnitPrice($context);
215-
return $this->moneyFormatter->format($price->toScale(2, RoundingMode::UP)->toFloat(), null, 2, true);
216+
return $this->moneyFormatter->format($price->toScale(2, RoundingMode::Up)->toFloat(), null, 2, true);
216217
},
217218
])
218219
->add('ext_price', TextColumn::class, [
@@ -221,7 +222,8 @@ public function configure(DataTable $dataTable, array $options): void
221222
'render' => function ($value, ProjectBOMEntry $context) {
222223
$price = $this->projectBuildHelper->getEntryUnitPrice($context);
223224
return $this->moneyFormatter->format(
224-
$price->multipliedBy($context->getQuantity())->toScale(2, RoundingMode::UP)->toFloat(),
225+
$price->multipliedBy(BigDecimal::fromFloatShortest($context->getQuantity()))
226+
->toScale(2, RoundingMode::Up)->toFloat(),
225227
null,
226228
2,
227229
true

src/Doctrine/Types/BigDecimalType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?Bi
4444

4545

4646

47-
return BigDecimal::of($value);
47+
return BigDecimal::of(is_float($value) ? BigDecimal::fromFloatShortest($value) : $value);
4848
}
4949

5050
/**

src/Entity/PriceInformations/Currency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function getInverseExchangeRate(): ?BigDecimal
204204
return null;
205205
}
206206

207-
return BigDecimal::one()->dividedBy($tmp, $tmp->getScale(), RoundingMode::HALF_UP);
207+
return BigDecimal::one()->dividedBy($tmp, $tmp->getScale(), RoundingMode::HalfUp);
208208
}
209209

210210
/**

src/Entity/PriceInformations/Pricedetail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ public function getPrice(): BigDecimal
195195
#[SerializedName('price_per_unit')]
196196
public function getPricePerUnit(float|string|BigDecimal $multiplier = 1.0): BigDecimal
197197
{
198-
$tmp = BigDecimal::of($multiplier);
198+
$tmp = is_float($multiplier) ? BigDecimal::fromFloatShortest($multiplier) : BigDecimal::of($multiplier);
199199
$tmp = $tmp->multipliedBy($this->price);
200200

201-
return $tmp->dividedBy($this->price_related_quantity, static::PRICE_PRECISION, RoundingMode::HALF_UP);
201+
return $tmp->dividedBy(BigDecimal::fromFloatShortest($this->price_related_quantity), static::PRICE_PRECISION, RoundingMode::HalfUp);
202202
}
203203

204204
/**
@@ -317,7 +317,7 @@ public function setCurrency(?Currency $currency): self
317317
*/
318318
public function setPrice(BigDecimal $new_price): self
319319
{
320-
$tmp = $new_price->toScale(self::PRICE_PRECISION, RoundingMode::HALF_UP);
320+
$tmp = $new_price->toScale(self::PRICE_PRECISION, RoundingMode::HalfUp);
321321
//Only change the object, if the value changes, so that doctrine does not detect it as changed.
322322
if ((string) $tmp !== (string) $this->price) {
323323
$this->price = $tmp;

src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected function importOrderdetails(array $data): void
286286
//Partkeepr stores the price per item, we need to convert it to the price per packaging unit
287287
$price_per_item = BigDecimal::of($partdistributor['price']);
288288
$packaging_unit = (float) ($partdistributor['packagingUnit'] ?? 1);
289-
$pricedetail->setPrice($price_per_item->multipliedBy($packaging_unit));
289+
$pricedetail->setPrice($price_per_item->multipliedBy(BigDecimal::fromFloatShortest($packaging_unit)));
290290
$pricedetail->setPriceRelatedQuantity($packaging_unit);
291291
//We have to set the minimum discount quantity to the packaging unit (PartKeepr does not know this concept)
292292
//But in Part-DB the minimum discount qty have to be unique across a orderdetail

src/Services/LogSystem/TimeTravel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logE
222222
if (isset($metadata->fieldMappings[$field])) {
223223
//We need to convert the string to a BigDecimal first
224224
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) {
225-
$data = BigDecimal::of($data);
225+
$data = is_float($data) ? BigDecimal::fromFloatShortest($data) : BigDecimal::of($data);
226226
}
227227

228228
if (!$data instanceof \DateTimeInterface

src/Services/Parts/PricedetailHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function calculateAvgPrice(Part $part, ?float $amount = null, ?Currency $
170170
return null;
171171
}
172172

173-
return $avg->dividedBy($count, Pricedetail::PRICE_PRECISION, RoundingMode::HALF_UP);
173+
return $avg->dividedBy($count, Pricedetail::PRICE_PRECISION, RoundingMode::HalfUp);
174174
}
175175

176176
/**
@@ -213,6 +213,6 @@ public function convertMoneyToCurrency(BigDecimal $value, ?Currency $originCurre
213213
$val_target = $val_base->multipliedBy($targetCurrency->getInverseExchangeRate());
214214
}
215215

216-
return $val_target->toScale(Pricedetail::PRICE_PRECISION, RoundingMode::HALF_UP);
216+
return $val_target->toScale(Pricedetail::PRICE_PRECISION, RoundingMode::HalfUp);
217217
}
218218
}

src/Services/ProjectSystem/ProjectBuildHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function calculateTotalBuildPrice(Project $project, int $number_of_builds
190190
continue;
191191
}
192192
$has_price = true;
193-
$total = $total->plus($unit_price->multipliedBy($entry->getQuantity())->multipliedBy($number_of_builds));
193+
$total = $total->plus($unit_price->multipliedBy(BigDecimal::fromFloatShortest($entry->getQuantity()))->multipliedBy($number_of_builds));
194194
}
195195

196196
return $has_price ? $total : null;
@@ -206,7 +206,7 @@ public function calculateUnitBuildPrice(Project $project, int $number_of_builds
206206
if ($total === null) {
207207
return null;
208208
}
209-
return $total->dividedBy($number_of_builds, 10, RoundingMode::HALF_UP);
209+
return $total->dividedBy($number_of_builds, 10, RoundingMode::HalfUp);
210210
}
211211

212212
/**
@@ -215,7 +215,7 @@ public function calculateUnitBuildPrice(Project $project, int $number_of_builds
215215
public function roundedTotalBuildPrice(Project $project, int $number_of_builds = 1, ?Currency $currency = null): ?BigDecimal
216216
{
217217
return $this->calculateTotalBuildPrice($project, $number_of_builds, $currency)
218-
?->toScale(2, RoundingMode::UP);
218+
?->toScale(2, RoundingMode::Up);
219219
}
220220

221221
/**
@@ -224,7 +224,7 @@ public function roundedTotalBuildPrice(Project $project, int $number_of_builds =
224224
public function roundedUnitBuildPrice(Project $project, int $number_of_builds = 1, ?Currency $currency = null): ?BigDecimal
225225
{
226226
return $this->calculateUnitBuildPrice($project, $number_of_builds, $currency)
227-
?->toScale(2, RoundingMode::UP);
227+
?->toScale(2, RoundingMode::Up);
228228
}
229229

230230
/**

0 commit comments

Comments
 (0)