0
0
Fork 0

Invoice out list and summary changes

This commit is contained in:
William Buezas 2024-02-16 08:10:47 -03:00
parent af12512de9
commit 41e5110a8a
1 changed files with 34 additions and 35 deletions

View File

@ -2,7 +2,6 @@
import { onMounted, onUnmounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { exportFile, useQuasar } from 'quasar';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import InvoiceOutSummary from './Card/InvoiceOutSummary.vue';
@ -16,12 +15,14 @@ import InvoiceOutFilter from './InvoiceOutFilter.vue';
import { toDate, toCurrency } from 'src/filters/index';
import { useStateStore } from 'stores/useStateStore';
import { useSummaryDialog } from 'src/composables/useSummaryDialog';
import { useSession } from 'src/composables/useSession';
const { t } = useI18n();
const selectedCards = ref(new Map());
const quasar = useQuasar();
const router = useRouter();
const stateStore = useStateStore();
const session = useSession();
const token = session.getToken();
const { viewSummary } = useSummaryDialog();
onMounted(() => (stateStore.rightDrawer = true));
@ -55,35 +56,31 @@ const toggleAllCards = (cardsData) => {
}
};
const downloadCsv = () => {
if (selectedCards.value.size === 0) return;
const selectedCardsArray = Array.from(selectedCards.value.values());
let file;
for (var i = 0; i < selectedCardsArray.length; i++) {
if (i == 0) file += Object.keys(selectedCardsArray[i]).join(';') + '\n';
file +=
Object.keys(selectedCardsArray[i])
.map(function (key) {
return selectedCardsArray[i][key];
})
.join(';') + '\n';
}
const status = exportFile('file.csv', file, {
encoding: 'windows-1252',
mimeType: 'text/csv;charset=windows-1252;',
});
if (status === true) {
quasar.notify({
message: t('fileAllowed'),
color: 'positive',
icon: 'check',
});
} else {
quasar.notify({
message: t('fileDenied'),
color: 'negative',
icon: 'warning',
});
const openPdf = () => {
try {
if (selectedCards.value.size === 0) return;
const selectedCardsArray = Array.from(selectedCards.value.values());
if (selectedCards.value.size === 1) {
const [invoiceOut] = selectedCardsArray;
const url = `api/InvoiceOuts/${invoiceOut.id}/download?access_token=${token}`;
window.open(url, '_blank');
} else {
const invoiceOutIdsArray = selectedCardsArray.map(
(invoiceOut) => invoiceOut.id
);
const invoiceOutIds = invoiceOutIdsArray.join(',');
const params = new URLSearchParams({
access_token: token,
ids: invoiceOutIds,
});
const url = `api/InvoiceOuts/downloadZip?${params}`;
window.open(url, '_blank');
}
} catch (err) {
console.error('Error opening PDF');
}
};
</script>
@ -129,13 +126,14 @@ const downloadCsv = () => {
<VnSubToolbar class="bg-vn-dark justify-end">
<template #st-actions>
<QBtn
@click="downloadCsv()"
@click="openPdf()"
class="q-mr-xl"
color="primary"
:disable="selectedCards.size === 0"
:label="t('globals.download')"
/>
>
<QTooltip>{{ t('downloadPdf') }}</QTooltip>
</QBtn>
<QCheckbox
left-label
:label="t('globals.markAll')"
@ -167,7 +165,6 @@ const downloadCsv = () => {
:label="t('invoiceOut.list.amount')"
:value="toCurrency(row.amount)"
/>
<VnLv :label="t('invoiceOut.list.client')">
<template #value>
<span class="link" @click.stop>
@ -216,9 +213,11 @@ en:
fileDenied: Browser denied file download...
fileAllowed: Successful download of CSV file
youCanSearchByInvoiceReference: You can search by invoice reference
downloadPdf: Download PDF
es:
searchInvoice: Buscar factura emitida
fileDenied: El navegador denegó la descarga de archivos...
fileAllowed: Descarga exitosa de archivo CSV
youCanSearchByInvoiceReference: Puedes buscar por referencia de la factura
downloadPdf: Download PDF
</i18n>