hotfix_ticketSale_handle_notifications #1660

Merged
jsegarra merged 3 commits from hotfix_ticketSale_handle_notifications into master 2025-04-01 09:20:34 +00:00
2 changed files with 85 additions and 64 deletions

View File

@ -73,6 +73,7 @@ const exprBuilder = (param, value) => {
option-value="id" option-value="id"
option-label="name" option-label="name"
url="Departments" url="Departments"
no-one="true"
/> />
</QItemSection> </QItemSection>
</QItem> </QItem>

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { onMounted, ref, computed, watch } from 'vue'; import { onMounted, ref, computed, watch, inject } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter, useRoute } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
@ -25,7 +25,7 @@ import VnTable from 'src/components/VnTable/VnTable.vue';
import VnConfirm from 'src/components/ui/VnConfirm.vue'; import VnConfirm from 'src/components/ui/VnConfirm.vue';
import TicketProblems from 'src/components/TicketProblems.vue'; import TicketProblems from 'src/components/TicketProblems.vue';
import RightMenu from 'src/components/common/RightMenu.vue'; import RightMenu from 'src/components/common/RightMenu.vue';
const app = inject('app');
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const { t } = useI18n(); const { t } = useI18n();
@ -196,13 +196,17 @@ const changeQuantity = async (sale) => {
if (!sale.itemFk || sale.quantity == null || sale?.originalQuantity === sale.quantity) if (!sale.itemFk || sale.quantity == null || sale?.originalQuantity === sale.quantity)
return; return;
else sale.originalQuantity = sale.quantity; else sale.originalQuantity = sale.quantity;
if (!sale.id) return addSale(sale); try {
if (!sale.id) await addSale(sale);
} catch (e) {
app.config.errorHandler(e);
return;
}
if (await isSalePrepared(sale)) { if (await isSalePrepared(sale)) {
await confirmUpdate(() => updateQuantity(sale)); await confirmUpdate(() => updateQuantity(sale));
} else await updateQuantity(sale); } else await updateQuantity(sale);
}; };
const updateQuantity = async (sale) => { const updateQuantity = async (sale) => {
try { try {
let { quantity, id } = sale; let { quantity, id } = sale;
@ -215,7 +219,7 @@ const updateQuantity = async (sale) => {
(s) => s.id === sale.id, (s) => s.id === sale.id,
); );
sale.quantity = quantity; sale.quantity = quantity;
throw e; app.config.errorHandler(e);
} }
}; };
@ -224,24 +228,27 @@ const addSale = async (sale) => {
barcode: sale.itemFk, barcode: sale.itemFk,
quantity: sale.quantity, quantity: sale.quantity,
}; };
try {
const { data } = await axios.post(`tickets/${route.params.id}/addSale`, params);
const { data } = await axios.post(`tickets/${route.params.id}/addSale`, params); if (!data) return;
if (!data) return; const newSale = data;
sale.id = newSale.id;
sale.image = newSale.item.image;
sale.subName = newSale.item.subName;
sale.concept = newSale.concept;
sale.quantity = newSale.quantity;
sale.discount = newSale.discount;
sale.price = newSale.price;
sale.item = newSale.item;
const newSale = data; notify('globals.dataSaved', 'positive');
sale.id = newSale.id; sale.isNew = false;
sale.image = newSale.item.image; resetChanges();
sale.subName = newSale.item.subName; } catch (e) {
sale.concept = newSale.concept; app.config.errorHandler(e);
sale.quantity = newSale.quantity; }
sale.discount = newSale.discount;
sale.price = newSale.price;
sale.item = newSale.item;
notify('globals.dataSaved', 'positive');
sale.isNew = false;
resetChanges();
}; };
const changeConcept = async (sale) => { const changeConcept = async (sale) => {
if (await isSalePrepared(sale)) { if (await isSalePrepared(sale)) {
@ -250,10 +257,14 @@ const changeConcept = async (sale) => {
}; };
const updateConcept = async (sale) => { const updateConcept = async (sale) => {
const data = { newConcept: sale.concept }; try {
await axios.post(`Sales/${sale.id}/updateConcept`, data); const data = { newConcept: sale.concept };
notify('globals.dataSaved', 'positive'); await axios.post(`Sales/${sale.id}/updateConcept`, data);
resetChanges(); notify('globals.dataSaved', 'positive');
resetChanges();
} catch (e) {
app.config.errorHandler(e);
}
}; };
const DEFAULT_EDIT = { const DEFAULT_EDIT = {
@ -264,18 +275,6 @@ const DEFAULT_EDIT = {
oldQuantity: null, oldQuantity: null,
}; };
const edit = ref({ ...DEFAULT_EDIT }); const edit = ref({ ...DEFAULT_EDIT });
const usesMana = ref(null);
const getUsesMana = async () => {
const { data } = await axios.get('Sales/usesMana');
usesMana.value = data;
};
const getMana = async () => {
const { data } = await axios.get(`Tickets/${route.params.id}/getDepartmentMana`);
mana.value = data;
await getUsesMana();
};
const selectedValidSales = computed(() => { const selectedValidSales = computed(() => {
if (!sales.value) return; if (!sales.value) return;
@ -312,11 +311,15 @@ const changePrice = async (sale) => {
} }
}; };
const updatePrice = async (sale, newPrice) => { const updatePrice = async (sale, newPrice) => {
await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice }); try {
sale.price = newPrice; await axios.post(`Sales/${sale.id}/updatePrice`, { newPrice });
edit.value = { ...DEFAULT_EDIT }; sale.price = newPrice;
notify('globals.dataSaved', 'positive'); edit.value = { ...DEFAULT_EDIT };
resetChanges(); notify('globals.dataSaved', 'positive');
resetChanges();
} catch (e) {
app.config.errorHandler(e);
}
}; };
const changeDiscount = async (sale) => { const changeDiscount = async (sale) => {
@ -339,15 +342,20 @@ const updateDiscounts = async (sales, newDiscount) => {
}; };
const updateDiscount = async (sales, newDiscount = 0) => { const updateDiscount = async (sales, newDiscount = 0) => {
const salesIds = sales.map(({ id }) => id); try {
const params = { const salesIds = sales.map(({ id }) => id);
salesIds, const params = {
newDiscount, salesIds,
manaCode: manaCode.value, newDiscount,
}; manaCode: manaCode.value,
await axios.post(`Tickets/${route.params.id}/updateDiscount`, params); };
notify('globals.dataSaved', 'positive'); await axios.post(`Tickets/${route.params.id}/updateDiscount`, params);
resetChanges(); notify('globals.dataSaved', 'positive');
resetChanges();
} catch (e) {
app.config.errorHandler(e);
return;
}
}; };
const getNewPrice = computed(() => { const getNewPrice = computed(() => {
@ -369,11 +377,15 @@ const getNewPrice = computed(() => {
}); });
const newOrderFromTicket = async () => { const newOrderFromTicket = async () => {
const { data } = await axios.post(`Orders/newFromTicket`, { try {
ticketFk: Number(route.params.id), const { data } = await axios.post(`Orders/newFromTicket`, {
}); ticketFk: Number(route.params.id),
const routeData = router.resolve({ name: 'OrderCatalog', params: { id: data } }); });
window.open(routeData.href, '_blank'); const routeData = router.resolve({ name: 'OrderCatalog', params: { id: data } });
window.open(routeData.href, '_blank');
} catch (e) {
app.config.errorHandler(e);
}
}; };
const goToLog = (saleId) => { const goToLog = (saleId) => {
@ -388,11 +400,15 @@ const goToLog = (saleId) => {
}; };
const changeTicketState = async (val) => { const changeTicketState = async (val) => {
stateBtnDropdownRef.value.hide(); try {
const params = { ticketFk: route.params.id, code: val }; stateBtnDropdownRef.value.hide();
await axios.post('Tickets/state', params); const params = { ticketFk: route.params.id, code: val };
notify('globals.dataSaved', 'positive'); await axios.post('Tickets/state', params);
resetChanges(); notify('globals.dataSaved', 'positive');
resetChanges();
} catch (e) {
app.config.errorHandler(e);
}
}; };
const removeSelectedSales = () => { const removeSelectedSales = () => {
@ -412,10 +428,14 @@ const removeSales = async () => {
.forEach((sale) => tableRef.value.CrudModelRef.formData.splice(sale.$index, 1)); .forEach((sale) => tableRef.value.CrudModelRef.formData.splice(sale.$index, 1));
if (params.sales.length == 0) return; if (params.sales.length == 0) return;
await axios.post('Sales/deleteSales', params); try {
removeSelectedSales(); await axios.post('Sales/deleteSales', params);
notify('globals.dataSaved', 'positive'); removeSelectedSales();
resetChanges(); notify('globals.dataSaved', 'positive');
resetChanges();
} catch (e) {
app.config.errorHandler(e);
}
}; };
const setTransferParams = async () => { const setTransferParams = async () => {