Apply the default currency value to pricedetails placeholder.

This commit is contained in:
Jan Böhmer 2019-08-31 13:43:41 +02:00
parent 8153a922f0
commit 42399b5517
3 changed files with 37 additions and 10 deletions

View file

@ -205,6 +205,10 @@ class Orderdetail extends DBElement
return $this->supplier_product_url; return $this->supplier_product_url;
} }
if ($this->supplier === null) {
return "";
}
return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available... return $this->getSupplier()->getAutoProductUrl($this->supplierpartnr); // maybe an automatic url is available...
} }

View file

@ -34,6 +34,7 @@ namespace App\Form\Part;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Supplier; use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail; use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Form\Type\StructuralEntityType; use App\Form\Type\StructuralEntityType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -41,12 +42,18 @@ use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\Extension\Core\Type\UrlType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use function foo\func;
class OrderdetailType extends AbstractType class OrderdetailType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
/** @var Orderdetail $orderdetail */
$orderdetail = $builder->getData();
$builder->add('supplierpartnr', TextType::class, [ $builder->add('supplierpartnr', TextType::class, [
'label' => 'orderdetails.edit.supplierpartnr', 'label' => 'orderdetails.edit.supplierpartnr',
'required' => false, 'required' => false,
@ -70,16 +77,30 @@ class OrderdetailType extends AbstractType
'label' => 'orderdetails.edit.obsolete' 'label' => 'orderdetails.edit.obsolete'
]); ]);
//Attachment section
$builder->add('pricedetails', CollectionType::class, [ //Add pricedetails after we know the data, so we can set the default currency
'entry_type' => PricedetailType::class, $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
'allow_add' => true, 'allow_delete' => true, /** @var Orderdetail $orderdetail */
'label' => false, $orderdetail = $event->getData();
'by_reference' => false,
'entry_options' => [ $dummy_pricedetail = new Pricedetail();
'measurement_unit' => $options['measurement_unit'] if ($orderdetail->getSupplier() !== null) {
] $dummy_pricedetail->setCurrency($orderdetail->getSupplier()->getDefaultCurrency());
]); }
//Attachment section
$event->getForm()->add('pricedetails', CollectionType::class, [
'entry_type' => PricedetailType::class,
'allow_add' => true, 'allow_delete' => true,
'label' => false,
'prototype_data' => $dummy_pricedetail,
'by_reference' => false,
'entry_options' => [
'measurement_unit' => $options['measurement_unit']
]
]);
});
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)

View file

@ -38,6 +38,7 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit; use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Entity\PriceInformations\Orderdetail;
use App\Form\AttachmentFormType; use App\Form\AttachmentFormType;
use App\Form\AttachmentType; use App\Form\AttachmentType;
use App\Form\Type\SIUnitType; use App\Form\Type\SIUnitType;
@ -150,6 +151,7 @@ class PartBaseType extends AbstractType
'allow_add' => true, 'allow_delete' => true, 'allow_add' => true, 'allow_delete' => true,
'label' => false, 'label' => false,
'by_reference' => false, 'by_reference' => false,
'prototype_data' => new Orderdetail(),
'entry_options' => [ 'entry_options' => [
'measurement_unit' => $part->getPartUnit() 'measurement_unit' => $part->getPartUnit()
] ]