From 1cbb8cbacfaba2e4fde7abc99aed672b7cade7ae Mon Sep 17 00:00:00 2001 From: flfeders Date: Tue, 23 Apr 2024 20:28:26 +0200 Subject: [PATCH] Rebuild Inventory Added Advance Invoices --- pages/createDocument/edit/[[id]].vue | 116 ++++++++- pages/createDocument/index.vue | 3 + pages/incomingInvoices/[mode]/[[id]].vue | 7 +- pages/inventory/index.vue | 304 +++++++++++++++++++---- pages/projects/[mode]/[[id]].vue | 21 +- stores/data.js | 50 +++- 6 files changed, 432 insertions(+), 69 deletions(-) diff --git a/pages/createDocument/edit/[[id]].vue b/pages/createDocument/edit/[[id]].vue index 9e9952b..8494a1b 100644 --- a/pages/createDocument/edit/[[id]].vue +++ b/pages/createDocument/edit/[[id]].vue @@ -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() - + + + + Auto Positionen + + + - - + + + + + + + + + + + + + + + + + + + + diff --git a/pages/createDocument/index.vue b/pages/createDocument/index.vue index 1ba7599..23f1310 100644 --- a/pages/createDocument/index.vue +++ b/pages/createDocument/index.vue @@ -193,6 +193,9 @@ const templateTypes = [ { key: "invoices", label: "Rechnungen" + },{ + key: "advanceInvoices", + label: "Abschlagsrechnungen" }, { key: "quotes", label: "Angebote" diff --git a/pages/incomingInvoices/[mode]/[[id]].vue b/pages/incomingInvoices/[mode]/[[id]].vue index 2d18bb7..3ff2883 100644 --- a/pages/incomingInvoices/[mode]/[[id]].vue +++ b/pages/incomingInvoices/[mode]/[[id]].vue @@ -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()
-
+ { - 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) +} + diff --git a/stores/data.js b/stores/data.js index 70896e5..d114a8d 100644 --- a/stores/data.js +++ b/stores/data.js @@ -134,6 +134,10 @@ export const useDataStore = defineStore('data', () => { labelSingle: "Rechnung", }, + advanceInvoices: { + label: "Abschlagsrechnungen", + labelSingle: "Abschlagsrechnung" + }, quotes: { label: "Angebote", labelSingle: "Angebot" @@ -765,7 +769,15 @@ export const useDataStore = defineStore('data', () => { } else if(dataType === "createddocuments") { console.log(data.type) - const numberRange = useNumberRange(data.type) + + let type = "" + if(data.type === "advanceInvoices"){ + type = "invoices" + } else { + type = data.type + } + + const numberRange = useNumberRange(type) data.documentNumber = await numberRange.useNextNumber() } @@ -1190,7 +1202,7 @@ export const useDataStore = defineStore('data', () => { }) const getStockByProductId = computed(() => (productId) => { - let productMovements = movements.value.filter(movement => movement.productId === productId) + let productMovements = movements.value.filter(movement => movement.productId === productId && movement.projectId === null) let count = 0 @@ -1201,6 +1213,39 @@ export const useDataStore = defineStore('data', () => { return count }) + const getStocksByProjectId = computed(() => (projectId) => { + let projectMovements = movements.value.filter(movement => movement.projectId === projectId) + + let projectProducts = [... new Set(projectMovements.map(i => i.productId))] + + console.log(projectProducts) + + let productStocks = [] + + projectProducts.forEach(product => { + let count = 0 + let productMovements = movements.value.filter(i => i.productId === product && i.projectId && projectId) + + productMovements.forEach(movement => { + count += movement.quantity + }) + + productStocks.push({ + productId: product, + stock: count + }) + + }) + + /*let count = 0 + + projectMovements.forEach(movement => { + count += movement.quantity + })*/ + + return productStocks + }) + const getEventTypes = computed(() => { return ownTenant.value.calendarConfig.eventTypes }) @@ -1604,6 +1649,7 @@ export const useDataStore = defineStore('data', () => { getWorkingTimesByProfileId, getStartedWorkingTimes, getStockByProductId, + getStocksByProjectId, getIncomingInvoicesByVehicleId, getEventTypes, getTimeTypes,