fix : ne fait plus de pesée si une pesée existe + fix save des granulé + fix de la génération du pdf
This commit is contained in:
@@ -98,6 +98,30 @@ const selectedBuildingIds = ref<string[]>([])
|
|||||||
const selectedPelletBuildingIds = ref<Record<string, string[]>>({})
|
const selectedPelletBuildingIds = ref<Record<string, string[]>>({})
|
||||||
const merchandiseDetail = ref('')
|
const merchandiseDetail = ref('')
|
||||||
|
|
||||||
|
// Extrait l'ID d'une relation depuis un IRI ou un objet complet.
|
||||||
|
const getRelationId = (value: unknown): string | null => {
|
||||||
|
if (!value) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
const match = value.match(/\/(\d+)$/)
|
||||||
|
return match ? match[1] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'object' && 'id' in value) {
|
||||||
|
const record = value as { id?: number | string }
|
||||||
|
if (typeof record.id === 'number') {
|
||||||
|
return String(record.id)
|
||||||
|
}
|
||||||
|
if (typeof record.id === 'string') {
|
||||||
|
return record.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// Type de marchandise sélectionné dans le select
|
// Type de marchandise sélectionné dans le select
|
||||||
const selectedMerchandiseType = computed(() =>
|
const selectedMerchandiseType = computed(() =>
|
||||||
merchandiseTypes.value.find((type) => String(type.id) === selectedMerchandiseTypeId.value)
|
merchandiseTypes.value.find((type) => String(type.id) === selectedMerchandiseTypeId.value)
|
||||||
@@ -130,8 +154,12 @@ onMounted(async () => {
|
|||||||
const existingPelletSelections = receptionStore.current?.pelletBuildings ?? []
|
const existingPelletSelections = receptionStore.current?.pelletBuildings ?? []
|
||||||
const selectionMap: Record<string, string[]> = {}
|
const selectionMap: Record<string, string[]> = {}
|
||||||
for (const selection of existingPelletSelections) {
|
for (const selection of existingPelletSelections) {
|
||||||
const pelletTypeId = String(selection.pelletType.id)
|
// L'API peut renvoyer les relations comme IRI ou comme objets selon le contexte.
|
||||||
const buildingId = String(selection.building.id)
|
const pelletTypeId = getRelationId(selection.pelletType)
|
||||||
|
const buildingId = getRelationId(selection.building)
|
||||||
|
if (!pelletTypeId || !buildingId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (!selectionMap[pelletTypeId]) {
|
if (!selectionMap[pelletTypeId]) {
|
||||||
selectionMap[pelletTypeId] = []
|
selectionMap[pelletTypeId] = []
|
||||||
}
|
}
|
||||||
@@ -186,7 +214,13 @@ async function syncPelletSelections(receptionIri: string) {
|
|||||||
const existing = await getReceptionPelletBuildingList(receptionIri)
|
const existing = await getReceptionPelletBuildingList(receptionIri)
|
||||||
const existingMap = new Map<string, number>()
|
const existingMap = new Map<string, number>()
|
||||||
for (const selection of existing) {
|
for (const selection of existing) {
|
||||||
const key = `${selection.pelletType.id}:${selection.building.id}`
|
// Construit la table de correspondance avec des IDs normalisés pour éviter les doublons.
|
||||||
|
const pelletTypeId = getRelationId(selection.pelletType)
|
||||||
|
const buildingId = getRelationId(selection.building)
|
||||||
|
if (!pelletTypeId || !buildingId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const key = `${pelletTypeId}:${buildingId}`
|
||||||
existingMap.set(key, selection.id)
|
existingMap.set(key, selection.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,14 +73,8 @@ const printReceipt = async () => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ouvre l'onglet tout de suite pour éviter le blocage popup de Chrome
|
|
||||||
const previewWindow = window.open('', '_blank')
|
|
||||||
if (previewWindow) {
|
|
||||||
previewWindow.opener = null
|
|
||||||
}
|
|
||||||
|
|
||||||
await saveWeight()
|
await saveWeight()
|
||||||
await printPdf(`/receptions/${receptionStore.current.id}/receipt`, previewWindow)
|
await printPdf(`/receptions/${receptionStore.current.id}/receipt`)
|
||||||
|
|
||||||
// Laisse le temps a la boite de dialogue d'impression de s'ouvrir.
|
// Laisse le temps a la boite de dialogue d'impression de s'ouvrir.
|
||||||
await new Promise((resolve) => setTimeout(resolve, 600))
|
await new Promise((resolve) => setTimeout(resolve, 600))
|
||||||
@@ -98,6 +92,8 @@ const printReceipt = async () => {
|
|||||||
|
|
||||||
// Récupère le poids dès l'arrivée sur l'écran
|
// Récupère le poids dès l'arrivée sur l'écran
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchWeight()
|
if (false === displayWeight.value) {
|
||||||
|
fetchWeight()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const usePdfPrinter = () => {
|
|||||||
const receptionStore = useReceptionStore()
|
const receptionStore = useReceptionStore()
|
||||||
const currentReception = receptionStore.current
|
const currentReception = receptionStore.current
|
||||||
|
|
||||||
const printPdf = async (url: string, previewWindow?: Window | null): Promise<void> => {
|
const printPdf = async (url: string): Promise<void> => {
|
||||||
const blob = await api.getBlob(url);
|
const blob = await api.getBlob(url);
|
||||||
|
|
||||||
const pdfBlob = blob.type === 'application/pdf'
|
const pdfBlob = blob.type === 'application/pdf'
|
||||||
@@ -16,17 +16,14 @@ export const usePdfPrinter = () => {
|
|||||||
|
|
||||||
const filename = `${currentReception.identificationNumber}_${currentReception.supplier.name}_${currentReception.licensePlate}.pdf`;
|
const filename = `${currentReception.identificationNumber}_${currentReception.supplier.name}_${currentReception.licensePlate}.pdf`;
|
||||||
|
|
||||||
if (previewWindow) {
|
const a = document.createElement('a');
|
||||||
previewWindow.location.replace(blobUrl)
|
a.href = blobUrl;
|
||||||
}
|
a.download = filename;
|
||||||
|
a.style.display = 'none';
|
||||||
const a = document.createElement('a')
|
document.body.appendChild(a);
|
||||||
a.href = blobUrl
|
a.click();
|
||||||
a.download = filename
|
a.remove();
|
||||||
a.style.display = 'none'
|
// L'ouverture dans un nouvel onglet déclenche un 2e PDF sans le nom personnalisé.
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
a.remove()
|
|
||||||
setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000);
|
setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user