diff --git a/composables/usePDFGenerator.js b/composables/usePDFGenerator.js index 8227b7b..046f66e 100644 --- a/composables/usePDFGenerator.js +++ b/composables/usePDFGenerator.js @@ -900,7 +900,7 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => { if(row.descriptionText) { - pages[pageCounter - 1].drawText(row.descriptionText.match(/.{1,80}/g).join("\n"), { + pages[pageCounter - 1].drawText(row.descriptionText.match(/.{1,100}/g).join("\n"), { ...getCoordinatesForPDFLib(21,rowHeight + ( textAutoLines * 4), page1), size:10, color:rgb(0,0,0), @@ -1015,7 +1015,6 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => { } - pages[pageCounter - 1].drawText(invoiceData.endText,{ ...getCoordinatesForPDFLib(20,rowHeight+22, page1), size: 10, diff --git a/pages/createDocument/edit/[[id]].vue b/pages/createDocument/edit/[[id]].vue index 08cca6d..153ae2c 100644 --- a/pages/createDocument/edit/[[id]].vue +++ b/pages/createDocument/edit/[[id]].vue @@ -85,7 +85,7 @@ const setupPage = async () => { if(servicecategories.value.length > 0) selectedServicecategorie.value = servicecategories.value[0].id if(route.params) { - if(route.params.id) itemInfo.value = dataStore.getCreatedDocumentById(Number(route.params.id)) + if(route.params.id) itemInfo.value = await useSupabaseSelectSingle("createddocuments", route.params.id) if(!itemInfo.value.deliveryDateType) itemInfo.value.deliveryDateType = "Lieferdatum" @@ -98,7 +98,11 @@ const setupPage = async () => { if(route.query) { if(route.query.type) itemInfo.value.type = route.query.type - setDocumentTypeConfig() + if(!itemInfo.value.startText && !itemInfo.value.endText) { + setDocumentTypeConfig(true) + } else { + setDocumentTypeConfig(false) + } @@ -170,7 +174,7 @@ const setupPage = async () => { } } -const setDocumentTypeConfig = () => { +const setDocumentTypeConfig = (withTexts = false) => { if(itemInfo.value.type === "invoices" ||itemInfo.value.type === "advanceInvoices" || itemInfo.value.type === "serialInvoices") { itemInfo.value.documentNumberTitle = "Rechnungsnummer" itemInfo.value.title = `Rechnung-Nr. ${itemInfo.value.documentNumber ? itemInfo.value.documentNumber : "XXXX"}` @@ -185,11 +189,10 @@ const setDocumentTypeConfig = () => { itemInfo.value.title = `Auftragsbestätigung-Nr. ${itemInfo.value.documentNumber ? itemInfo.value.documentNumber : "XXXX"}` } - /*if(!itemInfo.value.startText)*/ itemInfo.value.startText = dataStore.getTextTemplatesByDocumentType(itemInfo.value.type).find(i => i.default && i.pos === "startText").text - /*if(!itemInfo.value.endText)*/ itemInfo.value.endText = dataStore.getTextTemplatesByDocumentType(itemInfo.value.type).find(i => i.default && i.pos === "endText").text - - - + if(withTexts) { + itemInfo.value.startText = dataStore.getTextTemplatesByDocumentType(itemInfo.value.type).find(i => i.default && i.pos === "startText").text + itemInfo.value.endText = dataStore.getTextTemplatesByDocumentType(itemInfo.value.type).find(i => i.default && i.pos === "endText").text + } itemInfo.value.letterhead = letterheads.value[0].id @@ -492,12 +495,7 @@ const getDocumentData = () => { let unit = dataStore.units.find(i => i.id === row.unit) - if(!['pagebreak','title','text'].includes(row.mode)) { - if(row.mode === 'normal') row.text = dataStore.getProductById(row.product).name - if(row.mode === 'service') row.text = dataStore.getServiceById(row.service).name - - console.log(row) - + if(!['pagebreak','title'].includes(row.mode)){ if(row.agriculture?.description) { console.log("Row has Agri") row.descriptionText = row.agriculture.description @@ -505,6 +503,12 @@ const getDocumentData = () => { console.log("Row has no Agri") row.descriptionText = row.description } + } + + if(!['pagebreak','title','text'].includes(row.mode)) { + if(row.mode === 'normal') row.text = dataStore.getProductById(row.product).name + if(row.mode === 'service') row.text = dataStore.getServiceById(row.service).name + return { ...row, @@ -533,9 +537,6 @@ const getDocumentData = () => { } } - - - const returnData = { type: itemInfo.value.type, adressLine: `${businessInfo.name}, ${businessInfo.street}, ${businessInfo.zip} ${businessInfo.city}`, @@ -645,29 +646,23 @@ const saveSerialInvoice = async () => { await router.push(`/createDocument/edit/${data[0].id}`) } -const saveDocument = async () => { - let createData = { - type: itemInfo.value.type, - state: itemInfo.value.state || "Entwurf", - customer: itemInfo.value.customer, - contact: itemInfo.value.contact, - address: itemInfo.value.address, - project: itemInfo.value.project, - documentNumber: itemInfo.value.documentNumber, - documentDate: itemInfo.value.documentDate, - deliveryDate: itemInfo.value.deliveryDate, - paymentDays: itemInfo.value.paymentDays, - deliveryDateType: itemInfo.value.deliveryDateType, - info: {}, - createdBy: itemInfo.value.createdBy, - title: itemInfo.value.title, - description: itemInfo.value.description, - startText: itemInfo.value.startText, - endText: itemInfo.value.endText, - rows: itemInfo.value.rows, - contactPerson: itemInfo.value.contactPerson, - linkedDocument: itemInfo.value.linkedDocument, - agriculture: itemInfo.value.agriculture +const saveDocument = async (state) => { + + itemInfo.value.state = state + + if(state !== "Entwurf") { + console.log("???") + + let type = "" + if(itemInfo.value.type === "advanceInvoices"){ + type = "invoices" + } else { + type = itemInfo.value.type + } + + const numberRange = useNumberRange(type) + itemInfo.value.documentNumber = await numberRange.useNextNumber() + setDocumentTypeConfig(false) } if(dataStore.ownTenant.extraModules.includes("agriculture")) { @@ -695,23 +690,45 @@ const saveDocument = async () => { } }) - let data = null - - if(route.params.id) { - data = await dataStore.updateItem("createddocuments", {...createData, id: itemInfo.value.id}) - } else { - data = await dataStore.createNewItem("createddocuments", createData) + let createData = { + type: itemInfo.value.type, + state: itemInfo.value.state || "Entwurf", + customer: itemInfo.value.customer, + contact: itemInfo.value.contact, + address: itemInfo.value.address, + project: itemInfo.value.project, + documentNumber: itemInfo.value.documentNumber, + documentDate: itemInfo.value.documentDate, + deliveryDate: itemInfo.value.deliveryDate, + paymentDays: itemInfo.value.paymentDays, + deliveryDateType: itemInfo.value.deliveryDateType, + info: {}, + createdBy: itemInfo.value.createdBy, + title: itemInfo.value.title, + description: itemInfo.value.description, + startText: itemInfo.value.startText, + endText: itemInfo.value.endText, + rows: itemInfo.value.rows, + contactPerson: itemInfo.value.contactPerson, + linkedDocument: itemInfo.value.linkedDocument, + agriculture: itemInfo.value.agriculture, + letterhead: itemInfo.value.letterhead } - await router.push(`/createDocument/edit/${data[0].id}`) + if(route.params.id) { + await dataStore.updateItem("createddocuments", {...createData, id: itemInfo.value.id}) + } else { + const {data} = await dataStore.createNewItem("createddocuments", createData) + await router.push(`/createDocument/edit/${data[0].id}`) + } + + await setupPage() } const closeDocument = async () => { - itemInfo.value.state = "Gebucht" - - await saveDocument() + await saveDocument("Gebucht") await generateDocument() @@ -756,7 +773,7 @@ setupPage()