0
0
Fork 0

refactor: refs #6899 fix negativeBases call

This commit is contained in:
Jon Elias 2024-07-03 09:45:59 +02:00
parent 06f8121ede
commit 10f5323b9a
2 changed files with 28 additions and 53 deletions

View File

@ -1,41 +1,20 @@
<script setup> <script setup>
import { computed, ref, onBeforeMount } from 'vue'; import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
import { toCurrency } from 'src/filters'; import { toCurrency } from 'src/filters';
import VnTable from 'src/components/VnTable/VnTable.vue'; import VnTable from 'src/components/VnTable/VnTable.vue';
import { useInvoiceOutGlobalStore } from 'src/stores/invoiceOutGlobal.js'; import { useInvoiceOutGlobalStore } from 'src/stores/invoiceOutGlobal.js';
import { useArrayData } from 'src/composables/useArrayData'; import { useArrayData } from 'src/composables/useArrayData';
// import useStateStore from 'src/stores/useStateStore';
const { t } = useI18n(); const { t } = useI18n();
const tableRef = ref(); const tableRef = ref();
// const userFrom = Date.vnFirstDayOfMonth().toISOString();
// const userTo = Date.vnLastDayOfMonth().toISOString();
const invoiceOutGlobalStore = useInvoiceOutGlobalStore(); const invoiceOutGlobalStore = useInvoiceOutGlobalStore();
// const stateStore = useStateStore(); const userParams = {
const arrayData = useArrayData('InvoiceOutNegative', { from: Date.vnFirstDayOfMonth().toISOString(),
url: 'InvoiceOuts/negativeBases', to: Date.vnLastDayOfMonth().toISOString(),
limit: 0, };
userParams: { useArrayData('InvoiceOutNegative', { userParams });
from: Date.vnFirstDayOfMonth().toISOString(),
to: Date.vnLastDayOfMonth().toISOString(),
},
exprBuilder: (param, value) => {
switch (param) {
case 'from':
case 'to':
return;
default:
return { [param]: value };
}
},
});
onBeforeMount(async () => {
await arrayData.fetch({ append: false });
// stateStore.rightDrawer = true;
});
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -51,7 +30,7 @@ const columns = computed(() => [
}, },
columnField: { columnField: {
component: null, component: null,
} },
}, },
{ {
align: 'left', align: 'left',
@ -65,7 +44,7 @@ const columns = computed(() => [
}, },
columnField: { columnField: {
component: null, component: null,
} },
}, },
{ {
align: 'left', align: 'left',
@ -86,7 +65,7 @@ const columns = computed(() => [
}, },
columnField: { columnField: {
component: null, component: null,
} },
}, },
{ {
align: 'left', align: 'left',
@ -139,8 +118,6 @@ const columns = computed(() => [
]); ]);
const downloadCSV = async () => { const downloadCSV = async () => {
console.log('arrayData from: ', arrayData.store.userParams.from);
console.log('arrayData to: ', arrayData.store.userParams.to);
const filterParams = { const filterParams = {
limit: 20, limit: 20,
where: { where: {
@ -148,15 +125,15 @@ const downloadCSV = async () => {
}, },
}; };
for (const [key, value] of Object.entries(arrayData.store.userParams)) { for (const [key, value] of Object.entries(userParams)) {
if (value) { if (value) {
filterParams.where.and.push({ [key]: value }); filterParams.where.and.push({ [key]: value });
} }
}; }
await invoiceOutGlobalStore.getNegativeBasesCsv( await invoiceOutGlobalStore.getNegativeBasesCsv(
arrayData.store.userParams.from, userParams.from,
arrayData.store.userParams.to, userParams.to,
filterParams filterParams
); );
}; };
@ -171,30 +148,28 @@ const downloadCSV = async () => {
</VnSubToolbar> </VnSubToolbar>
<VnTable <VnTable
ref="tableRef" ref="tableRef"
data-key="invoiceOut" data-key="negativeFilter"
url="InvoiceOuts/negativeBases" url="InvoiceOuts/negativeBases"
:user-params="arrayData.store.userParams" :user-params="userParams"
:expr-builder="(param, value) => { :expr-builder="
switch (param) { (param, value) => {
case 'from': switch (param) {
case 'to': case 'from':
return; case 'to':
default: return;
return { [param]: value }; default:
return { [param]: value };
}
} }
}" "
:limit="0" :limit="0"
:columns="columns" :columns="columns"
default-mode="table" default-mode="table"
auto-load auto-load
:is-editable="false" :is-editable="false"
:use-model="true" :use-model="true"
:order="''"
> >
<!-- <template #moreBeforeActions>
<QBtn color="primary" icon-right="download" @click="downloadCSV()">
<QTooltip>{{ t('Download as CSV') }}</QTooltip>
</QBtn>
</template> -->
</VnTable> </VnTable>
</template> </template>

View File

@ -237,7 +237,7 @@ export const useInvoiceOutGlobalStore = defineStore({
async getNegativeBasesCsv() { async getNegativeBasesCsv() {
try { try {
const arrayData = useArrayData('InvoiceOutNegative'); const arrayData = useArrayData('InvoiceOutNegative');
const params = arrayData.store.currentFilter; const params = arrayData.store.userParams;
const { data } = await axios.get('InvoiceOuts/negativeBasesCsv', { const { data } = await axios.get('InvoiceOuts/negativeBasesCsv', {
params, params,