feat: refs #6696 refactor ticketSale
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
d790907e79
commit
b28835b126
|
@ -123,8 +123,8 @@ async function fetchMana() {
|
||||||
|
|
||||||
async function updateDiscount({ saleFk, discount, canceller }) {
|
async function updateDiscount({ saleFk, discount, canceller }) {
|
||||||
const body = { salesIds: [saleFk], newDiscount: discount };
|
const body = { salesIds: [saleFk], newDiscount: discount };
|
||||||
const claimId = claim.value.ticketFk;
|
const ticketFk = claim.value.ticketFk;
|
||||||
const query = `Tickets/${claimId}/updateDiscount`;
|
const query = `Tickets/${ticketFk}/updateDiscount`;
|
||||||
|
|
||||||
await axios.post(query, body, {
|
await axios.post(query, body, {
|
||||||
signal: canceller.signal,
|
signal: canceller.signal,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onBeforeMount } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { toCurrency } from 'src/filters';
|
import { toCurrency } from 'src/filters';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
@ -13,7 +13,7 @@ const $props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['save', 'cancel']);
|
const emit = defineEmits(['save', 'cancel', 'show']);
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const QPopupProxyRef = ref(null);
|
const QPopupProxyRef = ref(null);
|
||||||
|
@ -31,23 +31,21 @@ const cancel = () => {
|
||||||
QPopupProxyRef.value.hide();
|
QPopupProxyRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
async function onShow() {
|
||||||
try {
|
const { data: manaData } = await axios.get(
|
||||||
const { data: manaData } = await axios.get(
|
`Tickets/${route.params.id}/getSalesPersonMana`
|
||||||
`Tickets/${route.params.id}/getSalesPersonMana`
|
);
|
||||||
);
|
mana.value = manaData;
|
||||||
mana.value = manaData;
|
|
||||||
|
|
||||||
const { data: usesManaData } = await axios.get('Sales/usesMana');
|
const { data: usesManaData } = await axios.get('Sales/usesMana');
|
||||||
usesMana.value = usesManaData;
|
usesMana.value = usesManaData;
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching mana data:', error);
|
emit('show');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<QPopupProxy ref="QPopupProxyRef">
|
<QPopupProxy ref="QPopupProxyRef" @show="onShow()">
|
||||||
<QForm @submit="save">
|
<QForm @submit="save">
|
||||||
<div>
|
<div>
|
||||||
<QSpinner v-if="!mana" color="primary" size="md" />
|
<QSpinner v-if="!mana" color="primary" size="md" />
|
||||||
|
|
|
@ -8,7 +8,7 @@ import FetchedTags from 'components/ui/FetchedTags.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||||
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
|
import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
|
||||||
import TicketEditManaProxy from './TicketEditMana.vue';
|
import TicketEditMana from './TicketEditMana.vue';
|
||||||
import VnImg from 'src/components/ui/VnImg.vue';
|
import VnImg from 'src/components/ui/VnImg.vue';
|
||||||
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
||||||
import TicketSaleMoreActions from './TicketSaleMoreActions.vue';
|
import TicketSaleMoreActions from './TicketSaleMoreActions.vue';
|
||||||
|
@ -28,7 +28,6 @@ const stateStore = useStateStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
const editPriceProxyRef = ref(null);
|
|
||||||
const stateBtnDropdownRef = ref(null);
|
const stateBtnDropdownRef = ref(null);
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
const arrayData = useArrayData('ticketData');
|
const arrayData = useArrayData('ticketData');
|
||||||
|
@ -41,7 +40,6 @@ const isTicketEditable = ref(false);
|
||||||
const sales = ref([]);
|
const sales = ref([]);
|
||||||
const editableStatesOptions = ref([]);
|
const editableStatesOptions = ref([]);
|
||||||
const selectedSales = ref([]);
|
const selectedSales = ref([]);
|
||||||
const componentName = ref('mana');
|
|
||||||
const ticketState = computed(() => store.data?.ticketState?.state?.code);
|
const ticketState = computed(() => store.data?.ticketState?.state?.code);
|
||||||
const transfer = ref({
|
const transfer = ref({
|
||||||
lastActiveTickets: [],
|
lastActiveTickets: [],
|
||||||
|
@ -132,7 +130,7 @@ const columns = computed(() => [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: t('ticketSale.packaging'),
|
label: t('ticketSale.pack'),
|
||||||
name: 'itemPackingTypeFk',
|
name: 'itemPackingTypeFk',
|
||||||
format: (row, dashIfEmpty) => dashIfEmpty(row?.item?.itemPackingTypeFk),
|
format: (row, dashIfEmpty) => dashIfEmpty(row?.item?.itemPackingTypeFk),
|
||||||
},
|
},
|
||||||
|
@ -259,7 +257,7 @@ const onOpenEditPricePopover = async (sale) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const onOpenEditDiscountPopover = async (sale) => {
|
const onDiscountClick = async (sale) => {
|
||||||
if (isLocked.value) return;
|
if (isLocked.value) return;
|
||||||
if (sale) {
|
if (sale) {
|
||||||
edit.value = {
|
edit.value = {
|
||||||
|
@ -268,46 +266,36 @@ const onOpenEditDiscountPopover = async (sale) => {
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
edit.value = {
|
edit.value = {
|
||||||
|
sales: selectedValidSales.value || [],
|
||||||
discount: null,
|
discount: null,
|
||||||
sales: selectedValidSales.value,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatePrice = async (sale) => {
|
const updatePrice = async (sale, componentName) => {
|
||||||
canProceed.value = await isSalePrepared(sale);
|
canProceed.value = await isSalePrepared(sale);
|
||||||
if (!canProceed.value) return;
|
if (!canProceed.value) return;
|
||||||
const newPrice = edit.value.price;
|
const newPrice = edit.value.price;
|
||||||
if (newPrice != null && newPrice != sale.price) {
|
if (newPrice != null && newPrice != sale.price) {
|
||||||
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
|
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice, componentName });
|
||||||
sale.price = newPrice;
|
sale.price = newPrice;
|
||||||
edit.value = { ...DEFAULT_EDIT };
|
edit.value = { ...DEFAULT_EDIT };
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeDiscount = async (sale) => {
|
const updateDiscount = async (sales, componentName, newDiscount) => {
|
||||||
canProceed.value = await isSalePrepared(sale);
|
const hasChanges = sales.some((sale) => sale.discount != newDiscount);
|
||||||
if (!canProceed.value) return;
|
if (!hasChanges || newDiscount == null || newDiscount === '') return;
|
||||||
const newDiscount = edit.value.discount;
|
const canProceed = await Promise.all(sales.map((sale) => isSalePrepared(sale)));
|
||||||
if (newDiscount != null && newDiscount != sale.discount) await updateDiscount([sale]);
|
if (canProceed.includes(false)) return;
|
||||||
};
|
|
||||||
|
|
||||||
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 saleIds = sales.map((sale) => sale.id);
|
||||||
const _newDiscount = newDiscount || edit.value.discount;
|
const params = { salesIds: saleIds, newDiscount, componentName };
|
||||||
const params = {
|
|
||||||
salesIds: saleIds,
|
|
||||||
newDiscount: _newDiscount,
|
|
||||||
componentName: componentName.value,
|
|
||||||
};
|
|
||||||
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
|
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
|
||||||
notify('globals.dataSaved', 'positive');
|
notify('globals.dataSaved', 'positive');
|
||||||
for (let sale of sales) sale.discount = _newDiscount;
|
for (let sale of sales) sale.discount = params.newDiscount;
|
||||||
edit.value = { ...DEFAULT_EDIT };
|
edit.value = { ...DEFAULT_EDIT };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -769,51 +757,44 @@ watch(
|
||||||
</template>
|
</template>
|
||||||
<template #column-price="{ row }">
|
<template #column-price="{ row }">
|
||||||
<template v-if="isTicketEditable && row.id">
|
<template v-if="isTicketEditable && row.id">
|
||||||
<QBtn flat class="link" dense @click="onOpenEditPricePopover(row)">
|
<QBtn flat class="link" dense>
|
||||||
{{ toCurrency(row.price) }}
|
{{ toCurrency(row.price) }}
|
||||||
|
<TicketEditMana
|
||||||
|
:new-price="getNewPrice"
|
||||||
|
@show="onOpenEditPricePopover(row)"
|
||||||
|
@save="(componentName) => updatePrice(row, componentName)"
|
||||||
|
>
|
||||||
|
<VnInput
|
||||||
|
v-model.number="edit.price"
|
||||||
|
:label="t('basicData.price')"
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
</TicketEditMana>
|
||||||
</QBtn>
|
</QBtn>
|
||||||
|
|
||||||
<TicketEditManaProxy
|
|
||||||
ref="editPriceProxyRef"
|
|
||||||
:new-price="getNewPrice"
|
|
||||||
@save="
|
|
||||||
(newManaCode) => {
|
|
||||||
componentName = newManaCode;
|
|
||||||
updatePrice(row);
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<VnInput
|
|
||||||
v-model.number="edit.price"
|
|
||||||
:label="t('basicData.price')"
|
|
||||||
type="number"
|
|
||||||
/>
|
|
||||||
</TicketEditManaProxy>
|
|
||||||
</template>
|
</template>
|
||||||
<span v-else>{{ toCurrency(row.price) }}</span>
|
<span v-else>{{ toCurrency(row.price) }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #column-discount="{ row }">
|
<template #column-discount="{ row }">
|
||||||
<template v-if="!isLocked && row.id">
|
<template v-if="!isLocked && row.id">
|
||||||
<QBtn flat class="link" dense @click="onOpenEditDiscountPopover(row)">
|
<QBtn flat class="link" dense>
|
||||||
{{ toPercentage(row.discount / 100) }}
|
{{ toPercentage(row.discount / 100) }}
|
||||||
|
<TicketEditMana
|
||||||
|
:new-price="getNewPrice"
|
||||||
|
@show="onDiscountClick(row)"
|
||||||
|
@save="
|
||||||
|
(componentName) =>
|
||||||
|
updateDiscount([row], componentName, edit.discount)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<VnInput
|
||||||
|
v-model.number="edit.discount"
|
||||||
|
:label="t('ticketSale.discount')"
|
||||||
|
type="number"
|
||||||
|
@keydown.enter.prevent.stop
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
</TicketEditMana>
|
||||||
</QBtn>
|
</QBtn>
|
||||||
<TicketEditManaProxy
|
|
||||||
:new-price="getNewPrice"
|
|
||||||
@save="
|
|
||||||
(newManaCode) => {
|
|
||||||
componentName = newManaCode;
|
|
||||||
changeDiscount(row);
|
|
||||||
}
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<VnInput
|
|
||||||
v-model.number="edit.discount"
|
|
||||||
:label="t('ticketSale.discount')"
|
|
||||||
type="number"
|
|
||||||
@keydown.enter.prevent.stop
|
|
||||||
autofocus
|
|
||||||
/>
|
|
||||||
</TicketEditManaProxy>
|
|
||||||
</template>
|
</template>
|
||||||
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useQuasar } from 'quasar';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import VnSmsDialog from 'components/common/VnSmsDialog.vue';
|
import VnSmsDialog from 'components/common/VnSmsDialog.vue';
|
||||||
import TicketEditManaProxy from './TicketEditMana.vue';
|
import TicketEditMana from './TicketEditMana.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
import useNotify from 'src/composables/useNotify.js';
|
import useNotify from 'src/composables/useNotify.js';
|
||||||
|
@ -14,7 +14,7 @@ import { toDateFormat } from 'src/filters/date';
|
||||||
import { useRole } from 'src/composables/useRole';
|
import { useRole } from 'src/composables/useRole';
|
||||||
import { useVnConfirm } from 'composables/useVnConfirm';
|
import { useVnConfirm } from 'composables/useVnConfirm';
|
||||||
|
|
||||||
const emit = defineEmits(['updateDiscounts', 'getMana', 'refreshTable']);
|
const emit = defineEmits(['updateDiscounts', 'refreshTable']);
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
disable: {
|
disable: {
|
||||||
|
@ -34,14 +34,6 @@ const props = defineProps({
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
mana: {
|
|
||||||
type: Number,
|
|
||||||
default: null,
|
|
||||||
},
|
|
||||||
usesMana: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
ticketConfig: {
|
ticketConfig: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
|
@ -114,13 +106,9 @@ const calculateSalePrice = async () => {
|
||||||
emit('refreshTable', props.sales);
|
emit('refreshTable', props.sales);
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeMultipleDiscount = () => {
|
const changeMultipleDiscount = (componentName, newDiscount) => {
|
||||||
const hasChanges = props.sales.some((sale) => {
|
if (newDiscount != null)
|
||||||
return sale.discount != newDiscount.value;
|
emit('updateDiscounts', props.sales, componentName, newDiscount);
|
||||||
});
|
|
||||||
|
|
||||||
if (newDiscount.value != null && hasChanges)
|
|
||||||
emit('updateDiscounts', props.sales, newDiscount.value);
|
|
||||||
btnDropdownRef.value.hide();
|
btnDropdownRef.value.hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,19 +197,15 @@ const createRefund = async (withWarehouse) => {
|
||||||
<QItemLabel>{{ t('Recalculate price') }}</QItemLabel>
|
<QItemLabel>{{ t('Recalculate price') }}</QItemLabel>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem
|
<QItem clickable v-ripple data-cy="updateDiscountItem">
|
||||||
clickable
|
|
||||||
v-ripple
|
|
||||||
@click="emit('getMana')"
|
|
||||||
data-cy="updateDiscountItem"
|
|
||||||
>
|
|
||||||
<QItemSection>
|
<QItemSection>
|
||||||
<QItemLabel>{{ t('Update discount') }}</QItemLabel>
|
<QItemLabel>{{ t('Update discount') }}</QItemLabel>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
<TicketEditManaProxy
|
<TicketEditMana
|
||||||
:uses-mana="props.usesMana"
|
@save="
|
||||||
:mana="props.mana"
|
(componentName) =>
|
||||||
@save="changeMultipleDiscount()"
|
changeMultipleDiscount(componentName, newDiscount)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<VnInput
|
<VnInput
|
||||||
v-model.number="newDiscount"
|
v-model.number="newDiscount"
|
||||||
|
@ -229,7 +213,7 @@ const createRefund = async (withWarehouse) => {
|
||||||
type="number"
|
type="number"
|
||||||
data-cy="ticketSaleDiscountInput"
|
data-cy="ticketSaleDiscountInput"
|
||||||
/>
|
/>
|
||||||
</TicketEditManaProxy>
|
</TicketEditMana>
|
||||||
</QItem>
|
</QItem>
|
||||||
<QItem
|
<QItem
|
||||||
v-if="isClaimable"
|
v-if="isClaimable"
|
||||||
|
|
|
@ -15,6 +15,7 @@ ticketSale:
|
||||||
available: Available
|
available: Available
|
||||||
discount: Disc
|
discount: Disc
|
||||||
packaging: Packaging
|
packaging: Packaging
|
||||||
|
pack: Pack.
|
||||||
subtotal: Subtotal
|
subtotal: Subtotal
|
||||||
tax: VAT
|
tax: VAT
|
||||||
history: History
|
history: History
|
||||||
|
|
|
@ -116,6 +116,7 @@ ticketSale:
|
||||||
available: Disponible
|
available: Disponible
|
||||||
discount: Dto
|
discount: Dto
|
||||||
packaging: Encajado
|
packaging: Encajado
|
||||||
|
pack: Enc.
|
||||||
subtotal: Subtotal
|
subtotal: Subtotal
|
||||||
tax: IVA
|
tax: IVA
|
||||||
history: Historial
|
history: Historial
|
||||||
|
|
Loading…
Reference in New Issue