-
-
Notifications
You must be signed in to change notification settings - Fork 191
Add Price and Extended price to Project Bom #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,18 +32,21 @@ | |||||||||||||||||||||||||||||
| use App\Services\ElementTypeNameGenerator; | ||||||||||||||||||||||||||||||
| use App\Services\EntityURLGenerator; | ||||||||||||||||||||||||||||||
| use App\Services\Formatters\AmountFormatter; | ||||||||||||||||||||||||||||||
| use App\Services\Parts\PricedetailHelper; | ||||||||||||||||||||||||||||||
| use Doctrine\ORM\QueryBuilder; | ||||||||||||||||||||||||||||||
| use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider; | ||||||||||||||||||||||||||||||
| use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter; | ||||||||||||||||||||||||||||||
| use Omines\DataTablesBundle\Column\TextColumn; | ||||||||||||||||||||||||||||||
| use Omines\DataTablesBundle\DataTable; | ||||||||||||||||||||||||||||||
| use Omines\DataTablesBundle\DataTableTypeInterface; | ||||||||||||||||||||||||||||||
| use Symfony\Contracts\Translation\TranslatorInterface; | ||||||||||||||||||||||||||||||
| use Brick\Math\BigDecimal; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| class ProjectBomEntriesDataTable implements DataTableTypeInterface | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| public function __construct(protected TranslatorInterface $translator, protected PartDataTableHelper $partDataTableHelper, | ||||||||||||||||||||||||||||||
| protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter) | ||||||||||||||||||||||||||||||
| protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter, | ||||||||||||||||||||||||||||||
| protected PricedetailHelper $pricedetailHelper) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -179,6 +182,25 @@ public function configure(DataTable $dataTable, array $options): void | |||||||||||||||||||||||||||||
| return ''; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||
| ->add('price', TextColumn::class, [ | ||||||||||||||||||||||||||||||
| 'label' => 'project.bom.price', | ||||||||||||||||||||||||||||||
| 'render' => function ($value, ProjectBOMEntry $context) { | ||||||||||||||||||||||||||||||
| $price = $this->getBomEntryUnitPrice($context); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // return the price | ||||||||||||||||||||||||||||||
| return htmlspecialchars(number_format($price->toFloat(),2)); | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| 'visible' => false, | ||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||
| ->add('ext_price', TextColumn::class, [ | ||||||||||||||||||||||||||||||
| 'label' => 'project.bom.ext_price', | ||||||||||||||||||||||||||||||
| 'render' => function ($value, ProjectBOMEntry $context) { | ||||||||||||||||||||||||||||||
| $price = $this->getBomEntryUnitPrice($context); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // return the price | ||||||||||||||||||||||||||||||
| return htmlspecialchars(number_format($price->toFloat() * $context->getQuantity(),2)); | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
|
Comment on lines
+201
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ->add('addedDate', LocaleDateTimeColumn::class, [ | ||||||||||||||||||||||||||||||
| 'label' => $this->translator->trans('part.table.addedDate'), | ||||||||||||||||||||||||||||||
|
|
@@ -205,6 +227,14 @@ function (QueryBuilder $builder) use ($options): void { | |||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| private function getBomEntryUnitPrice(ProjectBOMEntry $entry): BigDecimal | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| if ($entry->getPart() instanceof Part) { | ||||||||||||||||||||||||||||||
| return $this->pricedetailHelper->calculateAvgPrice($entry->getPart(), $entry->getQuantity()) ?? BigDecimal::zero(); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| return $entry->getPrice() ?? BigDecimal::zero(); | ||||||||||||||||||||||||||||||
|
Comment on lines
+232
to
+236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We previously not correctly handled cases with amount < minimum order amount.
Suggested change
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just forgot to add roundUpDisplayedPrice
Suggested change
|
||||||||||||||||||||||||||||||
| private function getQuery(QueryBuilder $builder, array $options): void | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rounding prices up to the full cent?
This might be especially helpful for very cheap parts:
Currently resistors / caps might be shown as 0,00€, even while not being free.