Skip to content

Commit fa7cedd

Browse files
committed
Added Price and Extended price to project bom table.
1 parent 851055b commit fa7cedd

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/DataTables/ProjectBomEntriesDataTable.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Omines\DataTablesBundle\DataTable;
4040
use Omines\DataTablesBundle\DataTableTypeInterface;
4141
use Symfony\Contracts\Translation\TranslatorInterface;
42+
use Brick\Math\BigDecimal;
4243

4344
class ProjectBomEntriesDataTable implements DataTableTypeInterface
4445
{
@@ -179,6 +180,67 @@ public function configure(DataTable $dataTable, array $options): void
179180
return '';
180181
}
181182
])
183+
->add('price', TextColumn::class, [
184+
'label' => 'project.bom.price',
185+
'render' => function ($value, ProjectBOMEntry $context) {
186+
// Let's attempt to get the part, if we don't we will just assume zero
187+
$part = $context->getPart();
188+
$price = BigDecimal::zero();
189+
$pricedetails = null;
190+
$order = null;
191+
// Check if we get a part and get the first order if so
192+
// if not see if there is a non-part price set
193+
if($part) {
194+
$order = $context->getPart()->getOrderdetails()->first();
195+
} else if($context->getPrice() !== null) {
196+
$price = $context->getPrice();
197+
}
198+
199+
// check if there is an order, if so get the first pricedetail of the order
200+
if($order!==null && $order !== false) {
201+
$pricedetails = $order->getPricedetails()->first();
202+
}
203+
204+
// check if there is a pricedetail, if so get the first price
205+
if($pricedetails !== null && $pricedetails !== false) {
206+
$price = $pricedetails->getPrice();
207+
}
208+
209+
// return the price
210+
return htmlspecialchars(number_format($price->toFloat(),2));
211+
},
212+
'visible' => false,
213+
])
214+
->add('ext_price', TextColumn::class, [
215+
'label' => 'project.bom.ext_price',
216+
'render' => function ($value, ProjectBOMEntry $context) {
217+
// Let's attempt to get the part, if we don't we will just assume zero
218+
$part = $context->getPart();
219+
$price = BigDecimal::zero();
220+
$pricedetails = null;
221+
$order = null;
222+
// Check if we get a part and get the first order if so
223+
// if not see if there is a non-part price set
224+
if($part) {
225+
$order = $context->getPart()->getOrderdetails()->first();
226+
} else if($context->getPrice() !== null) {
227+
$price = $context->getPrice();
228+
}
229+
230+
// check if there is an order, if so get the first pricedetail of the order
231+
if($order!==null && $order !== false) {
232+
$pricedetails = $order->getPricedetails()->first();
233+
}
234+
235+
// check if there is a pricedetail, if so get the first price
236+
if($pricedetails !== null && $pricedetails !== false) {
237+
$price = $pricedetails->getPrice();
238+
}
239+
240+
// return the price
241+
return htmlspecialchars(number_format($price->toFloat() * $context->getQuantity(),2));
242+
},
243+
])
182244

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

0 commit comments

Comments
 (0)