diff --git a/src/pages/Ticket/Card/TicketEditMana.vue b/src/pages/Ticket/Card/TicketEditMana.vue
index a55658a07..de9a982b9 100644
--- a/src/pages/Ticket/Card/TicketEditMana.vue
+++ b/src/pages/Ticket/Card/TicketEditMana.vue
@@ -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 });
diff --git a/src/pages/Ticket/Card/TicketSale.vue b/src/pages/Ticket/Card/TicketSale.vue
index 2cd20f1db..94d393900 100644
--- a/src/pages/Ticket/Card/TicketSale.vue
+++ b/src/pages/Ticket/Card/TicketSale.vue
@@ -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"
/>
{{ toPercentage(row.discount / 100) }}
+
-
- {
- changeDiscount(row);
- popup.hide();
- }
- "
- v-model.number="edit.discount"
- :label="t('ticketSale.discount')"
- type="number"
- />
-
+ editManaProxyRef.save(row)"
+ v-model.number="edit.discount"
+ :label="t('ticketSale.discount')"
+ type="number"
+ />
{{ toPercentage(row.discount / 100) }}