Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/DataTables/ProjectBomEntriesDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Omines\DataTablesBundle\DataTable;
use Omines\DataTablesBundle\DataTableTypeInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Brick\Math\BigDecimal;

class ProjectBomEntriesDataTable implements DataTableTypeInterface
{
Expand Down Expand Up @@ -179,6 +180,67 @@ public function configure(DataTable $dataTable, array $options): void
return '';
}
])
->add('price', TextColumn::class, [
'label' => 'project.bom.price',
'render' => function ($value, ProjectBOMEntry $context) {
// Let's attempt to get the part, if we don't we will just assume zero
$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 htmlspecialchars(number_format($price->toFloat(),2));
},
'visible' => false,
])
->add('ext_price', TextColumn::class, [
'label' => 'project.bom.ext_price',
'render' => function ($value, ProjectBOMEntry $context) {
// Let's attempt to get the part, if we don't we will just assume zero
$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 htmlspecialchars(number_format($price->toFloat() * $context->getQuantity(),2));
},
])

->add('addedDate', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.addedDate'),
Expand Down