From 96a771e7aca8eb9526ce6c2628fd8db586963615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Fri, 17 Nov 2023 23:05:47 +0100 Subject: [PATCH] Allow to edit the vendor_barcode field of a PartLot --- src/Entity/Parts/PartLot.php | 26 +++++++++++++++++++ src/Form/Part/PartLotType.php | 8 +++++- .../parts/edit/edit_form_styles.html.twig | 18 ++++++++++++- translations/messages.en.xlf | 18 +++++++++++++ translations/validators.en.xlf | 6 +++++ 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index fe683499..960183ba 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -47,6 +47,7 @@ use App\Validator\Constraints\ValidPartLot; use DateTime; use Doctrine\ORM\Mapping as ORM; use Exception; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -64,6 +65,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Index(columns: ['needs_refill'], name: 'part_lots_idx_needs_refill')] #[ORM\Index(columns: ['vendor_barcode'], name: 'part_lots_idx_barcode')] #[ValidPartLot] +#[UniqueEntity(['vendor_barcode'], message: 'validator.part_lot.vendor_barcode_must_be_unique')] #[ApiResource( operations: [ new Get(security: 'is_granted("read", object)'), @@ -159,6 +161,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named * @var string|null The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor) */ #[ORM\Column(type: Types::STRING, nullable: true)] + #[Groups(['part_lot:read', 'part_lot:write'])] protected ?string $vendor_barcode = null; public function __clone() @@ -361,6 +364,29 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named return $this->description; } + /** + * The content of the barcode of this part lot (e.g. a barcode on the package put by the vendor), or + * null if no barcode is set. + * @return string|null + */ + public function getVendorBarcode(): ?string + { + return $this->vendor_barcode; + } + + /** + * Set the content of the barcode of this part lot (e.g. a barcode on the package put by the vendor). + * @param string|null $vendor_barcode + * @return $this + */ + public function setVendorBarcode(?string $vendor_barcode): PartLot + { + $this->vendor_barcode = $vendor_barcode; + return $this; + } + + + #[Assert\Callback] public function validate(ExecutionContextInterface $context, $payload): void { diff --git a/src/Form/Part/PartLotType.php b/src/Form/Part/PartLotType.php index ed730cbf..da061c7f 100644 --- a/src/Form/Part/PartLotType.php +++ b/src/Form/Part/PartLotType.php @@ -80,7 +80,7 @@ class PartLotType extends AbstractType 'required' => false, ]); - $builder->add('expirationDate', DateType::class, [ + $builder->add('expiration_date', DateType::class, [ 'label' => 'part_lot.edit.expiration_date', 'attr' => [], 'widget' => 'single_text', @@ -102,6 +102,12 @@ class PartLotType extends AbstractType 'required' => false, 'help' => 'part_lot.owner.help', ]); + + $builder->add('vendor_barcode', TextType::class, [ + 'label' => 'part_lot.edit.vendor_barcode', + 'help' => 'part_lot.edit.vendor_barcode.help', + 'required' => false, + ]); } public function configureOptions(OptionsResolver $resolver): void diff --git a/templates/parts/edit/edit_form_styles.html.twig b/templates/parts/edit/edit_form_styles.html.twig index 2d60afa8..4e68ae5f 100644 --- a/templates/parts/edit/edit_form_styles.html.twig +++ b/templates/parts/edit/edit_form_styles.html.twig @@ -89,7 +89,23 @@ {% import 'components/collection_type.macro.html.twig' as collection %} - {{ form_widget(form) }} + {{ form_row(form.description) }} + {{ form_row(form.storage_location) }} + {{ form_row(form.amount) }} + {{ form_row(form.instock_unknown) }} + {{ form_row(form.needs_refill) }} + {{ form_row(form.expiration_date) }} + + {% set id = 'collapse_' ~ random() %} + + +
+ {{ form_row(form.comment) }} + {{ form_row(form.owner) }} + {{ form_row(form.vendor_barcode) }} +