src/Form/GestionComerciale/CommandeType.php line 212

Open in your IDE?
  1. <?php
  2. namespace App\Form\GestionComerciale;
  3. use App\DataTransformer\Clients\IdToClientTransformer;
  4. use App\DataTransformer\Localisation\IdToSecteurGeographiqueTransformer;
  5. use App\DataTransformer\Utilisateur\IdToContactTransformer;
  6. use App\Entity\Adresses\Adresse;
  7. use App\Entity\Clients\Client;
  8. use App\Entity\Clients\ClientCategorie;
  9. use App\Entity\FO\Societe;
  10. use App\Entity\GestionComerciale\Commande;
  11. use App\Entity\GestionComerciale\StatutPaiement;
  12. use App\Entity\Localisation\SecteurGeographique;
  13. use App\Entity\Localisation\Zone;
  14. use App\Entity\Transporteurs\Transporteur;
  15. use App\Entity\Utilisateur\Contact;
  16. use App\Entity\Utilisateur\Utilisateur;
  17. use App\Entity\Utilisateur\UtilisateurZoneGeographique;
  18. use App\Entity\Vehicules\VehiculeClient;
  19. use App\Repository\GestionComerciale\StatutPaiementRepository;
  20. use App\Repository\Transporteurs\TransporteurRepository;
  21. use App\Repository\Utilisateur\UtilisateurRepository;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  24. use Symfony\Component\Form\AbstractType;
  25. use Symfony\Component\Form\ChoiceList\ChoiceList;
  26. use Symfony\Component\Form\Extension\Core\Type\DateType;
  27. use Symfony\Component\Form\Extension\Core\Type\FileType;
  28. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  29. use Symfony\Component\Form\Extension\Core\Type\TextType;
  30. use Symfony\Component\Form\FormBuilderInterface;
  31. use Symfony\Component\Form\FormEvent;
  32. use Symfony\Component\Form\FormEvents;
  33. use Symfony\Component\Form\FormInterface;
  34. use Symfony\Component\OptionsResolver\OptionsResolver;
  35. class CommandeType extends AbstractType
  36. {
  37.     private EntityManagerInterface $entityManager;
  38.     private $transformerClient;
  39.     public function __construct(EntityManagerInterface $entityManager,IdToClientTransformer $transformerClient)
  40.     {
  41.         $this->entityManager $entityManager;
  42.         $this->transformerClient $transformerClient;
  43.     }
  44.     /**
  45.      * @param FormBuilderInterface $builder
  46.      * @param array $options
  47.      */
  48.     public function buildForm(FormBuilderInterface $builder, array $options)
  49.     {
  50.         $entity   $builder->getData();
  51.         $entityID "";
  52.         //if($entity->getID() != NULL){
  53.         $entityID $entity->getID();
  54.         //};
  55.         $builder
  56.             ->add('marge'HiddenType::class)
  57.             ->add('tauxMarge'HiddenType::class)
  58.             ->add('email')
  59.             ->add('telephone')
  60.             ->add('telephone2')
  61.             ->add('aBloquer')
  62.             ->add('numeroSuivi')
  63.             ->add('delaiRelance')
  64.             ->add('commercial'EntityType::class, [
  65.                 'class'         => Utilisateur::class,
  66.                 //'choice_name'   => ChoiceList::fieldName($this, 'nomPrenom'),
  67.                 'query_builder' => function (UtilisateurRepository $er) {
  68.                     return $er->createQueryBuilder('x')
  69.                               ->where('x.type = :type')
  70.                               ->setParameters(["type" => "4"])
  71.                               ->orderBy('x.nom''ASC');
  72.                 },
  73.             ])
  74.             ->add('assistanteCommercial'EntityType::class, [
  75.                 'class'         => Utilisateur::class,
  76.                 //'choice_name'   => ChoiceList::fieldName($this, 'nomPrenom'),
  77.                 'query_builder' => function (UtilisateurRepository $er) {
  78.                     return $er->createQueryBuilder('x')
  79.                               ->where('x.type = :type')
  80.                               ->setParameters(["type" => "5"])
  81.                               ->orderBy('x.nom''ASC');
  82.                 },
  83.             ])
  84.             ->add('fraisPortSupplementaire'TextType::class, ['attr' => ['class' => 'numeric']])
  85.             ->add('tauxTvaFraisPort'HiddenType::class)
  86.             ->add('francoPort')
  87.             ->add('dateBon'DateType::class, [
  88.                                'widget' => 'single_text',
  89.                            ]
  90.             )
  91.             ->add('date'DateType::class, [
  92.                             'widget' => 'single_text',
  93.                             'attr'   => [
  94.                                 'min' => $this->getDateDebutEx2($entityIDtrue),
  95.                                 'max' => $this->getDateFinEx2($entityIDtrue),
  96.                             ],
  97.                         ]
  98.             )
  99.             ->add('dateApproximativeReception'DateType::class, [
  100.                                                   'widget' => 'single_text',
  101.                                               ]
  102.             )
  103.             ->add('totalPoids'HiddenType::class)
  104.             ->add('typeDocumentCommercial')
  105.             ->add('commentaire')
  106.             /*->add('statutCommande', EntityType::class, array(
  107.                     'class' => 'DTC\GestionComercialeBundle\Entity\StatutCommande',
  108.                     //'choice_name'   => ChoiceList::fieldName($this, 'libelle'),
  109.                     'query_builder' => function(StatutCommandeRepository $er )  {
  110.                         return $er->createQueryBuilder('x')
  111.                                   ->where('x.documentCommercial = :documentCommercial AND x.ordre IN (:ordre)')
  112.                                   ->setParameters(array("documentCommercial"=>"2","ordre"=>array(0,1,2)))
  113.                                   ->orderBy('x.ordre', 'DESC');
  114.                 }
  115.             ))
  116.             */
  117.             ->add('statutPaiement'EntityType::class, [
  118.                 'class'         => StatutPaiement::class,
  119.                 //'choice_name'   => ChoiceList::fieldName($this, 'libelle'),
  120.                 'query_builder' => function (StatutPaiementRepository $er) {
  121.                     return $er->createQueryBuilder('x')
  122.                               ->orderBy('x.ordre''ASC');
  123.                 },
  124.             ])
  125.             ->add('transporteur'EntityType::class, [
  126.                 'class'         => Transporteur::class,
  127.                 //'choice_name'   => ChoiceList::fieldName($this, 'libelle'),
  128.                 'required'      => false,
  129.                 'query_builder' => function (TransporteurRepository $er) {
  130.                     return $er->createQueryBuilder('x')
  131.                               ->orderBy('x.position,x.libelle''ASC');
  132.                 },
  133.             ])
  134.             ->add(
  135.                 'client',
  136.                 TextType::class,
  137.                 [
  138.                     'attr' => [
  139.                         'class' => 'select2-hidden-accessible',
  140.                     ],
  141.                 ]
  142.             )
  143.             ->add('secteurGeographique'EntityType::class, [
  144.                 'multiple' => false// Wether or not multiple values are allowed (default to false)
  145.                 'class'    => SecteurGeographique::class,
  146.                 'attr'     => [
  147.                     'class' => 'select2-hidden-accessible',
  148.                 ],
  149.             ])
  150.             ->add('valideManuellement')
  151.             ->add('contactFacturation'EntityType::class, [
  152.                 'multiple' => false// Wether or not multiple values are allowed (default to false)
  153.                 'class'    => Contact::class,
  154.                 'attr'     => [
  155.                     'class' => 'select2-hidden-accessible',
  156.                 ],
  157.             ])
  158.             ->add('contactLivraison'EntityType::class, [
  159.                 'multiple' => false// Wether or not multiple values are allowed (default to false)
  160.                 'class'    => Contact::class,
  161.                 'attr'     => [
  162.                     'class' => 'select2-hidden-accessible',
  163.                 ],
  164.             ])
  165.             ->add('contactAcheteur'EntityType::class, [
  166.                 'multiple' => false// Wether or not multiple values are allowed (default to false)
  167.                 'class'    => Contact::class,
  168.                 'attr'     => [
  169.                     'class' => 'select2-hidden-accessible',
  170.                 ],
  171.             ])
  172.             ->add('dateLivraisonSouhaitee'DateType::class, [
  173.                                               'widget' => 'single_text',
  174.                                           ]
  175.             )
  176.             ->add('nbColis')
  177.             //->add('fichierImport', FileType::class, [])
  178.         ;
  179.         $builder->get('client')->addModelTransformer($this->transformerClient);
  180. //        $builder->get('contactFacturation')->addModelTransformer(new IdToContactTransformer($this->entityManager));
  181. //        $builder->get('contactLivraison')->addModelTransformer(new IdToContactTransformer($this->entityManager));
  182. //        $builder->get('contactAcheteur')->addModelTransformer(new IdToContactTransformer($this->entityManager));
  183.         $builder->add('referenceClient');
  184. //        $builder->get('client')->addModelTransformer(new IdToClientTransformer($this->entityManager));
  185. //        $builder->get('secteurGeographique')->addModelTransformer(new IdToSecteurGeographiqueTransformer($this->entityManager));
  186.         $formModifier = function (FormInterface $formClient $client null$entity) {
  187.             //$adresses = null === $client ? array() : $client->getAdresses();
  188.             //var_dump($form->getData());
  189.             $vehicules null === $client ? [] : $client->getVehiculesClient();
  190.             if (null === $client) {
  191.                 $adresses = [];
  192.             } else {
  193.                 $adresses $this->entityManager->getRepository(Adresse::class)->findBy([
  194.                                                                                             'visible' => 1,
  195.                                                                                             'client'  => $client->getId(),
  196.                                                                                         ]);
  197.             }
  198.             if (is_object($entity->getAdresseLivraison()) && $entity->getAdresseLivraison()->getVisible() == false) {
  199.                 $adresses[] = $entity->getAdresseLivraison();
  200.             }
  201.             if (is_object($entity->getAdresseFacturation()) && $entity->getAdresseFacturation()->getVisible() == false) {
  202.                 $adresses[] = $entity->getAdresseFacturation();
  203.             }
  204.             $reglement null === $client ?: $client->getModeReglement();
  205.             $pro       "0";
  206.             if (is_object($client)) {
  207.                 $repo_client_categorie $this->entityManager->getRepository(ClientCategorie::class);
  208.                 $premiere_categorie    $repo_client_categorie->getCategorieRacinePourClient($client);
  209.                 if (!is_object($premiere_categorie)) {
  210.                     $pro "0";
  211.                 } elseif (!is_object($premiere_categorie->getCategorie())) {
  212.                     $pro "0";
  213.                 } elseif (!$premiere_categorie->getCategorie()->getProfessionnel()) {
  214.                     $pro "0";
  215.                 } else {
  216.                     $pro "1";
  217.                 }
  218.             }
  219.             /*if(is_object($client)) {
  220.                 if(is_object($client->getTypeClient())) {
  221.                     if($client->getTypeClient()->getId() == "2") $pro = "1";
  222.                 }
  223.             }*/
  224.             $repo_utilisateur_zone_geographique $this->entityManager->getRepository(UtilisateurZoneGeographique::class);
  225.             $repo_zone                          $this->entityManager->getRepository(Zone::class);
  226.             $dataTva       1;
  227.             $dataAtributes = [];
  228.             foreach ($adresses as $a) {
  229.                 $paysUe  "0";
  230.                 $dataTva 1;
  231.                 $pays_obj null;
  232.                 $pays_id  null;
  233.                 if (is_object($a->getPays())) {
  234.                     if ($a->getPays()->getId() != "370095" && $a->getPays()->getEurope()) {
  235.                         $paysUe "1";
  236.                     }
  237.                     if ($pro == && $a->getPays()->getId() != "370095") {
  238.                         $dataTva 0;
  239.                     }
  240.                     if ($pro == && $a->getPays()->getEurope() == false) {
  241.                         $dataTva 0;
  242.                     }
  243.                     $pays_obj $a->getPays();
  244.                     $pays_id  $a->getPays()->getId();
  245.                 }
  246.                 if (is_object($client) && is_object($client->getCompta()) && $client->getCompta()->getTva() == 0) {
  247.                     //    echo "eeee";
  248.                     $dataTva 0;
  249.                 }
  250.                 $data_societe               "";
  251.                 $data_numero                "";
  252.                 $data_rue                   "";
  253.                 $data_complement            "";
  254.                 $data_complement2           "";
  255.                 $data_cp                    "";
  256.                 $data_ville                 "";
  257.                 $data_pays                  "";
  258.                 $data_secteur               "";
  259.                 $data_secteur_libelle       "";
  260.                 $data_secteur_obj           "";
  261.                 $data_commercial            "";
  262.                 $data_assistante_commercial "";
  263.                 $data_societe      $a->getSociete();
  264.                 $data_numero       $a->getNumero();
  265.                 $data_rue          $a->getRue();
  266.                 $data_complement   $a->getComplement();
  267.                 $data_complement_2 $a->getComplement2();
  268.                 if (is_object($a->getCodePostal())) {
  269.                     $data_cp $a->getCodePostal()->getCodePostal();
  270.                 }
  271.                 if (is_object($a->getVille())) {
  272.                     $data_ville $a->getVille()->getTitre();
  273.                 }
  274.                 if (is_object($a->getPays())) {
  275.                     $data_pays $a->getPays()->getTitre();
  276.                 }
  277.                 if ($data_cp != "") {
  278.                     $data_secteur_obj $repo_zone->findSecteurGeograhiqueByCodePostal($data_cp$pays_id);
  279.                     //echo "XXX";
  280.                 }
  281.                 if (!is_object($data_secteur_obj) && is_object($pays_obj) && is_object($pays_obj->getSecteurGeographique())) {
  282.                     $data_secteur_obj $pays_obj;
  283.                     //echo "YYYY";
  284.                 }
  285.                 //echo "AAAA";
  286.                 if (is_object($data_secteur_obj) && is_object($data_secteur_obj->getSecteurGeographique())) {
  287.                     $data_secteur               $data_secteur_obj->getSecteurGeographique()->getId();
  288.                     $data_secteur_libelle       $data_secteur_obj->getSecteurGeographique()->getLibelle();
  289.                     $data_assistante_commercial $repo_utilisateur_zone_geographique->findAssistanteCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  290.                     $data_commercial            $repo_utilisateur_zone_geographique->findCommercialByCodePostal($data_secteur_obj->getSecteurGeographique());
  291.                 }
  292.                 $adrTab = [
  293.                     'data-pro'                   => $pro,
  294.                     'data-ue'                    => $paysUe,
  295.                     'data-tva'                   => $dataTva,
  296.                     'data-societe'               => $data_societe,
  297.                     'data-numero'                => $data_numero,
  298.                     'data-rue'                   => $data_rue,
  299.                     'data-complement'            => $data_complement,
  300.                     'data-complement2'           => $data_complement2,
  301.                     'data-cp'                    => $data_cp,
  302.                     'data-ville'                 => $data_ville,
  303.                     'data-pays'                  => $data_pays,
  304.                     'data-secteur'               => $data_secteur,
  305.                     'data-secteur-libelle'       => $data_secteur_libelle,
  306.                     'data-commercial'            => $data_commercial,
  307.                     'data-assistante-commercial' => $data_assistante_commercial,
  308.                 ];
  309.                 $dataAtributes[] = $adrTab;
  310.             }
  311.             $dataKm                 "";
  312.             $dataCT                 "";
  313.             $dataSerie              "";
  314.             $dataImmat              "";
  315.             $dataModele             "";
  316.             $dataMarque             "";
  317.             $dataLibelle            "";
  318.             $dataAtributesVehicules = [];
  319.             foreach ($vehicules as $vehicule) {
  320.                 $dataImmat $vehicule->getImmatriculation();
  321.                 $dataSerie $vehicule->getNumSerie();
  322.                 if (is_object($vehicule->getDateControleTechnique())) {
  323.                     $dataCT $vehicule->getDateControleTechnique()->format("d/m/Y");
  324.                 } else {
  325.                     $dataCT "";
  326.                 }
  327.                 $dataKm $vehicule->getKilometrage();
  328.                 if (is_object($vehicule->getMarque())) {
  329.                     $dataMarque $vehicule->getMarque()->getLibelle();
  330.                 }
  331.                 if (is_object($vehicule->getModele())) {
  332.                     $dataModele $vehicule->getModele()->getLibelle();
  333.                 } else {
  334.                     $dataModele $vehicule->getLibelle();
  335.                 }
  336.                 if ($vehicule->getLibelle() != '') {
  337.                     $dataLibelle $vehicule->getLibelle();
  338.                 }
  339.                 $adrTab                   = [
  340.                     'data-km'      => $dataKm,
  341.                     'data-ct'      => $dataCT,
  342.                     'data-serie'   => $dataSerie,
  343.                     'data-immat'   => $dataImmat,
  344.                     'data-modele'  => $dataModele,
  345.                     'data-marque'  => $dataMarque,
  346.                     'data-libelle' => $dataLibelle,
  347.                 ];
  348.                 $dataAtributesVehicules[] = $adrTab;
  349.             }
  350.             $form->add('vehiculesClient'EntityType::class, [
  351.                 'class'        => VehiculeClient::class,
  352.                 'placeholder'  => '',
  353.                 'choices'      => $vehicules,
  354.                 'choice_attr'  => $dataAtributesVehicules,
  355.                 'choice_label' => function ($choiceValue$key$value) {
  356.                     return $choiceValue->getLibelle() . ' (' $choiceValue->getImmatriculation() . ')';
  357.                 },
  358.             ]);
  359.             $form->add('adresseLivraison'EntityType::class, [
  360.                 'class'       => Adresse::class,
  361.                 'placeholder' => '',
  362.                 'choices'     => $adresses,
  363.                 'choice_attr' => $dataAtributes,
  364.             ]);
  365.             $form->add('adresseFacturation'EntityType::class, [
  366.                 'class'       => Adresse::class,
  367.                 'placeholder' => '',
  368.                 'choices'     => $adresses,
  369.                 'choice_attr' => $dataAtributes,
  370.             ]);
  371.         };
  372.         $builder->addEventListener(
  373.             FormEvents::PRE_SET_DATA,
  374.             function (FormEvent $event) use ($formModifier$entity) {
  375.                 // this would be your entity, i.e. SportMeetup
  376.                 $data $event->getData();
  377.                 $formModifier($event->getForm(), $data->getClient(), $entity);
  378.             }
  379.         );
  380.         $builder->get('client')->addEventListener(
  381.             FormEvents::POST_SUBMIT,
  382.             function (FormEvent $event) use ($formModifier$entity) {
  383.                 // It's important here to fetch $event->getForm()->getData(), as
  384.                 // $event->getData() will get you the client data (that is, the ID)
  385.                 $client $event->getForm()->getData();
  386.                 // since we've added the listener to the child, we'll have to pass on
  387.                 // the parent to the callback functions!
  388.                 $formModifier($event->getForm()->getParent(), $client$entity);
  389.             }
  390.         );
  391.     }
  392.     public function configureOptions(OptionsResolver $resolver)
  393.     {
  394.         $resolver->setDefaults([
  395.                                    'data_class' => Commande::class,
  396.                                ]);
  397.     }
  398.     public function getBlockPrefix():string
  399.     {
  400.         return 'dtc_gestioncomercialebundle_commande';
  401.     }
  402.     public function getName()
  403.     {
  404.         return 'dtc_gestioncomercialebundle_commande';
  405.     }
  406.     public function getDateDebutEx($ID)
  407.     {
  408.         if ($ID == "") {
  409.             return false;
  410.         }
  411.         $repository $this->entityManager->getRepository(Societe::class);
  412.         $societe    $repository->find(1);
  413.         $dateDebut  $societe->getDateDebutExercice(1);
  414.         $dateDebut  $dateDebut->format('d/m/Y');
  415.         $repository $this->entityManager->getRepository(Commande::class);
  416.         $commande $repository->find($ID);
  417.         $dateInit $commande->getDate();
  418.         if (is_a($dateInit'DateTime')) {
  419.             $dateFacture $dateInit->format('d/m/Y');
  420.         } else {
  421.             $dateFacture = new \DateTime;
  422.             $dateFacture $dateFacture->format('d/m/Y');
  423.         }
  424.         list($monthDebut$dayDebut$yearDebut) = explode("/"$dateDebut);
  425.         $dayMonthDebut $dayDebut "/" $monthDebut;
  426.         list($dayFacture$monthFacture$yearFacture) = explode("/"$dateFacture);
  427.         $dayMonthFacture $dayFacture "/" $monthFacture;
  428.         //echo $dayMonthFacture."//".$dayMonthDebut;
  429.         //$dayMonthFin = new \DateTime($dayMonthFin);
  430.         $dayMonthDebut \DateTime::createFromFormat('d/m'$dayMonthDebut);
  431.         //$dayMonthFacture = new \DateTime($dayMonthFacture);
  432.         $dayMonthFacture \DateTime::createFromFormat('d/m'$dayMonthFacture);
  433.         if ($dayMonthDebut <= $dayMonthFacture) {
  434.             //echo "superieur dateDebut";
  435.             $dayMonthDebut   $dayMonthDebut->format('d/m');
  436.             $dayMonthFacture $dayMonthFacture->format('d/m');
  437.             //echo $dayMonthFacture."//".$dayMonthDebut;
  438.             $Date $dayMonthDebut "/" $yearFacture;
  439.             return $Date//->format('d/m/Y');
  440.         } elseif ($dayMonthDebut >= $dayMonthFacture) {
  441.             //echo "inferieur dateDebut";
  442.             $yearFacture $yearFacture 1;
  443.             //echo $yearFacture;
  444.             $dayMonthDebut   $dayMonthDebut->format('d/m');
  445.             $dayMonthFacture $dayMonthFacture->format('d/m');
  446.             //echo $dayMonthFacture."//".$dayMonthDebut;
  447.             $Date $dayMonthDebut "/" $yearFacture;
  448.             //echo $Date;
  449.             return $Date;//->format('d/m/Y');
  450.         }
  451.     }
  452.     public function getDateFinEx($ID)
  453.     {
  454.         if ($ID == "") {
  455.             return false;
  456.         }
  457.         $repository $this->entityManager->getRepository(Societe::class);
  458.         $societe    $repository->find(1);
  459.         $dateFin    $societe->getDateFinExercice(1);
  460.         $dateFin    $dateFin->format('d/m/Y');
  461.         $repository $this->entityManager->getRepository(Commande::class);
  462.         $commande $repository->find($ID);
  463.         $dateInit $commande->getDate($ID);
  464.         if (is_a($dateInit'DateTime')) {
  465.             $dateFacture $dateInit->format('d/m/Y');
  466.         } else {
  467.             $dateFacture = new \DateTime;
  468.             $dateFacture $dateFacture->format('d/m/Y');
  469.         }
  470.         list($dayFin$monthFin$yearFin) = explode("/"$dateFin);
  471.         $dayMonthFin $dayFin "/" $monthFin;
  472.         list($dayFacture$monthFacture$yearFacture) = explode("/"$dateFacture);
  473.         $dayMonthFacture $dayFacture "/" $monthFacture;
  474.         //$dayMonthFin = new \DateTime($dayMonthFin);
  475.         $dayMonthFin \DateTime::createFromFormat('d/m'$dayMonthFin);
  476.         //$dayMonthFacture = new \DateTime($dayMonthFacture);
  477.         $dayMonthFacture \DateTime::createFromFormat('d/m'$dayMonthFacture);
  478.         if ($dayMonthFacture <= $dayMonthFin) {
  479.             //echo "infĂ©rieur datefin";
  480.             $dayMonthFin $dayMonthFin->format('d/m');
  481.             $Date        $dayMonthFin "/" $yearFacture;
  482.             //echo $Date;
  483.             return $Date;//->format('d/m/Y');
  484.         } elseif ($dayMonthFacture >= $dayMonthFin) {
  485.             //echo "supĂ©rieur datefin";
  486.             $yearFacture $yearFacture 1;
  487.             //echo $yearFacture;
  488.             $dayMonthFin $dayMonthFin->format('d/m');
  489.             //echo $dayMonthFin;
  490.             $Date $dayMonthFin "/" $yearFacture;
  491.             //echo $Date;
  492.             return $Date;//->format('d/m/Y');
  493.         }
  494.     }
  495.     public function getDateFinEx2($ID$formatage false)
  496.     {
  497.         if ($ID == "") {
  498.             return false;
  499.         }
  500.         $repository $this->entityManager->getRepository(Societe::class);
  501.         $societe    $repository->find(1);
  502.         $dateFin    $societe->getDateFinExercice();
  503.         //$dateFin = $dateFin->format('d/m/Y');
  504.         $repository $this->entityManager->getRepository(Commande::class);
  505.         $commande $repository->find($ID);
  506.         $dateInit $commande->getDate();
  507.         if (!is_object($dateInit)) {
  508.             $dateInit = new \DateTime;
  509.         }
  510.         $dateFinEx = new \DateTime;
  511.         $dateFinEx->setDate($dateInit->format('Y'), $dateFin->format('m'), $dateFin->format('d'));
  512.         if ($dateFinEx $dateInit) {
  513.             $dateFinEx->add(new \DateInterval('P1Y'));
  514.         }
  515.         if ($formatage) {
  516. //            $interval = $dateInit->diff($dateFinEx);
  517. //            return $interval->format('%R%ad');
  518.             return $dateFinEx->format('Y-m-d');
  519.         } else {
  520.             return $dateFinEx;
  521.         }
  522.     }
  523.     public function getDateDebutEx2($ID$formatage false)
  524.     {
  525.         if ($ID == "") {
  526.             return false;
  527.         }
  528.         $repository $this->entityManager->getRepository(Commande::class);
  529.         $commande $repository->find($ID);
  530.         $dateInit $commande->getDate();
  531.         if (!is_object($dateInit)) {
  532.             $dateInit = new \DateTime;
  533.         }
  534.         $dateDebut $this->getDateFinEx2($ID);
  535.         $dateDebut->sub(new \DateInterval('P1Y'));
  536.         if ($formatage) {
  537. //            $interval = $dateInit->diff($dateDebut);
  538. //            return $interval->format('%R%ad');
  539.             return $dateDebut->format('Y-m-d');
  540.         } else {
  541.             return $dateDebut;
  542.         }
  543.     }
  544. }