diff --git a/pages/incomingInvoices/[mode]/[[id]].vue b/pages/incomingInvoices/edit/[id].vue similarity index 69% rename from pages/incomingInvoices/[mode]/[[id]].vue rename to pages/incomingInvoices/edit/[id].vue index eb71ff4..b8a8205 100644 --- a/pages/incomingInvoices/[mode]/[[id]].vue +++ b/pages/incomingInvoices/edit/[id].vue @@ -14,23 +14,6 @@ const route = useRoute() const router = useRouter() const toast = useToast() -const availableDocuments = ref([]) -const setup = async () => { - let filetype = (await supabase.from("filetags").select().eq("tenant",profileStore.currentTenant).eq("incomingDocumentType","invoices").single()).data.id - console.log(filetype) - let ids = (await supabase.from("files").select("id").eq("tenant",profileStore.currentTenant).eq("type", filetype)).data.map(i => i.id) - availableDocuments.value = await useFiles().selectSomeDocuments(ids) - -} - -setup() - - -//let currentDocument = ref(null) -//Working -const mode = ref(route.params.mode || "show") -const useNetMode = ref(false) - const itemInfo = ref({ vendor: 0, expense: true, @@ -51,28 +34,28 @@ const itemInfo = ref({ ] }) +const setup = async () => { + let filetype = (await supabase.from("filetags").select().eq("tenant",profileStore.currentTenant).eq("incomingDocumentType","invoices").single()).data.id + console.log(filetype) - - -//Functions -const setupPage = async () => { - if((mode.value === "show" || mode.value === "edit" ) && route.params.id){ - itemInfo.value = await useSupabaseSelectSingle("incominginvoices",route.params.id) - //currentDocument.value = await dataStore.getDocumentById(currentVendorInvoice.value.document) - } - console.log(itemInfo.value) + itemInfo.value = await useSupabaseSelectSingle("incominginvoices", route.params.id, "*, files(*)") + await loadFile(itemInfo.value.files[itemInfo.value.files.length-1].id) } -const currentDocument = computed(() => { - if(itemInfo.value) { - return dataStore.getDocumentById(itemInfo.value.document) +setup() + +const useNetMode = ref(false) + +const loadedFile = ref(null) +const loadFile = async (id) => { + console.log(id) + loadedFile.value = await useFiles().selectDocument(id) + console.log(loadedFile.value) +} + - } else { - return null - } -}) const changeNetMode = (mode) => { useNetMode.value = mode @@ -137,117 +120,42 @@ const totalCalculated = computed(() => { }) -const setState = async (newState) => { - if(mode.value === 'show') { - await dataStore.updateItem('incominginvoices',{...itemInfo.value, state: newState}) - } else if(mode.value === 'edit') { - await dataStore.updateItem('incominginvoices',{...itemInfo.value, state: newState}) - } - await router.push("/incomingInvoices") +const updateIncomingInvoice = async () => { + + let item = itemInfo.value + delete item.files + + const data = await dataStore.updateItem('incominginvoices',item) } - -setupPage()