Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 6839-newUIMenu
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-11-07 12:50:54 +01:00
commit a12f1a9c81
7 changed files with 40 additions and 26 deletions

View File

@ -13,7 +13,7 @@ const { t } = useI18n();
const invoiceOutGlobalStore = useInvoiceOutGlobalStore(); const invoiceOutGlobalStore = useInvoiceOutGlobalStore();
// invoiceOutGlobalStore state and getters // invoiceOutGlobalStore state and getters
const { initialDataLoading, formInitialData, invoicing, status } = const { initialDataLoading, formInitialData, status } =
storeToRefs(invoiceOutGlobalStore); storeToRefs(invoiceOutGlobalStore);
// invoiceOutGlobalStore actions // invoiceOutGlobalStore actions
@ -151,9 +151,8 @@ onMounted(async () => {
rounded rounded
/> />
</div> </div>
<QBtn <QBtn
v-if="!invoicing" v-if="!getStatus || getStatus === 'stopping'"
:label="t('invoiceOut')" :label="t('invoiceOut')"
type="submit" type="submit"
color="primary" color="primary"
@ -163,7 +162,7 @@ onMounted(async () => {
dense dense
/> />
<QBtn <QBtn
v-if="invoicing" v-else
:label="t('stop')" :label="t('stop')"
color="primary" color="primary"
class="q-mt-md full-width" class="q-mt-md full-width"

View File

@ -3,11 +3,12 @@ import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import VnTable from 'components/VnTable/VnTable.vue'; import VnTable from 'components/VnTable/VnTable.vue';
import FetchData from 'src/components/FetchData.vue';
const tableRef = ref(); const tableRef = ref();
const payrollComponents = ref([]);
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const entityId = computed(() => route.params.id); const entityId = computed(() => route.params.id);
const columns = computed(() => [ const columns = computed(() => [
{ {
align: 'left', align: 'left',
@ -25,8 +26,9 @@ const columns = computed(() => [
create: true, create: true,
component: 'select', component: 'select',
attrs: { attrs: {
url: 'payrollComponents', options: payrollComponents,
fields: ['id', 'name'], optionLabel: 'name',
optionValue: 'id',
}, },
cardVisible: true, cardVisible: true,
}, },
@ -73,6 +75,16 @@ const columns = computed(() => [
]); ]);
</script> </script>
<template> <template>
<FetchData
url="PayrollComponents"
:filter="{
fields: ['id', 'name'],
where: { name: { neq: '' } },
order: 'name ASC',
}"
@on-fetch="(data) => (payrollComponents = data)"
auto-load
/>
<VnTable <VnTable
ref="tableRef" ref="tableRef"
data-key="WorkerBalance" data-key="WorkerBalance"
@ -94,6 +106,7 @@ const columns = computed(() => [
:is-editable="true" :is-editable="true"
:use-model="true" :use-model="true"
:default-remove="false" :default-remove="false"
search-url="balance"
/> />
</template> </template>
<i18n> <i18n>

View File

@ -134,6 +134,7 @@ const columns = computed(() => [
:is-editable="true" :is-editable="true"
:use-model="true" :use-model="true"
:default-remove="false" :default-remove="false"
search-url="formation"
/> />
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -100,5 +100,6 @@ const columns = [
:is-editable="true" :is-editable="true"
:use-model="true" :use-model="true"
:default-remove="false" :default-remove="false"
search-url="medical"
/> />
</template> </template>

View File

@ -71,6 +71,7 @@ function setNotifications(data) {
:default-remove="false" :default-remove="false"
:default-save="false" :default-save="false"
@on-fetch="setNotifications" @on-fetch="setNotifications"
search-url="notifications"
> >
<template #body> <template #body>
<div <div

View File

@ -63,6 +63,7 @@ function reloadData() {
url="DeviceProductionUsers" url="DeviceProductionUsers"
:filter="{ where: { userFk: routeId } }" :filter="{ where: { userFk: routeId } }"
order="id" order="id"
search-url="pda"
auto-load auto-load
> >
<template #body="{ rows }"> <template #body="{ rows }">

View File

@ -93,7 +93,7 @@ export const useInvoiceOutGlobalStore = defineStore({
async makeInvoice(formData, clientsToInvoice) { async makeInvoice(formData, clientsToInvoice) {
this.invoicing = true; this.invoicing = true;
this.status = 'packageInvoicing'; const promises = [];
try { try {
this.printer = formData.printer; this.printer = formData.printer;
const params = { const params = {
@ -118,10 +118,11 @@ export const useInvoiceOutGlobalStore = defineStore({
); );
throw new Error("There aren't addresses to invoice"); throw new Error("There aren't addresses to invoice");
} }
this.status = 'invoicing';
for (const address of this.addresses) { for (let index = 0; index < this.parallelism; index++) {
await this.invoiceClient(address, formData); promises.push(this.invoiceClient(formData, index));
} }
await Promise.all(promises);
} catch (err) { } catch (err) {
this.handleError(err); this.handleError(err);
} }
@ -171,17 +172,14 @@ export const useInvoiceOutGlobalStore = defineStore({
} }
}, },
async invoiceClient(address, formData) { async invoiceClient(formData, index) {
try { const address = this.addresses[index];
if (this.nRequests === this.parallelism || this.isInvoicing) return; if (!address || !this.status || this.status == 'stopping') {
this.status = 'stopping';
if (this.status === 'stopping') {
if (this.nRequests) return;
this.invoicing = false; this.invoicing = false;
this.status = 'done';
return; return;
} }
try {
const params = { const params = {
clientId: address.clientId, clientId: address.clientId,
addressId: address.id, addressId: address.id,
@ -191,13 +189,11 @@ export const useInvoiceOutGlobalStore = defineStore({
serialType: formData.serialType, serialType: formData.serialType,
}; };
this.status = 'invoicing';
this.invoicing = true; this.invoicing = true;
const { data } = await axios.post('InvoiceOuts/invoiceClient', params); const { data } = await axios.post('InvoiceOuts/invoiceClient', params);
if (data) await this.makePdfAndNotify(data, address); if (data) await this.makePdfAndNotify(data, address);
this.addressIndex++;
this.isInvoicing = false; this.isInvoicing = false;
} catch (err) { } catch (err) {
if (err?.response?.status >= 400 && err?.response?.status < 500) { if (err?.response?.status >= 400 && err?.response?.status < 500) {
@ -205,13 +201,16 @@ export const useInvoiceOutGlobalStore = defineStore({
return; return;
} else { } else {
this.invoicing = false; this.invoicing = false;
this.status = 'done';
notify( notify(
'invoiceOut.globalInvoices.errors.criticalInvoiceError', 'invoiceOut.globalInvoices.errors.criticalInvoiceError',
'negative' 'negative'
); );
throw new Error('Critical invoicing error, process stopped'); throw new Error('Critical invoicing error, process stopped');
} }
} finally {
this.addressIndex++;
if (this.status != 'stopping')
await this.invoiceClient(formData, this.addressIndex);
} }
}, },
@ -234,7 +233,6 @@ export const useInvoiceOutGlobalStore = defineStore({
handleError(err) { handleError(err) {
this.invoicing = false; this.invoicing = false;
this.status = null;
throw err; throw err;
}, },
@ -279,7 +277,7 @@ export const useInvoiceOutGlobalStore = defineStore({
return 0; return 0;
} }
let porcentaje = (state.addressIndex / this.getNAddresses) * 100; let porcentaje = (state.addressIndex / this.getNAddresses) * 100;
return porcentaje; return porcentaje?.toFixed(2);
}, },
getAddressNumber(state) { getAddressNumber(state) {
return state.addressIndex; return state.addressIndex;