Many Changes

This commit is contained in:
2024-01-04 12:27:46 +01:00
parent 57e856c71c
commit 991cac18f2
31 changed files with 1504 additions and 297 deletions

View File

@@ -1,6 +1,5 @@
import {defineStore} from 'pinia'
import {createClient} from '@supabase/supabase-js'
import * as dayJs from "dayjs"
//const supabase = createClient('https://uwppvcxflrcsibuzsbil.supabase.co','eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA5MzgxOTQsImV4cCI6MjAxNjUxNDE5NH0.CkxYSQH0uLfwx9GVUlO6AYMU2FMLAxGMrwEKvyPv7Oo')
@@ -47,6 +46,10 @@ export const useDataStore = defineStore('data', () => {
const bankStatements = ref([])
const historyItems = ref([])
const numberRanges = ref([])
const notifications = ref([])
const absenceRequests = ref([])
const accounts = ref([])
const taxTypes = ref([])
async function fetchData () {
fetchDocuments()
@@ -74,6 +77,10 @@ export const useDataStore = defineStore('data', () => {
await fetchBankStatements()
await fetchHistoryItems()
await fetchNumberRanges()
await fetchNotifications()
await fetchAbsenceRequests()
await fetchAccounts()
await fetchTaxTypes()
loaded.value = true
}
@@ -104,6 +111,10 @@ export const useDataStore = defineStore('data', () => {
bankStatements.value= []
historyItems.value = []
numberRanges.value = []
notifications.value = []
absenceRequests.value = []
accounts.value = []
taxTypes.value = []
}
async function fetchOwnTenant () {
@@ -117,7 +128,7 @@ export const useDataStore = defineStore('data', () => {
bankAccounts.value = (await supabase.from("bankAccounts").select()).data
}
async function fetchBankStatements () {
bankStatements.value = (await supabase.from("bankStatements").select()).data
bankStatements.value = (await supabase.from("bankStatements").select().order("date", {ascending:false})).data
}
async function fetchEvents () {
events.value = (await supabase.from("events").select()).data
@@ -176,6 +187,18 @@ export const useDataStore = defineStore('data', () => {
async function fetchNumberRanges () {
numberRanges.value = (await supabase.from("numberRanges").select()).data
}
async function fetchNotifications () {
notifications.value = (await supabase.from("notifications").select().order("created_at", {ascending: false})).data
}
async function fetchAbsenceRequests () {
absenceRequests.value = (await supabase.from("absenceRequests").select()).data
}
async function fetchAccounts () {
accounts.value = (await supabase.from("accounts").select()).data
}
async function fetchTaxTypes () {
taxTypes.value = (await supabase.from("taxTypes").select()).data
}
async function fetchDocuments () {
documents.value = (await supabase.from("documents").select()).data
@@ -224,6 +247,10 @@ export const useDataStore = defineStore('data', () => {
return contacts.value.filter(item => item.customer === customerId)
})
const getContactsByVendorId = computed(() => (vendorId:string) => {
return contacts.value.filter(item => item.vendor === vendorId)
})
const getDocumentsByProjectId = computed(() => (projectId:string) => {
return documents.value.filter(item => item.project === projectId)
})
@@ -232,10 +259,36 @@ export const useDataStore = defineStore('data', () => {
return times.value.filter(time => time.projectId === projectId)
})
const getTasksByProjectId = computed(() => (projectId:string) => {
return tasks.value.filter(item => item.project === projectId)
})
const getHistoryItemsByCustomer = computed(() => (customerId:string) => {
return historyItems.value.filter(item => item.customer === customerId)
})
const getHistoryItemsByVendor = computed(() => (vendorId:string) => {
return historyItems.value.filter(item => item.vendor === vendorId)
})
const getMovementsBySpaceId = computed(() => (spaceId:string) => {
return movements.value.filter(movement => movement.spaceId === spaceId)
})
const getStockByProductId = computed(() => (productId:string) => {
let productMovements = movements.value.filter(movement => movement.productId === productId)
let count = 0
productMovements.forEach(movement => {
count += movement.quantity
})
return count
})
const getEventTypes = computed(() => {
return ownTenant.value.calendarConfig.eventTypes
})
@@ -279,6 +332,16 @@ export const useDataStore = defineStore('data', () => {
backgroundColor: "black"
}
}),
...absenceRequests.value.map(absence => {
return {
resourceId: absence.user,
resourceType: "person",
title: absence.reason,
start: dayJs(absence.start).toDate(),
end: dayJs(absence.end).add(1,'day').toDate(),
allDay: true
}
})
]
})
@@ -304,7 +367,7 @@ export const useDataStore = defineStore('data', () => {
return contacts.value.find(item => item.id === itemId)
})
const getVehiclesById = computed(() => (itemId:string) => {
const getVehicleById = computed(() => (itemId:string) => {
return vehicles.value.find(item => item.id === itemId)
})
@@ -324,10 +387,18 @@ export const useDataStore = defineStore('data', () => {
return jobs.value.find(item => item.id === itemId)
})
const getAbsenceRequestById = computed(() => (itemId:string) => {
return absenceRequests.value.find(item => item.id === itemId)
})
const getProfileById = computed(() => (itemId:string) => {
return profiles.value.find(item => item.id === itemId)
})
const getAccountById = computed(() => (accountId:string) => {
return accounts.value.find(item => item.id === accountId)
})
const getProjectById = computed(() => (itemId:string) => {
let project = projects.value.find(project => project.id === itemId)
@@ -367,6 +438,10 @@ export const useDataStore = defineStore('data', () => {
bankStatements,
historyItems,
numberRanges,
notifications,
absenceRequests,
accounts,
taxTypes,
//Functions
fetchData,
clearStore,
@@ -393,15 +468,22 @@ export const useDataStore = defineStore('data', () => {
fetchVendors,
fetchVendorInvoices,
fetchNumberRanges,
fetchNotifications,
fetchDocuments,
fetchAbsenceRequests,
addHistoryItem,
//Getters
getOpenTasksCount,
getMovementsBySpace,
getContactsByCustomerId,
getContactsByVendorId,
getDocumentsByProjectId,
getTimesByProjectId,
getTasksByProjectId,
getMovementsBySpaceId,
getStockByProductId,
getHistoryItemsByCustomer,
getHistoryItemsByVendor,
getEventTypes,
getTimeTypes,
getDocumentTags,
@@ -412,13 +494,15 @@ export const useDataStore = defineStore('data', () => {
getVendorInvoiceById,
getContractById,
getContactById,
getVehiclesById,
getVehicleById,
getDocumentById,
getSpaceById,
getCustomerById,
getJobById,
getAbsenceRequestById,
getProjectById,
getProfileById
getProfileById,
getAccountById,
}