diff --git a/src/pages/InvoiceOut/InvoiceOutList.vue b/src/pages/InvoiceOut/InvoiceOutList.vue index 7d19359d4..7bdf2ffbd 100644 --- a/src/pages/InvoiceOut/InvoiceOutList.vue +++ b/src/pages/InvoiceOut/InvoiceOutList.vue @@ -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'); } }; @@ -129,13 +126,14 @@ const downloadCsv = () => {