feat: refactor canProceed
gitea/salix-front/pipeline/pr-master This commit looks good
Details
gitea/salix-front/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
b2dab7ba59
commit
874fbb48f5
|
@ -48,6 +48,7 @@ globals:
|
|||
rowRemoved: Row removed
|
||||
pleaseWait: Please wait...
|
||||
noPinnedModules: You don't have any pinned modules
|
||||
enterToConfirm: Press Enter to confirm
|
||||
summary:
|
||||
basicData: Basic data
|
||||
daysOnward: Days onward
|
||||
|
|
|
@ -48,6 +48,7 @@ globals:
|
|||
rowRemoved: Fila eliminada
|
||||
pleaseWait: Por favor espera...
|
||||
noPinnedModules: No has fijado ningún módulo
|
||||
enterToConfirm: Pulsa Enter para confirmar
|
||||
summary:
|
||||
basicData: Datos básicos
|
||||
daysOnward: Días adelante
|
||||
|
|
|
@ -52,7 +52,6 @@ const transfer = ref({
|
|||
sales: [],
|
||||
});
|
||||
const tableRef = ref([]);
|
||||
const canProceed = ref();
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
|
@ -132,7 +131,6 @@ const columns = computed(() => [
|
|||
align: 'left',
|
||||
label: t('globals.amount'),
|
||||
name: 'amount',
|
||||
format: (row) => toCurrency(getSaleTotal(row)),
|
||||
},
|
||||
{
|
||||
align: 'left',
|
||||
|
@ -182,8 +180,6 @@ const resetChanges = async () => {
|
|||
};
|
||||
const rowToUpdate = ref(null);
|
||||
const changeQuantity = async (sale) => {
|
||||
canProceed.value = await isSalePrepared(sale);
|
||||
if (!canProceed.value) return;
|
||||
if (
|
||||
!sale.itemFk ||
|
||||
sale.quantity == null ||
|
||||
|
@ -192,11 +188,21 @@ const changeQuantity = async (sale) => {
|
|||
return;
|
||||
if (!sale.id) return addSale(sale);
|
||||
|
||||
if (await isSalePrepared(sale)) {
|
||||
await confirmUpdate(() => updateQuantity(sale));
|
||||
} else await updateQuantity(sale);
|
||||
};
|
||||
|
||||
const updateQuantity = async (sale) => {
|
||||
try {
|
||||
let { quantity, id } = sale;
|
||||
if (!rowToUpdate.value) return;
|
||||
rowToUpdate.value = null;
|
||||
sale.isNew = false;
|
||||
await updateQuantity(sale);
|
||||
const params = { quantity: quantity };
|
||||
await axios.post(`Sales/${id}/updateQuantity`, params);
|
||||
notify('globals.dataSaved', 'positive');
|
||||
tableRef.value.reload();
|
||||
} catch (e) {
|
||||
const { quantity } = tableRef.value.CrudModelRef.originalData.find(
|
||||
(s) => s.id === sale.id,
|
||||
|
@ -206,12 +212,6 @@ const changeQuantity = async (sale) => {
|
|||
}
|
||||
};
|
||||
|
||||
const updateQuantity = async ({ quantity, id }) => {
|
||||
const params = { quantity: quantity };
|
||||
await axios.post(`Sales/${id}/updateQuantity`, params);
|
||||
notify('globals.dataSaved', 'positive');
|
||||
};
|
||||
|
||||
const addSale = async (sale) => {
|
||||
const params = {
|
||||
barcode: sale.itemFk,
|
||||
|
@ -236,13 +236,17 @@ const addSale = async (sale) => {
|
|||
sale.isNew = false;
|
||||
arrayData.fetch({});
|
||||
};
|
||||
const changeConcept = async (sale) => {
|
||||
if (await isSalePrepared(sale)) {
|
||||
await confirmUpdate(() => updateConcept(sale));
|
||||
} else await updateConcept(sale);
|
||||
};
|
||||
|
||||
const updateConcept = async (sale) => {
|
||||
canProceed.value = await isSalePrepared(sale);
|
||||
if (!canProceed.value) return;
|
||||
const data = { newConcept: sale.concept };
|
||||
await axios.post(`Sales/${sale.id}/updateConcept`, data);
|
||||
notify('globals.dataSaved', 'positive');
|
||||
tableRef.value.reload();
|
||||
};
|
||||
|
||||
const DEFAULT_EDIT = {
|
||||
|
@ -294,33 +298,36 @@ const onOpenEditDiscountPopover = async (sale) => {
|
|||
};
|
||||
}
|
||||
};
|
||||
|
||||
const updatePrice = async (sale) => {
|
||||
canProceed.value = await isSalePrepared(sale);
|
||||
if (!canProceed.value) return;
|
||||
const changePrice = async (sale) => {
|
||||
const newPrice = edit.value.price;
|
||||
if (newPrice != null && newPrice != sale.price) {
|
||||
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
|
||||
sale.price = newPrice;
|
||||
edit.value = { ...DEFAULT_EDIT };
|
||||
notify('globals.dataSaved', 'positive');
|
||||
if (await isSalePrepared(sale)) {
|
||||
await confirmUpdate(() => updatePrice(sale, newPrice));
|
||||
} else updatePrice(sale, newPrice);
|
||||
}
|
||||
|
||||
await getMana();
|
||||
};
|
||||
const updatePrice = async (sale, newPrice) => {
|
||||
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
|
||||
sale.price = newPrice;
|
||||
edit.value = { ...DEFAULT_EDIT };
|
||||
notify('globals.dataSaved', 'positive');
|
||||
tableRef.value.reload();
|
||||
};
|
||||
|
||||
const changeDiscount = async (sale) => {
|
||||
const newDiscount = edit.value.discount;
|
||||
if (newDiscount != null && newDiscount != sale.discount) {
|
||||
if (isSalePrepared(sale))
|
||||
if (await isSalePrepared(sale))
|
||||
await confirmUpdate(() => updateDiscount([sale], newDiscount));
|
||||
else await updateDiscount([sale], newDiscount);
|
||||
}
|
||||
};
|
||||
|
||||
const updateDiscounts = async (sales, newDiscount = null) => {
|
||||
const someSaleIsPrepared = sales.some(isSalePrepared);
|
||||
if (someSaleIsPrepared);
|
||||
await confirmUpdate(() => updateDiscount(sales, newDiscount));
|
||||
const someSaleIsPrepared = await sales.some(isSalePrepared);
|
||||
if (someSaleIsPrepared) await confirmUpdate(() => updateDiscount(sales, newDiscount));
|
||||
else updateDiscount(sales, newDiscount);
|
||||
};
|
||||
|
||||
const updateDiscount = async (sales, newDiscount = null) => {
|
||||
|
@ -426,9 +433,13 @@ onMounted(async () => {
|
|||
const items = ref([]);
|
||||
const newRow = ref({});
|
||||
|
||||
const changeItem = async (sale) => {
|
||||
if (await isSalePrepared(sale)) {
|
||||
await confirmUpdate(() => updateItem(sale));
|
||||
} else await updateItem(sale);
|
||||
};
|
||||
|
||||
const updateItem = async (row) => {
|
||||
canProceed.value = await isSalePrepared(row);
|
||||
if (!canProceed.value) return;
|
||||
const selectedItem = items.value.find((item) => item.id === row.itemFk);
|
||||
if (selectedItem) {
|
||||
row.item = selectedItem;
|
||||
|
@ -499,22 +510,27 @@ async function isSalePrepared(sale) {
|
|||
|
||||
const matchingSale = data.find(({ itemFk }) => itemFk === sale.itemFk);
|
||||
if (!matchingSale) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const flagsToCheck = [
|
||||
'hasSaleGroupDetail',
|
||||
'isControled',
|
||||
'isPrepared',
|
||||
'isPrevious',
|
||||
'isPreviousSelected',
|
||||
];
|
||||
if (flagsToCheck.some((flag) => matchingSale[flag] === 1)) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
matchingSale.hasSaleGroupDetail ||
|
||||
matchingSale.isControled ||
|
||||
matchingSale.isPrepared ||
|
||||
matchingSale.isPrevious ||
|
||||
matchingSale.isPreviousSelected
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => newRow.value.itemFk,
|
||||
(newItemFk) => {
|
||||
if (newItemFk) {
|
||||
updateItem(newRow.value);
|
||||
changeItem(newRow.value);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -751,7 +767,7 @@ watch(
|
|||
option-value="id"
|
||||
v-model="row.itemFk"
|
||||
:use-like="false"
|
||||
@update:model-value="updateItem(row)"
|
||||
@update:model-value="changeItem(row)"
|
||||
>
|
||||
<template #option="scope">
|
||||
<QItem v-bind="scope.itemProps">
|
||||
|
@ -777,7 +793,11 @@ watch(
|
|||
</div>
|
||||
<FetchedTags :item="row" :max-length="6" />
|
||||
<QPopupProxy v-if="row.id && isTicketEditable">
|
||||
<VnInput v-model="row.concept" @change="updateConcept(row)" />
|
||||
<VnInput
|
||||
v-model="row.concept"
|
||||
@keyup.enter.stop="changeConcept(row)"
|
||||
:hint="t('globals.enterToConfirm')"
|
||||
/>
|
||||
</QPopupProxy>
|
||||
</template>
|
||||
<template #column-quantity="{ row }">
|
||||
|
@ -786,7 +806,7 @@ watch(
|
|||
type="number"
|
||||
v-model.number="row.quantity"
|
||||
@blur="changeQuantity(row)"
|
||||
@keyup.enter="changeQuantity(row)"
|
||||
@keyup.enter.stop="changeQuantity(row)"
|
||||
@update:model-value="() => (rowToUpdate = row)"
|
||||
@focus="edit.oldQuantity = row.quantity"
|
||||
/>
|
||||
|
@ -800,10 +820,12 @@ watch(
|
|||
<TicketEditManaProxy
|
||||
ref="editPriceProxyRef"
|
||||
:mana="mana"
|
||||
:sale="row"
|
||||
:new-price="getNewPrice"
|
||||
@save="updatePrice(row)"
|
||||
@save="changePrice"
|
||||
>
|
||||
<VnInput
|
||||
@keyup.enter.stop="() => editManaProxyRef.save(row)"
|
||||
v-model.number="edit.price"
|
||||
:label="t('basicData.price')"
|
||||
type="number"
|
||||
|
@ -838,6 +860,9 @@ watch(
|
|||
</template>
|
||||
<span v-else>{{ toPercentage(row.discount / 100) }}</span>
|
||||
</template>
|
||||
<template #column-amount="{ row }">
|
||||
{{ toCurrency(getSaleTotal(row)) }}
|
||||
</template>
|
||||
</VnTable>
|
||||
|
||||
<QPageSticky :offset="[20, 20]" style="z-index: 2">
|
||||
|
|
Loading…
Reference in New Issue