refactor: pull request changes
This commit is contained in:
parent
a8f4192b4c
commit
d88a404ce6
|
@ -1,3 +1,6 @@
|
||||||
UPDATE `salix`.`ACL`
|
UPDATE `salix`.`ACL`
|
||||||
SET `property`='refund'
|
SET `property`='refund'
|
||||||
WHERE `model`='Sale' AND `property`='payBack';
|
WHERE `model`='Sale' AND `property`='payBack';
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL`(`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES('Sale', 'refundAll', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
||||||
|
|
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
||||||
arg: 'sales',
|
arg: 'sales',
|
||||||
description: 'The sales',
|
description: 'The sales',
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
required: false
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'ticketId',
|
arg: 'ticketId',
|
||||||
|
@ -49,12 +49,12 @@ module.exports = Self => {
|
||||||
if (!hasValidRole)
|
if (!hasValidRole)
|
||||||
throw new UserError(`You don't have privileges to create refund`);
|
throw new UserError(`You don't have privileges to create refund`);
|
||||||
|
|
||||||
if (sales) {
|
for (let sale of sales)
|
||||||
for (let sale of sales)
|
salesIds.push(sale.id);
|
||||||
salesIds.push(sale.id);
|
|
||||||
|
|
||||||
const query = `
|
const query = `
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.sale
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
|
@ -68,36 +68,13 @@ module.exports = Self => {
|
||||||
taxClassFk INT,
|
taxClassFk INT,
|
||||||
ticketServiceTypeFk INT
|
ticketServiceTypeFk INT
|
||||||
);
|
);
|
||||||
|
|
||||||
CALL vn.ticket_doRefund(?, @newTicket);
|
CALL vn.ticket_doRefund(?, @newTicket);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.sale;
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
DROP TEMPORARY TABLE tmp.ticketService;`;
|
DROP TEMPORARY TABLE tmp.ticketService;`;
|
||||||
|
|
||||||
await Self.rawSql(query, [salesIds, ticketId], myOptions);
|
await Self.rawSql(query, [salesIds, ticketId], myOptions);
|
||||||
} else {
|
|
||||||
const query = `
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService;
|
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.sale
|
|
||||||
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
|
||||||
FROM sale s
|
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
|
||||||
WHERE t.id IN (?);
|
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tmp.ticketService
|
|
||||||
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
|
|
||||||
FROM ticketService ts
|
|
||||||
WHERE ts.ticketFk IN (?);
|
|
||||||
|
|
||||||
CALL vn.ticket_doRefund(?, @newTicket);
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.sale;
|
|
||||||
DROP TEMPORARY TABLE tmp.ticketService;`;
|
|
||||||
|
|
||||||
await Self.rawSql(query, [ticketId, ticketId, ticketId], myOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||||
ticketId = newTicket.id;
|
ticketId = newTicket.id;
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('refundAll', {
|
||||||
|
description: 'Create ticket with all lines and services changing the sign to the quantites',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'ticketId',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The ticket id'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/refundAll`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.refundAll = async(ctx, ticketId, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager');
|
||||||
|
const isSalesAssistant = await Self.app.models.Account.hasRole(userId, 'salesAssistant');
|
||||||
|
const hasValidRole = isClaimManager || isSalesAssistant;
|
||||||
|
|
||||||
|
if (!hasValidRole)
|
||||||
|
throw new UserError(`You don't have privileges to create refund`);
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketService;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
|
SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
WHERE t.id IN (?);
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE tmp.ticketService
|
||||||
|
SELECT ts.description, - ts.quantity, ts.price, ts.taxClassFk, ts.ticketServiceTypeFk
|
||||||
|
FROM ticketService ts
|
||||||
|
WHERE ts.ticketFk IN (?);
|
||||||
|
|
||||||
|
CALL vn.ticket_doRefund(?, @newTicket);
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
|
DROP TEMPORARY TABLE tmp.ticketService;`;
|
||||||
|
|
||||||
|
await Self.rawSql(query, [ticketId, ticketId, ticketId], myOptions);
|
||||||
|
|
||||||
|
const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions);
|
||||||
|
ticketId = newTicket.id;
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return ticketId;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
||||||
require('../methods/sale/updateConcept')(Self);
|
require('../methods/sale/updateConcept')(Self);
|
||||||
require('../methods/sale/recalculatePrice')(Self);
|
require('../methods/sale/recalculatePrice')(Self);
|
||||||
require('../methods/sale/refund')(Self);
|
require('../methods/sale/refund')(Self);
|
||||||
|
require('../methods/sale/refundAll')(Self);
|
||||||
require('../methods/sale/canEdit')(Self);
|
require('../methods/sale/canEdit')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('concept', {
|
Self.validatesPresenceOf('concept', {
|
||||||
|
|
|
@ -275,7 +275,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
refundAll() {
|
refundAll() {
|
||||||
const params = {ticketId: this.id};
|
const params = {ticketId: this.id};
|
||||||
const query = `Sales/refund`;
|
const query = `Sales/refundAll`;
|
||||||
return this.$http.post(query, params).then(res => {
|
return this.$http.post(query, params).then(res => {
|
||||||
this.$state.go('ticket.card.sale', {id: res.data});
|
this.$state.go('ticket.card.sale', {id: res.data});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue