src/Form/GestionComerciale/CommandeType.php line 214

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