Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7194054c7 | |||
| 0c0b57f898 | |||
| c18566124a | |||
| c6259a96cd | |||
| 40fdded7e2 | |||
| 4202977950 | |||
| 0733a239a8 | |||
| cf645493c1 | |||
| 388d39a379 | |||
| d6d2144cc1 | |||
| 6a519874ed | |||
| 3804362546 | |||
| 9864dbc00f | |||
| be03f4e51a | |||
| 8cc2cea444 | |||
| f70e701854 | |||
| f1b18cfbbe | |||
| 5734aaef54 |
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.1.131'
|
app.version: '0.1.133'
|
||||||
|
|||||||
@@ -525,7 +525,60 @@
|
|||||||
},
|
},
|
||||||
"toast": {
|
"toast": {
|
||||||
"error": "Une erreur est survenue. Réessayez.",
|
"error": "Une erreur est survenue. Réessayez.",
|
||||||
"exportError": "L'export du répertoire transporteurs a échoué. Réessayez."
|
"exportError": "L'export du répertoire transporteurs a échoué. Réessayez.",
|
||||||
|
"createSuccess": "Transporteur créé avec succès",
|
||||||
|
"integrateSuccess": "Transporteur QUALIMAT intégré"
|
||||||
|
},
|
||||||
|
"containerType": {
|
||||||
|
"BENNE": "Benne",
|
||||||
|
"FOND_MOUVANT": "Fond mouvant"
|
||||||
|
},
|
||||||
|
"tab": {
|
||||||
|
"qualimat": "Qualimat",
|
||||||
|
"addresses": "Adresses",
|
||||||
|
"contacts": "Contacts",
|
||||||
|
"prices": "Prix"
|
||||||
|
},
|
||||||
|
"form": {
|
||||||
|
"title": "Ajouter un transporteur",
|
||||||
|
"back": "Retour au répertoire",
|
||||||
|
"submit": "Valider",
|
||||||
|
"comingSoon": "À venir",
|
||||||
|
"duplicateName": "Un transporteur actif portant ce nom existe déjà.",
|
||||||
|
"main": {
|
||||||
|
"name": "Nom",
|
||||||
|
"certificationType": "Certification transport",
|
||||||
|
"isChartered": "Affréter",
|
||||||
|
"indexationRate": "Indexation %",
|
||||||
|
"containerType": "Benne / Fond mouvant",
|
||||||
|
"volumeM3": "Volume m³",
|
||||||
|
"discharge": "Décharge",
|
||||||
|
"liotPlates": "Immatriculations LIOT",
|
||||||
|
"liotPlatesHint": "Séparées par « ; »"
|
||||||
|
},
|
||||||
|
"qualimat": {
|
||||||
|
"empty": "Aucun transporteur QUALIMAT trouvé.",
|
||||||
|
"searchHint": "Saisissez le nom du transporteur pour lancer la recherche.",
|
||||||
|
"columns": {
|
||||||
|
"name": "Nom",
|
||||||
|
"address": "Adresse",
|
||||||
|
"validityDate": "Date de validité"
|
||||||
|
},
|
||||||
|
"confirm": {
|
||||||
|
"title": "Intégration QUALIMAT",
|
||||||
|
"message": "Êtes-vous sûr de vouloir intégrer ce transporteur ?",
|
||||||
|
"cancel": "Annuler",
|
||||||
|
"confirm": "Intégrer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"errors": {
|
||||||
|
"nameRequired": "Le nom du transporteur est obligatoire.",
|
||||||
|
"certificationRequired": "Le type de certification est obligatoire.",
|
||||||
|
"dischargeRequired": "La décharge est obligatoire pour une certification « Autre ».",
|
||||||
|
"indexationRequired": "Le taux d'indexation est obligatoire pour un transporteur affrété.",
|
||||||
|
"containerTypeRequired": "Le type de contenant est obligatoire pour un transporteur affrété.",
|
||||||
|
"volumeRequired": "Le volume est obligatoire pour un transporteur affrété."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,434 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests du workflow « Ajouter un transporteur » (M4 Transport, ERP-165).
|
||||||
|
*
|
||||||
|
* `useCarrierForm` porte le formulaire principal (Nom + Certification + Affréter)
|
||||||
|
* et l'orchestration des onglets de création. On vérifie ici le CONTRAT propre à
|
||||||
|
* la création :
|
||||||
|
* - pré-check front : nom requis → POST bloqué, erreur inline, aucun appel réseau ;
|
||||||
|
* - POST /carriers (groupe carrier:write:main) : payload + Accept ld+json +
|
||||||
|
* toast:false ; au succès, verrouillage + bascule sur l'onglet Qualimat +
|
||||||
|
* réaffichage du nom normalisé ;
|
||||||
|
* - 409 doublon (RG-4.12) → erreur inline dédiée sur `name` ;
|
||||||
|
* - 422 → mapping inline par champ (propertyPath) ;
|
||||||
|
* - onglets : 4 onglets (Qualimat/Adresses/Contacts/Prix), completeTab
|
||||||
|
* déverrouille/avance et signale le dernier onglet ;
|
||||||
|
* - patchCarrier : PATCH partiel, no-op avant création.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const mockPost = vi.hoisted(() => vi.fn())
|
||||||
|
const mockPatch = vi.hoisted(() => vi.fn())
|
||||||
|
|
||||||
|
vi.stubGlobal('useApi', () => ({
|
||||||
|
get: vi.fn(),
|
||||||
|
post: mockPost,
|
||||||
|
put: vi.fn(),
|
||||||
|
patch: mockPatch,
|
||||||
|
delete: vi.fn(),
|
||||||
|
}))
|
||||||
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
||||||
|
vi.stubGlobal('useToast', () => ({
|
||||||
|
success: vi.fn(),
|
||||||
|
error: vi.fn(),
|
||||||
|
warning: vi.fn(),
|
||||||
|
info: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
const { useCarrierForm, CARRIER_TAB_KEYS } = await import('../useCarrierForm')
|
||||||
|
|
||||||
|
describe('useCarrierForm', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front : nom vide → erreur inline sur name, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.name).toBe('transport.carriers.form.errors.nameRequired')
|
||||||
|
expect(form.mainLocked.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front : nom en espaces uniquement → erreur inline, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = ' '
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.name).toBe('transport.carriers.form.errors.nameRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front : certification vide (hors LIOT) → erreur inline sur certificationType, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
// certificationType laissé null → bloqué côté front (RG-4.01).
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.certificationType).toBe('transport.carriers.form.errors.certificationRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front : cas LIOT → certification non requise (aucune erreur de certification)', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 5, name: 'LIOT', certificationType: null })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'LIOT'
|
||||||
|
form.main.liotPlates = 'AA-123-BB'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(true)
|
||||||
|
expect(form.mainErrors.errors.certificationType).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.02 : certification AUTRE sans décharge → erreur inline, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
// dischargeDocumentIri null (upload non fourni).
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.dischargeDocument).toBe('transport.carriers.form.errors.dischargeRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.03 : affrété sans indexation / contenant / volume → 3 erreurs inline, pas de POST', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(mockPost).not.toHaveBeenCalled()
|
||||||
|
expect(form.mainErrors.errors.indexationRate).toBe('transport.carriers.form.errors.indexationRequired')
|
||||||
|
expect(form.mainErrors.errors.containerType).toBe('transport.carriers.form.errors.containerTypeRequired')
|
||||||
|
expect(form.mainErrors.errors.volumeM3).toBe('transport.carriers.form.errors.volumeRequired')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('front RG-4.03 : affrété avec tous les champs remplis → POST envoyé', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 8, name: 'ACME', certificationType: 'GMP_PLUS' })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
form.main.indexationRate = '5'
|
||||||
|
form.main.containerType = 'BENNE'
|
||||||
|
form.main.volumeM3 = '30'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(true)
|
||||||
|
expect(mockPost).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockPost.mock.calls[0]?.[1]).toMatchObject({
|
||||||
|
isChartered: true,
|
||||||
|
indexationRate: '5',
|
||||||
|
containerType: 'BENNE',
|
||||||
|
volumeM3: '30',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('POST /carriers avec Accept ld+json, verrouille et bascule sur Qualimat', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 42, name: 'TRANSPORTS ACME', certificationType: 'GMP_PLUS' })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Transports Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(true)
|
||||||
|
expect(mockPost).toHaveBeenCalledTimes(1)
|
||||||
|
const [url, body, opts] = mockPost.mock.calls[0] ?? []
|
||||||
|
expect(url).toBe('/carriers')
|
||||||
|
expect(body).toEqual({
|
||||||
|
name: 'Transports Acme',
|
||||||
|
certificationType: 'GMP_PLUS',
|
||||||
|
isChartered: false,
|
||||||
|
})
|
||||||
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
||||||
|
|
||||||
|
expect(form.carrierId.value).toBe(42)
|
||||||
|
// RG-4.13 : réaffiche le nom normalisé (UPPERCASE) renvoyé par le serveur.
|
||||||
|
expect(form.main.name).toBe('TRANSPORTS ACME')
|
||||||
|
expect(form.mainLocked.value).toBe(true)
|
||||||
|
// L'onglet Qualimat était déjà accessible (saisie assistée) ; le POST
|
||||||
|
// déverrouille Adresses (index 1) et bascule dessus.
|
||||||
|
expect(form.activeTab.value).toBe('addresses')
|
||||||
|
expect(form.unlockedIndex.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('buildMainPayload : omet certificationType vide, garde isChartered', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'X'
|
||||||
|
|
||||||
|
const body = form.buildMainPayload()
|
||||||
|
expect(body).toEqual({ name: 'X', isChartered: false })
|
||||||
|
expect('certificationType' in body).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('409 doublon (RG-4.12) : erreur inline dédiée sur name, pas de verrouillage', async () => {
|
||||||
|
mockPost.mockRejectedValueOnce({ response: { status: 409 } })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Doublon'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(form.mainErrors.errors.name).toBe('transport.carriers.form.duplicateName')
|
||||||
|
expect(form.mainLocked.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('422 : mappe les violations serveur inline par champ', async () => {
|
||||||
|
// Contrainte re-validée uniquement back (ex. longueur du nom) : le pré-check
|
||||||
|
// front passe (nom rempli, certif choisie, non affrété), la 422 mappe inline
|
||||||
|
// sur le champ via son propertyPath.
|
||||||
|
mockPost.mockRejectedValueOnce({
|
||||||
|
response: {
|
||||||
|
status: 422,
|
||||||
|
_data: { violations: [{ propertyPath: 'name', message: 'Le nom du transporteur ne peut dépasser 255 caractères.' }] },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
|
||||||
|
const created = await form.submitMain()
|
||||||
|
|
||||||
|
expect(created).toBe(false)
|
||||||
|
expect(form.mainErrors.errors.name).toBe('Le nom du transporteur ne peut dépasser 255 caractères.')
|
||||||
|
expect(form.mainLocked.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('onglets : 4 clés Qualimat/Adresses/Contacts/Prix', () => {
|
||||||
|
expect(CARRIER_TAB_KEYS).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
||||||
|
const form = useCarrierForm()
|
||||||
|
expect(form.tabKeys.value).toEqual(['qualimat', 'addresses', 'contacts', 'prices'])
|
||||||
|
// L'onglet Qualimat (index 0) est accessible dès le départ (saisie assistée) ;
|
||||||
|
// Adresses / Contacts / Prix restent verrouillés jusqu'au POST principal.
|
||||||
|
expect(form.unlockedIndex.value).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('completeTab : déverrouille/avance, et signale le dernier onglet du flux', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
|
||||||
|
// Qualimat → Adresses (pas le dernier).
|
||||||
|
expect(form.completeTab('qualimat')).toBe(false)
|
||||||
|
expect(form.isValidated('qualimat')).toBe(true)
|
||||||
|
expect(form.activeTab.value).toBe('addresses')
|
||||||
|
expect(form.unlockedIndex.value).toBe(1)
|
||||||
|
|
||||||
|
expect(form.completeTab('addresses')).toBe(false)
|
||||||
|
expect(form.activeTab.value).toBe('contacts')
|
||||||
|
|
||||||
|
expect(form.completeTab('contacts')).toBe(false)
|
||||||
|
expect(form.activeTab.value).toBe('prices')
|
||||||
|
|
||||||
|
// Prix = dernier onglet → true (création terminée).
|
||||||
|
expect(form.completeTab('prices')).toBe(true)
|
||||||
|
expect(form.isValidated('prices')).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('editMode : completeTab ne verrouille pas et ne bascule pas d\'onglet', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.editMode.value = true
|
||||||
|
form.activeTab.value = 'qualimat'
|
||||||
|
|
||||||
|
expect(form.completeTab('qualimat')).toBe(false)
|
||||||
|
expect(form.isValidated('qualimat')).toBe(false)
|
||||||
|
expect(form.activeTab.value).toBe('qualimat')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('patchCarrier : PATCH /carriers/{id} en mode strict, no-op avant création', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
|
||||||
|
await form.patchCarrier({ liotPlates: 'AA-123-BB' })
|
||||||
|
expect(mockPatch).not.toHaveBeenCalled()
|
||||||
|
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 9, name: 'ACME', certificationType: 'OVOCOM' })
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'OVOCOM'
|
||||||
|
await form.submitMain()
|
||||||
|
|
||||||
|
await form.patchCarrier({ liotPlates: 'AA-123-BB' })
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith('/carriers/9', { liotPlates: 'AA-123-BB' }, { toast: false })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('useCarrierForm — champs conditionnels (ERP-166)', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('cas LIOT (insensible à la casse) : masque la certification, payload réduit', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'liot'
|
||||||
|
|
||||||
|
expect(form.isLiot.value).toBe(true)
|
||||||
|
expect(form.showCertification.value).toBe(false)
|
||||||
|
|
||||||
|
form.main.liotPlates = 'AA-123-BB ; CC-456-DD'
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'liot',
|
||||||
|
isChartered: false,
|
||||||
|
liotPlates: 'AA-123-BB ; CC-456-DD',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('LIOT masque les champs conditionnels (affrètement / décharge)', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'LIOT'
|
||||||
|
form.main.isChartered = true
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
|
||||||
|
expect(form.showCharteredFields.value).toBe(false)
|
||||||
|
expect(form.showDischarge.value).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.03 affrété : indexation / contenant / volume visibles et dans le payload', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
expect(form.showCharteredFields.value).toBe(true)
|
||||||
|
|
||||||
|
form.main.indexationRate = '5'
|
||||||
|
form.main.containerType = 'BENNE'
|
||||||
|
form.main.volumeM3 = '30'
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'Acme',
|
||||||
|
certificationType: 'GMP_PLUS',
|
||||||
|
isChartered: true,
|
||||||
|
indexationRate: '5',
|
||||||
|
containerType: 'BENNE',
|
||||||
|
volumeM3: '30',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.03 affrété mais champs vides : omis du payload (422 NotBlank back)', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
form.main.isChartered = true
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toEqual({
|
||||||
|
name: 'Acme',
|
||||||
|
certificationType: 'GMP_PLUS',
|
||||||
|
isChartered: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('RG-4.02 AUTRE : décharge visible + dischargeDocument dans le payload si IRI résolu', () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
form.main.certificationType = 'AUTRE'
|
||||||
|
|
||||||
|
expect(form.showDischarge.value).toBe(true)
|
||||||
|
|
||||||
|
form.main.dischargeDocumentIri = '/api/uploaded_documents/7'
|
||||||
|
expect(form.buildMainPayload()).toMatchObject({ dischargeDocument: '/api/uploaded_documents/7' })
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('useCarrierForm — copie QUALIMAT (ERP-166)', () => {
|
||||||
|
const QUALIMAT_ROW = {
|
||||||
|
'@id': '/api/qualimat_carriers/42',
|
||||||
|
id: '42',
|
||||||
|
name: 'TRANSPORTS QUALIMAT',
|
||||||
|
siret: '12345678900012',
|
||||||
|
address: '1 rue du Port',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
validityDate: '2027-01-15',
|
||||||
|
status: 'VALIDE',
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockPost.mockReset()
|
||||||
|
mockPatch.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('copie name + certificationType=QUALIMAT (readonly) + IRI + adresse, sans PATCH avant création', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
expect(mockPatch).not.toHaveBeenCalled()
|
||||||
|
expect(form.main.name).toBe('TRANSPORTS QUALIMAT')
|
||||||
|
expect(form.main.certificationType).toBe('QUALIMAT')
|
||||||
|
expect(form.main.qualimatCarrierIri).toBe('/api/qualimat_carriers/42')
|
||||||
|
expect(form.isQualimat.value).toBe(true)
|
||||||
|
expect(form.certificationReadonly.value).toBe(true)
|
||||||
|
expect(form.qualimatAddress.value).toEqual({
|
||||||
|
country: 'France',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
street: '1 rue du Port',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('après création : PATCH /carriers/{id} avec qualimatCarrier + name + certification', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 9, name: 'X', certificationType: 'GMP_PLUS' })
|
||||||
|
mockPatch.mockResolvedValueOnce({})
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'X'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
await form.submitMain()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(ok).toBe(true)
|
||||||
|
expect(mockPatch).toHaveBeenCalledWith(
|
||||||
|
'/carriers/9',
|
||||||
|
{
|
||||||
|
qualimatCarrier: '/api/qualimat_carriers/42',
|
||||||
|
name: 'TRANSPORTS QUALIMAT',
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
},
|
||||||
|
{ toast: false },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('après création : PATCH en échec → pas de copie locale (rollback) et retour false', async () => {
|
||||||
|
mockPost.mockResolvedValueOnce({ id: 9, name: 'X', certificationType: 'GMP_PLUS' })
|
||||||
|
mockPatch.mockRejectedValueOnce({ response: { status: 500, _data: {} } })
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'X'
|
||||||
|
form.main.certificationType = 'GMP_PLUS'
|
||||||
|
await form.submitMain()
|
||||||
|
|
||||||
|
const ok = await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
// Échec serveur : l'UI ne doit pas refléter une intégration QUALIMAT non persistée.
|
||||||
|
expect(ok).toBe(false)
|
||||||
|
expect(form.main.name).toBe('X')
|
||||||
|
expect(form.main.certificationType).toBe('GMP_PLUS')
|
||||||
|
expect(form.main.qualimatCarrierIri).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('buildMainPayload inclut qualimatCarrier + certificationType QUALIMAT après intégration', async () => {
|
||||||
|
const form = useCarrierForm()
|
||||||
|
form.main.name = 'Acme'
|
||||||
|
await form.applyQualimatSelection(QUALIMAT_ROW)
|
||||||
|
|
||||||
|
expect(form.buildMainPayload()).toMatchObject({
|
||||||
|
qualimatCarrier: '/api/qualimat_carriers/42',
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
import { useQualimatSearch, type QualimatCarrierRow } from '../useQualimatSearch'
|
||||||
|
|
||||||
|
const mockApiGet = vi.hoisted(() => vi.fn())
|
||||||
|
vi.stubGlobal('useApi', () => ({ get: mockApiGet }))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests de la saisie assistée QUALIMAT (M4 Transport, ERP-166 — RG-4.01).
|
||||||
|
*
|
||||||
|
* `useQualimatSearch` est une fine enveloppe de `usePaginatedList<QualimatCarrierRow>`
|
||||||
|
* sur `/qualimat_carriers`. La pagination générique est couverte par
|
||||||
|
* `usePaginatedList.test.ts` ; on vérifie ici le CONTRAT propre à la recherche :
|
||||||
|
* - ressource ciblée `/qualimat_carriers` + enveloppe Hydra + `Accept: application/ld+json` ;
|
||||||
|
* - le filtre `search` (branché sur le nom du transporteur) est transmis et
|
||||||
|
* retombe en page 1.
|
||||||
|
*/
|
||||||
|
describe('useQualimatSearch', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
mockApiGet.mockReset()
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE: QualimatCarrierRow[] = [
|
||||||
|
{
|
||||||
|
'@id': '/api/qualimat_carriers/1',
|
||||||
|
id: '1',
|
||||||
|
name: 'TRANSPORTS ACME',
|
||||||
|
siret: '12345678900012',
|
||||||
|
address: '1 rue du Port',
|
||||||
|
postalCode: '86000',
|
||||||
|
city: 'Poitiers',
|
||||||
|
validityDate: '2027-01-15',
|
||||||
|
status: 'VALIDE',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
it('cible /qualimat_carriers, consomme l\'enveloppe Hydra et envoie l\'Accept ld+json', async () => {
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
const repo = useQualimatSearch()
|
||||||
|
|
||||||
|
await repo.fetch()
|
||||||
|
|
||||||
|
const [url, query, opts] = mockApiGet.mock.calls[0]
|
||||||
|
expect(url).toBe('/qualimat_carriers')
|
||||||
|
expect(query).toMatchObject({ page: 1, itemsPerPage: 10 })
|
||||||
|
expect(opts).toMatchObject({ toast: false, headers: { Accept: 'application/ld+json' } })
|
||||||
|
expect(repo.items.value).toEqual(PAGE)
|
||||||
|
expect(repo.totalItems.value).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('transmet le filtre `search` (nom du transporteur) et retombe en page 1', async () => {
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
const repo = useQualimatSearch()
|
||||||
|
await repo.fetch()
|
||||||
|
|
||||||
|
mockApiGet.mockResolvedValueOnce({ member: PAGE, totalItems: 1 })
|
||||||
|
await repo.setFilters({ search: 'acme' })
|
||||||
|
|
||||||
|
expect(repo.currentPage.value).toBe(1)
|
||||||
|
const query = mockApiGet.mock.calls.at(-1)?.[1] as Record<string, unknown>
|
||||||
|
expect(query.search).toBe('acme')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,347 @@
|
|||||||
|
import { computed, reactive, ref } from 'vue'
|
||||||
|
import { useFormErrors } from '~/shared/composables/useFormErrors'
|
||||||
|
import {
|
||||||
|
emptyCarrierAddressCopy,
|
||||||
|
emptyCarrierMain,
|
||||||
|
type CarrierAddressCopy,
|
||||||
|
type CarrierMainDraft,
|
||||||
|
type CarrierMainResponse,
|
||||||
|
} from '~/modules/transport/types/carrierForm'
|
||||||
|
import type { QualimatCarrierRow } from '~/modules/transport/composables/useQualimatSearch'
|
||||||
|
|
||||||
|
/** Nom du cas spécial « compte-propre » LIOT (comparaison insensible à la casse, RG-4.01). */
|
||||||
|
const LIOT_NAME = 'LIOT'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workflow de l'écran « Ajouter un transporteur » (M4 Transport, ERP-165) —
|
||||||
|
* miroir conceptuel de `useSupplierForm` (M2) / `useProviderForm` (M3).
|
||||||
|
*
|
||||||
|
* Périmètre ERP-165 : le formulaire PRINCIPAL (pré-onglets) et l'orchestration de
|
||||||
|
* la barre d'onglets. La création est INCRÉMENTALE (spec-front § Écran Ajouter) :
|
||||||
|
* - on POST d'abord le formulaire principal (`POST /api/carriers`) ;
|
||||||
|
* - au succès le bloc principal passe en lecture seule, le 1er onglet (Qualimat)
|
||||||
|
* se déverrouille et devient actif ;
|
||||||
|
* - chaque onglet validé déverrouille le suivant (PATCH partiels par groupe de
|
||||||
|
* sérialisation) et passe en lecture seule.
|
||||||
|
*
|
||||||
|
* Les champs conditionnels du formulaire principal (indexation / benne / volume
|
||||||
|
* si affrété, décharge si AUTRE, cas LIOT) et la saisie assistée QUALIMAT arrivent
|
||||||
|
* à ERP-166 ; le contenu des onglets Adresses / Contacts / Prix aux tickets
|
||||||
|
* suivants. Ce composable pose le POST principal, le PATCH partiel et le gating
|
||||||
|
* des onglets.
|
||||||
|
*
|
||||||
|
* État 100 % local à l'instance (refs / reactive) — aucune persistance URL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clés des onglets du flux de création, dans l'ordre de la barre (spec-front
|
||||||
|
* § Écran Ajouter). Toujours les 4 (pas de gating par permission au M4, ≠ l'onglet
|
||||||
|
* Comptabilité du M3).
|
||||||
|
*/
|
||||||
|
export const CARRIER_TAB_KEYS = ['qualimat', 'addresses', 'contacts', 'prices'] as const
|
||||||
|
|
||||||
|
export function useCarrierForm() {
|
||||||
|
const api = useApi()
|
||||||
|
const { t } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
|
|
||||||
|
// Erreurs de validation par champ (ERP-101) du formulaire principal.
|
||||||
|
const mainErrors = useFormErrors()
|
||||||
|
|
||||||
|
// ── État du transporteur créé ─────────────────────────────────────────────
|
||||||
|
const carrierId = ref<number | null>(null)
|
||||||
|
const mainLocked = ref(false)
|
||||||
|
const mainSubmitting = ref(false)
|
||||||
|
|
||||||
|
// ── Formulaire principal ──────────────────────────────────────────────────
|
||||||
|
const main = reactive<CarrierMainDraft>(emptyCarrierMain())
|
||||||
|
|
||||||
|
// Adresse copiée depuis QUALIMAT à la sélection (alimente l'onglet Adresses,
|
||||||
|
// ticket ultérieur). Vide tant qu'aucun transporteur QUALIMAT n'est intégré.
|
||||||
|
const qualimatAddress = ref<CarrierAddressCopy>(emptyCarrierAddressCopy())
|
||||||
|
|
||||||
|
// ── Affichage conditionnel du formulaire principal (RG-4.01 / 4.02 / 4.03) ──
|
||||||
|
// Cas LIOT : nom == « LIOT » → seul `liotPlates` est pertinent, le reste masqué.
|
||||||
|
const isLiot = computed(() => main.name.trim().toUpperCase() === LIOT_NAME)
|
||||||
|
// Transporteur QUALIMAT : la FK est posée → certification figée à « QUALIMAT ».
|
||||||
|
const isQualimat = computed(() => main.qualimatCarrierIri !== null)
|
||||||
|
// Certification masquée en cas LIOT ; lecture seule si QUALIMAT (ou bloc verrouillé).
|
||||||
|
const showCertification = computed(() => !isLiot.value)
|
||||||
|
const certificationReadonly = computed(() => isQualimat.value || mainLocked.value)
|
||||||
|
// RG-4.03 : champs d'affrètement (indexation / contenant / volume) visibles et
|
||||||
|
// obligatoires si « Affréter » coché — masqués en cas LIOT.
|
||||||
|
const showCharteredFields = computed(() => main.isChartered && !isLiot.value)
|
||||||
|
// RG-4.02 : décharge visible et obligatoire si certification == AUTRE (hors LIOT).
|
||||||
|
const showDischarge = computed(() => main.certificationType === 'AUTRE' && !isLiot.value)
|
||||||
|
|
||||||
|
// ── Onglets : ordre + gating progressif ───────────────────────────────────
|
||||||
|
const tabKeys = ref<string[]>([...CARRIER_TAB_KEYS])
|
||||||
|
// Index du dernier onglet déverrouillé. L'onglet Qualimat (index 0) est la saisie
|
||||||
|
// assistée du formulaire principal : accessible DÈS LE DÉPART (≠ Adresses /
|
||||||
|
// Contacts / Prix, déverrouillés seulement après le POST principal).
|
||||||
|
const unlockedIndex = ref(0)
|
||||||
|
const activeTab = ref<string>(CARRIER_TAB_KEYS[0])
|
||||||
|
// Onglets validés (passent en lecture seule).
|
||||||
|
const validated = reactive<Record<string, boolean>>({})
|
||||||
|
// Mode MODIFICATION (ticket ultérieur) : navigation libre, pas de verrouillage
|
||||||
|
// ni de bascule automatique d'onglet à la validation (cf. completeTab).
|
||||||
|
const editMode = ref(false)
|
||||||
|
|
||||||
|
function isValidated(key: string): boolean {
|
||||||
|
return validated[key] === true
|
||||||
|
}
|
||||||
|
|
||||||
|
function tabIndex(key: string): number {
|
||||||
|
return tabKeys.value.indexOf(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validation FRONT du formulaire principal : seul le nom est requis côté front
|
||||||
|
* (ERP-101) : feedback immédiat sur tous les champs obligatoires (y compris
|
||||||
|
* conditionnels), alignés sur les RG du back (qui reste autoritaire) :
|
||||||
|
* - RG-4.01 : nom requis ; certification requise hors cas LIOT (où tout est masqué) ;
|
||||||
|
* - RG-4.02 : décharge requise si certification AUTRE ;
|
||||||
|
* - RG-4.03 : indexation + contenant + volume requis si « Affréter ».
|
||||||
|
*/
|
||||||
|
function validateMainFront(): boolean {
|
||||||
|
let valid = true
|
||||||
|
if (!main.name?.trim()) {
|
||||||
|
mainErrors.setError('name', t('transport.carriers.form.errors.nameRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cas LIOT : seul le nom compte, les autres champs sont masqués (RG-4.01).
|
||||||
|
if (isLiot.value) {
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.01 : certification obligatoire hors LIOT.
|
||||||
|
if (!main.certificationType) {
|
||||||
|
mainErrors.setError('certificationType', t('transport.carriers.form.errors.certificationRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.02 : décharge obligatoire si certification AUTRE.
|
||||||
|
if (main.certificationType === 'AUTRE' && !main.dischargeDocumentIri) {
|
||||||
|
mainErrors.setError('dischargeDocument', t('transport.carriers.form.errors.dischargeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RG-4.03 : indexation / contenant / volume obligatoires si affrété.
|
||||||
|
if (main.isChartered) {
|
||||||
|
if (!main.indexationRate.trim()) {
|
||||||
|
mainErrors.setError('indexationRate', t('transport.carriers.form.errors.indexationRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if (!main.containerType) {
|
||||||
|
mainErrors.setError('containerType', t('transport.carriers.form.errors.containerTypeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if (!main.volumeM3.trim()) {
|
||||||
|
mainErrors.setError('volumeM3', t('transport.carriers.form.errors.volumeRequired'))
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return valid
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payload du POST principal (groupe `carrier:write:main`). `name` et
|
||||||
|
* `certificationType` sont omis s'ils sont vides afin que la 422 porte la
|
||||||
|
* violation métier (NotBlank sur le nom, « certification obligatoire » sur la
|
||||||
|
* certification) sur le champ plutôt qu'une erreur de type.
|
||||||
|
*/
|
||||||
|
function buildMainPayload(): Record<string, unknown> {
|
||||||
|
// Cas LIOT (RG-4.01) : seul `liotPlates` est pertinent ; les autres champs
|
||||||
|
// sont masqués côté front et non envoyés (le back stocke ce qu'il reçoit).
|
||||||
|
if (isLiot.value) {
|
||||||
|
const payload: Record<string, unknown> = { name: main.name, isChartered: false }
|
||||||
|
if (main.liotPlates.trim()) {
|
||||||
|
payload.liotPlates = main.liotPlates
|
||||||
|
}
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload: Record<string, unknown> = { isChartered: main.isChartered }
|
||||||
|
if (main.name.trim()) {
|
||||||
|
payload.name = main.name
|
||||||
|
}
|
||||||
|
if (main.certificationType) {
|
||||||
|
payload.certificationType = main.certificationType
|
||||||
|
}
|
||||||
|
// FK QUALIMAT (saisie assistée, § 2.5) envoyée si une ligne a été intégrée.
|
||||||
|
if (main.qualimatCarrierIri) {
|
||||||
|
payload.qualimatCarrier = main.qualimatCarrierIri
|
||||||
|
}
|
||||||
|
// RG-4.02 : décharge envoyée seulement en certification AUTRE ; omise quand
|
||||||
|
// absente pour que la 422 « obligatoire » porte sur le champ.
|
||||||
|
if (main.certificationType === 'AUTRE' && main.dischargeDocumentIri) {
|
||||||
|
payload.dischargeDocument = main.dischargeDocumentIri
|
||||||
|
}
|
||||||
|
// RG-4.03 : indexation / contenant / volume envoyés seulement si affrété ;
|
||||||
|
// omis quand vides pour déclencher la 422 NotBlank inline sur le champ.
|
||||||
|
if (main.isChartered) {
|
||||||
|
if (main.indexationRate.trim()) {
|
||||||
|
payload.indexationRate = main.indexationRate
|
||||||
|
}
|
||||||
|
if (main.containerType) {
|
||||||
|
payload.containerType = main.containerType
|
||||||
|
}
|
||||||
|
if (main.volumeM3.trim()) {
|
||||||
|
payload.volumeM3 = main.volumeM3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /carriers (groupe `carrier:write:main`). Pré-check front, puis création.
|
||||||
|
* Au succès : verrouille le bloc principal, déverrouille l'onglet Adresses et
|
||||||
|
* bascule dessus (l'onglet Qualimat, saisie assistée, était déjà accessible).
|
||||||
|
* Retourne true si créé, false sinon.
|
||||||
|
*/
|
||||||
|
async function submitMain(): Promise<boolean> {
|
||||||
|
if (mainSubmitting.value) return false
|
||||||
|
mainErrors.clearErrors()
|
||||||
|
if (!validateMainFront()) return false
|
||||||
|
|
||||||
|
mainSubmitting.value = true
|
||||||
|
try {
|
||||||
|
const created = await api.post<CarrierMainResponse>('/carriers', buildMainPayload(), {
|
||||||
|
headers: { Accept: 'application/ld+json' },
|
||||||
|
toast: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
carrierId.value = created.id
|
||||||
|
// Réaffiche les valeurs normalisées renvoyées par le serveur (nom en
|
||||||
|
// UPPERCASE — RG-4.13 ; certification éventuellement forcée).
|
||||||
|
main.name = created.name ?? main.name
|
||||||
|
main.certificationType = created.certificationType ?? main.certificationType
|
||||||
|
|
||||||
|
mainLocked.value = true
|
||||||
|
// Déverrouille l'onglet suivant (Adresses, index 1) et bascule dessus.
|
||||||
|
unlockedIndex.value = Math.max(unlockedIndex.value, 1)
|
||||||
|
activeTab.value = tabKeys.value[1] ?? CARRIER_TAB_KEYS[1]
|
||||||
|
toast.success({ title: t('transport.carriers.toast.createSuccess') })
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// 409 = doublon de nom (RG-4.12) → erreur inline dédiée + toast ;
|
||||||
|
// 422 → mapping inline par champ ; autre → toast de fallback (ERP-101).
|
||||||
|
const status = (error as { response?: { status?: number } })?.response?.status
|
||||||
|
if (status === 409) {
|
||||||
|
const message = t('transport.carriers.form.duplicateName')
|
||||||
|
mainErrors.setError('name', message)
|
||||||
|
toast.error({ title: t('transport.carriers.toast.error'), message })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mainErrors.handleApiError(error, { fallbackMessage: t('transport.carriers.toast.error') })
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
mainSubmitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PATCH partiel du transporteur (mode strict : un seul groupe de sérialisation
|
||||||
|
* par appel — spec-back § 2.9). Servira les onglets à champs scalaires des
|
||||||
|
* tickets suivants. No-op tant que le transporteur n'existe pas.
|
||||||
|
*/
|
||||||
|
async function patchCarrier(payload: Record<string, unknown>): Promise<void> {
|
||||||
|
if (carrierId.value === null) return
|
||||||
|
await api.patch(`/carriers/${carrierId.value}`, payload, { toast: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intègre une ligne QUALIMAT sélectionnée dans l'onglet Qualimat (RG-4.01 /
|
||||||
|
* § 2.5) : copie le nom, force la certification à « QUALIMAT » (lecture seule),
|
||||||
|
* pose la FK `qualimatCarrier` (IRI) et copie l'adresse (pour l'onglet Adresses).
|
||||||
|
* Si le transporteur existe déjà (post-POST, cas nominal de l'onglet), persiste
|
||||||
|
* d'abord la copie via un PATCH partiel `carrier:write:main` : la copie locale
|
||||||
|
* (nom, certification figée « QUALIMAT », FK, adresse) n'est appliquée qu'en cas
|
||||||
|
* de succès, pour ne pas laisser l'UI dans un état QUALIMAT non sauvegardé si le
|
||||||
|
* PATCH échoue. Retourne true si l'intégration a abouti.
|
||||||
|
*/
|
||||||
|
async function applyQualimatSelection(row: QualimatCarrierRow): Promise<boolean> {
|
||||||
|
// Transporteur déjà créé : on persiste avant de refléter localement.
|
||||||
|
if (carrierId.value !== null) {
|
||||||
|
try {
|
||||||
|
await patchCarrier({
|
||||||
|
qualimatCarrier: row['@id'],
|
||||||
|
name: row.name,
|
||||||
|
certificationType: 'QUALIMAT',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
mainErrors.handleApiError(error, { fallbackMessage: t('transport.carriers.toast.error') })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main.name = row.name ?? ''
|
||||||
|
main.certificationType = 'QUALIMAT'
|
||||||
|
main.qualimatCarrierIri = row['@id']
|
||||||
|
qualimatAddress.value = {
|
||||||
|
country: 'France',
|
||||||
|
postalCode: row.postalCode ?? '',
|
||||||
|
city: row.city ?? '',
|
||||||
|
street: row.address ?? '',
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marque un onglet validé (passe en lecture seule), déverrouille et avance à
|
||||||
|
* l'onglet suivant. Retourne true si c'était le dernier onglet du flux (création
|
||||||
|
* terminée), false sinon.
|
||||||
|
*/
|
||||||
|
function completeTab(key: string): boolean {
|
||||||
|
// En modification : navigation libre, l'onglet reste éditable après validation.
|
||||||
|
if (editMode.value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
validated[key] = true
|
||||||
|
const index = tabIndex(key)
|
||||||
|
const next = tabKeys.value[index + 1]
|
||||||
|
if (next === undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
unlockedIndex.value = Math.max(unlockedIndex.value, index + 1)
|
||||||
|
activeTab.value = next
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
// état
|
||||||
|
main,
|
||||||
|
qualimatAddress,
|
||||||
|
carrierId,
|
||||||
|
mainLocked,
|
||||||
|
mainSubmitting,
|
||||||
|
mainErrors,
|
||||||
|
// affichage conditionnel
|
||||||
|
isLiot,
|
||||||
|
isQualimat,
|
||||||
|
showCertification,
|
||||||
|
certificationReadonly,
|
||||||
|
showCharteredFields,
|
||||||
|
showDischarge,
|
||||||
|
// onglets
|
||||||
|
tabKeys,
|
||||||
|
activeTab,
|
||||||
|
unlockedIndex,
|
||||||
|
validated,
|
||||||
|
editMode,
|
||||||
|
isValidated,
|
||||||
|
// actions
|
||||||
|
validateMainFront,
|
||||||
|
buildMainPayload,
|
||||||
|
submitMain,
|
||||||
|
patchCarrier,
|
||||||
|
applyQualimatSelection,
|
||||||
|
completeTab,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { usePaginatedList } from '~/shared/composables/usePaginatedList'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ligne du référentiel QUALIMAT renvoyée par la saisie assistée (groupe
|
||||||
|
* `qualimat:read`). `@id` est l'IRI conservée comme FK `carrier.qualimatCarrier`
|
||||||
|
* (RG-4.01 / § 2.5) ; `validityDate` pilote le fond rouge de la colonne « Date de
|
||||||
|
* validité » (RG-4.04).
|
||||||
|
*/
|
||||||
|
export interface QualimatCarrierRow {
|
||||||
|
'@id': string
|
||||||
|
id: string
|
||||||
|
name: string | null
|
||||||
|
siret: string | null
|
||||||
|
address: string | null
|
||||||
|
postalCode: string | null
|
||||||
|
city: string | null
|
||||||
|
validityDate: string | null
|
||||||
|
status: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Filtre de la recherche QUALIMAT (branché sur le nom du transporteur). */
|
||||||
|
export interface QualimatSearchFilters {
|
||||||
|
search?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saisie assistée QUALIMAT (M4 Transport, ERP-166 — RG-4.01 / spec-back § 4.7).
|
||||||
|
*
|
||||||
|
* `GET /api/qualimat_carriers?search=` : référentiel en LECTURE SEULE, lignes
|
||||||
|
* actives uniquement (filtré côté serveur), recherche fuzzy nom + siret. Simple
|
||||||
|
* enveloppe de `usePaginatedList` (règle frontend : toute GetCollection passe par
|
||||||
|
* ce composable — pagination Hydra, état 100 % local) consommée par le
|
||||||
|
* `MalioDataTable` de l'onglet Qualimat. Le filtre `search` est piloté par le nom
|
||||||
|
* saisi dans le formulaire principal (pas de champ de recherche dédié).
|
||||||
|
*
|
||||||
|
* Volontairement PAR INSTANCE (état local à l'écran d'ajout).
|
||||||
|
*/
|
||||||
|
export function useQualimatSearch() {
|
||||||
|
return usePaginatedList<QualimatCarrierRow, QualimatSearchFilters>({ url: '/qualimat_carriers' })
|
||||||
|
}
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<!-- En-tete : retour vers le repertoire + titre. -->
|
||||||
|
<div class="flex items-center gap-3 pt-11">
|
||||||
|
<MalioButtonIcon
|
||||||
|
icon="mdi:arrow-left-bold"
|
||||||
|
icon-size="24"
|
||||||
|
variant="ghost"
|
||||||
|
v-bind="{ ariaLabel: t('transport.carriers.form.back') }"
|
||||||
|
@click="goBack"
|
||||||
|
/>
|
||||||
|
<h1 class="text-[30px] font-semibold text-m-primary">{{ t('transport.carriers.form.title') }}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Formulaire principal (pre-onglets) ─────────────────────────────
|
||||||
|
Champs conditionnels (ERP-166) : cas LIOT (nom == LIOT) → seul
|
||||||
|
« immatriculations » ; certification AUTRE → champ Decharge ; Affreter
|
||||||
|
coche → indexation / contenant / volume. La certification est en lecture
|
||||||
|
seule pour un transporteur QUALIMAT (saisie assistee, onglet Qualimat). -->
|
||||||
|
<div class="mt-[48px] grid grid-cols-3 xl:grid-cols-4 gap-x-[44px] gap-y-4">
|
||||||
|
<MalioInputText
|
||||||
|
v-model="main.name"
|
||||||
|
:label="t('transport.carriers.form.main.name')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.name"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Cas LIOT : seul le champ immatriculations est pertinent. -->
|
||||||
|
<MalioInputText
|
||||||
|
v-if="isLiot"
|
||||||
|
v-model="main.liotPlates"
|
||||||
|
:label="t('transport.carriers.form.main.liotPlates')"
|
||||||
|
:hint="t('transport.carriers.form.main.liotPlatesHint')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.liotPlates"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Cas standard : certification + affretement + champs conditionnels. -->
|
||||||
|
<template v-if="!isLiot">
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="main.certificationType"
|
||||||
|
:options="certificationOptions"
|
||||||
|
:label="t('transport.carriers.form.main.certificationType')"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:readonly="certificationReadonly"
|
||||||
|
:error="mainErrors.errors.certificationType"
|
||||||
|
@update:model-value="(v: string | number | null) => main.certificationType = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Colonne 3 RÉSERVÉE à la Décharge (RG-4.02 : visible et obligatoire
|
||||||
|
si certification AUTRE). Si elle n'apparaît pas, on garde la colonne
|
||||||
|
vide (xl) pour qu'« Affréter » reste en colonne 4 de la ligne 1.
|
||||||
|
L'upload reel (File → IRI via useUpload) arrive a ERP-171. -->
|
||||||
|
<!-- TODO ERP-171 : brancher useUpload pour resoudre le File en IRI
|
||||||
|
(main.dischargeDocumentIri). Le champ est deja visible/obligatoire. -->
|
||||||
|
<MalioInputUpload
|
||||||
|
v-if="showDischarge"
|
||||||
|
:label="t('transport.carriers.form.main.discharge')"
|
||||||
|
accept="application/pdf,image/*"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:clearable="true"
|
||||||
|
:error="mainErrors.errors.dischargeDocument"
|
||||||
|
@clear="main.dischargeDocumentIri = null"
|
||||||
|
/>
|
||||||
|
<div v-else class="hidden xl:block"></div>
|
||||||
|
|
||||||
|
<!-- « Affréter » : toujours en colonne 4 de la ligne 1 (colonne 3
|
||||||
|
réservée à la décharge ci-dessus). Wrapper h-12 + centrage vertical
|
||||||
|
pour aligner la case sur la ligne de champ des inputs/selects. -->
|
||||||
|
<div class="flex h-12 items-center">
|
||||||
|
<MalioCheckbox
|
||||||
|
id="carrier-is-chartered"
|
||||||
|
:label="t('transport.carriers.form.main.isChartered')"
|
||||||
|
:model-value="main.isChartered"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:reserve-message-space="false"
|
||||||
|
@update:model-value="(val: boolean) => main.isChartered = val"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RG-4.03 : champs d'affretement (ligne 2) visibles + obligatoires si
|
||||||
|
« Affreter ». La ligne 1 étant pleine (4 colonnes), ils démarrent
|
||||||
|
naturellement en colonne 1 de la ligne 2. -->
|
||||||
|
<template v-if="showCharteredFields">
|
||||||
|
<MalioInputNumber
|
||||||
|
v-model="main.indexationRate"
|
||||||
|
:label="t('transport.carriers.form.main.indexationRate')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.indexationRate"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Contenant : Benne / Fond mouvant (RG-4.03). -->
|
||||||
|
<MalioSelect
|
||||||
|
:model-value="main.containerType"
|
||||||
|
:options="containerOptions"
|
||||||
|
:label="t('transport.carriers.form.main.containerType')"
|
||||||
|
empty-option-label=""
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.containerType"
|
||||||
|
@update:model-value="(v: string | number | null) => main.containerType = v === null ? null : String(v)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<MalioInputNumber
|
||||||
|
v-model="main.volumeM3"
|
||||||
|
:label="t('transport.carriers.form.main.volumeM3')"
|
||||||
|
:required="true"
|
||||||
|
:readonly="mainLocked"
|
||||||
|
:error="mainErrors.errors.volumeM3"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!mainLocked" class="mt-12 flex justify-center">
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
:label="t('transport.carriers.form.submit')"
|
||||||
|
:disabled="mainSubmitting"
|
||||||
|
@click="onSubmitMain"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ── Onglets a validation incrementale ─────────────────────────────
|
||||||
|
Barre Qualimat · Adresses · Contacts · Prix. Onglet Qualimat = saisie
|
||||||
|
assistee (table de selection) ; Adresses / Contacts / Prix arrivent aux
|
||||||
|
tickets suivants (placeholders « A venir »). -->
|
||||||
|
<MalioTabList v-model="activeTab" :tabs="tabs" class="mt-[60px]">
|
||||||
|
<!-- Onglet Qualimat : datatable paginé filtré par le NOM du transporteur
|
||||||
|
(pas de champ de recherche dédié — RG-4.01 / 4.04). -->
|
||||||
|
<template #qualimat>
|
||||||
|
<div class="mt-12 flex flex-col gap-6">
|
||||||
|
<MalioDataTable
|
||||||
|
:columns="qualimatColumns"
|
||||||
|
:items="qualimatRows"
|
||||||
|
:total-items="qualimatTotalDisplay"
|
||||||
|
:page="qualimatPage"
|
||||||
|
:per-page="qualimatPerPage"
|
||||||
|
:per-page-options="qualimatPerPageOptions"
|
||||||
|
row-clickable
|
||||||
|
:empty-message="qualimatEmptyMessage"
|
||||||
|
@row-click="onQualimatRowClick"
|
||||||
|
@update:page="qualimatGoToPage"
|
||||||
|
@update:per-page="qualimatSetPerPage"
|
||||||
|
>
|
||||||
|
<!-- Radio reflétant la ligne QUALIMAT intégrée (lecture). -->
|
||||||
|
<template #cell-select="{ item }">
|
||||||
|
<MalioRadioButton
|
||||||
|
:model-value="main.qualimatCarrierIri"
|
||||||
|
name="qualimat-row"
|
||||||
|
:value="item.iri"
|
||||||
|
group-class="mt-0"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<!-- Date de validité : fond rouge si périmée (RG-4.04). -->
|
||||||
|
<template #cell-validityDate="{ item }">
|
||||||
|
<span
|
||||||
|
v-if="item.validityDate"
|
||||||
|
:class="isExpired(item.validityDate as string) ? 'inline-block rounded px-2 py-0.5 bg-m-danger text-white' : ''"
|
||||||
|
>
|
||||||
|
{{ formatDateFr(item.validityDate as string) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</MalioDataTable>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Adresses / Contacts / Prix : contenu aux tickets suivants. -->
|
||||||
|
<template
|
||||||
|
v-for="key in placeholderTabs"
|
||||||
|
:key="key"
|
||||||
|
#[key]
|
||||||
|
>
|
||||||
|
<div class="mt-12 flex justify-center text-m-muted">
|
||||||
|
{{ t('transport.carriers.form.comingSoon') }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</MalioTabList>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation d'integration QUALIMAT (RG-4.01). -->
|
||||||
|
<MalioModal v-model="confirmOpen" modal-class="max-w-md">
|
||||||
|
<template #header>
|
||||||
|
<h2 class="text-[24px] font-bold">{{ t('transport.carriers.form.qualimat.confirm.title') }}</h2>
|
||||||
|
</template>
|
||||||
|
<p>{{ t('transport.carriers.form.qualimat.confirm.message') }}</p>
|
||||||
|
<template #footer>
|
||||||
|
<MalioButton
|
||||||
|
variant="secondary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.qualimat.confirm.cancel')"
|
||||||
|
@click="confirmOpen = false"
|
||||||
|
/>
|
||||||
|
<MalioButton
|
||||||
|
variant="primary"
|
||||||
|
button-class="flex-1"
|
||||||
|
:label="t('transport.carriers.form.qualimat.confirm.confirm')"
|
||||||
|
@click="confirmIntegrate"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</MalioModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { debounce } from '~/shared/utils/debounce'
|
||||||
|
import { useCarrierForm } from '~/modules/transport/composables/useCarrierForm'
|
||||||
|
import { useQualimatSearch, type QualimatCarrierRow } from '~/modules/transport/composables/useQualimatSearch'
|
||||||
|
|
||||||
|
interface SelectOption {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const router = useRouter()
|
||||||
|
const toast = useToast()
|
||||||
|
const { can } = usePermissions()
|
||||||
|
|
||||||
|
useHead({ title: t('transport.carriers.form.title') })
|
||||||
|
|
||||||
|
// Gating de la route : la creation est reservee a `manage` (Admin / Bureau).
|
||||||
|
// Commerciale (consultation seule), Compta et Usine sont rediriges vers le repertoire.
|
||||||
|
if (!can('transport.carriers.manage')) {
|
||||||
|
await navigateTo('/carriers')
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
main,
|
||||||
|
mainLocked,
|
||||||
|
mainSubmitting,
|
||||||
|
mainErrors,
|
||||||
|
isLiot,
|
||||||
|
certificationReadonly,
|
||||||
|
showCharteredFields,
|
||||||
|
showDischarge,
|
||||||
|
tabKeys,
|
||||||
|
activeTab,
|
||||||
|
unlockedIndex,
|
||||||
|
submitMain,
|
||||||
|
applyQualimatSelection,
|
||||||
|
} = useCarrierForm()
|
||||||
|
|
||||||
|
const {
|
||||||
|
items: qualimatItems,
|
||||||
|
totalItems: qualimatTotal,
|
||||||
|
currentPage: qualimatPage,
|
||||||
|
itemsPerPage: qualimatPerPage,
|
||||||
|
itemsPerPageOptions: qualimatPerPageOptions,
|
||||||
|
goToPage: qualimatGoToPage,
|
||||||
|
setItemsPerPage: qualimatSetPerPage,
|
||||||
|
setFilters: qualimatSetFilters,
|
||||||
|
} = useQualimatSearch()
|
||||||
|
|
||||||
|
// Certifications selectionnables manuellement (spec § Formulaire principal) :
|
||||||
|
// GMP+ / OVOCOM / Compte-propre / Autre. QUALIMAT n'y figure PAS — il est posé par
|
||||||
|
// la saisie assistee (onglet Qualimat). On l'ajoute cependant aux options QUAND il
|
||||||
|
// est deja selectionne (transporteur QUALIMAT integre), uniquement pour AFFICHER
|
||||||
|
// son libelle dans le select en lecture seule.
|
||||||
|
const SELECTABLE_CERTIFICATIONS = ['GMP_PLUS', 'OVOCOM', 'COMPTE_PROPRE', 'AUTRE'] as const
|
||||||
|
|
||||||
|
const certificationOptions = computed<SelectOption[]>(() => {
|
||||||
|
const codes: string[] = [...SELECTABLE_CERTIFICATIONS]
|
||||||
|
if (main.certificationType === 'QUALIMAT') {
|
||||||
|
codes.unshift('QUALIMAT')
|
||||||
|
}
|
||||||
|
return codes.map(code => ({
|
||||||
|
value: code,
|
||||||
|
label: t(`transport.carriers.certification.${code}`),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Colonnes du datatable de selection QUALIMAT (radio / Nom / Adresse / Validite).
|
||||||
|
const qualimatColumns = [
|
||||||
|
{ key: 'select', label: '' },
|
||||||
|
{ key: 'name', label: t('transport.carriers.form.qualimat.columns.name') },
|
||||||
|
{ key: 'address', label: t('transport.carriers.form.qualimat.columns.address') },
|
||||||
|
{ key: 'validityDate', label: t('transport.carriers.form.qualimat.columns.validityDate') },
|
||||||
|
]
|
||||||
|
|
||||||
|
// Le datatable n'affiche QUE des résultats de recherche : vide tant que le Nom n'est
|
||||||
|
// pas saisi (pas de liste complète par défaut). `main.name` pilote l'affichage.
|
||||||
|
const hasQualimatSearch = computed(() => main.name.trim() !== '')
|
||||||
|
|
||||||
|
// Lignes « plates » pour MalioDataTable (l'IRI sert au radio + à retrouver la ligne
|
||||||
|
// source au clic). Le détail QUALIMAT complet reste dans `qualimatItems`.
|
||||||
|
const qualimatRows = computed(() => {
|
||||||
|
if (!hasQualimatSearch.value) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return qualimatItems.value.map(row => ({
|
||||||
|
id: row.id,
|
||||||
|
iri: row['@id'],
|
||||||
|
name: row.name,
|
||||||
|
address: formatQualimatAddress(row),
|
||||||
|
validityDate: row.validityDate,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Total / message vide alignés sur « tableau vide tant qu'on n'a pas recherché ».
|
||||||
|
const qualimatTotalDisplay = computed(() => (hasQualimatSearch.value ? qualimatTotal.value : 0))
|
||||||
|
const qualimatEmptyMessage = computed(() => hasQualimatSearch.value
|
||||||
|
? t('transport.carriers.form.qualimat.empty')
|
||||||
|
: t('transport.carriers.form.qualimat.searchHint'))
|
||||||
|
|
||||||
|
// Contenant (RG-4.03) : Benne / Fond mouvant — select simple.
|
||||||
|
const CONTAINER_TYPES = ['BENNE', 'FOND_MOUVANT'] as const
|
||||||
|
|
||||||
|
const containerOptions = computed<SelectOption[]>(() =>
|
||||||
|
CONTAINER_TYPES.map(code => ({
|
||||||
|
value: code,
|
||||||
|
label: t(`transport.carriers.containerType.${code}`),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Icone (Iconify) affichee dans chaque onglet, par cle.
|
||||||
|
const TAB_ICONS: Record<string, string> = {
|
||||||
|
qualimat: 'mdi:truck-check-outline',
|
||||||
|
addresses: 'mdi:map-marker-outline',
|
||||||
|
contacts: 'mdi:account-box-plus-outline',
|
||||||
|
prices: 'mdi:currency-eur',
|
||||||
|
}
|
||||||
|
|
||||||
|
// Onglets desactives tant que le formulaire principal n'est pas valide
|
||||||
|
// (unlockedIndex = -1 au depart) ; deverrouillage progressif ensuite.
|
||||||
|
const tabs = computed(() => tabKeys.value.map((key, index) => ({
|
||||||
|
key,
|
||||||
|
label: t(`transport.carriers.tab.${key}`),
|
||||||
|
icon: TAB_ICONS[key],
|
||||||
|
disabled: index > unlockedIndex.value,
|
||||||
|
})))
|
||||||
|
|
||||||
|
// Onglets dont le contenu arrive aux tickets suivants (tout sauf Qualimat).
|
||||||
|
const placeholderTabs = computed(() => tabKeys.value.filter(key => key !== 'qualimat'))
|
||||||
|
|
||||||
|
// ── Saisie assistee QUALIMAT (onglet Qualimat) ───────────────────────────────
|
||||||
|
const confirmOpen = ref(false)
|
||||||
|
const pendingRow = ref<QualimatCarrierRow | null>(null)
|
||||||
|
|
||||||
|
// Le datatable QUALIMAT est filtré par le NOM saisi dans le formulaire principal
|
||||||
|
// (RG-4.01) — pas de champ de recherche dédié. Aucune recherche tant que le Nom est
|
||||||
|
// vide (tableau vide par défaut) ; sinon re-filtrage debouncé à chaque frappe.
|
||||||
|
const filterQualimatByName = debounce((term: string) => {
|
||||||
|
if (term.trim() === '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void qualimatSetFilters({ search: term })
|
||||||
|
}, 300)
|
||||||
|
|
||||||
|
watch(() => main.name, term => filterQualimatByName(term))
|
||||||
|
|
||||||
|
/** Adresse QUALIMAT condensee pour la colonne « Adresse » (voie · CP · ville). */
|
||||||
|
function formatQualimatAddress(row: QualimatCarrierRow): string {
|
||||||
|
return [row.address, row.postalCode, row.city].filter(Boolean).join(' · ')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** RG-4.04 : un agrement est perime si sa date de validite est < aujourd'hui. */
|
||||||
|
function isExpired(value: string): boolean {
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const today = new Date()
|
||||||
|
today.setHours(0, 0, 0, 0)
|
||||||
|
date.setHours(0, 0, 0, 0)
|
||||||
|
return date.getTime() < today.getTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Format court francais JJ-MM-AAAA (chaine vide si date absente / invalide). */
|
||||||
|
function formatDateFr(value: string | null | undefined): string {
|
||||||
|
if (!value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
|
return `${day}-${month}-${date.getFullYear()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clic sur une ligne du datatable → retrouve la ligne QUALIMAT source + modal. */
|
||||||
|
function onQualimatRowClick(item: Record<string, unknown>): void {
|
||||||
|
const row = qualimatItems.value.find(r => r.id === item.id)
|
||||||
|
if (row) {
|
||||||
|
askIntegrate(row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ouvre la modal de confirmation d'integration pour une ligne QUALIMAT. */
|
||||||
|
function askIntegrate(row: QualimatCarrierRow): void {
|
||||||
|
pendingRow.value = row
|
||||||
|
confirmOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Confirme l'integration : copie + PATCH (cf. useCarrierForm.applyQualimatSelection). */
|
||||||
|
async function confirmIntegrate(): Promise<void> {
|
||||||
|
const row = pendingRow.value
|
||||||
|
confirmOpen.value = false
|
||||||
|
if (row === null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const ok = await applyQualimatSelection(row)
|
||||||
|
if (ok) {
|
||||||
|
toast.success({ title: t('transport.carriers.toast.integrateSuccess') })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Retour vers le repertoire transporteurs (fleche d'en-tete). */
|
||||||
|
function goBack(): void {
|
||||||
|
router.push('/carriers')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Valide le formulaire principal (POST /carriers ; bascule geree par le composable). */
|
||||||
|
async function onSubmitMain(): Promise<void> {
|
||||||
|
await submitMain()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/**
|
||||||
|
* Types du workflow « Ajouter un transporteur » (M4 Transport, ERP-165 / ERP-166).
|
||||||
|
*
|
||||||
|
* Périmètre :
|
||||||
|
* - ERP-165 : formulaire PRINCIPAL minimal (Nom + Certification + Affréter).
|
||||||
|
* - ERP-166 : champs CONDITIONNELS du formulaire principal (indexation / benne /
|
||||||
|
* volume si affrété — RG-4.03 ; décharge si AUTRE — RG-4.02 ; immatriculations
|
||||||
|
* LIOT — RG-4.01) + saisie assistée QUALIMAT (copie name / certification /
|
||||||
|
* adresse + FK qualimatCarrier — RG-4.01 / § 2.5).
|
||||||
|
*
|
||||||
|
* L'upload réel de la décharge (file → IRI via useUpload) arrive à ERP-171 ; ici
|
||||||
|
* on porte seulement l'IRI résolu (`dischargeDocumentIri`).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brouillon du formulaire principal. Les décimales (indexation / volume) sont
|
||||||
|
* portées en `string` car `MalioInputNumber` émet une chaîne ; le serveur parse.
|
||||||
|
* `certificationType` est un code enum back (GMP_PLUS | OVOCOM | COMPTE_PROPRE |
|
||||||
|
* AUTRE | QUALIMAT — ce dernier posé par la saisie assistée) ou `null`.
|
||||||
|
* `containerType` vaut `BENNE` | `FOND_MOUVANT` (radio) ou `null`.
|
||||||
|
*/
|
||||||
|
export interface CarrierMainDraft {
|
||||||
|
name: string
|
||||||
|
certificationType: string | null
|
||||||
|
isChartered: boolean
|
||||||
|
indexationRate: string
|
||||||
|
containerType: string | null
|
||||||
|
volumeM3: string
|
||||||
|
liotPlates: string
|
||||||
|
/** IRI du document de décharge (résolu par useUpload — ERP-171). */
|
||||||
|
dischargeDocumentIri: string | null
|
||||||
|
/** IRI de la ligne QUALIMAT liée (saisie assistée — null si non QUALIMAT). */
|
||||||
|
qualimatCarrierIri: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Brouillon principal vide (état initial du formulaire de création). */
|
||||||
|
export function emptyCarrierMain(): CarrierMainDraft {
|
||||||
|
return {
|
||||||
|
name: '',
|
||||||
|
certificationType: null,
|
||||||
|
isChartered: false,
|
||||||
|
indexationRate: '',
|
||||||
|
containerType: null,
|
||||||
|
volumeM3: '',
|
||||||
|
liotPlates: '',
|
||||||
|
dischargeDocumentIri: null,
|
||||||
|
qualimatCarrierIri: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adresse copiée depuis le référentiel QUALIMAT à la sélection (RG-4.01 / § 2.5).
|
||||||
|
* Stockée dans l'état du formulaire pour alimenter l'onglet Adresses (ticket
|
||||||
|
* ultérieur) ; pré-remplie « France » côté pays par défaut.
|
||||||
|
*/
|
||||||
|
export interface CarrierAddressCopy {
|
||||||
|
country: string
|
||||||
|
postalCode: string
|
||||||
|
city: string
|
||||||
|
street: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adresse copiée vide. */
|
||||||
|
export function emptyCarrierAddressCopy(): CarrierAddressCopy {
|
||||||
|
return { country: 'France', postalCode: '', city: '', street: '' }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Réponse du POST / PATCH principal (groupe `carrier:read`). Le serveur renvoie
|
||||||
|
* le nom normalisé (UPPERCASE, RG-4.13) que l'UI réaffiche tel quel.
|
||||||
|
*/
|
||||||
|
export interface CarrierMainResponse {
|
||||||
|
id: number
|
||||||
|
name: string | null
|
||||||
|
certificationType: string | null
|
||||||
|
'@id'?: string
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user