This commit is contained in:
2025-07-31 20:34:29 +02:00
parent 23573caceb
commit 80d68e0aa9

View File

@@ -17,9 +17,6 @@ definePageMeta({
middleware: "auth"
})
const showProductSelectionModal = ref(false)
const showServiceSelectionModal = ref(false)
const itemInfo = ref({
type: "invoices",
@@ -107,7 +104,7 @@ const setupPage = async () => {
checkCompatibilityWithInputPrice()
}
if(itemInfo.value.project) checkForOpenAdvanceInvoices()
if(itemInfo.value.project) await checkForOpenAdvanceInvoices()
if(!itemInfo.value.deliveryDateType) itemInfo.value.deliveryDateType = "Lieferdatum"
@@ -236,8 +233,11 @@ const setupPage = async () => {
} else {
// Import all
if(process.dev) console.log(linkedDocument)
itemInfo.value.taxType = linkedDocument.taxType
itemInfo.value.customer = linkedDocument.customer
await setCustomerData(null,true)
itemInfo.value.letterhead = linkedDocument.letterhead
itemInfo.value.contact = linkedDocument.contact
itemInfo.value.deliveryDateType = linkedDocument.deliveryDateType
@@ -256,7 +256,7 @@ const setupPage = async () => {
itemInfo.value.endText = linkedDocument.endText
}
setCustomerData(null,true)
checkCompatibilityWithInputPrice()
@@ -546,15 +546,6 @@ const removePosition = (id) => {
}
const getRowMargin = (row) => {
if(row.mode === "normal" && row.product) {
let purchasePrice = products.value.find(i => i.id === row.product).purchasePrice || 0
return row.price - purchasePrice
} else {
return 0
}
}
const findDocumentErrors = computed(() => {
let errors = []
@@ -621,7 +612,7 @@ const findDocumentErrors = computed(() => {
}
return errors.sort((a,b) => (a.type === "breaking") ? -1 : 1)
return errors.sort((a) => (a.type === "breaking") ? -1 : 1)
})
const tabItems = computed(() => {
@@ -638,6 +629,8 @@ const tabItems = computed(() => {
const renderCurrency = (value, currency = "€") => {
return Number(value).toFixed(2).replace(".",",") + " €"
//return Number(value).toFixed(2).replace(".",",") + " " + currency
return useCurrency(value, currency)
}
const documentTotal = computed(() => {
@@ -731,18 +724,15 @@ const documentReport = computed(() => {
itemInfo.value.rows.filter(i => !i.optional && !i.alternative).forEach(row => {
if(row.product) {
let product = products.value.find(i => i.id === row.product)
console.log(product.purchasePrice)
totalProductsPurchasePrice += product.purchasePrice * row.quantity
} else if(row.service) {
let service = services.value.find(i => i.id === row.service)
console.log(service)
if(service.materialComposition) {
service.materialComposition.forEach(entry => {
let productData = products.value.find(i => i.id === entry.product)
console.log(productData)
totalProductsFromServicesPurchasePrice += productData.purchasePrice * entry.quantity * row.quantity
})
@@ -1070,7 +1060,6 @@ const getDocumentData = () => {
const showDocument = ref(false)
const uri = ref("")
const generateDocument = async () => {
const ownTenant = profileStore.ownTenant
const path = letterheads.value.find(i => i.id === itemInfo.value.letterhead).path
/*const {data,error} = await supabase.functions.invoke('create_pdf',{
@@ -1316,7 +1305,6 @@ const getTextTemplateByType = (type, pos) => {
const checkCompatibilityWithInputPrice = () => {
itemInfo.value.rows.forEach(row => {
console.log(row)
if(!row.inputPrice) {
row.inputPrice = row.price
}
@@ -1653,7 +1641,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
</UFormGroup>
<UFormGroup
label="Ansprechpartner:"
v-if="itemInfo.customer ? dataStore.getCustomerById(itemInfo.customer).isCompany : false "
v-if="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).isCompany : false "
>
<InputGroup>
<USelectMenu
@@ -1672,13 +1660,13 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
class="w-full"
:disabled="!itemInfo.customer"
>
<span class="truncate">{{dataStore.getContactById(itemInfo.contact) ? dataStore.getContactById(itemInfo.contact).fullName : "Kein Kontakt ausgewählt"}}</span>
<span class="truncate">{{itemInfo.contact ? contacts.find(i => i.id === itemInfo.contact).fullName : "Kein Kontakt ausgewählt"}}</span>
<UIcon name="i-heroicons-chevron-right-20-solid" class="w-5 h-5 transition-transform text-gray-400 dark:text-gray-500" :class="['transform rotate-90']" />
</UButton>
<template #label>
{{dataStore.getContactById(itemInfo.contact) ? dataStore.getContactById(itemInfo.contact).fullName : "Kein Kontakt ausgewählt"}}
{{ itemInfo.contact ? contacts.find(i => i.id === itemInfo.contact).fullName : "Kein Kontakt ausgewählt"}}
</template>
</USelectMenu>
<!-- <UButton
@@ -1690,7 +1678,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
<EntityModalButtons
type="contacts"
:id="itemInfo.contact"
:create-query="{customerId: itemInfo.customer}"
:create-query="{customer: itemInfo.customer}"
@return-data="(data) => itemInfo.contact = data.id"
/>
</InputGroup>
@@ -1702,25 +1690,25 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
>
<UInput
v-model="itemInfo.address.street"
:placeholder="dataStore.getCustomerById(itemInfo.customer) ? dataStore.getCustomerById(itemInfo.customer).infoData.street : 'Straße + Hausnummer'"
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.street : 'Straße + Hausnummer'"
:color="itemInfo.address.street ? 'primary' : 'rose'"
/>
<UInput
v-model="itemInfo.address.special"
class="mt-3"
:placeholder="dataStore.getCustomerById(itemInfo.customer) ? dataStore.getCustomerById(itemInfo.customer).infoData.special : 'Adresszusatz'"
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.special : 'Adresszusatz'"
/>
<InputGroup class="mt-3">
<UInput
class="flex-auto"
v-model="itemInfo.address.zip"
:placeholder="dataStore.getCustomerById(itemInfo.customer) ? dataStore.getCustomerById(itemInfo.customer).infoData.zip : 'PLZ'"
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.zip : 'PLZ'"
:color="itemInfo.address.zip ? 'primary' : 'rose'"
/>
<UInput
class="flex-auto"
v-model="itemInfo.address.city"
:placeholder="dataStore.getCustomerById(itemInfo.customer) ? dataStore.getCustomerById(itemInfo.customer).infoData.city : 'Ort'"
:placeholder="itemInfo.customer ? customers.find(i => i.id === itemInfo.customer).infoData.city : 'Ort'"
:color="itemInfo.address.city ? 'primary' : 'rose'"
/>
</InputGroup>
@@ -1915,7 +1903,7 @@ const setRowData = async (row, service = {sellingPriceComposed: {}}, product = {
@change="checkForOpenAdvanceInvoices"
>
<template #label>
{{dataStore.getProjectById(itemInfo.project) ? dataStore.getProjectById(itemInfo.project).name : "Kein Projekt ausgewählt"}}
{{itemInfo.project ? projects.find(i => i.id === itemInfo.project).name : "Kein Projekt ausgewählt"}}
</template>
<template #option="{option: project}">
{{dataStore.getCustomerById(project.customer).name}} - {{project.name}}