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

View File

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