1746 lines
57 KiB
JavaScript
1746 lines
57 KiB
JavaScript
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,
|
|
historyItemHolder: "task"
|
|
},
|
|
customers: {
|
|
label: "Kunden",
|
|
labelSingle: "Kunde",
|
|
redirect:true,
|
|
numberRangeHolder: "customerNumber",
|
|
historyItemHolder: "customer"
|
|
},
|
|
contacts: {
|
|
label: "Kontakte",
|
|
labelSingle: "Kontakt",
|
|
redirect:true,
|
|
historyItemHolder: "contact"
|
|
},
|
|
contracts: {
|
|
label: "Verträge",
|
|
labelSingle: "Vertrag",
|
|
redirect:true
|
|
},
|
|
absencerequests: {
|
|
label: "Abwesenheitsanträge",
|
|
labelSingle: "Abwesenheitsantrag",
|
|
redirect:true
|
|
},
|
|
plants: {
|
|
label: "Objekte",
|
|
labelSingle: "Objekte",
|
|
redirect:true,
|
|
historyItemHolder: "plant"
|
|
},
|
|
products: {
|
|
label: "Artikel",
|
|
labelSingle: "Artikel",
|
|
redirect:true
|
|
},
|
|
projects: {
|
|
label: "Projekte",
|
|
labelSingle: "Projekt",
|
|
redirect:true,
|
|
historyItemHolder: "project"
|
|
},
|
|
vehicles: {
|
|
label: "Fahrzeuge",
|
|
labelSingle: "Fahrzeug",
|
|
redirect:true,
|
|
historyItemHolder: "vehicle"
|
|
},
|
|
vendors: {
|
|
label: "Lieferanten",
|
|
labelSingle: "Lieferant",
|
|
redirect:true,
|
|
numberRangeHolder: "vendorNumber",
|
|
historyItemHolder: "vendor"
|
|
},
|
|
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",
|
|
redirect:true
|
|
},
|
|
inventoryitems: {
|
|
label: "Inventarartikel",
|
|
labelSingle: "Inventarartikel",
|
|
redirect: true
|
|
},
|
|
services: {
|
|
label: "Leistungen",
|
|
labelSingle: "Leistung",
|
|
redirect: true
|
|
},
|
|
events: {
|
|
label: "Termine",
|
|
labelSingle: "Termin",
|
|
historyItemHolder: "event",
|
|
redirect: true
|
|
},
|
|
profiles: {
|
|
label: "Mitarbeiter",
|
|
labelSingle: "Mitarbeiter",
|
|
redirect: true,
|
|
historyItemHolder: "profile"
|
|
},
|
|
workingtimes: {
|
|
label: "Anwesenheiten",
|
|
labelSingle: "Anwesenheit"
|
|
},
|
|
texttemplates: {
|
|
label: "Textvorlagen",
|
|
labelSingle: "Textvorlage"
|
|
},
|
|
bankstatements: {
|
|
label: "Kontobewegungen",
|
|
labelSingle: "Kontobewegung",
|
|
historyItemHolder: "bankStatement",
|
|
},
|
|
statementallocations: {
|
|
label: "Bankzuweisungen",
|
|
labelSingle: "Bankzuweisung"
|
|
}
|
|
}
|
|
|
|
const documentTypesForCreation = ref({
|
|
invoices: {
|
|
label: "Rechnungen",
|
|
labelSingle: "Rechnung",
|
|
|
|
},
|
|
advanceInvoices: {
|
|
label: "Abschlagsrechnungen",
|
|
labelSingle: "Abschlagsrechnung"
|
|
},
|
|
quotes: {
|
|
label: "Angebote",
|
|
labelSingle: "Angebot"
|
|
},
|
|
deliveryNotes: {
|
|
label: "Lieferscheine",
|
|
labelSingle: "Lieferschein"
|
|
},
|
|
confirmationOrders: {
|
|
label: "Auftragsbestätigungen",
|
|
labelSingle: "Auftragsbestätigung"
|
|
}
|
|
})
|
|
|
|
|
|
const loaded = ref(false)
|
|
const showProfileSelection = ref(false)
|
|
const ownTenant = ref({
|
|
calendarConfig: {
|
|
eventTypes: []
|
|
},
|
|
timeConfig: {
|
|
timeTypes: []
|
|
},
|
|
tags: {
|
|
documents: [] ,
|
|
products: []
|
|
},
|
|
measures: []
|
|
})
|
|
|
|
|
|
const profiles = ref([])
|
|
const ownProfiles = ref([])
|
|
const activeProfile = ref([])
|
|
const tenants = 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 bankrequisitions = 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([])
|
|
const workingtimes = ref([])
|
|
const phasesTemplates = ref([])
|
|
const emailAccounts = ref([])
|
|
const texttemplates =ref([])
|
|
const services =ref([])
|
|
const serviceCategories =ref([])
|
|
const resources =ref([])
|
|
|
|
|
|
const rights = ref({
|
|
createUser: {label: "Benutzer erstellen"},
|
|
modifyUser: {label: "Benutzer bearbeiten"},
|
|
deactivateUser: {label: "Benutzer sperren"},
|
|
createProject: {label: "Projekt erstellen"},
|
|
viewOwnProjects: {label: "Eigene Projekte sehen"},
|
|
viewAllProjects: {label: "Alle Projekte sehen"},
|
|
createTask: {label: "Aufgabe erstellen"},
|
|
viewOwnTasks: {label:"Eigene Aufgaben sehen"},
|
|
viewAllTasks: {label: "Alle Aufgaben sehen"},
|
|
trackOwnTime: {label:"Eigene Zeite erfassen"},
|
|
createOwnTime: {label:"Eigene Zeiten erstellen"},
|
|
createTime: {label:"Zeiten erstellen"},
|
|
viewOwnTimes: {label:"Eigene Zeiten anzeigen"},
|
|
viewTimes: {label:"Zeiten anzeigen"},
|
|
})
|
|
|
|
const roles = ref([
|
|
{
|
|
key: "tenantAdmin",
|
|
label: "Firmenadministrator",
|
|
rights: [
|
|
...Object.keys(rights.value)
|
|
]
|
|
},
|
|
{
|
|
key:"worker",
|
|
label: "Monteur",
|
|
rights: [
|
|
"viewOwnProjects",
|
|
"createTasks",
|
|
"viewOwnTasks",
|
|
"viewOwnTimes",
|
|
"createOwnTime"
|
|
]
|
|
},
|
|
{
|
|
key:"manager",
|
|
label: "Vorarbeiter",
|
|
rights: [
|
|
"createProjects",
|
|
"viewOwnProjects",
|
|
"createTasks",
|
|
"viewOwnTasks",
|
|
]
|
|
},
|
|
{
|
|
key:"booker",
|
|
label: "Buchhalter",
|
|
rights: [
|
|
"createTasks",
|
|
"viewOwnTasks",
|
|
"createTime",
|
|
"viewAllTimes"
|
|
]
|
|
}
|
|
])
|
|
|
|
async function initializeData (userId) {
|
|
|
|
let profileconnections = (await supabase.from("profileconnections").select()).data
|
|
let profiles = (await supabase.from("profiles").select()).data
|
|
let activeProfileConnection = profileconnections.find(i => i.active)
|
|
if(activeProfileConnection) {
|
|
activeProfile.value = profiles.find(i => i.id === activeProfileConnection.profile_id)
|
|
currentTenant.value = activeProfile.value.tenant
|
|
|
|
await fetchData()
|
|
|
|
//loaded.value = true
|
|
|
|
} else {
|
|
await fetchOwnProfiles()
|
|
await fetchTenants()
|
|
showProfileSelection.value = true
|
|
}
|
|
|
|
|
|
}
|
|
|
|
async function changeProfile(newActiveProfileId) {
|
|
loaded.value = false
|
|
|
|
let profileconnections = (await supabase.from("profileconnections").select()).data
|
|
|
|
let oldActiveProfileConnection = profileconnections.find(i => i.active)
|
|
|
|
const {error} = await supabase.from("profileconnections").update({active: true}).eq("profile_id", newActiveProfileId)
|
|
|
|
if(error) {
|
|
console.log(error)
|
|
} else {
|
|
if(oldActiveProfileConnection){
|
|
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileConnection.profile_id)
|
|
}
|
|
|
|
reloadNuxtApp({
|
|
path:"/",
|
|
ttl: 10000
|
|
})
|
|
|
|
/*await clearStore()
|
|
await fetchData()
|
|
router.push("/")
|
|
loaded.value = true*/
|
|
|
|
|
|
}
|
|
}
|
|
|
|
async function fetchData () {
|
|
await fetchOwnProfiles()
|
|
await fetchProfiles()
|
|
|
|
await fetchTenants()
|
|
await fetchOwnTenant()
|
|
|
|
//loaded.value = true
|
|
await fetchDocuments()
|
|
await fetchEvents()
|
|
await fetchTasks()
|
|
await fetchProjects()
|
|
await fetchTimes()
|
|
await fetchCustomers()
|
|
await fetchContracts()
|
|
await fetchContacts()
|
|
await fetchForms()
|
|
await fetchFormSubmits()
|
|
await fetchProducts()
|
|
await fetchUnits()
|
|
await fetchMovements()
|
|
await fetchSpaces()
|
|
await fetchVehicles()
|
|
await fetchVendors()
|
|
await fetchIncomingInvoices()
|
|
await fetchBankAccounts()
|
|
await fetchBankStatements()
|
|
await fetchBankRequisitions()
|
|
await fetchHistoryItems()
|
|
await fetchNumberRanges()
|
|
await fetchNotifications()
|
|
await fetchAbsenceRequests()
|
|
await fetchAccounts()
|
|
await fetchTaxTypes()
|
|
await fetchPlants()
|
|
await fetchInventoryItems()
|
|
await fetchChats()
|
|
await fetchMessages()
|
|
await fetchCreatedDocuments()
|
|
await fetchWorkingTimes()
|
|
await fetchPhasesTemplates()
|
|
await fetchEmailAccounts()
|
|
await fetchTextTemplates()
|
|
await fetchServices()
|
|
await fetchServiceCategories()
|
|
await fetchResources()
|
|
loaded.value = true
|
|
|
|
|
|
}
|
|
|
|
function clearStore () {
|
|
console.log("Clear")
|
|
loaded.value = false
|
|
ownTenant.value = {}
|
|
profiles.value = []
|
|
ownProfiles.value = []
|
|
tenants.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= []
|
|
bankrequisitions.value= []
|
|
historyItems.value = []
|
|
numberRanges.value = []
|
|
notifications.value = []
|
|
absencerequests.value = []
|
|
accounts.value = []
|
|
taxTypes.value = []
|
|
plants.value = []
|
|
inventoryitems.value = []
|
|
chats.value = []
|
|
messages.value = []
|
|
createddocuments.value = []
|
|
workingtimes.value = []
|
|
phasesTemplates.value = []
|
|
emailAccounts.value = []
|
|
texttemplates.value = []
|
|
services.value = []
|
|
serviceCategories.value = []
|
|
resources.value = []
|
|
}
|
|
|
|
function hasRight (right) {
|
|
const role = profiles.value.find(i => i.id === activeProfile.value.id).role
|
|
const grantedRights = roles.value.find(i => i.key === role).rights
|
|
|
|
if(grantedRights.includes(right)){
|
|
return true
|
|
} else return false
|
|
|
|
}
|
|
|
|
var deepDiffMapper = function () {
|
|
return {
|
|
VALUE_CREATED: 'created',
|
|
VALUE_UPDATED: 'updated',
|
|
VALUE_DELETED: 'deleted',
|
|
VALUE_UNCHANGED: 'unchanged',
|
|
map: function(obj1, obj2, k = null) {
|
|
if (this.isFunction(obj1) || this.isFunction(obj2)) {
|
|
throw 'Invalid argument. Function given, object expected.';
|
|
}
|
|
if (this.isValue(obj1) || this.isValue(obj2)) {
|
|
return {
|
|
type: this.compareValues(obj1, obj2),
|
|
data: {o: obj1, n: obj2, k: k}//obj1 === undefined ? obj2 : obj1
|
|
};
|
|
}
|
|
|
|
var diff = {};
|
|
for (var key in obj1) {
|
|
if (this.isFunction(obj1[key])) {
|
|
continue;
|
|
}
|
|
|
|
var value2 = undefined;
|
|
if (obj2[key] !== undefined) {
|
|
value2 = obj2[key];
|
|
}
|
|
|
|
diff[key] = this.map(obj1[key], value2,key);
|
|
}
|
|
for (var key in obj2) {
|
|
if (this.isFunction(obj2[key]) || diff[key] !== undefined) {
|
|
continue;
|
|
}
|
|
|
|
diff[key] = this.map(undefined, obj2[key],key);
|
|
}
|
|
|
|
return diff;
|
|
|
|
},
|
|
compareValues: function (value1, value2) {
|
|
if (value1 === value2) {
|
|
return this.VALUE_UNCHANGED;
|
|
}
|
|
if (this.isDate(value1) && this.isDate(value2) && value1.getTime() === value2.getTime()) {
|
|
return this.VALUE_UNCHANGED;
|
|
}
|
|
if (value1 === undefined) {
|
|
return this.VALUE_CREATED;
|
|
}
|
|
if (value2 === undefined) {
|
|
return this.VALUE_DELETED;
|
|
}
|
|
return this.VALUE_UPDATED;
|
|
},
|
|
isFunction: function (x) {
|
|
return Object.prototype.toString.call(x) === '[object Function]';
|
|
},
|
|
isArray: function (x) {
|
|
return Object.prototype.toString.call(x) === '[object Array]';
|
|
},
|
|
isDate: function (x) {
|
|
return Object.prototype.toString.call(x) === '[object Date]';
|
|
},
|
|
isObject: function (x) {
|
|
return Object.prototype.toString.call(x) === '[object Object]';
|
|
},
|
|
isValue: function (x) {
|
|
return !this.isObject(x) && !this.isArray(x);
|
|
}
|
|
}
|
|
}();
|
|
|
|
|
|
|
|
const generateHistoryItems = async (dataType,newData, oldData=null) => {
|
|
//console.log(oldData)
|
|
//console.log(newData)
|
|
|
|
if(dataTypes[dataType].historyItemHolder){
|
|
let itemsToCreate = []
|
|
|
|
const checkPropState = (key,propContent) => {
|
|
//console.log(propContent)
|
|
if(propContent.type && propContent.data){
|
|
if(propContent.type === "updated" ||propContent.type === "created"){
|
|
createHistoryItem(key,propContent)
|
|
}
|
|
} else {
|
|
for (let prop in propContent) {
|
|
checkPropState(prop,propContent[prop])
|
|
}
|
|
}
|
|
}
|
|
|
|
const createHistoryItem = (key,prop) => {
|
|
|
|
//console.log("OLD: " + prop.data.o)
|
|
//console.log("NEW: " + prop.data.n)
|
|
|
|
let name = "" || key
|
|
let oldVal = prop.data.o || "-"
|
|
let newVal = prop.data.n || "-"
|
|
|
|
|
|
|
|
if(key === "project") {
|
|
name = "Projekt"
|
|
oldVal = oldVal !== "-" ? projects.value.find(i => i.id === prop.data.o).name : "-"
|
|
newVal = projects.value.find(i => i.id === prop.data.n).name
|
|
} else if (key === "title") {
|
|
name = "Titel"
|
|
} else if(key === "type") {
|
|
name = "Typ"
|
|
} else if(key === "notes") {
|
|
name = "Notizen"
|
|
} else if(key === "link") {
|
|
name = "Link"
|
|
} else if(key === "start") {
|
|
name = "Start"
|
|
oldVal = dayjs(prop.data.o).format("DD.MM.YYYY HH:mm")
|
|
newVal = dayjs(prop.data.n).format("DD.MM.YYYY HH:mm")
|
|
} else if(key === "end") {
|
|
name = "Ende"
|
|
oldVal = dayjs(prop.data.o).format("DD.MM.YYYY HH:mm")
|
|
newVal = dayjs(prop.data.n).format("DD.MM.YYYY HH:mm")
|
|
} else if(key === "birthday") {
|
|
name = "Geburtstag"
|
|
oldVal = dayjs(prop.data.o).format("DD.MM.YYY")
|
|
newVal = dayjs(prop.data.n).format("DD.MM.YYY")
|
|
} else if(key === "resources") {
|
|
name = "Resourcen"
|
|
oldVal = prop.data.o.map(i => i.title).join(", ")
|
|
newVal = prop.data.n.map(i => i.title).join(", ")
|
|
} else if(key === "customerNumber") {
|
|
name = "Kundennummer"
|
|
} else if(key === "active") {
|
|
name = "Aktiv"
|
|
if(oldVal === true){
|
|
oldVal = "Aktiv"
|
|
newVal = "Gesperrt"
|
|
} else if(oldVal === "-") {
|
|
oldVal = "Gesperrt"
|
|
newVal = "Aktiv"
|
|
}
|
|
} else if(key === "isCompany") {
|
|
name = "Firmenkunde"
|
|
if(oldVal === true){
|
|
oldVal = "Firma"
|
|
newVal = "Privatkunde"
|
|
} else if(oldVal === "-") {
|
|
oldVal = "Privatkunde"
|
|
newVal = "Firma"
|
|
}
|
|
} else if(key === "special") {
|
|
name = "Adresszusatz"
|
|
} else if(key === "street") {
|
|
name = "Straße & Hausnummer"
|
|
} else if(key === "city") {
|
|
name = "Ort"
|
|
} else if(key === "zip") {
|
|
name = "Postleitzahl"
|
|
} else if(key === "country") {
|
|
name = "Land"
|
|
} else if(key === "web") {
|
|
name = "Webseite"
|
|
} else if(key === "email") {
|
|
name = "E-Mail"
|
|
} else if(key === "tel") {
|
|
name = "Telefon"
|
|
} else if(key === "ustid") {
|
|
name = "USt-ID"
|
|
} else if(key === "role") {
|
|
name = "Rolle"
|
|
} else if(key === "phoneHome") {
|
|
name = "Festnetz"
|
|
} else if(key === "phoneMobile") {
|
|
name = "Mobiltelefon"
|
|
} else if(key === "salutation") {
|
|
name = "Anrede"
|
|
} else if(key === "firstName") {
|
|
name = "Vorname"
|
|
} else if(key === "lastName") {
|
|
name = "Nachname"
|
|
} else if(key === "name") {
|
|
name = "Name"
|
|
} else if(key === "customer") {
|
|
name = "Kunde"
|
|
oldVal = customers.value.find(i => i.id === prop.data.o).name
|
|
newVal = customers.value.find(i => i.id === prop.data.n).name
|
|
} else if(key === "vendor") {
|
|
name = "Lieferant"
|
|
oldVal = vendors.value.find(i => i.id === prop.data.o).name
|
|
newVal = vendors.value.find(i => i.id === prop.data.n).name
|
|
} else if(key === "description") {
|
|
name = "Beschreibung"
|
|
} else if(key === "categorie") {
|
|
name = "Kategorie"
|
|
} else if(key === "profile") {
|
|
name = "Mitarbeiter"
|
|
oldVal = profiles.value.find(i => i.id === prop.data.o).fullName
|
|
newVal = profiles.value.find(i => i.id === prop.data.n).fullName
|
|
} else if(key === "plant") {
|
|
name = "Objekt"
|
|
oldVal = plants.value.find(i => i.id === prop.data.o).name
|
|
newVal = plants.value.find(i => i.id === prop.data.n).name
|
|
} else if(key === "annualPaidLeaveDays") {
|
|
name = "Urlaubstage"
|
|
} else if(key === "employeeNumber") {
|
|
name = "Mitarbeiternummer"
|
|
} else if(key === "weeklyWorkingDays") {
|
|
name = "Wöchentliche Arbeitstage"
|
|
} else if(key === "weeklyWorkingHours") {
|
|
name = "Wöchentliche Arbeitszeit"
|
|
} else if(key === "licensePlate") {
|
|
name = "Kennzeichen"
|
|
} else if(key === "driver") {
|
|
name = "Fahrer"
|
|
oldVal = profiles.value.find(i => i.id === prop.data.o).fullName
|
|
newVal = profiles.value.find(i => i.id === prop.data.n).fullName
|
|
}
|
|
|
|
|
|
|
|
let text = ""
|
|
if(prop.type === "updated" && newVal !== "-" && oldVal !== "-") {
|
|
text = `Gerändert: ${name} von "${oldVal}" zu "${newVal}"`
|
|
} else if(prop.type === "updated" && newVal !== "-" && oldVal === "-") {
|
|
text = `Hinzugefügt: ${name} "${newVal}"`
|
|
} else if(prop.type === "created") {
|
|
text = `Hinzugefügt: ${name} "${newVal}"`
|
|
} else if(prop.type === "updated" && newVal === "-" && oldVal !== "-") {
|
|
text = `Entfernt: ${name} "${oldVal}"`
|
|
}
|
|
|
|
let historyItem = {
|
|
text: text,
|
|
createdBy: activeProfile.value.id,
|
|
oldVal: prop.data.o,
|
|
newVal: prop.data.n,
|
|
tenant: currentTenant.value
|
|
}
|
|
|
|
historyItem[dataTypes[dataType].historyItemHolder] = newData.id
|
|
|
|
|
|
const checkIfNaN = (x) => {
|
|
return typeof x === "number" && x !== x;
|
|
}
|
|
//console.log(key)
|
|
//console.log(checkIfNaN(key))
|
|
|
|
if(key !== "fullName" && key !== "phases") {
|
|
//console.log(historyItem)
|
|
itemsToCreate.push(historyItem)
|
|
}
|
|
|
|
}
|
|
|
|
if(oldData) {
|
|
let result = deepDiffMapper.map(oldData,newData)
|
|
|
|
//console.log(result)
|
|
|
|
for (let prop in result) {
|
|
//console.log(prop)
|
|
checkPropState(prop,result[prop])
|
|
|
|
}
|
|
|
|
} else {
|
|
let historyItem = {
|
|
text: `${dataTypes[dataType].labelSingle} erstellt`,
|
|
createdBy: activeProfile.value.id,
|
|
tenant: currentTenant.value
|
|
}
|
|
|
|
historyItem[dataTypes[dataType].historyItemHolder] = newData.id
|
|
|
|
//console.log(historyItem)
|
|
itemsToCreate.push(historyItem)
|
|
}
|
|
|
|
const {data,error} = await supabase.from("historyitems").insert(itemsToCreate)
|
|
|
|
if(error) {
|
|
console.log(error)
|
|
} else {
|
|
fetchHistoryItems()
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//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){
|
|
if(typeOf(data) === 'object') {
|
|
data = {...data, tenant: currentTenant.value}
|
|
} else if(typeOf(data) === 'array') {
|
|
data.map(i => {
|
|
return {
|
|
...i,
|
|
tenant: currentTenant.value
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
//console.log(dataType)
|
|
if(dataTypes[dataType].numberRangeHolder) {
|
|
|
|
const numberRange = useNumberRange(dataType)
|
|
if(!data[dataTypes[dataType].numberRangeHolder]) {
|
|
data[dataTypes[dataType].numberRangeHolder] = await numberRange.useNextNumber()
|
|
}
|
|
|
|
|
|
} else if(dataType === "createddocuments") {
|
|
console.log(data.type)
|
|
|
|
let type = ""
|
|
if(data.type === "advanceInvoices"){
|
|
type = "invoices"
|
|
} else {
|
|
type = data.type
|
|
}
|
|
|
|
const numberRange = useNumberRange(type)
|
|
data.documentNumber = await numberRange.useNextNumber()
|
|
|
|
}
|
|
|
|
|
|
|
|
const {data:supabaseData,error:supabaseError} = await supabase
|
|
.from(dataType)
|
|
.insert(data)
|
|
.select()
|
|
|
|
if(supabaseError) {
|
|
console.log(supabaseError)
|
|
toast.add({title: "Es ist ein Fehler bei der Erstellung aufgetreten", color: "rose"})
|
|
} else if (supabaseData) {
|
|
console.log(supabaseData)
|
|
await generateHistoryItems(dataType, supabaseData[0])
|
|
|
|
if(dataType !== "statementallocations"){
|
|
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}`)
|
|
return supabaseData
|
|
}
|
|
}
|
|
|
|
async function updateItem (dataType, data, oldData = null) {
|
|
console.log(dataType, data)
|
|
//Temporary Fix TODO: Remove and build Solution
|
|
data = JSON.parse(JSON.stringify(data))
|
|
delete data.users
|
|
|
|
if(oldData) {
|
|
oldData = JSON.parse(JSON.stringify(oldData))
|
|
delete oldData.users
|
|
}
|
|
|
|
const {tenants, ...newData} = data
|
|
|
|
|
|
await generateHistoryItems(dataType,data,oldData)
|
|
|
|
const {data:supabaseData,error: supabaseError} = await supabase
|
|
.from(dataType)
|
|
.update(newData)
|
|
.eq('id',newData.id)
|
|
.select()
|
|
|
|
if(supabaseError) {
|
|
console.log(supabaseError)
|
|
toast.add({title: `Fehler beim Speichern`, color: 'rose'})
|
|
} else if(supabaseData) {
|
|
//await eval(dataType + '.value[' + dataType + '.value.findIndex(i => i.id === ' + JSON.stringify(data.id) + ')] = ' + JSON.stringify(supabaseData[0]))
|
|
if(dataType === 'profiles') await fetchProfiles()
|
|
toast.add({title: `${dataTypes[dataType].labelSingle} gespeichert`})
|
|
if(dataTypes[dataType].redirect) await router.push(`/${dataType}/show/${data.id}`)
|
|
return supabaseData
|
|
}
|
|
}
|
|
|
|
const uploadFiles = async (formData, files, upsert) => {
|
|
//console.log(files)
|
|
//console.log(formData)
|
|
let documentsToInsert = []
|
|
|
|
const uploadSingleFile = async (file) => {
|
|
|
|
const {data, error} = await supabase
|
|
.storage
|
|
.from("files")
|
|
.upload(`${currentTenant.value}/${file.name}`, file, {upsert: upsert})
|
|
|
|
if (error) {
|
|
console.log(error)
|
|
console.log(error.statusCode)
|
|
|
|
if(error.statusCode === '400') {
|
|
console.log("is 400")
|
|
toast.add({title: "Hochladen fehlgeschlagen", description: "Die Datei enthält ungültige Zeichen", icon: "i-heroicons-x-circle", color: "rose", timeout: 10000})
|
|
} else if(error.statusCode === '409') {
|
|
console.log("is 409")
|
|
toast.add({title: "Hochladen fehlgeschlagen", description: "Es existiert bereits eine Datei mit diesem Namen", icon: "i-heroicons-x-circle", color: "rose", timeout: 10000})
|
|
} else {
|
|
toast.add({title: "Hochladen fehlgeschlagen", icon: "i-heroicons-x-circle", color: "rose", timeout: 10000})
|
|
|
|
}
|
|
|
|
} else if (data) {
|
|
const returnPath = data.path
|
|
|
|
documentsToInsert.push({...formData, path: returnPath, tenant: currentTenant.value})
|
|
}
|
|
|
|
//console.log(data)
|
|
}
|
|
|
|
//uploadInProgress.value = true
|
|
|
|
|
|
if(files.length === 1) {
|
|
await uploadSingleFile(files[0])
|
|
} else if( files.length > 1) {
|
|
|
|
for(let i = 0; i < files.length; i++){
|
|
await uploadSingleFile(files[i])
|
|
}
|
|
|
|
}
|
|
|
|
//console.log(documentsToInsert)
|
|
|
|
const {data, error} = await supabase
|
|
.from("documents")
|
|
.insert(documentsToInsert)
|
|
.select()
|
|
if(error) console.log(error)
|
|
else {
|
|
//console.log(data)
|
|
|
|
await fetchDocuments()
|
|
|
|
//documents.value.push(...data)
|
|
}
|
|
//uploadModalOpen.value = false;
|
|
//uploadInProgress.value = false;
|
|
|
|
|
|
}
|
|
|
|
async function fetchOwnTenant () {
|
|
ownTenant.value = (await supabase.from("tenants").select().eq('id', currentTenant.value).single()).data
|
|
}
|
|
|
|
async function fetchProfiles () {
|
|
profiles.value = (await supabase.from("profiles").select().eq("tenant",currentTenant.value).order("lastName")).data
|
|
}
|
|
|
|
async function fetchOwnProfiles () {
|
|
let profiles = (await supabase.from("profiles").select().order("fullName")).data
|
|
let conns = (await supabase.from("profileconnections").select()).data.map(i => i.profile_id)
|
|
//console.log(conns)
|
|
//console.log(profiles.filter(i => conns.includes(i.id)))
|
|
ownProfiles.value = profiles.filter(i => conns.includes(i.id))
|
|
}
|
|
|
|
async function fetchTenants () {
|
|
tenants.value = (await supabase.from("tenants").select()).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 fetchBankRequisitions () {
|
|
bankrequisitions.value = (await supabase.from("bankrequisitions").select().eq('status', "LN")).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 fetchWorkingTimes() {
|
|
workingtimes.value = (await supabase.from("workingtimes").select().eq('tenant', currentTenant.value).order('created_at', {ascending:true})).data
|
|
}
|
|
|
|
async function fetchPhasesTemplates() {
|
|
phasesTemplates.value = (await supabase.from("phasesTemplates").select().eq('tenant', currentTenant.value).order('created_at', {ascending:true})).data
|
|
}
|
|
|
|
async function fetchEmailAccounts() {
|
|
emailAccounts.value = (await supabase.from("emailAccounts").select().eq('tenant', currentTenant.value)).data
|
|
}
|
|
|
|
async function fetchTextTemplates() {
|
|
texttemplates.value = (await supabase.from("texttemplates").select().eq('tenant', currentTenant.value)).data
|
|
}
|
|
|
|
async function fetchServices() {
|
|
services.value = (await supabase.from("services").select().eq('tenant', currentTenant.value)).data
|
|
}
|
|
|
|
async function fetchServiceCategories() {
|
|
serviceCategories.value = (await supabase.from("serviceCategories").select().eq('tenant', currentTenant.value)).data
|
|
}
|
|
|
|
async function fetchResources() {
|
|
resources.value = (await supabase.from("resources").select().eq('tenant', currentTenant.value)).data
|
|
}
|
|
|
|
async function fetchDocuments () {
|
|
let tempDocuments = (await supabase.from("documents").select().eq('tenant', currentTenant.value)).data
|
|
|
|
if(tempDocuments.length > 0){
|
|
let paths = []
|
|
tempDocuments.forEach(doc => {
|
|
paths.push(doc.path)
|
|
})
|
|
|
|
const {data,error} = await supabase.storage.from('files').createSignedUrls(paths,3600)
|
|
|
|
tempDocuments = tempDocuments.map((doc,index) => {
|
|
|
|
return {
|
|
...doc,
|
|
url: data[index].signedUrl
|
|
}
|
|
})
|
|
|
|
documents.value = tempDocuments
|
|
} else {
|
|
documents.value = []
|
|
}
|
|
|
|
|
|
}
|
|
|
|
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(i => i.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 getProjectsByCustomerId = computed(() => (customerId) => {
|
|
return projects.value.filter(item => item.customer === customerId)
|
|
})
|
|
|
|
const getPlantsByCustomerId = computed(() => (customerId) => {
|
|
return plants.value.filter(item => item.customer === customerId)
|
|
})
|
|
|
|
const getContractsByCustomerId = computed(() => (customerId) => {
|
|
return contracts.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 && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
const getDocumentsByPlantId = computed(() => (itemId) => {
|
|
return documents.value.filter(item => item.plant === itemId && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
const getDocumentsByContractId = computed(() => (itemId) => {
|
|
return documents.value.filter(item => item.contract === itemId && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
const getDocumentsByVehicleId = computed(() => (itemId) => {
|
|
return documents.value.filter(item => item.vehicle === itemId && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
const getDocumentsByProductId = computed(() => (itemId) => {
|
|
return documents.value.filter(item => item.product === itemId && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
const getDocumentsByVendorId = computed(() => (itemId) => {
|
|
return documents.value.filter(item => item.vendor === itemId && !item.tags.includes("Archiviert"))
|
|
})
|
|
|
|
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 getTextTemplatesByDocumentType = computed(() => (documentType) => {
|
|
return texttemplates.value.filter(i => i.documentType === documentType)
|
|
})
|
|
|
|
const getCreatedDocumentsByProject = computed(() => (project) => {
|
|
return createddocuments.value.filter(i => i.project === project)
|
|
})
|
|
|
|
const getCreatedDocumentsByType = computed(() => (type) => {
|
|
return createddocuments.value.filter(i => i.type === type)
|
|
})
|
|
|
|
const getWorkingTimesByProfileId = computed(() => (profileId) => {
|
|
return workingtimes.value.filter(i => i.profile === profileId)
|
|
})
|
|
|
|
const getStartedWorkingTimes = computed(() => () => {
|
|
return workingtimes.value.filter(i => !i.endDate)
|
|
})
|
|
|
|
const getStockByProductId = computed(() => (productId) => {
|
|
let productMovements = movements.value.filter(movement => movement.productId === productId && movement.projectId === null)
|
|
|
|
let count = 0
|
|
|
|
productMovements.forEach(movement => {
|
|
count += movement.quantity
|
|
})
|
|
|
|
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
|
|
})
|
|
|
|
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.filter(i => i.tenant === currentTenant.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 getResourcesList = computed(() => {
|
|
return [
|
|
...profiles.value.filter(i => i.tenant === currentTenant.value).map(profile => {
|
|
return {
|
|
type: 'Mitarbeiter',
|
|
title: profile.fullName,
|
|
id: profile.id
|
|
}
|
|
}),
|
|
...vehicles.value.map(vehicle => {
|
|
return {
|
|
type: 'Fahrzeug',
|
|
title: vehicle.licensePlate,
|
|
id: vehicle.id
|
|
}
|
|
}),
|
|
...inventoryitems.value.filter(i=> i.usePlanning).map(item => {
|
|
return {
|
|
type: 'Inventar',
|
|
title: item.name,
|
|
id: 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 {
|
|
id: absence.id,
|
|
resourceId: absence.user,
|
|
resourceType: "person",
|
|
title: `Abw.: ${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 => {
|
|
console.log(event)
|
|
event.resources.forEach(resource => {
|
|
console.log(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: "Mitarbeiter",
|
|
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 {
|
|
id: absence.id,
|
|
resourceId: absence.user,
|
|
resourceType: "person",
|
|
title: `Abw.: ${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 getServiceById = computed(() => (itemId) => {
|
|
return services.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 getInventoryItemById = computed(() => (itemId) => {
|
|
return inventoryitems.value.find(item => item.id === itemId)
|
|
})
|
|
|
|
const getBankAccountById = computed(() => (itemId) => {
|
|
return bankAccounts.value.find(item => item.id === itemId)
|
|
})
|
|
|
|
const getEventById = computed(() => (itemId) => {
|
|
return events.value.find(item => item.id === itemId)
|
|
})
|
|
|
|
const getWorkingTimeById = computed(() => (itemId) => {
|
|
return workingtimes.value.find(item => item.id === itemId)
|
|
})
|
|
|
|
/*const getOpenDocuments = computed(() => (itemId) => {
|
|
|
|
let items = createddocuments.value.filter(i => i.type === "invoices" || i.type === "advanceInvoices")
|
|
items = items.filter(i => bankstatements.value.filter(x => x.assignments.find(y => y.type === 'createdDocument' && y.id === i.id)).length === 0)
|
|
|
|
/!*let finalItems = []
|
|
items.forEach(item => {
|
|
if(bankstatements.value.filter(i => i.assignments.find(x => x.id === item.id))){
|
|
finalItems.push(item)
|
|
}
|
|
|
|
})
|
|
|
|
return finalItems*!/
|
|
|
|
return items
|
|
|
|
//return createddocuments.value.filter(i => (i.type === "invoices" || i.type === "advanceInvoices") && !bankstatements.value.some(x => x.amount -))
|
|
|
|
})*/
|
|
const getOpenIncomingInvoices = computed(() => (itemId) => {
|
|
|
|
return incominginvoices.value.filter(i => bankstatements.value.filter(x => x.assignments.find(y => y.type === 'incomingInvoice' && y.id === i.id)).length === 0)
|
|
|
|
//return incominginvoices.value.filter(i => !i.paid)
|
|
|
|
})
|
|
|
|
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,
|
|
showProfileSelection,
|
|
ownTenant,
|
|
initializeData,
|
|
changeProfile,
|
|
uploadFiles,
|
|
hasRight,
|
|
generateHistoryItems,
|
|
|
|
//Data
|
|
profiles,
|
|
ownProfiles,
|
|
activeProfile,
|
|
tenants,
|
|
events,
|
|
customers,
|
|
tasks,
|
|
projects,
|
|
documents,
|
|
spaces,
|
|
units,
|
|
times,
|
|
products,
|
|
movements,
|
|
forms,
|
|
contracts,
|
|
formSubmits,
|
|
contacts,
|
|
vehicles,
|
|
vendors,
|
|
incominginvoices,
|
|
bankAccounts,
|
|
bankstatements,
|
|
bankrequisitions,
|
|
historyItems,
|
|
numberRanges,
|
|
notifications,
|
|
absencerequests,
|
|
accounts,
|
|
taxTypes,
|
|
plants,
|
|
inventoryitems,
|
|
chats,
|
|
messages,
|
|
createddocuments,
|
|
workingtimes,
|
|
phasesTemplates,
|
|
emailAccounts,
|
|
texttemplates,
|
|
services,
|
|
serviceCategories,
|
|
documentTypesForCreation,
|
|
|
|
//Functions
|
|
createNewItem,
|
|
updateItem,
|
|
fetchData,
|
|
clearStore,
|
|
fetchOwnTenant,
|
|
fetchProfiles,
|
|
fetchOwnProfiles,
|
|
fetchBankAccounts,
|
|
fetchBankStatements,
|
|
fetchBankRequisitions,
|
|
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,
|
|
fetchWorkingTimes,
|
|
addHistoryItem,
|
|
//Getters
|
|
getOpenTasksCount,
|
|
getOwnProfile,
|
|
getMovementsBySpace,
|
|
getContactsByCustomerId,
|
|
getProjectsByCustomerId,
|
|
getPlantsByCustomerId,
|
|
getContractsByCustomerId,
|
|
getContactsByVendorId,
|
|
getDocumentsByProjectId,
|
|
getDocumentsByPlantId,
|
|
getDocumentsByContractId,
|
|
getDocumentsByVehicleId,
|
|
getDocumentsByProductId,
|
|
getDocumentsByVendorId,
|
|
getEventsByProjectId,
|
|
getTimesByProjectId,
|
|
getTasksByProjectId,
|
|
getTasksByPlantId,
|
|
getProjectsByPlantId,
|
|
getMovementsBySpaceId,
|
|
getMessagesByChatId,
|
|
getTextTemplatesByDocumentType,
|
|
getCreatedDocumentsByProject,
|
|
getCreatedDocumentsByType,
|
|
getWorkingTimesByProfileId,
|
|
getStartedWorkingTimes,
|
|
getStockByProductId,
|
|
getStocksByProjectId,
|
|
getIncomingInvoicesByVehicleId,
|
|
getEventTypes,
|
|
getTimeTypes,
|
|
getDocumentTags,
|
|
getMeasures,
|
|
getResources,
|
|
getResourcesList,
|
|
getEvents,
|
|
getEventsByResource,
|
|
getCostCentresComposed,
|
|
getProductById,
|
|
getServiceById,
|
|
getVendorById,
|
|
getIncomingInvoiceById,
|
|
getContractById,
|
|
getContactById,
|
|
getVehicleById,
|
|
getDocumentById,
|
|
getSpaceById,
|
|
getCustomerById,
|
|
getTaskById,
|
|
getAbsenceRequestById,
|
|
getProjectById,
|
|
getProfileById,
|
|
getAccountById,
|
|
getPlantById,
|
|
getCreatedDocumentById,
|
|
getInventoryItemById,
|
|
getBankAccountById,
|
|
getEventById,
|
|
getWorkingTimeById,
|
|
//getOpenDocuments,
|
|
getOpenIncomingInvoices
|
|
}
|
|
|
|
|
|
}) |