diff --git a/components/displayOpenBalances.vue b/components/displayOpenBalances.vue index 55771c6..aad0c82 100644 --- a/components/displayOpenBalances.vue +++ b/components/displayOpenBalances.vue @@ -11,10 +11,13 @@ const setupPage = async () => { let draftDocuments = documents.filter(i => i.state === "Entwurf") let finalizedDocuments = documents.filter(i => i.state === "Gebucht") + console.log(finalizedDocuments) + finalizedDocuments = finalizedDocuments.filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== getDocumentSum(i).toFixed(2)) finalizedDocuments.forEach(i => { + console.log(getDocumentSum(i)) unpaidInvoicesSum.value += getDocumentSum(i) - i.statementallocations.reduce((n,{amount}) => n + amount, 0) }) unpaidInvoicesCount.value = finalizedDocuments.length diff --git a/pages/createDocument/edit/[[id]].vue b/pages/createDocument/edit/[[id]].vue index d961de5..6bde368 100644 --- a/pages/createDocument/edit/[[id]].vue +++ b/pages/createDocument/edit/[[id]].vue @@ -36,7 +36,7 @@ const itemInfo = ref({ deliveryDate: dayjs(), deliveryDateType: "Lieferdatum", dateOfPerformance: null, - paymentDays: 7, + paymentDays: profileStore.ownTenant.standardPaymentDays, createdBy: profileStore.activeProfile.id, title: null, description: null, @@ -61,6 +61,7 @@ const itemInfo = ref({ usedAdvanceInvoices: [] }) +console.log(profileStore.ownTenant) const letterheads = ref([]) const createddocuments = ref([]) @@ -78,6 +79,7 @@ const texttemplates = ref([]) const loaded = ref(false) const setupPage = async () => { + letterheads.value = (await useSupabaseSelect("letterheads","*")).filter(i => i.documentTypes.length === 0 || i.documentTypes.includes(itemInfo.value.type)) createddocuments.value = (await useSupabaseSelect("createddocuments","*")) projects.value = (await useSupabaseSelect("projects","*")) @@ -154,7 +156,7 @@ const setupPage = async () => { setPosNumbers() - if(linkedDocuments.find(i => i.agriculture)){ + if(linkedDocuments.find(i => i.agriculture.dieselUsage)){ itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "dieselPos") itemInfo.value.rows.push({ @@ -185,6 +187,19 @@ const setupPage = async () => { setCustomerData() + if(route.query.loadMode === "storno") { + itemInfo.value.rows.forEach(row => { + row.price = row.price * -1 + }) + + itemInfo.value.description = `Stornorechnung zu Rechnung ${linkedDocument.documentNumber} vom ${dayjs(linkedDocument.documentDate).format('DD.MM.YYYY')}` + + itemInfo.value.type = "cancellationInvoices" + + setDocumentTypeConfig(true) + + } + } @@ -227,7 +242,7 @@ const addAdvanceInvoiceToInvoice = (advanceInvoice) => { } const setDocumentTypeConfig = (withTexts = false) => { - if(itemInfo.value.type === "invoices" ||itemInfo.value.type === "advanceInvoices" || itemInfo.value.type === "serialInvoices") { + if(itemInfo.value.type === "invoices" ||itemInfo.value.type === "advanceInvoices" || itemInfo.value.type === "serialInvoices"|| itemInfo.value.type === "cancellationInvoices") { itemInfo.value.documentNumberTitle = "Rechnungsnummer" itemInfo.value.title = `Rechnung-Nr. ${itemInfo.value.documentNumber ? itemInfo.value.documentNumber : "XXXX"}` } else if(itemInfo.value.type === "quotes") { @@ -433,6 +448,21 @@ const findDocumentErrors = computed(() => { if(row.mode === "title" && !row.text) errors.push({message: `In Position ${row.pos} ist kein Titel hinterlegt`, type: "breaking"}) if(row.mode === "text" && !row.text) errors.push({message: `In einer Freitext Position ist kein Titel hinterlegt`, type: "breaking"}) if(row.mode === "free" && !row.text) errors.push({message: `In einer freien Position ist kein Titel hinterlegt`, type: "breaking"}) + + if(["normal","service","free"].includes(row.mode)){ + + if(!row.taxPercent) errors.push({message: `In Position ${row.pos} ist kein Steuersatz hinterlegt`, type: "breaking"}) + if(!row.price || row.price === 0) errors.push({message: `In Position ${row.pos} ist kein Preis hinterlegt`, type: "breaking"}) + + + } + + if(row.agriculture){ + if(row.agriculture.dieselUsage && (!row.agriculture.dieselPrice || row.agriculture.dieselPrice === 0)) { + errors.push({message: `In Position ${row.pos} ist kein Dieselpreis hinterlegt`, type: "breaking"}) + } + } + }) } @@ -760,7 +790,7 @@ const saveDocument = async (state,resetup = false) => { console.log("???") let type = "" - if(itemInfo.value.type === "advanceInvoices"){ + if(itemInfo.value.type === "advanceInvoices" || itemInfo.value.type === "cancellationInvoices"){ type = "invoices" } else { type = itemInfo.value.type @@ -852,9 +882,16 @@ const closeDocument = async () => { fileData.project = itemInfo.value.project fileData.createddocument = itemInfo.value.id - fileData.folder = (await supabase.from("folders").select("id").eq("tenant", profileStore.currentTenant).eq("function", itemInfo.value.type).eq("year",dayjs().format("YYYY")).single()).data.id - let tag = (await supabase.from("filetags").select("id").eq("tenant", profileStore.currentTenant).eq("createddocumenttype", itemInfo.value.type).single()).data + let mappedType = itemInfo.value.type + + if(mappedType === "advanceInvoices" || mappedType === "cancellationInvoices"){ + mappedType = "invoices" + } + + fileData.folder = (await supabase.from("folders").select("id").eq("tenant", profileStore.currentTenant).eq("function", mappedType).eq("year",dayjs().format("YYYY")).single()).data.id + + let tag = (await supabase.from("filetags").select("id").eq("tenant", profileStore.currentTenant).eq("createddocumenttype", mappedType).single()).data function dataURLtoFile(dataurl, filename) { var arr = dataurl.split(","), @@ -893,12 +930,14 @@ const setRowData = (row) => { row.unit = services.value.find(i => i.id === row.service).unit row.price = services.value.find(i => i.id === row.service).sellingPriceComposed.total || services.value.find(i => i.id === row.service).sellingPrice row.description = services.value.find(i => i.id === row.service).description + row.taxPercent = services.value.find(i => i.id === row.service).taxPercentage } if(row.product) { row.unit = products.value.find(i => i.id === row.product).unit row.price = products.value.find(i => i.id === row.product).sellingPrice row.description = products.value.find(i => i.id === row.product).description + row.taxPercent = products.value.find(i => i.id === row.product).taxPercentage } @@ -956,14 +995,14 @@ const setRowData = (row) => { diff --git a/pages/createDocument/show/[id].vue b/pages/createDocument/show/[id].vue index f235a94..df4764d 100644 --- a/pages/createDocument/show/[id].vue +++ b/pages/createDocument/show/[id].vue @@ -79,6 +79,13 @@ const openEmail = () => { > E-Mail + + Stornieren + { > Projekt + diff --git a/stores/data.js b/stores/data.js index 1053d7e..ce433c0 100644 --- a/stores/data.js +++ b/stores/data.js @@ -1728,6 +1728,10 @@ export const useDataStore = defineStore('data', () => { label: "Abschlagsrechnungen", labelSingle: "Abschlagsrechnung" }, + cancellationInvoices: { + label: "Stornorechnungen", + labelSingle: "Stornorechnung" + }, quotes: { label: "Angebote", labelSingle: "Angebot"