<?php
namespace App\Form;
use App\Entity\Client;
use App\Entity\Piece;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
class PieceSearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$responsable=$options['responsable'];
$piece=new Piece();
if($responsable->isSuperAdmin()) {
$builder->add('user', EntityType::class, [
'class' => User::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('r')
->orderBy('r.firstName', 'ASC')
->orderBy('r.lastName', 'ASC');
},
'choice_label' => 'nomComplet',
'placeholder' => 'Collaborateur',
'label' => 'Collaborateur',
'required' => false
]);
}
$builder
->add('code', TextType::class, [
"label" => "Code",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Code']
])
->add('client', EntityType::class, [
'class' => Client::class,
'query_builder' => function (EntityRepository $er)use($responsable) {
if($responsable->isSuperAdmin()) {
return $er->createQueryBuilder('r')
->orderBy('r.firstName', 'ASC')
->addOrderBy('r.lastName', 'ASC');
}else{
return $er->createQueryBuilder('r')
->andWhere('r.user = :user')
->setParameter('user',$responsable)
->orderBy('r.firstName', 'ASC')
->addOrderBy('r.lastName', 'ASC');
}
},
'choice_label' => 'nomComplet',
'placeholder' => 'Client',
'label' => 'Client',
'required' => false,
])
->add('client', EntityType::class, [
'class' => Client::class,
'query_builder' => function (EntityRepository $er)use($responsable) {
if($responsable->isSuperAdmin()) {
return $er->createQueryBuilder('r')
->orderBy('r.firstName', 'ASC')
->addOrderBy('r.lastName', 'ASC');
}else{
return $er->createQueryBuilder('r')
->andWhere('r.user = :user')
->setParameter('user',$responsable)
->orderBy('r.firstName', 'ASC')
->addOrderBy('r.lastName', 'ASC');
}
},
'choice_label' => 'nomComplet',
'placeholder' => 'Client',
'label' => 'Client',
'required' => false,
])
->add('dateDu', DateType::class, [
"label" => "Date Du",
"required" => false,
'empty_data'=>'',
'widget' => 'single_text',
'attr' => [
'autocomplete' => 'off',
'placeholder' => "jj/mm/aaaa",
]
])
->add('dateAu', DateType::class, [
"label" => "Date Au",
"required" => false,
'empty_data'=>'',
'widget' => 'single_text',
'attr' => [
'autocomplete' => 'off',
'placeholder' => "jj/mm/aaaa",
]
])
->add('amountHTMin', TextType::class, [
"label" => "Montant HT min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant HT min']
])
->add('amountHTMax', TextType::class, [
"label" => "Montant HT max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant HT max']
])
->add('amountTVAMin', TextType::class, [
"label" => "Montant TVA min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant TVA min']
])
->add('amountTVAMax', TextType::class, [
"label" => "Montant TVA max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant TVA max']
])
->add('amountDiscountMin', TextType::class, [
"label" => "Montant remise min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant remise min']
])
->add('amountDiscountMax', TextType::class, [
"label" => "Montant remise max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant remise max']
])
->add('amountTTCMin', TextType::class, [
"label" => "Montant TTC min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant TTC min']
])
->add('amountTTCMax', TextType::class, [
"label" => "Montant TTC max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Montant TTC max']
])
->add('discountMin', TextType::class, [
"label" => "Remise min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Remise min']
])
->add('discountMax', TextType::class, [
"label" => "Remise max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Remise max']
])
->add('soldeMin', TextType::class, [
"label" => "Solde min",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Solde min']
])
->add('soldeMax', TextType::class, [
"label" => "Solde max",
"required" => false,
'attr' => [
'autocomplete' => 'off',
'placeholder' => 'Solde max']
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'responsable'=>null
]);
}
}