diff --git a/CHANGELOG.md b/CHANGELOG.md index cc8d9f5a2..ea4725448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,19 +5,41 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2306.01] - 2023-02-23 + +### Added +- (Tickets -> Datos Básicos) Mensaje de confirmación al intentar generar tickets con negativos + +### Changed +- (General -> Inicio) Ahora permite recuperar la contraseña tanto con el correo de recuperación como el usuario + +### Fixed +- (Monitor de tickets) Cuando ordenas por columna, ya no se queda deshabilitado el botón de 'Actualizar' +- (Zone -> Días de entrega) Al hacer click en un día, muestra correctamente las zonas + ## [2304.01] - 2023-02-09 ### Added - (Rutas) Al descargar varias facturas se comprime en un zip -- (Trabajadores -> Nuevo trabajador) Nueva sección +- (Trabajadores -> Nuevo trabajador) Nueva sección +- (Tickets -> Adelantar tickets) Añadidos campos "líneas" y "litros" al ticket origen +- (Tickets -> Adelantar tickets) Nuevo icono muestra cuando las agencias de los tickets origen/destino son distintas ### Changed - (Entradas -> Compras) Cambiados los campos "Precio Grouping/Packing" por "PVP" y "Precio" por "Coste" - (Artículos -> Últimas entradas) Cambiados los campos "P.P.U." y "P.P.P." por "PVP" +- (Rutas -> Sumario/Tickets) Actualizados campos de los tickets +- (Proveedores -> Crear/Editar) Permite añadir Proveedores con la misma razón social pero con países distintos +- (Tickets -> Adelantar tickets) Cambiados selectores de estado por checks "Pendiente origen/destino" +- (Tickets -> Adelantar tickets) Cambiado stock de destino a origen. ### Fixed - (Artículos -> Etiquetas) Permite intercambiar la relevancia entre dos etiquetas. +- (Cliente -> Datos Fiscales) No se permite seleccionar 'Notificar vía e-mail' a los clientes sin e-mail +- (Tickets -> Datos básicos) Permite guardar la hora de envío - (Tickets -> Añadir pago) Eliminado "null" en las referencias +- (Tickets -> Adelantar tickets) Permite ordenar por importe +- (Tickets -> Adelantar tickets) El filtrado por encajado muestra también los tickets sin tipo de encajado ## [2302.01] - 2023-01-26 diff --git a/back/methods/account/recover-password.js b/back/methods/account/recover-password.js index ddea76829..787a45284 100644 --- a/back/methods/account/recover-password.js +++ b/back/methods/account/recover-password.js @@ -3,9 +3,9 @@ module.exports = Self => { description: 'Send email to the user', accepts: [ { - arg: 'email', + arg: 'user', type: 'string', - description: 'The email of user', + description: 'The user name or email', required: true } ], @@ -15,11 +15,20 @@ module.exports = Self => { } }); - Self.recoverPassword = async function(email) { + Self.recoverPassword = async function(user) { const models = Self.app.models; + const usesEmail = user.indexOf('@') !== -1; + if (!usesEmail) { + const account = await models.Account.findOne({ + fields: ['email'], + where: {name: user} + }); + user = account.email; + } + try { - await models.user.resetPassword({email, emailTemplate: 'recover-password'}); + await models.user.resetPassword({email: user, emailTemplate: 'recover-password'}); } catch (err) { if (err.code === 'EMAIL_NOT_FOUND') return; diff --git a/back/methods/campaign/latest.js b/back/methods/campaign/latest.js index a418f1267..56ab81330 100644 --- a/back/methods/campaign/latest.js +++ b/back/methods/campaign/latest.js @@ -22,7 +22,7 @@ module.exports = Self => { Self.latest = async filter => { const conn = Self.dataSource.connector; - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setFullYear(minDate.getFullYear() - 1); const where = {dated: {gte: minDate}}; diff --git a/back/methods/campaign/spec/latest.spec.js b/back/methods/campaign/spec/latest.spec.js index a71849b59..59e4c1e7a 100644 --- a/back/methods/campaign/spec/latest.spec.js +++ b/back/methods/campaign/spec/latest.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); describe('campaign latest()', () => { it('should return the campaigns from the last year', async() => { - const now = new Date(); + const now = Date.vnNew(); const result = await app.models.Campaign.latest(); const randomIndex = Math.floor(Math.random() * result.length); const campaignDated = result[randomIndex].dated; @@ -12,7 +12,7 @@ describe('campaign latest()', () => { }); it('should return the campaigns from the current year', async() => { - const now = new Date(); + const now = Date.vnNew(); const currentYear = now.getFullYear(); const result = await app.models.Campaign.latest({ where: {dated: {like: `%${currentYear}%`}} diff --git a/back/methods/campaign/spec/upcoming.spec.js b/back/methods/campaign/spec/upcoming.spec.js index 14bffe3cf..2aec5117f 100644 --- a/back/methods/campaign/spec/upcoming.spec.js +++ b/back/methods/campaign/spec/upcoming.spec.js @@ -4,7 +4,7 @@ describe('campaign upcoming()', () => { it('should return the upcoming campaign but from the last year', async() => { const response = await app.models.Campaign.upcoming(); const campaignDated = response.dated; - const now = new Date(); + const now = Date.vnNew(); expect(campaignDated).toEqual(jasmine.any(Date)); expect(campaignDated).toBeLessThanOrEqual(now); diff --git a/back/methods/campaign/upcoming.js b/back/methods/campaign/upcoming.js index 2f1a5a377..c98fee6e5 100644 --- a/back/methods/campaign/upcoming.js +++ b/back/methods/campaign/upcoming.js @@ -14,7 +14,7 @@ module.exports = Self => { }); Self.upcoming = async() => { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setFullYear(minDate.getFullYear() - 1); return Self.findOne({ diff --git a/back/methods/chat/getServiceAuth.js b/back/methods/chat/getServiceAuth.js index 827092109..ff14e76cb 100644 --- a/back/methods/chat/getServiceAuth.js +++ b/back/methods/chat/getServiceAuth.js @@ -21,7 +21,7 @@ module.exports = Self => { if (!this.login) return; - if (Date.now() > this.login.expires) + if (Date.vnNow() > this.login.expires) this.login = await requestToken(); return this.login; @@ -48,7 +48,7 @@ module.exports = Self => { userId: requestData.userId, token: requestData.authToken }, - expires: Date.now() + (1000 * 60 * tokenLifespan) + expires: Date.vnNow() + (1000 * 60 * tokenLifespan) }; } } diff --git a/back/methods/chat/send.js b/back/methods/chat/send.js index c5c8feead..915120d49 100644 --- a/back/methods/chat/send.js +++ b/back/methods/chat/send.js @@ -33,7 +33,7 @@ module.exports = Self => { await models.Chat.create({ senderFk: sender.id, recipient: to, - dated: new Date(), + dated: Date.vnNew(), checkUserStatus: 0, message: message, status: 0, diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 075591969..883a1b693 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -49,7 +49,7 @@ module.exports = Self => { await models.Chat.create({ senderFk: sender.id, recipient: `@${recipient.name}`, - dated: new Date(), + dated: Date.vnNew(), checkUserStatus: 1, message: message, status: 0, diff --git a/back/methods/chat/spec/sendQueued.spec.js b/back/methods/chat/spec/sendQueued.spec.js index bbf5a73c7..ed791756b 100644 --- a/back/methods/chat/spec/sendQueued.spec.js +++ b/back/methods/chat/spec/sendQueued.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Chat sendCheckingPresence()', () => { - const today = new Date(); + const today = Date.vnNew(); today.setHours(6, 0); const chatModel = models.Chat; diff --git a/back/methods/collection/setSaleQuantity.js b/back/methods/collection/setSaleQuantity.js index b6c56ddc4..4ac3d6d4b 100644 --- a/back/methods/collection/setSaleQuantity.js +++ b/back/methods/collection/setSaleQuantity.js @@ -24,7 +24,7 @@ module.exports = Self => { } }); - Self.setSaleQuantity = async(saleId, quantity) => { + Self.setSaleQuantity = async(saleId, quantity, options) => { const models = Self.app.models; const myOptions = {}; let tx; diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js index f14e65e9f..239d654ef 100644 --- a/back/methods/dms/deleteTrashFiles.js +++ b/back/methods/dms/deleteTrashFiles.js @@ -32,7 +32,7 @@ module.exports = Self => { where: {code: 'trash'} }, myOptions); - const date = new Date(); + const date = Date.vnNew(); date.setMonth(date.getMonth() - 4); const dmsToDelete = await models.Dms.find({ diff --git a/back/methods/dms/saveSign.js b/back/methods/dms/saveSign.js index f668c5ed2..ed462a301 100644 --- a/back/methods/dms/saveSign.js +++ b/back/methods/dms/saveSign.js @@ -163,7 +163,7 @@ module.exports = Self => { fields: ['alertLevel'] }); - signedTime ? signedTime != undefined : signedTime = new Date(); + signedTime ? signedTime != undefined : signedTime = Date.vnNew(); if (alertLevel >= 2) { let dir; diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index b5ee3d18f..ea9ee3622 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -127,7 +127,7 @@ module.exports = Self => { const uploadOptions = { headers: { 'Content-Type': 'multipart/form-data', - 'X-File-ModifiedDate': new Date(), + 'X-File-ModifiedDate': Date.vnNew(), 'Cookie': options.headers.headers.Cookie, ...data.getHeaders() }, diff --git a/back/methods/edi/updateData.js b/back/methods/edi/updateData.js index c5705513f..232695f4e 100644 --- a/back/methods/edi/updateData.js +++ b/back/methods/edi/updateData.js @@ -230,7 +230,7 @@ module.exports = Self => { UPDATE edi.tableConfig SET updated = ? WHERE fileName = ? - `, [new Date(), baseName], options); + `, [Date.vnNew(), baseName], options); } console.log(`Updated table ${toTable}\n`); diff --git a/back/methods/notification/clean.js b/back/methods/notification/clean.js index bdc6737df..8ce32d389 100644 --- a/back/methods/notification/clean.js +++ b/back/methods/notification/clean.js @@ -32,7 +32,7 @@ module.exports = Self => { if (!config.cleanDays) return; - const cleanDate = new Date(); + const cleanDate = Date.vnNew(); cleanDate.setDate(cleanDate.getDate() - config.cleanDays); await models.NotificationQueue.destroyAll({ diff --git a/back/methods/notification/specs/clean.spec.js b/back/methods/notification/specs/clean.spec.js index 4c9dc563d..857886a64 100644 --- a/back/methods/notification/specs/clean.spec.js +++ b/back/methods/notification/specs/clean.spec.js @@ -10,7 +10,7 @@ describe('Notification Clean()', () => { const notification = await models.Notification.findOne({}, options); const notificationConfig = await models.NotificationConfig.findOne({}); - const cleanDate = new Date(); + const cleanDate = Date.vnNew(); cleanDate.setDate(cleanDate.getDate() - (notificationConfig.cleanDays + 1)); let before; diff --git a/back/models/image.js b/back/models/image.js index f7063c654..e8cab11aa 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -77,7 +77,7 @@ module.exports = Self => { const newImage = await Self.upsertWithWhere(data, { name: fileName, collectionFk: collectionName, - updated: (new Date).getTime() + updated: Date.vnNow() }, myOptions); // Resizes and saves the image diff --git a/back/models/notificationAcl.json b/back/models/notificationAcl.json index e3e97f52d..a20187961 100644 --- a/back/models/notificationAcl.json +++ b/back/models/notificationAcl.json @@ -6,6 +6,16 @@ "table": "util.notificationAcl" } }, + "properties":{ + "notificationFk": { + "id": true, + "type": "number" + }, + "roleFk":{ + "id": true, + "type": "number" + } + }, "relations": { "notification": { "type": "belongsTo", diff --git a/back/models/notificationSubscription.js b/back/models/notificationSubscription.js new file mode 100644 index 000000000..f1b2811fa --- /dev/null +++ b/back/models/notificationSubscription.js @@ -0,0 +1,62 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.observe('before save', async function(ctx) { + const models = Self.app.models; + const userId = ctx.options.accessToken.userId; + const user = await ctx.instance.userFk; + const modifiedUser = await getUserToModify(null, user, models); + + if (userId != modifiedUser.id && userId != modifiedUser.bossFk) + throw new UserError('You dont have permission to modify this user'); + }); + + Self.remoteMethod('deleteNotification', { + description: 'Deletes a notification subscription', + accepts: [ + { + arg: 'ctx', + type: 'object', + http: {source: 'context'} + }, + { + arg: 'notificationId', + type: 'number', + required: true + }, + ], + returns: { + type: 'object', + root: true + }, + http: { + verb: 'POST', + path: '/deleteNotification' + } + }); + + Self.deleteNotification = async function(ctx, notificationId) { + const models = Self.app.models; + const user = ctx.req.accessToken.userId; + const modifiedUser = await getUserToModify(notificationId, null, models); + + if (user != modifiedUser.id && user != modifiedUser.bossFk) + throw new UserError('You dont have permission to modify this user'); + + await models.NotificationSubscription.destroyById(notificationId); + }; + + async function getUserToModify(notificationId, userFk, models) { + let userToModify = userFk; + if (notificationId) { + const subscription = await models.NotificationSubscription.findById(notificationId); + userToModify = subscription.userFk; + } + return await models.Worker.findOne({ + fields: ['id', 'bossFk'], + where: { + id: userToModify + } + }); + } +}; diff --git a/back/models/notificationSubscription.json b/back/models/notificationSubscription.json index 43fa6db27..a640e0917 100644 --- a/back/models/notificationSubscription.json +++ b/back/models/notificationSubscription.json @@ -7,15 +7,18 @@ } }, "properties": { - "notificationFk": { + "id": { "type": "number", "id": true, - "description": "Identifier" + "description": "Primary key" + }, + "notificationFk": { + "type": "number", + "description": "Foreign key to Notification" }, "userFk": { "type": "number", - "id": true, - "description": "Identifier" + "description": "Foreign key to Account" } }, "relations": { diff --git a/back/models/specs/notificationSubscription.spec.js b/back/models/specs/notificationSubscription.spec.js new file mode 100644 index 000000000..c7f37abed --- /dev/null +++ b/back/models/specs/notificationSubscription.spec.js @@ -0,0 +1,74 @@ +const models = require('vn-loopback/server/server').models; + +describe('loopback model NotificationSubscription', () => { + it('Should fail to delete a notification if the user is not editing itself or a subordinate', async() => { + const tx = await models.NotificationSubscription.beginTransaction({}); + + try { + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 2; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + let error; + + try { + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + } catch (e) { + error = e; + } + + expect(error.message).toContain('You dont have permission to modify this user'); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('Should delete a notification if the user is editing itself', async() => { + const tx = await models.NotificationSubscription.beginTransaction({}); + + try { + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 4; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + + const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + expect(deletedNotification).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('Should delete a notification if the user is editing a subordinate', async() => { + const tx = await models.NotificationSubscription.beginTransaction({}); + + try { + const options = {transaction: tx}; + const user = 9; + const notificationSubscriptionId = 5; + const ctx = {req: {accessToken: {userId: user}}}; + const notification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + await models.NotificationSubscription.deleteNotification(ctx, notification.id, options); + + const deletedNotification = await models.NotificationSubscription.findById(notificationSubscriptionId); + + expect(deletedNotification).toBeNull(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); + diff --git a/db/changes/230201/00-SupplierUniqueKey.sql b/db/changes/230201/00-SupplierUniqueKey.sql new file mode 100644 index 000000000..9c0d4a192 --- /dev/null +++ b/db/changes/230201/00-SupplierUniqueKey.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`supplier` ADD UNIQUE (name, countryFk); diff --git a/db/changes/230201/00-kkearSaleChecked.sql b/db/changes/230201/00-kkearSaleChecked.sql index 03e854bbd..3ea107da5 100644 --- a/db/changes/230201/00-kkearSaleChecked.sql +++ b/db/changes/230201/00-kkearSaleChecked.sql @@ -1,2 +1,173 @@ DELETE FROM `salix`.`ACL` WHERE model="SaleChecked"; DROP TABLE IF EXISTS `vn`.`saleChecked`; +DROP PROCEDURE IF EXISTS `vn`.`clean`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`clean`() +BEGIN + DECLARE vDateShort DATETIME; + DECLARE vOneYearAgo DATE; + DECLARE vFourYearsAgo DATE; + DECLARE v18Month DATE; + DECLARE v26Month DATE; + DECLARE v3Month DATE; + DECLARE vTrashId VARCHAR(15); + + SET vDateShort = util.VN_CURDATE() - INTERVAL 2 MONTH; + SET vOneYearAgo = util.VN_CURDATE() - INTERVAL 1 YEAR; + SET vFourYearsAgo = util.VN_CURDATE() - INTERVAL 4 YEAR; + SET v18Month = util.VN_CURDATE() - INTERVAL 18 MONTH; + SET v26Month = util.VN_CURDATE() - INTERVAL 26 MONTH; + SET v3Month = util.VN_CURDATE() - INTERVAL 3 MONTH; + + DELETE FROM ticketParking WHERE created < vDateShort; + DELETE FROM routesMonitor WHERE dated < vDateShort; + DELETE FROM workerTimeControlLog WHERE created < vDateShort; + DELETE FROM `message` WHERE sendDate < vDateShort; + DELETE FROM messageInbox WHERE sendDate < vDateShort; + DELETE FROM messageInbox WHERE sendDate < vDateShort; + DELETE FROM workerTimeControl WHERE timed < vFourYearsAgo; + DELETE FROM itemShelving WHERE created < util.VN_CURDATE() AND visible = 0; + DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); + DELETE FROM entryLog WHERE creationDate < vDateShort; + DELETE IGNORE FROM expedition WHERE created < v26Month; + DELETE FROM sms WHERE created < v18Month; + DELETE FROM saleTracking WHERE created < vOneYearAgo; + DELETE FROM ticketTracking WHERE created < v18Month; + DELETE tobs FROM ticketObservation tobs + JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; + DELETE FROM sharingCart where ended < vDateShort; + DELETE FROM sharingClient where ended < vDateShort; + DELETE tw.* FROM ticketWeekly tw + LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL; + DELETE FROM claim WHERE ticketCreated < vFourYearsAgo; + DELETE FROM message WHERE sendDate < vDateShort; + -- Robert ubicacion anterior de trevelLog comentario para debug + DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Month; + DELETE bm + FROM buyMark bm + JOIN buy b ON b.id = bm.id + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed <= vDateShort; + DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200; + DELETE FROM vn.itemShelvingLog WHERE created < vDateShort; + DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort; + DELETE FROM vn.itemCleanLog WHERE created < util.VN_NOW() - INTERVAL 1 YEAR; + DELETE FROM printQueue WHERE statusCode = 'printed' AND created < vDateShort; + + -- Equipos duplicados + DELETE w.* + FROM workerTeam w + JOIN (SELECT id, team, workerFk, COUNT(*) - 1 as duplicated + FROM workerTeam + GROUP BY team,workerFk + HAVING duplicated + ) d ON d.team = w.team AND d.workerFk = w.workerFk AND d.id != w.id; + + DELETE sc + FROM saleComponent sc + JOIN sale s ON s.id= sc.saleFk + JOIN ticket t ON t.id= s.ticketFk + WHERE t.shipped < v18Month; + + DELETE c + FROM vn.claim c + JOIN vn.claimState cs ON cs.id = c.claimStateFk + WHERE cs.description = "Anulado" AND + c.created < vDateShort; + DELETE + FROM vn.expeditionTruck + WHERE ETD < v3Month; + + -- borrar travels sin entradas + DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; + CREATE TEMPORARY TABLE tmp.thermographToDelete + SELECT th.id,th.dmsFk + FROM vn.travel t + LEFT JOIN vn.entry e ON e.travelFk = t.id + JOIN vn.travelThermograph th ON th.travelFk = t.id + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; + + SELECT dt.id INTO vTrashId + FROM vn.dmsType dt + WHERE dt.code = 'trash'; + + UPDATE tmp.thermographToDelete th + JOIN vn.dms d ON d.id = th.dmsFk + SET d.dmsTypeFk = vTrashId; + + DELETE th + FROM tmp.thermographToDelete tmp + JOIN vn.travelThermograph th ON th.id = tmp.id; + + DELETE t + FROM vn.travel t + LEFT JOIN vn.entry e ON e.travelFk = t.id + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; + + UPDATE dms d + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId + WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, util.VN_CURDATE()); + + -- borrar entradas sin compras + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + CREATE TEMPORARY TABLE tmp.entryToDelete + SELECT e.* + FROM vn.entry e + LEFT JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.entryConfig ec ON e.id != ec.defaultEntry + WHERE e.dated < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND b.entryFK IS NULL; + + DELETE e + FROM vn.entry e + JOIN tmp.entryToDelete tmp ON tmp.id = e.id; + + -- borrar de route registros menores a 4 años + DROP TEMPORARY TABLE IF EXISTS tmp.routeToDelete; + CREATE TEMPORARY TABLE tmp.routeToDelete + SELECT * + FROM vn.route r + WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); + + UPDATE tmp.routeToDelete tmp + JOIN vn.dms d ON d.id = tmp.gestdocFk + SET d.dmsTypeFk = vTrashId; + + DELETE r + FROM tmp.routeToDelete tmp + JOIN vn.route r ON r.id = tmp.id; + + -- borrar registros de dua y awb menores a 2 años + DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; + CREATE TEMPORARY TABLE tmp.duaToDelete + SELECT * + FROM vn.dua + WHERE operated < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + + UPDATE tmp.duaToDelete tm + JOIN vn.dms d ON d.id = tm.gestdocFk + SET d.dmsTypeFk = vTrashId; + + DELETE d + FROM tmp.duaToDelete tmp + JOIN vn.dua d ON d.id = tmp.id; + + DELETE FROM vn.awb WHERE created < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + + -- Borra los registros de collection y ticketcollection + DELETE FROM vn.collection WHERE created < vDateShort; + + DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; + + DELETE FROM travelLog WHERE creationDate < v3Month; + + CALL shelving_clean; + +END$$ +DELIMITER ; diff --git a/db/changes/230202/00-itemConfig.sql b/db/changes/230202/00-itemConfig.sql new file mode 100644 index 000000000..a793997d0 --- /dev/null +++ b/db/changes/230202/00-itemConfig.sql @@ -0,0 +1,9 @@ +ALTER TABLE `vn`.`itemConfig` ADD defaultTag INT DEFAULT 56 NOT NULL; +ALTER TABLE `vn`.`itemConfig` ADD CONSTRAINT itemConfig_FK FOREIGN KEY (defaultTag) REFERENCES vn.tag(id); +ALTER TABLE `vn`.`itemConfig` ADD validPriorities varchar(50) DEFAULT '[1,2,3]' NOT NULL; +ALTER TABLE `vn`.`itemConfig` ADD defaultPriority INT DEFAULT 2 NOT NULL; +ALTER TABLE `vn`.`item` MODIFY COLUMN relevancy tinyint(1) DEFAULT 0 NOT NULL COMMENT 'La web ordena de forma descendiente por este campo para mostrar los artículos'; + +INSERT INTO `salix`.`ACL` +(model, property, accessType, permission, principalType, principalId) +VALUES('ItemConfig', '*', 'READ', 'ALLOW', 'ROLE', 'buyer'); diff --git a/db/changes/230401/00-acl_notifications.sql b/db/changes/230401/00-acl_notifications.sql new file mode 100644 index 000000000..ab40b16a5 --- /dev/null +++ b/db/changes/230401/00-acl_notifications.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model,property,accessType,principalId) + VALUES + ('NotificationSubscription','*','*','employee'), + ('NotificationAcl','*','READ','employee'); diff --git a/db/changes/230401/00-ticket_canAdvance.sql b/db/changes/230401/00-ticket_canAdvance.sql new file mode 100644 index 000000000..fd9d451bf --- /dev/null +++ b/db/changes/230401/00-ticket_canAdvance.sql @@ -0,0 +1,110 @@ +DROP PROCEDURE IF EXISTS vn.ticket_canAdvance; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT) +BEGIN +/** + * Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar. + * + * @param vDateFuture Fecha de los tickets que se quieren adelantar. + * @param vDateToAdvance Fecha a cuando se quiere adelantar. + * @param vWarehouseFk Almacén + */ + + DECLARE vDateInventory DATE; + + SELECT inventoried INTO vDateInventory FROM vn.config; + + DROP TEMPORARY TABLE IF EXISTS tmp.stock; + CREATE TEMPORARY TABLE tmp.stock + (itemFk INT PRIMARY KEY, + amount INT) + ENGINE = MEMORY; + + INSERT INTO tmp.stock(itemFk, amount) + SELECT itemFk, SUM(quantity) amount FROM + ( + SELECT itemFk, quantity + FROM vn.itemTicketOut + WHERE shipped >= vDateInventory + AND shipped < vDateFuture + AND warehouseFk = vWarehouseFk + UNION ALL + SELECT itemFk, quantity + FROM vn.itemEntryIn + WHERE landed >= vDateInventory + AND landed < vDateFuture + AND isVirtualStock = FALSE + AND warehouseInFk = vWarehouseFk + UNION ALL + SELECT itemFk, quantity + FROM vn.itemEntryOut + WHERE shipped >= vDateInventory + AND shipped < vDateFuture + AND warehouseOutFk = vWarehouseFk + ) t + GROUP BY itemFk HAVING amount != 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.filter; + CREATE TEMPORARY TABLE tmp.filter + (INDEX (id)) + SELECT s.ticketFk futureId, + t2.ticketFk id, + count(DISTINCT s.id) saleCount, + t2.state, + t2.isNotValidated, + st.name futureState, + st.isNotValidated futureIsNotValidated, + GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, + t2.ipt, + t.workerFk, + CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, + CAST(COUNT(*) AS DECIMAL(10,0)) `futureLines`, + t2.shipped, + t.shipped futureShipped, + t2.totalWithVat, + t.totalWithVat futureTotalWithVat, + t2.agency, + am.name futureAgency, + t2.lines, + t2.liters, + SUM((s.quantity <= IFNULL(st.amount,0))) hasStock + FROM vn.ticket t + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.saleVolume sv ON t.id = sv.ticketFk + JOIN (SELECT + t2.id ticketFk, + t2.addressFk, + st.isNotValidated, + st.name state, + GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt, + t2.shipped, + t2.totalWithVat, + am.name agency, + CAST(SUM(litros) AS DECIMAL(10,0)) liters, + CAST(COUNT(*) AS DECIMAL(10,0)) `lines` + FROM vn.ticket t2 + JOIN vn.saleVolume sv ON t2.id = sv.ticketFk + JOIN vn.sale s ON s.ticketFk = t2.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticketState ts ON ts.ticketFk = t2.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.agencyMode am ON t2.agencyModeFk = am.id + LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance) + AND t2.warehouseFk = vWarehouseFk + GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.agencyMode am ON t.agencyModeFk = am.id + LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk + LEFT JOIN tmp.stock st ON st.itemFk = s.itemFk + WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) + AND t.warehouseFk = vWarehouseFk + GROUP BY t.id; + + DROP TEMPORARY TABLE tmp.stock; +END$$ +DELIMITER ; diff --git a/db/changes/230401/00-uniqueKeyNotificationSubscription.sql b/db/changes/230401/00-uniqueKeyNotificationSubscription.sql new file mode 100644 index 000000000..623ecf770 --- /dev/null +++ b/db/changes/230401/00-uniqueKeyNotificationSubscription.sql @@ -0,0 +1,4 @@ +ALTER TABLE + `util`.`notificationSubscription` +ADD + CONSTRAINT `notificationSubscription_UN` UNIQUE KEY (`notificationFk`, `userFk`); \ No newline at end of file diff --git a/db/changes/230401/00-updateIsToBeMailed.sql b/db/changes/230401/00-updateIsToBeMailed.sql new file mode 100644 index 000000000..1bb177f57 --- /dev/null +++ b/db/changes/230401/00-updateIsToBeMailed.sql @@ -0,0 +1,6 @@ +UPDATE `vn`.`client` + SET isToBeMailed = FALSE + WHERE + mailAddress is NULL + AND email is NULL + AND isToBeMailed = TRUE; diff --git a/db/changes/230401/01-alter_notSubs.sql b/db/changes/230401/01-alter_notSubs.sql new file mode 100644 index 000000000..07ea7c2bf --- /dev/null +++ b/db/changes/230401/01-alter_notSubs.sql @@ -0,0 +1,7 @@ +ALTER TABLE `util`.`notificationSubscription` +ADD `id` int(11) auto_increment NULL, +DROP PRIMARY KEY, +ADD CONSTRAINT PRIMARY KEY (`id`); + +ALTER TABLE `util`.`notificationSubscription` +ADD KEY `notificationSubscription_ibfk_1` (`notificationFk`); diff --git a/front/salix/services/index.js b/db/changes/230601/.gitkeep similarity index 100% rename from front/salix/services/index.js rename to db/changes/230601/.gitkeep diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 218fcb9ca..5c7bbf192 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2,7 +2,33 @@ CREATE SCHEMA IF NOT EXISTS `vn2008`; CREATE SCHEMA IF NOT EXISTS `tmp`; UPDATE `util`.`config` - SET `environment`= 'test'; + SET `environment`= 'development'; + +-- FOR MOCK vn.time + +DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`mockVnTime`() +BEGIN + + DECLARE vDate DATE; + SET vDate = '2000-01-01'; + + WHILE ( YEAR(vDate) <= 2002 ) DO + INSERT IGNORE INTO vn.`time` (dated, period, `month`, `year`, `day`, week, yearMonth, salesYear) + VALUES (vDate, CONCAT(YEAR(vDate), (WEEK(vDate)+1)), MONTH(vDate), YEAR(vDate), DAY(vDate), WEEK(vDate)+1, CONCAT(YEAR(vDate), MONTH(vDate)), YEAR(vDate)); + + SET vDate = DATE_ADD(vDate, INTERVAL 1 DAY); + END WHILE; + +END$$ +DELIMITER ; + +CALL `vn`.`mockVnTime`(); +DROP PROCEDURE IF EXISTS `vn`.`mockVnTime`; +-- END MOCK vn.time ALTER TABLE `vn`.`itemTaxCountry` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; @@ -934,10 +960,10 @@ INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), - (10, 7, 7, 71, NOW(), 1, 18, NULL, 94, 3, NULL), - (11, 7, 8, 71, NOW(), 1, 18, NULL, 94, 3, NULL), - (12, 7, 9, 71, NOW(), 1, 18, NULL, 94, 3, NULL), - (13, 1, 10,71, NOW(), 1, 18, NULL, 94, 3, NULL); + (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) @@ -1910,7 +1936,7 @@ DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +1 YEAR)), '-12-25'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` + SELECT w.id, w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL +1 YEAR)), '-12-25') as ended, CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` FROM `vn`.`worker` `w`; INSERT INTO `vn`.`business`(`id`, `workerFk`, `companyCodeFk`, `started`, `ended`, `workerBusiness`, `reasonEndFk`, `notes`, `departmentFk`, `workerBusinessProfessionalCategoryFk`, `calendarTypeFk`, `isHourlyLabor`, `workerBusinessAgreementFk`, `workcenterFk`) @@ -1920,7 +1946,7 @@ DROP TEMPORARY TABLE IF EXISTS tmp.worker; CREATE TEMPORARY TABLE tmp.worker (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -2 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-24'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` + SELECT '1111' as 'id', w.id as `workerFk`, 'VNL', CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -2 YEAR)), '-12-25') as started, CONCAT(YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 YEAR)) as ended, '-12-24'), CONCAT('E-46-', RPAD(CONCAT(w.id, 9), 8, w.id)), NULL as `notes`, NULL as `departmentFk`, 23, 1 as `workerBusinessProfessionalCategoryFk`, 1 as `calendarTypeFk`, 1 as `isHourlyLabor`, 1 as `workerBusinessAgreementFk`, 1 as `workcenterFk` FROM `vn`.`worker` `w` WHERE `w`.`id` = 1109; @@ -1954,10 +1980,6 @@ INSERT INTO `vn`.`workerBusinessType` (`id`, `name`, `isFullTime`, `isPermanent` (100, 'INDEFINIDO A TIEMPO COMPLETO', 1, 1, 1), (109, 'CONVERSION DE TEMPORAL EN INDEFINIDO T.COMPLETO', 1, 1, 1); -INSERT INTO `vn`.`businessCategory` (`id`, `description`, `rate`) - VALUES - (1, 'basic employee', 1); - UPDATE `vn`.`business` b SET `rate` = 7, `workerBusinessCategoryFk` = 1, @@ -2705,7 +2727,10 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) VALUES (1, 1109), (1, 1110), - (3, 1109); + (3, 1109), + (1,9), + (1,3); + INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES diff --git a/db/dump/mockDate.sql b/db/dump/mockDate.sql index c63c2d76c..937da071c 100644 --- a/db/dump/mockDate.sql +++ b/db/dump/mockDate.sql @@ -3,18 +3,17 @@ USE `util`; DELIMITER ;; DROP FUNCTION IF EXISTS `util`.`mockedDate`; -CREATE FUNCTION `util`.`mockedDate`() +CREATE FUNCTION `util`.`mockedDate`() RETURNS DATETIME DETERMINISTIC BEGIN - RETURN NOW(); - -- '2022-01-19 08:00:00' + RETURN CONVERT_TZ('2001-01-01 11:00:00', 'utc', 'Europe/Madrid'); END ;; DELIMITER ; DELIMITER ;; DROP FUNCTION IF EXISTS `util`.`VN_CURDATE`; -CREATE FUNCTION `util`.`VN_CURDATE`() +CREATE FUNCTION `util`.`VN_CURDATE`() RETURNS DATE DETERMINISTIC BEGIN @@ -24,7 +23,7 @@ DELIMITER ; DELIMITER ;; DROP FUNCTION IF EXISTS `util`.`VN_CURTIME`; -CREATE FUNCTION `util`.`VN_CURTIME`() +CREATE FUNCTION `util`.`VN_CURTIME`() RETURNS TIME DETERMINISTIC BEGIN @@ -34,10 +33,10 @@ DELIMITER ; DELIMITER ;; DROP FUNCTION IF EXISTS `util`.`VN_NOW`; -CREATE FUNCTION `util`.`VN_NOW`() +CREATE FUNCTION `util`.`VN_NOW`() RETURNS DATETIME DETERMINISTIC BEGIN - RETURN mockedDate(); + RETURN mockedDate(); END ;; -DELIMITER ; \ No newline at end of file +DELIMITER ; diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 772d6055d..4626279e4 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -80203,4 +80203,3 @@ USE `vncontrol`; -- Dump completed on 2022-11-21 7:57:28 - diff --git a/db/tests/vn/buyUltimate.spec.js b/db/tests/vn/buyUltimate.spec.js index e0b3fa568..4c98945c1 100644 --- a/db/tests/vn/buyUltimate.spec.js +++ b/db/tests/vn/buyUltimate.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('buyUltimate()', () => { - const today = new Date(); + const today = Date.vnNew(); it(`should create buyUltimate temporal table and update it's values`, async() => { let stmts = []; let stmt; diff --git a/db/tests/vn/buyUltimateFromInterval.spec.js b/db/tests/vn/buyUltimateFromInterval.spec.js index b5e6970f7..7a4a79d47 100644 --- a/db/tests/vn/buyUltimateFromInterval.spec.js +++ b/db/tests/vn/buyUltimateFromInterval.spec.js @@ -5,7 +5,7 @@ describe('buyUltimateFromInterval()', () => { let today; let future; beforeAll(() => { - let now = new Date(); + let now = Date.vnNew(); now.setHours(0, 0, 0, 0); today = now; diff --git a/db/tests/vn/ticketCalculateClon.spec.js b/db/tests/vn/ticketCalculateClon.spec.js index 03814682d..a3c790492 100644 --- a/db/tests/vn/ticketCalculateClon.spec.js +++ b/db/tests/vn/ticketCalculateClon.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('ticket ticketCalculateClon()', () => { - const today = new Date(); + const today = Date.vnNew(); it('should add the ticket to the order containing the original ticket', async() => { let stmts = []; let stmt; diff --git a/db/tests/vn/ticketCreateWithUser.spec.js b/db/tests/vn/ticketCreateWithUser.spec.js index 1c13be1b3..4aeece564 100644 --- a/db/tests/vn/ticketCreateWithUser.spec.js +++ b/db/tests/vn/ticketCreateWithUser.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('ticket ticketCreateWithUser()', () => { - const today = new Date(); + const today = Date.vnNew(); it('should confirm the procedure creates the expected ticket', async() => { let stmts = []; let stmt; diff --git a/db/tests/vn/timeBusiness_calculateByUser.spec.js b/db/tests/vn/timeBusiness_calculateByUser.spec.js index 441f567ac..5fe51d8f8 100644 --- a/db/tests/vn/timeBusiness_calculateByUser.spec.js +++ b/db/tests/vn/timeBusiness_calculateByUser.spec.js @@ -3,9 +3,9 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('timeBusiness_calculateByUser()', () => { it('should return the expected hours for today', async() => { - let start = new Date(); + let start = Date.vnNew(); start.setHours(0, 0, 0, 0); - let end = new Date(); + let end = Date.vnNew(); end.setHours(0, 0, 0, 0); let stmts = []; diff --git a/db/tests/vn/timeControl_calculateByUser.spec.js b/db/tests/vn/timeControl_calculateByUser.spec.js index 2aa16c7a4..73e00ec3a 100644 --- a/db/tests/vn/timeControl_calculateByUser.spec.js +++ b/db/tests/vn/timeControl_calculateByUser.spec.js @@ -3,11 +3,11 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; describe('timeControl_calculateByUser()', () => { it(`should return today's worked hours`, async() => { - let start = new Date(); + let start = Date.vnNew(); start.setHours(0, 0, 0, 0); start.setDate(start.getDate() - 1); - let end = new Date(); + let end = Date.vnNew(); end.setHours(0, 0, 0, 0); end.setDate(end.getDate() + 1); @@ -17,7 +17,7 @@ describe('timeControl_calculateByUser()', () => { stmts.push('START TRANSACTION'); stmts.push(` - DROP TEMPORARY TABLE IF EXISTS + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate, tmp.timeBusinessCalculate `); @@ -48,14 +48,14 @@ describe('timeControl_calculateByUser()', () => { }); it(`should return the worked hours between last sunday and monday`, async() => { - let lastSunday = new Date(); + let lastSunday = Date.vnNew(); let daysSinceSunday = lastSunday.getDay(); if (daysSinceSunday === 0) // this means today is sunday but you need the previous sunday :) daysSinceSunday = 7; lastSunday.setHours(23, 0, 0, 0); lastSunday.setDate(lastSunday.getDate() - daysSinceSunday); - let monday = new Date(); + let monday = Date.vnNew(); let daysSinceMonday = daysSinceSunday - 1; // aiming for monday (today could be monday) monday.setHours(7, 0, 0, 0); monday.setDate(monday.getDate() - daysSinceMonday); @@ -66,7 +66,7 @@ describe('timeControl_calculateByUser()', () => { stmts.push('START TRANSACTION'); stmts.push(` - DROP TEMPORARY TABLE IF EXISTS + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate, tmp.timeBusinessCalculate `); diff --git a/db/tests/vn/zone_getLanded.spec.js b/db/tests/vn/zone_getLanded.spec.js index 5f82156d3..888d7c132 100644 --- a/db/tests/vn/zone_getLanded.spec.js +++ b/db/tests/vn/zone_getLanded.spec.js @@ -6,7 +6,7 @@ describe('zone zone_getLanded()', () => { let stmts = []; let stmt; stmts.push('START TRANSACTION'); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); let params = { @@ -40,7 +40,7 @@ describe('zone zone_getLanded()', () => { it(`should return data for a shipped tomorrow`, async() => { let stmts = []; let stmt; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); stmts.push('START TRANSACTION'); diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index 7bf56e2c8..7d80c69ee 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -436,7 +436,7 @@ let actions = { }, pickDate: async function(selector, date) { - date = date || new Date(); + date = date || Date.vnNew(); const timeZoneOffset = date.getTimezoneOffset() * 60000; const localDate = (new Date(date.getTime() - timeZoneOffset)) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a1412f431..8f9fcda57 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -31,7 +31,7 @@ export default { }, recoverPassword: { recoverPasswordButton: 'vn-login a[ui-sref="recover-password"]', - email: 'vn-recover-password vn-textfield[ng-model="$ctrl.email"]', + email: 'vn-recover-password vn-textfield[ng-model="$ctrl.user"]', sendEmailButton: 'vn-recover-password vn-submit', }, accountIndex: { @@ -562,15 +562,15 @@ export default { payoutBank: '.vn-dialog vn-autocomplete[ng-model="$ctrl.bankFk"]', payoutDescription: 'vn-textfield[ng-model="$ctrl.receipt.description"]', submitPayout: '.vn-dialog button[response="accept"]', - searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr', + searchWeeklyResult: 'vn-ticket-weekly-index vn-card smart-table slot-table table tbody tr', searchResultDate: 'vn-ticket-summary [label=Landed] span', topbarSearch: 'vn-searchbar', moreMenu: 'vn-ticket-index vn-icon-button[icon=more_vert]', - fourthWeeklyTicket: 'vn-ticket-weekly-index vn-table vn-tbody vn-tr:nth-child(4)', - fiveWeeklyTicket: 'vn-ticket-weekly-index vn-table vn-tbody vn-tr:nth-child(5)', - weeklyTicket: 'vn-ticket-weekly-index vn-table > div > vn-tbody > vn-tr', - firstWeeklyTicketDeleteIcon: 'vn-ticket-weekly-index vn-tr:nth-child(1) vn-icon-button[icon="delete"]', - firstWeeklyTicketAgency: 'vn-ticket-weekly-index vn-tr:nth-child(1) [ng-model="weekly.agencyModeFk"]', + fourthWeeklyTicket: 'vn-ticket-weekly-index vn-card smart-table slot-table tr:nth-child(4)', + fiveWeeklyTicket: 'vn-ticket-weekly-index vn-card smart-table slot-table tr:nth-child(5)', + weeklyTicket: 'vn-ticket-weekly-index vn-card smart-table slot-table table tbody tr', + firstWeeklyTicketDeleteIcon: 'vn-ticket-weekly-index vn-card smart-table slot-table tr:nth-child(1) vn-icon-button[icon="delete"]', + firstWeeklyTicketAgency: 'vn-ticket-weekly-index vn-card smart-table slot-table tr:nth-child(1) [ng-model="weekly.agencyModeFk"]', acceptDeleteTurn: '.vn-confirm.shown button[response="accept"]' }, createTicketView: { @@ -778,8 +778,8 @@ export default { ipt: 'vn-autocomplete[label="Destination IPT"]', tableIpt: 'vn-autocomplete[name="ipt"]', tableFutureIpt: 'vn-autocomplete[name="futureIpt"]', - futureState: 'vn-autocomplete[label="Origin Grouped State"]', - state: 'vn-autocomplete[label="Destination Grouped State"]', + futureState: 'vn-check[label="Pending Origin"]', + state: 'vn-check[label="Pending Destination"]', warehouseFk: 'vn-autocomplete[label="Warehouse"]', tableButtonSearch: 'vn-button[vn-tooltip="Search"]', moveButton: 'vn-button[vn-tooltip="Advance tickets"]', @@ -944,9 +944,9 @@ export default { routeSummary: { header: 'vn-route-summary > vn-card > h5', cost: 'vn-route-summary vn-label-value[label="Cost"]', - firstTicketID: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(2) > span', + firstTicketID: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(10) > span', firstTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor', - firstAlias: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(3) > span', + firstAlias: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(5) > span', firstClientDescriptor: '.vn-popover.shown vn-client-descriptor', goToRouteSummaryButton: 'vn-route-summary > vn-card > h5 > a', @@ -1260,6 +1260,21 @@ export default { importBuysButton: 'vn-entry-buy-import button[type="submit"]' }, entryLatestBuys: { + table: 'tbody > tr:not(.empty-rows)', + chip: 'vn-chip > vn-icon', + generalSearchInput: 'vn-textfield[ng-model="$ctrl.filter.search"]', + firstReignIcon: 'vn-horizontal.item-category vn-one', + typeInput: 'vn-autocomplete[ng-model="$ctrl.filter.typeFk"]', + salesPersonInput: 'vn-autocomplete[ng-model="$ctrl.filter.salesPersonFk"]', + supplierInput: 'vn-autocomplete[ng-model="$ctrl.filter.supplierFk"]', + fromInput: 'vn-date-picker[ng-model="$ctrl.filter.from"]', + toInput: 'vn-date-picker[ng-model="$ctrl.filter.to"]', + activeCheck: 'vn-check[ng-model="$ctrl.filter.active"]', + floramondoCheck: 'vn-check[ng-model="$ctrl.filter.floramondo"]', + visibleCheck: 'vn-check[ng-model="$ctrl.filter.visible"]', + addTagButton: 'vn-icon-button[vn-tooltip="Add tag"]', + itemTagInput: 'vn-autocomplete[ng-model="itemTag.tagFk"]', + itemTagValueInput: 'vn-autocomplete[ng-model="itemTag.value"]', firstBuy: 'vn-entry-latest-buys tbody > tr:nth-child(1)', allBuysCheckBox: 'vn-entry-latest-buys thead vn-check', secondBuyCheckBox: 'vn-entry-latest-buys tbody tr:nth-child(2) vn-check[ng-model="buy.checked"]', diff --git a/e2e/helpers/tests.js b/e2e/helpers/tests.js index aac9963dd..992ec051f 100644 --- a/e2e/helpers/tests.js +++ b/e2e/helpers/tests.js @@ -1,6 +1,7 @@ require('@babel/register')({presets: ['@babel/env']}); require('core-js/stable'); require('regenerator-runtime/runtime'); +require('vn-loopback/server/boot/date')(); const axios = require('axios'); const Docker = require('../../db/docker.js'); diff --git a/e2e/paths/01-salix/04_recoverPassword.spec.js b/e2e/paths/01-salix/04_recoverPassword.spec.js index e6cb02ab1..aa0389648 100644 --- a/e2e/paths/01-salix/04_recoverPassword.spec.js +++ b/e2e/paths/01-salix/04_recoverPassword.spec.js @@ -26,7 +26,7 @@ describe('RecoverPassword path', async() => { expect(message.text).toContain('Notification sent!'); }); - it('should send email', async() => { + it('should send email using email', async() => { await page.waitForState('login'); await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); @@ -37,4 +37,16 @@ describe('RecoverPassword path', async() => { expect(message.text).toContain('Notification sent!'); }); + + it('should send email using username', async() => { + await page.waitForState('login'); + await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); + + await page.write(selectors.recoverPassword.email, 'BruceWayne'); + await page.waitToClick(selectors.recoverPassword.sendEmailButton); + const message = await page.waitForSnackbar(); + await page.waitForState('login'); + + expect(message.text).toContain('Notification sent!'); + }); }); diff --git a/e2e/paths/02-client/20_credit_insurance.spec.js b/e2e/paths/02-client/20_credit_insurance.spec.js index 904a51145..a4f148b8f 100644 --- a/e2e/paths/02-client/20_credit_insurance.spec.js +++ b/e2e/paths/02-client/20_credit_insurance.spec.js @@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer'; describe('Client credit insurance path', () => { let browser; let page; - let previousMonth = new Date(); + let previousMonth = Date.vnNew(); previousMonth.setMonth(previousMonth.getMonth() - 1); beforeAll(async() => { diff --git a/e2e/paths/03-worker/04_time_control.spec.js b/e2e/paths/03-worker/04_time_control.spec.js index b5da799fc..eb1417ba9 100644 --- a/e2e/paths/03-worker/04_time_control.spec.js +++ b/e2e/paths/03-worker/04_time_control.spec.js @@ -22,7 +22,7 @@ describe('Worker time control path', () => { const hankPymId = 1107; it('should go to the next month, go to current month and go 1 month in the past', async() => { - let date = new Date(); + let date = Date.vnNew(); date.setDate(1); date.setMonth(date.getMonth() + 1); let month = date.toLocaleString('default', {month: 'long'}); @@ -32,7 +32,7 @@ describe('Worker time control path', () => { expect(result).toContain(month); - date = new Date(); + date = Date.vnNew(); date.setDate(1); month = date.toLocaleString('default', {month: 'long'}); @@ -41,7 +41,7 @@ describe('Worker time control path', () => { expect(result).toContain(month); - date = new Date(); + date = Date.vnNew(); date.setDate(1); date.setMonth(date.getMonth() - 1); const timestamp = Math.round(date.getTime() / 1000); diff --git a/e2e/paths/03-worker/05_calendar.spec.js b/e2e/paths/03-worker/05_calendar.spec.js index c310baf5a..f0af0a053 100644 --- a/e2e/paths/03-worker/05_calendar.spec.js +++ b/e2e/paths/03-worker/05_calendar.spec.js @@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer'; describe('Worker calendar path', () => { const reasonableTimeBetweenClicks = 300; - const date = new Date(); + const date = Date.vnNew(); const lastYear = (date.getFullYear() - 1).toString(); let browser; diff --git a/e2e/paths/04-item/13_fixedPrice.spec.js b/e2e/paths/04-item/13_fixedPrice.spec.js index 40ccc009e..1b0f82d83 100644 --- a/e2e/paths/04-item/13_fixedPrice.spec.js +++ b/e2e/paths/04-item/13_fixedPrice.spec.js @@ -22,7 +22,7 @@ describe('Item fixed prices path', () => { }); it('should fill the fixed price data', async() => { - const now = new Date(); + const now = Date.vnNew(); await page.autocompleteSearch(selectors.itemFixedPrice.fourthWarehouse, 'Warehouse one'); await page.writeOnEditableTD(selectors.itemFixedPrice.fourthGroupingPrice, '1'); await page.writeOnEditableTD(selectors.itemFixedPrice.fourthPackingPrice, '1'); diff --git a/e2e/paths/05-ticket/06_basic_data_steps.spec.js b/e2e/paths/05-ticket/06_basic_data_steps.spec.js index fa901e325..55aec45fb 100644 --- a/e2e/paths/05-ticket/06_basic_data_steps.spec.js +++ b/e2e/paths/05-ticket/06_basic_data_steps.spec.js @@ -93,7 +93,7 @@ describe('Ticket Edit basic data path', () => { it(`should split ticket without negatives`, async() => { const newAgency = 'Gotham247'; - const newDate = new Date(); + const newDate = Date.vnNew(); newDate.setDate(newDate.getDate() - 1); await page.accessToSearchResult('14'); @@ -127,7 +127,7 @@ describe('Ticket Edit basic data path', () => { }); it(`should old ticket have old date and agency`, async() => { - const oldDate = new Date(); + const oldDate = Date.vnNew(); const oldAgency = 'Super-Man delivery'; await page.accessToSearchResult('14'); diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index 48b4ebdd0..80c288a01 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer'; describe('Ticket create path', () => { let browser; let page; - let nextMonth = new Date(); + let nextMonth = Date.vnNew(); nextMonth.setMonth(nextMonth.getMonth() + 1); beforeAll(async() => { diff --git a/e2e/paths/05-ticket/18_index_payout.spec.js b/e2e/paths/05-ticket/18_index_payout.spec.js index 220dacf61..89b5937a1 100644 --- a/e2e/paths/05-ticket/18_index_payout.spec.js +++ b/e2e/paths/05-ticket/18_index_payout.spec.js @@ -63,6 +63,6 @@ describe('Ticket index payout path', () => { const reference = await page.waitToGetProperty(selectors.clientBalance.firstLineReference, 'innerText'); expect(count).toEqual(4); - expect(reference).toContain('Cash, Albaran: 7, 8Payment'); + expect(reference).toContain('Cash,Albaran: 7, 8Payment'); }); }); diff --git a/e2e/paths/05-ticket/22_advance.spec.js b/e2e/paths/05-ticket/22_advance.spec.js index 6aaa81591..3a6234fe9 100644 --- a/e2e/paths/05-ticket/22_advance.spec.js +++ b/e2e/paths/05-ticket/22_advance.spec.js @@ -50,7 +50,7 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.autocompleteSearch(selectors.ticketAdvance.ipt, 'Horizontal'); await page.waitToClick(selectors.ticketAdvance.submit); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 0); + await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.clearInput(selectors.ticketAdvance.ipt); @@ -62,7 +62,7 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.autocompleteSearch(selectors.ticketAdvance.futureIpt, 'Horizontal'); await page.waitToClick(selectors.ticketAdvance.submit); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 0); + await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.clearInput(selectors.ticketAdvance.futureIpt); @@ -70,26 +70,36 @@ describe('Ticket Advance path', () => { await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); }); - it('should search with the origin grouped state', async() => { + it('should search with the origin pending state', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.autocompleteSearch(selectors.ticketAdvance.futureState, 'Free'); + await page.waitToClick(selectors.ticketAdvance.futureState); await page.waitToClick(selectors.ticketAdvance.submit); await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.clearInput(selectors.ticketAdvance.futureState); + await page.waitToClick(selectors.ticketAdvance.futureState); + await page.waitToClick(selectors.ticketAdvance.submit); + await page.waitForNumberOfElements(selectors.ticketAdvance.table, 0); + + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketAdvance.futureState); await page.waitToClick(selectors.ticketAdvance.submit); await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); }); it('should search with the destination grouped state', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.autocompleteSearch(selectors.ticketAdvance.state, 'Free'); + await page.waitToClick(selectors.ticketAdvance.state); await page.waitToClick(selectors.ticketAdvance.submit); await page.waitForNumberOfElements(selectors.ticketAdvance.table, 0); await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.clearInput(selectors.ticketAdvance.state); + await page.waitToClick(selectors.ticketAdvance.state); + await page.waitToClick(selectors.ticketAdvance.submit); + await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); + + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketAdvance.state); await page.waitToClick(selectors.ticketAdvance.submit); await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); }); @@ -116,42 +126,7 @@ describe('Ticket Advance path', () => { await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); }); - it('should search in smart-table with stock', async() => { - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.write(selectors.ticketAdvance.tableStock, '5'); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 2); - - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.waitToClick(selectors.ticketAdvance.submit); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); - }); - - it('should search in smart-table with especified Lines', async() => { - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.write(selectors.ticketAdvance.tableLines, '0'); - await page.keyboard.press('Enter'); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); - - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.waitToClick(selectors.ticketAdvance.submit); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); - }); - - it('should search in smart-table with especified Liters', async() => { - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.write(selectors.ticketAdvance.tableLiters, '0'); - await page.keyboard.press('Enter'); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); - - await page.waitToClick(selectors.ticketAdvance.tableButtonSearch); - await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - await page.waitToClick(selectors.ticketAdvance.submit); - await page.waitForNumberOfElements(selectors.ticketAdvance.table, 1); - }); - - it('should check the three last tickets and move to the future', async() => { + it('should check the one ticket and move to the present', async() => { await page.waitToClick(selectors.ticketAdvance.multiCheck); await page.waitToClick(selectors.ticketAdvance.moveButton); await page.waitToClick(selectors.ticketAdvance.acceptButton); diff --git a/e2e/paths/08-route/02_basic_data.spec.js b/e2e/paths/08-route/02_basic_data.spec.js index b1440f2d1..ff8361499 100644 --- a/e2e/paths/08-route/02_basic_data.spec.js +++ b/e2e/paths/08-route/02_basic_data.spec.js @@ -18,7 +18,7 @@ describe('Route basic Data path', () => { }); it('should edit the route basic data', async() => { - const nextMonth = new Date(); + const nextMonth = Date.vnNew(); nextMonth.setMonth(nextMonth.getMonth() + 1); await page.autocompleteSearch(selectors.routeBasicData.worker, 'adminBossNick'); diff --git a/e2e/paths/09-invoice-in/03_basic_data.spec.js b/e2e/paths/09-invoice-in/03_basic_data.spec.js index 0a28ed191..778b5949c 100644 --- a/e2e/paths/09-invoice-in/03_basic_data.spec.js +++ b/e2e/paths/09-invoice-in/03_basic_data.spec.js @@ -19,7 +19,7 @@ describe('InvoiceIn basic data path', () => { }); it(`should edit the invoiceIn basic data`, async() => { - const now = new Date(); + const now = Date.vnNew(); await page.pickDate(selectors.invoiceInBasicData.issued, now); await page.pickDate(selectors.invoiceInBasicData.operated, now); await page.autocompleteSearch(selectors.invoiceInBasicData.supplier, 'Verdnatura'); diff --git a/e2e/paths/09-invoice-out/02_descriptor.spec.js b/e2e/paths/09-invoice-out/02_descriptor.spec.js index 8d403e083..5169345bc 100644 --- a/e2e/paths/09-invoice-out/02_descriptor.spec.js +++ b/e2e/paths/09-invoice-out/02_descriptor.spec.js @@ -100,7 +100,7 @@ describe('InvoiceOut descriptor path', () => { }); it(`should check the invoiceOut booked in the summary data`, async() => { - let today = new Date(); + let today = Date.vnNew(); let day = today.getDate(); if (day < 10) day = `0${day}`; diff --git a/e2e/paths/10-travel/01_create.spec.js b/e2e/paths/10-travel/01_create.spec.js index e5d812ebd..15da42d5d 100644 --- a/e2e/paths/10-travel/01_create.spec.js +++ b/e2e/paths/10-travel/01_create.spec.js @@ -4,7 +4,7 @@ import getBrowser from '../../helpers/puppeteer'; describe('Travel create path', () => { let browser; let page; - const date = new Date(); + const date = Date.vnNew(); const day = 15; date.setDate(day); diff --git a/e2e/paths/10-travel/02_basic_data_and_log.spec.js b/e2e/paths/10-travel/02_basic_data_and_log.spec.js index a231a70b2..341b38f59 100644 --- a/e2e/paths/10-travel/02_basic_data_and_log.spec.js +++ b/e2e/paths/10-travel/02_basic_data_and_log.spec.js @@ -22,7 +22,7 @@ describe('Travel basic data path', () => { }); it('should set a wrong delivery date then receive an error on submit', async() => { - const lastMonth = new Date(); + const lastMonth = Date.vnNew(); lastMonth.setMonth(lastMonth.getMonth() - 1); await page.pickDate(selectors.travelBasicData.deliveryDate, lastMonth); diff --git a/e2e/paths/10-travel/03_descriptor.spec.js b/e2e/paths/10-travel/03_descriptor.spec.js index f459ef043..77b26b676 100644 --- a/e2e/paths/10-travel/03_descriptor.spec.js +++ b/e2e/paths/10-travel/03_descriptor.spec.js @@ -123,7 +123,7 @@ describe('Travel descriptor path', () => { }); it('should update the landed date to a future date to enable cloneWithEntries', async() => { - const nextMonth = new Date(); + const nextMonth = Date.vnNew(); nextMonth.setMonth(nextMonth.getMonth() + 1); await page.pickDate(selectors.travelBasicData.deliveryDate, nextMonth); await page.waitToClick(selectors.travelBasicData.save); diff --git a/e2e/paths/12-entry/03_latestBuys.spec.js b/e2e/paths/12-entry/03_latestBuys.spec.js index 553d41b95..a73e12659 100644 --- a/e2e/paths/12-entry/03_latestBuys.spec.js +++ b/e2e/paths/12-entry/03_latestBuys.spec.js @@ -4,10 +4,15 @@ import getBrowser from '../../helpers/puppeteer'; describe('Entry lastest buys path', () => { let browser; let page; + const httpRequests = []; beforeAll(async() => { browser = await getBrowser(); page = browser.page; + page.on('request', req => { + if (req.url().includes(`Buys/latestBuysFilter`)) + httpRequests.push(req.url()); + }); await page.loginAndModule('buyer', 'entry'); }); @@ -20,6 +25,87 @@ describe('Entry lastest buys path', () => { await page.waitForSelector(selectors.entryLatestBuys.editBuysButton, {visible: false}); }); + it('should filter by name', async() => { + await page.write(selectors.entryLatestBuys.generalSearchInput, 'Melee'); + await page.keyboard.press('Enter'); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('search=Melee')))).toBeDefined(); + }); + + it('should filter by reign and type', async() => { + await page.click(selectors.entryLatestBuys.firstReignIcon); + await page.autocompleteSearch(selectors.entryLatestBuys.typeInput, 'Alstroemeria'); + await page.click(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('categoryFk')))).toBeDefined(); + expect(httpRequests.find(req => req.includes(('typeFk')))).toBeDefined(); + }); + + it('should filter by from date', async() => { + await page.pickDate(selectors.entryLatestBuys.fromInput, new Date()); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('from')))).toBeDefined(); + }); + + it('should filter by to date', async() => { + await page.pickDate(selectors.entryLatestBuys.toInput, new Date()); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('to')))).toBeDefined(); + }); + + it('should filter by sales person', async() => { + await page.autocompleteSearch(selectors.entryLatestBuys.salesPersonInput, 'buyerNick'); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('salesPersonFk')))).toBeDefined(); + }); + + it('should filter by supplier', async() => { + await page.autocompleteSearch(selectors.entryLatestBuys.supplierInput, 'Farmer King'); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('supplierFk')))).toBeDefined(); + }); + + it('should filter by active', async() => { + await page.waitToClick(selectors.entryLatestBuys.activeCheck); + await page.waitToClick(selectors.entryLatestBuys.activeCheck); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('active=true')))).toBeDefined(); + expect(httpRequests.find(req => req.includes(('active=false')))).toBeDefined(); + }); + + it('should filter by visible', async() => { + await page.waitToClick(selectors.entryLatestBuys.visibleCheck); + await page.waitToClick(selectors.entryLatestBuys.visibleCheck); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('visible=true')))).toBeDefined(); + expect(httpRequests.find(req => req.includes(('visible=false')))).toBeDefined(); + }); + + it('should filter by floramondo', async() => { + await page.waitToClick(selectors.entryLatestBuys.floramondoCheck); + await page.waitToClick(selectors.entryLatestBuys.floramondoCheck); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('floramondo=true')))).toBeDefined(); + expect(httpRequests.find(req => req.includes(('floramondo=false')))).toBeDefined(); + }); + + it('should filter by tag Color', async() => { + await page.waitToClick(selectors.entryLatestBuys.addTagButton); + await page.autocompleteSearch(selectors.entryLatestBuys.itemTagInput, 'Color'); + await page.autocompleteSearch(selectors.entryLatestBuys.itemTagValueInput, 'Brown'); + await page.waitToClick(selectors.entryLatestBuys.chip); + + expect(httpRequests.find(req => req.includes(('tags')))).toBeDefined(); + }); + it('should select all lines but one and then check the edit buys button appears', async() => { await page.waitToClick(selectors.entryLatestBuys.allBuysCheckBox); await page.waitToClick(selectors.entryLatestBuys.secondBuyCheckBox); diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index 85b51fd04..17ccbf041 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -15,7 +15,7 @@ export default class Calendar extends FormInput { constructor($element, $scope, vnWeekDays, moment) { super($element, $scope); this.weekDays = vnWeekDays.locales; - this.defaultDate = new Date(); + this.defaultDate = Date.vnNew(); this.displayControls = true; this.moment = moment; } @@ -115,8 +115,8 @@ export default class Calendar extends FormInput { let wday = date.getDay(); let month = date.getMonth(); - const currentDay = new Date().getDate(); - const currentMonth = new Date().getMonth(); + const currentDay = Date.vnNew().getDate(); + const currentMonth = Date.vnNew().getMonth(); let classes = { today: day === currentDay && month === currentMonth, diff --git a/front/core/components/calendar/index.spec.js b/front/core/components/calendar/index.spec.js index e3a3b0f87..c4ad6f14b 100644 --- a/front/core/components/calendar/index.spec.js +++ b/front/core/components/calendar/index.spec.js @@ -2,7 +2,7 @@ describe('Component vnCalendar', () => { let controller; let $element; - let date = new Date(); + let date = Date.vnNew(); date.setHours(0, 0, 0, 0); date.setDate(1); @@ -48,7 +48,7 @@ describe('Component vnCalendar', () => { it(`should return the selected element, then emit a 'selection' event`, () => { jest.spyOn(controller, 'emit'); - const day = new Date(); + const day = Date.vnNew(); day.setHours(0, 0, 0, 0); const clickEvent = new Event('click'); diff --git a/front/core/components/date-picker/index.spec.js b/front/core/components/date-picker/index.spec.js index f76396311..13ab1d70a 100644 --- a/front/core/components/date-picker/index.spec.js +++ b/front/core/components/date-picker/index.spec.js @@ -4,7 +4,7 @@ describe('Component vnDatePicker', () => { let $ctrl; let today; - today = new Date(); + today = Date.vnNew(); today.setHours(0, 0, 0, 0); beforeEach(ngModule('vnCore')); diff --git a/front/core/components/field/style.scss b/front/core/components/field/style.scss index 9012b8c4c..0d539b029 100644 --- a/front/core/components/field/style.scss +++ b/front/core/components/field/style.scss @@ -82,8 +82,6 @@ } &[type=time], &[type=date] { - clip-path: inset(0 20px 0 0); - &::-webkit-inner-spin-button, &::-webkit-clear-button { display: none; @@ -99,7 +97,7 @@ } &[type=number] { -moz-appearance: textfield; - + &::-webkit-outer-spin-button, &::-webkit-inner-spin-button { -webkit-appearance: none; diff --git a/front/core/components/input-time/index.js b/front/core/components/input-time/index.js index 0d01fbd32..67fa9d6fd 100644 --- a/front/core/components/input-time/index.js +++ b/front/core/components/input-time/index.js @@ -31,7 +31,7 @@ export default class InputTime extends Field { date = this.modelDate ? new Date(this.modelDate) - : new Date(); + : Date.vnNew(); date.setHours(split[0], split[1], 0, 0); } diff --git a/front/core/components/input-time/index.spec.js b/front/core/components/input-time/index.spec.js index abb684df8..7b4f1c823 100644 --- a/front/core/components/input-time/index.spec.js +++ b/front/core/components/input-time/index.spec.js @@ -20,7 +20,7 @@ describe('Component vnInputTime', () => { describe('field() setter', () => { it(`should display the formated the date`, () => { - let date = new Date(); + let date = Date.vnNew(); $ctrl.field = date; let displayed = $filter('date')(date, 'HH:mm'); diff --git a/front/core/components/smart-table/index.js b/front/core/components/smart-table/index.js index 770dcdf32..ad9883950 100644 --- a/front/core/components/smart-table/index.js +++ b/front/core/components/smart-table/index.js @@ -478,8 +478,8 @@ export default class SmartTable extends Component { const params = {q: JSON.stringify(stateFilter)}; - this.$state.go(this.$state.current.name, params, {location: 'replace'}); - this.refresh(); + this.$state.go(this.$state.current.name, params, {location: 'replace'}) + .then(() => this.refresh()); } applySort() { @@ -499,8 +499,8 @@ export default class SmartTable extends Component { stateFilter.tableOrder = order; const params = {q: JSON.stringify(stateFilter)}; - this.$state.go(this.$state.current.name, params, {location: 'replace'}); - this.refresh(); + this.$state.go(this.$state.current.name, params, {location: 'replace'}) + .then(() => this.refresh()); } filterSanitizer(field) { @@ -589,7 +589,7 @@ export default class SmartTable extends Component { refresh() { this.isRefreshing = true; this.model.refresh() - .then(() => this.isRefreshing = false); + .finally(() => this.isRefreshing = false); } } diff --git a/front/core/components/smart-table/index.spec.js b/front/core/components/smart-table/index.spec.js index 5fd4c33b7..5a1be98e1 100644 --- a/front/core/components/smart-table/index.spec.js +++ b/front/core/components/smart-table/index.spec.js @@ -160,7 +160,7 @@ describe('Component smartTable', () => { describe('applySort()', () => { it('should call the $state go and model refresh without making changes on the model order', () => { controller.$state = { - go: jest.fn(), + go: jest.fn().mockReturnValue(new Promise(resolve => resolve())), current: { name: 'section' } @@ -171,13 +171,12 @@ describe('Component smartTable', () => { expect(controller.model.order).toBeUndefined(); expect(controller.$state.go).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); it('should call the $state go and model refresh after setting model order according to the controller sortCriteria', () => { const orderBy = {field: 'myField', sortType: 'ASC'}; controller.$state = { - go: jest.fn(), + go: jest.fn().mockReturnValue(new Promise(resolve => resolve())), current: { name: 'section' } @@ -190,7 +189,6 @@ describe('Component smartTable', () => { expect(controller.model.order).toEqual(`${orderBy.field} ${orderBy.sortType}`); expect(controller.$state.go).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); }); @@ -293,12 +291,10 @@ describe('Component smartTable', () => { controller.$inputsScope = { searchProps: {} }; - jest.spyOn(controller, 'refresh'); controller.defaultFilter(); expect(controller.model.addFilter).toHaveBeenCalled(); - expect(controller.refresh).toHaveBeenCalled(); }); }); diff --git a/front/core/services/date.js b/front/core/services/date.js new file mode 100644 index 000000000..120297951 --- /dev/null +++ b/front/core/services/date.js @@ -0,0 +1,2 @@ +import * as date from 'vn-loopback/server/boot/date'; +date.default(); diff --git a/front/core/services/index.js b/front/core/services/index.js index ff1d438ed..867a13df0 100644 --- a/front/core/services/index.js +++ b/front/core/services/index.js @@ -10,3 +10,4 @@ import './week-days'; import './report'; import './email'; import './file'; +import './date'; diff --git a/front/salix/components/instance-log/index.html b/front/salix/components/instance-log/index.html index 354e81080..9794f75c2 100644 --- a/front/salix/components/instance-log/index.html +++ b/front/salix/components/instance-log/index.html @@ -1,8 +1,8 @@ - .window:not(:has(.empty-rows)) { - width:60%; - vn-log { - vn-card { - visibility: hidden; - & > * { - visibility: visible; - } - } +vn-log.vn-instance-log { + vn-card { + width: 900px; + visibility: hidden; + & > * { + visibility: visible; } } } diff --git a/front/salix/components/recover-password/index.html b/front/salix/components/recover-password/index.html index 73f5401d9..5121f81bd 100644 --- a/front/salix/components/recover-password/index.html +++ b/front/salix/components/recover-password/index.html @@ -1,7 +1,7 @@
Recover password
{ const formData = new FormData(); - const now = new Date(); + const now = Date.vnNew(); const timestamp = now.getTime(); const fileName = `${file.name}_${timestamp}`; diff --git a/front/salix/index.js b/front/salix/index.js index 5220f36f6..2488ef9b6 100644 --- a/front/salix/index.js +++ b/front/salix/index.js @@ -1,5 +1,5 @@ import './module'; import './routes'; import './components'; -import './services'; import './styles'; +import 'vn-loopback/server/boot/date'; diff --git a/jest-front.js b/jest-front.js index 6d7532260..eabda9110 100644 --- a/jest-front.js +++ b/jest-front.js @@ -14,6 +14,10 @@ import './modules/ticket/front/module.js'; import './modules/travel/front/module.js'; import './modules/worker/front/module.js'; import './modules/shelving/front/module.js'; +import 'vn-loopback/server/boot/date'; + +// Set NODE_ENV +process.env.NODE_ENV = 'development'; core.run(vnInterceptor => { vnInterceptor.setApiPath(null); @@ -39,3 +43,4 @@ window.ngModule = function(moduleName, ...args) { return angular.mock.module(...fns); }; + diff --git a/jest.front.config.js b/jest.front.config.js index a03c61d11..3289df8bb 100644 --- a/jest.front.config.js +++ b/jest.front.config.js @@ -1,5 +1,6 @@ // For a detailed explanation regarding each configuration property, visit: // https://jestjs.io/docs/en/configuration.html +/* eslint max-len: ["error", { "code": 150 }]*/ module.exports = { name: 'front end', diff --git a/loopback/locale/es.json b/loopback/locale/es.json index f86d211f7..ad6d53d64 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -261,5 +261,8 @@ "The DOCUWARE PDF document does not exists": "El documento PDF Docuware no existe", "It is not possible to modify tracked sales": "No es posible modificar líneas de pedido que se hayan empezado a preparar", "It is not possible to modify sales that their articles are from Floramondo": "No es posible modificar líneas de pedido cuyos artículos sean de Floramondo", - "It is not possible to modify cloned sales": "No es posible modificar líneas de pedido clonadas" + "It is not possible to modify cloned sales": "No es posible modificar líneas de pedido clonadas", + "A supplier with the same name already exists. Change the country.": "Un proveedor con el mismo nombre ya existe. Cambie el país.", + "There is no assigned email for this client": "No hay correo asignado para este cliente" } + diff --git a/loopback/server/boot/date.js b/loopback/server/boot/date.js new file mode 100644 index 000000000..0875b6d5f --- /dev/null +++ b/loopback/server/boot/date.js @@ -0,0 +1,17 @@ +module.exports = () => { + Date.vnUTC = () => { + const env = process.env.NODE_ENV; + if (!env || env === 'development') + return new Date(Date.UTC(2001, 0, 1, 11)); + + return new Date(Date.UTC()); + }; + + Date.vnNew = () => { + return new Date(Date.vnUTC()); + }; + + Date.vnNow = () => { + return new Date(Date.vnUTC()).getTime(); + }; +}; diff --git a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js index 22a48f83e..f0686ffa6 100644 --- a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js +++ b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js @@ -95,7 +95,7 @@ module.exports = Self => { }, myOptions); const claim = await models.Claim.findOne(filter, myOptions); - const today = new Date(); + const today = Date.vnNew(); const newRefundTicket = await models.Ticket.create({ clientFk: claim.ticket().clientFk, @@ -172,7 +172,7 @@ module.exports = Self => { async function saveObservation(observation, options) { const query = `INSERT INTO vn.ticketObservation (ticketFk, observationTypeFk, description) VALUES(?, ?, ?) - ON DUPLICATE KEY + ON DUPLICATE KEY UPDATE description = CONCAT(vn.ticketObservation.description, VALUES(description),' ')`; await Self.rawSql(query, [ observation.ticketFk, diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index ba7bda71d..2ce3bc44b 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -60,7 +60,7 @@ module.exports = Self => { const landedPlusWeek = new Date(ticket.landed); landedPlusWeek.setDate(landedPlusWeek.getDate() + 7); const hasClaimManagerRole = await models.Account.hasRole(userId, 'claimManager', myOptions); - const isClaimable = landedPlusWeek >= new Date(); + const isClaimable = landedPlusWeek >= Date.vnNew(); if (ticket.isDeleted) throw new UserError(`You can't create a claim for a removed ticket`); diff --git a/modules/claim/back/methods/claim/regularizeClaim.js b/modules/claim/back/methods/claim/regularizeClaim.js index ab8ea58a4..672c94947 100644 --- a/modules/claim/back/methods/claim/regularizeClaim.js +++ b/modules/claim/back/methods/claim/regularizeClaim.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethodCtx('regularizeClaim', { - description: `Imports lines from claimBeginning to a new ticket + description: `Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company`, accessType: 'WRITE', accepts: [{ @@ -135,10 +135,10 @@ module.exports = Self => { } async function getTicketId(params, options) { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); let ticket = await Self.app.models.Ticket.findOne({ @@ -155,8 +155,8 @@ module.exports = Self => { } async function createTicket(ctx, options) { - ctx.args.shipped = new Date(); - ctx.args.landed = new Date(); + ctx.args.shipped = Date.vnNew(); + ctx.args.landed = Date.vnNew(); ctx.args.agencyModeId = null; ctx.args.routeId = null; diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index 9151c361e..7cf663caf 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -54,7 +54,7 @@ describe('Claim createFromSales()', () => { try { const options = {transaction: tx}; - const todayMinusEightDays = new Date(); + const todayMinusEightDays = Date.vnNew(); todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8); const ticket = await models.Ticket.findById(ticketId, null, options); @@ -85,7 +85,7 @@ describe('Claim createFromSales()', () => { try { const options = {transaction: tx}; - const todayMinusEightDays = new Date(); + const todayMinusEightDays = Date.vnNew(); todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8); const ticket = await models.Ticket.findById(ticketId, null, options); diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 8d888eb40..113df35c9 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Update Claim', () => { - const newDate = new Date(); + const newDate = Date.vnNew(); const originalData = { ticketFk: 3, clientFk: 1101, diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index 4cd4ce528..12ab45fac 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Update Claim', () => { - const newDate = new Date(); + const newDate = Date.vnNew(); const original = { ticketFk: 3, clientFk: 1101, diff --git a/modules/client/back/methods/client/consumptionSendQueued.js b/modules/client/back/methods/client/consumptionSendQueued.js index 77e0e34f2..31b54b21d 100644 --- a/modules/client/back/methods/client/consumptionSendQueued.js +++ b/modules/client/back/methods/client/consumptionSendQueued.js @@ -32,7 +32,7 @@ module.exports = Self => { c.id AS clientFk, c.email AS clientEmail, eu.email salesPersonEmail - FROM client c + FROM client c JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk JOIN ticket t ON t.clientFk = c.id JOIN sale s ON s.ticketFk = t.id @@ -61,10 +61,10 @@ module.exports = Self => { SET status = 'printed', printed = ? WHERE id = ?`, - [new Date(), queue.id]); + [Date.vnNew(), queue.id]); } catch (error) { await Self.rawSql(` - UPDATE clientConsumptionQueue + UPDATE clientConsumptionQueue SET status = ? WHERE id = ?`, [error.message, queue.id]); diff --git a/modules/client/back/methods/client/createReceipt.js b/modules/client/back/methods/client/createReceipt.js index a75ee8844..74fe2211e 100644 --- a/modules/client/back/methods/client/createReceipt.js +++ b/modules/client/back/methods/client/createReceipt.js @@ -51,7 +51,7 @@ module.exports = function(Self) { Self.createReceipt = async(ctx, options) => { const models = Self.app.models; const args = ctx.args; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); let tx; diff --git a/modules/client/back/methods/client/getCard.js b/modules/client/back/methods/client/getCard.js index 21b3140bd..afbe36e49 100644 --- a/modules/client/back/methods/client/getCard.js +++ b/modules/client/back/methods/client/getCard.js @@ -74,7 +74,7 @@ module.exports = function(Self) { ] }, myOptions); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const query = `SELECT vn.clientGetDebt(?, ?) AS debt`; const data = await Self.rawSql(query, [id, date], myOptions); diff --git a/modules/client/back/methods/client/getDebt.js b/modules/client/back/methods/client/getDebt.js index aafdbfa48..5f8a8c569 100644 --- a/modules/client/back/methods/client/getDebt.js +++ b/modules/client/back/methods/client/getDebt.js @@ -25,7 +25,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const query = `SELECT vn.clientGetDebt(?, ?) AS debt`; const [debt] = await Self.rawSql(query, [clientFk, date], myOptions); diff --git a/modules/client/back/methods/client/lastActiveTickets.js b/modules/client/back/methods/client/lastActiveTickets.js index 03616a0e3..d662f75aa 100644 --- a/modules/client/back/methods/client/lastActiveTickets.js +++ b/modules/client/back/methods/client/lastActiveTickets.js @@ -32,14 +32,14 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const ticket = await Self.app.models.Ticket.findById(ticketId, null, myOptions); const query = ` - SELECT + SELECT t.id, t.shipped, - a.name AS agencyName, + a.name AS agencyName, w.name AS warehouseName, ad.nickname AS nickname, ad.city AS city, @@ -52,7 +52,7 @@ 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 >= ? 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`; diff --git a/modules/client/back/methods/client/summary.js b/modules/client/back/methods/client/summary.js index 48cb75f31..caa3d8033 100644 --- a/modules/client/back/methods/client/summary.js +++ b/modules/client/back/methods/client/summary.js @@ -125,7 +125,7 @@ module.exports = Self => { async function getRecoveries(recoveryModel, clientId, options) { const filter = { where: { - and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] + and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.vnNow()}}]}] }, limit: 1 }; diff --git a/modules/client/back/methods/credit-classification/createWithInsurance.spec.js b/modules/client/back/methods/credit-classification/createWithInsurance.spec.js index 95ff5025f..a5837bb90 100644 --- a/modules/client/back/methods/credit-classification/createWithInsurance.spec.js +++ b/modules/client/back/methods/credit-classification/createWithInsurance.spec.js @@ -23,7 +23,7 @@ describe('Client createWithInsurance', () => { try { const options = {transaction: tx}; - const data = {clientFk: 1101, started: Date.now(), credit: 999, grade: 255}; + const data = {clientFk: 1101, started: Date.vnNow(), credit: 999, grade: 255}; const result = await models.CreditClassification.createWithInsurance(data, options); diff --git a/modules/client/back/methods/defaulter/filter.js b/modules/client/back/methods/defaulter/filter.js index ce1d89818..748581913 100644 --- a/modules/client/back/methods/defaulter/filter.js +++ b/modules/client/back/methods/defaulter/filter.js @@ -51,7 +51,7 @@ module.exports = Self => { const stmts = []; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const stmt = new ParameterizedSQL( `SELECT * @@ -65,14 +65,14 @@ module.exports = Self => { co.created, co.text observation, uw.id workerFk, - uw.name workerName, + uw.name workerName, c.creditInsurance, d.defaulterSinced FROM vn.defaulter d JOIN vn.client c ON c.id = d.clientFk LEFT JOIN vn.clientObservation co ON co.clientFk = c.id LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN account.user uw ON uw.id = co.workerFk + LEFT JOIN account.user uw ON uw.id = co.workerFk WHERE d.created = ? AND d.amount > 0 diff --git a/modules/client/back/methods/recovery/hasActiveRecovery.js b/modules/client/back/methods/recovery/hasActiveRecovery.js index 6b69d99d7..344b6b6ab 100644 --- a/modules/client/back/methods/recovery/hasActiveRecovery.js +++ b/modules/client/back/methods/recovery/hasActiveRecovery.js @@ -27,7 +27,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const query = ` SELECT count(*) AS hasActiveRecovery diff --git a/modules/client/back/methods/tpv-transaction/confirm.js b/modules/client/back/methods/tpv-transaction/confirm.js new file mode 100644 index 000000000..a26e0bad6 --- /dev/null +++ b/modules/client/back/methods/tpv-transaction/confirm.js @@ -0,0 +1,76 @@ +const UserError = require('vn-loopback/util/user-error'); +const base64url = require('base64url'); + +module.exports = Self => { + Self.remoteMethod('confirm', { + description: 'Confirms electronic payment transaction', + accessType: 'WRITE', + accepts: [ + { + arg: 'Ds_SignatureVersion', + type: 'string', + required: false, + }, { + arg: 'Ds_MerchantParameters', + type: 'string', + required: true, + }, { + arg: 'Ds_Signature', + type: 'string', + required: true, + } + ], + returns: { + type: 'Boolean', + root: true + }, + http: { + path: `/confirm`, + verb: 'POST' + } + }); + + Self.confirm = async(signatureVersion, merchantParameters, signature) => { + const $ = Self.app.models; + + const decodedParams = JSON.parse( + base64url.decode(merchantParameters, 'utf8')); + const params = {}; + + for (const param in decodedParams) + params[param] = decodeURIComponent(decodedParams[param]); + + const orderId = params['Ds_Order']; + const merchantId = parseInt(params['Ds_MerchantCode']); + + if (!orderId) + throw new UserError('Order id not found'); + if (!merchantId) + throw new UserError('Mechant id not found'); + + const merchant = await $.TpvMerchant.findById(merchantId, { + fields: ['id', 'secretKey'] + }); + + const base64hmac = Self.createSignature( + orderId, + merchant.secretKey, + merchantParameters + ); + + if (base64hmac !== base64url.toBase64(signature)) + throw new UserError('Invalid signature'); + + await Self.rawSql( + 'CALL hedera.tpvTransaction_confirm(?, ?, ?, ?, ?, ?)', [ + params['Ds_Amount'], + orderId, + merchantId, + params['Ds_Currency'], + params['Ds_Response'], + params['Ds_ErrorCode'] + ]); + + return true; + }; +}; diff --git a/modules/client/back/methods/tpv-transaction/end.js b/modules/client/back/methods/tpv-transaction/end.js new file mode 100644 index 000000000..5a757aa48 --- /dev/null +++ b/modules/client/back/methods/tpv-transaction/end.js @@ -0,0 +1,39 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('end', { + description: 'Ends electronic payment transaction', + accessType: 'WRITE', + accepts: [ + { + arg: 'orderId', + type: 'string', + required: true, + }, { + arg: 'status', + type: 'string', + required: true, + } + ], + http: { + path: `/end`, + verb: 'POST' + } + }); + + Self.end = async(ctx, orderId, status) => { + const userId = ctx.req.accessToken.userId; + const transaction = await Self.findById(orderId, { + fields: ['id', 'clientFk'] + }); + + if (transaction?.clientFk != userId) + throw new UserError('Transaction not owned by user'); + + await Self.rawSql( + 'CALL hedera.tpvTransaction_end(?, ?)', [ + orderId, + status + ]); + }; +}; diff --git a/modules/client/back/methods/tpv-transaction/start.js b/modules/client/back/methods/tpv-transaction/start.js new file mode 100644 index 000000000..ea6ed05eb --- /dev/null +++ b/modules/client/back/methods/tpv-transaction/start.js @@ -0,0 +1,85 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('start', { + description: 'Starts electronic payment transaction', + accessType: 'WRITE', + accepts: [ + { + arg: 'amount', + type: 'Number', + required: true, + }, { + arg: 'companyId', + type: 'Number', + required: false, + }, { + arg: 'urlOk', + type: 'String', + required: false, + }, { + arg: 'urlKo', + type: 'String', + required: false, + } + ], + returns: { + type: 'Object', + root: true + }, + http: { + path: `/start`, + verb: 'POST' + } + }); + + Self.start = async(ctx, amount, companyId, urlOk, urlKo) => { + const userId = ctx.req.accessToken.userId; + const [[row]] = await Self.rawSql( + 'CALL hedera.tpvTransaction_start(?, ?, ?)', [ + amount, + companyId, + userId + ]); + + if (!row) + throw new UserError('Transaction error'); + + const orderId = row.transactionId.padStart(12, '0'); + const merchantUrl = row.merchantUrl ? row.merchantUrl : ''; + urlOk = urlOk ? urlOk.replace('_transactionId_', orderId) : ''; + urlKo = urlKo ? urlKo.replace('_transactionId_', orderId) : ''; + + const params = { + 'Ds_Merchant_Amount': amount, + 'Ds_Merchant_Order': orderId, + 'Ds_Merchant_MerchantCode': row.merchant, + 'Ds_Merchant_Currency': row.currency, + 'Ds_Merchant_TransactionType': row.transactionType, + 'Ds_Merchant_Terminal': row.terminal, + 'Ds_Merchant_MerchantURL': merchantUrl, + 'Ds_Merchant_UrlOK': urlOk, + 'Ds_Merchant_UrlKO': urlKo + }; + for (const param in params) + params[param] = encodeURIComponent(params[param]); + + const json = JSON.stringify(params); + const merchantParameters = Buffer.from(json).toString('base64'); + + const signature = Self.createSignature( + orderId, + row.secretKey, + merchantParameters + ); + + return { + url: row.url, + postValues: { + 'Ds_SignatureVersion': 'HMAC_SHA256_V1', + 'Ds_MerchantParameters': merchantParameters, + 'Ds_Signature': signature + } + }; + }; +}; diff --git a/modules/client/back/models/client-sample.js b/modules/client/back/models/client-sample.js index 787cc2ad8..5e4393042 100644 --- a/modules/client/back/models/client-sample.js +++ b/modules/client/back/models/client-sample.js @@ -41,7 +41,7 @@ module.exports = Self => { // Disable old mandate if (oldMandate) - oldMandate.updateAttribute('finished', new Date()); + oldMandate.updateAttribute('finished', Date.vnNew()); // Create a new mandate await models.Mandate.create({ diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e07993f79..2d8e7bd27 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -141,6 +141,16 @@ module.exports = Self => { done(); } + Self.validateAsync('isToBeMailed', isToBeMailed, { + message: 'There is no assigned email for this client' + }); + + function isToBeMailed(err, done) { + if (this.isToBeMailed == true && !this.email) + err(); + done(); + } + Self.validateAsync('defaultAddressFk', isActive, {message: 'Unable to default a disabled consignee'} ); diff --git a/modules/client/back/models/tpv-transaction.js b/modules/client/back/models/tpv-transaction.js new file mode 100644 index 000000000..eb9dd7d6c --- /dev/null +++ b/modules/client/back/models/tpv-transaction.js @@ -0,0 +1,29 @@ +const crypto = require('crypto'); + +module.exports = Self => { + require('../methods/tpv-transaction/confirm')(Self); + require('../methods/tpv-transaction/start')(Self); + require('../methods/tpv-transaction/end')(Self); + + Self.createSignature = function(orderId, secretKey, merchantParameters) { + secretKey = Buffer.from(secretKey, 'base64'); + const iv = Buffer.alloc(8, 0); + + const cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv); + cipher.setAutoPadding(false); + const orderKey = Buffer.concat([ + cipher.update(zeroPad(orderId, 8)), + cipher.final() + ]); + + return crypto.createHmac('sha256', orderKey) + .update(merchantParameters) + .digest('base64'); + }; + + function zeroPad(buf, blocksize) { + const buffer = typeof buf === 'string' ? Buffer.from(buf, 'utf8') : buf; + const pad = Buffer.alloc((blocksize - (buffer.length % blocksize)) % blocksize, 0); + return Buffer.concat([buffer, pad]); + } +}; diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index b64129e2e..4d2b4c792 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -4,7 +4,6 @@ import Dialog from 'core/components/dialog'; class Controller extends Dialog { constructor($element, $, $transclude, vnReport) { super($element, $, $transclude); - this.viewReceipt = true; this.vnReport = vnReport; this.receipt = {}; } @@ -59,14 +58,18 @@ class Controller extends Dialog { if (value) { const accountingType = value.accountingType; - if (accountingType.receiptDescription != null) { - this.receipt.description = accountingType.receiptDescription; - if (this.originalDescription) this.receipt.description += `, ${this.originalDescription}`; - } else if (this.originalDescription) - this.receipt.description = this.originalDescription; + + this.receipt.description = []; + this.viewReceipt = accountingType.code == 'cash'; + if (accountingType.receiptDescription != null && accountingType.receiptDescription != '') + this.receipt.description.push(accountingType.receiptDescription); + if (this.originalDescription) + this.receipt.description.push(this.originalDescription); + this.receipt.description.join(', '); + this.maxAmount = accountingType && accountingType.maxAmount; - this.receipt.payed = new Date(); + this.receipt.payed = Date.vnNew(); if (accountingType.daysInFuture) this.receipt.payed.setDate(this.receipt.payed.getDate() + accountingType.daysInFuture); } diff --git a/modules/client/front/balance/create/index.spec.js b/modules/client/front/balance/create/index.spec.js index 2c4ed1940..408e6b66a 100644 --- a/modules/client/front/balance/create/index.spec.js +++ b/modules/client/front/balance/create/index.spec.js @@ -38,7 +38,7 @@ describe('Client', () => { } }; - expect(controller.receipt.description).toEqual('Cash, Albaran: 1, 2'); + expect(controller.receipt.description.join(',')).toEqual('Cash,Albaran: 1, 2'); }); }); @@ -75,7 +75,6 @@ describe('Client', () => { jest.spyOn(controller.vnReport, 'show'); controller.$params = {id: 1101}; - controller.viewReceipt = false; $httpBackend.expect('POST', `Clients/1101/createReceipt`).respond({id: 1}); controller.responseHandler('accept'); diff --git a/modules/client/front/consumption/index.js b/modules/client/front/consumption/index.js index d9b657318..eb3a10dd6 100644 --- a/modules/client/front/consumption/index.js +++ b/modules/client/front/consumption/index.js @@ -17,11 +17,11 @@ class Controller extends Section { } setDefaultFilter() { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); this.filterParams = { diff --git a/modules/client/front/consumption/index.spec.js b/modules/client/front/consumption/index.spec.js index 33cbce58f..f2acddbca 100644 --- a/modules/client/front/consumption/index.spec.js +++ b/modules/client/front/consumption/index.spec.js @@ -26,7 +26,7 @@ describe('Client', () => { it('should call the window.open function', () => { jest.spyOn(window, 'open').mockReturnThis(); - const now = new Date(); + const now = Date.vnNew(); controller.$.model.userParams = { from: now, to: now @@ -49,7 +49,7 @@ describe('Client', () => { describe('sendEmail()', () => { it('should make a GET query sending the report', () => { - const now = new Date(); + const now = Date.vnNew(); controller.$.model.userParams = { from: now, to: now diff --git a/modules/client/front/credit-insurance/create/index.js b/modules/client/front/credit-insurance/create/index.js index 83dc18806..e3138e459 100644 --- a/modules/client/front/credit-insurance/create/index.js +++ b/modules/client/front/credit-insurance/create/index.js @@ -5,7 +5,7 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.creditClassification = { - started: this.$filter('date')(new Date(), 'yyyy-MM-dd HH:mm') + started: this.$filter('date')(Date.vnNew(), 'yyyy-MM-dd HH:mm') }; } diff --git a/modules/client/front/credit-insurance/create/index.spec.js b/modules/client/front/credit-insurance/create/index.spec.js index 36a91ceca..c50afd5cf 100644 --- a/modules/client/front/credit-insurance/create/index.spec.js +++ b/modules/client/front/credit-insurance/create/index.spec.js @@ -24,7 +24,7 @@ describe('Client', () => { describe('onSubmit()', () => { it('should perform a POST query', () => { - let started = new Date(); + let started = Date.vnNew(); controller.creditClassification = { started: started, credit: 300, diff --git a/modules/client/front/credit-insurance/index/index.js b/modules/client/front/credit-insurance/index/index.js index 5f59c918a..b40025c65 100644 --- a/modules/client/front/credit-insurance/index/index.js +++ b/modules/client/front/credit-insurance/index/index.js @@ -52,7 +52,7 @@ class Controller extends Section { } returnDialog() { - let params = {finished: Date.now()}; + let params = {finished: Date.vnNow()}; this.$http.patch(`CreditClassifications/${this.classificationId}`, params).then(() => { this._getClassifications(this.client.id); }); diff --git a/modules/client/front/credit-insurance/index/index.spec.js b/modules/client/front/credit-insurance/index/index.spec.js index 8629db684..af072691a 100644 --- a/modules/client/front/credit-insurance/index/index.spec.js +++ b/modules/client/front/credit-insurance/index/index.spec.js @@ -39,7 +39,7 @@ describe('Client', () => { it(`should return false if finds a classification without due date`, () => { controller.classifications = [ - {finished: Date.now()}, + {finished: Date.vnNow()}, {finished: null} ]; @@ -50,8 +50,8 @@ describe('Client', () => { it(`should return true if all classifications are defined with due date`, () => { controller.classifications = [ - {finished: Date.now()}, - {finished: Date.now()} + {finished: Date.vnNow()}, + {finished: Date.vnNow()} ]; let result = controller.canCreateNew(); diff --git a/modules/client/front/credit-insurance/insurance/create/index.js b/modules/client/front/credit-insurance/insurance/create/index.js index 94de53352..9eae5bfa9 100644 --- a/modules/client/front/credit-insurance/insurance/create/index.js +++ b/modules/client/front/credit-insurance/insurance/create/index.js @@ -5,7 +5,7 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.insurance = { - created: this.$filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss') + created: this.$filter('date')(Date.vnNew(), 'yyyy-MM-dd HH:mm:ss') }; } diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 4beadfda6..bfadc5c6a 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -82,7 +82,7 @@ export default class Controller extends Section { chipColor(date) { const day = 24 * 60 * 60 * 1000; - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); const observationShipped = new Date(date); diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js index 0732c68a1..f92378d08 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -38,14 +38,14 @@ describe('client defaulter', () => { describe('chipColor()', () => { it('should return undefined when the date is the present', () => { - let today = new Date(); + let today = Date.vnNew(); let result = controller.chipColor(today); expect(result).toEqual(undefined); }); it('should return warning when the date is 10 days in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 11); let result = controller.chipColor(pastDate); @@ -53,7 +53,7 @@ describe('client defaulter', () => { }); it('should return alert when the date is 20 days in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 21); let result = controller.chipColor(pastDate); diff --git a/modules/client/front/greuge/create/index.js b/modules/client/front/greuge/create/index.js index dcc0fa522..147ad9bcb 100644 --- a/modules/client/front/greuge/create/index.js +++ b/modules/client/front/greuge/create/index.js @@ -5,7 +5,7 @@ class Controller extends Section { constructor(...args) { super(...args); this.greuge = { - shipped: new Date(), + shipped: Date.vnNew(), clientFk: this.$params.id }; } diff --git a/modules/client/front/notification/index.spec.js b/modules/client/front/notification/index.spec.js index 4e754f6ad..e1de104be 100644 --- a/modules/client/front/notification/index.spec.js +++ b/modules/client/front/notification/index.spec.js @@ -39,7 +39,7 @@ describe('Client notification', () => { describe('campaignSelection() setter', () => { it('should set the campaign from and to properties', () => { - const dated = new Date(); + const dated = Date.vnNew(); controller.campaignSelection = { dated: dated, scopeDays: 14 @@ -61,8 +61,8 @@ describe('Client notification', () => { controller.$.filters = {hide: () => {}}; controller.campaign = { - from: new Date(), - to: new Date() + from: Date.vnNew(), + to: Date.vnNew() }; const data = controller.$.model.data; diff --git a/modules/client/front/recovery/create/index.js b/modules/client/front/recovery/create/index.js index 4fd05eaa0..1779d647e 100644 --- a/modules/client/front/recovery/create/index.js +++ b/modules/client/front/recovery/create/index.js @@ -5,7 +5,7 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.recovery = { - started: new Date() + started: Date.vnNew() }; } diff --git a/modules/client/front/recovery/index/index.js b/modules/client/front/recovery/index/index.js index d53ded805..e89b6832c 100644 --- a/modules/client/front/recovery/index/index.js +++ b/modules/client/front/recovery/index/index.js @@ -4,7 +4,7 @@ import Section from 'salix/components/section'; class Controller extends Section { setFinished(recovery) { if (!recovery.finished) { - let params = {finished: Date.now()}; + let params = {finished: Date.vnNow()}; this.$http.patch(`Recoveries/${recovery.id}`, params).then( () => this.$.model.refresh() ); diff --git a/modules/client/front/summary/index.js b/modules/client/front/summary/index.js index 1f22612d2..877579e33 100644 --- a/modules/client/front/summary/index.js +++ b/modules/client/front/summary/index.js @@ -100,7 +100,7 @@ class Controller extends Summary { } chipColor(date) { - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); const ticketShipped = new Date(date); diff --git a/modules/client/front/summary/index.spec.js b/modules/client/front/summary/index.spec.js index 0261cef45..a05d48518 100644 --- a/modules/client/front/summary/index.spec.js +++ b/modules/client/front/summary/index.spec.js @@ -76,14 +76,14 @@ describe('Client', () => { describe('chipColor()', () => { it('should return warning when the date is the present', () => { - let today = new Date(); + let today = Date.vnNew(); let result = controller.chipColor(today); expect(result).toEqual('warning'); }); it('should return success when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.chipColor(futureDate); @@ -91,7 +91,7 @@ describe('Client', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.chipColor(pastDate); diff --git a/modules/client/front/unpaid/index.js b/modules/client/front/unpaid/index.js index a8ff64386..fcf620b54 100644 --- a/modules/client/front/unpaid/index.js +++ b/modules/client/front/unpaid/index.js @@ -4,7 +4,7 @@ import Section from 'salix/components/section'; export default class Controller extends Section { setDefaultDate(hasData) { if (hasData && !this.clientUnpaid.dated) - this.clientUnpaid.dated = new Date(); + this.clientUnpaid.dated = Date.vnNew(); } } diff --git a/modules/client/front/unpaid/index.spec.js b/modules/client/front/unpaid/index.spec.js index bfeb7df19..0f6460a03 100644 --- a/modules/client/front/unpaid/index.spec.js +++ b/modules/client/front/unpaid/index.spec.js @@ -14,7 +14,7 @@ describe('client unpaid', () => { describe('setDefaultDate()', () => { it(`should not set today date if has dated`, () => { const hasData = true; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); controller.clientUnpaid = { diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index b920f4b58..30d47a2a3 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -150,10 +150,10 @@ module.exports = Self => { const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); stmt = new ParameterizedSQL(` - SELECT + SELECT i.image, i.id AS itemFk, i.size, @@ -209,7 +209,7 @@ 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(? ,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` , [userConfig.warehouseFk, date]); diff --git a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js index 9b1e60532..0578fcdd4 100644 --- a/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js +++ b/modules/entry/back/methods/entry/specs/latestBuysFilter.spec.js @@ -332,10 +332,10 @@ describe('Entry latests buys filter()', () => { const options = {transaction: tx}; try { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); - const to = new Date(); + const to = Date.vnNew(); to.setHours(23, 59, 59, 999); const ctx = { diff --git a/modules/entry/front/latest-buys-search-panel/index.html b/modules/entry/front/latest-buys-search-panel/index.html index 8cfab622a..075d6a8f7 100644 --- a/modules/entry/front/latest-buys-search-panel/index.html +++ b/modules/entry/front/latest-buys-search-panel/index.html @@ -1,198 +1,243 @@ - -
-
- - - - - - - - - -
{{name}}
-
- {{category.name}} -
-
> -
-
- - - - - {{name}}: {{nickname}} - - - - - - - - - - - - - - - - - - - Tags - - - - - - - - - - - - - - - - - More fields - - - - - - - - -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - - -
-
+ + + + + + + + + + + + + + + + + + +
{{name}}
+
+ {{category.name}} +
> +
+
+ + + + + {{name}}: {{nickname}} + + + + + + + + + + + + + + + + + + Tags + + + + + + + + + + + + + +
+ + Id/Name: {{$ctrl.filter.search}} + + + {{category.selection.name}} + + + {{type.selection.name}} + + + Sales person: {{salesPerson.selection.nickname}} + + + Supplier: {{supplier.selection.name}} + + + From: {{$ctrl.filter.from | date:'dd/MM/yyyy'}} + + + To: {{$ctrl.filter.to | date:'dd/MM/yyyy'}} + + + Active: {{$ctrl.filter.active ? '✓' : '✗'}} + + + Floramondo: {{$ctrl.filter.floramondo ? '✓' : '✗'}} + + + Visible: {{$ctrl.filter.visible ? '✓' : '✗'}} + + + {{$ctrl.showTagInfo(chipTag)}} + + +
+
diff --git a/modules/entry/front/latest-buys-search-panel/index.js b/modules/entry/front/latest-buys-search-panel/index.js index 83dc88724..4078580ea 100644 --- a/modules/entry/front/latest-buys-search-panel/index.js +++ b/modules/entry/front/latest-buys-search-panel/index.js @@ -1,67 +1,61 @@ import ngModule from '../module'; import SearchPanel from 'core/components/searchbar/search-panel'; +import './style.scss'; class Controller extends SearchPanel { constructor($element, $) { super($element, $); - let model = 'Item'; - let moreFields = ['description', 'name']; + } - let properties; - let validations = window.validations; + $onInit() { + this.filter = { + isActive: true, + tags: [] + }; + } - if (validations && validations[model]) - properties = validations[model].properties; - else - properties = {}; - - this.moreFields = []; - for (let field of moreFields) { - let prop = properties[field]; - this.moreFields.push({ - name: field, - label: prop ? prop.description : field, - type: prop ? prop.type : null - }); + changeCategory(id) { + if (this.filter.categoryFk != id) { + this.filter.categoryFk = id; + this.addFilters(); } } - get filter() { - let filter = this.$.filter; - - for (let fieldFilter of this.fieldFilters) - filter[fieldFilter.name] = fieldFilter.value; - - return filter; + removeItemFilter(param) { + this.filter[param] = null; + if (param == 'categoryFk') this.filter['typeFk'] = null; + this.addFilters(); } - set filter(value) { - if (!value) - value = {}; - if (!value.tags) - value.tags = [{}]; + removeTag(tag) { + const index = this.filter.tags.indexOf(tag); + if (index > -1) this.filter.tags.splice(index, 1); + this.addFilters(); + } - this.fieldFilters = []; - for (let field of this.moreFields) { - if (value[field.name] != undefined) { - this.fieldFilters.push({ - name: field.name, - value: value[field.name], - info: field - }); - } + onKeyPress($event) { + if ($event.key === 'Enter') + this.addFilters(); + } + + addFilters() { + for (let i = 0; i < this.filter.tags.length; i++) { + if (!this.filter.tags[i].value) + this.filter.tags.splice(i, 1); } - - this.$.filter = value; + return this.model.addFilter({}, this.filter); } - removeField(index, field) { - this.fieldFilters.splice(index, 1); - delete this.$.filter[field]; + showTagInfo(itemTag) { + if (!itemTag.tagFk) return itemTag.value; + return `${this.tags.find(tag => tag.id == itemTag.tagFk).name}: ${itemTag.value}`; } } ngModule.component('vnLatestBuysSearchPanel', { template: require('./index.html'), - controller: Controller + controller: Controller, + bindings: { + model: '<' + } }); diff --git a/modules/entry/front/latest-buys-search-panel/index.spec.js b/modules/entry/front/latest-buys-search-panel/index.spec.js index 9e187a25a..c3c5acbfb 100644 --- a/modules/entry/front/latest-buys-search-panel/index.spec.js +++ b/modules/entry/front/latest-buys-search-panel/index.spec.js @@ -10,50 +10,46 @@ describe('Entry', () => { beforeEach(angular.mock.inject($componentController => { $element = angular.element(``); controller = $componentController('vnLatestBuysSearchPanel', {$element}); + controller.model = {addFilter: () => {}}; })); - describe('filter() setter', () => { - it(`should set the tags property to the scope filter with an empty array`, () => { - const expectedFilter = { - tags: [{}] - }; - controller.filter = null; + describe('removeItemFilter()', () => { + it(`should remove param from filter`, () => { + controller.filter = {tags: [], categoryFk: 1, typeFk: 1}; + const expectFilter = {tags: [], categoryFk: null, typeFk: null}; - expect(controller.filter).toEqual(expectedFilter); - }); + controller.removeItemFilter('categoryFk'); - it(`should set the tags property to the scope filter with an array of tags`, () => { - const expectedFilter = { - description: 'My item', - tags: [{}] - }; - const expectedFieldFilter = [{ - info: { - label: 'description', - name: 'description', - type: null - }, - name: 'description', - value: 'My item' - }]; - controller.filter = { - description: 'My item' - }; - - expect(controller.filter).toEqual(expectedFilter); - expect(controller.fieldFilters).toEqual(expectedFieldFilter); + expect(controller.filter).toEqual(expectFilter); }); }); - describe('removeField()', () => { - it(`should remove the description property from the fieldFilters and from the scope filter`, () => { - const expectedFilter = {tags: [{}]}; - controller.filter = {description: 'My item'}; + describe('removeTag()', () => { + it(`should remove tag from filter`, () => { + const tag = {tagFk: 1, value: 'Value'}; + controller.filter = {tags: [tag]}; + const expectFilter = {tags: []}; - controller.removeField(0, 'description'); + controller.removeTag(tag); - expect(controller.filter).toEqual(expectedFilter); - expect(controller.fieldFilters).toEqual([]); + expect(controller.filter).toEqual(expectFilter); + }); + }); + + describe('showTagInfo()', () => { + it(`should show tag value`, () => { + const tag = {value: 'Value'}; + const result = controller.showTagInfo(tag); + + expect(result).toEqual('Value'); + }); + + it(`should show tag name and value`, () => { + const tag = {tagFk: 1, value: 'Value'}; + controller.tags = [{id: 1, name: 'tagName'}]; + const result = controller.showTagInfo(tag); + + expect(result).toEqual('tagName: Value'); }); }); }); diff --git a/modules/entry/front/latest-buys-search-panel/style.scss b/modules/entry/front/latest-buys-search-panel/style.scss new file mode 100644 index 000000000..ec189c7e4 --- /dev/null +++ b/modules/entry/front/latest-buys-search-panel/style.scss @@ -0,0 +1,70 @@ +@import "variables"; + +vn-latest-buys-search-panel vn-side-menu div { + & > .input { + padding-left: $spacing-md; + padding-right: $spacing-md; + border-color: $color-spacer; + border-bottom: $border-thin; + } + & > .horizontal { + grid-auto-flow: column; + grid-column-gap: $spacing-sm; + align-items: center; + } + & > .checks { + padding: $spacing-md; + flex-wrap: wrap; + border-color: $color-spacer; + border-bottom: $border-thin; + } + & > .tags { + padding: $spacing-md; + padding-bottom: 0%; + padding-top: 0%; + align-items: center; + } + & > .chips { + display: flex; + flex-wrap: wrap; + padding: $spacing-md; + overflow: hidden; + max-width: 100%; + border-color: $color-spacer; + border-top: $border-thin; + } + & > .item-category { + padding: $spacing-sm; + justify-content: flex-start; + align-items: flex-start; + flex-wrap: wrap; + + vn-autocomplete[vn-id="category"] { + display: none; + } + + & > vn-one { + padding: $spacing-sm; + min-width: 33.33%; + text-align: center; + box-sizing: border-box; + + & > vn-icon { + padding: $spacing-sm; + background-color: $color-font-secondary; + border-radius: 50%; + cursor: pointer; + + &.active { + background-color: $color-main; + color: #fff; + } + & > i:before { + font-size: 2.6rem; + width: 16px; + height: 16px; + } + } + } + } +} diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index fc44ddfc2..727b19220 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -7,17 +7,11 @@ on-data-change="$ctrl.reCheck()" auto-load="true">
- - - + + + - + { const options = {transaction: tx}; try { - const from = new Date(); - const to = new Date(); + const from = Date.vnNew(); + const to = Date.vnNew(); from.setHours(0, 0, 0, 0); to.setHours(23, 59, 59, 999); to.setDate(to.getDate() + 1); diff --git a/modules/invoiceIn/back/models/invoice-in.json b/modules/invoiceIn/back/models/invoice-in.json index fa8a1d8f8..c6a736b06 100644 --- a/modules/invoiceIn/back/models/invoice-in.json +++ b/modules/invoiceIn/back/models/invoice-in.json @@ -94,11 +94,6 @@ "model": "Supplier", "foreignKey": "supplierFk" }, - "supplierContact": { - "type": "hasMany", - "model": "SupplierContact", - "foreignKey": "supplierFk" - }, "currency": { "type": "belongsTo", "model": "Currency", diff --git a/modules/invoiceIn/front/basic-data/index.spec.js b/modules/invoiceIn/front/basic-data/index.spec.js index 09aa08293..98710ac35 100644 --- a/modules/invoiceIn/front/basic-data/index.spec.js +++ b/modules/invoiceIn/front/basic-data/index.spec.js @@ -78,7 +78,7 @@ describe('InvoiceIn', () => { description: 'This is a description', files: [{ lastModified: 1668673957761, - lastModifiedDate: new Date(), + lastModifiedDate: Date.vnNew(), name: 'file-example.png', size: 19653, type: 'image/png', diff --git a/modules/invoiceIn/front/card/index.js b/modules/invoiceIn/front/card/index.js index c7ac08cc7..48217faa5 100644 --- a/modules/invoiceIn/front/card/index.js +++ b/modules/invoiceIn/front/card/index.js @@ -6,13 +6,15 @@ class Controller extends ModuleCard { const filter = { include: [ { - relation: 'supplier' - }, - { - relation: 'supplierContact', + relation: 'supplier', scope: { - where: { - email: {neq: null} + include: { + relation: 'contacts', + scope: { + where: { + email: {neq: null}, + } + } } } }, diff --git a/modules/invoiceIn/front/descriptor/index.html b/modules/invoiceIn/front/descriptor/index.html index 223914c9c..c4330fbf0 100644 --- a/modules/invoiceIn/front/descriptor/index.html +++ b/modules/invoiceIn/front/descriptor/index.html @@ -40,7 +40,7 @@ Send agricultural receipt as PDF diff --git a/modules/invoiceIn/front/descriptor/index.js b/modules/invoiceIn/front/descriptor/index.js index 4dc89a459..e005211a3 100644 --- a/modules/invoiceIn/front/descriptor/index.js +++ b/modules/invoiceIn/front/descriptor/index.js @@ -75,7 +75,7 @@ class Controller extends Descriptor { filter: { where: { invoiceInFk: id, - dueDated: {gte: new Date()} + dueDated: {gte: Date.vnNew()} } }}) .then(res => { diff --git a/modules/invoiceIn/front/dueDay/index.js b/modules/invoiceIn/front/dueDay/index.js index 3cc1c81e8..ee9b13e5c 100644 --- a/modules/invoiceIn/front/dueDay/index.js +++ b/modules/invoiceIn/front/dueDay/index.js @@ -4,7 +4,7 @@ import Section from 'salix/components/section'; class Controller extends Section { add() { this.$.model.insert({ - dueDated: new Date(), + dueDated: Date.vnNew(), bankFk: this.vnConfig.local.bankFk }); } diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index d42184ae5..f3c7a5093 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -60,9 +60,9 @@ module.exports = Self => { try { query = ` SELECT MAX(issued) issued - FROM vn.invoiceOut io - JOIN vn.time t ON t.dated = io.issued - WHERE io.serial = 'A' + FROM vn.invoiceOut io + JOIN vn.time t ON t.dated = io.issued + WHERE io.serial = 'A' AND t.year = YEAR(?) AND io.companyFk = ?`; const [maxIssued] = await Self.rawSql(query, [ @@ -77,7 +77,7 @@ module.exports = Self => { if (args.invoiceDate < args.maxShipped) args.maxShipped = args.invoiceDate; - const minShipped = new Date(); + const minShipped = Date.vnNew(); minShipped.setFullYear(minShipped.getFullYear() - 1); minShipped.setMonth(1); minShipped.setDate(1); @@ -131,11 +131,11 @@ module.exports = Self => { const models = Self.app.models; const args = ctx.args; const query = `SELECT DISTINCT clientFk AS id - FROM ticket t + FROM ticket t JOIN ticketPackaging tp ON t.id = tp.ticketFk JOIN client c ON c.id = t.clientFk WHERE t.shipped BETWEEN '2017-11-21' AND ? - AND t.clientFk >= ? + AND t.clientFk >= ? AND (t.clientFk <= ? OR ? IS NULL) AND c.isActive`; return models.InvoiceOut.rawSql(query, [ @@ -149,16 +149,16 @@ module.exports = Self => { async function getInvoiceableClients(ctx, options) { const models = Self.app.models; const args = ctx.args; - const minShipped = new Date(); + const minShipped = Date.vnNew(); minShipped.setFullYear(minShipped.getFullYear() - 1); const query = `SELECT c.id, SUM(IFNULL ( - s.quantity * + s.quantity * s.price * (100-s.discount)/100, - 0) + 0) + IFNULL(ts.quantity * ts.price,0) ) AS sumAmount, c.hasToInvoiceByAddress, @@ -170,7 +170,7 @@ module.exports = Self => { LEFT JOIN ticketService ts ON ts.ticketFk = t.id JOIN address a ON a.id = t.addressFk JOIN client c ON c.id = t.clientFk - WHERE ISNULL(t.refFk) AND c.id >= ? + WHERE ISNULL(t.refFk) AND c.id >= ? AND (t.clientFk <= ? OR ? IS NULL) AND t.shipped BETWEEN ? AND util.dayEnd(?) AND t.companyFk = ? AND c.hasToInvoice diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 297afa8e8..a458aa18e 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -108,14 +108,14 @@ module.exports = Self => { throw new UserError(`This client is not invoiceable`); // Can't invoice tickets into future - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 1); if (maxShipped >= tomorrow) throw new UserError(`Can't invoice to future`); const maxInvoiceDate = await getMaxIssued(args.serial, companyId, myOptions); - if (new Date() < maxInvoiceDate) + if (Date.vnNew() < maxInvoiceDate) throw new UserError(`Can't invoice to past`); if (ticketId) { @@ -155,7 +155,7 @@ module.exports = Self => { async function isInvoiceable(clientId, options) { const models = Self.app.models; const query = `SELECT (hasToInvoice AND isTaxDataChecked) AS invoiceable - FROM client + FROM client WHERE id = ?`; const [result] = await models.InvoiceOut.rawSql(query, [clientId], options); @@ -172,12 +172,12 @@ module.exports = Self => { async function getMaxIssued(serial, companyId, options) { const models = Self.app.models; - const query = `SELECT MAX(issued) AS issued - FROM invoiceOut + const query = `SELECT MAX(issued) AS issued + FROM invoiceOut WHERE serial = ? AND companyFk = ?`; const [maxIssued] = await models.InvoiceOut.rawSql(query, [serial, companyId], options); - const maxInvoiceDate = maxIssued && maxIssued.issued || new Date(); + const maxInvoiceDate = maxIssued && maxIssued.issued || Date.vnNew(); return maxInvoiceDate; } diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js index e5cf5fda0..d3d789393 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('InvoiceOut filter()', () => { - let today = new Date(); + let today = Date.vnNew(); today.setHours(2, 0, 0, 0); it('should return the invoice out matching ref', async() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/invoiceClient.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/invoiceClient.spec.js index 5f890de26..9a0574dba 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/invoiceClient.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/invoiceClient.spec.js @@ -5,7 +5,7 @@ describe('InvoiceOut invoiceClient()', () => { const clientId = 1101; const addressId = 121; const companyFk = 442; - const minShipped = new Date(); + const minShipped = Date.vnNew(); minShipped.setFullYear(minShipped.getFullYear() - 1); minShipped.setMonth(1); minShipped.setDate(1); @@ -33,8 +33,8 @@ describe('InvoiceOut invoiceClient()', () => { ctx.args = { clientId: clientId, addressId: addressId, - invoiceDate: new Date(), - maxShipped: new Date(), + invoiceDate: Date.vnNew(), + maxShipped: Date.vnNew(), companyFk: companyFk, minShipped: minShipped }; diff --git a/modules/invoiceOut/front/index/global-invoicing/index.js b/modules/invoiceOut/front/index/global-invoicing/index.js index f772a4936..0c5773adc 100644 --- a/modules/invoiceOut/front/index/global-invoicing/index.js +++ b/modules/invoiceOut/front/index/global-invoicing/index.js @@ -6,7 +6,7 @@ class Controller extends Dialog { constructor($element, $, $transclude) { super($element, $, $transclude); this.invoice = { - maxShipped: new Date() + maxShipped: Date.vnNew() }; this.clientsNumber = 'allClients'; } diff --git a/modules/invoiceOut/front/index/global-invoicing/index.spec.js b/modules/invoiceOut/front/index/global-invoicing/index.spec.js index e88b0b1d4..aa9674b0e 100644 --- a/modules/invoiceOut/front/index/global-invoicing/index.spec.js +++ b/modules/invoiceOut/front/index/global-invoicing/index.spec.js @@ -76,8 +76,8 @@ describe('InvoiceOut', () => { jest.spyOn(controller.vnApp, 'showError'); controller.invoice = { - invoiceDate: new Date(), - maxShipped: new Date() + invoiceDate: Date.vnNew(), + maxShipped: Date.vnNew() }; controller.responseHandler('accept'); @@ -88,14 +88,14 @@ describe('InvoiceOut', () => { it('should make an http POST query and then call to the showSuccess() method', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - const minShipped = new Date(); + const minShipped = Date.vnNew(); minShipped.setFullYear(minShipped.getFullYear() - 1); minShipped.setMonth(1); minShipped.setDate(1); minShipped.setHours(0, 0, 0, 0); controller.invoice = { - invoiceDate: new Date(), - maxShipped: new Date(), + invoiceDate: Date.vnNew(), + maxShipped: Date.vnNew(), fromClientId: 1101, toClientId: 1101, companyFk: 442, diff --git a/modules/invoiceOut/front/index/manual/index.js b/modules/invoiceOut/front/index/manual/index.js index ed50e37da..3abe4b825 100644 --- a/modules/invoiceOut/front/index/manual/index.js +++ b/modules/invoiceOut/front/index/manual/index.js @@ -8,7 +8,7 @@ class Controller extends Dialog { this.isInvoicing = false; this.invoice = { - maxShipped: new Date() + maxShipped: Date.vnNew() }; } diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 68eacfbad..5a47de6bf 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('upsertFixedPrice()', () => { - const now = new Date(); + const now = Date.vnNew(); const fixedPriceId = 1; let originalFixedPrice; @@ -72,4 +72,45 @@ describe('upsertFixedPrice()', () => { throw e; } }); + + it(`should recalculate rate2 if change rate3`, async() => { + const tx = await models.FixedPrice.beginTransaction({}); + + const tomorrow = new Date(now); + tomorrow.setDate(tomorrow.getDate() + 1); + + const rate2 = 2; + const firstRate3 = 1; + const secondRate3 = 2; + try { + const options = {transaction: tx}; + const ctx = {args: { + id: undefined, + itemFk: 1, + warehouseFk: 1, + started: tomorrow, + ended: tomorrow, + rate2: rate2, + rate3: firstRate3, + minPrice: 0, + hasMinPrice: false + }}; + + // create new fixed price + const newFixedPrice = await models.FixedPrice.upsertFixedPrice(ctx, options); + + // change rate3 to same fixed price id + ctx.args.id = newFixedPrice.id; + ctx.args.rate3 = secondRate3; + + const result = await models.FixedPrice.upsertFixedPrice(ctx, options); + + expect(result.rate2).not.toEqual(rate2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/item/back/methods/fixed-price/upsertFixedPrice.js b/modules/item/back/methods/fixed-price/upsertFixedPrice.js index ad35ec3a1..eb3eec1bd 100644 --- a/modules/item/back/methods/fixed-price/upsertFixedPrice.js +++ b/modules/item/back/methods/fixed-price/upsertFixedPrice.js @@ -72,6 +72,16 @@ module.exports = Self => { try { delete args.ctx; // removed unwanted data + + if (args.id) { + const beforeFixedPrice = await models.FixedPrice.findById(args.id, {fields: ['rate3']}, myOptions); + const [result] = await Self.rawSql(`SELECT vn.priceFixed_getRate2(?, ?) as rate2`, + [args.id, args.rate3], myOptions); + + if (beforeFixedPrice.rate3 != args.rate3 && result && result.rate2) + args.rate2 = result.rate2; + } + const fixedPrice = await models.FixedPrice.upsert(args, myOptions); const targetItem = await models.Item.findById(args.itemFk, null, myOptions); diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 05b223598..0f57856c7 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -27,7 +27,7 @@ module.exports = Self => { }); for (let image of images) { - const currentStamp = new Date().getTime(); + const currentStamp = Date.vnNew().getTime(); const updatedStamp = image.updated.getTime(); const graceTime = Math.abs(currentStamp - updatedStamp); const maxTTL = 3600 * 48 * 1000; // 48 hours in ms; @@ -97,7 +97,7 @@ module.exports = Self => { await row.updateAttributes({ error: error, attempts: row.attempts + 1, - updated: new Date() + updated: Date.vnNew() }); } diff --git a/modules/item/back/methods/item/getVisibleAvailable.js b/modules/item/back/methods/item/getVisibleAvailable.js index b291ad9b4..612f64022 100644 --- a/modules/item/back/methods/item/getVisibleAvailable.js +++ b/modules/item/back/methods/item/getVisibleAvailable.js @@ -29,7 +29,7 @@ module.exports = Self => { } }); - Self.getVisibleAvailable = async(id, warehouseFk, dated = new Date(), options) => { + Self.getVisibleAvailable = async(id, warehouseFk, dated = Date.vnNew(), options) => { const myOptions = {}; if (typeof options == 'object') diff --git a/modules/item/back/methods/item/getWasteByItem.js b/modules/item/back/methods/item/getWasteByItem.js index b93d534da..56b90b04a 100644 --- a/modules/item/back/methods/item/getWasteByItem.js +++ b/modules/item/back/methods/item/getWasteByItem.js @@ -32,7 +32,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const wastes = await Self.rawSql(` SELECT *, 100 * dwindle / total AS percentage @@ -43,7 +43,7 @@ module.exports = Self => { sum(ws.saleTotal) AS total, sum(ws.saleWaste) AS dwindle FROM bs.waste ws - WHERE buyer = ? AND family = ? + WHERE buyer = ? AND family = ? AND year = YEAR(TIMESTAMPADD(WEEK,-1, ?)) AND week = WEEK(TIMESTAMPADD(WEEK,-1, ?), 1) GROUP BY buyer, itemFk diff --git a/modules/item/back/methods/item/getWasteByWorker.js b/modules/item/back/methods/item/getWasteByWorker.js index 4c3c64a91..8fa351eed 100644 --- a/modules/item/back/methods/item/getWasteByWorker.js +++ b/modules/item/back/methods/item/getWasteByWorker.js @@ -19,7 +19,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const wastes = await Self.rawSql(` SELECT *, 100 * dwindle / total AS percentage diff --git a/modules/item/back/methods/item/regularize.js b/modules/item/back/methods/item/regularize.js index 0878e3242..dfbcaa69f 100644 --- a/modules/item/back/methods/item/regularize.js +++ b/modules/item/back/methods/item/regularize.js @@ -94,8 +94,8 @@ module.exports = Self => { } async function createTicket(ctx, options) { - ctx.args.shipped = new Date(); - ctx.args.landed = new Date(); + ctx.args.shipped = Date.vnNew(); + ctx.args.landed = Date.vnNew(); ctx.args.companyId = null; ctx.args.agencyModeId = null; ctx.args.routeId = null; @@ -106,10 +106,10 @@ module.exports = Self => { } async function getTicketId(params, options) { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); let ticket = await Self.app.models.Ticket.findOne({ diff --git a/modules/item/back/methods/item/specs/getVisibleAvailable.spec.js b/modules/item/back/methods/item/specs/getVisibleAvailable.spec.js index 8e4864ee8..13b2417d7 100644 --- a/modules/item/back/methods/item/specs/getVisibleAvailable.spec.js +++ b/modules/item/back/methods/item/specs/getVisibleAvailable.spec.js @@ -8,7 +8,7 @@ describe('item getVisibleAvailable()', () => { try { const itemFk = 1; const warehouseFk = 1; - const dated = new Date(); + const dated = Date.vnNew(); const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options); @@ -29,7 +29,7 @@ describe('item getVisibleAvailable()', () => { try { const itemFk = 1; const warehouseFk = 1; - const dated = new Date(); + const dated = Date.vnNew(); dated.setDate(dated.getDate() - 1); const result = await models.Item.getVisibleAvailable(itemFk, warehouseFk, dated, options); diff --git a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js index 25e661aee..00488e534 100644 --- a/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js +++ b/modules/item/back/methods/item/specs/lastEntriesFilter.spec.js @@ -1,9 +1,9 @@ const {models} = require('vn-loopback/server/server'); describe('item lastEntriesFilter()', () => { it('should return one entry for the given item', async() => { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); const tx = await models.Item.beginTransaction({}); @@ -23,11 +23,11 @@ describe('item lastEntriesFilter()', () => { }); it('should return five entries for the given item', async() => { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2, 1); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index 133b11b48..b88f24456 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -80,7 +80,7 @@ class Controller extends Descriptor { } onUploadResponse() { - const timestamp = new Date().getTime(); + const timestamp = Date.vnNew().getTime(); const src = this.$rootScope.imagePath('catalog', '200x200', this.item.id); const zoomSrc = this.$rootScope.imagePath('catalog', '1600x900', this.item.id); const newSrc = `${src}&t=${timestamp}`; diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index c997ea491..1e93f9f16 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -7,7 +7,7 @@ class Controller extends Section { super($element, $scope); this.$anchorScroll = $anchorScroll; this.$location = $location; - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); this.today = today.toJSON(); } diff --git a/modules/item/front/fixed-price/index.html b/modules/item/front/fixed-price/index.html index f9d177562..ce7cefe7a 100644 --- a/modules/item/front/fixed-price/index.html +++ b/modules/item/front/fixed-price/index.html @@ -131,7 +131,7 @@ class="dense" vn-focus ng-model="price.rate3" - on-change="$ctrl.upsertPrice(price); $ctrl.recalculateRate2(price)" + on-change="$ctrl.upsertPrice(price);" step="0.01"s> diff --git a/modules/item/front/fixed-price/index.js b/modules/item/front/fixed-price/index.js index f03d73f08..df2989043 100644 --- a/modules/item/front/fixed-price/index.js +++ b/modules/item/front/fixed-price/index.js @@ -113,24 +113,6 @@ export default class Controller extends Section { return {[param]: value}; } } - - recalculateRate2(price) { - if (!price.id || !price.rate3) return; - - const query = 'FixedPrices/getRate2'; - const params = { - fixedPriceId: price.id, - rate3: price.rate3 - }; - this.$http.get(query, {params}) - .then(res => { - const rate2 = res.data.rate2; - if (rate2) { - price.rate2 = rate2; - this.upsertPrice(price); - } - }); - } } ngModule.vnComponent('vnFixedPrice', { diff --git a/modules/item/front/fixed-price/index.spec.js b/modules/item/front/fixed-price/index.spec.js index db9579444..42dd898b3 100644 --- a/modules/item/front/fixed-price/index.spec.js +++ b/modules/item/front/fixed-price/index.spec.js @@ -24,7 +24,7 @@ describe('fixed price', () => { }); it('should perform an http request to update the price', () => { - const now = new Date(); + const now = Date.vnNew(); jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPATCH('FixedPrices/upsertFixedPrice').respond(); @@ -85,25 +85,5 @@ describe('fixed price', () => { expect(controller.$.model.remove).toHaveBeenCalled(); }); }); - - describe('recalculateRate2()', () => { - it(`should rate2 recalculate`, () => { - jest.spyOn(controller.vnApp, 'showSuccess'); - const price = { - id: 1, - itemFk: 1, - rate2: 2, - rate3: 2 - }; - const response = {rate2: 1}; - controller.recalculateRate2(price); - - const query = `FixedPrices/getRate2?fixedPriceId=${price.id}&rate3=${price.rate3}`; - $httpBackend.expectGET(query).respond(response); - $httpBackend.flush(); - - expect(price.rate2).toEqual(response.rate2); - }); - }); }); }); diff --git a/modules/item/front/last-entries/index.js b/modules/item/front/last-entries/index.js index 014761da9..0c6804838 100644 --- a/modules/item/front/last-entries/index.js +++ b/modules/item/front/last-entries/index.js @@ -5,11 +5,11 @@ class Controller extends Section { constructor($element, $) { super($element, $); - const from = new Date(); + const from = Date.vnNew(); from.setDate(from.getDate() - 75); from.setHours(0, 0, 0, 0); - const to = new Date(); + const to = Date.vnNew(); to.setDate(to.getDate() + 10); to.setHours(23, 59, 59, 59); diff --git a/modules/item/front/request-search-panel/index.spec.js b/modules/item/front/request-search-panel/index.spec.js index 2fb339209..56c76eabf 100644 --- a/modules/item/front/request-search-panel/index.spec.js +++ b/modules/item/front/request-search-panel/index.spec.js @@ -15,7 +15,7 @@ describe(' Component vnRequestSearchPanel', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; - controller.from = new Date(); + controller.from = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.from).toBeDefined(); @@ -26,7 +26,7 @@ describe(' Component vnRequestSearchPanel', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; - controller.to = new Date(); + controller.to = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.to).toBeDefined(); @@ -35,8 +35,8 @@ describe(' Component vnRequestSearchPanel', () => { describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { - controller.filter.from = new Date(); - controller.filter.to = new Date(); + controller.filter.from = Date.vnNew(); + controller.filter.to = Date.vnNew(); controller.scopeDays = 1; diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 2fe08ada6..747cbeff2 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -7,10 +7,10 @@ export default class Controller extends Section { super($element, $); if (!this.$state.q) { - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); - const nextWeek = new Date(); + const nextWeek = Date.vnNew(); nextWeek.setHours(23, 59, 59, 59); nextWeek.setDate(nextWeek.getDate() + 7); @@ -27,7 +27,7 @@ export default class Controller extends Section { $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); @@ -82,7 +82,7 @@ export default class Controller extends Section { } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index 0fc061023..aadeaddca 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -93,7 +93,7 @@ describe('Item', () => { }); it(`should return "warning" if date is today`, () => { - let date = new Date(); + let date = Date.vnNew(); let result = controller.compareDate(date); expect(result).toEqual('warning'); diff --git a/modules/mdb/back/methods/mdbApp/lock.js b/modules/mdb/back/methods/mdbApp/lock.js index 98e61fb53..a12a93814 100644 --- a/modules/mdb/back/methods/mdbApp/lock.js +++ b/modules/mdb/back/methods/mdbApp/lock.js @@ -51,7 +51,7 @@ module.exports = Self => { const updatedMdbApp = await mdbApp.updateAttributes({ userFk: userId, - locked: new Date() + locked: Date.vnNew() }, myOptions); if (tx) await tx.commit(); diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js index 1df4365a9..864a73f52 100644 --- a/modules/mdb/back/methods/mdbVersion/upload.js +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -26,6 +26,11 @@ module.exports = Self => { type: 'string', required: true, description: `The old version number` + }, { + arg: 'description', + type: 'string', + required: false, + description: `The description of changes` }, { arg: 'unlock', type: 'boolean', @@ -42,8 +47,7 @@ module.exports = Self => { verb: 'POST' } }); - - Self.upload = async(ctx, appName, toVersion, branch, fromVersion, unlock, options) => { + Self.upload = async(ctx, options) => { const models = Self.app.models; const myOptions = {}; const $t = ctx.req.__; // $translate @@ -51,6 +55,12 @@ module.exports = Self => { const AccessContainer = models.AccessContainer; const fileOptions = {}; let tx; + const appName = ctx.args.appName; + const toVersion = ctx.args.toVersion; + const branch = ctx.args.branch; + const fromVersion = ctx.args.fromVersion; + let description = ctx.args.description; + const unlock = ctx.args.unlock; if (typeof options == 'object') Object.assign(myOptions, options); @@ -132,13 +142,46 @@ module.exports = Self => { await fs.symlink(rootRelative, destinationRoot); } } + if (description) { + let formatDesc; + const mainBranches = new Set(['master', 'test', 'dev']); + if (mainBranches.has(branch)) + formatDesc = `> :branch_${branch}: `; + else + formatDesc = `> :branch: `; + formatDesc += `*${appName.toUpperCase()}* v.${toVersion} `; + + const oldVersion = await models.MdbVersionTree.findOne({ + where: {version: fromVersion}, + fields: ['branchFk'] + }, myOptions); + + if (branch == oldVersion.branchFk) + formatDesc += `[*${branch}*]: `; + else + formatDesc += `[*${oldVersion.branchFk}* » *${branch}*]: `; + + const params = await models.MdbConfig.findOne(myOptions); + const issueTrackerUrl = params.issueTrackerUrl; + const issueNumberRegex = params.issueNumberRegex; + const chatDestination = params.chatDestination; + + const regex = new RegExp(issueNumberRegex, 'g'); + formatDesc += description.replace(regex, (match, issueId) => { + const newUrl = issueTrackerUrl.replace('{index}', issueId); + return `[#${issueId}](${newUrl})`; + }); + + await models.Chat.send(ctx, chatDestination, formatDesc, myOptions); + } await models.MdbVersionTree.create({ app: appName, version: toVersion, branchFk: branch, fromVersion, - userFk: userId + userFk: userId, + description, }, myOptions); await models.MdbVersion.upsert({ diff --git a/modules/mdb/back/model-config.json b/modules/mdb/back/model-config.json index 8010afca2..b59a4fda0 100644 --- a/modules/mdb/back/model-config.json +++ b/modules/mdb/back/model-config.json @@ -11,6 +11,9 @@ "MdbVersionTree": { "dataSource": "vn" }, + "MdbConfig": { + "dataSource": "vn" + }, "AccessContainer": { "dataSource": "accessStorage" } diff --git a/modules/mdb/back/models/mdbBranch.json b/modules/mdb/back/models/mdbBranch.json index 486dfaf25..b22d14ece 100644 --- a/modules/mdb/back/models/mdbBranch.json +++ b/modules/mdb/back/models/mdbBranch.json @@ -11,6 +11,11 @@ "id": true, "type": "string", "description": "Identifier" + }, + "dsName": { + "id": true, + "type": "string", + "description": "ODBC name" } } } \ No newline at end of file diff --git a/modules/mdb/back/models/mdbConfig.json b/modules/mdb/back/models/mdbConfig.json new file mode 100644 index 000000000..60634104a --- /dev/null +++ b/modules/mdb/back/models/mdbConfig.json @@ -0,0 +1,24 @@ +{ + "name": "MdbConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "mdbConfig" + } + }, + "properties": { + "id": { + "type": "string", + "id": true + }, + "issueTrackerUrl": { + "type": "string" + }, + "issueNumberRegex": { + "type": "string" + }, + "chatDestination": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/modules/mdb/back/models/mdbVersionTree.json b/modules/mdb/back/models/mdbVersionTree.json index 8c0260e54..106473b64 100644 --- a/modules/mdb/back/models/mdbVersionTree.json +++ b/modules/mdb/back/models/mdbVersionTree.json @@ -23,6 +23,9 @@ }, "userFk": { "type": "number" + }, + "description": { + "type": "string" } }, "relations": { diff --git a/modules/monitor/back/methods/sales-monitor/clientsFilter.js b/modules/monitor/back/methods/sales-monitor/clientsFilter.js index 09ea24eb1..13e38f8e1 100644 --- a/modules/monitor/back/methods/sales-monitor/clientsFilter.js +++ b/modules/monitor/back/methods/sales-monitor/clientsFilter.js @@ -34,7 +34,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const stmt = new ParameterizedSQL(` SELECT @@ -51,7 +51,7 @@ module.exports = Self => { JOIN account.user u ON c.salesPersonFk = u.id LEFT JOIN sharingCart sc ON sc.workerFk = c.salesPersonFk AND ? BETWEEN sc.started AND sc.ended - LEFT JOIN workerTeamCollegues wtc + LEFT JOIN workerTeamCollegues wtc ON wtc.collegueFk = IFNULL(sc.workerSubstitute, c.salesPersonFk)`, [date]); diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index 7be130dda..881fc637a 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -104,7 +104,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const conn = Self.dataSource.connector; const models = Self.app.models; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const args = ctx.args; const myOptions = {}; diff --git a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js index bcb37830c..febfc5357 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/clientsFilter.spec.js @@ -8,8 +8,8 @@ describe('SalesMonitor clientsFilter()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 18}}, args: {}}; - const from = new Date(); - const to = new Date(); + const from = Date.vnNew(); + const to = Date.vnNew(); from.setHours(0, 0, 0, 0); to.setHours(23, 59, 59, 59); @@ -35,9 +35,9 @@ describe('SalesMonitor clientsFilter()', () => { try { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 18}}, args: {}}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); - const today = new Date(); + const today = Date.vnNew(); yesterday.setHours(0, 0, 0, 0); today.setHours(23, 59, 59, 59); diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index d2e1a5bec..4e0fb85b7 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -26,9 +26,9 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 9}}, args: { @@ -54,10 +54,10 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 9}}, args: { @@ -205,10 +205,10 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 18}}, args: {}}; @@ -234,10 +234,10 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 18}}, args: {}}; diff --git a/modules/monitor/front/index/clients/index.js b/modules/monitor/front/index/clients/index.js index 58613f09d..ac3ce9140 100644 --- a/modules/monitor/front/index/clients/index.js +++ b/modules/monitor/front/index/clients/index.js @@ -5,7 +5,7 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); - const date = new Date(); + const date = Date.vnNew(); this.dateFrom = date; this.dateTo = date; this.filter = { @@ -64,9 +64,9 @@ export default class Controller extends Section { let from = this.dateFrom; let to = this.dateTo; if (!from) - from = new Date(); + from = Date.vnNew(); if (!to) - to = new Date(); + to = Date.vnNew(); const minHour = new Date(from); minHour.setHours(0, 0, 0, 0); const maxHour = new Date(to); diff --git a/modules/monitor/front/index/orders/index.js b/modules/monitor/front/index/orders/index.js index e3a47f68b..40100b79f 100644 --- a/modules/monitor/front/index/orders/index.js +++ b/modules/monitor/front/index/orders/index.js @@ -26,7 +26,7 @@ export default class Controller extends Section { } chipColor(date) { - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); const orderLanded = new Date(date); diff --git a/modules/monitor/front/index/search-panel/index.spec.js b/modules/monitor/front/index/search-panel/index.spec.js index f862e8d77..18cf1abfc 100644 --- a/modules/monitor/front/index/search-panel/index.spec.js +++ b/modules/monitor/front/index/search-panel/index.spec.js @@ -38,7 +38,7 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; - controller.from = new Date(); + controller.from = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.from).toBeDefined(); @@ -49,7 +49,7 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; - controller.to = new Date(); + controller.to = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.to).toBeDefined(); @@ -58,8 +58,8 @@ describe('Monitor Component vnMonitorSalesSearchPanel', () => { describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { - controller.filter.from = new Date(); - controller.filter.to = new Date(); + controller.filter.from = Date.vnNew(); + controller.filter.to = Date.vnNew(); controller.scopeDays = 1; diff --git a/modules/monitor/front/index/tickets/index.js b/modules/monitor/front/index/tickets/index.js index 91d9079d8..2f2dead05 100644 --- a/modules/monitor/front/index/tickets/index.js +++ b/modules/monitor/front/index/tickets/index.js @@ -91,7 +91,7 @@ export default class Controller extends Section { $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); @@ -105,7 +105,7 @@ export default class Controller extends Section { } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); diff --git a/modules/monitor/front/index/tickets/index.spec.js b/modules/monitor/front/index/tickets/index.spec.js index 5d42743c1..c12ea6844 100644 --- a/modules/monitor/front/index/tickets/index.spec.js +++ b/modules/monitor/front/index/tickets/index.spec.js @@ -32,7 +32,7 @@ describe('Component vnMonitorSalesTickets', () => { let params = controller.fetchParams({ scopeDays: 2 }); - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); to.setDate(to.getDate() + params.scopeDays); @@ -66,14 +66,14 @@ describe('Component vnMonitorSalesTickets', () => { describe('compareDate()', () => { it('should return warning when the date is the present', () => { - let today = new Date(); + let today = Date.vnNew(); let result = controller.compareDate(today); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.compareDate(futureDate); @@ -81,7 +81,7 @@ describe('Component vnMonitorSalesTickets', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); @@ -99,7 +99,7 @@ describe('Component vnMonitorSalesTickets', () => { describe('dateRange()', () => { it('should return two dates with the hours at the start and end of the given date', () => { - const now = new Date(); + const now = Date.vnNew(); const today = now.getDate(); diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index 5873189f8..f11367579 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -9,7 +9,7 @@ describe('order new()', () => { try { const options = {transaction: tx}; - const landed = new Date(); + const landed = Date.vnNew(); const addressFk = 6; const agencyModeFk = 1; @@ -30,7 +30,7 @@ describe('order new()', () => { try { const options = {transaction: tx}; - const landed = new Date(); + const landed = Date.vnNew(); const addressFk = 121; const agencyModeFk = 1; diff --git a/modules/order/front/basic-data/index.spec.js b/modules/order/front/basic-data/index.spec.js index 01009d085..21dee0765 100644 --- a/modules/order/front/basic-data/index.spec.js +++ b/modules/order/front/basic-data/index.spec.js @@ -46,7 +46,7 @@ describe('Order', () => { it('should set agencyModeFk to null and get the available agencies if the order has landed and client', async() => { controller.order.agencyModeFk = 999; controller.order.addressFk = 999; - controller.order.landed = new Date(); + controller.order.landed = Date.vnNew(); const expectedAgencies = [{id: 1}, {id: 2}]; diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index a8e6e977e..750f2e226 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -8,7 +8,7 @@ export default class Controller extends Section { } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); date = new Date(date); diff --git a/modules/order/front/index/index.spec.js b/modules/order/front/index/index.spec.js index 5b85b3333..abe336478 100644 --- a/modules/order/front/index/index.spec.js +++ b/modules/order/front/index/index.spec.js @@ -26,14 +26,14 @@ describe('Component vnOrderIndex', () => { describe('compareDate()', () => { it('should return warning when the date is the present', () => { - let curDate = new Date(); + let curDate = Date.vnNew(); let result = controller.compareDate(curDate); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.compareDate(futureDate); @@ -41,7 +41,7 @@ describe('Component vnOrderIndex', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index 0ecec7e88..9d1268958 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -74,35 +74,35 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const stmts = []; const stmt = new ParameterizedSQL( `SELECT * FROM ( - SELECT r.id routeFk, - r.created, - r.agencyModeFk, + SELECT r.id routeFk, + r.created, + r.agencyModeFk, am.name agencyModeName, - am.agencyFk, + am.agencyFk, a.name agencyAgreement, SUM(t.packages) packages, r.m3, - r.kmEnd - r.kmStart kmTotal, - CAST(IFNULL(sat.routePrice, - (sat.kmPrice * (GREATEST(r.kmEnd - r.kmStart , sat.minimumKm)) - + GREATEST(r.m3 , sat.minimumM3) * sat.m3Price) - + sat.packagePrice * SUM(t.packages) ) + r.kmEnd - r.kmStart kmTotal, + CAST(IFNULL(sat.routePrice, + (sat.kmPrice * (GREATEST(r.kmEnd - r.kmStart , sat.minimumKm)) + + GREATEST(r.m3 , sat.minimumM3) * sat.m3Price) + + sat.packagePrice * SUM(t.packages) ) AS DECIMAL(10,2)) price, r.invoiceInFk, sat.supplierFk, s.name supplierName FROM vn.route r - LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id + LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id LEFT JOIN vn.agency a ON am.agencyFk = a.id 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 + LEFT JOIN vn.supplier s ON s.id = sat.supplierFk WHERE r.created > DATE_ADD(?, INTERVAL -2 MONTH) AND sat.supplierFk IS NOT NULL GROUP BY r.id ) a` diff --git a/modules/route/back/methods/agency-term/specs/filter.spec.js b/modules/route/back/methods/agency-term/specs/filter.spec.js index d6c00e585..41e696157 100644 --- a/modules/route/back/methods/agency-term/specs/filter.spec.js +++ b/modules/route/back/methods/agency-term/specs/filter.spec.js @@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models; describe('AgencyTerm filter()', () => { const authUserId = 9; - const today = new Date(); + const today = Date.vnNew(); today.setHours(2, 0, 0, 0); it('should return all results matching the filter', async() => { @@ -57,10 +57,10 @@ describe('AgencyTerm filter()', () => { const options = {transaction: tx}; try { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); - const to = new Date(); + const to = Date.vnNew(); to.setHours(23, 59, 59, 999); const ctx = { diff --git a/modules/route/back/methods/route/getTickets.js b/modules/route/back/methods/route/getTickets.js index 708644c1a..1eb9e27f5 100644 --- a/modules/route/back/methods/route/getTickets.js +++ b/modules/route/back/methods/route/getTickets.js @@ -50,14 +50,17 @@ module.exports = Self => { am.name AS agencyModeName, u.nickname AS userNickname, vn.ticketTotalVolume(t.id) AS volume, - tob.description + tob.description, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt FROM vn.route r JOIN ticket t ON t.routeFk = r.id + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk LEFT JOIN ticketState ts ON ts.ticketFk = t.id LEFT JOIN state st ON st.id = ts.stateFk LEFT JOIN warehouse wh ON wh.id = t.warehouseFk LEFT JOIN observationType ot ON ot.code = 'delivery' - LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id + LEFT JOIN ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = ot.id LEFT JOIN address a ON a.id = t.addressFk LEFT JOIN agencyMode am ON am.id = t.agencyModeFk @@ -70,7 +73,9 @@ module.exports = Self => { const where = filter.where; where['r.id'] = filter.id; - stmt.merge(conn.makeSuffix(filter)); + stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(conn.makeGroupBy('t.id')); + stmt.merge(conn.makeOrderBy(filter.order)); const tickets = await conn.executeStmt(stmt, myOptions); diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index d1fc6b297..9192854f8 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('route clone()', () => { - const createdDate = new Date(); + const createdDate = Date.vnNew(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { const ids = [996, 997, 998, 999]; diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 9d481f21e..18c0ca04f 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('Route filter()', () => { - const today = new Date(); + const today = Date.vnNew(); today.setHours(2, 0, 0, 0); it('should return the routes matching "search"', async() => { @@ -23,10 +23,10 @@ describe('Route filter()', () => { const options = {transaction: tx}; try { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); - const to = new Date(); + const to = Date.vnNew(); to.setHours(23, 59, 59, 999); const ctx = { args: { diff --git a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js index bb38cb50e..0acc6c1a7 100644 --- a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js +++ b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js @@ -23,7 +23,7 @@ describe('route getSuggestedTickets()', () => { await ticketInRoute.updateAttributes({ routeFk: null, - landed: new Date() + landed: Date.vnNew() }, options); const result = await models.Route.getSuggestedTickets(routeID, options); diff --git a/modules/route/back/methods/route/specs/insertTicket.spec.js b/modules/route/back/methods/route/specs/insertTicket.spec.js index 7c60e755f..19d02e1ef 100644 --- a/modules/route/back/methods/route/specs/insertTicket.spec.js +++ b/modules/route/back/methods/route/specs/insertTicket.spec.js @@ -23,7 +23,7 @@ describe('route insertTicket()', () => { const ticketInRoute = await app.models.Ticket.findById(ticketId, null, options); await ticketInRoute.updateAttributes({ routeFk: null, - landed: new Date() + landed: Date.vnNew() }, options); const result = await app.models.Route.insertTicket(routeId, ticketId, options); diff --git a/modules/route/back/methods/route/updateWorkCenter.js b/modules/route/back/methods/route/updateWorkCenter.js index 7796fba41..75169ce7e 100644 --- a/modules/route/back/methods/route/updateWorkCenter.js +++ b/modules/route/back/methods/route/updateWorkCenter.js @@ -33,12 +33,13 @@ module.exports = Self => { } try { + const date = Date.vnNew(); const [result] = await Self.rawSql(` SELECT IFNULL(wl.workCenterFk, r.defaultWorkCenterFk) AS commissionWorkCenter FROM vn.routeConfig r LEFT JOIN vn.workerLabour wl ON wl.workerFk = ? - AND CURDATE() BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()); - `, [userId], myOptions); + AND ? BETWEEN wl.started AND IFNULL(wl.ended, ?); + `, [userId, date, date], myOptions); const route = await models.Route.findById(id, null, myOptions); await route.updateAttribute('commissionWorkCenterFk', result.commissionWorkCenter, myOptions); diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 94f6db09c..7c19a26cd 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -54,7 +54,7 @@ export default class Controller extends Section { openClonationDialog() { this.$.clonationDialog.show(); - this.createdDate = new Date(); + this.createdDate = Date.vnNew(); } cloneSelectedRoutes() { diff --git a/modules/route/front/index/index.spec.js b/modules/route/front/index/index.spec.js index c1f414d5e..399ece714 100644 --- a/modules/route/front/index/index.spec.js +++ b/modules/route/front/index/index.spec.js @@ -58,7 +58,7 @@ describe('Component vnRouteIndex', () => { describe('cloneSelectedRoutes()', () => { it('should perform an http request to Routes/clone', () => { - controller.createdDate = new Date(); + controller.createdDate = Date.vnNew(); $httpBackend.expect('POST', 'Routes/clone').respond(); controller.cloneSelectedRoutes(); diff --git a/modules/route/front/main/index.js b/modules/route/front/main/index.js index 938f81bcc..8c57bbad6 100644 --- a/modules/route/front/main/index.js +++ b/modules/route/front/main/index.js @@ -3,11 +3,11 @@ import ModuleMain from 'salix/components/module-main'; export default class Route extends ModuleMain { $postLink() { - const to = new Date(); + const to = Date.vnNew(); to.setDate(to.getDate() + 1); to.setHours(0, 0, 0, 0); - const from = new Date(); + const from = Date.vnNew(); from.setDate(from.getDate()); from.setHours(0, 0, 0, 0); @@ -21,7 +21,7 @@ export default class Route extends ModuleMain { $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); diff --git a/modules/route/front/main/index.spec.js b/modules/route/front/main/index.spec.js index e5724b493..0c16a7b1f 100644 --- a/modules/route/front/main/index.spec.js +++ b/modules/route/front/main/index.spec.js @@ -15,7 +15,7 @@ describe('Route Component vnRoute', () => { let params = controller.fetchParams({ scopeDays: 2 }); - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); to.setDate(to.getDate() + params.scopeDays); diff --git a/modules/route/front/search-panel/index.spec.js b/modules/route/front/search-panel/index.spec.js index 16e1a5cfc..ae15e16e4 100644 --- a/modules/route/front/search-panel/index.spec.js +++ b/modules/route/front/search-panel/index.spec.js @@ -15,7 +15,7 @@ describe('Route Component vnRouteSearchPanel', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; - controller.from = new Date(); + controller.from = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.from).toBeDefined(); @@ -26,7 +26,7 @@ describe('Route Component vnRouteSearchPanel', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; - controller.to = new Date(); + controller.to = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.to).toBeDefined(); @@ -35,8 +35,8 @@ describe('Route Component vnRouteSearchPanel', () => { describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { - controller.filter.from = new Date(); - controller.filter.to = new Date(); + controller.filter.from = Date.vnNew(); + controller.filter.to = Date.vnNew(); controller.scopeDays = 1; diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index 86f558634..a64ad4ff7 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -10,26 +10,26 @@ - - - - - {{$ctrl.summary.route.worker.user.name}} - @@ -40,35 +40,35 @@ - - - -

- Ticket

-

Ticket @@ -77,45 +77,49 @@ Order - Ticket id - Alias + Street + City + PC + Client + Warehouse Packages - Warehouse - PC - Street + Packaging + Ticket {{ticket.priority | dashIfEmpty}} + {{ticket.street}} + {{ticket.city}} + {{ticket.postalCode}} + + + {{ticket.nickname}} + + + {{ticket.warehouseName}} + {{ticket.packages}} + {{ticket.volume}} + {{ticket.ipt}} - {{ticket.id}} - - {{ticket.nickname}} - - - {{ticket.packages}} - {{ticket.volume}} - {{ticket.warehouseName}} - {{ticket.postalCode}} - {{ticket.street}} - - - + + @@ -123,12 +127,12 @@ - - diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index dae894ac7..18d6fb160 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -6,9 +6,9 @@ data="$ctrl.tickets" auto-load="true"> - -
@@ -25,18 +25,18 @@ vn-tooltip="Open buscaman" icon="icon-buscaman"> - - - City PC Client + Warehouse Packages + Packaging Ticket @@ -100,8 +102,10 @@ {{::ticket.nickname}} + {{ticket.warehouseName}} {{::ticket.packages}} {{::ticket.volume | number:2}} + {{::ticket.ipt}}
- - @@ -160,7 +164,7 @@ - - - \ No newline at end of file + diff --git a/modules/shelving/back/models/parking.json b/modules/shelving/back/models/parking.json index 7efcf72d3..53fec6e69 100644 --- a/modules/shelving/back/models/parking.json +++ b/modules/shelving/back/models/parking.json @@ -29,5 +29,12 @@ "pickingOrder": { "type": "number" } + }, + "relations": { + "saleGroup": { + "type": "hasMany", + "model": "saleGroup", + "foreignKey": "parkingFk" + } } } diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 44549c65c..4e509aafc 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -16,10 +16,6 @@ module.exports = Self => { message: 'The social name cannot be empty' }); - Self.validatesUniquenessOf('name', { - message: 'The supplier name must be unique' - }); - if (this.city) { Self.validatesPresenceOf('city', { message: 'City cannot be empty' @@ -117,6 +113,27 @@ module.exports = Self => { throw new UserError('You can not modify is pay method checked'); }); + Self.validateAsync('name', 'countryFk', hasSupplierSameName, { + message: 'A supplier with the same name already exists. Change the country.' + }); + + async function hasSupplierSameName(err, done) { + if (!this.name || !this.countryFk) done(); + const supplier = await Self.app.models.Supplier.findOne( + { + where: { + name: this.name, + countryFk: this.countryFk + }, + fields: ['id'] + }); + + if (supplier && supplier.id != this.id) + err(); + + done(); + } + Self.observe('before save', async function(ctx) { const changes = ctx.data || ctx.instance; const orgData = ctx.currentInstance; diff --git a/modules/supplier/front/consumption/index.js b/modules/supplier/front/consumption/index.js index 8de6a1e71..9af0d1747 100644 --- a/modules/supplier/front/consumption/index.js +++ b/modules/supplier/front/consumption/index.js @@ -11,11 +11,11 @@ class Controller extends Section { } setDefaultFilter() { - const minDate = new Date(); + const minDate = Date.vnNew(); minDate.setHours(0, 0, 0, 0); minDate.setMonth(minDate.getMonth() - 2); - const maxDate = new Date(); + const maxDate = Date.vnNew(); maxDate.setHours(23, 59, 59, 59); this.filterParams = { diff --git a/modules/supplier/front/consumption/index.spec.js b/modules/supplier/front/consumption/index.spec.js index ebf19ccec..0ac531a68 100644 --- a/modules/supplier/front/consumption/index.spec.js +++ b/modules/supplier/front/consumption/index.spec.js @@ -28,7 +28,7 @@ describe('Supplier', () => { it('should call the window.open function', () => { jest.spyOn(window, 'open').mockReturnThis(); - const now = new Date(); + const now = Date.vnNew(); controller.$.model.userParams = { from: now, to: now @@ -86,7 +86,7 @@ describe('Supplier', () => { {id: 1, email: 'batman@gothamcity.com'} ]); - const now = new Date(); + const now = Date.vnNew(); controller.$.model.userParams = { from: now, to: now diff --git a/modules/supplier/front/descriptor/index.js b/modules/supplier/front/descriptor/index.js index a26d9c510..9f23ce68c 100644 --- a/modules/supplier/front/descriptor/index.js +++ b/modules/supplier/front/descriptor/index.js @@ -13,7 +13,7 @@ class Controller extends Descriptor { get entryFilter() { if (!this.supplier) return null; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const from = new Date(date.getTime()); diff --git a/modules/ticket/back/locale/ticket/es.yml b/modules/ticket/back/locale/ticket/es.yml index 2c524a74f..15b5a39bf 100644 --- a/modules/ticket/back/locale/ticket/es.yml +++ b/modules/ticket/back/locale/ticket/es.yml @@ -21,3 +21,5 @@ companyFk: empresa agencyModeFk: agencia ticketFk: ticket mergedTicket: ticket fusionado +withWarningAccept: aviso negativos +isWithoutNegatives: sin negativos diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 67919e76c..ac397d38e 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -14,7 +14,7 @@ describe('ticket moveExpeditions()', () => { const options = {transaction: tx}; myCtx.args = { clientId: 1101, - landed: new Date(), + landed: Date.vnNew(), warehouseId: 1, addressId: 121, agencyModeId: 1, diff --git a/modules/ticket/back/methods/sale/getClaimableFromTicket.js b/modules/ticket/back/methods/sale/getClaimableFromTicket.js index ecbc52b94..c51781f59 100644 --- a/modules/ticket/back/methods/sale/getClaimableFromTicket.js +++ b/modules/ticket/back/methods/sale/getClaimableFromTicket.js @@ -24,24 +24,24 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const query = ` - SELECT - s.id AS saleFk, - t.id AS ticketFk, + SELECT + s.id AS saleFk, + t.id AS ticketFk, t.landed, - s.concept, - s.itemFk, - s.quantity, - s.price, - s.discount, + s.concept, + s.itemFk, + s.quantity, + s.price, + s.discount, t.nickname - FROM vn.ticket t + FROM vn.ticket t 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, ?) + WHERE (t.landed) >= TIMESTAMPADD(DAY, -7, ?) AND t.id = ? AND cb.id IS NULL ORDER BY t.landed DESC, t.id DESC`; diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index c0c431636..febef9730 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -64,7 +64,7 @@ module.exports = Self => { const refundTickets = []; - const now = new Date(); + const now = Date.vnNew(); const mappedTickets = new Map(); for (let ticketId of ticketsIds) { diff --git a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js index 746e1b7fc..175bc4e4b 100644 --- a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js +++ b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js @@ -9,7 +9,7 @@ describe('ticket changeState()', () => { accessToken: {userId: 9}, }; const ctx = {req: activeCtx}; - const now = new Date(); + const now = Date.vnNew(); const sampleTicket = { shipped: now, landed: now, diff --git a/modules/ticket/back/methods/ticket/canBeInvoiced.js b/modules/ticket/back/methods/ticket/canBeInvoiced.js index a009d63cf..6b8f9e71a 100644 --- a/modules/ticket/back/methods/ticket/canBeInvoiced.js +++ b/modules/ticket/back/methods/ticket/canBeInvoiced.js @@ -43,7 +43,7 @@ module.exports = function(Self) { ticketBases => ticketBases.hasSomeNegativeBase ); - const today = new Date(); + const today = Date.vnNew(); const invalidTickets = tickets.some(ticket => { const shipped = new Date(ticket.shipped); diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 327278c2b..3726d85b7 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -17,14 +17,14 @@ module.exports = Self => { }); Self.closeAll = async() => { - const toDate = new Date(); + const toDate = Date.vnNew(); toDate.setHours(0, 0, 0, 0); toDate.setDate(toDate.getDate() - 1); - const todayMinDate = new Date(); + const todayMinDate = Date.vnNew(); todayMinDate.setHours(0, 0, 0, 0); - const todayMaxDate = new Date(); + const todayMaxDate = Date.vnNew(); todayMaxDate.setHours(23, 59, 59, 59); // Prevent closure for current day @@ -32,7 +32,7 @@ module.exports = Self => { throw new UserError('You cannot close tickets for today'); const tickets = await Self.rawSql(` - SELECT + SELECT t.id, t.clientFk, t.companyFk, @@ -53,7 +53,7 @@ module.exports = Self => { JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk WHERE al.code = 'PACKED' OR (am.code = 'refund' AND al.code != 'delivered') - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) + AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index f4a4bb98d..94b91e237 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -83,6 +83,11 @@ module.exports = Self => { type: 'boolean', description: 'Is whithout negatives', required: true + }, + { + arg: 'withWarningAccept', + type: 'boolean', + description: 'Has pressed in confirm message', }], returns: { type: ['object'], diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index a2add2e82..262b3fd74 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -137,7 +137,7 @@ module.exports = Self => { Self.filter = async(ctx, filter, options) => { const userId = ctx.req.accessToken.userId; const conn = Self.dataSource.connector; - const date = new Date(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const models = Self.app.models; const args = ctx.args; @@ -295,10 +295,10 @@ module.exports = Self => { stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems'); stmt = new ParameterizedSQL(` - CREATE TEMPORARY TABLE tmp.sale_getProblems + CREATE TEMPORARY TABLE tmp.sale_getProblems (INDEX (ticketFk)) ENGINE = MEMORY - SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped + 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) @@ -350,7 +350,7 @@ module.exports = Self => { const ticketsIndex = stmts.push(stmt) - 1; stmts.push( - `DROP TEMPORARY TABLE + `DROP TEMPORARY TABLE tmp.filter, tmp.ticket_problems`); diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 19571bb51..1e1646cba 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,14 +50,14 @@ module.exports = Self => { required: false }, { - arg: 'state', - type: 'string', + arg: 'isNotValidated', + type: 'boolean', description: 'Origin state', required: false }, { - arg: 'futureState', - type: 'string', + arg: 'futureIsNotValidated', + type: 'boolean', description: 'Destination state', required: false }, @@ -92,13 +92,23 @@ module.exports = Self => { case 'futureId': return {'f.futureId': value}; case 'ipt': - return {'f.ipt': value}; + return {or: + [ + {'f.ipt': {like: `%${value}%`}}, + {'f.ipt': null} + ] + }; case 'futureIpt': - return {'f.futureIpt': value}; - case 'state': - return {'f.stateCode': {like: `%${value}%`}}; - case 'futureState': - return {'f.futureStateCode': {like: `%${value}%`}}; + return {or: + [ + {'f.futureIpt': {like: `%${value}%`}}, + {'f.futureIpt': null} + ] + }; + case 'isNotValidated': + return {'f.isNotValidated': value}; + case 'futureIsNotValidated': + return {'f.futureIsNotValidated': value}; } }); diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 4e9c22a24..9739f5985 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -26,7 +26,7 @@ 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(); + const date = Date.vnNew(); date.setHours(0, 0, 0, 0); const myOptions = {}; diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index c9bb126fd..722c3294e 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -38,7 +38,7 @@ module.exports = Self => { }] }, myOptions); - const now = new Date(); + const now = Date.vnNew(); const maxDate = new Date(ticket.updated); maxDate.setHours(maxDate.getHours() + 1); @@ -56,7 +56,7 @@ module.exports = Self => { await models.Chat.sendCheckingPresence(ctx, salesPersonId, message); } - const fullYear = new Date().getFullYear(); + const fullYear = Date.vnNew().getFullYear(); const newShipped = ticket.shipped; const newLanded = ticket.landed; newShipped.setFullYear(fullYear); diff --git a/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js b/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js index 8b7e1685d..806f80227 100644 --- a/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js +++ b/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js @@ -61,7 +61,7 @@ describe('ticket canBeInvoiced()', () => { const ticket = await models.Ticket.findById(ticketId, null, options); - const shipped = new Date(); + const shipped = Date.vnNew(); shipped.setDate(shipped.getDate() + 1); await ticket.updateAttribute('shipped', shipped, options); diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 3a9c2db50..d65c87654 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -4,8 +4,8 @@ const LoopBackContext = require('loopback-context'); describe('ticket componentUpdate()', () => { const userID = 1101; const ticketID = 11; - const today = new Date(); - const tomorrow = new Date(); + const today = Date.vnNew(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 1); @@ -19,11 +19,11 @@ describe('ticket componentUpdate()', () => { beforeAll(async() => { const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; - componentOfSaleSeven = `SELECT value - FROM vn.saleComponent + componentOfSaleSeven = `SELECT value + FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; - componentOfSaleEight = `SELECT value - FROM vn.saleComponent + componentOfSaleEight = `SELECT value + FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven); firstvalueBeforeChange = componentValue.value; diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 688b0de61..6cc1a3ad2 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -26,9 +26,9 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 9}}, args: { @@ -54,10 +54,10 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); yesterday.setHours(0, 0, 0, 0); - const today = new Date(); + const today = Date.vnNew(); today.setHours(23, 59, 59, 59); const ctx = {req: {accessToken: {userId: 9}}, args: { diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index aab053127..11571bede 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -1,9 +1,9 @@ const models = require('vn-loopback/server/server').models; describe('TicketFuture getTicketsAdvance()', () => { - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); - let tomorrow = new Date(); + let tomorrow = Date.vnNew(); tomorrow.setDate(today.getDate() + 1); it('should return the tickets passing the required data', async() => { @@ -29,7 +29,7 @@ describe('TicketFuture getTicketsAdvance()', () => { } }); - it('should return the tickets matching the origin grouped state', async() => { + it('should return the tickets matching the origin pending state', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -39,7 +39,7 @@ describe('TicketFuture getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - state: 'OK' + futureIsNotValidated: true }; const ctx = {req: {accessToken: {userId: 9}}, args}; @@ -54,7 +54,7 @@ describe('TicketFuture getTicketsAdvance()', () => { } }); - it('should return the tickets matching the destination grouped state', async() => { + it('should return the tickets matching the destination pending state', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -64,13 +64,13 @@ describe('TicketFuture getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - futureState: 'FREE' + isNotValidated: true }; const ctx = {req: {accessToken: {userId: 9}}, args}; const result = await models.Ticket.getTicketsAdvance(ctx, options); - expect(result.length).toBeGreaterThan(0); + expect(result.length).toEqual(0); await tx.rollback(); } catch (e) { @@ -89,7 +89,7 @@ describe('TicketFuture getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - ipt: 'Vertical' + ipt: 'V' }; const ctx = {req: {accessToken: {userId: 9}}, args}; @@ -114,7 +114,7 @@ describe('TicketFuture getTicketsAdvance()', () => { dateFuture: tomorrow, dateToAdvance: today, warehouseFk: 1, - tfIpt: 'Vertical' + tfIpt: 'V' }; const ctx = {req: {accessToken: {userId: 9}}, args}; diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js index 51639e304..44896493f 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket getTicketsFuture()', () => { - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); it('should return the tickets passing the required data', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 275484f67..6b533e47c 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -5,8 +5,8 @@ describe('ticket merge()', () => { const tickets = [{ originId: 13, destinationId: 12, - originShipped: new Date(), - destinationShipped: new Date(), + originShipped: Date.vnNew(), + destinationShipped: Date.vnNew(), workerFk: 1 }]; diff --git a/modules/ticket/back/methods/ticket/specs/new.spec.js b/modules/ticket/back/methods/ticket/specs/new.spec.js index fce7cdceb..0a2f93bc4 100644 --- a/modules/ticket/back/methods/ticket/specs/new.spec.js +++ b/modules/ticket/back/methods/ticket/specs/new.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; let UserError = require('vn-loopback/util/user-error'); describe('ticket new()', () => { - const today = new Date(); + const today = Date.vnNew(); const ctx = {req: {accessToken: {userId: 1}}}; it('should throw an error if the client isnt frozen and isnt active', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index 5470382f9..1db1b6eaa 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -8,7 +8,7 @@ describe('sale priceDifference()', () => { try { const options = {transaction: tx}; - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 1); const ctx = {req: {accessToken: {userId: 1106}}}; @@ -45,8 +45,8 @@ describe('sale priceDifference()', () => { const ctx = {req: {accessToken: {userId: 1106}}}; ctx.args = { id: 1, - landed: new Date(), - shipped: new Date(), + landed: Date.vnNew(), + shipped: Date.vnNew(), addressId: 121, zoneId: 3, warehouseId: 1 @@ -68,7 +68,7 @@ describe('sale priceDifference()', () => { try { const options = {transaction: tx}; - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 1); const ctx = {req: {accessToken: {userId: 1106}}}; diff --git a/modules/ticket/back/methods/ticket/specs/restore.spec.js b/modules/ticket/back/methods/ticket/specs/restore.spec.js index bd976d124..3b35ae2b4 100644 --- a/modules/ticket/back/methods/ticket/specs/restore.spec.js +++ b/modules/ticket/back/methods/ticket/specs/restore.spec.js @@ -24,8 +24,8 @@ describe('ticket restore()', () => { let error; const tx = await app.models.Ticket.beginTransaction({}); - const now = new Date(); - now.setHours(now.getHours() - 1); + const now = Date.vnNew(); + now.setHours(now.getHours() - 1.1); try { const options = {transaction: tx}; @@ -46,7 +46,7 @@ describe('ticket restore()', () => { it('should restore the ticket making its state no longer deleted', async() => { const tx = await app.models.Ticket.beginTransaction({}); - const now = new Date(); + const now = Date.vnNew(); try { const options = {transaction: tx}; diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js index 848913fe1..a57968fc1 100644 --- a/modules/ticket/back/methods/ticket/summary.js +++ b/modules/ticket/back/methods/ticket/summary.js @@ -71,7 +71,7 @@ module.exports = Self => { }, { relation: 'address', scope: { - fields: ['street', 'city', 'provinceFk', 'phone', 'mobile', 'postalCode'], + fields: ['street', 'city', 'provinceFk', 'phone', 'mobile', 'postalCode', 'isEqualizated'], include: { relation: 'province', scope: { diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 62e763c8f..bee01a875 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -41,6 +41,12 @@ "SaleComponent": { "dataSource": "vn" }, + "SaleGroup": { + "dataSource": "vn" + }, + "SaleGroupDetail": { + "dataSource": "vn" + }, "SaleTracking": { "dataSource": "vn" }, diff --git a/modules/ticket/back/models/sale.json b/modules/ticket/back/models/sale.json index b30954ad1..669b05be6 100644 --- a/modules/ticket/back/models/sale.json +++ b/modules/ticket/back/models/sale.json @@ -75,6 +75,11 @@ "type": "hasOne", "model": "ItemShelvingSale", "foreignKey": "saleFk" + }, + "saleGroupDetail": { + "type": "hasOne", + "model": "SaleGroupDetail", + "foreignKey": "saleFk" } } } diff --git a/modules/ticket/back/models/saleGroup.json b/modules/ticket/back/models/saleGroup.json new file mode 100644 index 000000000..d5cf82cb5 --- /dev/null +++ b/modules/ticket/back/models/saleGroup.json @@ -0,0 +1,31 @@ +{ + "name": "SaleGroup", + "base": "VnModel", + "options": { + "mysql": { + "table": "saleGroup" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "parkingFk": { + "type": "number" + } + }, + "relations": { + "saleGroupDetail": { + "type": "hasMany", + "model": "SaleGroupDetail", + "foreignKey": "saleGroupFk" + }, + "parking": { + "type": "belongsTo", + "model": "Parking", + "foreignKey": "parkingFk" + } + } +} diff --git a/modules/ticket/back/models/saleGroupDetail.json b/modules/ticket/back/models/saleGroupDetail.json new file mode 100644 index 000000000..2fbc71bbd --- /dev/null +++ b/modules/ticket/back/models/saleGroupDetail.json @@ -0,0 +1,31 @@ +{ + "name": "SaleGroupDetail", + "base": "VnModel", + "options": { + "mysql": { + "table": "saleGroupDetail" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" + }, + "saleFk": { + "type": "number" + } + }, + "relations": { + "sale": { + "type": "belongsTo", + "model": "Sale", + "foreignKey": "saleFk" + }, + "saleGroup": { + "type": "belongsTo", + "model": "SaleGroup", + "foreignKey": "saleGroupFk" + } + } +} diff --git a/modules/ticket/front/advance-search-panel/index.html b/modules/ticket/front/advance-search-panel/index.html index e8d5dc60d..dfe1f6b08 100644 --- a/modules/ticket/front/advance-search-panel/index.html +++ b/modules/ticket/front/advance-search-panel/index.html @@ -39,26 +39,18 @@ - - - {{name}} - - - - - {{name}} - - + + + + { - for (let state of res.data) { - groupedStates.push({ - id: state.id, - code: state.code, - name: this.$t(state.code) - }); - } - this.groupedStates = groupedStates; - }); - } - getItemPackingTypes() { let itemPackingTypes = []; const filter = { diff --git a/modules/ticket/front/advance-search-panel/locale/es.yml b/modules/ticket/front/advance-search-panel/locale/es.yml index 3dce7dae5..4ea2fc737 100644 --- a/modules/ticket/front/advance-search-panel/locale/es.yml +++ b/modules/ticket/front/advance-search-panel/locale/es.yml @@ -1 +1,3 @@ Advance tickets: Adelantar tickets +Pending Origin: Pendiente origen +Pending Destination: Pendiente destino diff --git a/modules/ticket/front/advance/index.html b/modules/ticket/front/advance/index.html index f63c0fbf7..3dd52b909 100644 --- a/modules/ticket/front/advance/index.html +++ b/modules/ticket/front/advance/index.html @@ -32,8 +32,8 @@ - Origin - Destination + Origin + Destination @@ -43,19 +43,30 @@ check-field="checked"> + + ID Date - + IPT State - + + Liters + + + Stock + + + Lines + + Import @@ -64,7 +75,7 @@ Date - + IPT @@ -73,13 +84,10 @@ Liters - - Stock - Lines - + Import @@ -92,6 +100,13 @@ vn-click-stop> + + + + + {{::ticket.futureLiters | dashIfEmpty}} + {{::ticket.hasStock | dashIfEmpty}} + {{::ticket.futureLines | dashIfEmpty}} {{::(ticket.futureTotalWithVat ? ticket.futureTotalWithVat : 0) | currency: 'EUR': 2}} @@ -136,7 +154,6 @@ {{::ticket.liters | dashIfEmpty}} - {{::ticket.hasStock | dashIfEmpty}} {{::ticket.lines | dashIfEmpty}} diff --git a/modules/ticket/front/advance/index.js b/modules/ticket/front/advance/index.js index b770440f1..1b9272bcc 100644 --- a/modules/ticket/front/advance/index.js +++ b/modules/ticket/front/advance/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import Section from 'salix/components/section'; +import './style.scss'; export default class Controller extends Section { constructor($element, $) { @@ -62,19 +63,22 @@ export default class Controller extends Section { } setDefaultFilter() { - let today = new Date(); + let today = Date.vnNew(); const tomorrow = new Date(today); tomorrow.setDate(tomorrow.getDate() + 1); - this.filterParams = { - dateFuture: tomorrow, - dateToAdvance: today, - warehouseFk: this.vnConfig.warehouseFk - }; - this.$.model.applyFilter(null, this.filterParams); + this.$http.get(`UserConfigs/getUserConfig`) + .then(res => { + this.filterParams = { + dateFuture: tomorrow, + dateToAdvance: today, + warehouseFk: res.data.warehouseFk + }; + this.$.model.addFilter({}, this.filterParams); + }); } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); @@ -128,6 +132,11 @@ export default class Controller extends Section { }); } + agencies(futureAgency, agency) { + return this.$t(`Origin agency`, {agency: futureAgency}) + + '
' + this.$t(`Destination agency`, {agency: agency}); + } + moveTicketsAdvance() { let ticketsToMove = []; this.checked.forEach(ticket => { @@ -157,6 +166,10 @@ export default class Controller extends Section { return {'liters': value}; case 'lines': return {'lines': value}; + case 'futureLiters': + return {'futureLiters': value}; + case 'futureLines': + return {'futureLines': value}; case 'ipt': return {'ipt': value}; case 'futureIpt': diff --git a/modules/ticket/front/advance/index.spec.js b/modules/ticket/front/advance/index.spec.js index c5a04daee..6874f914b 100644 --- a/modules/ticket/front/advance/index.spec.js +++ b/modules/ticket/front/advance/index.spec.js @@ -26,14 +26,14 @@ describe('Component vnTicketAdvance', () => { describe('compareDate()', () => { it('should return warning when the date is the present', () => { - let today = new Date(); + let today = Date.vnNew(); let result = controller.compareDate(today); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.compareDate(futureDate); @@ -41,7 +41,7 @@ describe('Component vnTicketAdvance', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); @@ -81,7 +81,7 @@ describe('Component vnTicketAdvance', () => { describe('dateRange()', () => { it('should return two dates with the hours at the start and end of the given date', () => { - const now = new Date(); + const now = Date.vnNew(); const today = now.getDate(); diff --git a/modules/ticket/front/advance/locale/es.yml b/modules/ticket/front/advance/locale/es.yml index b444fbdd3..da22cd433 100644 --- a/modules/ticket/front/advance/locale/es.yml +++ b/modules/ticket/front/advance/locale/es.yml @@ -4,3 +4,6 @@ Advance confirmation: ¿Desea adelantar {{checked}} tickets? Success: Tickets movidos correctamente Lines: Líneas Liters: Litros +Item Packing Type: Encajado +Origin agency: "Agencia origen: {{agency}}" +Destination agency: "Agencia destino: {{agency}}" diff --git a/modules/ticket/front/advance/style.scss b/modules/ticket/front/advance/style.scss new file mode 100644 index 000000000..8fa9de438 --- /dev/null +++ b/modules/ticket/front/advance/style.scss @@ -0,0 +1,7 @@ +@import "variables"; + +vn-ticket-advance{ + vn-icon { + color: #f7931e + } +} diff --git a/modules/ticket/front/basic-data/step-one/index.js b/modules/ticket/front/basic-data/step-one/index.js index f532265e2..99782de44 100644 --- a/modules/ticket/front/basic-data/step-one/index.js +++ b/modules/ticket/front/basic-data/step-one/index.js @@ -75,8 +75,10 @@ class Controller extends Component { } set shipped(value) { + if (new Date(this.ticket.shipped).toDateString() != value.toDateString()) + value.setHours(0, 0, 0, 0); + this.ticket.shipped = value; - this.ticket.shipped.setHours(0, 0, 0, 0); this.getLanded({ shipped: value, addressFk: this.ticket.addressFk, diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index 2b14c18cc..30946dab0 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -67,7 +67,7 @@ describe('Ticket', () => { jest.spyOn(controller, 'getShipped'); controller.ticket.addressFk = 99; controller.addressId = 100; - const landed = new Date(); + const landed = Date.vnNew(); const expectedResult = { landed: landed, addressFk: 100, @@ -101,7 +101,7 @@ describe('Ticket', () => { describe('shipped() getter', () => { it('should return the shipped property', () => { - const shipped = new Date(); + const shipped = Date.vnNew(); controller.ticket.shipped = shipped; expect(controller.shipped).toEqual(shipped); @@ -111,7 +111,7 @@ describe('Ticket', () => { describe('shipped() setter', () => { it('should set shipped property and call getLanded() method ', () => { jest.spyOn(controller, 'getLanded'); - const shipped = new Date(); + const shipped = Date.vnNew(); const expectedResult = { shipped: shipped, addressFk: 121, @@ -126,7 +126,7 @@ describe('Ticket', () => { describe('landed() getter', () => { it('should return the landed property', () => { - const landed = new Date(); + const landed = Date.vnNew(); controller.ticket.landed = landed; expect(controller.landed).toEqual(landed); @@ -136,7 +136,7 @@ describe('Ticket', () => { describe('landed() setter', () => { it('should set shipped property and call getShipped() method ', () => { jest.spyOn(controller, 'getShipped'); - const landed = new Date(); + const landed = Date.vnNew(); const expectedResult = { landed: landed, addressFk: 121, @@ -161,7 +161,7 @@ describe('Ticket', () => { it('should set agencyModeId property and call getLanded() method', () => { jest.spyOn(controller, 'getLanded'); controller.$.agencyMode = {selection: {warehouseFk: 1}}; - const shipped = new Date(); + const shipped = Date.vnNew(); const agencyModeId = 8; const expectedResult = { shipped: shipped, @@ -177,7 +177,7 @@ describe('Ticket', () => { it('should do nothing if attempting to set the same agencyMode id', () => { jest.spyOn(controller, 'getShipped'); - const landed = new Date(); + const landed = Date.vnNew(); const agencyModeId = 7; const expectedResult = { landed: landed, @@ -278,8 +278,8 @@ describe('Ticket', () => { agencyModeFk: 1, companyFk: 442, warehouseFk: 1, - shipped: new Date(), - landed: new Date() + shipped: Date.vnNew(), + landed: Date.vnNew() }; expect(controller.isFormInvalid()).toBeFalsy(); @@ -288,7 +288,7 @@ describe('Ticket', () => { describe('onStepChange()', () => { it('should call onStepChange method and return a NO_AGENCY_AVAILABLE signal error', async() => { - let landed = new Date(); + let landed = Date.vnNew(); landed.setHours(0, 0, 0, 0); controller._ticket = { @@ -299,7 +299,7 @@ describe('Ticket', () => { agencyModeFk: 1, companyFk: 442, warehouseFk: 1, - shipped: new Date(), + shipped: Date.vnNew(), landed: landed }; @@ -314,8 +314,8 @@ describe('Ticket', () => { describe('getLanded()', () => { it('should return an available landed date', async() => { - const shipped = new Date(); - const expectedResult = {landed: new Date()}; + const shipped = Date.vnNew(); + const expectedResult = {landed: Date.vnNew()}; const params = { shipped: shipped, addressFk: 121, @@ -336,8 +336,8 @@ describe('Ticket', () => { describe('getShipped()', () => { it('should return an available shipped date', async() => { - const landed = new Date(); - const expectedResult = {shipped: new Date()}; + const landed = Date.vnNew(); + const expectedResult = {shipped: Date.vnNew()}; const params = { landed: landed, addressFk: 121, @@ -358,7 +358,7 @@ describe('Ticket', () => { describe('zoneWhere() getter', () => { it('should return an object containing filter properties', async() => { - const shipped = new Date(); + const shipped = Date.vnNew(); controller.ticket.shipped = shipped; const expectedResult = { diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 6be455fc9..ad0c49dbb 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -40,7 +40,7 @@ - {{::sale.movable}} @@ -64,14 +64,14 @@
-
Total
+
Total
Price {{$ctrl.totalPrice | currency: 'EUR': 2}}
New price {{$ctrl.totalNewPrice | currency: 'EUR': 2}}
Difference {{$ctrl.totalPriceDifference | currency: 'EUR': 2}}
-
Charge difference to
+
Charge difference to
- @@ -95,4 +95,10 @@ warehouse-fk="$ctrl.ticket.warehouseFk" ticket-fk="$ctrl.ticket.id"> + + diff --git a/modules/ticket/front/basic-data/step-two/index.js b/modules/ticket/front/basic-data/step-two/index.js index 4ac9f292e..74e2df074 100644 --- a/modules/ticket/front/basic-data/step-two/index.js +++ b/modules/ticket/front/basic-data/step-two/index.js @@ -83,6 +83,17 @@ class Controller extends Component { } onSubmit() { + if (this.haveNegatives && !this.ticket.withoutNegatives) + this.$.negativesConfirm.show(); + else this.applyChanges(); + } + + onConfirmAccept() { + this.ticket.withWarningAccept = true; + this.applyChanges(); + } + + applyChanges() { if (!this.ticket.option) { return this.vnApp.showError( this.$t('Choose an option') @@ -102,7 +113,8 @@ class Controller extends Component { landed: this.ticket.landed, isDeleted: this.ticket.isDeleted, option: parseInt(this.ticket.option), - isWithoutNegatives: this.ticket.withoutNegatives + isWithoutNegatives: this.ticket.withoutNegatives, + withWarningAccept: this.ticket.withWarningAccept }; this.$http.post(query, params) diff --git a/modules/ticket/front/basic-data/step-two/locale/es.yml b/modules/ticket/front/basic-data/step-two/locale/es.yml index e1f1e0bfc..71f893e1e 100644 --- a/modules/ticket/front/basic-data/step-two/locale/es.yml +++ b/modules/ticket/front/basic-data/step-two/locale/es.yml @@ -8,4 +8,6 @@ New price: Nuevo precio Price difference: Diferencia de precio Create without negatives: Crear sin negativos Clone this ticket with the changes and only sales availables: Clona este ticket con los cambios y solo las ventas disponibles. -Movable: Movible \ No newline at end of file +Movable: Movible +Negatives are going to be generated, are you sure you want to advance all the lines?: Se van a generar negativos, ¿seguro que quieres adelantar todas las líneas? +Edit basic data: Editar datos básicos diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index f6001c6b8..ff029db78 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -177,7 +177,7 @@ class Controller extends Section { get canRestoreTicket() { const isDeleted = this.ticket.isDeleted; - const now = new Date(); + const now = Date.vnNew(); const maxDate = new Date(this.ticket.updated); maxDate.setHours(maxDate.getHours() + 1); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 67dc0affa..babc22038 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -43,7 +43,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { describe('canRestoreTicket() getter', () => { it('should return true for a ticket deleted within the last hour', () => { controller.ticket.isDeleted = true; - controller.ticket.updated = new Date(); + controller.ticket.updated = Date.vnNew(); const result = controller.canRestoreTicket; @@ -51,7 +51,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { }); it('should return false for a ticket deleted more than one hour ago', () => { - const pastHour = new Date(); + const pastHour = Date.vnNew(); pastHour.setHours(pastHour.getHours() - 2); controller.ticket.isDeleted = true; diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 7ffe2fe5e..2d4432fe8 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -4,7 +4,7 @@ import Section from 'salix/components/section'; class Controller extends Section { constructor($element, $scope) { super($element, $scope); - this.landed = new Date(); + this.landed = Date.vnNew(); this.newRoute = null; } diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 5a538b1c8..71e32151c 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -76,7 +76,7 @@ describe('Ticket', () => { it('should make a query and then call to the $state go() method', () => { jest.spyOn(controller.$state, 'go').mockReturnThis(); - const landed = new Date(); + const landed = Date.vnNew(); const ticket = { clientFk: 1101, landed: landed, diff --git a/modules/ticket/front/future/index.js b/modules/ticket/front/future/index.js index 5fb2c8f82..b588f1e49 100644 --- a/modules/ticket/front/future/index.js +++ b/modules/ticket/front/future/index.js @@ -57,18 +57,21 @@ export default class Controller extends Section { } setDefaultFilter() { - const today = new Date(); + const today = Date.vnNew(); - this.filterParams = { - originDated: today, - futureDated: today, - warehouseFk: this.vnConfig.warehouseFk - }; - this.$.model.applyFilter(null, this.filterParams); + this.$http.get(`UserConfigs/getUserConfig`) + .then(res => { + this.filterParams = { + originDated: today, + futureDated: today, + warehouseFk: res.data.warehouseFk + }; + this.$.model.applyFilter(null, this.filterParams); + }); } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); diff --git a/modules/ticket/front/future/index.spec.js b/modules/ticket/front/future/index.spec.js index c609a4891..188421298 100644 --- a/modules/ticket/front/future/index.spec.js +++ b/modules/ticket/front/future/index.spec.js @@ -2,7 +2,7 @@ import './index.js'; import crudModel from 'core/mocks/crud-model'; describe('Component vnTicketFuture', () => { - const today = new Date(); + const today = Date.vnNew(); let controller; let $httpBackend; @@ -32,7 +32,7 @@ describe('Component vnTicketFuture', () => { }); it('should return sucess when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.compareDate(futureDate); @@ -40,7 +40,7 @@ describe('Component vnTicketFuture', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 3039a2a03..42332ccc8 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -90,7 +90,7 @@ export default class Controller extends Section { } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let timeTicket = new Date(date); timeTicket.setHours(0, 0, 0, 0); diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 03071654e..5046387b0 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -31,14 +31,14 @@ describe('Component vnTicketIndex', () => { describe('compareDate()', () => { it('should return warning when the date is the present', () => { - let today = new Date(); + let today = Date.vnNew(); let result = controller.compareDate(today); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { - let futureDate = new Date(); + let futureDate = Date.vnNew(); futureDate = futureDate.setDate(futureDate.getDate() + 10); let result = controller.compareDate(futureDate); @@ -46,7 +46,7 @@ describe('Component vnTicketIndex', () => { }); it('should return undefined when the date is in the past', () => { - let pastDate = new Date(); + let pastDate = Date.vnNew(); pastDate = pastDate.setDate(pastDate.getDate() - 10); let result = controller.compareDate(pastDate); diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index 1b807216b..3f9482fc4 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -22,7 +22,7 @@ export default class Ticket extends ModuleMain { $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { - const from = new Date(); + const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); diff --git a/modules/ticket/front/package/index.js b/modules/ticket/front/package/index.js index ed13f12d8..fd67ce583 100644 --- a/modules/ticket/front/package/index.js +++ b/modules/ticket/front/package/index.js @@ -6,7 +6,7 @@ class Controller extends Section { this.$.model.insert({ packagingFk: null, quantity: null, - created: new Date(), + created: Date.vnNew(), ticketFk: this.$params.id }); } diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index c21eaa46a..8d3f414c2 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -17,6 +17,7 @@ Item Description Quantity + Parking @@ -50,6 +51,7 @@ {{::sale.quantity}} + {{::sale.saleGroupDetail.saleGroup.parking.code | dashIfEmpty}} = new Date() || hasClaimManagerRole; + return landedPlusWeek >= Date.vnNew() || hasClaimManagerRole; } return false; } diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index fbee966fd..8585503cc 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -15,9 +15,9 @@ describe('Ticket', () => { const ticket = { id: 1, clientFk: 1101, - shipped: new Date(), - landed: new Date(), - created: new Date(), + shipped: Date.vnNew(), + landed: Date.vnNew(), + created: Date.vnNew(), client: {salesPersonFk: 1}, address: {mobile: 111111111} }; diff --git a/modules/ticket/front/search-panel/index.spec.js b/modules/ticket/front/search-panel/index.spec.js index 41c32c047..df320b55b 100644 --- a/modules/ticket/front/search-panel/index.spec.js +++ b/modules/ticket/front/search-panel/index.spec.js @@ -38,7 +38,7 @@ describe('Ticket Component vnTicketSearchPanel', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; - controller.from = new Date(); + controller.from = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.from).toBeDefined(); @@ -49,7 +49,7 @@ describe('Ticket Component vnTicketSearchPanel', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; - controller.to = new Date(); + controller.to = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.to).toBeDefined(); @@ -58,8 +58,8 @@ describe('Ticket Component vnTicketSearchPanel', () => { describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { - controller.filter.from = new Date(); - controller.filter.to = new Date(); + controller.filter.from = Date.vnNew(); + controller.filter.to = Date.vnNew(); controller.scopeDays = 1; diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index af44ed67c..a7441dcf1 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -105,7 +105,10 @@

Subtotal {{$ctrl.summary.totalWithoutVat | currency: 'EUR':2}}

-

VAT {{$ctrl.summary.totalWithVat - $ctrl.summary.totalWithoutVat | currency: 'EUR':2}}

+

VAT + RE + VAT + {{$ctrl.summary.totalWithVat - $ctrl.summary.totalWithoutVat | currency: 'EUR':2}} +

Total {{$ctrl.summary.totalWithVat | currency: 'EUR':2}}

diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index 3c739d5f9..ca3b6e662 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -17,87 +17,110 @@ model="model"> - - - - - - Ticket ID - Client - Shipment - Agency - Warehouse - Salesperson - - - - - - - - {{weekly.ticketFk}} - - - - - {{::weekly.clientName}} - - - - - - - - - - - {{::weekly.warehouseName}} - - - {{::weekly.userName}} - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Ticket ID + + Client + + Shipment + + Agency + + Warehouse + + Salesperson +
+ + {{weekly.ticketFk}} + + + + {{::weekly.clientName}} + + + + + + + + {{weekly.warehouseName}} + + {{::weekly.userName}} + + + + +
+
+
+
@@ -112,4 +135,4 @@ on-accept="$ctrl.onDeleteWeeklyAccept($data)" question="This ticket will be removed from weekly tickets! Continue anyway?" message="You are going to delete this weekly ticket"> - + \ No newline at end of file diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index 71365c4b3..a10ff7184 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -1,3 +1,4 @@ + import ngModule from '../module'; import Section from 'salix/components/section'; @@ -15,6 +16,44 @@ export default class Controller extends Section { {id: 5, name: 'Saturday'}, {id: 6, name: 'Sunday'} ]; + + this.smartTableOptions = { + activeButtons: { + search: true, + shownColumns: true, + }, + columns: [ + { + field: 'ticketFk', + searchable: false + }, + { + field: 'clientName', + }, + { + field: 'weekDay', + searchable: false, + }, + { + field: 'agencyModeFk', + searchable: false, + }, + { + field: 'warehouseFk', + searchable: false, + }, + { + field: 'nickname', + }, + ] + }; + } + + exprBuilder(param, value) { + switch (param) { + case 'clientName': return {'c.name': value}; + case 'nickName': return {'u.name': value}; + } } onUpdate(ticketFk, field, value) { diff --git a/modules/travel/back/methods/thermograph/createThermograph.js b/modules/travel/back/methods/thermograph/createThermograph.js index 23d9d6037..75d967628 100644 --- a/modules/travel/back/methods/thermograph/createThermograph.js +++ b/modules/travel/back/methods/thermograph/createThermograph.js @@ -40,7 +40,7 @@ module.exports = Self => { const models = Self.app.models; let tx; const myOptions = {}; - const date = new Date(); + const date = Date.vnNew(); if (typeof options == 'object') Object.assign(myOptions, options); diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index 611f4e429..e5b6b1580 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -39,8 +39,8 @@ module.exports = Self => { 'ref' ] }); - const started = new Date(); - const ended = new Date(); + const started = Date.vnNew(); + const ended = Date.vnNew(); if (!travel) throw new UserError('Travel not found'); diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 2e79ff193..0e434e048 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -49,7 +49,7 @@ describe('Travel cloneWithEntries()', () => { pending('#2687 - Cannot make a data rollback because of the triggers'); const warehouseThree = 3; const agencyModeOne = 1; - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); travelBefore = await models.Travel.findById(travelId); diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 3693aae82..599851b55 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -95,10 +95,10 @@ describe('Travel extraCommunityFilter()', () => { }); it('should return the routes matching "shipped from" and "landed to"', async() => { - const from = new Date(); + const from = Date.vnNew(); from.setDate(from.getDate() - 2); from.setHours(0, 0, 0, 0); - const to = new Date(); + const to = Date.vnNew(); to.setHours(23, 59, 59, 999); to.setDate(to.getDate() + 7); const ctx = { diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index c739866a0..1a6ee895c 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -54,8 +54,8 @@ describe('Travel filter()', () => { }); it('should return the routes matching "shipped from" and "shipped to"', async() => { - const from = new Date(); - const to = new Date(); + const from = Date.vnNew(); + const to = Date.vnNew(); from.setHours(0, 0, 0, 0); to.setHours(23, 59, 59, 999); to.setDate(to.getDate() + 1); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index e3f85d9ae..cdff8cfb9 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -53,7 +53,7 @@ describe('Travel Component vnTravelCreate', () => { it(`should do nothing if there's no response data.`, () => { controller.travel = {agencyModeFk: 4}; - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; $httpBackend.expectGET(query).respond(undefined); @@ -67,7 +67,7 @@ describe('Travel Component vnTravelCreate', () => { it(`should fill the fields when it's selected a date and agency.`, () => { controller.travel = {agencyModeFk: 1}; - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 9); const expectedResponse = { id: 8, diff --git a/modules/travel/front/extra-community/index.js b/modules/travel/front/extra-community/index.js index 2389570b9..920339469 100644 --- a/modules/travel/front/extra-community/index.js +++ b/modules/travel/front/extra-community/index.js @@ -25,12 +25,12 @@ class Controller extends Section { this.droppableElement = 'tbody[vn-droppable]'; const twoDays = 2; - const shippedFrom = new Date(); + const shippedFrom = Date.vnNew(); shippedFrom.setDate(shippedFrom.getDate() - twoDays); shippedFrom.setHours(0, 0, 0, 0); const sevenDays = 7; - const landedTo = new Date(); + const landedTo = Date.vnNew(); landedTo.setDate(landedTo.getDate() + sevenDays); landedTo.setHours(23, 59, 59, 59); diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 50036831f..7701289b7 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -20,7 +20,7 @@ export default class Controller extends Section { } compareDate(date) { - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); date = new Date(date); diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index 9abe46a64..9083c4519 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -50,7 +50,7 @@ describe('Travel Component vnTravelIndex', () => { describe('compareDate()', () => { it('should return warning if the date passed to compareDate() is todays', () => { - const today = new Date(); + const today = Date.vnNew(); const result = controller.compareDate(today); @@ -58,7 +58,7 @@ describe('Travel Component vnTravelIndex', () => { }); it('should return success if the date passed to compareDate() is in the future', () => { - const tomorrow = new Date(); + const tomorrow = Date.vnNew(); tomorrow.setDate(tomorrow.getDate() + 1); const result = controller.compareDate(tomorrow); @@ -67,7 +67,7 @@ describe('Travel Component vnTravelIndex', () => { }); it('should return undefined if the date passed to compareDate() is in the past', () => { - const yesterday = new Date(); + const yesterday = Date.vnNew(); yesterday.setDate(yesterday.getDate() - 1); const result = controller.compareDate(yesterday); diff --git a/modules/travel/front/main/index.js b/modules/travel/front/main/index.js index d6f103033..fbaf78c16 100644 --- a/modules/travel/front/main/index.js +++ b/modules/travel/front/main/index.js @@ -15,7 +15,7 @@ export default class Travel extends ModuleMain { $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { - const shippedFrom = new Date(); + const shippedFrom = Date.vnNew(); shippedFrom.setHours(0, 0, 0, 0); const shippedTo = new Date(shippedFrom.getTime()); diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js index 6d9db4dc8..bf5a27b41 100644 --- a/modules/travel/front/main/index.spec.js +++ b/modules/travel/front/main/index.spec.js @@ -15,7 +15,7 @@ describe('Travel Component vnTravel', () => { let params = controller.fetchParams({ scopeDays: 2 }); - const shippedFrom = new Date(); + const shippedFrom = Date.vnNew(); shippedFrom.setHours(0, 0, 0, 0); const shippedTo = new Date(shippedFrom.getTime()); shippedTo.setDate(shippedTo.getDate() + params.scopeDays); diff --git a/modules/travel/front/search-panel/index.spec.js b/modules/travel/front/search-panel/index.spec.js index a1f3c36b3..884f4fb17 100644 --- a/modules/travel/front/search-panel/index.spec.js +++ b/modules/travel/front/search-panel/index.spec.js @@ -15,7 +15,7 @@ describe('Travel Component vnTravelSearchPanel', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; - controller.shippedFrom = new Date(); + controller.shippedFrom = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.shippedFrom).toBeDefined(); @@ -26,7 +26,7 @@ describe('Travel Component vnTravelSearchPanel', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; - controller.shippedTo = new Date(); + controller.shippedTo = Date.vnNew(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.shippedTo).toBeDefined(); @@ -35,8 +35,8 @@ describe('Travel Component vnTravelSearchPanel', () => { describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { - controller.filter.shippedFrom = new Date(); - controller.filter.shippedTo = new Date(); + controller.filter.shippedFrom = Date.vnNew(); + controller.filter.shippedTo = Date.vnNew(); controller.scopeDays = 1; diff --git a/modules/worker/back/methods/calendar/absences.js b/modules/worker/back/methods/calendar/absences.js index ddf38a604..8420ed770 100644 --- a/modules/worker/back/methods/calendar/absences.js +++ b/modules/worker/back/methods/calendar/absences.js @@ -35,12 +35,12 @@ module.exports = Self => { Self.absences = async(ctx, workerFk, businessFk, year, options) => { const models = Self.app.models; - const started = new Date(); + const started = Date.vnNew(); started.setFullYear(year); started.setMonth(0); started.setDate(1); - const ended = new Date(); + const ended = Date.vnNew(); ended.setFullYear(year); ended.setMonth(12); ended.setDate(0); diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 2180a5312..365773182 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -6,7 +6,7 @@ describe('Worker absences()', () => { const workerId = 1106; const businessId = 1106; - const now = new Date(); + const now = Date.vnNew(); const year = now.getFullYear(); const [absences] = await app.models.Calendar.absences(ctx, workerId, businessId, year); @@ -22,7 +22,7 @@ describe('Worker absences()', () => { const businessId = 1106; const ctx = {req: {accessToken: {userId: 9}}}; - const now = new Date(); + const now = Date.vnNew(); const year = now.getFullYear(); const tx = await app.models.Calendar.beginTransaction({}); @@ -55,15 +55,15 @@ describe('Worker absences()', () => { const workerId = 1106; const userId = 1106; - const today = new Date(); + const today = Date.vnNew(); // getting how many days in a year - const yearStart = new Date(); + const yearStart = Date.vnNew(); yearStart.setHours(0, 0, 0, 0); yearStart.setMonth(0); yearStart.setDate(1); - const yearEnd = new Date(); + const yearEnd = Date.vnNew(); const currentYear = yearEnd.getFullYear(); yearEnd.setFullYear(currentYear + 1); yearEnd.setHours(0, 0, 0, 0); @@ -92,7 +92,7 @@ describe('Worker absences()', () => { // normal test begins const contract = await app.models.WorkerLabour.findById(businessId, null, options); - const startingContract = new Date(); + const startingContract = Date.vnNew(); startingContract.setHours(0, 0, 0, 0); startingContract.setMonth(today.getMonth()); startingContract.setDate(1); diff --git a/modules/worker/back/methods/holiday/getByWarehouse.js b/modules/worker/back/methods/holiday/getByWarehouse.js index 093885d13..50029e62b 100644 --- a/modules/worker/back/methods/holiday/getByWarehouse.js +++ b/modules/worker/back/methods/holiday/getByWarehouse.js @@ -17,7 +17,7 @@ module.exports = Self => { }); Self.getByWarehouse = async warehouseFk => { - let beginningYear = new Date(); + let beginningYear = Date.vnNew(); beginningYear.setMonth(0); beginningYear.setDate(1); beginningYear.setHours(0, 0, 0, 0); diff --git a/modules/worker/back/methods/worker-time-control-mail/checkInbox.js b/modules/worker/back/methods/worker-time-control-mail/checkInbox.js index 7825f38b8..4d9f98cc3 100644 --- a/modules/worker/back/methods/worker-time-control-mail/checkInbox.js +++ b/modules/worker/back/methods/worker-time-control-mail/checkInbox.js @@ -93,7 +93,7 @@ module.exports = Self => { }; async function emailConfirm(buffer) { - const now = new Date(); + const now = Date.vnNew(); const from = JSON.stringify(Imap.parseHeader(buffer).from); const subject = JSON.stringify(Imap.parseHeader(buffer).subject); @@ -121,7 +121,7 @@ module.exports = Self => { } async function emailReply(buffer, emailBody) { - const now = new Date(); + const now = Date.vnNew(); const from = JSON.stringify(Imap.parseHeader(buffer).from); const subject = JSON.stringify(Imap.parseHeader(buffer).subject); diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 78c212e9b..579a83112 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -42,8 +42,8 @@ module.exports = Self => { let stmt; if (!args.week || !args.year) { - const from = new Date(); - const to = new Date(); + const from = Date.vnNew(); + const to = Date.vnNew(); const time = await models.Time.findOne({ where: { @@ -79,7 +79,7 @@ module.exports = Self => { week: args.week }; await models.WorkerTimeControlMail.updateAll(where, { - updated: new Date(), state: 'SENDED' + updated: Date.vnNew(), state: 'SENDED' }, myOptions); stmt = new ParameterizedSQL( @@ -102,7 +102,7 @@ module.exports = Self => { week: args.week }; await models.WorkerTimeControlMail.updateAll(where, { - updated: new Date(), state: 'SENDED' + updated: Date.vnNew(), state: 'SENDED' }, myOptions); stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]); @@ -223,11 +223,11 @@ module.exports = Self => { let timeTableDecimalInSeconds = 0; for (let journey of journeys) { - const start = new Date(); + const start = Date.vnNew(); const [startHours, startMinutes, startSeconds] = getTime(journey.start); start.setHours(startHours, startMinutes, startSeconds, 0); - const end = new Date(); + const end = Date.vnNew(); const [endHours, endMinutes, endSeconds] = getTime(journey.end); end.setHours(endHours, endMinutes, endSeconds, 0); diff --git a/modules/worker/back/methods/worker-time-control/specs/filter.spec.js b/modules/worker/back/methods/worker-time-control/specs/filter.spec.js index 927d83df3..0c4d229f2 100644 --- a/modules/worker/back/methods/worker-time-control/specs/filter.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/filter.spec.js @@ -3,9 +3,9 @@ const models = require('vn-loopback/server/server').models; describe('workerTimeControl filter()', () => { it('should return 1 result filtering by id', async() => { const ctx = {req: {accessToken: {userId: 1106}}, args: {workerFk: 1106}}; - const firstHour = new Date(); + const firstHour = Date.vnNew(); firstHour.setHours(7, 0, 0, 0); - const lastHour = new Date(); + const lastHour = Date.vnNew(); lastHour.setDate(lastHour.getDate() + 1); lastHour.setHours(15, 0, 0, 0); @@ -21,9 +21,9 @@ describe('workerTimeControl filter()', () => { it('should return a privilege error for a non subordinate worker', async() => { const ctx = {req: {accessToken: {userId: 1107}}, args: {workerFk: 1106}}; - const firstHour = new Date(); + const firstHour = Date.vnNew(); firstHour.setHours(7, 0, 0, 0); - const lastHour = new Date(); + const lastHour = Date.vnNew(); lastHour.setDate(lastHour.getDate() + 1); lastHour.setHours(15, 0, 0, 0); diff --git a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js index e9924c67b..e90c849b7 100644 --- a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js @@ -35,7 +35,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { let error; try { - ctx.args = {timed: new Date(), direction: 'in'}; + ctx.args = {timed: Date.vnNew(), direction: 'in'}; await models.WorkerTimeControl.addTimeEntry(ctx, workerId); } catch (e) { error = e; @@ -52,7 +52,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { let error; try { - ctx.args = {timed: new Date(), direction: 'in'}; + ctx.args = {timed: Date.vnNew(), direction: 'in'}; await models.WorkerTimeControl.addTimeEntry(ctx, workerId); } catch (e) { error = e; @@ -71,7 +71,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { try { const options = {transaction: tx}; - const todayAtOne = new Date(); + const todayAtOne = Date.vnNew(); todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; @@ -95,7 +95,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { try { const options = {transaction: tx}; - const todayAtOne = new Date(); + const todayAtOne = Date.vnNew(); todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; @@ -123,7 +123,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { try { const options = {transaction: tx}; - const todayAtOne = new Date(); + const todayAtOne = Date.vnNew(); todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; @@ -151,7 +151,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { try { const options = {transaction: tx}; - const todayAtOne = new Date(); + const todayAtOne = Date.vnNew(); todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; @@ -179,7 +179,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { try { const options = {transaction: tx}; - const todayAtOne = new Date(); + const todayAtOne = Date.vnNew(); todayAtOne.setHours(1, 0, 0, 0); ctx.args = {timed: todayAtOne, direction: 'in'}; @@ -204,7 +204,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { pending('https://redmine.verdnatura.es/issues/4707'); activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - const date = new Date(); + const date = Date.vnNew(); date.setDate(date.getDate() - 16); date.setHours(8, 0, 0); let error; @@ -227,7 +227,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { it('should fail to add a time entry for a worker without an existing contract', async() => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - const date = new Date(); + const date = Date.vnNew(); date.setFullYear(date.getFullYear() - 2); let error; @@ -252,7 +252,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -282,7 +282,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -316,7 +316,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -350,7 +350,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -384,7 +384,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -421,7 +421,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -456,7 +456,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -493,7 +493,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = jessicaJonesId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -528,7 +528,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = jessicaJonesId; - let date = new Date(); + let date = Date.vnNew(); date.setDate(date.getDate() - 21); date = weekDay(date, monday); let error; @@ -565,7 +565,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setMonth(date.getMonth() - 2); date.setDate(1); let error; @@ -600,7 +600,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setMonth(date.getMonth() - 2); date.setDate(1); let error; @@ -634,7 +634,7 @@ describe('workerTimeControl add/delete timeEntry()', () => { activeCtx.accessToken.userId = salesBossId; const workerId = hankPymId; - let date = new Date(); + let date = Date.vnNew(); date.setMonth(date.getMonth() - 2); date.setDate(1); let error; diff --git a/modules/worker/back/methods/worker/activeContract.js b/modules/worker/back/methods/worker/activeContract.js index 05dcee6b5..d3d439cd0 100644 --- a/modules/worker/back/methods/worker/activeContract.js +++ b/modules/worker/back/methods/worker/activeContract.js @@ -27,7 +27,7 @@ module.exports = Self => { if (!isSubordinate) throw new UserError(`You don't have enough privileges`); - const now = new Date(); + const now = Date.vnNew(); return models.WorkerLabour.findOne({ where: { diff --git a/modules/worker/back/methods/worker/createAbsence.js b/modules/worker/back/methods/worker/createAbsence.js index 1467d6d6b..43a9f4d23 100644 --- a/modules/worker/back/methods/worker/createAbsence.js +++ b/modules/worker/back/methods/worker/createAbsence.js @@ -80,8 +80,8 @@ module.exports = Self => { if (hasHoursRecorded && isNotHalfAbsence) throw new UserError(`The worker has hours recorded that day`); - const date = new Date(); - const now = new Date(); + const date = Date.vnNew(); + const now = Date.vnNew(); date.setHours(0, 0, 0, 0); const [result] = await Self.rawSql( `SELECT COUNT(*) halfHolidayCounter diff --git a/modules/worker/back/methods/worker/holidays.js b/modules/worker/back/methods/worker/holidays.js index 7f093a330..9c214e0f7 100644 --- a/modules/worker/back/methods/worker/holidays.js +++ b/modules/worker/back/methods/worker/holidays.js @@ -45,13 +45,13 @@ module.exports = Self => { if (!isSubordinate) throw new UserError(`You don't have enough privileges`); - const started = new Date(); + const started = Date.vnNew(); started.setFullYear(args.year); started.setMonth(0); started.setDate(1); started.setHours(0, 0, 0, 0); - const ended = new Date(); + const ended = Date.vnNew(); ended.setFullYear(args.year); ended.setMonth(12); ended.setDate(0); diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index 7214e815e..346e43c51 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -10,7 +10,7 @@ describe('Worker createAbsence()', () => { args: { businessFk: 18, absenceTypeId: 1, - dated: new Date() + dated: Date.vnNew() } }; @@ -45,7 +45,7 @@ describe('Worker createAbsence()', () => { args: { businessFk: 18, absenceTypeId: 1, - dated: new Date() + dated: Date.vnNew() } }; ctx.req.__ = value => { @@ -82,7 +82,7 @@ describe('Worker createAbsence()', () => { id: 1, businessFk: 1, absenceTypeId: 6, - dated: new Date() + dated: Date.vnNew() } }; const workerId = 1; @@ -111,7 +111,7 @@ describe('Worker createAbsence()', () => { id: 1106, businessFk: 1106, absenceTypeId: 1, - dated: new Date() + dated: Date.vnNew() } }; const workerId = 1106; diff --git a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js index a105669cf..0f3f913dc 100644 --- a/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/deleteAbsence.spec.js @@ -28,7 +28,7 @@ describe('Worker deleteAbsence()', () => { const createdAbsence = await app.models.Calendar.create({ businessFk: businessId, dayOffTypeFk: 1, - dated: new Date() + dated: Date.vnNew() }, options); ctx.args = {absenceId: createdAbsence.id}; @@ -59,7 +59,7 @@ describe('Worker deleteAbsence()', () => { const createdAbsence = await app.models.Calendar.create({ businessFk: businessId, dayOffTypeFk: 1, - dated: new Date() + dated: Date.vnNew() }, options); ctx.args = {absenceId: createdAbsence.id}; diff --git a/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js index 054a829e5..f5b06cc9e 100644 --- a/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js +++ b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js @@ -3,10 +3,10 @@ const models = require('vn-loopback/server/server').models; describe('Worker getWorkedHours()', () => { it(`should return the expected hours and the worked hours of a given date`, async() => { const workerID = 1106; - const started = new Date(); + const started = Date.vnNew(); started.setHours(0, 0, 0, 0); - const ended = new Date(); + const ended = Date.vnNew(); ended.setHours(23, 59, 59, 999); const [result] = await models.Worker.getWorkedHours(workerID, started, ended); diff --git a/modules/worker/back/methods/worker/specs/holidays.spec.js b/modules/worker/back/methods/worker/specs/holidays.spec.js index d8310b738..f23b247ca 100644 --- a/modules/worker/back/methods/worker/specs/holidays.spec.js +++ b/modules/worker/back/methods/worker/specs/holidays.spec.js @@ -17,7 +17,7 @@ describe('Worker holidays()', () => { }); it('should now get the absence calendar for a full year contract', async() => { - const now = new Date(); + const now = Date.vnNew(); const year = now.getFullYear(); ctx.args = {businessFk: businessId, year: year}; @@ -29,7 +29,7 @@ describe('Worker holidays()', () => { }); it('should now get the payed holidays calendar for a worker', async() => { - const now = new Date(); + const now = Date.vnNew(); const year = now.getFullYear(); ctx.args = {businessFk: businessId, year: year}; diff --git a/modules/worker/back/methods/worker/specs/updateAbsence.spec.js b/modules/worker/back/methods/worker/specs/updateAbsence.spec.js index 6339b3163..a624fc1d3 100644 --- a/modules/worker/back/methods/worker/specs/updateAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/updateAbsence.spec.js @@ -21,7 +21,7 @@ describe('Worker updateAbsence()', () => { createdAbsence = await app.models.Calendar.create({ businessFk: businessId, dayOffTypeFk: 1, - dated: new Date() + dated: Date.vnNew() }); }); diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 95e1fc134..4ca0fc929 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -5,7 +5,7 @@ import './style.scss'; class Controller extends Section { constructor($element, $) { super($element, $); - this.date = new Date(); + this.date = Date.vnNew(); this.events = {}; this.buildYearFilter(); } @@ -15,7 +15,7 @@ class Controller extends Section { } set year(value) { - const newYear = new Date(); + const newYear = Date.vnNew(); newYear.setFullYear(value); this.date = newYear; @@ -76,7 +76,7 @@ class Controller extends Section { } buildYearFilter() { - const now = new Date(); + const now = Date.vnNew(); now.setFullYear(now.getFullYear() + 1); const maxYear = now.getFullYear(); diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 1da4066d9..586a7223d 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -6,7 +6,7 @@ describe('Worker', () => { let $httpParamSerializer; let $scope; let controller; - let year = new Date().getFullYear(); + let year = Date.vnNew().getFullYear(); beforeEach(ngModule('worker')); @@ -67,7 +67,7 @@ describe('Worker', () => { controller.getIsSubordinate = jest.fn(); controller.getActiveContract = jest.fn(); - let today = new Date(); + let today = Date.vnNew(); let tomorrow = new Date(today.getTime()); tomorrow.setDate(tomorrow.getDate() + 1); @@ -105,7 +105,7 @@ describe('Worker', () => { describe('getContractHolidays()', () => { it(`should return the worker holidays amount and then set the contractHolidays property`, () => { - const today = new Date(); + const today = Date.vnNew(); const year = today.getFullYear(); const serializedParams = $httpParamSerializer({year}); @@ -119,7 +119,7 @@ describe('Worker', () => { describe('formatDay()', () => { it(`should set the day element style`, () => { - const today = new Date(); + const today = Date.vnNew(); controller.events[today.getTime()] = { name: 'Holiday', @@ -170,7 +170,7 @@ describe('Worker', () => { it(`should call to the create() method`, () => { jest.spyOn(controller, 'create').mockReturnThis(); - const selectedDay = new Date(); + const selectedDay = Date.vnNew(); const $event = { target: { closest: () => { @@ -188,7 +188,7 @@ describe('Worker', () => { it(`should call to the delete() method`, () => { jest.spyOn(controller, 'delete').mockReturnThis(); - const selectedDay = new Date(); + const selectedDay = Date.vnNew(); const expectedEvent = { dated: selectedDay, type: 'holiday', @@ -212,7 +212,7 @@ describe('Worker', () => { it(`should call to the edit() method`, () => { jest.spyOn(controller, 'edit').mockReturnThis(); - const selectedDay = new Date(); + const selectedDay = Date.vnNew(); const expectedEvent = { dated: selectedDay, type: 'leaveOfAbsence', @@ -238,7 +238,7 @@ describe('Worker', () => { it(`should make a HTTP POST query and then call to the repaintCanceller() method`, () => { jest.spyOn(controller, 'repaintCanceller').mockReturnThis(); - const dated = new Date(); + const dated = Date.vnNew(); const calendarElement = {}; const expectedResponse = {id: 10}; @@ -287,7 +287,7 @@ describe('Worker', () => { const expectedParams = {absenceId: 10}; const calendarElement = {}; - const selectedDay = new Date(); + const selectedDay = Date.vnNew(); const expectedEvent = { dated: selectedDay, type: 'leaveOfAbsence', diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 2ff032def..ef2f64e85 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -82,7 +82,7 @@ class Controller extends Descriptor { } onUploadResponse() { - const timestamp = new Date().getTime(); + const timestamp = Date.vnNew().getTime(); const src = this.$rootScope.imagePath('user', '520x520', this.worker.id); const zoomSrc = this.$rootScope.imagePath('user', '1600x1600', this.worker.id); const newSrc = `${src}&t=${timestamp}`; diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index c3d3e5eab..f7379fea0 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -16,7 +16,7 @@ class Controller extends Section { $postLink() { const timestamp = this.$params.timestamp; - let initialDate = new Date(); + let initialDate = Date.vnNew(); if (timestamp) { initialDate = new Date(timestamp * 1000); @@ -199,7 +199,7 @@ class Controller extends Section { getFinishTime() { if (!this.weekDays) return; - let today = new Date(); + let today = Date.vnNew(); today.setHours(0, 0, 0, 0); let todayInWeek = this.weekDays.find(day => day.dated.getTime() === today.getTime()); diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index 4f317a5e6..b68162d39 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -18,7 +18,7 @@ describe('Component vnWorkerTimeControl', () => { describe('date() setter', () => { it(`should set the weekDays, the date in the controller and call fetchHours`, () => { - let today = new Date(); + let today = Date.vnNew(); jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; @@ -33,7 +33,7 @@ describe('Component vnWorkerTimeControl', () => { describe('hours() setter', () => { it(`should set hours data at it's corresponding week day`, () => { - let today = new Date(); + let today = Date.vnNew(); jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; @@ -64,7 +64,7 @@ describe('Component vnWorkerTimeControl', () => { describe('getWorkedHours() ', () => { it('should set the weekdays expected and worked hours plus the total worked hours', () => { - let today = new Date(); + let today = Date.vnNew(); jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; @@ -117,7 +117,7 @@ describe('Component vnWorkerTimeControl', () => { describe('save() ', () => { it(`should make a query an then call to the fetchHours() method`, () => { controller.fetchHours = jest.fn(); - controller.selectedRow = {id: 1, timed: new Date(), direction: 'in'}; + controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'}; controller.$.editEntry = { hide: () => {} }; diff --git a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js index bc7aa1ed9..4f79b2315 100644 --- a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js +++ b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Agency getAgenciesWithWarehouse()', () => { - const today = new Date(); + const today = Date.vnNew(); it('should return the agencies that can handle the given delivery request', async() => { const tx = await app.models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/agency/specs/getLanded.spec.js b/modules/zone/back/methods/agency/specs/getLanded.spec.js index c199b2ba6..e2e6b3eb3 100644 --- a/modules/zone/back/methods/agency/specs/getLanded.spec.js +++ b/modules/zone/back/methods/agency/specs/getLanded.spec.js @@ -3,7 +3,7 @@ const models = require('vn-loopback/server/server').models; describe('agency getLanded()', () => { it('should return a landing date', async() => { const ctx = {req: {accessToken: {userId: 1}}}; - const shipped = new Date(); + const shipped = Date.vnNew(); shipped.setDate(shipped.getDate() + 1); const addressFk = 121; const agencyModeFk = 7; diff --git a/modules/zone/back/methods/agency/specs/getShipped.spec.js b/modules/zone/back/methods/agency/specs/getShipped.spec.js index f2b36fc94..43e2c1208 100644 --- a/modules/zone/back/methods/agency/specs/getShipped.spec.js +++ b/modules/zone/back/methods/agency/specs/getShipped.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); describe('agency getShipped()', () => { it('should return a shipment date', async() => { - const landed = new Date(); + const landed = Date.vnNew(); landed.setDate(landed.getDate() + 1); const addressFk = 121; const agencyModeFk = 7; @@ -25,7 +25,7 @@ describe('agency getShipped()', () => { }); it('should not return a shipment date', async() => { - const newDate = new Date(); + const newDate = Date.vnNew(); newDate.setMonth(newDate.getMonth() - 1); const landed = newDate; const addressFk = 121; diff --git a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js index 7d207b383..ea10e708f 100644 --- a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js +++ b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Agency landsThatDay()', () => { - const today = new Date(); + const today = Date.vnNew(); it('should return a list of agencies that can land a shipment on a day for an address', async() => { const tx = await app.models.Agency.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index fb228bcf4..e3846132b 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -22,7 +22,7 @@ module.exports = Self => { const models = Self.app.models; const token = ctx.req.accessToken; const userId = token.userId; - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); let tx; diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 2a0088203..76706b55c 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -31,7 +31,7 @@ module.exports = Self => { Object.assign(myOptions, options); query = ` - SELECT * + SELECT * FROM ( SELECT DISTINCT z.id, @@ -40,18 +40,21 @@ module.exports = Self => { IFNULL(ze.hour, z.hour) as hour, IFNULL(ze.price, z.price) as price FROM vn.zone z - JOIN agencyMode am ON am.id = z.agencyModeFk - LEFT JOIN zoneEvent ze ON ze.zoneFk = z.id - WHERE - ( - dated = ? - OR ? BETWEEN started AND ended - OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0 - ) + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.zoneEvent ze ON ze.zoneFk = z.id + WHERE (( + ze.type = 'day' + AND ze.dated = ? + ) OR ( + ze.type != 'day' + AND ze.weekDays & (1 << WEEKDAY(?)) + AND (ze.started IS NULL OR ? >= ze.started) + AND (ze.ended IS NULL OR ? <= ze.ended) + )) AND z.id IN (?) ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z GROUP BY z.id`; - return Self.rawSql(query, [date, date, date, zoneIds], myOptions); + return Self.rawSql(query, [date, date, date, date, zoneIds], myOptions); }; }; diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index 3a345f2ce..a34132be4 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; describe('zone exclusionGeo()', () => { const zoneId = 1; - const today = new Date(); + const today = Date.vnNew(); it(`should show an error when location isn't selected`, async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getEventsFiltered.spec.js b/modules/zone/back/methods/zone/specs/getEventsFiltered.spec.js index 8160ee05e..6fd6bb994 100644 --- a/modules/zone/back/methods/zone/specs/getEventsFiltered.spec.js +++ b/modules/zone/back/methods/zone/specs/getEventsFiltered.spec.js @@ -6,7 +6,7 @@ describe('zone getEventsFiltered()', () => { try { const options = {transaction: tx}; - const today = new Date(); + const today = Date.vnNew(); const result = await models.Zone.getEventsFiltered(10, today, today, options); @@ -26,7 +26,7 @@ describe('zone getEventsFiltered()', () => { try { const options = {transaction: tx}; - const today = new Date(); + const today = Date.vnNew(); const result = await models.Zone.getEventsFiltered(9, today, today, options); @@ -45,7 +45,7 @@ describe('zone getEventsFiltered()', () => { try { const options = {transaction: tx}; - const date = new Date(); + const date = Date.vnNew(); date.setFullYear(date.getFullYear() - 2); const dateTomorrow = new Date(date.setDate(date.getDate() + 1)); diff --git a/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js index 4fb4b4e5c..cdd6fe584 100644 --- a/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js +++ b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js @@ -6,7 +6,7 @@ describe('zone getZoneClosing()', () => { try { const options = {transaction: tx}; - const date = new Date(); + const date = Date.vnNew(); const today = date.toISOString().split('T')[0]; const result = await models.Zone.getZoneClosing([1, 2, 3], today, options); diff --git a/modules/zone/back/methods/zone/specs/includingExpired.spec.js b/modules/zone/back/methods/zone/specs/includingExpired.spec.js index 98fdc272d..121a84887 100644 --- a/modules/zone/back/methods/zone/specs/includingExpired.spec.js +++ b/modules/zone/back/methods/zone/specs/includingExpired.spec.js @@ -50,7 +50,7 @@ describe('zone includingExpired()', () => { it('should return an array containing available zones', async() => { const ctx = {req: {accessToken: {userId: 1}}}; const where = { - shipped: new Date(), + shipped: Date.vnNew(), addressFk: addressId, agencyModeFk: inhousePickupId, warehouseFk: warehouseId diff --git a/modules/zone/front/calendar/index.js b/modules/zone/front/calendar/index.js index 3bc7158ef..288a8f328 100644 --- a/modules/zone/front/calendar/index.js +++ b/modules/zone/front/calendar/index.js @@ -8,7 +8,7 @@ class Controller extends Component { this.vnWeekDays = vnWeekDays; this.nMonths = 4; - let date = new Date(); + let date = Date.vnNew(); date.setDate(1); date.setHours(0, 0, 0, 0); this.date = date; diff --git a/modules/zone/front/calendar/index.spec.js b/modules/zone/front/calendar/index.spec.js index 338f47917..43280a9e8 100644 --- a/modules/zone/front/calendar/index.spec.js +++ b/modules/zone/front/calendar/index.spec.js @@ -22,7 +22,7 @@ describe('component vnZoneCalendar', () => { it('should set the month property and then call the refreshEvents() method', () => { jest.spyOn(controller, 'refreshEvents').mockReturnThis(); - controller.date = new Date(); + controller.date = Date.vnNew(); expect(controller.refreshEvents).toHaveBeenCalledWith(); expect(controller.months.length).toEqual(4); @@ -31,7 +31,7 @@ describe('component vnZoneCalendar', () => { describe('step()', () => { it('should set the date month to 4 months backwards', () => { - const now = new Date(); + const now = Date.vnNew(); now.setDate(15); now.setMonth(now.getMonth() - 4); @@ -44,7 +44,7 @@ describe('component vnZoneCalendar', () => { }); it('should set the date month to 4 months forwards', () => { - const now = new Date(); + const now = Date.vnNew(); now.setDate(15); now.setMonth(now.getMonth() + 4); @@ -63,13 +63,13 @@ describe('component vnZoneCalendar', () => { controller.data = { exclusions: [{ - dated: new Date() + dated: Date.vnNew() }], events: [{ - dated: new Date() + dated: Date.vnNew() }], geoExclusions: [{ - dated: new Date() + dated: Date.vnNew() }], }; @@ -85,9 +85,9 @@ describe('component vnZoneCalendar', () => { describe('refreshEvents()', () => { it('should fill the days property with the events.', () => { controller.data = []; - controller.firstDay = new Date(); + controller.firstDay = Date.vnNew(); - const lastDay = new Date(); + const lastDay = Date.vnNew(); lastDay.setDate(lastDay.getDate() + 10); controller.lastDay = lastDay; @@ -114,7 +114,7 @@ describe('component vnZoneCalendar', () => { jest.spyOn(controller, 'emit'); const $event = {}; - const $days = [new Date()]; + const $days = [Date.vnNew()]; const $type = 'day'; const $weekday = 1; @@ -136,7 +136,7 @@ describe('component vnZoneCalendar', () => { describe('hasEvents()', () => { it('should return true for an existing event on a date', () => { - const dated = new Date(); + const dated = Date.vnNew(); controller.days[dated.getTime()] = true; @@ -148,7 +148,7 @@ describe('component vnZoneCalendar', () => { describe('getClass()', () => { it('should return the className "excluded" for an excluded date', () => { - const dated = new Date(); + const dated = Date.vnNew(); controller.exclusions = []; controller.exclusions[dated.getTime()] = true; @@ -159,7 +159,7 @@ describe('component vnZoneCalendar', () => { }); it('should return the className "geoExcluded" for a date with geo excluded', () => { - const dated = new Date(); + const dated = Date.vnNew(); controller.geoExclusions = []; controller.geoExclusions[dated.getTime()] = true; diff --git a/modules/zone/front/create/index.js b/modules/zone/front/create/index.js index 859204d8d..db337a9a3 100644 --- a/modules/zone/front/create/index.js +++ b/modules/zone/front/create/index.js @@ -7,7 +7,7 @@ export default class Controller extends Section { travelingDays: 0, price: 0.20, bonus: 0.20, - hour: new Date() + hour: Date.vnNew() }; } diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 63c87fbea..28705880c 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -103,7 +103,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { const target = document.createElement('div'); target.dispatchEvent(event); - const day = new Date(); + const day = Date.vnNew(); const events = [ {zoneFk: 1}, {zoneFk: 2}, diff --git a/modules/zone/front/descriptor/index.js b/modules/zone/front/descriptor/index.js index 08ada0606..3f4863a60 100644 --- a/modules/zone/front/descriptor/index.js +++ b/modules/zone/front/descriptor/index.js @@ -28,7 +28,7 @@ class Controller extends Descriptor { onDelete() { const $t = this.$translate.instant; - const today = new Date(); + const today = Date.vnNew(); today.setHours(0, 0, 0, 0); const filter = {where: {zoneFk: this.id, shipped: {gte: today}}}; this.$http.get(`Tickets`, {filter}).then(res => { diff --git a/modules/zone/front/events/index.spec.js b/modules/zone/front/events/index.spec.js index b4ff800d6..558d97b6f 100644 --- a/modules/zone/front/events/index.spec.js +++ b/modules/zone/front/events/index.spec.js @@ -68,7 +68,7 @@ describe('component vnZoneEvents', () => { it('should call the createInclusion() method', () => { jest.spyOn(controller, 'createInclusion').mockReturnThis(); - const weekday = {dated: new Date()}; + const weekday = {dated: Date.vnNew()}; const days = [weekday]; const type = 'EventType'; const events = []; @@ -114,7 +114,7 @@ describe('component vnZoneEvents', () => { jest.spyOn(controller, 'createExclusion').mockReturnThis(); const weekday = {}; - const days = [{dated: new Date()}]; + const days = [{dated: Date.vnNew()}]; const type = 'EventType'; const events = []; const exclusions = []; @@ -156,7 +156,7 @@ describe('component vnZoneEvents', () => { it('shoud set the excludeSelected property and then call the excludeDialog show() method', () => { controller.$.excludeDialog = {show: jest.fn()}; - const days = [new Date()]; + const days = [Date.vnNew()]; controller.createExclusion(days); expect(controller.excludeSelected).toBeDefined(); @@ -170,7 +170,7 @@ describe('component vnZoneEvents', () => { controller.$.includeDialog = {show: jest.fn()}; const type = 'weekday'; - const days = [new Date()]; + const days = [Date.vnNew()]; const weekday = 1; controller.createInclusion(type, days, weekday); @@ -187,7 +187,7 @@ describe('component vnZoneEvents', () => { controller.$.includeDialog = {show: jest.fn()}; const type = 'nonListedType'; - const days = [new Date()]; + const days = [Date.vnNew()]; const weekday = 1; controller.createInclusion(type, days, weekday); diff --git a/package-lock.json b/package-lock.json index 31820196f..61180fa3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "salix-back", - "version": "9.0.0", + "version": "23.02.03", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "salix-back", - "version": "9.0.0", + "version": "23.02.03", "license": "GPL-3.0", "dependencies": { "axios": "^1.2.2", + "base64url": "^3.0.1", "bcrypt": "^5.0.1", "bmp-js": "^0.1.0", "compression": "^1.7.3", @@ -4200,6 +4201,14 @@ "node": ">= 0.4" } }, + "node_modules/base64url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", + "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/batch": { "version": "0.6.1", "dev": true, @@ -29057,6 +29066,11 @@ "base64-js": { "version": "1.0.2" }, + "base64url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", + "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==" + }, "batch": { "version": "0.6.1", "dev": true diff --git a/package.json b/package.json index 46b7d4ffc..89bd1a3e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.04.01", + "version": "23.06.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", @@ -13,6 +13,7 @@ }, "dependencies": { "axios": "^1.2.2", + "base64url": "^3.0.1", "bcrypt": "^5.0.1", "bmp-js": "^0.1.0", "compression": "^1.7.3", diff --git a/print/templates/email/buyer-week-waste/buyer-week-waste.js b/print/templates/email/buyer-week-waste/buyer-week-waste.js index 9d4fe1ce1..1ae40cd98 100755 --- a/print/templates/email/buyer-week-waste/buyer-week-waste.js +++ b/print/templates/email/buyer-week-waste/buyer-week-waste.js @@ -13,7 +13,7 @@ module.exports = { dated: function() { const filters = this.$options.filters; - return filters.date(new Date(), '%d-%m-%Y'); + return filters.date(Date.vnNew(), '%d-%m-%Y'); } }, methods: { diff --git a/print/templates/email/osticket-report/osticket-report.js b/print/templates/email/osticket-report/osticket-report.js index eb9c76a89..0d39947d5 100755 --- a/print/templates/email/osticket-report/osticket-report.js +++ b/print/templates/email/osticket-report/osticket-report.js @@ -37,7 +37,7 @@ module.exports = { dated: function() { const filters = this.$options.filters; - return filters.date(new Date(), '%d-%m-%Y'); + return filters.date(Date.vnNew(), '%d-%m-%Y'); }, startedTime: function() { return new Date(this.started).getTime(); diff --git a/print/templates/reports/balance-compensation/sql/client.sql b/print/templates/reports/balance-compensation/sql/client.sql index 92e6f6cab..b4463be23 100644 --- a/print/templates/reports/balance-compensation/sql/client.sql +++ b/print/templates/reports/balance-compensation/sql/client.sql @@ -8,5 +8,4 @@ SELECT r.payed FROM client c JOIN receipt r ON r.clientFk = c.id - JOIN supplier s ON c.fi = s.nif - WHERE r.id = ? \ No newline at end of file + WHERE r.id = ? diff --git a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js index 321862671..88645309d 100644 --- a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js +++ b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js @@ -26,7 +26,7 @@ module.exports = { let QRdata = JSON.stringify({ company: 'vnl', user: this.userFk, - created: new Date(), + created: Date.vnNew(), table: 'expeditionPallet', id: this.id });