feat: updates

This commit is contained in:
Javier Segarra 2025-04-11 12:30:37 +02:00
parent 37bc464a98
commit b32a889dfe
17 changed files with 83 additions and 57 deletions

View File

@ -44,7 +44,8 @@ onBeforeMount(async () => {
});
// It enables to load data only once if the module is the same as the dataKey
if (!isSameDataKey.value || !route.params.id) await getData();
if (!isSameDataKey.value || !route.params.id || $props.id !== route.params.id)
await getData();
watch(
() => [$props.url, $props.filter],
async () => {

View File

@ -19,6 +19,7 @@ globals:
logOut: Log out
date: Date
dataSaved: Data saved
openDetail: Open detail
dataDeleted: Data deleted
delete: Delete
search: Search

View File

@ -20,10 +20,11 @@ globals:
date: Fecha
dataSaved: Datos guardados
dataDeleted: Datos eliminados
dataCreated: Datos creados
openDetail: Ver detalle
delete: Eliminar
search: Buscar
changes: Cambios
dataCreated: Datos creados
add: Añadir
create: Crear
edit: Modificar

View File

@ -6,10 +6,12 @@ import { toCurrency } from 'filters/index';
import VnStockValueDisplay from 'src/components/ui/VnStockValueDisplay.vue';
import VnTable from 'src/components/VnTable/VnTable.vue';
import axios from 'axios';
import notifyResults from 'src/utils/notifyResults';
import { displayResults } from 'src/pages/Ticket/Negative/composables/notifyResults';
import FetchData from 'components/FetchData.vue';
import { useState } from 'src/composables/useState';
const MATCH = 'match';
const { notifyResults } = displayResults();
const { t } = useI18n();
const $props = defineProps({
@ -18,14 +20,20 @@ const $props = defineProps({
required: true,
default: () => {},
},
filter: {
type: Object,
required: true,
default: () => {},
},
replaceAction: {
type: Boolean,
required: false,
required: true,
default: false,
},
sales: {
type: Array,
required: false,
required: true,
default: () => [],
},
});
@ -36,6 +44,8 @@ const proposalTableRef = ref(null);
const sale = computed(() => $props.sales[0]);
const saleFk = computed(() => sale.value.saleFk);
const filter = computed(() => ({
where: $props.filter,
itemFk: $props.itemLack.itemFk,
sales: saleFk.value,
}));

View File

@ -1,13 +1,17 @@
<script setup>
import ItemProposal from './ItemProposal.vue';
import { useDialogPluginComponent } from 'quasar';
const $props = defineProps({
itemLack: {
type: Object,
required: true,
default: () => {},
},
filter: {
type: Object,
required: true,
default: () => {},
},
replaceAction: {
type: Boolean,
required: false,
@ -31,7 +35,7 @@ defineExpose({ show: () => dialogRef.value.show(), hide: () => dialogRef.value.h
<QDialog ref="dialogRef" transition-show="scale" transition-hide="scale">
<QCard class="dialog-width">
<QCardSection class="row items-center q-pb-none">
<span class="text-h6 text-grey">{{ $t('Item proposal') }}</span>
<span class="text-h6 text-grey">{{ $t('itemProposal') }}</span>
<QSpace />
<QBtn icon="close" flat round dense v-close-popup />
</QCardSection>

View File

@ -1,7 +1,6 @@
<script setup>
import TicketDescriptor from './TicketDescriptor.vue';
import TicketSummary from './TicketSummary.vue';
const $props = defineProps({
id: {
type: Number,

View File

@ -3,6 +3,8 @@ import { ref } from 'vue';
import VnInputDate from 'src/components/common/VnInputDate.vue';
import split from './components/split';
import { displayResults } from 'src/pages/Ticket/Negative/composables/notifyResults';
const { notifyResults } = displayResults();
const emit = defineEmits(['ticketTransferred']);
const $props = defineProps({
@ -16,7 +18,8 @@ const splitDate = ref(Date.vnNew());
const splitSelectedRows = async () => {
const tickets = Array.isArray($props.ticket) ? $props.ticket : [$props.ticket];
await split(tickets, splitDate.value);
const results = await split(tickets, splitDate.value);
notifyResults(results, 'ticketFk');
emit('ticketTransferred', tickets);
};
</script>

View File

@ -1,13 +1,11 @@
import axios from 'axios';
import notifyResults from 'src/utils/notifyResults';
export default async function (data, date) {
const reducedData = data.reduce((acc, item) => {
const existing = acc.find(({ ticketFk }) => ticketFk === item.id);
if (existing) {
existing.sales.push(item.saleFk);
} else {
acc.push({ ticketFk: item.id, sales: [item.saleFk], date });
acc.push({ ticketFk: item.ticketFk, sales: [item.saleFk], date });
}
return acc;
}, []);
@ -16,7 +14,5 @@ export default async function (data, date) {
const results = await Promise.allSettled(promises);
notifyResults(results, 'ticketFk');
return results;
}

View File

@ -23,7 +23,6 @@ const tableRef = ref();
const changeItemDialogRef = ref(null);
const changeStateDialogRef = ref(null);
const changeQuantityDialogRef = ref(null);
const showProposalDialog = ref(false);
const showChangeQuantityDialog = ref(false);
const selectedRows = ref([]);
const route = useRoute();
@ -63,6 +62,7 @@ const showItemProposal = () => {
.dialog({
component: ItemProposalProxy,
componentProps: {
filter: filter.value,
itemLack: tableRef.value.itemLack,
replaceAction: true,
sales: selectedRows.value,
@ -123,15 +123,11 @@ const showItemProposal = () => {
</QBtn>
<QBtn
color="primary"
@click="showProposalDialog = true"
@click="showItemProposal"
:disable="selectedRows.length < 1"
data-cy="itemProposal"
>
<QIcon
name="import_export"
class="rotate-90"
@click="showItemProposal"
></QIcon>
<QIcon name="import_export" class="rotate-90" />
<QTooltip bottom anchor="bottom right">
{{ t('itemProposal') }}
</QTooltip>

View File

@ -151,7 +151,6 @@ const saveChange = async (field, { row }) => {
fetchItemLack.value.fetch();
} catch (err) {
console.error('Error saving changes', err);
f;
}
};

View File

@ -2,7 +2,9 @@
import { ref } from 'vue';
import axios from 'axios';
import VnSelect from 'src/components/common/VnSelect.vue';
import notifyResults from 'src/utils/notifyResults';
import { displayResults } from 'src/pages/Ticket/Negative/composables/notifyResults';
const { notifyResults } = displayResults();
const emit = defineEmits(['update-item']);
const showChangeItemDialog = ref(false);
@ -37,7 +39,6 @@ const updateItem = async () => {
<template>
<QCard class="q-pa-sm">
<QCardSection class="row items-center justify-center column items-stretch">
{{ showChangeItemDialog }}
<span>{{ $t('negative.detail.modal.changeItem.title') }}</span>
<VnSelect
url="Items/WithName"

View File

@ -2,8 +2,9 @@
import { ref } from 'vue';
import axios from 'axios';
import VnInput from 'src/components/common/VnInput.vue';
import notifyResults from 'src/utils/notifyResults';
import { displayResults } from 'src/pages/Ticket/Negative/composables/notifyResults';
const { notifyResults } = displayResults();
const showChangeQuantityDialog = ref(false);
const newQuantity = ref(null);
const $props = defineProps({
@ -16,15 +17,16 @@ const emit = defineEmits(['update-quantity']);
const updateQuantity = async () => {
try {
showChangeQuantityDialog.value = true;
const rowsToUpdate = $props.selectedRows.map(({ saleFk }) =>
const rowsToUpdate = $props.selectedRows.map(({ saleFk, ticketFk }) =>
axios.post(`Sales/${saleFk}/updateQuantity`, {
saleFk,
ticketFk,
quantity: +newQuantity.value,
}),
);
const result = await Promise.allSettled(rowsToUpdate);
notifyResults(result, 'saleFk');
notifyResults(result, 'ticketFk');
emit('update-quantity', newQuantity.value);
} catch (err) {

View File

@ -3,8 +3,9 @@ import { ref } from 'vue';
import axios from 'axios';
import VnSelect from 'src/components/common/VnSelect.vue';
import FetchData from 'components/FetchData.vue';
import notifyResults from 'src/utils/notifyResults';
import { displayResults } from 'src/pages/Ticket/Negative/composables/notifyResults';
const { notifyResults } = displayResults();
const emit = defineEmits(['update-state']);
const editableStates = ref([]);
const showChangeStateDialog = ref(false);

View File

@ -0,0 +1,39 @@
import { Notify } from 'quasar';
import useOpenURL from 'src/composables/useOpenURL';
import { useI18n } from 'vue-i18n';
export function displayResults() {
const { t } = useI18n();
const notifyResults = (results, key, path = 'sale') =>
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
const data = JSON.parse(result.value.config.data);
if (result.value.data.status === 'noSplit') {
Notify.create({
type: 'warning',
message: `Ticket ${data[key]}: ${t('negative.split.noSplit')}`,
});
} else
Notify.create({
type: 'positive',
message: t('globals.dataSaved'),
actions: [
{
label: t('globals.openDetail'),
color: 'white',
handler: () => {
useOpenURL(`#/ticket/${data[key]}/${path}`);
},
},
],
});
} else {
const data = JSON.parse(result.reason.config.data);
Notify.create({
type: 'negative',
message: `Ticket ${data[key]}: ${result.reason.response?.data?.error?.message ?? result.reason.message}`,
});
}
});
return { notifyResults };
}

View File

@ -289,3 +289,4 @@ negative:
newTicket: New ticket
status: Result
message: Message
noSplit: No split

View File

@ -290,6 +290,7 @@ negative:
newTicket: Ticket nuevo
status: Estado
message: Mensaje
noSplit: No se puede splitar
rounding: Redondeo
noVerifiedData: Sin datos comprobados
purchaseRequest: Petición de compra

View File

@ -1,29 +0,0 @@
import { Notify } from 'quasar';
import useOpenURL from 'src/composables/useOpenURL';
export default function (results, key) {
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
const data = JSON.parse(result.value.config.data);
Notify.create({
type: 'positive',
message: `Operación (${index + 1}) ${data[key]} completada con éxito.`,
actions: [
{
label: 'Ver',
color: 'white',
handler: () => {
useOpenURL(`#/ticket/${data[key]}/summary`);
},
},
],
});
} else {
const data = JSON.parse(result.reason.config.data);
Notify.create({
type: 'negative',
message: `Operación (${index + 1}) ${data[key]} fallida: ${result.reason.message}`,
});
}
});
}