Added Function to Cancel Invoices

This commit is contained in:
2025-01-17 17:26:59 +01:00
parent cdb3131185
commit 6626bd568d
5 changed files with 63 additions and 9 deletions

View File

@@ -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

View File

@@ -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) => {
<UAlert
class="my-5"
title="Vorhandene Probleme:"
title="Vorhandene Probleme und Informationen:"
:color="findDocumentErrors.filter(i => i.type === 'breaking').length > 0 ? 'rose' : 'white'"
variant="outline"
v-if="findDocumentErrors.length > 0"
>
<template #description>
<ul class="list-disc ml-5">
<li v-for="error in findDocumentErrors" :class="[...error.type === 'breaking' ? ['text-rose-600'] : ['text-gray-700']]">
<li v-for="error in findDocumentErrors" :class="[...error.type === 'breaking' ? ['text-rose-600'] : ['text-white']]">
{{error.message}}
</li>
</ul>

View File

@@ -111,7 +111,7 @@
</div>
</template>
<template #amount-data="{row}">
{{displayCurrency(calculateDocSum(row))}}
<span v-if="row.type !== 'deliveryNotes'">{{displayCurrency(calculateDocSum(row))}}</span>
</template>
</UTable>

View File

@@ -79,6 +79,13 @@ const openEmail = () => {
>
E-Mail
</UButton>
<UButton
@click="router.push(`/createDocument/edit/?linkedDocument=${itemInfo.id}&loadMode=storno`)"
variant="outline"
color="rose"
>
Stornieren
</UButton>
<UButton
v-if="itemInfo.project"
@click="router.push(`/standardEntity/projects/show/${itemInfo.project}`)"
@@ -87,6 +94,7 @@ const openEmail = () => {
>
Projekt
</UButton>
</template>
</UDashboardToolbar>
<UDashboardPanelContent>

View File

@@ -1728,6 +1728,10 @@ export const useDataStore = defineStore('data', () => {
label: "Abschlagsrechnungen",
labelSingle: "Abschlagsrechnung"
},
cancellationInvoices: {
label: "Stornorechnungen",
labelSingle: "Stornorechnung"
},
quotes: {
label: "Angebote",
labelSingle: "Angebot"