gigafibre-fsm/scripts/migration/diag_dispatch_addr2.sql
louispaulb 4abce6fd66 feat(dispatch): pont d'écriture legacy + adresses/coords/carte/UX Planification
Pont d'écriture Ops → legacy osTicket via endpoint PHP token-gated (hérite des
droits write de l'app facturation.targo.ca → AUCUN grant DB). Fidèle à ticket_view.php :
réassignation (assign_to + participant[assistants] + followed_by + ticket_msg + lock
respecté) + fermeture (status=closed + date_closed + closed_by + réouverture des enfants).
Auteur du log = utilisateur Authentik réel (email → staff legacy par email/nom).

Hub (legacy-dispatch-sync.js):
- adresse de SERVICE importée (champ address) + reimportAddresses + fillMissingCoords
- garde TERRITOIRE (rejette les homonymes hors-zone Gaspésie/Outaouais/Estrie) + centroïde CP/ville
- purgeStaleOrphans (anciens imports TT- périmés), # ticket legacy dans titre + description
- legacyWrite (POST form + X-Ops-Token lu d'un fichier), pushAssignments (reassign), closeTicketLegacy
roster.js: occupancy + unassigned-jobs exposent address/latitude/longitude.

Ops (PlanificationPage.vue):
- carte des jobs à assigner (pins couleur=compétence + lettre repère liste↔carte), chips
  filtre par type, panneau ouvert par défaut
- clics cellule: bande quart/garde + blocs jobs → tournée ; fond → menu horaire (fini le clic droit)
- éditeur de tournée: itinéraire routier réel + adresse + fil ticket (expand), refresh occupation à l'assignation
- bouton « Publier au legacy » (aperçu + ✕ désassigner) + « Fermer le ticket »
- fix dates (lundi calculé en local — plus de décalage UTC) + nav ±1 jour

services/legacy-bridge/ops_reassign.php: endpoint (placeholders; secrets injectés au déploiement, hors repo).
scripts/migration: backfill_dispatch_address.sql + diagnostics.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 22:32:00 -04:00

23 lines
1.2 KiB
SQL

-- diag_dispatch_addr2.sql — état du champ address + coords SL pour le job actif sans coords.
\timing on
-- 1) Remplissage du champ address sur les jobs du pont
SELECT count(*) FILTER (WHERE coalesce(address,'') = '') AS addr_vide,
count(*) FILTER (WHERE coalesce(address,'') <> '') AS addr_ok,
count(*) AS total
FROM "tabDispatch Job" WHERE coalesce(legacy_ticket_id,'') <> '';
-- 2) Le job actif sans coords (LEG-187195) : la SL liée a-t-elle des coords ?
SELECT sl.name, sl.address_line, sl.city,
round(sl.latitude::numeric,5) AS lat, round(sl.longitude::numeric,5) AS lon
FROM "tabService Location" sl WHERE sl.name = 'LOC-0000002656';
-- 3) Parmi les jobs sans coords : combien sont actifs (open/assigned) vs terminés ?
SELECT status, count(*) FROM "tabDispatch Job"
WHERE coalesce(legacy_ticket_id,'') <> '' AND (latitude IS NULL OR abs(coalesce(latitude,0)) < 1)
GROUP BY status ORDER BY 2 DESC;
-- 4) Parmi les jobs SANS service_location : combien actifs ? (ce sont eux qui perdent l'adresse)
SELECT status, count(*) FROM "tabDispatch Job"
WHERE coalesce(legacy_ticket_id,'') <> '' AND coalesce(service_location,'') = ''
GROUP BY status ORDER BY 2 DESC;