Group by supplier

This commit is contained in:
Dave Branton 2026-05-22 19:13:10 +12:00
parent bd97bf1c97
commit b1390b481a
2 changed files with 65 additions and 3 deletions

View file

@ -139,6 +139,7 @@ class ToolsController extends AbstractController
$combined_bom=[];
$needs_ordering = [];
$can_build = true;
$orders_per_supplier = null;
if ($form->isSubmitted())
{
if ($form->isValid())
@ -165,14 +166,39 @@ class ToolsController extends AbstractController
}
}
}
$orders_per_supplier=[];
foreach($combined_bom as $cb)
{
$total_instock = $cb['part']->getAmountSum();
if ($total_instock < $cb['quantity'])
{
$needs_ordering[] = array('needed'=>($cb['quantity']-$total_instock), 'part'=>$cb['part']);
$can_build = false;
$suppliers = $cb['part']->getOrderDetails();
if ($suppliers && count($suppliers) > 0)
{
$mid = $suppliers[0]->getSupplier()->getID();
$orderable_part=array(
'part'=>$cb['part'],
'pn'=>$suppliers[0]->getSupplierPartNr(),
'needed'=>($cb['quantity']-$total_instock),
'link'=>$suppliers[0]->getSupplierProductURL());
if (array_key_exists($mid, $orders_per_supplier))
{
$orders_per_supplier[$mid]['items'][] = $orderable_part;
}
else
{
$orders_per_supplier[$mid] = array(
'supplier'=>$suppliers[0]->getSupplier()->getName(),
'items'=>array($orderable_part));
}
}
else
{
$needs_ordering[] = array('needed'=>($cb['quantity']-$total_instock), 'part'=>$cb['part']);
}
}
}
}
@ -181,7 +207,8 @@ class ToolsController extends AbstractController
return $this->render('tools/multi_build/multi_build.html.twig', [
'form'=>$form,
'needs_ordering'=>$needs_ordering,
'can_build'=>$can_build
'can_build'=>$can_build,
'orders_per_supplier'=>$orders_per_supplier
]);
}

View file

@ -10,7 +10,7 @@
<div class="alert {% if can_build %}alert-success{% else %}alert-danger{% endif %}" role="alert">
{% if not can_build %}
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i> {% trans %}project.builds.build_not_possible{% endtrans %}</h5>
<h5><i class="fa-solid fa-circle-exclamation fa-fw"></i>Parts needed without supplier.</h5>
<ul>
{% for bom_entry in needs_ordering %}
<li>
@ -22,6 +22,41 @@
{% endif %}
</div>
{% if orders_per_supplier is not null %}
<table class="table table-striped table-hover">
{% for supplier in orders_per_supplier %}
<thead>
<tr>
<th colspan=7>
{% if supplier.supplier is not null %}{{ supplier.supplier }}{% else %}No supplier{% endif %}
</th>
</tr>
<tr>
<th></th>
<th>{% trans %}name.label{% endtrans %}</th>
<th>{% trans %}orderdetails.edit.supplierpartnr{% endtrans %}</th>
<th>{% trans %}description.label{% endtrans %}</th>
<th>Quantity Needed</th>
<th></th>
</tr>
</thead>
{% for item in supplier.items %}
<tr>
<td/>
<td><a href="{{ entity_url(item.part) }}">{{ item.part.name }}</a></td>
<td><a href="{{ item.link }}">{{ item.pn }}</a></td>
<td>{{ item.part.description }}</td>
<td>{{ item.needed }}</td>
<td/>
</tr>
{% endfor %}
{% endfor %}
</table>
{% endif %}
{{ form(form) }}