231801_test_to_master #1519
|
@ -35,7 +35,7 @@ module.exports = Self => {
|
||||||
const tickets = await models.Ticket.find(filter, myOptions);
|
const tickets = await models.Ticket.find(filter, myOptions);
|
||||||
|
|
||||||
const ticketsIds = tickets.map(ticket => ticket.id);
|
const ticketsIds = tickets.map(ticket => ticket.id);
|
||||||
const refundedTickets = await models.Ticket.refund(ticketsIds, true, myOptions);
|
const refundedTickets = await models.Ticket.refund(ticketsIds, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -118,8 +118,11 @@ class Controller extends Section {
|
||||||
const query = 'InvoiceOuts/refund';
|
const query = 'InvoiceOuts/refund';
|
||||||
const params = {ref: this.invoiceOut.ref};
|
const params = {ref: this.invoiceOut.ref};
|
||||||
this.$http.post(query, params).then(res => {
|
this.$http.post(query, params).then(res => {
|
||||||
const ticketIds = res.data.map(ticket => ticket.id).join(', ');
|
const refundTicket = res.data;
|
||||||
this.vnApp.showSuccess(this.$t('The following refund tickets have been created', {ticketIds}));
|
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
|
||||||
|
ticketId: refundTicket.id
|
||||||
|
}));
|
||||||
|
this.$state.go('ticket.card.sale', {id: refundTicket.id});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,6 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'servicesIds',
|
arg: 'servicesIds',
|
||||||
type: ['number']
|
type: ['number']
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'createSingleTicket',
|
|
||||||
type: 'boolean',
|
|
||||||
required: false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -28,7 +23,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.refund = async(salesIds, servicesIds, createSingleTicket = false, options) => {
|
Self.refund = async(salesIds, servicesIds, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -67,40 +62,14 @@ module.exports = Self => {
|
||||||
const sales = await models.Sale.find(salesFilter, myOptions);
|
const sales = await models.Sale.find(salesFilter, myOptions);
|
||||||
const ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))];
|
const ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))];
|
||||||
|
|
||||||
const refundTickets = [];
|
|
||||||
const mappedTickets = new Map();
|
|
||||||
const now = Date.vnNew();
|
const now = Date.vnNew();
|
||||||
|
|
||||||
const [firstTicketId] = ticketsIds;
|
const [firstTicketId] = ticketsIds;
|
||||||
if (createSingleTicket) {
|
|
||||||
await createTicketRefund(
|
const refundTicket = await createTicketRefund(firstTicketId, now, refundAgencyMode, refoundZoneId, myOptions);
|
||||||
firstTicketId,
|
|
||||||
refundTickets,
|
|
||||||
mappedTickets,
|
|
||||||
now,
|
|
||||||
refundAgencyMode,
|
|
||||||
refoundZoneId,
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
for (let ticketId of ticketsIds) {
|
|
||||||
await createTicketRefund(
|
|
||||||
ticketId,
|
|
||||||
refundTickets,
|
|
||||||
mappedTickets,
|
|
||||||
now,
|
|
||||||
refundAgencyMode,
|
|
||||||
refoundZoneId,
|
|
||||||
myOptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const sale of sales) {
|
for (const sale of sales) {
|
||||||
const refundTicketId = await getTicketRefundId(createSingleTicket, sale.ticketFk, refundTickets, mappedTickets);
|
|
||||||
|
|
||||||
const createdSale = await models.Sale.create({
|
const createdSale = await models.Sale.create({
|
||||||
ticketFk: refundTicketId,
|
ticketFk: refundTicket.id,
|
||||||
itemFk: sale.itemFk,
|
itemFk: sale.itemFk,
|
||||||
quantity: - sale.quantity,
|
quantity: - sale.quantity,
|
||||||
concept: sale.concept,
|
concept: sale.concept,
|
||||||
|
@ -120,16 +89,13 @@ module.exports = Self => {
|
||||||
where: {id: {inq: servicesIds}}
|
where: {id: {inq: servicesIds}}
|
||||||
};
|
};
|
||||||
const services = await models.TicketService.find(servicesFilter, myOptions);
|
const services = await models.TicketService.find(servicesFilter, myOptions);
|
||||||
|
|
||||||
for (const service of services) {
|
for (const service of services) {
|
||||||
const refundTicketId = await getTicketRefundId(createSingleTicket, service.ticketFk, refundTickets, mappedTickets);
|
|
||||||
|
|
||||||
await models.TicketService.create({
|
await models.TicketService.create({
|
||||||
description: service.description,
|
description: service.description,
|
||||||
quantity: - service.quantity,
|
quantity: - service.quantity,
|
||||||
price: service.price,
|
price: service.price,
|
||||||
taxClassFk: service.taxClassFk,
|
taxClassFk: service.taxClassFk,
|
||||||
ticketFk: refundTicketId,
|
ticketFk: refundTicket.id,
|
||||||
ticketServiceTypeFk: service.ticketServiceTypeFk,
|
ticketServiceTypeFk: service.ticketServiceTypeFk,
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
}
|
||||||
|
@ -137,22 +103,14 @@ module.exports = Self => {
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return refundTickets;
|
return refundTicket;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function createTicketRefund(
|
async function createTicketRefund(ticketId, now, refundAgencyMode, refoundZoneId, myOptions) {
|
||||||
ticketId,
|
|
||||||
refundTickets,
|
|
||||||
mappedTickets,
|
|
||||||
now,
|
|
||||||
refundAgencyMode,
|
|
||||||
refoundZoneId,
|
|
||||||
myOptions
|
|
||||||
) {
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const filter = {include: {relation: 'address'}};
|
const filter = {include: {relation: 'address'}};
|
||||||
|
@ -170,20 +128,11 @@ module.exports = Self => {
|
||||||
zoneFk: refoundZoneId
|
zoneFk: refoundZoneId
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
refundTickets.push(refundTicket);
|
|
||||||
|
|
||||||
mappedTickets.set(ticketId, refundTicket.id);
|
|
||||||
|
|
||||||
await models.TicketRefund.create({
|
await models.TicketRefund.create({
|
||||||
refundTicketFk: refundTicket.id,
|
refundTicketFk: refundTicket.id,
|
||||||
originalTicketFk: ticket.id,
|
originalTicketFk: ticket.id,
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
|
||||||
|
|
||||||
async function getTicketRefundId(createSingleTicket, ticketId, refundTickets, mappedTickets) {
|
return refundTicket;
|
||||||
if (createSingleTicket) {
|
|
||||||
const [firstRefundTicket] = refundTickets;
|
|
||||||
return firstRefundTicket.id;
|
|
||||||
} else return mappedTickets.get(ticketId);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,11 +7,6 @@ module.exports = Self => {
|
||||||
arg: 'ticketsIds',
|
arg: 'ticketsIds',
|
||||||
type: ['number'],
|
type: ['number'],
|
||||||
required: true
|
required: true
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'createSingleTicket',
|
|
||||||
type: 'boolean',
|
|
||||||
required: false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -24,7 +19,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.refund = async(ticketsIds, createSingleTicket = false, options) => {
|
Self.refund = async(ticketsIds, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -46,7 +41,7 @@ module.exports = Self => {
|
||||||
const services = await models.TicketService.find(filter, myOptions);
|
const services = await models.TicketService.find(filter, myOptions);
|
||||||
const servicesIds = services.map(service => service.id);
|
const servicesIds = services.map(service => service.id);
|
||||||
|
|
||||||
const refundedTickets = await models.Sale.refund(salesIds, servicesIds, createSingleTicket, myOptions);
|
const refundedTickets = await models.Sale.refund(salesIds, servicesIds, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,7 @@ class Controller extends Section {
|
||||||
const params = {ticketsIds: [this.id]};
|
const params = {ticketsIds: [this.id]};
|
||||||
const query = 'Tickets/refund';
|
const query = 'Tickets/refund';
|
||||||
return this.$http.post(query, params).then(res => {
|
return this.$http.post(query, params).then(res => {
|
||||||
const [refundTicket] = res.data;
|
const refundTicket = res.data;
|
||||||
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
|
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
|
||||||
ticketId: refundTicket.id
|
ticketId: refundTicket.id
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -516,7 +516,7 @@ class Controller extends Section {
|
||||||
const params = {salesIds: salesIds};
|
const params = {salesIds: salesIds};
|
||||||
const query = 'Sales/refund';
|
const query = 'Sales/refund';
|
||||||
this.$http.post(query, params).then(res => {
|
this.$http.post(query, params).then(res => {
|
||||||
const [refundTicket] = res.data;
|
const refundTicket = res.data;
|
||||||
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
|
this.vnApp.showSuccess(this.$t('The following refund ticket have been created', {
|
||||||
ticketId: refundTicket.id
|
ticketId: refundTicket.id
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue