feat : ajout du numéro identification des receptions et ajustement du bon de reception

This commit is contained in:
2026-01-29 09:43:46 +01:00
parent f901d52324
commit cff80b5ab2
10 changed files with 213 additions and 191 deletions

View File

@@ -1,40 +1,29 @@
import type { Ref } from 'vue'
import { useApi } from '~/composables/useApi'
type PrintFrameRef = Ref<HTMLIFrameElement | null>
import {useApi} from '~/composables/useApi'
export const usePdfPrinter = () => {
const api = useApi()
const api = useApi()
const receptionStore = useReceptionStore()
const currentReception = receptionStore.current
const printPdf = async (url: string, frameRef: PrintFrameRef): Promise<void> => {
if (!import.meta.client) {
return
const printPdf = async (url: string): Promise<void> => {
if (!import.meta.client) {
return
}
const blob = await api.getBlob(url)
const blobUrl = URL.createObjectURL(blob)
const a = document.createElement('a');
a.href = url;
// nom du fichier à changer par les infos du store pinia
a.download = `${currentReception.identificationNumber}_${currentReception.supplier.name}_${currentReception.licensePlate}`;
document.body.appendChild(a);
a.click();
a.remove();
window.open(blobUrl, '_blank', 'noopener,noreferrer')
setTimeout(() => URL.revokeObjectURL(blobUrl), 60000)
}
const frame = frameRef.value
if (!frame) {
return
return {
printPdf
}
// On charge le PDF en blob pour rester en same-origin dans l'iframe.
const blob = await api.getBlob(url)
const blobUrl = URL.createObjectURL(blob)
const tryPrint = () => {
frame.contentWindow?.focus()
frame.contentWindow?.print()
}
frame.onload = () => {
tryPrint()
// On libere l'URL blob apres l'impression.
setTimeout(() => URL.revokeObjectURL(blobUrl), 2000)
}
frame.src = blobUrl
setTimeout(tryPrint, 1200)
}
return {
printPdf
}
}