Skip to content

Commit f90d0f3

Browse files
committed
Add 'Add stock' button to part stock info page
1 parent 6330b71 commit f90d0f3

4 files changed

Lines changed: 96 additions & 1 deletion

File tree

config/reference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@
17121712
* length?: scalar|Param|null, // Default: 5
17131713
* width?: scalar|Param|null, // Default: 130
17141714
* height?: scalar|Param|null, // Default: 50
1715-
* font?: scalar|Param|null, // Default: "/home/jan/php/Part-DB-server/vendor/gregwar/captcha-bundle/DependencyInjection/../Generator/Font/captcha.ttf"
1715+
* font?: scalar|Param|null, // Default: "/home/user/documents/Part-DB-server/vendor/gregwar/captcha-bundle/DependencyInjection/../Generator/Font/captcha.ttf"
17161716
* keep_value?: scalar|Param|null, // Default: false
17171717
* charset?: scalar|Param|null, // Default: "abcdefhjkmnprstuvwxyz23456789"
17181718
* as_file?: scalar|Param|null, // Default: false

src/Controller/PartController.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use App\Entity\ProjectSystem\Project;
3737
use App\Exceptions\AttachmentDownloadException;
3838
use App\Form\Part\PartBaseType;
39+
use App\Form\Part\PartLotType;
3940
use App\Services\Attachments\AttachmentSubmitHandler;
4041
use App\Services\Attachments\PartPreviewGenerator;
4142
use App\Services\EntityMergers\Mergers\PartMerger;
@@ -127,6 +128,17 @@ public function show(
127128
$table = null;
128129
}
129130

131+
// Build the add-lot form for the INFO page modal (only when not in time-travel mode)
132+
$addLotForm = null;
133+
if ($timeTravel_timestamp === null && $this->isGranted('edit', $part)) {
134+
$newLot = new PartLot();
135+
$newLot->setPart($part);
136+
$addLotForm = $this->createForm(PartLotType::class, $newLot, [
137+
'measurement_unit' => $part->getPartUnit(),
138+
'action' => $this->generateUrl('part_lot_add', ['id' => $part->getID()]),
139+
]);
140+
}
141+
130142
return $this->render(
131143
'parts/info/show_part_info.html.twig',
132144
[
@@ -139,10 +151,39 @@ public function show(
139151
'comment_params' => $this->partInfoSettings->extractParamsFromNotes ? $parameterExtractor->extractParameters($part->getComment()) : [],
140152
'withdraw_add_helper' => $withdrawAddHelper,
141153
'highlightLotId' => $request->query->getInt('highlightLot', 0),
154+
'add_lot_form' => $addLotForm,
142155
]
143156
);
144157
}
145158

159+
#[Route(path: '/{id}/add_lot', name: 'part_lot_add', methods: ['POST'])]
160+
public function addLot(Part $part, Request $request, EntityManagerInterface $em): Response
161+
{
162+
$this->denyAccessUnlessGranted('edit', $part);
163+
164+
$newLot = new PartLot();
165+
$newLot->setPart($part);
166+
167+
$form = $this->createForm(PartLotType::class, $newLot, [
168+
'measurement_unit' => $part->getPartUnit(),
169+
]);
170+
171+
$form->handleRequest($request);
172+
173+
if ($form->isSubmitted() && $form->isValid()) {
174+
$em->persist($newLot);
175+
$em->flush();
176+
$this->addFlash('success', 'part.edited_flash');
177+
return $this->redirectToRoute('part_info', [
178+
'id' => $part->getID(),
179+
'highlightLot' => $newLot->getID(),
180+
]);
181+
}
182+
183+
$this->addFlash('error', 'part.created_flash.invalid');
184+
return $this->redirectToRoute('part_info', ['id' => $part->getID()]);
185+
}
186+
146187
#[Route(path: '/{id}/edit', name: 'part_edit')]
147188
public function edit(Part $part, Request $request): Response
148189
{
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% if add_lot_form is not null %}
2+
{% form_theme add_lot_form 'form/extended_bootstrap_layout.html.twig' %}
3+
4+
<div class="modal fade" id="add-lot-modal" tabindex="-1" aria-labelledby="add-lot-modal-title" aria-hidden="true">
5+
<div class="modal-dialog modal-lg">
6+
<div class="modal-content">
7+
{{ form_start(add_lot_form) }}
8+
<div class="modal-header">
9+
<h1 class="modal-title fs-5" id="add-lot-modal-title">
10+
<i class="fas fa-plus-square fa-fw"></i>
11+
{% trans %}part_lot.create{% endtrans %}
12+
</h1>
13+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
14+
</div>
15+
<div class="modal-body">
16+
{{ form_row(add_lot_form.description) }}
17+
{{ form_row(add_lot_form.storage_location) }}
18+
{{ form_row(add_lot_form.amount) }}
19+
{{ form_row(add_lot_form.instock_unknown) }}
20+
{{ form_row(add_lot_form.needs_refill) }}
21+
{{ form_row(add_lot_form.expiration_date) }}
22+
23+
<div>
24+
<a class="btn btn-link btn-sm {{ offset_label }}" data-bs-toggle="collapse" href="#add-lot-advanced" role="button" aria-expanded="false" aria-controls="add-lot-advanced">
25+
{% trans %}part_lot.edit.advanced{% endtrans %}
26+
</a>
27+
<div class="collapse" id="add-lot-advanced">
28+
{{ form_row(add_lot_form.comment) }}
29+
{{ form_row(add_lot_form.owner) }}
30+
{{ form_row(add_lot_form.user_barcode) }}
31+
{{ form_row(add_lot_form.last_stocktake_at) }}
32+
</div>
33+
</div>
34+
</div>
35+
<div class="modal-footer">
36+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans %}modal.close{% endtrans %}</button>
37+
<button type="submit" class="btn btn-success">
38+
<i class="fas fa-plus-square fa-fw"></i>
39+
{% trans %}part_lot.create{% endtrans %}
40+
</button>
41+
</div>
42+
{{ form_end(add_lot_form) }}
43+
</div>
44+
</div>
45+
</div>
46+
{% endif %}

templates/parts/info/_part_lots.html.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
{% include "parts/info/_withdraw_modal.html.twig" %}
55
{% include "parts/info/_stocktake_modal.html.twig" %}
6+
{% include "parts/info/_add_lot_modal.html.twig" %}
67

78
<div class="table-responsive">
89
<table class="table table-striped table-hover">
@@ -126,3 +127,10 @@
126127

127128
</table>
128129
</div>
130+
131+
{% if add_lot_form is not null %}
132+
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#add-lot-modal">
133+
<i class="fas fa-plus-square fa-fw"></i>
134+
{% trans %}part_lot.create{% endtrans %}
135+
</button>
136+
{% endif %}

0 commit comments

Comments
 (0)