<?php
namespace App\Form;
use App\Entity\PromoCode;
use App\Entity\RDV;
use App\Entity\Salon;
use App\Entity\Client;
use App\Entity\Product;
use App\Entity\Intervenant;
use App\Entity\CancelReason;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Security\Core\Security;
class RDVType extends AbstractType
{
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$intervenant =
[
'label' => 'Choisir un intervenant',
'class' => Intervenant::class,
'empty_data' => '',
'attr' => [
'placeholder' => 'Choisir un intervenant',
],
'placeholder' => 'Choisir un intervenant',
'label_attr' => array('class' => ''),
'required' => false
];
if (!$options['edition']) {
$intervenant['query_builder'] = function (EntityRepository $repository) {
$qb = $repository->createQueryBuilder('i');
// the function returns a QueryBuilder object
return $qb
// find all users where 'deleted' is NOT '1'
->where($qb->expr()->eq('i.status', '?1'))
->setParameter('1', '1')
->orderBy('i.lastname', 'ASC');
};
}
$builder
->add('intervenant', EntityType::class, $intervenant);
$array = [
'label' => 'Choisir un produit',
'class' => Product::class,
'query_builder' => function (EntityRepository $er) {
// the function returns a QueryBuilder object
return $er->createQueryBuilder('p')
->where('p.indisponibleVente = :indisponibleVente')
->setParameter('indisponibleVente', 0);
},
'placeholder' => 'Choisir un produit',
'multiple' => true,
'mapped' => false,
'attr' => [
'placeholder' => 'Choisir un produit',
'style' => 'width:100%'
],
'label_attr' => array('class' => ''),
'choice_label' => 'name'
];
if (isset($options['salon'])) {
/** @var Salon $salon */
$salon = $options['salon'];
$array = array_merge($array, [
'query_builder' => function (EntityRepository $er) use ($salon) {
return $er->createQueryBuilder('p')
->where('p.type = :type')
->andWhere('p.indisponibleVente = :indisponibleVente')
->setParameter('indisponibleVente', 0)
->setParameter('type', $salon->getService());
},
]);
}
if (!isset($options['view'])) {
$builder->add('products', EntityType::class, $array);
}
$builder->add('salon', EntityType::class, [
'label' => 'Salon',
'class' => Salon::class,
'attr' => [
'placeholder' => 'Salon',
],
'placeholder' => 'Salon',
'label_attr' => array('class' => ''),
]);
$builder->add('comment', TextareaType::class, [
'label' => 'Remarques sur RDV',
'required' => false
]);
$builder->add('codePromo', EntityType::class, [
'label' => 'Code promo',
'class' => PromoCode::class,
'required' => false,
'attr' => [
'readonly' => !$options['canValidate'],
],
]);
$builder->add('infoCheque', TextType::class, [
'label' => 'Infos chèque',
'required' => false
]);
$builder->add('chequeReception', CheckboxType::class, [
'label' => 'Chèque réceptionné?',
'required' => false,
]);
$builder->add('consignesClient', TextareaType::class, [
'label' => 'Consignes client',
'required' => false,
'mapped' => false,
]);
$builder->add('roomNumber', TextType::class, [
'label' => 'Batiment / Étage / Numéro de chambre',
'attr' => [
'placeholder' => 'Entrer le batiment / étage / numéro de chambre',
],
'required' => false,
'mapped' => false,
]);
$builder->add('client', EntityType::class, [
'label' => 'Choisir un client',
'placeholder' => 'Choisir un client',
'choice_label' => function (Client $client) {
$site = $client->getSite();
$zipcode = '';
if ($site) {
$zipcode = $site->getAddress() ? $site->getAddress()->getZipcode() : '';
}
return $client->getLastname() . ' ' . $client->getFirstname() . ' ' . $zipcode;
},
'class' => Client::class,
'attr' => [
'placeholder' => 'Choisir un client',
],
'label_attr' => array('class' => ''),
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('(c.statusProspect != :status AND c.statusProspect != :statusParti) OR c.statusProspect IS NULL' )
->setParameter('status', Client::STATUS_INACTIF)
->setParameter('statusParti', 'Parti');
},
]);
$builder->add('start', DateTimeType::class, [
'widget' => 'single_text',
'required' => true,
// prevents rendering it as type="date", to avoid HTML5 date pickers
'html5' => false,
'label' => 'Début prestation',
'disabled' => $options['disabled'] ? true : false,
]);
$builder->add('hasAddService', ChoiceType::class, [
'label' => "Si votre parent souhaite un service additionnel à l’ehpad peut-il le commander ?",
'choices' => [
'Ne sait pas' => 'Ne sait pas',
'Oui' => 'Oui',
'Non' => 'Non',
],
'required' => true,
]);
if ($options['withCustomPicker']) {
$builder->remove('start');
$builder->remove('intervenant');
}
if ($options['view'] === 'client') {
$builder->remove('start');
$builder->remove('intervenant');
$builder->remove('salon');
$builder->remove('client');
$builder->add('recurrence', ChoiceType::class, [
'label' => 'Récurrence souhaitée',
'choices' => [
'Hebdomadaire' => 'hebdo',
'Tous les 15 jours' => 'bi mensuelle',
'Tous les mois' => 'mensuelle',
'Tous les 2 mois' => 'bimestriel',
'Trimestrielle' => 'trimestrielle',
'Non, demande ponctuelle' => 'ponctuel',
],
'placeholder' => 'Sélectionner',
'required' => false,
]);
$builder->add('email', EmailType::class, [
'label' => "L’adresse mail de facturation",
'mapped' => false,
'attr' => [
'placeholder' => 'L’adresse mail de facturation',
],
'required' => true,
]);
$builder->add('civilite', ChoiceType::class, [
'label' => 'Civilité bénéficiaire de la prestation',
'mapped' => false,
'attr' => [
'placeholder' => 'Civilité bénéficiaire de la prestation',
],
'required' => true,
'placeholder' => 'Choisir une civilite',
'choices' => [
'Madame' => 'Madame',
'Monsieur' => 'Monsieur',
],
]);
$builder->add('lastname', null, [
'label' => "Nom bénéficiaire de la prestation",
'mapped' => false,
'attr' => [
'placeholder' => 'Nom bénéficiaire de la prestation',
],
'required' => true,
]);
$builder->add('firstname', null, [
'label' => "Prénom bénéficiaire de la prestation",
'mapped' => false,
'attr' => [
'placeholder' => 'Prénom bénéficiaire de la prestation',
],
'required' => true,
]);
}
if (isset($options['edition']) && $options['edition'] === true) {
$builder->add('start', DateTimeType::class, [
'widget' => 'single_text',
// prevents rendering it as type="date", to avoid HTML5 date pickers
'html5' => false,
'label' => 'Début prestation',
'disabled' => $options['disabled'] ? true : false,
]);
$builder->add('end', DateTimeType::class, [
'widget' => 'single_text',
'html5' => false,
'label' => 'Fin prestation',
]);
$builder->add('priorite', ChoiceType::class, [
'label' => 'Priorité',
'choices' => [
'1' => 1,
'2' => 2,
'3' => 3
]
]);
$canValidate = $options['canValidate'];
$choices = [
'Planifié' => RDV::STATUS_PLANIFIER,
'Annulé' => RDV::STATUS_ANNULER,
'Validé' => RDV::STATUS_VALIDATED,
//'Replanifié' => RDV::STATUS_REPLANIFIER,
'Facturé' => RDV::STATUS_FACTURER,
//'Reporté' => RDV::STATUS_REPORTE,
// 'Facture annulé' => RDV::STATUS_FACTURE_ANNULER,
];
/*if ($options['hideFacture']) {
unset($choices['Facturé']);
}*/
$optionsStatus = [
'label' => 'Statut',
'choices' => $choices
];
if ($canValidate === false) {
$optionsStatus = [
'label' => 'Statut',
'choices' => $choices,
'choice_attr' => function ($choice, $key, $value) {
if ($value === 'billing') {
return ['disabled' => 'disabled'];
}
return [];
},
];
}
if($options['canChangeStatus'] === false){
$optionsStatus = [
'label' => 'Statut',
'choices' => $choices,
'choice_attr' => function ($choice, $key, $value) {
return ['disabled' => 'disabled'];
},
];
}
$builder->add('status', ChoiceType::class, $optionsStatus);
$builder->add('author', TextType::class, [
'label' => 'Prise de RDV par',
'disabled' => true,
'attr' => [
'placeholder' => $options['createdFrom'],
],
]);
// $builder ->add('validate', CheckboxType::class, [
// 'label' => 'RDV Valider',
// 'mapped' => false,
// 'required' => false
// ]);
$builder->add('comment', TextareaType::class, [
'label' => 'Remarques sur RDV',
'required' => false
]);
$builder->add('commentForfait', TextareaType::class, [
'label' => 'Remarques forfait',
'required' => false,
'label_attr' => [
'style' => 'display:none',
],
'attr' => [
'style' => 'display:none',
],
]);
$builder->add('cancelReason', EntityType::class, [
'label' => 'Choisir un motif d\'annulation',
'class' => CancelReason::class,
'placeholder' => 'Choisir un motif d\'annulation',
'required' => false,
'attr' => [
'placeholder' => 'Choisir un motif d\'annulation',
],
'label_attr' => array('class' => ''),
]);
$builder->add('recurrence', null, [
'label' => 'Récurrence saisie par le client (espace réservation)',
'disabled' => true,
]);
} else {
// $builder->add('start',HiddenType::class, [
// ]);
$builder->add('end', HiddenType::class, []);
$builder->add('priorite', HiddenType::class, []);
$builder->add('status', HiddenType::class, []);
};
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => RDV::class,
'edition' => false,
'salon' => null,
'canValidate' => false,
'view' => null,
'famille' => null,
'productIds' => null,
'allow_extra_fields' => true,
'createdFrom' => null,
'hideFacture' => false,
'csrf_protection' => true,
'csrf_field_name' => '_token',
// important part; unique key
'csrf_token_id' => 'form_intention',
'withCustomPicker' => false,
'canChangeStatus' => true
]);
}
}