Changes in RLS and Tenants
Many Changes in Invoice Editor Page Loading Rebuilt Started Rights Management
This commit is contained in:
875
spaces/stores/data.js
Normal file
875
spaces/stores/data.js
Normal file
@@ -0,0 +1,875 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import dayjs from "dayjs"
|
||||
import {typeOf} from "uri-js/dist/esnext/util";
|
||||
import {useNumberRange} from "~/composables/useNumberRange.js";
|
||||
|
||||
//const supabase = createClient('https://uwppvcxflrcsibuzsbil.supabase.co','eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA5MzgxOTQsImV4cCI6MjAxNjUxNDE5NH0.CkxYSQH0uLfwx9GVUlO6AYMU2FMLAxGMrwEKvyPv7Oo')
|
||||
|
||||
// @ts-ignore
|
||||
export const useDataStore = defineStore('data', () => {
|
||||
|
||||
const supabase = useSupabaseClient()
|
||||
const user = useSupabaseUser()
|
||||
const toast = useToast()
|
||||
const router = useRouter()
|
||||
|
||||
const dataTypes = {
|
||||
tasks: {
|
||||
label: "Aufgaben",
|
||||
labelSingle: "Aufgabe",
|
||||
redirect: true
|
||||
},
|
||||
customers: {
|
||||
label: "Kunden",
|
||||
labelSingle: "Kunde",
|
||||
redirect:true,
|
||||
numberRangeHolder: "customerNumber"
|
||||
},
|
||||
contacts: {
|
||||
label: "Kontakte",
|
||||
labelSingle: "Kontakt",
|
||||
redirect:true
|
||||
},
|
||||
contracts: {
|
||||
label: "Verträge",
|
||||
labelSingle: "Vertrag",
|
||||
redirect:true
|
||||
},
|
||||
absenceRequests: {
|
||||
label: "Abwesenheitsanträge",
|
||||
labelSingle: "Abwesenheitsantrag",
|
||||
redirect:true
|
||||
},
|
||||
plants: {
|
||||
label: "Objekte",
|
||||
labelSingle: "Objekte",
|
||||
redirect:true
|
||||
},
|
||||
products: {
|
||||
label: "Artikel",
|
||||
labelSingle: "Artikel",
|
||||
redirect:true
|
||||
},
|
||||
projects: {
|
||||
label: "Projekte",
|
||||
labelSingle: "Projekt",
|
||||
redirect:true
|
||||
},
|
||||
vehicles: {
|
||||
label: "Fahrzeuge",
|
||||
labelSingle: "Fahrzeug",
|
||||
redirect:true
|
||||
},
|
||||
vendors: {
|
||||
label: "Lieferanten",
|
||||
labelSingle: "Lieferant",
|
||||
redirect:true,
|
||||
numberRangeHolder: "vendorNumber"
|
||||
},
|
||||
messages: {
|
||||
label: "Nachrichten",
|
||||
labelSingle: "Nachricht"
|
||||
},
|
||||
spaces: {
|
||||
label: "Lagerplätze",
|
||||
labelSingle: "Lagerplatz",
|
||||
redirect: true,
|
||||
numberRangeHolder: "spaceNumber"
|
||||
},
|
||||
users: {
|
||||
label: "Benutzer",
|
||||
labelSingle: "Benutzer"
|
||||
},
|
||||
createdDocuments: {
|
||||
label: "Dokumente",
|
||||
labelSingle: "Dokument"
|
||||
},
|
||||
incomingInvoices: {
|
||||
label: "Eingangsrechnungen",
|
||||
labelSingle: "Eingangsrechnung"
|
||||
}
|
||||
}
|
||||
|
||||
const documentTypesForCreation = ref({
|
||||
invoices: {
|
||||
label: "Rechnungen",
|
||||
labelSingle: "Rechnung",
|
||||
|
||||
},
|
||||
quotes: {
|
||||
label: "Angebote",
|
||||
labelSingle: "Angebot"
|
||||
},
|
||||
deliveryNotes: {
|
||||
label: "Lieferscheine",
|
||||
labelSingle: "Lieferschein"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const loaded = ref(false)
|
||||
const ownTenant = ref({
|
||||
calendarConfig: {
|
||||
eventTypes: []
|
||||
},
|
||||
timeConfig: {
|
||||
timeTypes: []
|
||||
},
|
||||
tags: {
|
||||
documents: [] ,
|
||||
products: []
|
||||
},
|
||||
measures: []
|
||||
})
|
||||
|
||||
|
||||
const profiles = ref([])
|
||||
const currentTenant = ref(null)
|
||||
const events = ref([])
|
||||
const customers = ref([])
|
||||
const tasks = ref([])
|
||||
const projects = ref([])
|
||||
const documents = ref([])
|
||||
const spaces = ref([])
|
||||
const units = ref([])
|
||||
const times = ref([])
|
||||
const products = ref([])
|
||||
const movements = ref([])
|
||||
const forms = ref([])
|
||||
const contracts = ref([])
|
||||
const formSubmits = ref([])
|
||||
const contacts = ref([])
|
||||
const vehicles = ref([])
|
||||
const vendors = ref([])
|
||||
const incomingInvoices = ref([])
|
||||
const bankAccounts = ref([])
|
||||
const bankStatements = ref([])
|
||||
const historyItems = ref([])
|
||||
const numberRanges = ref([])
|
||||
const notifications = ref([])
|
||||
const absenceRequests = ref([])
|
||||
const accounts = ref([])
|
||||
const taxTypes = ref([])
|
||||
const plants = ref([])
|
||||
const inventoryItems = ref([])
|
||||
const chats = ref([])
|
||||
const messages = ref([])
|
||||
const createdDocuments = ref([])
|
||||
|
||||
async function initializeData () {
|
||||
await fetchProfiles()
|
||||
currentTenant.value = profiles.value.find(i => i.id === user.value.id).tenants[0].id
|
||||
|
||||
await fetchData()
|
||||
|
||||
}
|
||||
|
||||
async function changeTenant() {
|
||||
loaded.value = false
|
||||
await clearStore()
|
||||
await fetchData()
|
||||
router.push("/")
|
||||
loaded.value = true
|
||||
|
||||
}
|
||||
|
||||
async function fetchData () {
|
||||
await fetchProfiles()
|
||||
|
||||
fetchDocuments()
|
||||
await fetchOwnTenant()
|
||||
await fetchEvents()
|
||||
await fetchTasks()
|
||||
await fetchProjects()
|
||||
await fetchTimes()
|
||||
await fetchCustomers()
|
||||
await fetchContracts()
|
||||
await fetchContacts()
|
||||
await fetchForms()
|
||||
await fetchFormSubmits()
|
||||
await fetchProducts()
|
||||
await fetchUnits()
|
||||
//await fetchDocuments()
|
||||
await fetchMovements()
|
||||
await fetchSpaces()
|
||||
await fetchVehicles()
|
||||
await fetchVendors()
|
||||
await fetchIncomingInvoices()
|
||||
await fetchBankAccounts()
|
||||
await fetchBankStatements()
|
||||
await fetchHistoryItems()
|
||||
await fetchNumberRanges()
|
||||
await fetchNotifications()
|
||||
await fetchAbsenceRequests()
|
||||
await fetchAccounts()
|
||||
await fetchTaxTypes()
|
||||
await fetchPlants()
|
||||
await fetchInventoryItems()
|
||||
await fetchChats()
|
||||
await fetchMessages()
|
||||
await fetchCreatedDocuments()
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
function clearStore () {
|
||||
console.log("Clear")
|
||||
loaded.value = false
|
||||
ownTenant.value = {}
|
||||
profiles.value= []
|
||||
events.value= []
|
||||
customers.value= []
|
||||
tasks.value= []
|
||||
projects.value= []
|
||||
documents.value= []
|
||||
spaces.value= []
|
||||
units.value= []
|
||||
times.value= []
|
||||
products.value= []
|
||||
movements.value= []
|
||||
forms.value= []
|
||||
contracts.value= []
|
||||
formSubmits.value= []
|
||||
contacts.value= []
|
||||
vehicles.value= []
|
||||
vendors.value= []
|
||||
incomingInvoices.value= []
|
||||
bankAccounts.value= []
|
||||
bankStatements.value= []
|
||||
historyItems.value = []
|
||||
numberRanges.value = []
|
||||
notifications.value = []
|
||||
absenceRequests.value = []
|
||||
accounts.value = []
|
||||
taxTypes.value = []
|
||||
plants.value = []
|
||||
inventoryItems.value = []
|
||||
chats.value = []
|
||||
messages.value = []
|
||||
createdDocuments.value = []
|
||||
}
|
||||
|
||||
//Realtime Update
|
||||
const channelA = supabase
|
||||
.channel('schema-db-changes')
|
||||
.on(
|
||||
'postgres_changes',
|
||||
{
|
||||
event: '*',
|
||||
schema: 'public',
|
||||
},
|
||||
(payload) => {
|
||||
console.log(payload)
|
||||
|
||||
if(payload.eventType === 'INSERT') {
|
||||
const c = payload.table + '.value.push(' + JSON.stringify(payload.new) + ')'
|
||||
eval(c)
|
||||
} else if(payload.eventType === 'UPDATE'){
|
||||
const c = payload.table + '.value[' + payload.table + '.value.findIndex(i => i.id === ' + JSON.stringify(payload.old.id) + ')] = ' + JSON.stringify(payload.new)
|
||||
eval(c)
|
||||
}
|
||||
}
|
||||
)
|
||||
.subscribe()
|
||||
|
||||
async function createNewItem (dataType,data){
|
||||
console.log(dataType)
|
||||
if(dataTypes[dataType].numberRangeHolder) {
|
||||
|
||||
const numberRange = useNumberRange(dataType)
|
||||
data[dataTypes[dataType].numberRangeHolder] = await numberRange.useNextNumber()
|
||||
|
||||
} else if(dataType === "createdDocuments") {
|
||||
console.log(data.type)
|
||||
const numberRange = useNumberRange(data.type)
|
||||
data.documentNumber = await numberRange.useNextNumber()
|
||||
|
||||
}
|
||||
|
||||
const {data:supabaseData,error:supabaseError} = await supabase
|
||||
.from(dataType)
|
||||
.insert(typeOf(data) === 'Object' ? [data] : data)
|
||||
.select()
|
||||
|
||||
if(supabaseError) {
|
||||
console.log(supabaseError)
|
||||
} else if (supabaseData) {
|
||||
await eval( dataType + '.value.push(' + JSON.stringify(...supabaseData) + ')')
|
||||
toast.add({title: `${dataTypes[dataType].labelSingle} hinzugefügt`})
|
||||
if(dataTypes[dataType].redirect) await router.push(`/${dataType}/show/${supabaseData[0].id}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function updateItem (dataType, data) {
|
||||
const {data:supabaseData,error: supabaseError} = await supabase
|
||||
.from(dataType)
|
||||
.update(data)
|
||||
.eq('id',data.id)
|
||||
.select()
|
||||
|
||||
if(supabaseError) {
|
||||
console.log(supabaseError)
|
||||
} else if(supabaseData) {
|
||||
await eval(dataType + '.value[' + dataType + '.value.findIndex(i => i.id === ' + JSON.stringify(data.id) + ')] = ' + JSON.stringify(supabaseData[0]))
|
||||
toast.add({title: `${dataTypes[dataType].labelSingle} gespeichert`})
|
||||
if(dataTypes[dataType].redirect) await router.push(`/${dataType}/show/${supabaseData[0].id}`)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchOwnTenant () {
|
||||
ownTenant.value = (await supabase.from("tenants").select().eq('id', currentTenant.value)).data[0]
|
||||
}
|
||||
|
||||
async function fetchProfiles () {
|
||||
profiles.value = (await supabase.from("profiles").select('* , tenants (id, name)')).data
|
||||
}
|
||||
async function fetchBankAccounts () {
|
||||
bankAccounts.value = (await supabase.from("bankaccounts").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchBankStatements () {
|
||||
bankStatements.value = (await supabase.from("bankstatements").select().eq('tenant', currentTenant.value).order("date", {ascending:false})).data
|
||||
}
|
||||
async function fetchEvents () {
|
||||
events.value = (await supabase.from("events").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchContracts () {
|
||||
contracts.value = (await supabase.from("contracts").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchContacts () {
|
||||
contacts.value = (await supabase.from("contacts").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchCustomers () {
|
||||
customers.value = (await supabase.from("customers").select().eq('tenant', currentTenant.value).order("customerNumber", {ascending:true})).data
|
||||
}
|
||||
async function fetchTasks () {
|
||||
tasks.value = (await supabase.from("tasks").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchForms () {
|
||||
forms.value = (await supabase.from("forms").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchFormSubmits () {
|
||||
formSubmits.value = (await supabase.from("formSubmits").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchProducts () {
|
||||
products.value = (await supabase.from("products").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchUnits () {
|
||||
units.value = (await supabase.from("units").select()).data
|
||||
}
|
||||
async function fetchProjects () {
|
||||
projects.value = (await supabase.from("projects").select().eq("tenant",currentTenant.value)).data
|
||||
}
|
||||
async function fetchSpaces () {
|
||||
spaces.value = (await supabase.from("spaces").select().eq('tenant', currentTenant.value).order("spaceNumber", {ascending:true})).data
|
||||
}
|
||||
async function fetchMovements () {
|
||||
movements.value = (await supabase.from("movements").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchVehicles () {
|
||||
vehicles.value = (await supabase.from("vehicles").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchTimes () {
|
||||
times.value = (await supabase.from("times").select().eq('tenant', currentTenant.value).order("start", {ascending:false})).data
|
||||
}
|
||||
async function fetchHistoryItems () {
|
||||
|
||||
historyItems.value = (await supabase.from("historyitems").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchVendors () {
|
||||
vendors.value = (await supabase.from("vendors").select().eq('tenant', currentTenant.value).order("vendorNumber", {ascending:true})).data
|
||||
}
|
||||
async function fetchIncomingInvoices () {
|
||||
incomingInvoices.value = (await supabase.from("incominginvoices").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchNumberRanges () {
|
||||
numberRanges.value = (await supabase.from("numberranges").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchNotifications () {
|
||||
notifications.value = (await supabase.from("notifications").select().eq('tenant', currentTenant.value).order("created_at", {ascending: false})).data
|
||||
}
|
||||
async function fetchAbsenceRequests () {
|
||||
absenceRequests.value = (await supabase.from("absencerequests").select().eq('tenant', currentTenant.value)).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 fetchPlants () {
|
||||
plants.value = (await supabase.from("plants").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchInventoryItems () {
|
||||
inventoryItems.value = (await supabase.from("inventoryitems").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchChats() {
|
||||
chats.value = (await supabase.from("chats").select()).data
|
||||
}
|
||||
async function fetchMessages() {
|
||||
messages.value = (await supabase.from("messages").select().eq('tenant', currentTenant.value).order('created_at', {ascending:true})).data
|
||||
}
|
||||
async function fetchCreatedDocuments() {
|
||||
createdDocuments.value = (await supabase.from("createddocuments").select().eq('tenant', currentTenant.value).order('created_at', {ascending:true})).data
|
||||
}
|
||||
|
||||
async function fetchDocuments () {
|
||||
let tempDocuments = (await supabase.from("documents").select().eq('tenant', currentTenant.value)).data
|
||||
|
||||
if(tempDocuments.length > 0) {
|
||||
for(const [index,doc] of tempDocuments.entries()){
|
||||
// @ts-ignore
|
||||
tempDocuments[index].url = (await supabase.storage.from('files').createSignedUrl(doc.path, 60 * 60)).data.signedUrl
|
||||
}
|
||||
}
|
||||
|
||||
documents.value = tempDocuments
|
||||
|
||||
}
|
||||
|
||||
async function addHistoryItem(text, user, elementId, resourceType) {
|
||||
let data = {
|
||||
user: user,
|
||||
text: text
|
||||
}
|
||||
|
||||
if(resourceType === "customers") {
|
||||
data.customer = elementId
|
||||
}
|
||||
|
||||
const {data:insertData,error:insertError} = await supabase
|
||||
.from("historyItems")
|
||||
.insert([addHistoryItemData.value])
|
||||
.select()
|
||||
|
||||
if(insertError) {
|
||||
console.log(insertError)
|
||||
} else {
|
||||
toast.add({title: "Eintrag erfolgreich erstellt"})
|
||||
await fetchHistoryItems()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Getters
|
||||
|
||||
const getOpenTasksCount = computed(() => {
|
||||
return tasks.value.filter(task => task.categorie != "Erledigt").length
|
||||
})
|
||||
|
||||
const getOwnProfile = computed(() => {
|
||||
return profiles.value.find(profile => profile.id === user.value.id)
|
||||
})
|
||||
|
||||
const getMovementsBySpace = computed(() => (spaceId) => {
|
||||
return movements.value.filter(movement => movement.spaceId === spaceId)
|
||||
})
|
||||
|
||||
const getContactsByCustomerId = computed(() => (customerId) => {
|
||||
return contacts.value.filter(item => item.customer === customerId)
|
||||
})
|
||||
|
||||
const getContactsByVendorId = computed(() => (vendorId) => {
|
||||
return contacts.value.filter(item => item.vendor === vendorId)
|
||||
})
|
||||
|
||||
const getDocumentsByProjectId = computed(() => (projectId) => {
|
||||
return documents.value.filter(item => item.project === projectId)
|
||||
})
|
||||
|
||||
const getEventsByProjectId = computed(() => (projectId) => {
|
||||
return events.value.filter(item => item.project === projectId)
|
||||
})
|
||||
|
||||
const getTimesByProjectId = computed(() => (projectId) => {
|
||||
return times.value.filter(time => time.projectId === projectId)
|
||||
})
|
||||
|
||||
const getTasksByProjectId = computed(() => (projectId) => {
|
||||
return tasks.value.filter(item => item.project === projectId)
|
||||
})
|
||||
|
||||
const getTasksByPlantId = computed(() => (plantId) => {
|
||||
return tasks.value.filter(item => item.plant === plantId)
|
||||
})
|
||||
|
||||
const getProjectsByPlantId = computed(() => (plantId) => {
|
||||
return projects.value.filter(item => item.plant === plantId)
|
||||
})
|
||||
|
||||
const getIncomingInvoicesByVehicleId = computed(() => (vehicleId) => {
|
||||
return incomingInvoices.value.filter(i => i.accounts.find(a => a.costCentre === vehicleId))
|
||||
})
|
||||
|
||||
const getMovementsBySpaceId = computed(() => (spaceId) => {
|
||||
return movements.value.filter(movement => movement.spaceId === spaceId)
|
||||
})
|
||||
|
||||
const getMessagesByChatId = computed(() => (chatId) => {
|
||||
return messages.value.filter(i => i.destination === chatId)
|
||||
})
|
||||
|
||||
const getStockByProductId = computed(() => (productId) => {
|
||||
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
|
||||
})
|
||||
|
||||
const getTimeTypes = computed(() => {
|
||||
return ownTenant.value.timeConfig.timeTypes
|
||||
})
|
||||
|
||||
const getDocumentTags = computed(() => {
|
||||
return ownTenant.value.tags.documents
|
||||
})
|
||||
|
||||
const getMeasures = computed(() => {
|
||||
return ownTenant.value.measures
|
||||
})
|
||||
|
||||
const getResources = computed(() => {
|
||||
return [
|
||||
...profiles.value.map(profile => {
|
||||
return {
|
||||
type: 'Mitarbeiter',
|
||||
title: profile.fullName,
|
||||
id: profile.id
|
||||
}
|
||||
}),
|
||||
...vehicles.value.map(vehicle => {
|
||||
return {
|
||||
type: 'Fahrzeug',
|
||||
title: vehicle.licensePlate,
|
||||
id: `F-${vehicle.id}`
|
||||
}
|
||||
}),
|
||||
...inventoryItems.value.filter(i=> i.usePlanning).map(item => {
|
||||
return {
|
||||
type: 'Inventar',
|
||||
title: item.name,
|
||||
id: `I-${item.id}`
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const getEvents = computed(() => {
|
||||
return [
|
||||
...events.value.map(event => {
|
||||
let eventColor = ownTenant.value.calendarConfig.eventTypes.find(type => type.label === event.type).color
|
||||
|
||||
let title = ""
|
||||
if(event.title) {
|
||||
title = event.title
|
||||
} else if(event.project) {
|
||||
projects.value.find(i => i.id === event.project) ? projects.value.find(i => i.id === event.project).name : ""
|
||||
}
|
||||
|
||||
return {
|
||||
...event,
|
||||
title: title,
|
||||
borderColor: eventColor,
|
||||
textColor: eventColor,
|
||||
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
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const getEventsByResource = computed(() => {
|
||||
let tempEvents = []
|
||||
events.value.forEach(event => {
|
||||
event.resources.forEach(resource => {
|
||||
let eventColor = ownTenant.value.calendarConfig.eventTypes.find(type => type.label === event.type).color
|
||||
|
||||
let title = ""
|
||||
if(event.title) {
|
||||
title = event.title
|
||||
} else if(event.project) {
|
||||
projects.value.find(i => i.id === event.project) ? projects.value.find(i => i.id === event.project).name : ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
tempEvents.push({
|
||||
...event,
|
||||
resourceId: resource.type !== 'Mitarbeiter' ? `${resource.type[0]}-${resource.id}`: resource.id,
|
||||
resourceType: resource.type,
|
||||
title: title,
|
||||
borderColor: eventColor,
|
||||
textColor: eventColor,
|
||||
backgroundColor: "black"
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
return [
|
||||
...tempEvents,
|
||||
/*...events.value.map(event => {
|
||||
|
||||
|
||||
let eventColor = ownTenant.value.calendarConfig.eventTypes.find(type => type.label === event.type).color
|
||||
|
||||
return {
|
||||
...event,
|
||||
title: !event.title ? projects.value.find(i => i.id === event.project).name : event.title,
|
||||
borderColor: eventColor,
|
||||
textColor: eventColor,
|
||||
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
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const getCostCentresComposed = computed(() => {
|
||||
return [
|
||||
...vehicles.value.map(vehicle => {
|
||||
return {
|
||||
label: "Fahrzeug - " + vehicle.licensePlate,
|
||||
id: vehicle.id
|
||||
}
|
||||
}),
|
||||
...projects.value.map(project => {
|
||||
return {
|
||||
label: "Projekt - " + project.name,
|
||||
id: project.id
|
||||
}
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
//Get Item By Id
|
||||
const getProductById = computed(() => (itemId) => {
|
||||
return products.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getVendorById = computed(() => (itemId) => {
|
||||
return vendors.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getIncomingInvoiceById = computed(() => (itemId) => {
|
||||
return incomingInvoices.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getContractById = computed(() => (itemId) => {
|
||||
return contracts.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getContactById = computed(() => (itemId) => {
|
||||
return contacts.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getVehicleById = computed(() => (itemId) => {
|
||||
return vehicles.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getDocumentById = computed(() => (itemId) => {
|
||||
return documents.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getSpaceById = computed(() => (itemId) => {
|
||||
return spaces.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getCustomerById = computed(() => (itemId) => {
|
||||
return customers.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getTaskById = computed(() => (itemId) => {
|
||||
return tasks.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getAbsenceRequestById = computed(() => (itemId) => {
|
||||
return absenceRequests.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getProfileById = computed(() => (itemId) => {
|
||||
return profiles.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getAccountById = computed(() => (accountId) => {
|
||||
return accounts.value.find(item => item.id === accountId)
|
||||
})
|
||||
|
||||
const getPlantById = computed(() => (plantId) => {
|
||||
return plants.value.find(item => item.id === plantId)
|
||||
})
|
||||
|
||||
const getCreatedDocumentById = computed(() => (documentId) => {
|
||||
return createdDocuments.value.find(item => item.id === documentId)
|
||||
})
|
||||
|
||||
const getProjectById = computed(() => (itemId) => {
|
||||
if(projects.value.find(i => i.id === itemId)) {
|
||||
let project = projects.value.find(project => project.id === itemId)
|
||||
|
||||
/*let projectHours = 0
|
||||
|
||||
let projectTimes = times.value.filter(time => time.projectId === itemId)
|
||||
projectTimes.forEach(time => projectHours += time.duration)
|
||||
|
||||
project.projectHours = projectHours*/
|
||||
|
||||
return project
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
return {
|
||||
//General
|
||||
currentTenant,
|
||||
loaded,
|
||||
ownTenant,
|
||||
initializeData,
|
||||
changeTenant,
|
||||
|
||||
//Data
|
||||
profiles,
|
||||
events,
|
||||
customers,
|
||||
tasks,
|
||||
projects,
|
||||
documents,
|
||||
spaces,
|
||||
units,
|
||||
times,
|
||||
products,
|
||||
movements,
|
||||
forms,
|
||||
contracts,
|
||||
formSubmits,
|
||||
contacts,
|
||||
vehicles,
|
||||
vendors,
|
||||
incomingInvoices,
|
||||
bankAccounts,
|
||||
bankStatements,
|
||||
historyItems,
|
||||
numberRanges,
|
||||
notifications,
|
||||
absenceRequests,
|
||||
accounts,
|
||||
taxTypes,
|
||||
plants,
|
||||
inventoryItems,
|
||||
chats,
|
||||
messages,
|
||||
createdDocuments,
|
||||
documentTypesForCreation,
|
||||
//Functions
|
||||
createNewItem,
|
||||
updateItem,
|
||||
fetchData,
|
||||
clearStore,
|
||||
fetchOwnTenant,
|
||||
fetchProfiles,
|
||||
fetchBankAccounts,
|
||||
fetchBankStatements,
|
||||
fetchEvents,
|
||||
fetchContracts,
|
||||
fetchContacts,
|
||||
fetchCustomers,
|
||||
fetchTasks,
|
||||
fetchForms,
|
||||
fetchFormSubmits,
|
||||
fetchProducts,
|
||||
fetchUnits,
|
||||
fetchProjects,
|
||||
fetchSpaces,
|
||||
fetchMovements,
|
||||
fetchVehicles,
|
||||
fetchTimes,
|
||||
fetchHistoryItems,
|
||||
fetchVendors,
|
||||
fetchIncomingInvoices,
|
||||
fetchNumberRanges,
|
||||
fetchNotifications,
|
||||
fetchDocuments,
|
||||
fetchAbsenceRequests,
|
||||
fetchPlants,
|
||||
fetchInventoryItems,
|
||||
fetchChats,
|
||||
fetchMessages,
|
||||
addHistoryItem,
|
||||
//Getters
|
||||
getOpenTasksCount,
|
||||
getOwnProfile,
|
||||
getMovementsBySpace,
|
||||
getContactsByCustomerId,
|
||||
getContactsByVendorId,
|
||||
getDocumentsByProjectId,
|
||||
getEventsByProjectId,
|
||||
getTimesByProjectId,
|
||||
getTasksByProjectId,
|
||||
getTasksByPlantId,
|
||||
getProjectsByPlantId,
|
||||
getMovementsBySpaceId,
|
||||
getMessagesByChatId,
|
||||
getStockByProductId,
|
||||
getIncomingInvoicesByVehicleId,
|
||||
getEventTypes,
|
||||
getTimeTypes,
|
||||
getDocumentTags,
|
||||
getMeasures,
|
||||
getResources,
|
||||
getEvents,
|
||||
getEventsByResource,
|
||||
getCostCentresComposed,
|
||||
getProductById,
|
||||
getVendorById,
|
||||
getIncomingInvoiceById,
|
||||
getContractById,
|
||||
getContactById,
|
||||
getVehicleById,
|
||||
getDocumentById,
|
||||
getSpaceById,
|
||||
getCustomerById,
|
||||
getTaskById,
|
||||
getAbsenceRequestById,
|
||||
getProjectById,
|
||||
getProfileById,
|
||||
getAccountById,
|
||||
getPlantById,
|
||||
getCreatedDocumentById
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user