<?php
namespace App\Form;
use App\Entity\Claim;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Validator\Constraints\File;
class ClaimMFType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('department', null, [
'label' => 'Dienststelle',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('mfType', null, [
'label' => 'Fahrzeug Art',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('mfModel', null, [
'label' => 'Fahrzeug Typ',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('mfPlate', null, [
'label' => 'Kontrollschild',
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('claimDate', null, [
'label' => 'Wann hat sich das Schadenereignis zugetragen?',
'required' => false,
'years' => range(date('Y'), date('Y')-5),
])
->add('claimAddress', AddressBlockType::class, [
'label' => "Unfallstelle",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('claimDescription', null, [
'label' => "Genaue Beschreibung des Unfallhergangs (auch dann, wenn ein Polizeirapport aufgenommen wurde)",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('responsible', ChoiceType::class, [
'label' => 'Eigenverschulden',
'choices' => [
'Unklar' => 0,
'Nein' => 1,
'Ja' => 2,
],
'required' => true,
'placeholder' => false
])
//Angaben zum Schaden
->add('claimDamageCause', null, [
'label' => "Schadenursache",
'required' => false,
])
->add('claimDamage', null, [
'label' => "Schadenart",
'required' => false,
])
->add('damageCosts', NumberType::class, [
'scale' => 2,
'label' => "Schadensumme",
'required' => false,
'html5' => true,
'constraints' => [
new Assert\Range([
'min' => 0,
'max' => 9999999999999.99,
]),
],
])
//Fremde Sachen
->add('foreignDeductible', NumberType::class, [
'scale' => 2,
'label' => "Selbstbehalt",
'required' => false,
'html5' => true,
'constraints' => [
new Assert\Range([
'min' => 0,
'max' => 9999999999999.99,
]),
],
])
->add('foreignDamageCosts', NumberType::class, [
'scale' => 2,
'label' => "Schadensumme",
'required' => false,
'html5' => true,
'constraints' => [
new Assert\Range([
'min' => 0,
'max' => 9999999999999.99,
]),
],
])
//Beteiligte Person
->add('involvedPerson', InvolvedPersonType::class, [
'label' => "Beteiligte Person",
])
->add('driver', NameAddressBlockType::class, [
'label' => "Angaben zum Fahrer",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
])
->add('driverBirthdate', null, [
'label' => "Geburtsdatum des Fahrers",
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
'years' => range(date('Y'), date('Y')-100),
])
->add('mfLicense', MfLicenseType::class, [
'label' => 'Führerausweis',
'required' => true,
])
->add('policeReport', null, [
'label' => "Von welcher polizeistelle wurde ein Rapport aufgenommen?",
'required' => false,
])
->add('persons', CollectionType::class, [
'label' => false,
'entry_type' => PersonType::class,
'entry_options' => [],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__item__',
])
->add('remark', null, [
'label' => "Beschädigte Sachen / Weitere Angaben / Bemerkungen",
'required' => false,
])
->add('name', null, [
'label' => false,
'required' => true,
'constraints' => [
new Assert\NotBlank(),
],
'attr' => [
'placeholder' => 'Name',
],
])
->add('email', EmailType::class, [
'label' => false,
'required' => true,
'constraints' => [
new Assert\NotBlank(),
new Assert\Email(),
],
'attr' => [
'placeholder' => 'Email',
],
])
->add('ccEmail', EmailType::class, [
'label' => false,
'required' => false,
'constraints' => [
new Assert\Email(),
],
'attr' => [
'placeholder' => 'CC Email',
],
])
->add('claimFiles', FileType::class,[
'label' => 'Dateien',
'data_class' => null,
'required' => false,
'multiple' => true,
'mapped' => false,
'constraints' => [
new Assert\All([
new File(['maxSize' => '100m'])
])
]
])
->add('submit', SubmitType::class, [
'label' => 'Senden',
'attr' => [
'class' => 'btn btn-primary',
],
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Claim::class,
]);
}
}