WIP: #7925 remove redirect #897
|
@ -13,7 +13,7 @@ const { t } = useI18n();
|
|||
const invoiceOutGlobalStore = useInvoiceOutGlobalStore();
|
||||
|
||||
// invoiceOutGlobalStore state and getters
|
||||
const { initialDataLoading, formInitialData, invoicing, status } =
|
||||
const { initialDataLoading, formInitialData, status } =
|
||||
storeToRefs(invoiceOutGlobalStore);
|
||||
|
||||
// invoiceOutGlobalStore actions
|
||||
|
@ -151,9 +151,8 @@ onMounted(async () => {
|
|||
rounded
|
||||
/>
|
||||
</div>
|
||||
|
||||
<QBtn
|
||||
v-if="!invoicing"
|
||||
v-if="!getStatus || getStatus === 'stopping'"
|
||||
:label="t('invoiceOut')"
|
||||
type="submit"
|
||||
color="primary"
|
||||
|
@ -163,7 +162,7 @@ onMounted(async () => {
|
|||
dense
|
||||
/>
|
||||
<QBtn
|
||||
v-if="invoicing"
|
||||
v-else
|
||||
:label="t('stop')"
|
||||
color="primary"
|
||||
class="q-mt-md full-width"
|
||||
|
|
|
@ -3,11 +3,12 @@ import { ref, computed } from 'vue';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
import VnTable from 'components/VnTable/VnTable.vue';
|
||||
import FetchData from 'src/components/FetchData.vue';
|
||||
const tableRef = ref();
|
||||
const payrollComponents = ref([]);
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const entityId = computed(() => route.params.id);
|
||||
|
||||
const columns = computed(() => [
|
||||
{
|
||||
align: 'left',
|
||||
|
@ -25,8 +26,9 @@ const columns = computed(() => [
|
|||
create: true,
|
||||
component: 'select',
|
||||
attrs: {
|
||||
url: 'payrollComponents',
|
||||
fields: ['id', 'name'],
|
||||
options: payrollComponents,
|
||||
optionLabel: 'name',
|
||||
optionValue: 'id',
|
||||
},
|
||||
cardVisible: true,
|
||||
},
|
||||
|
@ -73,6 +75,16 @@ const columns = computed(() => [
|
|||
]);
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
url="PayrollComponents"
|
||||
:filter="{
|
||||
fields: ['id', 'name'],
|
||||
where: { name: { neq: '' } },
|
||||
order: 'name ASC',
|
||||
}"
|
||||
@on-fetch="(data) => (payrollComponents = data)"
|
||||
auto-load
|
||||
/>
|
||||
<VnTable
|
||||
ref="tableRef"
|
||||
data-key="WorkerBalance"
|
||||
|
@ -94,6 +106,7 @@ const columns = computed(() => [
|
|||
:is-editable="true"
|
||||
:use-model="true"
|
||||
:default-remove="false"
|
||||
search-url="balance"
|
||||
/>
|
||||
</template>
|
||||
<i18n>
|
||||
|
|
|
@ -134,6 +134,7 @@ const columns = computed(() => [
|
|||
:is-editable="true"
|
||||
:use-model="true"
|
||||
:default-remove="false"
|
||||
search-url="formation"
|
||||
/>
|
||||
</template>
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -100,5 +100,6 @@ const columns = [
|
|||
:is-editable="true"
|
||||
:use-model="true"
|
||||
:default-remove="false"
|
||||
search-url="medical"
|
||||
/>
|
||||
</template>
|
||||
|
|
|
@ -71,6 +71,7 @@ function setNotifications(data) {
|
|||
:default-remove="false"
|
||||
:default-save="false"
|
||||
@on-fetch="setNotifications"
|
||||
search-url="notifications"
|
||||
>
|
||||
<template #body>
|
||||
<div
|
||||
|
|
|
@ -63,6 +63,7 @@ function reloadData() {
|
|||
url="DeviceProductionUsers"
|
||||
:filter="{ where: { userFk: routeId } }"
|
||||
order="id"
|
||||
search-url="pda"
|
||||
auto-load
|
||||
>
|
||||
<template #body="{ rows }">
|
||||
|
|
|
@ -93,7 +93,7 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
|
||||
async makeInvoice(formData, clientsToInvoice) {
|
||||
this.invoicing = true;
|
||||
this.status = 'packageInvoicing';
|
||||
const promises = [];
|
||||
try {
|
||||
this.printer = formData.printer;
|
||||
const params = {
|
||||
|
@ -118,10 +118,11 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
);
|
||||
throw new Error("There aren't addresses to invoice");
|
||||
}
|
||||
|
||||
for (const address of this.addresses) {
|
||||
await this.invoiceClient(address, formData);
|
||||
this.status = 'invoicing';
|
||||
for (let index = 0; index < this.parallelism; index++) {
|
||||
promises.push(this.invoiceClient(formData, index));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
} catch (err) {
|
||||
this.handleError(err);
|
||||
}
|
||||
|
@ -171,17 +172,14 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
}
|
||||
},
|
||||
|
||||
async invoiceClient(address, formData) {
|
||||
async invoiceClient(formData, index) {
|
||||
const address = this.addresses[index];
|
||||
if (!address || !this.status || this.status == 'stopping') {
|
||||
this.status = 'stopping';
|
||||
this.invoicing = false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (this.nRequests === this.parallelism || this.isInvoicing) return;
|
||||
|
||||
if (this.status === 'stopping') {
|
||||
if (this.nRequests) return;
|
||||
this.invoicing = false;
|
||||
this.status = 'done';
|
||||
return;
|
||||
}
|
||||
|
||||
const params = {
|
||||
clientId: address.clientId,
|
||||
addressId: address.id,
|
||||
|
@ -191,13 +189,11 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
serialType: formData.serialType,
|
||||
};
|
||||
|
||||
this.status = 'invoicing';
|
||||
this.invoicing = true;
|
||||
|
||||
const { data } = await axios.post('InvoiceOuts/invoiceClient', params);
|
||||
|
||||
if (data) await this.makePdfAndNotify(data, address);
|
||||
this.addressIndex++;
|
||||
this.isInvoicing = false;
|
||||
} catch (err) {
|
||||
if (err?.response?.status >= 400 && err?.response?.status < 500) {
|
||||
|
@ -205,13 +201,16 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
return;
|
||||
} else {
|
||||
this.invoicing = false;
|
||||
this.status = 'done';
|
||||
notify(
|
||||
'invoiceOut.globalInvoices.errors.criticalInvoiceError',
|
||||
'negative'
|
||||
);
|
||||
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) {
|
||||
this.invoicing = false;
|
||||
this.status = null;
|
||||
throw err;
|
||||
},
|
||||
|
||||
|
@ -279,7 +277,7 @@ export const useInvoiceOutGlobalStore = defineStore({
|
|||
return 0;
|
||||
}
|
||||
let porcentaje = (state.addressIndex / this.getNAddresses) * 100;
|
||||
return porcentaje;
|
||||
return porcentaje?.toFixed(2);
|
||||
},
|
||||
getAddressNumber(state) {
|
||||
return state.addressIndex;
|
||||
|
|
Loading…
Reference in New Issue