src/Repository/DossierRepository.php line 237

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Dossier;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Common\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Dossier|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Dossier|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Dossier[]    findAll()
  10.  * @method Dossier[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class DossierRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryDossier::class);
  17.     }
  18.     public function countBySubcode($subcode) {
  19.         $conn $this->getEntityManager()->getConnection();
  20.         $sql "SELECT d.id                
  21.                 FROM walkinn_dossier d
  22.                 WHERE d.code_walkinn LIKE '" $subcode "%'
  23.                 ORDER BY d.id ASC
  24.                 ";
  25.         
  26.         
  27.         $stmt $conn->prepare($sql);
  28.         $stmt->execute();
  29.         $results $stmt->fetchAll();
  30.         return count($results) +1;
  31.     }
  32.     public function getClientsIds($dossierId
  33.     {
  34.         $conn $this->getEntityManager()->getConnection();
  35.         $sql 
  36.             " SELECT DISTINCT(segment.client_id)
  37.             FROM walkinn_dossier_segment segment
  38.             WHERE 1 = 1
  39.             AND segment.actif = 1
  40.             AND segment.dossier_id = :dossierId
  41.             ORDER BY segment.date_depart ASC "
  42.         ;
  43.         
  44.         
  45.         $stmt $conn->prepare($sql);
  46.         $stmt->execute(['dossierId' => $dossierId]);
  47.         $results $stmt->fetchAll(\PDO::FETCH_COLUMN);
  48.         return $results;
  49.     }
  50.     public function getSupplierIds($dossierId
  51.     {
  52.         $conn $this->getEntityManager()->getConnection();
  53.         $sql 
  54.             " SELECT service.prestataire_id
  55.             , (SELECT MIN(jour) FROM walkinn_dossier_segment_service_day WHERE dossier_segment_service_id = segment_service.id) AS min_day
  56.             , tampon.id AS tampon_id
  57.             FROM walkinn_dossier_segment_service segment_service
  58.             LEFT JOIN walkinn_service service ON service.id = segment_service.service_id
  59.             LEFT JOIN walkinn_dossier_segment segment ON segment.id = segment_service.segment_id
  60.             LEFT JOIN walkinn_dossier_commande_fournisseur_tampon tampon ON tampon.dossier_id = :dossierId AND tampon.fournisseur_id = service.prestataire_id
  61.             WHERE 1 = 1
  62.             AND segment.actif = 1
  63.             AND segment.dossier_id = :dossierId
  64.             AND service.prestataire_id IS NOT NULL
  65.             GROUP BY service.prestataire_id
  66.             ORDER BY min_day
  67.             "
  68.         ;
  69.         
  70.         $stmt $conn->prepare($sql);
  71.         $stmt->execute(['dossierId' => $dossierId]);
  72.         $results $stmt->fetchAll();
  73.         return $results;
  74.     }
  75.     public function getSegmentsIds($dossierId
  76.     {
  77.         $conn $this->getEntityManager()->getConnection();
  78.         $sql 
  79.             " SELECT DISTINCT(segment.id)
  80.             FROM walkinn_dossier_segment segment
  81.             WHERE 1 = 1
  82.             AND segment.actif = 1
  83.             AND segment.dossier_id = :dossierId
  84.             ORDER BY segment.date_depart ASC "
  85.         ;
  86.         
  87.         
  88.         $stmt $conn->prepare($sql);
  89.         $stmt->execute(['dossierId' => $dossierId]);
  90.         $results $stmt->fetchAll(\PDO::FETCH_COLUMN);
  91.         return $results;
  92.     }
  93.     public function countAllFromWeb()
  94.     {
  95.         $conn $this->getEntityManager()->getConnection();
  96.         $sql "SELECT wd.id
  97.                 FROM walkinn_dossier wd
  98.                 INNER JOIN kernix_reservation kr ON wd.id = kr.dossier_id;
  99.                 ";
  100.         
  101.         
  102.         $stmt $conn->prepare($sql);
  103.         $stmt->execute();
  104.         $results $stmt->fetchAll();
  105.         return count($results);
  106.     }
  107.     public function infosForCommandesTdb()
  108.     {
  109.         $conn $this->getEntityManager()->getConnection();
  110.         $sql "SELECT 
  111.                     u.id AS utilisateur_id,
  112.                     u.firstname,
  113.                     COUNT(CASE WHEN wd.dossier_etat_id = 4 THEN 1 END) AS done,
  114.                     COUNT(CASE WHEN wd.dossier_etat_id != 4 AND wd.dossier_seen = 1 THEN 1 END) AS doing,
  115.                     COUNT(CASE WHEN wd.dossier_etat_id != 4 AND (wd.dossier_seen IS NULL OR wd.dossier_seen != 1) THEN 1 END) AS todo
  116.                 FROM 
  117.                     ba_user u
  118.                 INNER JOIN doli_user du ON du.rowid = u.uid
  119.                 LEFT JOIN 
  120.                     (
  121.                         SELECT wd.id, wd.charge_dossier_id, wd.dossier_etat_id, wd.dossier_seen
  122.                         FROM walkinn_dossier wd
  123.                         INNER JOIN kernix_reservation kr ON kr.dossier_id = wd.id
  124.                         WHERE wd.actif = 1 AND wd.is_valide = 1
  125.                     ) AS wd ON wd.charge_dossier_id = u.id
  126.                 WHERE u.is_active = 1 AND du.statut = 1 AND du.employee = 1
  127.                 GROUP BY 
  128.                     u.id, u.firstname
  129.                 ORDER BY 
  130.                     u.firstname;
  131.                 ";
  132.         $stmt $conn->prepare($sql);
  133.         $stmt->execute();
  134.         $results $stmt->fetchAll();
  135.         return $results;
  136.     }
  137.     public function findCommandeWebUserToSet($destination_id) {
  138.         /**valeur à renvoyer si aucune trouvée */
  139.         $fallout_value null;
  140.         $conn $this->getEntityManager()->getConnection();
  141.         /** On récupère l'utilisateur affecté à la destination fournie */
  142.         $sql_1 "SELECT rowid
  143.             , ba_user.is_active as user_is_active
  144.             , ba_user.id as user_id
  145.             FROM doli_user_extrafields
  146.             INNER JOIN ba_user ON ba_user.id = doli_user_extrafields.fk_object
  147.             WHERE FIND_IN_SET('" $destination_id "', demandes_destinations) > 0;"
  148.         ;
  149.         $stmt_1 $conn->prepare($sql_1);
  150.         $stmt_1->execute();
  151.         $user_assigned_to_destination $stmt_1->fetch();
  152.         $user_reaffected_to_destination null;
  153.         if ($user_assigned_to_destination) { /** Si je trouve un utilisateur 1 affecté */
  154.             /** On récupère un éventuel utilisateur 2 auquel on aurait réaffecté les dossiers de l'utilisateur 1 */
  155.             $sql_2 "SELECT walkinn_user_dossiers_reattribution.id
  156.                 , u_destination.id as user_id
  157.                 , u_destination.is_active as user_is_active
  158.                 FROM walkinn_user_dossiers_reattribution walkinn_user_dossiers_reattribution
  159.                 INNER JOIN ba_user u_from ON walkinn_user_dossiers_reattribution.user_from_id = u_from.id
  160.                 INNER JOIN ba_user u_destination ON walkinn_user_dossiers_reattribution.user_destination_id = u_destination.id
  161.                 WHERE walkinn_user_dossiers_reattribution.active = 1 AND walkinn_user_dossiers_reattribution.user_from_id = " $user_assigned_to_destination['user_id'] . " AND u_destination.is_active = 1"
  162.             ;
  163.             $stmt_2 $conn->prepare($sql_2);
  164.             $stmt_2->execute();
  165.             $user_reaffected_to_destination $stmt_2->fetch();
  166.             if ($user_reaffected_to_destination && $user_reaffected_to_destination['user_is_active']) { /** Si un utilisateur 2 actif a été réaffecté aux dossiers de cette destination, on retourne l'id de cet utilisateur 2 */
  167.                 $value_to_return $user_reaffected_to_destination['user_id'];
  168.             } else if ($user_assigned_to_destination['user_is_active']) {/** Si aucun utilisateur 2 n'a été réaffecté et que l'utilisateur 1 est actif */
  169.                 $value_to_return $user_assigned_to_destination['user_id'];
  170.             } else {/** Si Si aucun utilisateur 2 n'a été réaffecté et que l'utilisateur 1 est inactif */
  171.                 $value_to_return $fallout_value;
  172.             }
  173.         } else { /** S'il n'y a aucun utilisateur affecté' */
  174.             $value_to_return $fallout_value;
  175.         }
  176.         return $value_to_return;
  177.     }
  178.     
  179.     public function findVoyageurDolibarrByDossier($dossier$type 'email') {
  180.         $conn $this->getEntityManager()->getConnection();
  181.         $sql "SELECT  soc.email, soc.rowid
  182.                 FROM walkinn_dossier d
  183.                 LEFT JOIN walkinn_dossier_segment ds ON ds.dossier_id = d.id
  184.                 LEFT JOIN walkinn_dossier_segment_pax dsp ON dsp.segment_id = ds.id
  185.                 LEFT JOIN doli_socpeople sp ON sp.rowid = dsp.contact_id
  186.                 LEFT JOIN doli_societe soc  ON soc.rowid = sp.fk_soc
  187.                 LEFT JOIN doli_socpeople_extrafields spe ON spe.fk_object = sp.rowid
  188.                 WHERE 1 = 1
  189.                   AND d.id = :id
  190.                   -- AND soc.email = sp.email
  191.                   AND soc.email IS NOT NULL
  192.                   AND soc.email != ''
  193.                   ";
  194.         $stmt $conn->prepare($sql);
  195.         $stmt->execute([':id' => $dossier->getId()]);
  196.         $results $stmt->fetchAll();
  197.         return $results[0][$type] ?? null;
  198.     }
  199.     // type : 'supp' ou 'reduc'
  200.     public function findLignesForKernix($dossierId$type 'supp'
  201.     {
  202.         $dossier $this->findOneById($dossierId);
  203.         $lignes = [];
  204.         if (null !== $dossier->getKernixReservation()) {
  205.             foreach ($dossier->getKernixReservation()->getKernixReservationLignes() as $ligne) {
  206.                 if ($type == $ligne->getTypeLigne()) {
  207.                     $arr = [
  208.                         'montant'  => abs($ligne->getMontant())
  209.                       , 'libelle'  => $ligne->getLibelle()
  210.                       , 'quantite' => $ligne->getQuantite()
  211.                       , 'code'     => $ligne->getCode()
  212.                     ];
  213.                     $lignes[] = $arr;
  214.                 }
  215.             }
  216.         }
  217.         return $lignes;
  218.     }
  219.     public function findParticipantsForKernix($dossierId)
  220.     {
  221.         $conn $this->getEntityManager()->getConnection();
  222.         $sql "SELECT  
  223.                        sp.rowid                      AS contact_id 
  224.                      , sp.lastname                   AS nom
  225.                      , sp.firstname                  AS prenom
  226.                      , sp.address                    AS `adresse`
  227.                      , sp.zip                        AS code_postal
  228.                      , sp.town                       AS ville
  229.                      , cc.code                       AS pays
  230.                      , sp.birthday                   AS date_naissance
  231.                      , sp.email                      AS email
  232.                      , sp.default_lang               AS langue
  233.                      , spe.taille                    AS taille    
  234.                      , spe.taille_pied               AS taille_pied                
  235.                      , spe.taille_pouce              AS taille_pouce
  236.                      , spe.taille_pied_pouce         AS taille_pied_pouce
  237.                      , spe.location_velo             AS location_velo
  238.                      , spe.velo                      AS velo
  239.                      , spe.prix_velo                 AS prix_velo
  240.                      , spe.souscription_assurance    AS souscription_assurance
  241.                      , spe.location_casque           AS location_casque
  242.                      , IFNULL(dsp.is_sup_single,0)   AS supp_single
  243.                 FROM walkinn_dossier d
  244.                 LEFT JOIN walkinn_dossier_segment ds ON ds.dossier_id = d.id
  245.                 INNER JOIN walkinn_dossier_segment_pax dsp ON dsp.segment_id = ds.id
  246.                 INNER JOIN doli_socpeople sp ON sp.rowid = dsp.contact_id
  247.                 LEFT JOIN doli_c_country cc ON cc.rowid = sp.fk_pays
  248.                 LEFT JOIN doli_societe soc  ON soc.rowid = sp.fk_soc
  249.                 LEFT JOIN doli_socpeople_extrafields spe ON spe.fk_object = sp.rowid
  250.                 -- LEFT JOIN doli_societe_contacts sc ON sc.fk_soc = soc.rowid AND sc.fk_socpeople = sp.rowid
  251.                 -- LEFT JOIN doli_c_type_contact ctc ON ctc.rowid = sc.fk_c_type_contact
  252.                 WHERE 1 = 1
  253.                   AND d.id = :dossierId
  254.                   AND ds.actif = 1
  255.                   AND dsp.actif = 1
  256.                   GROUP BY d.id, sp.rowid 
  257.                   ";
  258.         $stmt $conn->prepare($sql);
  259.         $stmt->execute([':dossierId' => $dossierId]);
  260.         $results $stmt->fetchAll();
  261.         //$return = [];
  262.         //foreach ($results as $key => $result) {
  263.         //    $return[$result['dossier_id']][] = $result;
  264.         //}
  265.         return $results;
  266.     }
  267.     public function findAjustementsForKernix($dossierId)
  268.     {
  269.         $conn $this->getEntityManager()->getConnection();
  270.         $sql "SELECT  
  271.                        a.id                   AS ajustement_id
  272.                     ,  ds.prix_vente          AS montant
  273.                     ,  ds.dossier_id          AS dossier_id
  274.                     ,  ds.id                  AS segment_id
  275.                     ,  ds.date_depart         AS date_depart
  276.                     ,  DATE_ADD(ds.date_depart, INTERVAL ds.nb_jours DAY) AS date_retour         
  277.                     ,  ds.nb_jours            AS nb_jours
  278.                     ,  a.type_id              AS type_id
  279.                 FROM walkinn_dossier_segment ds
  280.                 INNER JOIN walkinn_ajustement a ON a.prestation_id = ds.voyage_id
  281.                 INNER JOIN walkinn_voyage_ajustement va ON va.voyage_id = (SELECT MAX(voyage_id)
  282.                                                                            FROM walkinn_dossier_segment 
  283.                                                                            WHERE walkinn_dossier_segment.dossier_id = :dossierId AND is_prestation_seche = 0) 
  284.                 WHERE 1 = 1
  285.                   AND ds.dossier_id = :dossierId
  286.                   AND ds.actif = 1
  287.                   AND ds.is_prestation_seche = 1
  288.                   AND va.ajustement_id = a.id
  289.                   ";
  290.         $stmt $conn->prepare($sql);
  291.         $stmt->execute([':dossierId' => $dossierId]);
  292.         $ajustements $stmt->fetchAll();
  293.         $rows = [];
  294.         foreach ($ajustements as $ajustement) {
  295.             $dateExtra   = (in_array($ajustement['type_id'], [3,5,7])) ? true false
  296.             $id          $ajustement['ajustement_id'];
  297.             $segmentId   $ajustement['segment_id'];
  298.             $montant     $ajustement['montant'];
  299.             $dates       = [];
  300.             if (true === $dateExtra) {
  301.                 $dates[] = $ajustement['date_depart'];
  302.                 if ($ajustement['nb_jours'] > 1) {
  303.                     $dates[] = $ajustement['date_retour'];
  304.                 } 
  305.             }
  306.             $sql "SELECT  
  307.                     p.contact_id  AS contact_id,
  308.                     sp.service_id AS tarif_id
  309.                     FROM walkinn_dossier_segment ds
  310.                     INNER JOIN walkinn_dossier_segment_pax p ON p.segment_id = ds.id
  311.                     LEFT  JOIN walkinn_dossier_segment_service_pax sp ON sp.dossier_segment_pax_id = p.id
  312.                     WHERE 1 = 1
  313.                       AND p.actif = 1
  314.                       AND ds.id = :segmentId
  315.                     GROUP BY p.contact_id
  316.                       ";
  317.             $stmt $conn->prepare($sql);
  318.             $stmt->execute([':segmentId' => $segmentId]);
  319.             $participants $stmt->fetchAll();
  320.             if (!isset($rows[$id])) {
  321.                 $rows[$id] = [
  322.                     "id" => $id,
  323.                     "data" => [
  324.                         [
  325.                             "montant" => $montant,
  326.                             "dates"   => $dates,
  327.                             "participants" => $participants,
  328.                         ]
  329.                     ]
  330.                 ];
  331.             } else {
  332.                 $rows[$id]['data'][] = [
  333.                     "montant" => $montant,
  334.                     "dates"   => $dates,
  335.                     "participants" => $participants,
  336.                 ];
  337.             }
  338.         }
  339.         
  340.         return array_values($rows);
  341.     }
  342.     public function findHebergementsForKernix($dossierId)
  343.     {
  344.         $conn $this->getEntityManager()->getConnection();
  345.         $sql "SELECT  
  346.            r.id, pr.code, r.numero_chambre, p.contact_id AS contact_id
  347.                 FROM walkinn_dossier_segment ds
  348.                 INNER JOIN walkinn_dossier_segment_pax p ON p.segment_id = ds.id
  349.                 INNER JOIN walkinn_dossier_segment_pax_rooming r ON r.id = p.rooming_id
  350.                 INNER JOIN walkinn_pax_rooming pr ON pr.id = r.pax_rooming_id
  351.                 WHERE 1 = 1
  352.                   AND ds.dossier_id = :dossierId
  353.                   AND ds.actif = 1
  354.                   AND ds.is_prestation_seche = 0 
  355.                   ";
  356.         $stmt $conn->prepare($sql);
  357.         $stmt->execute([':dossierId' => $dossierId]);
  358.         $results $stmt->fetchAll();
  359.         $rows = [];
  360.         foreach ($results as $item) {
  361.             $key $item['code'] . '|' $item['numero_chambre'];
  362.         
  363.             if (!isset($rows[$key])) {
  364.                 $n 0;
  365.                 $rows[$key] = [
  366.                     'code' => $item['code'],
  367.                     'numero_chambre' => $item['numero_chambre'],
  368.                     'participants' => []
  369.                 ];
  370.             }
  371.         
  372.             $rows[$key]['participants'][] = [
  373.                 'contact_id' => $item['contact_id'],
  374.                 //'numero'     => count($rows[$key]['participants'])
  375.             ];
  376.         }
  377.         return array_values($rows);
  378.     }
  379.     public function findActivitesForKernix($dossierId)
  380.     {
  381.         $conn $this->getEntityManager()->getConnection();
  382.         $sql "
  383.             SELECT  
  384.                 we.id          AS id,
  385.                 dsp.contact_id AS contact_id
  386.             FROM walkinn_service AS serv
  387.             INNER JOIN walkinn_dossier_segment_service dss ON dss.service_id = serv.id AND dss.actif=1
  388.             INNER JOIN walkinn_dossier_segment ds ON ds.id = dss.segment_id AND ds.dossier_id = :dossierId AND ds.is_prestation_seche = 0 AND ds.actif = 1
  389.             INNER JOIN walkinn_voyage v ON v.id = ds.voyage_id
  390.             INNER JOIN walkinn_voyage_service vs ON vs.voyage_id = v.id AND vs.service_id = serv.id AND vs.actif = 1
  391.             INNER JOIN walkinn_editorial we ON we.service_id = serv.id
  392.             INNER JOIN walkinn_dossier_segment_service_pax dssp ON dssp.dossier_segment_service_id = dss.id AND dssp.actif = 1
  393.             INNER JOIN walkinn_dossier_segment_pax dsp ON dsp.id = dssp.dossier_segment_pax_id
  394.             WHERE 1 = 1
  395.             AND serv.type_id = :serviceTypeId";
  396.         $stmt $conn->prepare($sql);
  397.         $stmt->execute([':dossierId' => $dossierId':serviceTypeId' => \App\Enum\ServiceTypeEnum::ACTIVITE]);
  398.         $results $stmt->fetchAll();
  399.         
  400.         $grouped = [];
  401.         foreach ($results as $row) {
  402.             $id $row['id'];
  403.             if (!isset($grouped[$id])) {
  404.                 $grouped[$id] = [
  405.                     'id' => $id,
  406.                     'participants' => []
  407.                 ];
  408.             }
  409.         
  410.             $grouped[$id]['participants'][] = [
  411.                 'contact_id' => $row['contact_id'],
  412.                 //'numero' => count($grouped[$id]['participants'])
  413.             ];
  414.         }
  415.         
  416.         return array_values($grouped);
  417.     }
  418.     public function findLivraisonPropalForKernix($dossierId)
  419.     {
  420.         $element "propal";
  421.         return $this->findLivraisonForKernix($dossierId$element);
  422.     }
  423.     public function findLivraisonForKernix($dossierId$element)
  424.     {
  425.         $code    "SHIPPING";
  426.         return $this->findAdresseForKernix($dossierId$element$code);
  427.     }
  428.     public function findFacturationForKernix($dossierId$element)
  429.     {
  430.         $code    "BILLING";
  431.         return $this->findAdresseForKernix($dossierId$element$code);
  432.     }
  433.     public function findAdresseForKernix($dossierId$element$code)
  434.     {
  435.         $conn $this->getEntityManager()->getConnection();
  436.         $txt "";
  437.         if ($code == 'SHIPPING') {
  438.             $txt .= "
  439.                          , IF( ctc.rowid IS NOT NULL, spe.mode_transport  , spe.mode_transport   ) AS mode_transport 
  440.                          , IF( ctc.rowid IS NOT NULL, spe.format_livraison, spe.format_livraison ) AS format_livraison
  441.                          , IF( ctc.rowid IS NOT NULL, spe.lieu_livraison  , spe.lieu_livraison   ) AS lieu_livraison 
  442.                          , IF( ctc.rowid IS NOT NULL, spe.societe         , spe.societe          ) AS societe ";
  443.         }
  444.         $sql "SELECT  
  445.                        IF( ctc.rowid IS NOT NULL, sp.rowid            , sp.rowid             ) AS contact_id 
  446.                      , IF( ctc.rowid IS NOT NULL, sp.lastname         , sp.lastname          ) AS nom
  447.                      , IF( ctc.rowid IS NOT NULL, sp.firstname        , sp.firstname         ) AS prenom
  448.                      , IF( ctc.rowid IS NOT NULL, sp.phone_mobile     , sp.phone_mobile      ) AS telephone
  449.                      , IF( ctc.rowid IS NOT NULL, sp.email            , sp.email             ) AS email 
  450.                      , IF( ctc.rowid IS NOT NULL, sp.address          , sp.address           ) AS `adresse`
  451.                      , IF( ctc.rowid IS NOT NULL, sp.zip              , sp.zip               ) AS code_postal
  452.                      , IF( ctc.rowid IS NOT NULL, sp.town             , sp.town              ) AS ville
  453.                      , IF( ctc.rowid IS NOT NULL, cc.code             , sp.fk_pays           ) AS pays
  454.                      , IF( ctc.rowid IS NOT NULL, sp.default_lang     , sp.default_lang      ) AS langue
  455.                      {$txt}
  456.                      -- , ctc.*
  457.                 FROM walkinn_dossier d
  458.                 LEFT JOIN walkinn_dossier_segment ds ON ds.dossier_id = d.id
  459.                 LEFT JOIN walkinn_dossier_segment_pax dsp ON dsp.segment_id = ds.id
  460.                 LEFT JOIN doli_socpeople sp1 ON sp1.rowid = dsp.contact_id
  461.                 LEFT JOIN doli_societe soc  ON soc.rowid = sp1.fk_soc
  462.                 LEFT JOIN doli_socpeople sp ON soc.rowid = sp.fk_soc
  463.                 LEFT JOIN doli_c_country cc ON cc.rowid = sp.fk_pays
  464.                 LEFT JOIN doli_socpeople_extrafields spe ON spe.fk_object = sp.rowid
  465.                 LEFT JOIN doli_societe_contacts sc ON sc.fk_soc = soc.rowid AND sc.fk_socpeople = sp.rowid
  466.                 LEFT JOIN doli_c_type_contact ctc ON ctc.rowid = sc.fk_c_type_contact
  467.                 WHERE 1 = 1
  468.                   AND d.id = :dossierId
  469.                   AND ctc.element = :element
  470.                   AND ctc.code    = :code
  471.                   GROUP BY d.id, soc.rowid 
  472.                   
  473.                   ";
  474.         $stmt $conn->prepare($sql);
  475.         $stmt->execute([':dossierId' => $dossierId':element' => $element':code' => $code]);
  476.         $results $stmt->fetchAll();
  477.         return $results;
  478.     }
  479.     public function findPaymentsForKernix($factureId$isPending)
  480.     {
  481.         $conn $this->getEntityManager()->getConnection();
  482.         if ($isPending == 1) {
  483.             $txt "";
  484.             $sql "SELECT  
  485.                          kp.montant             AS 'montant',
  486.                          kp.mode_paiement       AS 'mode_paiement',
  487.                          kp.code_reduction      AS 'code_reduction',
  488.                          kp.emetteur            AS 'emetteur'
  489.                     --     kp.created_at          AS 'date'
  490.                          {$txt}
  491.                     FROM kernix_reservation kr
  492.                     INNER JOIN kernix_reservation_paiement kp ON kp.reservation_id = kr.id
  493.                     WHERE 1 = 1
  494.                       AND kr.facture_id = :factureId ";
  495.             $stmt $conn->prepare($sql);
  496.             $stmt->execute([':factureId' => $factureId]);
  497.         }
  498.         else {
  499.             $txt "";
  500.             $sql "SELECT  
  501.                          pay.amount             AS 'montant',
  502.                          dp.fk_paiement         AS 'mode_paiement',
  503.                          dp.note                AS 'code_reduction',
  504.                          db.emetteur            AS 'emetteur'
  505.                     --     dp.datec               AS 'date'
  506.                          {$txt}
  507.                     FROM doli_paiement_facture pay
  508.                     INNER JOIN doli_paiement dp ON dp.rowid = pay.fk_paiement
  509.                     LEFT JOIN doli_bank db ON db.rowid = dp.fk_bank
  510.                     WHERE 1 = 1
  511.                       AND pay.fk_facture = :rowId ";
  512.             $stmt $conn->prepare($sql);
  513.             $stmt->execute([':rowId' => $factureId]);
  514.         }
  515.         $results $stmt->fetchAll();
  516.         return $results;
  517.     }
  518.     public function findPaymentsForKernixByDossierId($dossierId$isPending)
  519.     {
  520.         $conn $this->getEntityManager()->getConnection();
  521.         if ($isPending == 1) {
  522.             $txt "";
  523.             $sql "SELECT  
  524.                          ROUND(kp.montant,2)           AS 'montant',
  525.                          kp.mode_paiement              AS 'mode_paiement',
  526.                          IFNULL(kp.code_reduction, '') AS 'code_reduction',
  527.                          IFNULL(kp.emetteur, '')       AS 'emetteur'
  528.                     --     kp.created_at               AS 'date'
  529.                          {$txt}
  530.                     FROM kernix_reservation kr
  531.                     INNER JOIN kernix_reservation_paiement kp ON kp.reservation_id = kr.id
  532.                     WHERE 1 = 1
  533.                       AND kr.dossier_id = :dossierId ";
  534.             $stmt $conn->prepare($sql);
  535.             $stmt->execute([':dossierId' => $dossierId]);
  536.         }
  537.         else {
  538.             $txt "";
  539.             $sql "SELECT  
  540.                          ROUND(pay.amount,2)      AS 'montant',
  541.                          dp.fk_paiement           AS 'mode_paiement',
  542.                          IFNULL(dp.note, '')      AS 'code_reduction',
  543.                          IFNULL(db.emetteur, '')  AS 'emetteur'
  544.                     --     dp.datec               AS 'date'
  545.                          {$txt}
  546.                     FROM doli_paiement_facture pay
  547.                     INNER JOIN doli_paiement dp ON dp.rowid = pay.fk_paiement
  548.                     LEFT JOIN doli_bank db ON db.rowid = dp.fk_bank
  549.                     LEFT JOIN kernix_reservation kr ON kr.facture_id = pay.fk_facture
  550.                     WHERE 1 = 1
  551.                       AND kr.dossier_id = :dossierId ";
  552.             $stmt $conn->prepare($sql);
  553.             $stmt->execute([':dossierId' => $dossierId]);
  554.         }
  555.         $results $stmt->fetchAll();
  556.         return $results;
  557.     }
  558.     // /**
  559.     //  * @return Dossier[] Returns an array of Dossier objects
  560.     //  */
  561.     /*
  562.     public function findByExampleField($value)
  563.     {
  564.         return $this->createQueryBuilder('d')
  565.             ->andWhere('d.exampleField = :val')
  566.             ->setParameter('val', $value)
  567.             ->orderBy('d.id', 'ASC')
  568.             ->setMaxResults(10)
  569.             ->getQuery()
  570.             ->getResult()
  571.         ;
  572.     }
  573.     */
  574.     /*
  575.     public function findOneBySomeField($value): ?Dossier
  576.     {
  577.         return $this->createQueryBuilder('d')
  578.             ->andWhere('d.exampleField = :val')
  579.             ->setParameter('val', $value)
  580.             ->getQuery()
  581.             ->getOneOrNullResult()
  582.         ;
  583.     }
  584.     */
  585. }