Merge pull request 'HOTFix: bug and simplify' (!1440) from hotfix_double_ticketSale into master
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1440 Reviewed-by: Alex Moreno <alexm@verdnatura.es> Reviewed-by: Jon Elias <jon@verdnatura.es>
This commit is contained in:
commit
b2dab7ba59
|
@ -21,6 +21,10 @@ const $props = defineProps({
|
|||
type: String,
|
||||
default: 'mana',
|
||||
},
|
||||
sale: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['save', 'cancel']);
|
||||
|
@ -29,8 +33,8 @@ const { t } = useI18n();
|
|||
const QPopupProxyRef = ref(null);
|
||||
const manaCode = ref($props.manaCode);
|
||||
|
||||
const save = () => {
|
||||
emit('save');
|
||||
const save = (sale = $props.sale) => {
|
||||
emit('save', sale);
|
||||
QPopupProxyRef.value.hide();
|
||||
};
|
||||
|
||||
|
@ -38,6 +42,7 @@ const cancel = () => {
|
|||
emit('cancel');
|
||||
QPopupProxyRef.value.hide();
|
||||
};
|
||||
defineExpose({ save });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -22,7 +22,6 @@ import { useVnConfirm } from 'composables/useVnConfirm';
|
|||
import useNotify from 'src/composables/useNotify.js';
|
||||
import axios from 'axios';
|
||||
import VnTable from 'src/components/VnTable/VnTable.vue';
|
||||
import VnUsesMana from 'src/components/ui/VnUsesMana.vue';
|
||||
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||
import RightMenu from 'src/components/common/RightMenu.vue';
|
||||
|
||||
|
@ -32,6 +31,7 @@ const { t } = useI18n();
|
|||
const { notify } = useNotify();
|
||||
const { openConfirmationModal } = useVnConfirm();
|
||||
const editPriceProxyRef = ref(null);
|
||||
const editManaProxyRef = ref(null);
|
||||
const stateBtnDropdownRef = ref(null);
|
||||
const quasar = useQuasar();
|
||||
const arrayData = useArrayData('ticketData');
|
||||
|
@ -310,17 +310,20 @@ const updatePrice = async (sale) => {
|
|||
};
|
||||
|
||||
const changeDiscount = async (sale) => {
|
||||
canProceed.value = await isSalePrepared(sale);
|
||||
if (!canProceed.value) return;
|
||||
const newDiscount = edit.value.discount;
|
||||
if (newDiscount != null && newDiscount != sale.discount) updateDiscount([sale]);
|
||||
if (newDiscount != null && newDiscount != sale.discount) {
|
||||
if (isSalePrepared(sale))
|
||||
await confirmUpdate(() => updateDiscount([sale], newDiscount));
|
||||
}
|
||||
};
|
||||
|
||||
const updateDiscounts = async (sales, newDiscount = null) => {
|
||||
const someSaleIsPrepared = sales.some(isSalePrepared);
|
||||
if (someSaleIsPrepared);
|
||||
await confirmUpdate(() => updateDiscount(sales, newDiscount));
|
||||
};
|
||||
|
||||
const updateDiscount = async (sales, newDiscount = null) => {
|
||||
for (const sale of sales) {
|
||||
const canProceed = await isSalePrepared(sale);
|
||||
if (!canProceed) return;
|
||||
}
|
||||
const saleIds = sales.map((sale) => sale.id);
|
||||
const _newDiscount = newDiscount || edit.value.discount;
|
||||
const params = {
|
||||
|
@ -469,7 +472,19 @@ const endNewRow = (row) => {
|
|||
}
|
||||
};
|
||||
|
||||
async function isSalePrepared(item) {
|
||||
async function confirmUpdate(cb) {
|
||||
quasar
|
||||
.dialog({
|
||||
component: VnConfirm,
|
||||
componentProps: {
|
||||
title: t('Item prepared'),
|
||||
message: t('This item is already prepared. Do you want to continue?'),
|
||||
},
|
||||
})
|
||||
.onOk(cb);
|
||||
}
|
||||
|
||||
async function isSalePrepared(sale) {
|
||||
const filter = {
|
||||
params: {
|
||||
where: { ticketFk: route.params.id },
|
||||
|
@ -482,40 +497,17 @@ async function isSalePrepared(item) {
|
|||
},
|
||||
});
|
||||
|
||||
const matchingSale = data.find((sale) => sale.itemFk === item.itemFk);
|
||||
const matchingSale = data.find(({ itemFk }) => itemFk === sale.itemFk);
|
||||
if (!matchingSale) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
return (
|
||||
matchingSale.hasSaleGroupDetail ||
|
||||
matchingSale.isControled ||
|
||||
matchingSale.isPrepared ||
|
||||
matchingSale.isPrevious ||
|
||||
matchingSale.isPreviousSelected
|
||||
) {
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
quasar
|
||||
.dialog({
|
||||
component: VnConfirm,
|
||||
componentProps: {
|
||||
title: t('Item prepared'),
|
||||
message: t(
|
||||
'This item is already prepared. Do you want to continue?',
|
||||
),
|
||||
data: item,
|
||||
},
|
||||
})
|
||||
.onOk(() => resolve(true))
|
||||
.onCancel(() => reject(new Error('cancelled')));
|
||||
});
|
||||
} catch (error) {
|
||||
tableRef.value.reload();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
);
|
||||
}
|
||||
|
||||
watch(
|
||||
|
@ -583,7 +575,7 @@ watch(
|
|||
:mana="mana"
|
||||
:ticket-config="ticketConfig"
|
||||
@get-mana="getMana()"
|
||||
@update-discounts="updateDiscount"
|
||||
@update-discounts="updateDiscounts"
|
||||
@refresh-table="resetChanges"
|
||||
/>
|
||||
<QBtn
|
||||
|
@ -825,27 +817,23 @@ watch(
|
|||
<QBtn flat class="link" dense @click="onOpenEditDiscountPopover(row)">
|
||||
{{ toPercentage(row.discount / 100) }}
|
||||
</QBtn>
|
||||
|
||||
<TicketEditManaProxy
|
||||
ref="editManaProxyRef"
|
||||
:mana="mana"
|
||||
:sale="row"
|
||||
:new-price="getNewPrice"
|
||||
:uses-mana="usesMana"
|
||||
:mana-code="manaCode"
|
||||
@save="changeDiscount(row)"
|
||||
@save="changeDiscount"
|
||||
>
|
||||
<template #default="{ popup }">
|
||||
<VnInput
|
||||
autofocus
|
||||
@keyup.enter="
|
||||
() => {
|
||||
changeDiscount(row);
|
||||
popup.hide();
|
||||
}
|
||||
"
|
||||
v-model.number="edit.discount"
|
||||
:label="t('ticketSale.discount')"
|
||||
type="number"
|
||||
/>
|
||||
</template>
|
||||
<VnInput
|
||||
autofocus
|
||||
@keyup.enter.stop="() => editManaProxyRef.save(row)"
|
||||
v-model.number="edit.discount"
|
||||
:label="t('ticketSale.discount')"
|
||||
type="number"
|
||||
/>
|
||||
</TicketEditManaProxy>
|
||||
</template>
|
||||
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
||||
|
|
Loading…
Reference in New Issue