Rebuild Inventory

Added Advance Invoices
This commit is contained in:
2024-04-23 20:28:26 +02:00
parent 633d75b798
commit 1cbb8cbacf
6 changed files with 432 additions and 69 deletions

View File

@@ -88,7 +88,7 @@ const setupPage = () => {
}
const setDocumentTypeConfig = () => {
if(itemInfo.value.type === "invoices") {
if(itemInfo.value.type === "invoices" ||itemInfo.value.type === "advanceInvoices") {
itemInfo.value.documentNumberTitle = "Rechnungsnummer"
itemInfo.value.title = `Rechnung-Nr. ${itemInfo.value.documentNumber ? itemInfo.value.documentNumber : "XXXX"}`
} else if(itemInfo.value.type === "quotes") {
@@ -120,7 +120,7 @@ const setCustomerData = () => {
const setContactPersonData = () => {
let profile = dataStore.activeProfile
console.log(profile)
//console.log(profile)
if(!itemInfo.value.contactPerson) itemInfo.value.contactPerson = profile.id
@@ -132,6 +132,40 @@ const setContactPersonData = () => {
}
const showAdvanceInvoiceCalcModal = ref(false)
const advanceInvoiceData = ref({
totalSumNet: 0,
partPerPecentage: 0,
part: 0
})
const importPositions = () => {
if(itemInfo.value.type === 'advanceInvoices') {
if(advanceInvoiceData.value.totalSumNet !== 0 && advanceInvoiceData.value.partPerPecentage !== 0 && advanceInvoiceData.value.part !== 0) {
showAdvanceInvoiceCalcModal.value = false
let lastId = 0
itemInfo.value.rows.forEach(row => {
if(row.id > lastId) lastId = row.id
})
itemInfo.value.rows.push({
id: lastId +1,
mode: "free",
text: "Abschlagszahlung",
quantity: 1,
unit: 10,
price: advanceInvoiceData.value.part,
taxPercent: 19,
discountPercent: 0,
advanceInvoiceData: advanceInvoiceData.value
})
setPosNumbers()
}
}
}
const getRowAmount = (row) => {
@@ -465,17 +499,73 @@ setupPage()
<UFormGroup
label="Dokumenttyp:"
>
<USelectMenu
:options="Object.keys(dataStore.documentTypesForCreation).map(i => {return {label: dataStore.documentTypesForCreation[i].labelSingle, type: i }})"
v-model="itemInfo.type"
value-attribute="type"
option-attribute="label"
@change="setDocumentTypeConfig"
<InputGroup>
<USelectMenu
:options="Object.keys(dataStore.documentTypesForCreation).map(i => {return {label: dataStore.documentTypesForCreation[i].labelSingle, type: i }})"
v-model="itemInfo.type"
value-attribute="type"
option-attribute="label"
@change="setDocumentTypeConfig"
class="flex-auto"
>
<template #label>
{{dataStore.documentTypesForCreation[itemInfo.type].labelSingle}}
</template>
</USelectMenu>
<UButton
variant="outline"
v-if="itemInfo.type === 'advanceInvoices'"
icon="i-heroicons-arrow-down-tray"
@click="showAdvanceInvoiceCalcModal = true"
>Auto Positionen</UButton>
</InputGroup>
<USlideover
v-model="showAdvanceInvoiceCalcModal"
>
<template #label>
{{dataStore.documentTypesForCreation[itemInfo.type].labelSingle}}
</template>
</USelectMenu>
<UCard class="h-full">
<template #header>
<UButton @click="importPositions">Übernehmen</UButton>
</template>
<UFormGroup
label="Gesamtsumme:"
>
<UInput
type="number"
:step="0.01"
v-model="advanceInvoiceData.totalSumNet"
@focusout="advanceInvoiceData.part = advanceInvoiceData.totalSumNet / 100 * advanceInvoiceData.partPerPecentage"
/>
</UFormGroup>
<UFormGroup
label="Prozent:"
>
<UInput
type="number"
:step="0.01"
v-model="advanceInvoiceData.partPerPecentage"
@focusout="advanceInvoiceData.part = advanceInvoiceData.totalSumNet / 100 * advanceInvoiceData.partPerPecentage"
/>
</UFormGroup>
<UFormGroup
label="Abzurechnender Anteil:"
>
<UInput
type="number"
:step="0.01"
v-model="advanceInvoiceData.part"
@focusout="advanceInvoiceData.partPerPecentage = Number((advanceInvoiceData.part / advanceInvoiceData.totalSumNet * 100).toFixed(2))"
/>
</UFormGroup>
</UCard>
</USlideover>
</UFormGroup>
<UFormGroup
label="Kunde:"
@@ -747,7 +837,7 @@ setupPage()
{{option.name}} - {{option.text}}
</template>
<template #label>
{{dataStore.texttemplates.find(i => i.text === itemInfo.startText) ? dataStore.texttemplates.find(i => i.text === itemInfo.startText).name : "Keine Vorlage ausgewählt oder Vorlage verändert"}}
{{dataStore.texttemplates.find(i => i.text === itemInfo.startText && i.documentType === itemInfo.type) ? dataStore.texttemplates.find(i => i.text === itemInfo.startText && i.documentType === itemInfo.type).name : "Keine Vorlage ausgewählt oder Vorlage verändert"}}
</template>
</USelectMenu>
</UFormGroup>

View File

@@ -193,6 +193,9 @@ const templateTypes = [
{
key: "invoices",
label: "Rechnungen"
},{
key: "advanceInvoices",
label: "Abschlagsrechnungen"
}, {
key: "quotes",
label: "Angebote"

View File

@@ -17,7 +17,7 @@ const {vendors} = storeToRefs(useDataStore())
const {fetchVendorInvoices} = useDataStore()
const availableDocuments = computed(() => {
return dataStore.documents.filter(i => i.tags.includes('Eingangsrechnung' && dataStore.incominginvoices.filter(x => x.document === i).length === 0))
return dataStore.documents.filter(i => i.tags.includes('Eingangsrechnung' /*&& dataStore.incominginvoices.filter(x => x.document === i).length === 0*/))
})
@@ -184,7 +184,7 @@ setupPage()
</template>
</UDashboardNavbar>
<div v-if="!itemInfo.document">
<div v-if="availableDocuments.length === 0" class="w-1/2 mx-auto text-center">
<!-- <div v-if="availableDocuments.length === 0" class="w-1/2 mx-auto text-center">
<p class="text-2xl mt-5">Keine Dokumente zur Auswahl vefügbar</p>
<UButton
@click="router.push(`/documents`)"
@@ -193,11 +193,10 @@ setupPage()
>
Zu den Dokumenten
</UButton>
</div>
</div>-->
<DocumentList
v-else
:documents="availableDocuments"
:return-document-id="true"
@selectDocument="(documentId) => itemInfo.document = documentId"

View File

@@ -11,45 +11,79 @@ const toast = useToast()
const inventoryChangeData = ref({
productId: "",
spaceId: "",
sourceSpaceId: null,
sourceProjectId: null,
destinationSpaceId: null,
destinationProjectId: null,
quantity: 1
})
const createMovement = async () => {
if(mode.value === '' || !checkSpaceId(inventoryChangeData.value.spaceId) || !checkArticle(inventoryChangeData.value.productId)){
let movements = []
} else {
if(mode.value === 'incoming'){
if(mode.value === 'incoming'){
const {error} = await supabase
.from("movements")
.insert([inventoryChangeData.value])
.select()
if(error) console.log(error)
} else if (mode.value === 'outgoing'){
inventoryChangeData.value.quantity *= -1
const {error} = await supabase
.from("movements")
.insert([inventoryChangeData.value])
.select()
if(error) console.log(error)
} else if (mode.value === 'change'){}
inventoryChangeData.value = {
productId: "",
spaceId: "",
quantity: 1
let movement = {
productId: inventoryChangeData.value.productId,
spaceId: inventoryChangeData.value.destinationSpaceId,
projectId: inventoryChangeData.value.destinationProjectId,
quantity: inventoryChangeData.value.quantity,
profileId: dataStore.activeProfile.id,
tenant: dataStore.currentTenant
}
movements.push(movement)
dataStore.fetchMovements()
/*const {error} = await supabase
.from("movements")
.insert([inventoryChangeData.value])
.select()
if(error) console.log(error)*/
} else if (mode.value === 'outgoing'){
let movement = {
productId: inventoryChangeData.value.productId,
spaceId: inventoryChangeData.value.sourceSpaceId,
projectId: inventoryChangeData.value.sourceProjectId,
quantity: inventoryChangeData.value.quantity * -1,
profileId: dataStore.activeProfile.id,
tenant: dataStore.currentTenant
}
movements.push(movement)
} else if (mode.value === 'change'){
let outMovement = {
productId: inventoryChangeData.value.productId,
spaceId: inventoryChangeData.value.sourceSpaceId,
projectId: inventoryChangeData.value.sourceProjectId,
quantity: inventoryChangeData.value.quantity * -1,
profileId: dataStore.activeProfile.id,
tenant: dataStore.currentTenant
}
let inMovement = {
productId: inventoryChangeData.value.productId,
spaceId: inventoryChangeData.value.destinationSpaceId,
projectId: inventoryChangeData.value.destinationProjectId,
quantity: inventoryChangeData.value.quantity,
profileId: dataStore.activeProfile.id,
tenant: dataStore.currentTenant
}
movements.push(outMovement)
movements.push(inMovement)
}
console.log(movements)
const {error} = await supabase
.from("movements")
.insert(movements)
.select()
if(error) console.log(error)
}
@@ -63,13 +97,17 @@ defineShortcuts({
})
function checkArticle(productId) {
function checkProductId(productId) {
return dataStore.products.filter(product =>product.id === productId).length > 0;
}
function checkSpaceId(spaceId) {
return dataStore.spaces.filter(space => space.id === spaceId).length > 0;
}
function checkProjectId(projectId) {
return dataStore.projects.some(i => i.id === projectId)
}
function changeFocusToSpaceId() {
document.getElementById('spaceIdInput').focus()
}
@@ -78,33 +116,154 @@ function changeFocusToQuantity() {
document.getElementById('quantityInput').focus()
}
function changeFocusToBarcode() {
document.getElementById('barcodeInput').focus()
}
const findProductByBarcodeOrEAN = (input) => {
return dataStore.products.find(i => i.barcode === input || i.ean === input)
}
const findSpaceBySpaceNumber = (input) => {
return dataStore.spaces.find(i => i.spaceNumber === input)
}
const barcodeInput = ref("")
const showBarcodeTip = ref(true)
const processBarcodeInput = () => {
if(findProductByBarcodeOrEAN(barcodeInput.value) && !findSpaceBySpaceNumber(barcodeInput.value)){
//Set Product
inventoryChangeData.value.productId = findProductByBarcodeOrEAN(barcodeInput.value).id
} else if (!findProductByBarcodeOrEAN(barcodeInput.value) && findSpaceBySpaceNumber(barcodeInput.value)){
//Set Space
if(mode.value === 'incoming'){
inventoryChangeData.value.destinationSpaceId = findSpaceBySpaceNumber(barcodeInput.value).id
} else if(mode.value === 'outgoing') {
inventoryChangeData.value.sourceSpaceId = findSpaceBySpaceNumber(barcodeInput.value).id
} else if(mode.value === 'change') {
if(!inventoryChangeData.value.sourceSpaceId){
inventoryChangeData.value.sourceSpaceId = findSpaceBySpaceNumber(barcodeInput.value).id
} else {
inventoryChangeData.value.destinationSpaceId = findSpaceBySpaceNumber(barcodeInput.value).id
}
}
//console.log(findSpaceBySpaceNumber(barcodeInput.value))
}
barcodeInput.value = ""
//console.log(movementData.value)
}
</script>
<template>
<div id="main">
<div class="my-3">
<div class="w-80 mx-auto mt-5">
<div class="flex flex-col">
<UButton
@click="mode = 'incoming'"
class="ml-3"
class="my-2"
:variant="mode === 'incoming' ? 'solid' : 'outline'"
>Wareneingang</UButton>
<UButton
@click="mode = 'outgoing'"
class="ml-1"
class="my-2"
:variant="mode === 'outgoing' ? 'solid' : 'outline'"
>Warenausgang</UButton>
<!-- <UButton
<UButton
@click="mode = 'change'"
class="ml-1"
disabled
class="my-2"
:variant="mode === 'change' ? 'solid' : 'outline'"
>Umlagern</UButton>-->
>Umlagern</UButton>
</div>
<UAlert
title="Info"
variant="outline"
color="primary"
v-if="showBarcodeTip"
@close="showBarcodeTip = false"
:close-button="{ icon: 'i-heroicons-x-mark-20-solid', color: 'gray', variant: 'link', padded: false }"
description="Über die Barcode Eingabe könenn folgende Werte automatisch erkannt werden: Quell Lagerplatz, Ziellagerplatz, Artikel(EAN oder Barcode). Es wird immer zuerst der Quell- und anschließend der Ziellagerplatz ausgefüllt."
/>
<!-- <UTooltip
text="Über die Barcode Eingabe könenn folgende Werte automatisch erkannt werden: Quell Lagerplatz, Ziellagerplatz, Artikel(EAN oder Barcode). Es wird immer zuerst der Quell- und anschließend der Ziellagerplatz ausgefüllt."
>-->
<UFormGroup
label="Barcode:"
class="mt-3"
>
<UInput
@keyup.enter="processBarcodeInput"
@focusout="processBarcodeInput"
@input="processBarcodeInput"
v-model="barcodeInput"
id="barcodeInput"
/>
</UFormGroup>
<!-- <template #text>
<span class="text-wrap">Über die Barcode Eingabe könenn folgende Werte automatisch erkannt werden: Quell Lagerplatz, Ziellagerplatz, Artikel(EAN oder Barcode). Es wird immer zuerst der Quell- und anschließend der Ziellagerplatz ausgefüllt.</span>
</template>
</UTooltip>-->
<UDivider
class="mt-5 w-80"
v-if="mode !== 'incoming'"
/>
<UFormGroup
label="Quell Lagerplatz:"
class="mt-3 w-80"
v-if="mode !== 'incoming' "
>
<USelectMenu
:options="dataStore.spaces"
searchable
option-attribute="spaceNumber"
:color="checkSpaceId(inventoryChangeData.sourceSpaceId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.sourceSpaceId"
@change="inventoryChangeData.sourceProjectId = null"
value-attribute="id"
>
<template #label>
{{dataStore.spaces.find(space => space.id === inventoryChangeData.sourceSpaceId) ? dataStore.spaces.find(space => space.id === inventoryChangeData.sourceSpaceId).description : "Kein Lagerplatz ausgewählt"}}
</template>
</USelectMenu>
</UFormGroup>
<UFormGroup
label="Quell Projekt:"
class="mt-3 w-80"
v-if="mode !== 'incoming' "
>
<USelectMenu
:options="dataStore.projects"
searchable
option-attribute="name"
:color="checkProjectId(inventoryChangeData.sourceProjectId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.sourceProjectId"
@change="inventoryChangeData.sourceSpaceId = null"
value-attribute="id"
>
<template #label>
{{dataStore.getProjectById(inventoryChangeData.sourceProjectId) ? dataStore.getProjectById(inventoryChangeData.sourceProjectId).name : "Kein Projekt ausgewählt"}}
</template>
</USelectMenu>
</UFormGroup>
<UDivider
class="mt-5 w-80"
/>
<UFormGroup
label="Artikel:"
@@ -117,7 +276,7 @@ function changeFocusToQuantity() {
variant="outline"
searchable
:search-attributes="['name','ean', 'barcode']"
:color="checkArticle(inventoryChangeData.productId) ? 'primary' : 'rose'"
:color="checkProductId(inventoryChangeData.productId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.productId"
v-on:select="changeFocusToSpaceId"
>
@@ -127,24 +286,53 @@ function changeFocusToQuantity() {
</USelectMenu>
</UFormGroup>
<UDivider
class="mt-5 w-80"
v-if="mode !== 'outgoing'"
/>
<UFormGroup
label="Lagerplatz:"
label="Ziel Lagerplatz:"
class="mt-3 w-80"
v-if="mode !== 'outgoing'"
>
<USelectMenu
:options="dataStore.spaces"
searchable
option-attribute="spaceNumber"
:color="checkSpaceId(inventoryChangeData.spaceId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.spaceId"
v-on:select="changeFocusToQuantity"
value-attribute="id"
:options="dataStore.spaces"
searchable
option-attribute="spaceNumber"
:color="checkSpaceId(inventoryChangeData.destinationSpaceId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.destinationSpaceId"
@change="inventoryChangeData.destinationProjectId = null"
value-attribute="id"
>
<template #label>
{{dataStore.spaces.find(space => space.id === inventoryChangeData.spaceId) ? dataStore.spaces.find(space => space.id === inventoryChangeData.spaceId).description : "Kein Lagerplatz ausgewählt"}}
{{dataStore.spaces.find(space => space.id === inventoryChangeData.destinationSpaceId) ? dataStore.spaces.find(space => space.id === inventoryChangeData.destinationSpaceId).description : "Kein Lagerplatz ausgewählt"}}
</template>
</USelectMenu>
</UFormGroup>
<UFormGroup
label="Ziel Projekt:"
class="mt-3 w-80"
v-if="mode !== 'outgoing'"
>
<USelectMenu
:options="dataStore.projects"
searchable
option-attribute="name"
:color="checkProjectId(inventoryChangeData.destinationProjectId) ? 'primary' : 'rose'"
v-model="inventoryChangeData.destinationProjectId"
value-attribute="id"
@change="inventoryChangeData.destinationSpaceId = null"
>
<template #label>
{{dataStore.getProjectById(inventoryChangeData.destinationProjectId) ? dataStore.getProjectById(inventoryChangeData.destinationProjectId).name : "Kein Projekt ausgewählt"}}
</template>
</USelectMenu>
</UFormGroup>
<UDivider
class="mt-5 w-80"
/>
<UFormGroup
label="Anzahl:"
@@ -161,13 +349,33 @@ function changeFocusToQuantity() {
</UFormGroup>
<UButton
@click="createMovement"
:disabled="mode === '' && checkSpaceId(inventoryChangeData.spaceId) && checkArticle(inventoryChangeData.productId)"
class="mt-3"
:disabled="mode === '' && checkSpaceId(inventoryChangeData.spaceId) && checkProductId(inventoryChangeData.productId)"
class="mt-3"
>
Bestätigen
</UButton>
<!-- <div class="my-3">
</div>
-->
</div>

View File

@@ -45,10 +45,10 @@ const tabItems = [
},{
key: "events",
label: "Termine"
}/*,{
},{
key: "material",
label: "Material"
}*/
}
]
const timeTableRows = [
@@ -426,6 +426,23 @@ setupPage()
</UTable>
</div>
<div v-else-if="item.key === 'material'" class="space-y-3">
Auf das Projekt gebuchte Artikel:
<UTable
:rows="dataStore.getStocksByProjectId(currentItem.id)"
:columns="[{key:'productId',label:'Artikel'},{key:'stock',label:'Anzahl'}]"
@select="(i) => router.push(`/products/show/${i.productId}`)"
>
<template #productId-data="{row}">
{{dataStore.getProductById(row.productId).name}}
</template>
<template #stock-data="{row}">
{{row.stock}} {{dataStore.units.find(i => i.id === dataStore.getProductById(row.productId).unit).short}}
</template>
</UTable>
</div>
</UCard>
</template>