Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 4185-secure_client_pass_changes
This commit is contained in:
commit
aa6ec3f770
|
@ -0,0 +1,5 @@
|
|||
const baseTime = null; // new Date(2022, 0, 19, 8, 0, 0, 0);
|
||||
if (baseTime) {
|
||||
jasmine.clock().install();
|
||||
jasmine.clock().mockDate(baseTime);
|
||||
}
|
|
@ -31,11 +31,13 @@ COPY \
|
|||
import-changes.sh \
|
||||
config.ini \
|
||||
dump/mysqlPlugins.sql \
|
||||
dump/mockDate.sql \
|
||||
dump/structure.sql \
|
||||
dump/dumpedFixtures.sql \
|
||||
./
|
||||
RUN gosu mysql docker-init.sh \
|
||||
&& docker-dump.sh mysqlPlugins \
|
||||
&& docker-dump.sh mockDate \
|
||||
&& docker-dump.sh structure \
|
||||
&& docker-dump.sh dumpedFixtures \
|
||||
&& gosu mysql docker-temp-stop.sh
|
||||
|
|
1468
db/dump/fixtures.sql
1468
db/dump/fixtures.sql
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
|||
CREATE SCHEMA IF NOT EXISTS `util`;
|
||||
USE `util`;
|
||||
|
||||
DELIMITER ;;
|
||||
DROP FUNCTION IF EXISTS `util`.`mockedDate`;
|
||||
CREATE FUNCTION `util`.`mockedDate`()
|
||||
RETURNS DATETIME
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN NOW();
|
||||
-- '2022-01-19 08:00:00'
|
||||
END ;;
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER ;;
|
||||
DROP FUNCTION IF EXISTS `util`.`VN_CURDATE`;
|
||||
CREATE FUNCTION `util`.`VN_CURDATE`()
|
||||
RETURNS DATE
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN DATE(mockedDate());
|
||||
END ;;
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER ;;
|
||||
DROP FUNCTION IF EXISTS `util`.`VN_CURTIME`;
|
||||
CREATE FUNCTION `util`.`VN_CURTIME`()
|
||||
RETURNS TIME
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN TIME(mockedDate());
|
||||
END ;;
|
||||
DELIMITER ;
|
||||
|
||||
DELIMITER ;;
|
||||
DROP FUNCTION IF EXISTS `util`.`VN_NOW`;
|
||||
CREATE FUNCTION `util`.`VN_NOW`()
|
||||
RETURNS DATETIME
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN mockedDate();
|
||||
END ;;
|
||||
DELIMITER ;
|
File diff suppressed because it is too large
Load Diff
|
@ -96,5 +96,12 @@ mysqldump \
|
|||
--databases \
|
||||
${SCHEMAS[@]} \
|
||||
${IGNORETABLES[@]} \
|
||||
| sed 's/\bCURDATE\b/vn.VN_CURDATE/ig'\
|
||||
| sed 's/\bCURTIME\b/vn.VN_CURTIME/ig' \
|
||||
| sed 's/\bNOW\b/vn.VN_NOW/ig' \
|
||||
| sed 's/\bCURRENT_DATE\b/vn.VN_CURDATE/ig' \
|
||||
| sed 's/\bCURRENT_TIME\b/vn.VN_CURTIME/ig' \
|
||||
| sed 's/\bLOCALTIME\b/vn.VN_NOW/ig' \
|
||||
| sed 's/\bLOCALTIMESTAMP\b/vn.VN_NOW/ig' \
|
||||
| sed 's/ AUTO_INCREMENT=[0-9]* //g' \
|
||||
> dump/structure.sql
|
|
@ -5,8 +5,9 @@ describe('zone zone_getLanded()', () => {
|
|||
it(`should return data for a shipped in the past`, async() => {
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
let params = {
|
||||
addressFk: 121,
|
||||
|
@ -14,7 +15,8 @@ describe('zone zone_getLanded()', () => {
|
|||
warehouseFk: 1,
|
||||
showExpiredZones: true};
|
||||
|
||||
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL -1 DAY), ?, ?, ?, ?)', [
|
||||
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL -1 DAY), ?, ?, ?, ?)', [
|
||||
date,
|
||||
params.addressFk,
|
||||
params.agencyModeFk,
|
||||
params.warehouseFk,
|
||||
|
@ -38,6 +40,8 @@ describe('zone zone_getLanded()', () => {
|
|||
it(`should return data for a shipped tomorrow`, async() => {
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
stmts.push('START TRANSACTION');
|
||||
|
||||
|
@ -47,7 +51,8 @@ describe('zone zone_getLanded()', () => {
|
|||
warehouseFk: 1,
|
||||
showExpiredZones: false};
|
||||
|
||||
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL +2 DAY), ?, ?, ?, ?)', [
|
||||
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(?, INTERVAL +2 DAY), ?, ?, ?, ?)', [
|
||||
date,
|
||||
params.addressFk,
|
||||
params.agencyModeFk,
|
||||
params.warehouseFk,
|
||||
|
|
|
@ -51,6 +51,9 @@ module.exports = function(Self) {
|
|||
Self.createReceipt = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
|
@ -92,8 +95,9 @@ module.exports = function(Self) {
|
|||
throw new UserError('Invalid account');
|
||||
|
||||
await Self.rawSql(
|
||||
`CALL vn.ledger_doCompensation(CURDATE(), ?, ?, ?, ?, ?, ?)`,
|
||||
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
date,
|
||||
args.compensationAccount,
|
||||
args.bankFk,
|
||||
accountingType.receiptDescription + originalClient.accountingAccount,
|
||||
|
@ -106,9 +110,10 @@ module.exports = function(Self) {
|
|||
} else if (accountingType.isAutoConciliated == true) {
|
||||
const description = `${originalClient.id} : ${originalClient.socialName} - ${accountingType.receiptDescription}`;
|
||||
const [xdiarioNew] = await Self.rawSql(
|
||||
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
|
||||
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
|
||||
[
|
||||
null,
|
||||
date,
|
||||
bank.account,
|
||||
originalClient.accountingAccount,
|
||||
description,
|
||||
|
@ -126,9 +131,10 @@ module.exports = function(Self) {
|
|||
);
|
||||
|
||||
await Self.rawSql(
|
||||
`SELECT xdiario_new(?, CURDATE(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
||||
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
||||
[
|
||||
xdiarioNew.ledger,
|
||||
date,
|
||||
originalClient.accountingAccount,
|
||||
bank.account,
|
||||
description,
|
||||
|
|
|
@ -74,8 +74,10 @@ module.exports = function(Self) {
|
|||
]
|
||||
}, myOptions);
|
||||
|
||||
const query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
|
||||
const data = await Self.rawSql(query, [id], myOptions);
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const query = `SELECT vn.clientGetDebt(?, ?) AS debt`;
|
||||
const data = await Self.rawSql(query, [id, date], myOptions);
|
||||
|
||||
client.debt = data[0].debt;
|
||||
|
||||
|
|
|
@ -25,8 +25,10 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`;
|
||||
const [debt] = await Self.rawSql(query, [clientFk], myOptions);
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const query = `SELECT vn.clientGetDebt(?, ?) AS debt`;
|
||||
const [debt] = await Self.rawSql(query, [clientFk, date], myOptions);
|
||||
|
||||
return debt;
|
||||
};
|
||||
|
|
|
@ -32,6 +32,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const ticket = await Self.app.models.Ticket.findById(ticketId, null, myOptions);
|
||||
const query = `
|
||||
SELECT
|
||||
|
@ -50,12 +52,12 @@ module.exports = Self => {
|
|||
JOIN vn.warehouse w ON t.warehouseFk = w.id
|
||||
JOIN vn.address ad ON t.addressFk = ad.id
|
||||
JOIN vn.province pr ON ad.provinceFk = pr.id
|
||||
WHERE t.shipped >= CURDATE() AND t.clientFk = ? AND ts.alertLevel = 0
|
||||
WHERE t.shipped >= ? AND t.clientFk = ? AND ts.alertLevel = 0
|
||||
AND t.id <> ? AND t.warehouseFk = ?
|
||||
ORDER BY t.shipped
|
||||
LIMIT 10`;
|
||||
|
||||
return Self.rawSql(query, [id, ticketId, ticket.warehouseFk], myOptions);
|
||||
return Self.rawSql(query, [date, id, ticketId, ticket.warehouseFk], myOptions);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -120,7 +120,6 @@ describe('client summary()', () => {
|
|||
const result = await models.Client.summary(clientId, options);
|
||||
|
||||
expect(result.recovery.id).toEqual(3);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
|
|
@ -122,7 +122,6 @@ module.exports = Self => {
|
|||
|
||||
return clientModel.findOne(filter, options);
|
||||
}
|
||||
|
||||
async function getRecoveries(recoveryModel, clientId, options) {
|
||||
const filter = {
|
||||
where: {
|
||||
|
|
|
@ -51,6 +51,8 @@ module.exports = Self => {
|
|||
|
||||
const stmts = [];
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
|
@ -72,10 +74,10 @@ module.exports = Self => {
|
|||
LEFT JOIN account.user u ON u.id = c.salesPersonFk
|
||||
LEFT JOIN account.user uw ON uw.id = co.workerFk
|
||||
WHERE
|
||||
d.created = CURDATE()
|
||||
d.created = ?
|
||||
AND d.amount > 0
|
||||
ORDER BY co.created DESC) d`
|
||||
);
|
||||
, [date]);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(`GROUP BY d.clientFk`);
|
||||
|
|
|
@ -27,13 +27,15 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const query = `
|
||||
SELECT count(*) AS hasActiveRecovery
|
||||
FROM vn.recovery
|
||||
WHERE clientFk = ?
|
||||
AND IFNULL(finished,CURDATE()) >= CURDATE();
|
||||
AND IFNULL(finished, ?) >= ?;
|
||||
`;
|
||||
const [result] = await Self.rawSql(query, [id], myOptions);
|
||||
const [result] = await Self.rawSql(query, [id, date, date], myOptions);
|
||||
|
||||
return result.hasActiveRecovery != 0;
|
||||
};
|
||||
|
|
|
@ -145,6 +145,8 @@ module.exports = Self => {
|
|||
|
||||
stmts.push('CALL cache.visible_refresh(@calc_id, FALSE, 1)');
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
i.image,
|
||||
|
@ -202,9 +204,9 @@ module.exports = Self => {
|
|||
LEFT JOIN itemType t ON t.id = i.typeFk
|
||||
LEFT JOIN intrastat intr ON intr.id = i.intrastatFk
|
||||
LEFT JOIN origin ori ON ori.id = i.originFk
|
||||
LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(CURDATE(),INTERVAL 1 YEAR)
|
||||
LEFT JOIN entry e ON e.id = b.entryFk AND e.created >= DATE_SUB(? ,INTERVAL 1 YEAR)
|
||||
LEFT JOIN supplier s ON s.id = e.supplierFk`
|
||||
);
|
||||
, [date]);
|
||||
|
||||
if (ctx.args.tags) {
|
||||
let i = 1;
|
||||
|
|
|
@ -32,6 +32,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const wastes = await Self.rawSql(`
|
||||
SELECT *, 100 * dwindle / total AS percentage
|
||||
FROM (
|
||||
|
@ -42,11 +44,11 @@ module.exports = Self => {
|
|||
sum(ws.saleWaste) AS dwindle
|
||||
FROM bs.waste ws
|
||||
WHERE buyer = ? AND family = ?
|
||||
AND year = YEAR(TIMESTAMPADD(WEEK,-1,CURDATE()))
|
||||
AND week = WEEK(TIMESTAMPADD(WEEK,-1,CURDATE()), 1)
|
||||
AND year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
|
||||
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
|
||||
GROUP BY buyer, itemFk
|
||||
) sub
|
||||
ORDER BY family, percentage DESC`, [buyer, family], myOptions);
|
||||
ORDER BY family, percentage DESC`, [buyer, family, date, date], myOptions);
|
||||
|
||||
const details = [];
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const wastes = await Self.rawSql(`
|
||||
SELECT *, 100 * dwindle / total AS percentage
|
||||
FROM (
|
||||
|
@ -27,11 +29,11 @@ module.exports = Self => {
|
|||
sum(ws.saleTotal) AS total,
|
||||
sum(ws.saleWaste) AS dwindle
|
||||
FROM bs.waste ws
|
||||
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1,CURDATE()))
|
||||
AND week = WEEK(TIMESTAMPADD(WEEK,-1,CURDATE()), 1)
|
||||
WHERE year = YEAR(TIMESTAMPADD(WEEK,-1, ?))
|
||||
AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1)
|
||||
GROUP BY buyer, family
|
||||
) sub
|
||||
ORDER BY percentage DESC`, null, myOptions);
|
||||
ORDER BY percentage DESC`, [date, date], myOptions);
|
||||
|
||||
const details = [];
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(`
|
||||
SELECT
|
||||
u.name AS salesPerson,
|
||||
|
@ -47,9 +49,10 @@ module.exports = Self => {
|
|||
JOIN client c ON c.id = v.userFk
|
||||
JOIN account.user u ON c.salesPersonFk = u.id
|
||||
LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk
|
||||
AND CURDATE() BETWEEN sc.started AND sc.ended
|
||||
AND ? BETWEEN sc.started AND sc.ended
|
||||
LEFT JOIN workerTeamCollegues wtc
|
||||
ON wtc.collegueFk = IFNULL(sc.workerSubstitute, c.salesPersonFk)`);
|
||||
ON wtc.collegueFk = IFNULL(sc.workerSubstitute, c.salesPersonFk)`,
|
||||
[date]);
|
||||
|
||||
if (!filter.where) filter.where = {};
|
||||
|
||||
|
|
|
@ -104,6 +104,8 @@ module.exports = Self => {
|
|||
const userId = ctx.req.accessToken.userId;
|
||||
const conn = Self.dataSource.connector;
|
||||
const models = Self.app.models;
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const args = ctx.args;
|
||||
const myOptions = {};
|
||||
|
||||
|
@ -264,15 +266,18 @@ module.exports = Self => {
|
|||
`);
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems');
|
||||
stmts.push(`
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE TEMPORARY TABLE tmp.sale_getProblems
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= CURDATE()`);
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= ?`, [date]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmts.push(`
|
||||
|
|
|
@ -74,6 +74,8 @@ module.exports = Self => {
|
|||
|
||||
filter = mergeFilters(filter, {where});
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmts = [];
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
|
@ -101,10 +103,10 @@ module.exports = Self => {
|
|||
LEFT JOIN vn.ticket t ON t.routeFk = r.id
|
||||
LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id
|
||||
LEFT JOIN vn.supplier s ON s.id = sat.supplierFk
|
||||
WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
|
||||
WHERE r.created > DATE_ADD(?, INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL
|
||||
GROUP BY r.id
|
||||
) a`
|
||||
);
|
||||
, [date]);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
stmt.merge(conn.makePagination(filter));
|
||||
|
|
|
@ -2,17 +2,17 @@ const app = require('vn-loopback/server/server');
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Route filter()', () => {
|
||||
let today = new Date();
|
||||
const today = new Date();
|
||||
today.setHours(2, 0, 0, 0);
|
||||
|
||||
it('should return the routes matching "search"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
search: 1,
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].id).toEqual(1);
|
||||
|
@ -28,7 +28,6 @@ describe('Route filter()', () => {
|
|||
|
||||
const to = new Date();
|
||||
to.setHours(23, 59, 59, 999);
|
||||
|
||||
const ctx = {
|
||||
args: {
|
||||
from: from,
|
||||
|
@ -48,43 +47,43 @@ describe('Route filter()', () => {
|
|||
});
|
||||
|
||||
it('should return the routes matching "m3"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
m3: 0.1,
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the routes matching "description"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
description: 'third route',
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the routes matching "workerFk"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
workerFk: 56,
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(5);
|
||||
});
|
||||
|
||||
it('should return the routes matching "warehouseFk"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
warehouseFk: 1,
|
||||
}
|
||||
|
@ -102,25 +101,25 @@ describe('Route filter()', () => {
|
|||
});
|
||||
|
||||
it('should return the routes matching "vehicleFk"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
vehicleFk: 2,
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the routes matching "agencyModeFk"', async() => {
|
||||
let ctx = {
|
||||
const ctx = {
|
||||
args: {
|
||||
agencyModeFk: 7,
|
||||
}
|
||||
};
|
||||
|
||||
let result = await app.models.Route.filter(ctx);
|
||||
const result = await app.models.Route.filter(ctx);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('route getSuggestedTickets()', () => {
|
||||
const routeID = 1;
|
||||
const ticketId = 12;
|
||||
|
||||
it('should return an array of suggested tickets', async() => {
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 19},
|
||||
headers: {origin: 'http://localhost'}
|
||||
};
|
||||
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
});
|
||||
|
||||
const tx = await app.models.Ticket.beginTransaction({});
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
const ticketInRoute = await app.models.Ticket.findById(ticketId, null, options);
|
||||
const ticketInRoute = await models.Ticket.findById(ticketId, null, options);
|
||||
|
||||
await ticketInRoute.updateAttributes({
|
||||
routeFk: null,
|
||||
landed: new Date()
|
||||
}, options);
|
||||
|
||||
const result = await app.models.Route.getSuggestedTickets(routeID, options);
|
||||
const result = await models.Route.getSuggestedTickets(routeID, options);
|
||||
|
||||
const length = result.length;
|
||||
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
||||
|
|
|
@ -24,6 +24,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const query = `
|
||||
SELECT
|
||||
s.id AS saleFk,
|
||||
|
@ -39,11 +41,11 @@ 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, CURDATE())
|
||||
WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?)
|
||||
AND t.id = ? AND cb.id IS NULL
|
||||
ORDER BY t.landed DESC, t.id DESC`;
|
||||
|
||||
const claimableSales = await Self.rawSql(query, [ticketFk], myOptions);
|
||||
const claimableSales = await Self.rawSql(query, [date, ticketFk], myOptions);
|
||||
|
||||
return claimableSales;
|
||||
};
|
||||
|
|
|
@ -132,6 +132,8 @@ module.exports = Self => {
|
|||
Self.filter = async(ctx, filter, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const conn = Self.dataSource.connector;
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
|
||||
|
@ -297,7 +299,8 @@ module.exports = Self => {
|
|||
stmts.push(stmt);
|
||||
|
||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems');
|
||||
stmts.push(`
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE TEMPORARY TABLE tmp.sale_getProblems
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
|
@ -305,7 +308,9 @@ module.exports = Self => {
|
|||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= CURDATE()`);
|
||||
AND f.shipped >= ?`, [date]);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
|
|
|
@ -26,6 +26,8 @@ module.exports = function(Self) {
|
|||
Self.makeInvoice = async(ctx, ticketsIds, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -81,7 +83,7 @@ module.exports = function(Self) {
|
|||
WHERE id IN(?) AND refFk IS NULL
|
||||
`, [ticketsIds], myOptions);
|
||||
|
||||
await Self.rawSql('CALL invoiceOut_new(?, CURDATE(), null, @invoiceId)', [serial], myOptions);
|
||||
await Self.rawSql('CALL invoiceOut_new(?, ?, null, @invoiceId)', [serial, date], myOptions);
|
||||
|
||||
const [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], myOptions);
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ describe('ticket canBeInvoiced()', () => {
|
|||
|
||||
it('should return falsy for a ticket shipping in future', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ module.exports = Self => {
|
|||
const models = Self.app.models;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
const date = new Date();
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -57,8 +58,8 @@ module.exports = Self => {
|
|||
|
||||
await Self.rawSql(`
|
||||
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
|
||||
VALUES (?, ?, ?, NOW())
|
||||
`, [thermograph.id, warehouseId, temperatureFk], myOptions);
|
||||
VALUES (?, ?, ?, ?)
|
||||
`, [thermograph.id, warehouseId, temperatureFk, date], myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('workerTimeControl filter()', () => {
|
||||
it('should return 1 result filtering by id', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 1106}}, args: {workerFk: 1106}};
|
||||
const ctx = {req: {accessToken: {userId: 1106}}, args: {workerFk: 1106}};
|
||||
const firstHour = new Date();
|
||||
firstHour.setHours(7, 0, 0, 0);
|
||||
const lastHour = new Date();
|
||||
|
@ -14,13 +14,13 @@ describe('workerTimeControl filter()', () => {
|
|||
timed: {between: [firstHour, lastHour]}
|
||||
}
|
||||
};
|
||||
let result = await app.models.WorkerTimeControl.filter(ctx, filter);
|
||||
const result = await models.WorkerTimeControl.filter(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
});
|
||||
|
||||
it('should return a privilege error for a non subordinate worker', async() => {
|
||||
let ctx = {req: {accessToken: {userId: 1107}}, args: {workerFk: 1106}};
|
||||
const ctx = {req: {accessToken: {userId: 1107}}, args: {workerFk: 1106}};
|
||||
const firstHour = new Date();
|
||||
firstHour.setHours(7, 0, 0, 0);
|
||||
const lastHour = new Date();
|
||||
|
@ -34,7 +34,7 @@ describe('workerTimeControl filter()', () => {
|
|||
};
|
||||
|
||||
let error;
|
||||
await app.models.WorkerTimeControl.filter(ctx, filter).catch(e => {
|
||||
await models.WorkerTimeControl.filter(ctx, filter).catch(e => {
|
||||
error = e;
|
||||
}).finally(() => {
|
||||
expect(error.message).toEqual(`You don't have enough privileges`);
|
||||
|
|
|
@ -8,10 +8,10 @@ describe('workerTimeControl add/delete timeEntry()', () => {
|
|||
const employeeId = 1;
|
||||
const salesPersonId = 1106;
|
||||
const salesBossId = 19;
|
||||
let activeCtx = {
|
||||
const activeCtx = {
|
||||
accessToken: {userId: 50},
|
||||
};
|
||||
let ctx = {req: activeCtx};
|
||||
const ctx = {req: activeCtx};
|
||||
|
||||
beforeAll(() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
|
@ -82,7 +82,7 @@ describe('workerTimeControl add/delete timeEntry()', () => {
|
|||
const workerId = salesPersonId;
|
||||
let error;
|
||||
|
||||
let calendar = await app.models.Calendar.findById(3);
|
||||
const calendar = await app.models.Calendar.findById(3);
|
||||
|
||||
try {
|
||||
ctx.args = {timed: new Date(calendar.dated), direction: 'in'};
|
||||
|
|
|
@ -80,6 +80,9 @@ module.exports = Self => {
|
|||
if (hasHoursRecorded && isNotHalfAbsence)
|
||||
throw new UserError(`The worker has hours recorded that day`);
|
||||
|
||||
const date = new Date();
|
||||
const now = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const [result] = await Self.rawSql(
|
||||
`SELECT COUNT(*) halfHolidayCounter
|
||||
FROM vn.calendar c
|
||||
|
@ -88,8 +91,8 @@ module.exports = Self => {
|
|||
JOIN vn.person pe ON pe.id = p.person_id
|
||||
WHERE c.dayOffTypeFk = 6
|
||||
AND pe.workerFk = ?
|
||||
AND c.dated BETWEEN util.firstDayOfYear(CURDATE())
|
||||
AND LAST_DAY(DATE_ADD(NOW(), INTERVAL 12-MONTH(NOW()) MONTH))`, [id]);
|
||||
AND c.dated BETWEEN util.firstDayOfYear(?)
|
||||
AND LAST_DAY(DATE_ADD(?, INTERVAL 12 - MONTH(?) MONTH))`, [id, date, now, now]);
|
||||
|
||||
const hasHalfHoliday = result.halfHolidayCounter > 0;
|
||||
const isHalfHoliday = absenceType.code === 'halfHoliday';
|
||||
|
|
|
@ -8,7 +8,6 @@ describe('zone getZoneClosing()', () => {
|
|||
const options = {transaction: tx};
|
||||
const date = new Date();
|
||||
const today = date.toISOString().split('T')[0];
|
||||
|
||||
const result = await models.Zone.getZoneClosing([1, 2, 3], today, options);
|
||||
|
||||
expect(result.length).toEqual(3);
|
||||
|
|
|
@ -93,11 +93,12 @@ module.exports = async function(request, response, next) {
|
|||
await email.send(mailOptions);
|
||||
}
|
||||
// Update queue status
|
||||
const date = new Date();
|
||||
sql = `UPDATE invoiceOut_queue
|
||||
SET status = "printed",
|
||||
printed = NOW()
|
||||
printed = ?
|
||||
WHERE invoiceFk = ?`;
|
||||
connection.query(sql, [invoiceOut.id]);
|
||||
connection.query(sql, [date, invoiceOut.id]);
|
||||
connection.query('COMMIT');
|
||||
} catch (error) {
|
||||
connection.query('ROLLBACK');
|
||||
|
|
Loading…
Reference in New Issue