Merge branch 'dev' into 8298-zonePriceOptimum
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javi Gallego 2025-01-08 13:43:17 +01:00
commit 53c604762a
5 changed files with 23 additions and 64 deletions

View File

@ -40,6 +40,7 @@ module.exports = Self => {
const sales = await Self.rawSql(` const sales = await Self.rawSql(`
SELECT s.ticketFk, SELECT s.ticketFk,
NULL ticketOrder,
sgd.saleGroupFk, sgd.saleGroupFk,
s.id saleFk, s.id saleFk,
s.itemFk, s.itemFk,
@ -83,6 +84,7 @@ module.exports = Self => {
GROUP BY s.id, ish.id, p.code, p2.code GROUP BY s.id, ish.id, p.code, p2.code
UNION ALL UNION ALL
SELECT s.ticketFk, SELECT s.ticketFk,
DENSE_RANK() OVER (ORDER BY ss.id),
sgd.saleGroupFk, sgd.saleGroupFk,
s.id saleFk, s.id saleFk,
s.itemFk, s.itemFk,

View File

@ -8,7 +8,7 @@ module.exports = Self => {
arg: 'id', arg: 'id',
type: 'number', type: 'number',
required: true, required: true,
description: 'The client id', description: 'The route id',
http: {source: 'path'} http: {source: 'path'}
}, { }, {
arg: 'replyTo', arg: 'replyTo',
@ -31,26 +31,13 @@ module.exports = Self => {
}); });
Self.driverRouteEmail = async(ctx, id) => { Self.driverRouteEmail = async(ctx, id) => {
const models = Self.app.models; const {agencyMode} = await Self.findById(id, {
const {workerFk, agencyMode} = await Self.findById(id, { fields: ['agencyModeFk'],
fields: ['workerFk', 'agencyModeFk'],
include: {relation: 'agencyMode'} include: {relation: 'agencyMode'}
}); });
const {reportMail} = agencyMode(); const {reportMail} = agencyMode();
let user;
let account;
if (workerFk) {
user = await models.VnUser.findById(workerFk, {
fields: ['active', 'id'],
include: {relation: 'emailUser'}
});
account = await models.Account.findById(workerFk);
}
if (user?.active && account) ctx.args.recipient = user.emailUser().email;
else ctx.args.recipient = reportMail;
ctx.args.recipient = reportMail;
if (!ctx.args.recipient) throw new UserError('An email is necessary'); if (!ctx.args.recipient) throw new UserError('An email is necessary');
return Self.sendTemplate(ctx, 'driver-route'); return Self.sendTemplate(ctx, 'driver-route');
}; };

View File

@ -41,22 +41,10 @@ module.exports = Self => {
const stmts = []; const stmts = [];
let stmt; let stmt;
if (!args.week || !args.year) { const {date: started, week, year} = Self.getMondayWeekYear(args.week, args.year);
const from = Date.vnNew(); args.week = week;
const to = Date.vnNew(); args.year = year;
const time = await models.Time.findOne({
where: {
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
},
order: 'week ASC'
}, myOptions);
args.week = time.week;
args.year = time.year;
}
const started = getStartDateOfWeekNumber(args.week, args.year);
started.setHours(0, 0, 0, 0); started.setHours(0, 0, 0, 0);
const ended = new Date(started); const ended = new Date(started);
@ -388,17 +376,6 @@ module.exports = Self => {
return true; return true;
}; };
function getStartDateOfWeekNumber(week, year) {
const simple = new Date(year, 0, 1 + (week - 1) * 7);
const dow = simple.getDay();
const weekStart = simple;
if (dow <= 4)
weekStart.setDate(simple.getDate() - simple.getDay() + 1);
else
weekStart.setDate(simple.getDate() + 8 - simple.getDay());
return weekStart;
}
function getTime(timeString) { function getTime(timeString) {
const [hours, minutes, seconds] = timeString.split(':'); const [hours, minutes, seconds] = timeString.split(':');
return [parseInt(hours), parseInt(minutes), parseInt(seconds)]; return [parseInt(hours), parseInt(minutes), parseInt(seconds)];

View File

@ -55,8 +55,8 @@ module.exports = Self => {
} }
}, myOptions); }, myOptions);
const dated = getMondayDateFromYearWeek(args.year, args.week); const {date} = Self.getMondayWeekYear(args.week, args.year);
const timestamp = dated.getTime() / 1000; const timestamp = date.getTime() / 1000;
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
ctx.args.url = url; ctx.args.url = url;
@ -64,23 +64,4 @@ module.exports = Self => {
await models.WorkerTimeControl.updateMailState(ctx, ctx.args.workerId, myOptions); await models.WorkerTimeControl.updateMailState(ctx, ctx.args.workerId, myOptions);
return Self.sendTemplate(ctx, 'weekly-hour-record'); return Self.sendTemplate(ctx, 'weekly-hour-record');
}; };
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
const yearStart = new Date(yearNumber, 0, 1);
const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000);
const firstMondayWeekNumber = getWeekNumber(firstMonday);
if (firstMondayWeekNumber > 1)
firstMonday.setDate(firstMonday.getDate() + 7);
firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7);
return firstMonday;
}
function getWeekNumber(date) {
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
const daysPassed = (date - firstDayOfYear) / 86400000;
return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7);
}
}; };

View File

@ -1,4 +1,5 @@
const UserError = require('vn-loopback/util/user-error'); const UserError = require('vn-loopback/util/user-error');
const moment = require('moment');
module.exports = Self => { module.exports = Self => {
require('../methods/worker-time-control/filter')(Self); require('../methods/worker-time-control/filter')(Self);
@ -19,4 +20,15 @@ module.exports = Self => {
return new UserError(`The introduced hour already exists`); return new UserError(`The introduced hour already exists`);
return err; return err;
}); });
Self.getMondayWeekYear = (week, year) => {
if (!week || !year) {
const today = Date.vnNew();
today.setDate(today.getDate() - 7);
week = moment(today).isoWeek();
year = moment(today).isoWeekYear();
}
const date = moment(year, 'YYYY').week(week).startOf('isoweek').toDate();
return {date, year, week};
};
}; };