|
39 | 39 | use Omines\DataTablesBundle\DataTable; |
40 | 40 | use Omines\DataTablesBundle\DataTableTypeInterface; |
41 | 41 | use Symfony\Contracts\Translation\TranslatorInterface; |
| 42 | +use Brick\Math\BigDecimal; |
42 | 43 |
|
43 | 44 | class ProjectBomEntriesDataTable implements DataTableTypeInterface |
44 | 45 | { |
@@ -179,6 +180,67 @@ public function configure(DataTable $dataTable, array $options): void |
179 | 180 | return ''; |
180 | 181 | } |
181 | 182 | ]) |
| 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 | + ]) |
182 | 244 |
|
183 | 245 | ->add('addedDate', LocaleDateTimeColumn::class, [ |
184 | 246 | 'label' => $this->translator->trans('part.table.addedDate'), |
|
0 commit comments