mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-19 18:01:30 +00:00
Made changes from MayNiklas proposed by jbtronics
This commit is contained in:
parent
fa7cedd2fe
commit
d6cf425ec5
1 changed files with 13 additions and 45 deletions
|
|
@ -32,6 +32,7 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||||
use App\Services\ElementTypeNameGenerator;
|
use App\Services\ElementTypeNameGenerator;
|
||||||
use App\Services\EntityURLGenerator;
|
use App\Services\EntityURLGenerator;
|
||||||
use App\Services\Formatters\AmountFormatter;
|
use App\Services\Formatters\AmountFormatter;
|
||||||
|
use App\Services\Parts\PricedetailHelper;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
|
||||||
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
|
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
|
||||||
|
|
@ -44,7 +45,8 @@ use Brick\Math\BigDecimal;
|
||||||
class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
{
|
{
|
||||||
public function __construct(protected TranslatorInterface $translator, protected PartDataTableHelper $partDataTableHelper,
|
public function __construct(protected TranslatorInterface $translator, protected PartDataTableHelper $partDataTableHelper,
|
||||||
protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter)
|
protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter,
|
||||||
|
protected PricedetailHelper $pricedetailHelper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,28 +185,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
->add('price', TextColumn::class, [
|
->add('price', TextColumn::class, [
|
||||||
'label' => 'project.bom.price',
|
'label' => 'project.bom.price',
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
// Let's attempt to get the part, if we don't we will just assume zero
|
$price = $this->getBomEntryUnitPrice($context);
|
||||||
$part = $context->getPart();
|
|
||||||
$price = BigDecimal::zero();
|
|
||||||
$pricedetails = null;
|
|
||||||
$order = null;
|
|
||||||
// Check if we get a part and get the first order if so
|
|
||||||
// if not see if there is a non-part price set
|
|
||||||
if($part) {
|
|
||||||
$order = $context->getPart()->getOrderdetails()->first();
|
|
||||||
} else if($context->getPrice() !== null) {
|
|
||||||
$price = $context->getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is an order, if so get the first pricedetail of the order
|
|
||||||
if($order!==null && $order !== false) {
|
|
||||||
$pricedetails = $order->getPricedetails()->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is a pricedetail, if so get the first price
|
|
||||||
if($pricedetails !== null && $pricedetails !== false) {
|
|
||||||
$price = $pricedetails->getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the price
|
// return the price
|
||||||
return htmlspecialchars(number_format($price->toFloat(),2));
|
return htmlspecialchars(number_format($price->toFloat(),2));
|
||||||
|
|
@ -214,28 +195,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
->add('ext_price', TextColumn::class, [
|
->add('ext_price', TextColumn::class, [
|
||||||
'label' => 'project.bom.ext_price',
|
'label' => 'project.bom.ext_price',
|
||||||
'render' => function ($value, ProjectBOMEntry $context) {
|
'render' => function ($value, ProjectBOMEntry $context) {
|
||||||
// Let's attempt to get the part, if we don't we will just assume zero
|
$price = $this->getBomEntryUnitPrice($context);
|
||||||
$part = $context->getPart();
|
|
||||||
$price = BigDecimal::zero();
|
|
||||||
$pricedetails = null;
|
|
||||||
$order = null;
|
|
||||||
// Check if we get a part and get the first order if so
|
|
||||||
// if not see if there is a non-part price set
|
|
||||||
if($part) {
|
|
||||||
$order = $context->getPart()->getOrderdetails()->first();
|
|
||||||
} else if($context->getPrice() !== null) {
|
|
||||||
$price = $context->getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is an order, if so get the first pricedetail of the order
|
|
||||||
if($order!==null && $order !== false) {
|
|
||||||
$pricedetails = $order->getPricedetails()->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is a pricedetail, if so get the first price
|
|
||||||
if($pricedetails !== null && $pricedetails !== false) {
|
|
||||||
$price = $pricedetails->getPrice();
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the price
|
// return the price
|
||||||
return htmlspecialchars(number_format($price->toFloat() * $context->getQuantity(),2));
|
return htmlspecialchars(number_format($price->toFloat() * $context->getQuantity(),2));
|
||||||
|
|
@ -267,6 +227,14 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
private function getQuery(QueryBuilder $builder, array $options): void
|
private function getQuery(QueryBuilder $builder, array $options): void
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue