diff --git a/frontend/pages/accounting/cashbooks.vue b/frontend/pages/accounting/cashbooks/[id].vue similarity index 81% rename from frontend/pages/accounting/cashbooks.vue rename to frontend/pages/accounting/cashbooks/[id].vue index 0ae937d..02b832f 100644 --- a/frontend/pages/accounting/cashbooks.vue +++ b/frontend/pages/accounting/cashbooks/[id].vue @@ -2,9 +2,10 @@ import dayjs from "dayjs" const toast = useToast() +const route = useRoute() +const router = useRouter() const loading = ref(true) -const savingCashbook = ref(false) const savingBooking = ref(false) const cashbooks = ref([]) const bookings = ref([]) @@ -13,7 +14,7 @@ const customers = ref([]) const vendors = ref([]) const ownaccounts = ref([]) const incomingInvoices = ref([]) -const selectedCashbookId = ref(null) +const selectedCashbookId = computed(() => Number(route.params.id)) const counterSearch = ref("") const expandedGroups = ref([]) @@ -25,12 +26,6 @@ const DATEV_TAX_KEY_ITEMS = [ { value: "18", label: "18 - EU Vorsteuer 7 %" } ] -const newCashbook = reactive({ - name: "", - datevNumber: "1000", - openingBalance: 0 -}) - const form = reactive({ date: dayjs().format("YYYY-MM-DD"), direction: "expense", @@ -168,7 +163,7 @@ const getBookingCounter = (booking) => { } const loadBookings = async () => { - if (!selectedCashbookId.value) { + if (!selectedCashbookId.value || !Number.isFinite(selectedCashbookId.value)) { bookings.value = [] return } @@ -196,41 +191,10 @@ const loadData = async () => { .filter((invoice) => invoice.state === "Gebucht" && !invoice.archived) .filter((invoice) => getIncomingInvoiceOpenAmount(invoice) > 0.004) - if (!selectedCashbookId.value && cashbooks.value.length > 0) { - selectedCashbookId.value = cashbooks.value[0].id - } - await loadBookings() loading.value = false } -const createCashbook = async () => { - if (!newCashbook.name || !newCashbook.datevNumber) { - toast.add({ title: "Bitte Bezeichnung und Kontennummer ausfüllen.", color: "warning" }) - return - } - - savingCashbook.value = true - try { - const created = await useNuxtApp().$api("/api/banking/cashbooks", { - method: "POST", - body: { - name: newCashbook.name, - datevNumber: newCashbook.datevNumber, - openingBalance: Number(newCashbook.openingBalance || 0) - } - }) - toast.add({ title: "Barkasse erstellt." }) - newCashbook.name = "" - newCashbook.datevNumber = "1000" - newCashbook.openingBalance = 0 - await loadData() - selectedCashbookId.value = created.id - } finally { - savingCashbook.value = false - } -} - const saveBooking = async () => { if (!selectedCashbookId.value || !form.date || !form.amount || !form.counter) { toast.add({ title: "Bitte Kasse, Datum, Betrag und Gegenkonto auswählen.", color: "warning" }) @@ -271,69 +235,21 @@ const deleteBooking = async (booking) => { await loadBookings() } -watch(selectedCashbookId, loadBookings) - onMounted(loadData) diff --git a/frontend/pages/accounting/cashbooks/index.vue b/frontend/pages/accounting/cashbooks/index.vue new file mode 100644 index 0000000..ba0c1d3 --- /dev/null +++ b/frontend/pages/accounting/cashbooks/index.vue @@ -0,0 +1,165 @@ + + +