Added Agriculture Module to Invoice Creation
This commit is contained in:
@@ -633,8 +633,8 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => {
|
|||||||
console.log(textAutoLines)
|
console.log(textAutoLines)
|
||||||
|
|
||||||
|
|
||||||
if(row.description) {
|
if(row.descriptionText) {
|
||||||
pages[pageCounter - 1].drawText(row.description.match(/.{1,70}/g).join("\n"), {
|
pages[pageCounter - 1].drawText(row.descriptionText.match(/.{1,70}/g).join("\n"), {
|
||||||
...getCoordinatesForPDFLib(52,rowHeight + ( textAutoLines * 4), page1),
|
...getCoordinatesForPDFLib(52,rowHeight + ( textAutoLines * 4), page1),
|
||||||
size:10,
|
size:10,
|
||||||
color:rgb(0,0,0),
|
color:rgb(0,0,0),
|
||||||
@@ -678,9 +678,9 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(row.description) {
|
if(row.descriptionText) {
|
||||||
let lineBreaks = (row.description.match(/\n/g) || []).length
|
let lineBreaks = (row.descriptionText.match(/\n/g) || []).length
|
||||||
let autoLines = (row.description.match(/.{1,70}/g) || []).length
|
let autoLines = (row.descriptionText.match(/.{1,70}/g) || []).length
|
||||||
rowHeight += 12 + (lineBreaks + autoLines + textAutoLines) * 2.5
|
rowHeight += 12 + (lineBreaks + autoLines + textAutoLines) * 2.5
|
||||||
} else {
|
} else {
|
||||||
rowHeight += 12 + textAutoLines * 2.5
|
rowHeight += 12 + textAutoLines * 2.5
|
||||||
@@ -860,8 +860,8 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => {
|
|||||||
//console.log(textAutoLines)
|
//console.log(textAutoLines)
|
||||||
|
|
||||||
|
|
||||||
if(row.description) {
|
if(row.descriptionText) {
|
||||||
pages[pageCounter - 1].drawText(row.description.match(/.{1,80}/g).join("\n"), {
|
pages[pageCounter - 1].drawText(row.descriptionText.match(/.{1,80}/g).join("\n"), {
|
||||||
...getCoordinatesForPDFLib(21,rowHeight + ( textAutoLines * 4), page1),
|
...getCoordinatesForPDFLib(21,rowHeight + ( textAutoLines * 4), page1),
|
||||||
size:10,
|
size:10,
|
||||||
color:rgb(0,0,0),
|
color:rgb(0,0,0),
|
||||||
@@ -870,7 +870,7 @@ export const useCreatePdf = async (invoiceData,backgroundSourceBuffer) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let addHeight = (row.description.match(/.{1,80}/g) || []).length * 4 + 10
|
let addHeight = (row.descriptionText.match(/.{1,80}/g) || []).length * 4 + 10
|
||||||
console.log(addHeight)
|
console.log(addHeight)
|
||||||
rowHeight += addHeight
|
rowHeight += addHeight
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ const itemInfo = ref({
|
|||||||
active: true,
|
active: true,
|
||||||
dateDirection: "Rückwirkend",
|
dateDirection: "Rückwirkend",
|
||||||
},
|
},
|
||||||
letterhead: null
|
letterhead: null,
|
||||||
|
agriculture: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -86,6 +87,9 @@ const setupPage = async () => {
|
|||||||
|
|
||||||
if(!itemInfo.value.deliveryDateType) itemInfo.value.deliveryDateType = "Lieferdatum"
|
if(!itemInfo.value.deliveryDateType) itemInfo.value.deliveryDateType = "Lieferdatum"
|
||||||
|
|
||||||
|
if(itemInfo.value.rows.find(i => i.agriculture)) {
|
||||||
|
processDieselPosition()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +227,7 @@ const addPosition = (mode) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if(mode === 'free'){
|
if(mode === 'free'){
|
||||||
itemInfo.value.rows.push({
|
let rowData = {
|
||||||
id: lastId +1,
|
id: lastId +1,
|
||||||
mode: "free",
|
mode: "free",
|
||||||
text: "",
|
text: "",
|
||||||
@@ -232,7 +236,10 @@ const addPosition = (mode) => {
|
|||||||
price: 0,
|
price: 0,
|
||||||
taxPercent: 19,
|
taxPercent: 19,
|
||||||
discountPercent: 0
|
discountPercent: 0
|
||||||
})
|
}
|
||||||
|
|
||||||
|
itemInfo.value.rows.push({...rowData, ...dataStore.ownTenant.extraModules.includes("agriculture") ? {agriculture: {}}: {}})
|
||||||
|
|
||||||
} else if(mode === 'normal'){
|
} else if(mode === 'normal'){
|
||||||
itemInfo.value.rows.push({
|
itemInfo.value.rows.push({
|
||||||
id: lastId +1,
|
id: lastId +1,
|
||||||
@@ -244,7 +251,7 @@ const addPosition = (mode) => {
|
|||||||
unit: 1
|
unit: 1
|
||||||
})
|
})
|
||||||
} else if(mode === 'service'){
|
} else if(mode === 'service'){
|
||||||
itemInfo.value.rows.push({
|
let rowData = {
|
||||||
id: lastId +1,
|
id: lastId +1,
|
||||||
mode: "service",
|
mode: "service",
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
@@ -252,7 +259,10 @@ const addPosition = (mode) => {
|
|||||||
taxPercent: 19,
|
taxPercent: 19,
|
||||||
discountPercent: 0,
|
discountPercent: 0,
|
||||||
unit: 1
|
unit: 1
|
||||||
})
|
}
|
||||||
|
|
||||||
|
//Push Agriculture Holder only if Module is activated
|
||||||
|
itemInfo.value.rows.push({...rowData, ...dataStore.ownTenant.extraModules.includes("agriculture") ? {agriculture: {}}: {}})
|
||||||
} else if(mode === "pagebreak") {
|
} else if(mode === "pagebreak") {
|
||||||
itemInfo.value.rows.push({
|
itemInfo.value.rows.push({
|
||||||
id: lastId +1,
|
id: lastId +1,
|
||||||
@@ -275,16 +285,10 @@ const addPosition = (mode) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const editRowDescription = (row) => {
|
|
||||||
rowToEdit.value = row.description
|
|
||||||
showEditRowDescription.value = true
|
|
||||||
|
|
||||||
}
|
|
||||||
const showEditRowDescription = ref(false)
|
const showEditRowDescription = ref(false)
|
||||||
const rowToEdit = ref("")
|
const rowToEdit = ref("")
|
||||||
const saveRowDescription = () => {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -351,6 +355,9 @@ const tabItems = computed(() => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const renderCurrency = (value, currency = "€") => {
|
||||||
|
return Number(value).toFixed(2).replace(".",",") + " €"
|
||||||
|
}
|
||||||
const documentTotal = computed(() => {
|
const documentTotal = computed(() => {
|
||||||
let totalNet = 0
|
let totalNet = 0
|
||||||
let total19 = 0
|
let total19 = 0
|
||||||
@@ -378,6 +385,51 @@ const documentTotal = computed(() => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const processDieselPosition = () => {
|
||||||
|
let agricultureData = {
|
||||||
|
dieselUsageTotal: 0,
|
||||||
|
dieselPriceTotal: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
itemInfo.value.rows.forEach(row => {
|
||||||
|
if(row.agriculture && row.agriculture.dieselUsage) {
|
||||||
|
agricultureData.dieselUsageTotal += Number(row.agriculture.dieselUsage)
|
||||||
|
agricultureData.dieselPriceTotal += Number(row.agriculture.dieselPrice) * Number(row.agriculture.dieselUsage)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if(agricultureData.dieselUsageTotal !== 0) {
|
||||||
|
|
||||||
|
if(itemInfo.value.rows.find(i => i.key === "dieselPos")){
|
||||||
|
let existingIndex = itemInfo.value.rows.findIndex(i => i.key === "dieselPos")
|
||||||
|
|
||||||
|
itemInfo.value.rows[existingIndex] = {
|
||||||
|
...itemInfo.value.rows[existingIndex],
|
||||||
|
price: agricultureData.dieselPriceTotal,
|
||||||
|
text: `${agricultureData.dieselUsageTotal} L Diesel`,
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
itemInfo.value.rows.push({
|
||||||
|
mode: "free",
|
||||||
|
text: `${agricultureData.dieselUsageTotal} L Diesel`,
|
||||||
|
quantity: 1,
|
||||||
|
unit: 10,
|
||||||
|
price: agricultureData.dieselPriceTotal,
|
||||||
|
taxPercent: 19,
|
||||||
|
discountPercent: 0,
|
||||||
|
key: "dieselPos"
|
||||||
|
})
|
||||||
|
|
||||||
|
setPosNumbers()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
itemInfo.value.agriculture = {...itemInfo.value.agriculture, ...agricultureData}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const getDocumentData = () => {
|
const getDocumentData = () => {
|
||||||
|
|
||||||
let customerData = dataStore.getCustomerById(itemInfo.value.customer)
|
let customerData = dataStore.getCustomerById(itemInfo.value.customer)
|
||||||
@@ -386,8 +438,6 @@ const getDocumentData = () => {
|
|||||||
let businessInfo = dataStore.ownTenant.businessInfo
|
let businessInfo = dataStore.ownTenant.businessInfo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let rows = itemInfo.value.rows.map(row => {
|
let rows = itemInfo.value.rows.map(row => {
|
||||||
|
|
||||||
let unit = dataStore.units.find(i => i.id === row.unit)
|
let unit = dataStore.units.find(i => i.id === row.unit)
|
||||||
@@ -420,6 +470,42 @@ const getDocumentData = () => {
|
|||||||
//console.log(templateEndText({zahlungsziel_in_tagen: itemInfo.value.paymentDays}))
|
//console.log(templateEndText({zahlungsziel_in_tagen: itemInfo.value.paymentDays}))
|
||||||
|
|
||||||
|
|
||||||
|
if(dataStore.ownTenant.extraModules.includes("agriculture")) {
|
||||||
|
itemInfo.value.rows.forEach(row => {
|
||||||
|
if(row.agriculture && row.agriculture.dieselUsage) {
|
||||||
|
row.agriculture.description = `${row.agriculture.dieselUsage} L Diesel zu ${renderCurrency(row.agriculture.dieselPrice)}/L verbraucht ${row.description ? "\n" + row.description : ""}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if Agricultural Description is Present
|
||||||
|
itemInfo.value.rows = itemInfo.value.rows.map(row => {
|
||||||
|
|
||||||
|
let descriptionText = ""
|
||||||
|
|
||||||
|
if(row.agriculture && row.agriculture.description) {
|
||||||
|
descriptionText = row.agriculture.description
|
||||||
|
} else {
|
||||||
|
descriptionText = row.description ? row.description : null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
descriptionText: descriptionText
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const generateContext = (itemInfo, contactData) => {
|
||||||
|
return {
|
||||||
|
vorname:contactData && contactData.firstName,
|
||||||
|
nachname: contactData && contactData.lastName,
|
||||||
|
zahlungsziel_in_tagen:itemInfo.paymentDays,
|
||||||
|
diesel_gesamtverbrauch: (itemInfo.agriculture && itemInfo.agriculture.dieselUsageTotal) && itemInfo.agriculture.dieselUsageTotal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const returnData = {
|
const returnData = {
|
||||||
adressLine: `${businessInfo.name}, ${businessInfo.street}, ${businessInfo.zip} ${businessInfo.city}`,
|
adressLine: `${businessInfo.name}, ${businessInfo.street}, ${businessInfo.zip} ${businessInfo.city}`,
|
||||||
@@ -445,13 +531,11 @@ const getDocumentData = () => {
|
|||||||
},
|
},
|
||||||
title: itemInfo.value.title,
|
title: itemInfo.value.title,
|
||||||
description: itemInfo.value.description,
|
description: itemInfo.value.description,
|
||||||
endText: templateEndText({zahlungsziel_in_tagen: itemInfo.value.paymentDays}),
|
endText: templateEndText(generateContext(itemInfo.value, contactData)),
|
||||||
startText: templateStartText({
|
startText: templateStartText(generateContext(itemInfo.value, contactData)),
|
||||||
vorname: contactData ? contactData.firstName : "",
|
|
||||||
nachname: contactData ? contactData.lastName : ""
|
|
||||||
}),
|
|
||||||
rows: rows,
|
rows: rows,
|
||||||
total: documentTotal.value
|
total: documentTotal.value,
|
||||||
|
agriculture: itemInfo.value.agriculture
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(returnData)
|
//console.log(returnData)
|
||||||
@@ -466,7 +550,6 @@ const generateDocument = async () => {
|
|||||||
const ownTenant = dataStore.ownTenant
|
const ownTenant = dataStore.ownTenant
|
||||||
const path = letterheads.value.find(i => i.id === itemInfo.value.letterhead).path
|
const path = letterheads.value.find(i => i.id === itemInfo.value.letterhead).path
|
||||||
|
|
||||||
//ownTenant.letterheadConfig[itemInfo.value.type]
|
|
||||||
|
|
||||||
const {data,error} = await supabase.storage.from("files").download(path)
|
const {data,error} = await supabase.storage.from("files").download(path)
|
||||||
|
|
||||||
@@ -545,9 +628,7 @@ const saveDocument = async () => {
|
|||||||
deliveryDate: itemInfo.value.deliveryDate,
|
deliveryDate: itemInfo.value.deliveryDate,
|
||||||
paymentDays: itemInfo.value.paymentDays,
|
paymentDays: itemInfo.value.paymentDays,
|
||||||
deliveryDateType: itemInfo.value.deliveryDateType,
|
deliveryDateType: itemInfo.value.deliveryDateType,
|
||||||
info: {
|
info: {},
|
||||||
|
|
||||||
},
|
|
||||||
createdBy: itemInfo.value.createdBy,
|
createdBy: itemInfo.value.createdBy,
|
||||||
title: itemInfo.value.title,
|
title: itemInfo.value.title,
|
||||||
description: itemInfo.value.description,
|
description: itemInfo.value.description,
|
||||||
@@ -555,9 +636,35 @@ const saveDocument = async () => {
|
|||||||
endText: itemInfo.value.endText,
|
endText: itemInfo.value.endText,
|
||||||
rows: itemInfo.value.rows,
|
rows: itemInfo.value.rows,
|
||||||
contactPerson: itemInfo.value.contactPerson,
|
contactPerson: itemInfo.value.contactPerson,
|
||||||
linkedDocument: itemInfo.value.linkedDocument
|
linkedDocument: itemInfo.value.linkedDocument,
|
||||||
|
agriculture: itemInfo.value.agriculture
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(dataStore.ownTenant.extraModules.includes("agriculture")) {
|
||||||
|
itemInfo.value.rows.forEach(row => {
|
||||||
|
if(row.agriculture && row.agriculture.dieselUsage) {
|
||||||
|
row.agriculture.description = `${row.agriculture.dieselUsage} L Diesel zu ${renderCurrency(row.agriculture.dieselPrice)}/L verbraucht ${row.description ? "\n" + row.description : ""}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if Agricultural Description is Present
|
||||||
|
itemInfo.value.rows = itemInfo.value.rows.map(row => {
|
||||||
|
|
||||||
|
let descriptionText = ""
|
||||||
|
|
||||||
|
if(row.agriculture && row.agriculture.description) {
|
||||||
|
descriptionText = row.agriculture.description
|
||||||
|
} else {
|
||||||
|
descriptionText = row.description ? row.description : null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...row,
|
||||||
|
descriptionText: descriptionText
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let data = null
|
let data = null
|
||||||
|
|
||||||
if(route.params.id) {
|
if(route.params.id) {
|
||||||
@@ -1193,9 +1300,7 @@ setupPage()
|
|||||||
@end="setPosNumbers"
|
@end="setPosNumbers"
|
||||||
>
|
>
|
||||||
<template #item="{element: row}">
|
<template #item="{element: row}">
|
||||||
<tr
|
<tr>
|
||||||
|
|
||||||
>
|
|
||||||
<td>
|
<td>
|
||||||
<UIcon
|
<UIcon
|
||||||
class="handle"
|
class="handle"
|
||||||
@@ -1450,6 +1555,12 @@ setupPage()
|
|||||||
icon="i-heroicons-document-text"
|
icon="i-heroicons-document-text"
|
||||||
@click="row.showEdit = true"
|
@click="row.showEdit = true"
|
||||||
/>
|
/>
|
||||||
|
<UButton
|
||||||
|
icon="i-mdi-water-drop-outline"
|
||||||
|
class="ml-3"
|
||||||
|
v-if="row.agriculture"
|
||||||
|
@click="row.showEditDiesel = true"
|
||||||
|
/>
|
||||||
<UModal v-model="row.showEdit">
|
<UModal v-model="row.showEdit">
|
||||||
<UCard>
|
<UCard>
|
||||||
<template #header>
|
<template #header>
|
||||||
@@ -1471,6 +1582,47 @@ setupPage()
|
|||||||
</UCard>
|
</UCard>
|
||||||
|
|
||||||
|
|
||||||
|
</UModal>
|
||||||
|
<UModal v-model="row.showEditDiesel">
|
||||||
|
<UCard>
|
||||||
|
<template #header>
|
||||||
|
Dieselverbrauch bearbeiten
|
||||||
|
</template>
|
||||||
|
<UFormGroup
|
||||||
|
label="Menge:"
|
||||||
|
>
|
||||||
|
<UInput
|
||||||
|
v-model="row.agriculture.dieselUsage"
|
||||||
|
>
|
||||||
|
<template #trailing>
|
||||||
|
L
|
||||||
|
</template>
|
||||||
|
</UInput>
|
||||||
|
</UFormGroup>
|
||||||
|
<UFormGroup
|
||||||
|
label="Preis:"
|
||||||
|
>
|
||||||
|
<UInput
|
||||||
|
v-model="row.agriculture.dieselPrice"
|
||||||
|
type="number"
|
||||||
|
steps="0.01"
|
||||||
|
>
|
||||||
|
<template #trailing>
|
||||||
|
€/L
|
||||||
|
</template>
|
||||||
|
</UInput>
|
||||||
|
</UFormGroup>
|
||||||
|
<template #footer>
|
||||||
|
<UButton
|
||||||
|
@click="row.showEditDiesel = false,
|
||||||
|
processDieselPosition()"
|
||||||
|
>
|
||||||
|
Speichern
|
||||||
|
</UButton>
|
||||||
|
</template>
|
||||||
|
</UCard>
|
||||||
|
|
||||||
|
|
||||||
</UModal>
|
</UModal>
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ const setupPage = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cancelEditorCreate = () => {
|
const cancelEditorCreate = () => {
|
||||||
if(itemInfo.value) {
|
if(itemInfo.value.id) {
|
||||||
router.push(`/vehicles/show/${itemInfo.value.id}`)
|
router.push(`/vehicles/show/${itemInfo.value.id}`)
|
||||||
} else {
|
} else {
|
||||||
router.push(`/vehicles`)
|
router.push(`/vehicles`)
|
||||||
@@ -207,6 +207,10 @@ setupPage()
|
|||||||
<td>Tankvolumen:</td>
|
<td>Tankvolumen:</td>
|
||||||
<td>{{itemInfo.tankSize !== 0 ? `${itemInfo.tankSize} L` : "Kein Tank verbaut"}}</td>
|
<td>{{itemInfo.tankSize !== 0 ? `${itemInfo.tankSize} L` : "Kein Tank verbaut"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Baujahr:</td>
|
||||||
|
<td>{{itemInfo.buildYear}}</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -316,6 +320,14 @@ setupPage()
|
|||||||
</template>
|
</template>
|
||||||
</UInput>
|
</UInput>
|
||||||
</UFormGroup>
|
</UFormGroup>
|
||||||
|
<UFormGroup
|
||||||
|
label="Baujahr:"
|
||||||
|
>
|
||||||
|
<UInput
|
||||||
|
v-model="itemInfo.buildYear"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
</UFormGroup>
|
||||||
</UForm>
|
</UForm>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user