diff --git a/pages/createDocument/edit/[[id]].vue b/pages/createDocument/edit/[[id]].vue
index 004bf00..fae2c18 100644
--- a/pages/createDocument/edit/[[id]].vue
+++ b/pages/createDocument/edit/[[id]].vue
@@ -129,74 +129,133 @@ const setupPage = async () => {
if(route.query.linkedDocuments) {
- let linkedDocuments = (await supabase.from("createddocuments").select().in("id",JSON.parse(route.query.linkedDocuments))).data
+ console.log(route.query.loadMode)
- //TODO: Implement Checking for Same Customer, Contact and Project
+ if(route.query.loadMode === "deliveryNotes") {
+ let linkedDocuments = (await supabase.from("createddocuments").select().in("id",JSON.parse(route.query.linkedDocuments))).data
- itemInfo.value.customer = linkedDocuments[0].customer
- itemInfo.value.project = linkedDocuments[0].project
- itemInfo.value.contact = linkedDocuments[0].contact
+ //TODO: Implement Checking for Same Customer, Contact and Project
- setCustomerData()
+ itemInfo.value.customer = linkedDocuments[0].customer
+ itemInfo.value.project = linkedDocuments[0].project
+ itemInfo.value.contact = linkedDocuments[0].contact
- let firstDate = null
- let lastDate = null
+ setCustomerData()
+
+ let firstDate = null
+ let lastDate = null
+
+ linkedDocuments.forEach(doc => {
+ let lastId = 0
+ itemInfo.value.rows.forEach(row => {
+ if(row.id > lastId) lastId = row.id
+ })
+
+ if(dayjs(doc.documentDate).isBefore(firstDate) || !firstDate) firstDate = doc.documentDate
+ if(dayjs(doc.documentDate).isAfter(lastDate) || !lastDate) lastDate = doc.documentDate
+
+ itemInfo.value.rows.push(...[
+ {
+ id:uuidv4(),
+ mode: "title",
+ text: `${doc.title} vom ${dayjs(doc.documentDate).format("DD.MM.YYYY")}`
+ },
+ ...doc.rows
+ ])
- linkedDocuments.forEach(doc => {
- let lastId = 0
- itemInfo.value.rows.forEach(row => {
- if(row.id > lastId) lastId = row.id
})
- if(dayjs(doc.documentDate).isBefore(firstDate) || !firstDate) firstDate = doc.documentDate
- if(dayjs(doc.documentDate).isAfter(lastDate) || !lastDate) lastDate = doc.documentDate
+ itemInfo.value.deliveryDateType = "Leistungszeitraum"
+ itemInfo.value.deliveryDate = firstDate
+ itemInfo.value.deliveryDateEnd = lastDate
- itemInfo.value.rows.push(...[
- {
+ itemInfo.value.rows.forEach(row => {
+
+ row.discountPercent = 0
+
+ setRowData(row)
+
+ })
+
+ setPosNumbers()
+
+ console.log(linkedDocuments)
+
+ if(linkedDocuments.find(i => i.rows.find( x => x.agriculture.dieselUsage))){
+ console.log("has diesel")
+
+ //Remove Existing Total Diesel Pos
+ itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "dieselPos")
+ //Remove Existing Total Ad Blue Pos
+ itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "adbluePos")
+
+ //Add Total Title
+ itemInfo.value.rows.push({
id:uuidv4(),
mode: "title",
- text: `${doc.title} vom ${dayjs(doc.documentDate).format("DD.MM.YYYY")}`
- },
- ...doc.rows
- ])
+ text: "Allgemein"
+ })
- })
+ processDieselPosition()
+ }
- itemInfo.value.deliveryDateType = "Leistungszeitraum"
- itemInfo.value.deliveryDate = firstDate
- itemInfo.value.deliveryDateEnd = lastDate
+ } else if(route.query.loadMode === "finalInvoice") {
+ let linkedDocuments = (await supabase.from("createddocuments").select().in("id",JSON.parse(route.query.linkedDocuments))).data
- itemInfo.value.rows.forEach(row => {
+ //TODO: Implement Checking for Same Customer, Contact and Project
- row.discountPercent = 0
+ console.log(linkedDocuments)
- setRowData(row)
+ itemInfo.value.customer = linkedDocuments[0].customer
+ itemInfo.value.project = linkedDocuments[0].project
+ itemInfo.value.contact = linkedDocuments[0].contact
- })
+ setCustomerData()
- setPosNumbers()
+ for await (const doc of linkedDocuments.filter(i => i.type === "confirmationOrders")) {
+ let linkedDocument = await useSupabaseSelectSingle("createddocuments",doc.id)
+ itemInfo.value.rows.push(...linkedDocument.rows)
+ }
- console.log(linkedDocuments)
+ for await (const doc of linkedDocuments.filter(i => i.type === "quotes")) {
+ let linkedDocument = await useSupabaseSelectSingle("createddocuments",doc.id)
+ itemInfo.value.rows.push(...linkedDocument.rows)
+ }
+
+ for await (const doc of linkedDocuments.filter(i => i.type === "advanceInvoices")) {
+ itemInfo.value.rows.push({
+ mode: "free",
+ text: `Abschlagsrechnung ${doc.documentNumber}`,
+ quantity: 1,
+ taxPercent: 19, // TODO TAX PERCENTAGE
+ discountPercent: 0,
+ unit: 10,
+ inputPrice: useSum().getCreatedDocumentSumDetailed(doc).totalNet *-1,
+ linkedEntitys: [
+ {
+ type: "createddocuments",
+ subtype: "advanceInvoices",
+ id: doc.id
+ }
+ ],
+ editDisabled: true
+
+ })
+
+ updateCustomSurcharge()
+
+ }
+
+ setPosNumbers()
- if(linkedDocuments.find(i => i.rows.find( x => x.agriculture.dieselUsage))){
- console.log("has diesel")
- //Remove Existing Total Diesel Pos
- itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "dieselPos")
- //Remove Existing Total Ad Blue Pos
- itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "adbluePos")
- //Add Total Title
- itemInfo.value.rows.push({
- id:uuidv4(),
- mode: "title",
- text: "Allgemein"
- })
- processDieselPosition()
}
+
+
}
if(route.query.linkedDocument) {
@@ -265,6 +324,12 @@ const setupPage = async () => {
row.price = row.price * -1
})
+ itemInfo.value.documentDate = dayjs()
+
+ itemInfo.value.usedAdvanceInvoices = linkedDocument.usedAdvanceInvoices
+
+ checkForOpenAdvanceInvoices()
+
itemInfo.value.description = `Stornorechnung zu Rechnung ${linkedDocument.documentNumber} vom ${dayjs(linkedDocument.documentDate).format('DD.MM.YYYY')}`
itemInfo.value.type = "cancellationInvoices"
@@ -310,11 +375,12 @@ setupPage()
const openAdvanceInvoices = ref([])
const checkForOpenAdvanceInvoices = async () => {
console.log("Check for Open Advance Invoices")
- const {data,error} = await supabase.from("createddocuments").select().eq("project", itemInfo.value.project).eq("advanceInvoiceResolved", false).eq("type","advanceInvoices")
+ const {data} = await supabase.from("createddocuments").select().eq("project", itemInfo.value.project).eq("advanceInvoiceResolved", false).eq("type","advanceInvoices")
+ const {data: usedAdvanceInvoices} = await supabase.from("createddocuments").select().in("id", itemInfo.value.usedAdvanceInvoices)
console.log(data)
- openAdvanceInvoices.value = data
+ openAdvanceInvoices.value = [...data, ...usedAdvanceInvoices.filter(i => !data.find(x => x.id === i.id))]
}
@@ -487,7 +553,8 @@ const addPosition = (mode) => {
inputPrice: 0,
price: 0,
taxPercent: taxPercentage,
- discountPercent: 0
+ discountPercent: 0,
+ linkedEntitys: []
}
itemInfo.value.rows.push({...rowData, ...profileStore.ownTenant.extraModules.includes("agriculture") ? {agriculture: {}}: {}})
@@ -501,7 +568,8 @@ const addPosition = (mode) => {
price: 0,
taxPercent: taxPercentage,
discountPercent: 0,
- unit: 1
+ unit: 1,
+ linkedEntitys: []
})
} else if(mode === 'service'){
let rowData = {
@@ -512,7 +580,8 @@ const addPosition = (mode) => {
price: 0,
taxPercent: taxPercentage,
discountPercent: 0,
- unit: 1
+ unit: 1,
+ linkedEntitys: []
}
//Push Agriculture Holder only if Module is activated
@@ -521,16 +590,19 @@ const addPosition = (mode) => {
itemInfo.value.rows.push({
id: uuidv4(),
mode: "pagebreak",
+ linkedEntitys: []
})
} else if(mode === "title") {
itemInfo.value.rows.push({
id: uuidv4(),
mode: "title",
+ linkedEntitys: []
})
} else if(mode === "text") {
itemInfo.value.rows.push({
id: uuidv4(),
mode: "text",
+ linkedEntitys: []
})
}
@@ -692,7 +764,22 @@ const documentTotal = computed(() => {
console.log(totalGrossAlreadyPaid)
- let sumToPay = totalGross - totalGrossAlreadyPaid
+ let sumToPay = 0
+
+ if(itemInfo.value.type === "invoices") {
+ sumToPay = totalGross - totalGrossAlreadyPaid
+ } else if(itemInfo.value.type === "cancellationInvoices") {
+ sumToPay = totalGross + totalGrossAlreadyPaid
+
+ }
+
+
+
+
+
+
+
+
return {
titleSums: titleSums,
@@ -2083,6 +2170,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {