src/Controller/GestionComerciale/AcompteController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller\GestionComerciale;
  3. use App\Entity\Clients\Client;
  4. use App\Entity\GestionComerciale\Acompte;
  5. use App\Entity\GestionComerciale\Commande;
  6. use App\Entity\GestionComerciale\MouvementCaisse;
  7. use App\Entity\GestionComerciale\TypeReglement;
  8. use App\Form\GestionComerciale\AcompteType;
  9. use App\Form\GestionComerciale\SupprimerAcompteType;
  10. use App\Library\Datatable\Util\Datatable;
  11. use App\Model\GestionCommerciale\TypeDocumentCommercial;
  12. use App\Security\Voter\EntityVoter;
  13. use App\Service\GestionComerciale\AcompteService;
  14. use App\Service\GestionComerciale\CommandeService;
  15. use App\Service\GestionComerciale\FactureService;
  16. use App\Service\GestionComerciale\MouvementCaisseService;
  17. use App\Service\GestionComerciale\NumerotationDocumentService;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Doctrine\ORM\Query\Expr\Join;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\JsonResponse;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Symfony\Component\Validator\Validator\ValidatorInterface;
  26. use Symfony\Contracts\Translation\TranslatorInterface;
  27. class AcompteController extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/vente/acompte/nouveau/{id}/{type}/{redirection}", name="dtc_acompte_ajouter")
  31.      */
  32.     public function ajouterAction(Request        $request$id$type ""$redirection ""EntityManagerInterface $emNumerotationDocumentService $numerotationService,
  33.                                   AcompteService $acompteServiceTranslatorInterface $translatorValidatorInterface $validatorCommandeService $commandeService
  34.     ) {
  35.         $titre_modal $translator->trans("Nouvel acompte");
  36.         $acompte     = new Acompte();
  37.         $repo_acompte $em->getRepository(Acompte::class);
  38.         $type_acompte $em->getRepository(TypeReglement::class)->find(1);
  39.         $acompte->setTypeReglement($type_acompte);
  40.         $user $this->getUser();
  41.         $acompte->setUtilisateur($user);
  42.         $repo_objet $em->getRepository(Commande::class);
  43.         $objet      $repo_objet->find($id);
  44.         $acompte->setCommande($objet);
  45.         //echo "<div>".$objet->getReference()."</div>";
  46.         if (is_object($objet->getCommande())) {
  47.             $acompte->setParent($objet->getCommande());
  48.         }
  49.         $client $objet->getClient();
  50.         if ( ! is_object($client)) {
  51.             $titre_modal $translator->trans('Informations');
  52.             $rendu       '<div class="modal-body modal_rouge"> <div class="alert alert-danger alert-dismissable text-center">Merci de sélectionner un client</div> </div><div class="modal-footer">    <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button></div>';
  53.             return new Response(json_encode(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]), 200, ['Content-Type' => 'application/json']);
  54.         }
  55.         $delai $client->getDelaiPaiement();
  56.         $acompte->setDelaiPaiement($delai);
  57.         $acompte->setClient($client);
  58.         $moderegle $client->getmodeReglement();
  59.         //echo "HELLO ".$acompte->getModeReglement()->getId();
  60.         //$acompte->setModeReglement($moderegle);
  61.         $acompte->setModeReglement(null);
  62.         $form   $this->createForm(AcompteType::class, $acompte);
  63.         $errors "";
  64.         $form->handleRequest($request);
  65.         $avoirs $repo_acompte->getAcomptesNonUtilisésTotalement($client);
  66.         if ($form->isSubmitted()) {
  67.             $objet_redirection $repo_objet->find($redirection);
  68.             if ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
  69.                 $url $this->generateUrl('dtc_commande_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  70.             } elseif ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::ORDREREPARATION) {
  71.                 $url $this->generateUrl('dtc_ordre_reparation_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  72.             } elseif ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::BP) {
  73.                 $url $this->generateUrl('dtc_bon_preparation_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  74.             } elseif ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::BL) {
  75.                 $url $this->generateUrl('dtc_bon_livraison_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  76.             } elseif ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::FACTURE) {
  77.                 $url $this->generateUrl('dtc_facture_afficher', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  78.             }
  79.             $avoirsAutiliser $request->request->get('selectsAvoir');
  80.             if (is_array($avoirsAutiliser) && count($avoirsAutiliser) > 0) {
  81.                 foreach ($avoirsAutiliser as $avoirAutiliserId) {
  82.                     $avoirAutiliser $repo_acompte->find($avoirAutiliserId);
  83.                     if (is_object($avoirAutiliser)) {
  84.                         $montantAutiliser $request->request->get('montantAvoir_'.$avoirAutiliserId);
  85.                         if ($montantAutiliser == $avoirAutiliser->getMontant()) {
  86.                             //$avoirAutiliser->setCommentaire('Utilisation totale : '.$montantAutiliser);
  87.                             $avoirAutiliser->setCommande($objet);
  88.                             $avoirAutiliser->setTypeReglement($type_acompte);
  89.                             $avoirAutiliser->setCommentaire("Acompte de ".$montantAutiliser."€ versé pour la Commande : ".$objet->getReference()."<br/>".$avoirAutiliser->getCommentaire());
  90.                         } else {
  91.                             //$avoirAutiliser->setCommentaire('Utilisation partielle : '.$montantAutiliser);
  92.                             $avoirAutiliser->setEstParent(true);
  93.                             for ($a 0$a 2$a++) {
  94.                                 $acompteTmp = new Acompte();
  95.                                 $acompteTmp->setUtilisateur($user);
  96.                                 if ($a == 0) {
  97.                                     $montant_acompte $montantAutiliser;
  98.                                     //$montant_acompte = 10;
  99.                                     $acompteTmp->setCommande($objet);
  100.                                     $acompteTmp->setCommentaire("Acompte de ".$montant_acompte."€ versé pour la Commande : ".$objet->getReference()."<br/>".$acompteTmp->getCommentaire());
  101.                                 } else {
  102.                                     $montant_acompte $avoirAutiliser->getMontant() - $montantAutiliser;
  103.                                     $acompteTmp->setCommande(null);
  104.                                     $acompteTmp->setCommentaire("Reste dû de l'avoir ".$avoirAutiliser->getNumTraite());
  105.                                 }
  106.                                 $acompteTmp->setMontant($montant_acompte);
  107.                                 $acompteTmp->setAcompteParent($avoirAutiliser);
  108.                                 $acompteTmp->setTypeReglement($type_acompte);
  109.                                 $delai $avoirAutiliser->getDelaiPaiement();
  110.                                 $acompteTmp->setDelaiPaiement($delai);
  111.                                 $moderegle $avoirAutiliser->getmodeReglement();
  112.                                 $acompteTmp->setModeReglement($moderegle);
  113.                                 $nom $objet->getClient()->getPrenom().' '.$objet->getClient()->getNom();
  114.                                 $acompteTmp->setNomClient($nom);
  115.                                 $acompteTmp->setClient($objet->getClient());
  116.                                 $acompteTmp->setNumTraite($numerotationService->generer($acompteTmp));
  117.                                 $em->persist($acompteTmp);
  118.                                 $em->flush();
  119.                             }
  120.                         }
  121.                         $em->persist($avoirAutiliser);
  122.                         $this->addFlash(
  123.                             'notice',
  124.                             $avoirAutiliser->getNumTraite().' a été déduit de cette commande !'
  125.                         );
  126.                     }
  127.                 }
  128.                 $em->flush();
  129.             }
  130.             if ($acompte->getMontant() != && $acompte->getMontant() != '') {
  131.                 if ($form->isValid()) {
  132.                     $nom $client->getPrenom().' '.$client->getNom();
  133.                     $acompte->setCommentaire("Acompte de ".$acompte->getMontant()."€ versé pour la Commande : ".$objet->getReference()."<br/>".$acompte->getCommentaire());
  134.                     $acompte->setNomClient($nom);
  135.                     $acompte->setClient($client);
  136.                     $acompte->setNumTraite($numerotationService->generer($acompte));
  137.                     $em->persist($acompte);
  138.                     $em->flush();
  139.                     $client $acompte->getClient();
  140.                     if (is_object($client)) {
  141.                         $soldeClient $acompteService->getSoldeClient($client);
  142.                         $acompte->setSolde($soldeClient);
  143.                         $em->persist($acompte);
  144.                         $em->flush();
  145.                     }
  146.                     if (is_object($acompte->getCommande())) {
  147.                         //recalculer statut de paiement
  148.                         $commandeService->changerStatutPaiement($acompte->getCommande());
  149.                     }
  150.                     $this->addFlash(
  151.                         'notice',
  152.                         $translator->trans('Acompte ajouté avec succès !')
  153.                     );
  154.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  155.                 } else {
  156.                     $errors $validator->validate($acompte);
  157.                     $rendu  $this->renderView(
  158.                         'GestionComerciale/Acompte/ajouter.html.twig',
  159.                         ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet'avoirs' => $avoirs]
  160.                     );
  161.                     return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  162.                 }
  163.             } else {
  164.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  165.             }
  166.         }
  167.         $rendu $this->renderView(
  168.             'GestionComerciale/Acompte/ajouter.html.twig',
  169.             ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet'avoirs' => $avoirs]
  170.         );
  171.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  172.         //return $this->render('GestionComerciale/Acompte/ajouter.html.twig', array('form' => $form->createView(),'errors'=>$errors,'id'=>$id,'type'=>$type));
  173.     }
  174.     /**
  175.      * @Route("/vente/acompte/modifier/{objet}/{id}/{type}/{redirection}", name="dtc_acompte_modifier")
  176.      */
  177.     public function modifierAction(Request             $requestAcompte $objet$id$typeEntityManagerInterface $emAcompteService $acompteService,
  178.                                    TranslatorInterface $translatorValidatorInterface $validator
  179.     ) {
  180.         $acompte     $objet;
  181.         $titre_modal $translator->trans("Modifier acompte");
  182.         $user $this->getUser();
  183.         $acompte->setUtilisateur($user);
  184.         $form   $this->createForm(AcompteType::class, $acompte);
  185.         $errors "";
  186.         $form->handleRequest($request);
  187.         if ($form->isSubmitted()) {
  188.             $droit $this->isGranted(EntityVoter::UPDATEAcompte::class);
  189.             if ( ! $droit) {
  190.                 $rendu $this->renderView(
  191.                     'GestionComerciale/Acompte/ajouter.html.twig',
  192.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]
  193.                 );
  194.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  195.             }
  196.             if ($form->isValid()) {
  197.                 $repo_objet $em->getRepository(Commande::class);
  198.                 $objet      $repo_objet->find($id);
  199.                 $acompte->setCommande($objet);
  200.                 $url $this->generateUrl('dtc_commande_modifier', ['id' => $objet->getId(), 'tab' => 'acomptes']);
  201.                 $em->persist($acompte);
  202.                 $em->flush();
  203.                 $client $acompte->getClient();
  204.                 if (is_object($client)) {
  205.                     $soldeClient $acompteService->getSoldeClient($client);
  206.                     $acompte->setSolde($soldeClient);
  207.                     $em->persist($acompte);
  208.                     $em->flush();
  209.                 }
  210.                 $this->addFlash(
  211.                     'notice',
  212.                     $translator->trans('Acompte modifié avec succès !')
  213.                 );
  214.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  215.             } else {
  216.                 $errors $validator->validate($acompte);
  217.                 $rendu  $this->renderView(
  218.                     'GestionComerciale/Acompte/ajouter.html.twig',
  219.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]
  220.                 );
  221.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  222.             }
  223.         }
  224.         $rendu $this->renderView('GestionComerciale/Acompte/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]);
  225.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  226.     }
  227.     /**
  228.      * @Route("/vente/acompte/supprimer/{objet}/{id}/{type}/{redirection}", name="dtc_acompte_supprimer")
  229.      */
  230.     public function supprimerAction(Request             $requestAcompte $objet$id$type$redirectionEntityManagerInterface $emFactureService $serviceFacture,
  231.                                     TranslatorInterface $translatorValidatorInterface $validatorMouvementCaisseService $mouvementCaisseService
  232.     ) {
  233.         $acompte     $objet;
  234.         $titre_modal $translator->trans("Demande de confirmation");
  235.         $user        $this->getUser();
  236.         $form           $this->createForm(SupprimerAcompteType::class, $acompte);
  237.         $errors         "";
  238.         $nonSupprimable false;
  239.         $supprimable    true;
  240.         if ((is_object($objet->getMouvementCaisse()) && is_object($objet->getMouvementCaisse()->getDateTransfertCompta())) || (is_object($objet->getBordereau()))) {
  241.             $nonSupprimable true;
  242.             $supprimable    false;
  243.             $this->addFlash(
  244.                 'warning',
  245.                 $translator->trans('Acompte non supprimable !')
  246.             );
  247.         }
  248.         $form->handleRequest($request);
  249.         $factures         = [];
  250.         $reglementsEnfant $acompte->getReglementsEnfant();
  251.         $nbEnfants        count($reglementsEnfant);
  252.         if ($nbEnfants 0) {
  253.             foreach ($reglementsEnfant as $reglementEnfant) {
  254.                 if (is_object($reglementEnfant) && is_object($reglementEnfant->getCommande())) {
  255.                     $factures[] = $reglementEnfant->getCommande();
  256.                 }
  257.             }
  258.         }
  259.         if (is_object($acompte->getCommande())) {
  260.             $factures[] = $acompte->getCommande();
  261.         }
  262.         if ($form->isSubmitted()) {
  263.             if ($form->isValid()) {
  264.                 $reglementsEnfant $acompte->getReglementsEnfant();
  265.                 $nbEnfants        count($reglementsEnfant);
  266.                 //$supprimable = true;
  267.                 if ($nbEnfants 0) {
  268.                     foreach ($reglementsEnfant as $reglementEnfant) {
  269.                         /*
  270.                         if($reglementEnfant->getMontant() == $acompte->getMontant()){
  271.                             $commande = $reglementEnfant->getCommande();
  272.                             $em->remove($reglementEnfant);
  273.                             $em->flush();
  274.                         } else {
  275.                             $supprimable = false;
  276.                         }
  277.                          *
  278.                          */
  279.                         $commande $reglementEnfant->getCommande();
  280.                         $em->remove($reglementEnfant);
  281.                         $em->flush();
  282.                         if (is_object($commande) && is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::FACTURETypeDocumentCommercial::AVOIR]
  283.                             )) {//facture
  284.                             $em->refresh($commande);
  285.                             $serviceFacture->changerStatutPaiementFacture($commande);
  286.                         }
  287.                     }
  288.                 }
  289.                 $commande $acompte->getCommande();
  290.                 if ($supprimable) {
  291.                     $repo_acompte $em->getRepository(Acompte::class);
  292.                     $enfants      $repo_acompte->findBy(["remboursement" => $acompte->getId()]);
  293.                     if (count($enfants) > 0) {
  294.                         foreach ($enfants as $e) {
  295.                             $e->setRemboursement(null);
  296.                             $em->persist($e);
  297.                         }
  298.                     }
  299.                     /*
  300.                     if(is_object($acompte->getCommande()) and is_object($acompte->getCommande()->getTypeDocumentCommercial()) and $acompte->getCommande()->getTypeDocumentCommercial() == TypeDocumentCommercial::FACTURE) {
  301.                         $statutPaiement = $em->getRepository('DTCGestionComercialeBundle:StatutPaiement')->find(1);
  302.                         $acompte->getCommande()->setStatutPaiement($statutPaiement);
  303.                         $em->persist($acompte->getCommande());
  304.                                 }
  305.                                  *
  306.                                  */
  307.                     $em->remove($acompte);
  308.                     $em->flush();
  309.                     $retour 'test';
  310.                     if (is_object($commande) && is_int($commande->getTypeDocumentCommercial()) && in_array($commande->getTypeDocumentCommercial(), [TypeDocumentCommercial::FACTURETypeDocumentCommercial::AVOIR])) {//facture
  311.                         $em->refresh($commande);
  312.                         $serviceFacture->changerStatutPaiementFacture($commande);
  313.                     }
  314.                     //Si reglement en especes il faut supprimer le mouvement de caisse
  315.                     if (is_object($acompte->getModeReglement()) && $acompte->getModeReglement()->getId() == 1) {
  316.                         $repo_mvt_caisse $em->getRepository(MouvementCaisse::class);
  317.                         $mouvementCaisse $repo_mvt_caisse->findOneByReglement($acompte);
  318.                         //Il existe un mouvement de caisse
  319.                         if (is_object($mouvementCaisse)) {
  320.                             $mouvementCaisseService->supprimerMouvementCaisse($mouvementCaisse);
  321.                         }
  322.                     }
  323.                     $flashMessage 'Acompte supprimé avec succès !';
  324.                     $flashType    'notice';
  325.                     /*
  326.         $this->addFlash(
  327.                         'notice',
  328.                        $translator->trans('Acompte supprimé avec succès !')
  329.                     );
  330.                      *
  331.                      */
  332.                 } else {
  333.                     /*
  334.                     $this->addFlash(
  335.                         'warning',
  336.                        $translator->trans('Acompte non supprimable !')
  337.                     );
  338.                      *
  339.                      */
  340.                     $flashMessage 'Acompte non supprimable !';
  341.                     $flashType    'warning';
  342.                 }
  343.                 $repo_objet $em->getRepository(Commande::class);
  344.                 if ($type == 'client') {
  345.                     $repo_objet $em->getRepository(Client::class);
  346.                 }
  347.                 $objet_redirection $repo_objet->find($redirection);
  348.                 //echo "ddddd";
  349.                 $callBackType '';
  350.                 $rendu        '';
  351.                 $this->addFlash($flashType$flashMessage);
  352.                 if (is_object($objet_redirection)) {
  353.                     //echo "eeeee";
  354.                     if ($type == 'client') {
  355.                         $url $this->generateUrl('dtc_client_modifier', ['id' => $objet_redirection->getId()]);
  356.                     } elseif (is_object($objet_redirection->getTypeDocumentCommercial()) and $objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::COMMANDE) {
  357.                         $url $this->generateUrl('dtc_commande_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  358.                     } elseif (is_object($objet_redirection->getTypeDocumentCommercial()) and $objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::ORDREREPARATION) {
  359.                         $url $this->generateUrl('dtc_ordre_reparation_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  360.                     } elseif (is_object($objet_redirection->getTypeDocumentCommercial()) and $objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::BP) {
  361.                         $url $this->generateUrl('dtc_bon_preparation_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  362.                     } elseif ($objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::BL) {
  363.                         $url $this->generateUrl('dtc_bon_livraison_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  364.                     } elseif (is_object($objet_redirection->getTypeDocumentCommercial()) and $objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::FACTURE) {
  365.                         $url $this->generateUrl('dtc_facture_afficher', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  366.                     } elseif (is_object($objet_redirection->getTypeDocumentCommercial()) and $objet_redirection->getTypeDocumentCommercial() == TypeDocumentCommercial::AVOIR) {
  367.                         $url $this->generateUrl('dtc_avoir_modifier', ['id' => $objet_redirection->getId(), 'tab' => 'acomptes']);
  368.                     }
  369.                 } else {
  370.                     $url          $this->generateUrl('dtc_reglement_remise_banque_liste', ['type' => '']);
  371.                     $callBackType 'supprimer-reglement-datatable';
  372.                     $rendu        $this->renderView(
  373.                         'FO/Supprimer/supprimer.html.twig',
  374.                         [
  375.                             'form'           => $form->createView(),
  376.                             'errors'         => $errors,
  377.                             'id'             => $id,
  378.                             'type'           => $type,
  379.                             'objet'          => $objet,
  380.                             'factures'       => $factures,
  381.                             "nonSupprimable" => $nonSupprimable,
  382.                         ]
  383.                     );
  384.                 }
  385.                 //echo "TEST".$url;
  386.                 //exit;
  387.                 return new JsonResponse(['rendu' => $rendu'valide' => '1''url' => $url'type' => $callBackType'id' => $acompte->getId()]);
  388.             } else {
  389.                 $errors $validator->validate($acompte);
  390.                 $rendu  $this->renderView(
  391.                     'FO/Supprimer/supprimer.html.twig',
  392.                     [
  393.                         'form'           => $form->createView(),
  394.                         'errors'         => $errors,
  395.                         'id'             => $id,
  396.                         'type'           => $type,
  397.                         'objet'          => $objet,
  398.                         'factures'       => $factures,
  399.                         "nonSupprimable" => $nonSupprimable,
  400.                     ]
  401.                 );
  402.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  403.             }
  404.         }
  405.         $rendu $this->renderView(
  406.             'FO/Supprimer/supprimer.html.twig',
  407.             [
  408.                 'form'           => $form->createView(),
  409.                 'errors'         => $errors,
  410.                 'id'             => $id,
  411.                 'type'           => $type,
  412.                 'objet'          => $objet,
  413.                 'factures'       => $factures,
  414.                 "nonSupprimable" => $nonSupprimable,
  415.             ]
  416.         );
  417.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  418.     }
  419.     /**
  420.      * @Route("/vente/acompte/{id}/{type}/{redirection}", name="dtc_acompte_liste")
  421.      */
  422.     public function listerAction(Request $request$id$type ""$redirectionEntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  423.     {
  424.         $repo_objet $em->getRepository(Commande::class);
  425.         $objet      $repo_objet->find($id);
  426.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [0], "visible" => true"orderable" => false];
  427.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-right""targets" => [1], "visible" => true"orderable" => false];
  428.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [2], "visible" => true"orderable" => false];
  429.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [3], "visible" => true];
  430.         $this->datatable($objet$type$redirection$datatable$translator);
  431.         return $this->render('GestionComerciale/Acompte/lister.html.twig', ['tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type"redirection" => $redirection]
  432.         );
  433.     }
  434.     /**
  435.      * set datatable configs
  436.      *
  437.      * @return \App\Library\Datatable\Util\Datatable
  438.      */
  439.     private function datatable($objet$type ""$redirection ""Datatable $datatableTranslatorInterface $translator)
  440.     {
  441.         //$type_jointure = 'x.'.$type;
  442.         $datatable->setDatatableId('dta-acomptes')
  443.                   ->setEntity(Acompte::class, "x")
  444.                   ->setFields(
  445.                       [
  446.                           //$translator->trans("ID") =>  'x.id',
  447.                           $translator->trans("Date")              => 'x.dateReglement',
  448.                           $translator->trans("Montant")           => 'x.montant',
  449.                           $translator->trans("Mode de Règlement") => 'r.libelle',
  450.                           $translator->trans("Actions") => 'x.id',
  451.                           "_identifier_"                => 'x.id',
  452.                       ]
  453.                   )
  454.                   ->addJoin('x.modeReglement''r'Join::LEFT_JOIN);
  455.         if ($type == 'multiBl') {
  456.             //$bls = $em->getRepository(Commande::class)->getBonsLivraison($objet->getCommande()->getId());
  457.             $bls       $objet->getBls();
  458.             $commandes = [];
  459.             foreach ($bls as $bl) {
  460.                 $commandes[] = $bl->getCommande()->getId();
  461.             }
  462.             $datatable->addJoin('x.commande''c'Join::LEFT_JOIN);
  463.             $where      'c.id IN (:commandes) and x.typeReglement = :typeReglement';
  464.             $parameters = ['commandes' => $commandes'typeReglement' => 1];
  465.         } else {
  466.             $where      'x.'.$type.' = :objet and x.typeReglement = :typeReglement';
  467.             $parameters = ['objet' => $objet'typeReglement' => 1];
  468.         }
  469.         $datatable->setWhere(
  470.             $where,
  471.             $parameters
  472.         )
  473.                   ->setRenderers(
  474.                       [
  475.                           => [
  476.                               'view'   => 'FO/DataTable/heure.html.twig',
  477.                               'params' => [],
  478.                           ],
  479.                           => [
  480.                               'view'   => 'FO/DataTable/prix.html.twig',
  481.                               'params' => [],
  482.                           ],
  483.                           => [
  484.                               'view'   => 'FO/DataTable/actions_modal.html.twig',
  485.                               'params' => [
  486.                                   //'edit_route'  => 'dtc_acompte_modifier',
  487.                                   'supprimer_route' => 'dtc_acompte_supprimer',
  488.                                   'id'              => $objet->getId(),
  489.                                   'type'            => $type,
  490.                                   'redirection'     => $redirection,
  491.                                   'entite'          => 'adresse',
  492.                                   'objet'           => Acompte::class,
  493.                               ],
  494.                           ],
  495.                       ]
  496.                   )
  497.                   ->setOrder("x.id""desc")
  498.                   ->setSearch(true)
  499.                   ->setSearchFields([12]);
  500.         return $datatable;
  501.     }
  502.     /**
  503.      * @Route("/vente/acompte/grid/{id}/{type}/{redirection}", name="dtc_acompte_liste_grid")
  504.      */
  505.     public function gridAction(Request $request$id ""$type ""$redirection ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  506.     {
  507.         $repo_objet $em->getRepository(Commande::class);
  508.         $objet      $repo_objet->find($id);
  509.         return $this->datatable($objet$type$redirection$datatable$translator)->execute();
  510.     }
  511. }