Added Agriculture Module to Invoice Creation
This commit is contained in:
@@ -54,7 +54,8 @@ const itemInfo = ref({
|
||||
active: true,
|
||||
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.rows.find(i => i.agriculture)) {
|
||||
processDieselPosition()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -223,7 +227,7 @@ const addPosition = (mode) => {
|
||||
})
|
||||
|
||||
if(mode === 'free'){
|
||||
itemInfo.value.rows.push({
|
||||
let rowData = {
|
||||
id: lastId +1,
|
||||
mode: "free",
|
||||
text: "",
|
||||
@@ -232,7 +236,10 @@ const addPosition = (mode) => {
|
||||
price: 0,
|
||||
taxPercent: 19,
|
||||
discountPercent: 0
|
||||
})
|
||||
}
|
||||
|
||||
itemInfo.value.rows.push({...rowData, ...dataStore.ownTenant.extraModules.includes("agriculture") ? {agriculture: {}}: {}})
|
||||
|
||||
} else if(mode === 'normal'){
|
||||
itemInfo.value.rows.push({
|
||||
id: lastId +1,
|
||||
@@ -244,7 +251,7 @@ const addPosition = (mode) => {
|
||||
unit: 1
|
||||
})
|
||||
} else if(mode === 'service'){
|
||||
itemInfo.value.rows.push({
|
||||
let rowData = {
|
||||
id: lastId +1,
|
||||
mode: "service",
|
||||
quantity: 1,
|
||||
@@ -252,7 +259,10 @@ const addPosition = (mode) => {
|
||||
taxPercent: 19,
|
||||
discountPercent: 0,
|
||||
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") {
|
||||
itemInfo.value.rows.push({
|
||||
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 rowToEdit = ref("")
|
||||
const saveRowDescription = () => {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -351,6 +355,9 @@ const tabItems = computed(() => {
|
||||
]
|
||||
})
|
||||
|
||||
const renderCurrency = (value, currency = "€") => {
|
||||
return Number(value).toFixed(2).replace(".",",") + " €"
|
||||
}
|
||||
const documentTotal = computed(() => {
|
||||
let totalNet = 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 = () => {
|
||||
|
||||
let customerData = dataStore.getCustomerById(itemInfo.value.customer)
|
||||
@@ -386,8 +438,6 @@ const getDocumentData = () => {
|
||||
let businessInfo = dataStore.ownTenant.businessInfo
|
||||
|
||||
|
||||
|
||||
|
||||
let rows = itemInfo.value.rows.map(row => {
|
||||
|
||||
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}))
|
||||
|
||||
|
||||
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 = {
|
||||
adressLine: `${businessInfo.name}, ${businessInfo.street}, ${businessInfo.zip} ${businessInfo.city}`,
|
||||
@@ -445,13 +531,11 @@ const getDocumentData = () => {
|
||||
},
|
||||
title: itemInfo.value.title,
|
||||
description: itemInfo.value.description,
|
||||
endText: templateEndText({zahlungsziel_in_tagen: itemInfo.value.paymentDays}),
|
||||
startText: templateStartText({
|
||||
vorname: contactData ? contactData.firstName : "",
|
||||
nachname: contactData ? contactData.lastName : ""
|
||||
}),
|
||||
endText: templateEndText(generateContext(itemInfo.value, contactData)),
|
||||
startText: templateStartText(generateContext(itemInfo.value, contactData)),
|
||||
rows: rows,
|
||||
total: documentTotal.value
|
||||
total: documentTotal.value,
|
||||
agriculture: itemInfo.value.agriculture
|
||||
}
|
||||
|
||||
//console.log(returnData)
|
||||
@@ -466,7 +550,6 @@ const generateDocument = async () => {
|
||||
const ownTenant = dataStore.ownTenant
|
||||
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)
|
||||
|
||||
@@ -545,9 +628,7 @@ const saveDocument = async () => {
|
||||
deliveryDate: itemInfo.value.deliveryDate,
|
||||
paymentDays: itemInfo.value.paymentDays,
|
||||
deliveryDateType: itemInfo.value.deliveryDateType,
|
||||
info: {
|
||||
|
||||
},
|
||||
info: {},
|
||||
createdBy: itemInfo.value.createdBy,
|
||||
title: itemInfo.value.title,
|
||||
description: itemInfo.value.description,
|
||||
@@ -555,9 +636,35 @@ const saveDocument = async () => {
|
||||
endText: itemInfo.value.endText,
|
||||
rows: itemInfo.value.rows,
|
||||
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
|
||||
|
||||
if(route.params.id) {
|
||||
@@ -1193,9 +1300,7 @@ setupPage()
|
||||
@end="setPosNumbers"
|
||||
>
|
||||
<template #item="{element: row}">
|
||||
<tr
|
||||
|
||||
>
|
||||
<tr>
|
||||
<td>
|
||||
<UIcon
|
||||
class="handle"
|
||||
@@ -1450,6 +1555,12 @@ setupPage()
|
||||
icon="i-heroicons-document-text"
|
||||
@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">
|
||||
<UCard>
|
||||
<template #header>
|
||||
@@ -1471,6 +1582,47 @@ setupPage()
|
||||
</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>
|
||||
</td>
|
||||
<td
|
||||
|
||||
Reference in New Issue
Block a user