From 132016f562db8a102d038d34b9143907bec7cb91 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Sat, 7 Jun 2025 16:34:44 +0200 Subject: [PATCH] Added AI Suggestion to IncomingInvoice Create --- composables/useFunctions.js | 20 +++++ pages/incomingInvoices/create.vue | 134 +++++++++++++++++++++++++++++- 2 files changed, 153 insertions(+), 1 deletion(-) diff --git a/composables/useFunctions.js b/composables/useFunctions.js index 08d0cfa..c6f6e8d 100644 --- a/composables/useFunctions.js +++ b/composables/useFunctions.js @@ -101,6 +101,26 @@ export const useFunctions = () => { } + const useGetInvoiceData = async (file) => { + const {data:{session:{access_token}}} = await supabase.auth.getSession() + + const {data} = await axios({ + method: "POST", + url: `${baseURL}/functions/getinvoicedatafromgpt`, + data: { + file + }, + headers: { + Authorization: `Bearer ${access_token}` + } + }) + + console.log(data) + + return data + + } + const useSendTelegramNotification = async (message) => { const {data:{session:{access_token}}} = await supabase.auth.getSession() diff --git a/pages/incomingInvoices/create.vue b/pages/incomingInvoices/create.vue index a40d90d..34e7f0b 100644 --- a/pages/incomingInvoices/create.vue +++ b/pages/incomingInvoices/create.vue @@ -145,6 +145,127 @@ const setCostCentre = async (item,data) => { item.costCentre = data.id } +const gptLoading = ref(false) + +const getInvoiceData = async () => { + gptLoading.value = true + console.log(loadedFile.value) + + + //loadedFile.value.url + + + /*let data = { + "invoice_number": "3423478673", + "invoice_date": "2025-05-30", + "invoice_type": "incoming", + "delivery_type": "null", + "delivery_note_number": "null", + "reference": "null", + "issuer": { + "name": "Boels Rental Germany GmbH", + "address": "Emeranstraße 49-51, 85622 Feldkirchen, Deutschland", + "phone": "+49-(0)1801663225", + "email": "fakturierung@boels.de", + "bank": "ABN AMRO Bank N.V.", + "bic": "ABNANL2A", + "iban": "NL09 ABNA 0520 5585 61" + }, + "recipient": { + "name": "Federspiel Technology UG", + "address": "Am Schwarzen Brack 14, 26452 Sande, Deutschland", + "phone": "null", + "email": "null" + }, + "invoice_items": [ + { + "description": "Bautrockner 50 ltr.", + "unit": "piece", + "quantity": 1, + "total": 395.22 + }, + { + "description": "Servicepauschale Kat. A", + "unit": "piece", + "quantity": 1, + "total": 32.1 + }, + { + "description": "Haftungsbegrenzung A: (Schäden, exkl. Feuer/Diebstahl/Einbruch)", + "unit": "piece", + "quantity": 1, + "total": 3.2 + }, + { + "description": "Haftungsbegrenzung B: (Feuer/Diebstahl/Einbruch)", + "unit": "piece", + "quantity": 1, + "total": 16.93 + } + ], + "subtotal": 89.1, + "tax_rate": 19, + "tax": 16.93, + "total": 106.03, + "terms": "Dieser Betrag wird automatisch mittels Lastschrift von ihrem Konto eingezogen" + } + + console.log(data) + console.log(data.subtotal)*/ + + + + let data = await useFunctions().useGetInvoiceData(loadedFile.value) + + + + + if(data.invoice_number) itemInfo.value.reference = data.invoice_number + if(data.invoice_date) itemInfo.value.date = dayjs(data.invoice_date) + if(data.issuer.id) itemInfo.value.vendor = data.issuer.id + if(data.invoice_duedate) itemInfo.value.dueDate = dayjs(data.invoice_duedate) + if(data.terms) itemInfo.value.paymentType = data.terms + if(data.subtotal) { + itemInfo.value.accounts = [ + { + account: null, + amountNet: data.subtotal, + amountTax: data.tax, + taxType: String(data.tax_rate), + costCentre: null, + amountGross: Number(data.subtotal) + Number(data.tax) + } + ] + } + + if(data.terms === "Direct Debit") { + itemInfo.value.paymentType = "Einzug" + } else if(data.terms === "Transfer") { + itemInfo.value.paymentType = "Überweisung" + } else if(data.terms === "Credit Card") { + itemInfo.value.paymentType = "Kreditkarte" + } else if(data.terms === "Other") { + itemInfo.value.paymentType = "Sonstiges" + } + + let description = "" + + if(data.delivery_note_number) description += `Lieferschein: ${data.delivery_note_number} \n` + if(data.reference) description += `Referenz: ${data.reference} \n` + if(data.invoice_items) { + data.invoice_items.forEach(item => { + description += `${item.description} - ${item.quantity} ${item.unit} - ${item.total}\n` + }) + } + itemInfo.value.description = description + + + + + gptLoading.value = false + + +} @@ -204,6 +325,17 @@ const setCostCentre = async (item,data) => {
+ + KI - Vorschlag + + + { :color="!item.amountNet ? 'rose' : 'primary'" :disabled="item.taxType === null" @keyup="item.amountTax = Number((item.amountNet * (Number(taxOptions.find(i => i.key === item.taxType).percentage)/100)).toFixed(2)), - item.amountGross = Number(item.amountNet) + NUmber(item.amountTax)" + item.amountGross = Number(item.amountNet) + Number(item.amountTax)" >