diff --git a/src/pages/Ecomerce/InvoicesView.vue b/src/pages/Ecomerce/InvoicesView.vue index 76599998..b89e28fa 100644 --- a/src/pages/Ecomerce/InvoicesView.vue +++ b/src/pages/Ecomerce/InvoicesView.vue @@ -8,9 +8,10 @@ import { currency, formatDate } from 'src/lib/filters.js'; import { usePrintService } from 'src/composables/usePrintService'; import { useAppStore } from 'stores/app'; import { storeToRefs } from 'pinia'; +import { onUserId } from 'src/utils/onUserId'; const { t } = useI18n(); -const jApi = inject('jApi'); +const api = inject('api'); const { openReport } = usePrintService(); const appStore = useAppStore(); const { isHeaderMounted } = storeToRefs(appStore); @@ -50,27 +51,38 @@ const columns = computed(() => [ } ]); -const fetchInvoices = async () => { - const params = { +const fetchInvoices = async clientFk => { + const { from, to } = { from: new Date(currentYear.value, 0), to: new Date(currentYear.value, 11, 31, 23, 59, 59) }; - invoices.value = await jApi.query( - `SELECT id, ref, issued, amount, hasPdf - FROM myInvoice - WHERE issued BETWEEN #from AND #to - ORDER BY issued DESC - LIMIT 100`, - params - ); + const filter = { + where: { + clientFk, + issued: { + between: [from, to] + } + }, + order: ['issued DESC'], + fields: ['id', 'ref', 'issued', 'amount', 'hasPdf'], + limit: 100 + }; + + const { data } = await api.get('InvoiceOuts', { + params: { + filter: JSON.stringify(filter) + } + }); + invoices.value = data; }; onMounted(async () => { - await fetchInvoices(); for (let year = currentYear.value - 5; year <= currentYear.value; year++) { years.value.push(year); } }); + +onUserId(fetchInvoices);