GET https://demosymph.omnipilote.ma/fr/dashboard/tickets/2618/ticket_fermer_details

Query Metrics

18 Database Queries
16 Different statements
55.11 ms Query time
6 Invalid entities
23 Managed entities

Grouped Statements

Show all queries

default connection

Time Count Info
19.67 ms
(35.68%)
1
WITH base AS (
    SELECT
        -- ====== aliases  ======
        ct.id  AS contrat_id,
        t.id   AS tickets,
        COALESCE(p.volume_mensel_recommande, dg.volume_mensel_recommande) AS volume_mensel_recommande,
        ct.type_contrat,
        p.name       AS designation,
        p.reference,
        c.name       AS raison_social,
        t.serie,
        t.comment    AS description_ticket,
        tc_last.comment   AS resolution,
        t.type_ticket,
        t.adresse,
        t.created_at,
        t.closed_at,
        COALESCE(t.compteur_mono_a4,0) + COALESCE(t.compteur_mono_a3,0) + COALESCE(t.compteur_mono_gf,0)
          + COALESCE(t.compteur_color_a4,0) + COALESCE(t.compteur_color_a3,0) + COALESCE(t.compteur_color_gf,0)
          AS total_compteur,
        COALESCE(p.limite_depassement, dg.limit_depasement) AS limit_depasement,

        -- prev_created_at  (LAG)
        LAG(t.created_at) OVER (PARTITION BY t.serie ORDER BY t.created_at, t.id) AS prev_created_at,

        -- JSON affectations  subquery  
        (
          SELECT COALESCE(JSON_ARRAYAGG(x.item), JSON_ARRAY())
          FROM (
            SELECT JSON_OBJECT(
                     'affectation_id', af.id,
                     'user_id', u.id,
                     'name', CONCAT(u.first_name, ' ', u.last_name),
                     'date', af.date_preview_start
                   ) AS item
            FROM affectation af
            JOIN affectation_user au ON au.affectation_id = af.id
            JOIN user u ON u.id = au.user_id
            WHERE 
            -- af.etat = 1 AND
             af.ticket_id = t.id
            ORDER BY af.date_preview_start DESC
            LIMIT 1
          ) x
        ) AS affectations,

        tc_cat.name AS category_name,
        c.id  AS client_id,
        c.mail

    FROM tickets t
    LEFT JOIN product p        ON p.id  = t.product_id
    LEFT JOIN contrat ct       ON ct.id = t.contrat_id
    LEFT JOIN client  c        ON c.id  = ct.client_id
    LEFT JOIN ticket_category tc_cat ON tc_cat.id = t.ticket_category_id

    --  commentaire per ticket
    LEFT JOIN (
      SELECT tc1.ticket_id, tc1.comment
      FROM tickets_comments tc1
      WHERE tc1.created_at = (
        SELECT MAX(tc2.created_at)
        FROM tickets_comments tc2
        WHERE tc2.ticket_id = tc1.ticket_id
      )
    ) tc_last ON tc_last.ticket_id = t.id

    LEFT JOIN setting dg ON dg.company_id = ?

    WHERE t.serie  = ?
      AND t.status = 2
)

SELECT
  b.contrat_id,
  b.tickets,
  b.volume_mensel_recommande,
  b.type_contrat,
  b.designation,
  b.reference,
  b.raison_social,
  b.serie,
  b.description_ticket,
  b.resolution,
  b.type_ticket,
  b.adresse,
  b.created_at,
  b.closed_at,
  b.total_compteur,
  b.limit_depasement,
  b.affectations,
  b.category_name,

  -- diff en minutes entre ticket courant   
  TIMESTAMPDIFF(
    MINUTE,
    COALESCE(b.prev_created_at, b.created_at),
    b.created_at
  ) AS diff_minutes,

  -- cumul en minutes
  SUM(
    TIMESTAMPDIFF(
      MINUTE,
      COALESCE(b.prev_created_at, b.created_at),
      b.created_at
    )
  ) OVER (
    PARTITION BY b.serie
    ORDER BY b.created_at, b.tickets
    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
  ) AS cum_minutes,

  -- cumul en jours
  ROUND(
    SUM(
      TIMESTAMPDIFF(
        MINUTE,
        COALESCE(b.prev_created_at, b.created_at),
        b.created_at
      )
    ) OVER (
      PARTITION BY b.serie
      ORDER BY b.created_at, b.tickets
      ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) / 1440.0
  , 1) AS jours_cumules,

  -- cumul en mois (~30 jours)
  ROUND(
    SUM(
      TIMESTAMPDIFF(
        MINUTE,
        COALESCE(b.prev_created_at, b.created_at),
        b.created_at
      )
    ) OVER (
      PARTITION BY b.serie
      ORDER BY b.created_at, b.tickets
      ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
    ) / (1440.0 * 30)
  , 1) AS mois_cumules,

  -- Volume mensuel moyen = total_compteur / mois_cumules
  ROUND(
    b.total_compteur / NULLIF(
      (
        SUM(
          TIMESTAMPDIFF(
            MINUTE,
            COALESCE(b.prev_created_at, b.created_at),
            b.created_at
          )
        ) OVER (
          PARTITION BY b.serie
          ORDER BY b.created_at, b.tickets
          ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
        ) / (1440.0 * 30)
      ), 0
    )
  , 0) AS volume_mensuel_moyen,

  -- Taux d'utilisation = (volume_mensuel_moyen / recommandé) * 100
  ROUND(
    (
      b.total_compteur / NULLIF(
        (
          SUM(
            TIMESTAMPDIFF(
              MINUTE,
              COALESCE(b.prev_created_at, b.created_at),
              b.created_at
            )
          ) OVER (
            PARTITION BY b.serie
            ORDER BY b.created_at, b.tickets
            ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
          ) / (1440.0 * 30)
        ), 0
      )
    ) / b.volume_mensel_recommande * 100
  , 0) AS taux_utilisation,

  CASE
   WHEN b.total_compteur IS NULL
    OR b.volume_mensel_recommande IS NULL
    OR b.volume_mensel_recommande = 0
    OR b.type_ticket LIKE '%Installation%'
    OR (
      SUM(
        TIMESTAMPDIFF(
          MINUTE,
          COALESCE(b.prev_created_at, b.created_at),
          b.created_at
        )
      ) OVER (
        PARTITION BY b.serie
        ORDER BY b.created_at, b.tickets
        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
      )
    ) IS NULL OR   ROUND(
    (
      b.total_compteur / NULLIF(
        (
          SUM(
            TIMESTAMPDIFF(
              MINUTE,
              COALESCE(b.prev_created_at, b.created_at),
              b.created_at
            )
          ) OVER (
            PARTITION BY b.serie
            ORDER BY b.created_at, b.tickets
            ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
          ) / (1440.0 * 30)
        ), 0
      )
    ) / b.volume_mensel_recommande * 100
  , 0) IS NULL
    THEN NULL

   WHEN ROUND(
     (
       b.total_compteur / NULLIF(
         (
           SUM(
             TIMESTAMPDIFF(
               MINUTE,
               COALESCE(b.prev_created_at, b.created_at),
               b.created_at
             )
           ) OVER (
             PARTITION BY b.serie
             ORDER BY b.created_at, b.tickets
             ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
           ) / (1440.0 * 30)
         ), 0
       )
     ) / b.volume_mensel_recommande * 100
   , 0) > b.limit_depasement
     THEN 'Attention volume mensuel élevé'

   WHEN ROUND(
     (
       b.total_compteur / NULLIF(
         (
           SUM(
             TIMESTAMPDIFF(
               MINUTE,
               COALESCE(b.prev_created_at, b.created_at),
               b.created_at
             )
           ) OVER (
             PARTITION BY b.serie
             ORDER BY b.created_at, b.tickets
             ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
           ) / (1440.0 * 30)
         ), 0
       )
     ) / b.volume_mensel_recommande * 100
   , 0) < 30
     THEN 'Équipement peu utilisé'

   ELSE 'Utilisation mensuelle normale'
  END AS message,

  b.client_id,
  b.mail

FROM base b
ORDER BY b.created_at DESC, b.tickets DESC
Parameters:
[
  1
  "1AE5100698"
]
5.27 ms
(9.56%)
1
SELECT t0.id AS id_1, t0.started_at AS started_at_2, t0.ended_at AS ended_at_3, t0.status AS status_4, t0.affectation_id AS affectation_id_5, t0.added_by_id AS added_by_id_6 FROM affectation_sequances t0 WHERE t0.affectation_id = ?
Parameters:
[
  2384
]
4.83 ms
(8.76%)
2
SELECT t0.id AS id_1, t0.name AS name_2 FROM type_attribute t0
Parameters:
[]
4.50 ms
(8.16%)
1
SELECT t0.id AS id_1, t0.email AS email_2, t0.roles AS roles_3, t0.password AS password_4, t0.is_active AS is_active_5, t0.reset_token AS reset_token_6, t0.first_name AS first_name_7, t0.last_name AS last_name_8, t0.created_at AS created_at_9, t0.updated_at AS updated_at_10, t0.civility AS civility_11, t0.telephone AS telephone_12, t0.company_id AS company_id_13, t14.id AS id_15, t14.email AS email_16, t14.date_of_birth AS date_of_birth_17, t14.created_at AS created_at_18, t14.salary AS salary_19, t14.last_name AS last_name_20, t14.first_name AS first_name_21, t14.civility AS civility_22, t14.telephone AS telephone_23, t14.department_id AS department_id_24, t14.fonction_id AS fonction_id_25, t14.user_id AS user_id_26 FROM user t0 LEFT JOIN employee t14 ON t14.user_id = t0.id WHERE t0.id = ?
Parameters:
[
  3
]
4.47 ms
(8.11%)
1
SELECT d0_.id AS id_0, d0_.type AS type_1, d0_.etat AS etat_2, d0_.created_at AS created_at_3, d0_.upadted_at AS upadted_at_4, d0_.montant AS montant_5, d0_.remise AS remise_6, d0_.duree AS duree_7, d0_.version AS version_8, d0_.devis_id AS devis_id_9, d0_.ticket_id AS ticket_id_10 FROM devis_intervenstion d0_ WHERE d0_.ticket_id = ? AND d0_.type = 'Diagnostique' ORDER BY d0_.version DESC LIMIT 1
Parameters:
[
  2618
]
2.91 ms
(5.28%)
2
SELECT t0.id AS id_1, t0.created_at AS created_at_2, t0.etat AS etat_3, t0.date_start AS date_start_4, t0.comment AS comment_5, t0.date_preview_end AS date_preview_end_6, t0.date_end AS date_end_7, t0.date_preview_start AS date_preview_start_8, t0.ticket_id AS ticket_id_9 FROM affectation t0 WHERE t0.ticket_id = ?
Parameters:
[
  2618
]
2.46 ms
(4.47%)
1
SELECT t0.id AS id_1, t0.logo AS logo_2, t0.rc AS rc_3, t0.ice AS ice_4, t0.address AS address_5, t0.code_postal AS code_postal_6, t0.ville AS ville_7, t0.pays AS pays_8, t0.email AS email_9, t0.id_fiscal AS id_fiscal_10, t0.phone AS phone_11, t0.fax AS fax_12, t0.currency AS currency_13, t0.exchange_rates AS exchange_rates_14, t0.cost AS cost_15, t0.ca AS ca_16, t0.week_work_hours AS week_work_hours_17, t0.day_work_hours AS day_work_hours_18, t0.workload_breakdown AS workload_breakdown_19, t0.cost_per_hour AS cost_per_hour_20, t0.dig_price AS dig_price_21, t0.ca_breakdown AS ca_breakdown_22, t0.marge AS marge_23, t0.marge_attribute AS marge_attribute_24, t0.marge_min AS marge_min_25, t0.marge_min_attribute AS marge_min_attribute_26, t0.contrat_title AS contrat_title_27, t0.contrat_service_titre AS contrat_service_titre_28, t0.interfacing AS interfacing_29, t0.limit_depasement AS limit_depasement_30, t0.notification_signature_contrat AS notification_signature_contrat_31, t0.notification_fin_contrat AS notification_fin_contrat_32, t0.envoi_automatique_factures AS envoi_automatique_factures_33, t0.volume_mensel_recommande AS volume_mensel_recommande_34, t0.show_all_pieces AS show_all_pieces_35, t0.show_all_consommable AS show_all_consommable_36, t0.permissions_version AS permissions_version_37, t0.company_id AS company_id_38, t0.contrat_emplacement_id AS contrat_emplacement_id_39 FROM setting t0 WHERE t0.company_id = ?
Parameters:
[
  2
]
2.20 ms
(3.99%)
1
SELECT t0.id AS id_1, t0.name AS name_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4 FROM roles t0 INNER JOIN user_roles ON t0.id = user_roles.roles_id WHERE user_roles.user_id = ?
Parameters:
[
  3
]
1.17 ms
(2.12%)
1
SELECT t0.id AS id_1, t0.email AS email_2, t0.roles AS roles_3, t0.password AS password_4, t0.is_active AS is_active_5, t0.reset_token AS reset_token_6, t0.first_name AS first_name_7, t0.last_name AS last_name_8, t0.created_at AS created_at_9, t0.updated_at AS updated_at_10, t0.civility AS civility_11, t0.telephone AS telephone_12, t0.company_id AS company_id_13, t14.id AS id_15, t14.email AS email_16, t14.date_of_birth AS date_of_birth_17, t14.created_at AS created_at_18, t14.salary AS salary_19, t14.last_name AS last_name_20, t14.first_name AS first_name_21, t14.civility AS civility_22, t14.telephone AS telephone_23, t14.department_id AS department_id_24, t14.fonction_id AS fonction_id_25, t14.user_id AS user_id_26 FROM user t0 LEFT JOIN employee t14 ON t14.user_id = t0.id INNER JOIN affectation_user ON t0.id = affectation_user.user_id WHERE affectation_user.affectation_id = ?
Parameters:
[
  2384
]
1.17 ms
(2.12%)
1
SELECT t0.id AS id_1, t0.serie AS serie_2, t0.reference AS reference_3, t0.designation AS designation_4, t0.type_ticket AS type_ticket_5, t0.email AS email_6, t0.adresse AS adresse_7, t0.phone AS phone_8, t0.comment AS comment_9, t0.ref_ticket AS ref_ticket_10, t0.is_referenced AS is_referenced_11, t0.closed_at AS closed_at_12, t0.created_at AS created_at_13, t0.updated_at AS updated_at_14, t0.status AS status_15, t0.compteur_mono_a4 AS compteur_mono_a4_16, t0.compteur_mono_a3 AS compteur_mono_a3_17, t0.compteur_mono_gf AS compteur_mono_gf_18, t0.compteur_color_a4 AS compteur_color_a4_19, t0.compteur_color_a3 AS compteur_color_a3_20, t0.compteur_color_gf AS compteur_color_gf_21, t0.description_file AS description_file_22, t0.code_machine AS code_machine_23, t0.ville AS ville_24, t0.contrat_id AS contrat_id_25, t0.product_id AS product_id_26, t0.client_id AS client_id_27, t0.user_id AS user_id_28, t0.ticket_category_id AS ticket_category_id_29 FROM tickets t0 WHERE t0.id = ?
Parameters:
[
  "2618"
]
1.15 ms
(2.09%)
1
SELECT t0.id AS id_1, t0.name AS name_2, t0.mail AS mail_3, t0.phone AS phone_4, t0.website AS website_5, t0.address AS address_6, t0.code_postal AS code_postal_7, t0.ville AS ville_8, t0.ref AS ref_9, t0.created_at AS created_at_10, t0.updated_at AS updated_at_11, t0.ice AS ice_12, t0.rc AS rc_13, t0.code_client AS code_client_14, t0.sage_sync AS sage_sync_15, t0.client_type_id AS client_type_id_16, t0.user_id AS user_id_17, t0.commercial_id AS commercial_id_18 FROM client t0 WHERE t0.id = ?
Parameters:
[
  582
]
1.15 ms
(2.08%)
1
SELECT t0.id AS id_1, t0.full_name AS full_name_2, t0.phone AS phone_3, t0.mail AS mail_4, t0.contact_function AS contact_function_5, t0.client_id AS client_id_6 FROM contact t0 WHERE t0.client_id = ? AND t0.contact_function = ? LIMIT 1
Parameters:
[
  582
  "Contact technique"
]
1.09 ms
(1.98%)
1
SELECT t0.id AS id_1, t0.version AS version_2, t0.type_contrat AS type_contrat_3, t0.adresse_facturation AS adresse_facturation_4, t0.ref_band_commande AS ref_band_commande_5, t0.statut AS statut_6, t0.periodicite_facturation AS periodicite_facturation_7, t0.premiere_mensualite AS premiere_mensualite_8, t0.terme_facturation AS terme_facturation_9, t0.action_aterme AS action_aterme_10, t0.val_decote AS val_decote_11, t0.loyers AS loyers_12, t0.sepatare_factures AS sepatare_factures_13, t0.preventive AS preventive_14, t0.ref_contrat AS ref_contrat_15, t0.created_at AS created_at_16, t0.updated_at AS updated_at_17, t0.sla AS sla_18, t0.delivery_status AS delivery_status_19, t0.sage_sync AS sage_sync_20, t0.numero_contrat AS numero_contrat_21, t0.date_start_contrat AS date_start_contrat_22, t0.client_id AS client_id_23, t0.devis_id AS devis_id_24, t0.added_by_id AS added_by_id_25 FROM contrat t0 WHERE t0.id = ?
Parameters:
[
  3543
]
1.09 ms
(1.97%)
1
SELECT t0.id AS id_1, t0.created_at AS created_at_2, t0.updated_at AS updated_at_3, t0.comment AS comment_4, t0.ticket_id AS ticket_id_5, t0.added_by_id AS added_by_id_6 FROM tickets_comments t0 WHERE t0.ticket_id = ?
Parameters:
[
  2618
]
1.06 ms
(1.92%)
1
SELECT d0_.id AS id_0, d0_.type AS type_1, d0_.etat AS etat_2, d0_.created_at AS created_at_3, d0_.upadted_at AS upadted_at_4, d0_.montant AS montant_5, d0_.remise AS remise_6, d0_.duree AS duree_7, d0_.version AS version_8, d0_.devis_id AS devis_id_9, d0_.ticket_id AS ticket_id_10 FROM devis_intervenstion d0_ WHERE d0_.ticket_id = ? AND d0_.type = 'Intervention' ORDER BY d0_.version DESC LIMIT 1
Parameters:
[
  2618
]
0.94 ms
(1.70%)
1
SELECT t0.id AS id_1, t0.name AS name_2, t0.price AS price_3, t0.reference AS reference_4, t0.created_at AS created_at_5, t0.description AS description_6, t0.type AS type_7, t0.number_users AS number_users_8, t0.number_pages AS number_pages_9, t0.is_exist AS is_exist_10, t0.sage_sync AS sage_sync_11, t0.volume_mensel_recommande AS volume_mensel_recommande_12, t0.limite_depassement AS limite_depassement_13, t0.marque AS marque_14, t0.category_id AS category_id_15 FROM product t0 WHERE t0.id = ?
Parameters:
[
  416
]

Database Connections

Name Service
default doctrine.dbal.default_connection
interfacage doctrine.dbal.interfacage_connection

Entity Managers

Name Service
default doctrine.orm.default_entity_manager

Second Level Cache

Second Level Cache is not enabled.

Managed Entities

default entity manager

Class Amount of managed objects
App\Entity\TypeAttribute 3
App\Entity\User 2
App\Entity\TicketsComments 2
App\Entity\Company 1
App\Entity\Setting 1
App\Entity\ContratArticles 1
App\Entity\Tickets 1
App\Entity\Contrat 1
App\Entity\Product 1
App\Entity\Client 1
App\Entity\TicketCategory 1
App\Entity\Affectation 1
App\Entity\Contact 1
App\Entity\Roles 1
App\Entity\Devis 1
App\Entity\Category 1
App\Entity\Employee 1
App\Entity\Department 1
App\Entity\Fonction 1

Entities Mapping

Class Mapping errors
App\Entity\User No errors.
App\Entity\Company No errors.
App\Entity\Employee No errors.
App\Entity\Department No errors.
App\Entity\Fonction No errors.
App\Entity\Client
  • The association App\Entity\Client#machineLocations refers to the owning side field App\Entity\MachineLocation#client which does not exist.
App\Entity\Devis No errors.
App\Entity\Contrat
  • The association App\Entity\Contrat#compteFacturations refers to the owning side field App\Entity\CompteFacturation#contrat which does not exist.
App\Entity\Tickets No errors.
App\Entity\Roles No errors.
App\Entity\Affectation No errors.
App\Entity\DemandePieces No errors.
App\Entity\PieceDemandeStatus No errors.
App\Entity\AffectationSequances No errors.
App\Entity\DemandeConsommables No errors.
App\Entity\ConsommableDemandeStatus No errors.
App\Entity\TicketsComments No errors.
App\Entity\Livraison
  • If association App\Entity\Livraison#devis is one-to-one, then the inversed side App\Entity\Devis#livraison has to be one-to-one as well.
App\Entity\Setting No errors.
App\Entity\ContratArticles No errors.
App\Entity\Product
  • The association App\Entity\Product#livraisons refers to the owning side field App\Entity\Livraison#machine which does not exist.
  • The mappings App\Entity\Product#livraisonStatut and App\Entity\LivraisonStatut#machine are inconsistent with each other.
App\Entity\TicketCategory No errors.
App\Entity\DevisIntervenstion No errors.
App\Entity\Contact No errors.
App\Entity\Utilisation
  • The association App\Entity\Utilisation#type refers to the inverse side field App\Entity\UtilisationType#utilisations which does not exist.
App\Entity\TypeAttribute No errors.
App\Entity\MachineAttribute No errors.
App\Entity\Permission No errors.
App\Entity\ClientType No errors.
App\Entity\CompteFacturation No errors.
App\Entity\Sites No errors.
App\Entity\MachineLocation
  • The association App\Entity\MachineLocation#contrat refers to the inverse side field App\Entity\Contrat#machineLocations which does not exist.
App\Entity\LivraisonStatut No errors.
App\Entity\Factures No errors.
App\Entity\Category No errors.
App\Entity\ProductOrder No errors.
App\Entity\DevisMachine No errors.
App\Entity\FactureMachine No errors.