Added Agriculture

Removed Prices for Delivery Notes
This commit is contained in:
2024-11-21 21:27:40 +01:00
parent 3633b8ee37
commit 60658a2ef9
2 changed files with 279 additions and 199 deletions

View File

@@ -1,6 +1,8 @@
<script setup>
import dayjs from "dayjs"
import Handlebars from "handlebars"
import {useNumberRange} from "~/composables/useNumberRange.js";
import { v4 as uuidv4 } from 'uuid';
const dataStore = useDataStore()
const user = useSupabaseUser()
@@ -102,6 +104,48 @@ const setupPage = async () => {
setContactPersonData()
if(route.query.linkedDocuments) {
let linkedDocuments = (await supabase.from("createddocuments").select().in("id",JSON.parse(route.query.linkedDocuments))).data
//TODO: Implement Checking for Same Customer, Contact and Project
itemInfo.value.customer = linkedDocuments[0].customer
itemInfo.value.project = linkedDocuments[0].project
itemInfo.value.contact = linkedDocuments[0].contact
setCustomerData()
linkedDocuments.forEach(doc => {
let lastId = 0
itemInfo.value.rows.forEach(row => {
if(row.id > lastId) lastId = row.id
})
itemInfo.value.rows.push(...[
{
id:uuidv4(),
mode: "text",
text: doc.title
},
...doc.rows
])
})
if(linkedDocuments.find(i => i.agriculture)){
itemInfo.value.rows = itemInfo.value.rows.filter(i => i.key !== "dieselPos")
itemInfo.value.rows.push({
id:uuidv4(),
mode: "text",
text: "Allgemein"
})
processDieselPosition()
}
}
if(route.query.linkedDocument) {
itemInfo.value.linkedDocument = route.query.linkedDocument
@@ -228,7 +272,7 @@ const addPosition = (mode) => {
if(mode === 'free'){
let rowData = {
id: lastId +1,
id: uuidv4(),
mode: "free",
text: "",
quantity: 1,
@@ -242,7 +286,7 @@ const addPosition = (mode) => {
} else if(mode === 'normal'){
itemInfo.value.rows.push({
id: lastId +1,
id: uuidv4(),
mode: "normal",
quantity: 1,
price: 0,
@@ -252,7 +296,7 @@ const addPosition = (mode) => {
})
} else if(mode === 'service'){
let rowData = {
id: lastId +1,
id: uuidv4(),
mode: "service",
quantity: 1,
price: 0,
@@ -265,17 +309,17 @@ const addPosition = (mode) => {
itemInfo.value.rows.push({...rowData, ...dataStore.ownTenant.extraModules.includes("agriculture") ? {agriculture: {}}: {}})
} else if(mode === "pagebreak") {
itemInfo.value.rows.push({
id: lastId +1,
id: uuidv4(),
mode: "pagebreak",
})
} else if(mode === "title") {
itemInfo.value.rows.push({
id: lastId +1,
id: uuidv4(),
mode: "title",
})
} else if(mode === "text") {
itemInfo.value.rows.push({
id: lastId +1,
id: uuidv4(),
mode: "text",
})
}
@@ -434,9 +478,15 @@ const getDocumentData = () => {
let customerData = dataStore.getCustomerById(itemInfo.value.customer)
let contactData = dataStore.getContactById(itemInfo.value.contact)
let userData = dataStore.getProfileById(user.value.id)
let businessInfo = dataStore.ownTenant.businessInfo
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 : ""}`
}
})
}
let rows = itemInfo.value.rows.map(row => {
@@ -446,6 +496,16 @@ const getDocumentData = () => {
if(row.mode === 'normal') row.text = dataStore.getProductById(row.product).name
if(row.mode === 'service') row.text = dataStore.getServiceById(row.service).name
console.log(row)
if(row.agriculture?.description) {
console.log("Row has Agri")
row.descriptionText = row.agriculture.description
} else if(row.description) {
console.log("Row has no Agri")
row.descriptionText = row.description
}
return {
...row,
rowAmount: `${getRowAmount(row)}`,
@@ -463,37 +523,6 @@ const getDocumentData = () => {
//Compile Start & EndText
const templateStartText = Handlebars.compile(itemInfo.value.startText);
const templateEndText = Handlebars.compile(itemInfo.value.endText);
/*console.log(templateStartText({
vorname: contactData ? contactData.firstName : "",
nachname: contactData ? contactData.lastName : ""
}))*/
//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 {
@@ -508,6 +537,7 @@ const getDocumentData = () => {
const returnData = {
type: itemInfo.value.type,
adressLine: `${businessInfo.name}, ${businessInfo.street}, ${businessInfo.zip} ${businessInfo.city}`,
recipient: {
name: customerData.name,
@@ -1285,11 +1315,11 @@ setupPage()
<th>Name</th>
<th>Menge</th>
<th>Einheit</th>
<th>Preis</th>
<th>Steuer</th>
<th>Rabatt</th>
<th v-if="itemInfo.type !== 'deliveryNotes'">Preis</th>
<th v-if="itemInfo.type !== 'deliveryNotes'">Steuer</th>
<th v-if="itemInfo.type !== 'deliveryNotes'">Rabatt</th>
<th>Beschreibung</th>
<th>Gesamt</th>
<th v-if="itemInfo.type !== 'deliveryNotes'">Gesamt</th>
</tr>
</thead>
@@ -1504,7 +1534,7 @@ setupPage()
</td>
<td
class="w-40"
v-if="!['pagebreak','title','text'].includes(row.mode)"
v-if="!['pagebreak','title','text'].includes(row.mode) && itemInfo.type !== 'deliveryNotes'"
>
<UInput
v-model="row.price"
@@ -1518,7 +1548,7 @@ setupPage()
</td>
<td
class="w-40"
v-if="!['pagebreak','title','text'].includes(row.mode)"
v-if="!['pagebreak','title','text'].includes(row.mode)&& itemInfo.type !== 'deliveryNotes'"
>
<USelectMenu
@@ -1536,7 +1566,7 @@ setupPage()
</td>
<td
class="w-40"
v-if="!['pagebreak','title','text'].includes(row.mode)"
v-if="!['pagebreak','title','text'].includes(row.mode)&& itemInfo.type !== 'deliveryNotes'"
>
<UInput
v-model="row.discountPercent"
@@ -1628,7 +1658,7 @@ setupPage()
</UModal>
</td>
<td
v-if="!['pagebreak','title','text'].includes(row.mode)"
v-if="!['pagebreak','title','text'].includes(row.mode) && itemInfo.type !== 'deliveryNotes'"
>
<p class="text-right font-bold whitespace-nowrap"><span v-if="row.discountPercent !== 0" class="line-through mr-2 text-rose-500">{{getRowAmountUndiscounted(row)}} </span>{{getRowAmount(row)}} </p>
@@ -1703,6 +1733,8 @@ setupPage()
<div class="w-full flex justify-end">
<table class="w-1/3">
<div class="w-full flex justify-end" v-if="itemInfo.type !== 'deliveryNotes'">
<table class="w-1/3" v-if="itemInfo.rows.length > 0">
<tr>
<td class="font-bold">Netto:</td>
<td class="text-right">{{documentTotal.totalNet}}</td>