feat: refs #7127 modify days when adding lines to a claim
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
4891e98109
commit
9113f2e3e5
|
@ -1931,9 +1931,9 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
|||
(1, 31, 4, 21, 2),
|
||||
(2, 32, 3, 21, 3);
|
||||
|
||||
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`)
|
||||
INSERT INTO `vn`.`claimConfig`(`id`, `maxResponsibility`, `monthsToRefund`, `minShipped`,`daysToClaim`)
|
||||
VALUES
|
||||
(1, 5, 4, '2016-10-01');
|
||||
(1, 5, 4, '2016-10-01', 7);
|
||||
|
||||
INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`)
|
||||
VALUES
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE vn.claimConfig ADD IF NOT EXISTS daysToClaim int(11) NOT NULL DEFAULT 7 COMMENT 'Dias para reclamar';
|
|
@ -4,7 +4,7 @@ const LoopBackContext = require('loopback-context');
|
|||
describe('ClaimBeginning model()', () => {
|
||||
const claimFk = 1;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 18},
|
||||
accessToken: {userId: 72},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
};
|
||||
|
|
|
@ -3,22 +3,18 @@ const LoopBackContext = require('loopback-context');
|
|||
|
||||
describe('Claim createFromSales()', () => {
|
||||
const ticketId = 23;
|
||||
const newSale = [{
|
||||
id: 31,
|
||||
instance: 0,
|
||||
quantity: 10
|
||||
}];
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 1},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
};
|
||||
|
||||
const ctx = {
|
||||
req: activeCtx
|
||||
};
|
||||
const newSale = [{id: 31, instance: 0, quantity: 10}];
|
||||
let activeCtx;
|
||||
let ctx;
|
||||
|
||||
beforeEach(() => {
|
||||
activeCtx = {
|
||||
accessToken: {userId: 72},
|
||||
headers: {origin: 'localhost:5000'},
|
||||
__: () => {}
|
||||
};
|
||||
ctx = {req: activeCtx};
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
const moment = require('moment');
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
|
||||
|
@ -13,8 +14,31 @@ module.exports = Self => {
|
|||
const options = ctx.options;
|
||||
const models = Self.app.models;
|
||||
const saleFk = ctx?.currentInstance?.saleFk || ctx?.instance?.saleFk;
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
const accessToken = loopBackContext.active.accessToken;
|
||||
const user = await models.VnUser.findById(accessToken.userId);
|
||||
const role = await models.VnRole.findById(user.roleFk);
|
||||
const sale = await models.Sale.findById(saleFk, {fields: ['ticketFk', 'quantity']}, options);
|
||||
|
||||
if (role.name !== 'salesPerson' && role.name !== 'claimManager')
|
||||
throw new UserError(`You don't have permission to modify this claim`);
|
||||
|
||||
if (role.name === 'salesPerson') {
|
||||
const query = `
|
||||
SELECT daysToClaim
|
||||
FROM vn.claimConfig`;
|
||||
const res = await Self.rawSql(query);
|
||||
const daysToClaim = res[0]?.daysToClaim;
|
||||
|
||||
const claim = await models.Claim.findById(ctx?.currentInstance?.claimFk, {fields: ['created']}, options);
|
||||
const claimDate = moment.utc(claim.created);
|
||||
const currentDate = moment.utc();
|
||||
const daysSinceSale = currentDate.diff(claimDate, 'days');
|
||||
|
||||
if (daysSinceSale > daysToClaim)
|
||||
throw new UserError(`You can't modify this claim because the deadline has already passed`);
|
||||
}
|
||||
|
||||
if (ctx.isNewInstance) {
|
||||
const claim = await models.Claim.findById(ctx.instance.claimFk, {fields: ['ticketFk']}, options);
|
||||
if (sale.ticketFk != claim.ticketFk)
|
||||
|
|
|
@ -30,7 +30,6 @@ module.exports = Self => {
|
|||
SELECT
|
||||
s.id AS saleFk,
|
||||
t.id AS ticketFk,
|
||||
t.landed,
|
||||
s.concept,
|
||||
s.itemFk,
|
||||
s.quantity,
|
||||
|
@ -41,11 +40,10 @@ module.exports = Self => {
|
|||
INNER JOIN vn.sale s ON s.ticketFk = t.id
|
||||
LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id
|
||||
|
||||
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
|
||||
AND t.id = ? AND cb.id IS NULL
|
||||
ORDER BY t.landed DESC, t.id DESC`;
|
||||
WHERE t.id = ?
|
||||
AND cb.id IS NULL`;
|
||||
|
||||
const claimableSales = await Self.rawSql(query, [date, ticketFk], myOptions);
|
||||
const claimableSales = await Self.rawSql(query, [ticketFk], myOptions);
|
||||
|
||||
return claimableSales;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue