Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 5475-email_2fa
This commit is contained in:
commit
f5d26bdb99
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -5,6 +5,17 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2316.01] - 2023-05-04
|
||||||
|
|
||||||
|
### Added
|
||||||
|
-
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
-
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
-
|
||||||
|
|
||||||
## [2314.01] - 2023-04-20
|
## [2314.01] - 2023-04-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -12,9 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia
|
- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia
|
||||||
- (Facturas recibidas -> Bases negativas) Nueva sección
|
- (Facturas recibidas -> Bases negativas) Nueva sección
|
||||||
|
|
||||||
### Changed
|
|
||||||
-
|
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
|
- (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`claimBeginning_afterInsert`;
|
|
@ -0,0 +1,72 @@
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
|
||||||
|
BEFORE UPDATE ON `client`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
DECLARE vText VARCHAR(255) DEFAULT NULL;
|
||||||
|
DECLARE vPayMethodFk INT;
|
||||||
|
-- Comprueba que el formato de los teléfonos es válido
|
||||||
|
|
||||||
|
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
|
||||||
|
CALL pbx.phone_isValid(NEW.phone);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN
|
||||||
|
CALL pbx.phone_isValid(NEW.mobile);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT id INTO vPayMethodFk
|
||||||
|
FROM vn.payMethod
|
||||||
|
WHERE code = 'bankDraft';
|
||||||
|
|
||||||
|
IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN
|
||||||
|
SET NEW.dueDay = 5;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Avisar al comercial si ha llegado la documentación sepa/core
|
||||||
|
|
||||||
|
IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN
|
||||||
|
SET vText = 'Sepa de VNL';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN
|
||||||
|
SET vText = 'Core de VNL';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF vText IS NOT NULL
|
||||||
|
THEN
|
||||||
|
INSERT INTO mail(receiver, replyTo, `subject`, body)
|
||||||
|
SELECT
|
||||||
|
CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'),
|
||||||
|
'administracion@verdnatura.es',
|
||||||
|
CONCAT('Cliente ', NEW.id),
|
||||||
|
CONCAT('Recibida la documentación: ', vText)
|
||||||
|
FROM worker w
|
||||||
|
LEFT JOIN account.user u ON w.userFk = u.id AND u.active
|
||||||
|
LEFT JOIN account.account ac ON ac.id = u.id
|
||||||
|
WHERE w.id = NEW.salesPersonFk;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN
|
||||||
|
IF (SELECT COUNT(clientFk)
|
||||||
|
FROM clientProtected
|
||||||
|
WHERE clientFk = NEW.id
|
||||||
|
) > 0 THEN
|
||||||
|
CALL util.throw("HAS_CLIENT_PROTECTED");
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
|
||||||
|
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||||
|
SET NEW.isTaxDataChecked = 0;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,13 @@
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert`
|
||||||
|
AFTER INSERT ON `invoiceOut`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
CREATE TABLE `vn`.`workerObservation` (
|
||||||
|
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`workerFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
`text` text COLLATE utf8mb3_unicode_ci NOT NULL,
|
||||||
|
`created` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
CONSTRAINT `workerFk_workerObservation_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `userFk_workerObservation_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user`(`id`) ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Todas las observaciones referentes a un trabajador';
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('WorkerObservation', '*', '*', 'ALLOW', 'ROLE', 'hr');
|
|
@ -1774,12 +1774,12 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
|
||||||
( 6, 'mana', 'Mana', 72, 4, 0),
|
( 6, 'mana', 'Mana', 72, 4, 0),
|
||||||
( 7, 'lack', 'Faltas', 72, 2, 0);
|
( 7, 'lack', 'Faltas', 72, 2, 0);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`)
|
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `rma`, `ticketFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183'),
|
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, '02676A049183', 11),
|
||||||
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL),
|
(2, util.VN_CURDATE(), 2, 1101, 18, 3, 0, util.VN_CURDATE(), 1, NULL, 16),
|
||||||
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL),
|
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, NULL, 7),
|
||||||
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL);
|
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, NULL, 8);
|
||||||
|
|
||||||
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -426,7 +426,8 @@ export default {
|
||||||
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
fourthStarted: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.started"]',
|
||||||
fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]',
|
fourthEnded: 'vn-fixed-price tr:nth-child(5) vn-date-picker[ng-model="price.ended"]',
|
||||||
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
fourthDeleteIcon: 'vn-fixed-price tr:nth-child(5) > td:nth-child(9) > vn-icon-button[icon="delete"]',
|
||||||
orderColumnId: 'vn-fixed-price th[field="itemFk"]'
|
orderColumnId: 'vn-fixed-price th[field="itemFk"]',
|
||||||
|
removeWarehouseFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(1) > vn-icon > i'
|
||||||
},
|
},
|
||||||
itemCreateView: {
|
itemCreateView: {
|
||||||
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
temporalName: 'vn-item-create vn-textfield[ng-model="$ctrl.item.provisionalName"]',
|
||||||
|
@ -987,6 +988,12 @@ export default {
|
||||||
locker: 'vn-worker-basic-data vn-input-number[ng-model="$ctrl.worker.locker"]',
|
locker: 'vn-worker-basic-data vn-input-number[ng-model="$ctrl.worker.locker"]',
|
||||||
saveButton: 'vn-worker-basic-data button[type=submit]'
|
saveButton: 'vn-worker-basic-data button[type=submit]'
|
||||||
},
|
},
|
||||||
|
workerNotes: {
|
||||||
|
addNoteFloatButton: 'vn-float-button',
|
||||||
|
note: 'vn-textarea[ng-model="$ctrl.note.text"]',
|
||||||
|
saveButton: 'button[type=submit]',
|
||||||
|
firstNoteText: 'vn-worker-note .text'
|
||||||
|
},
|
||||||
workerPbx: {
|
workerPbx: {
|
||||||
extension: 'vn-worker-pbx vn-textfield[ng-model="$ctrl.worker.sip.extension"]',
|
extension: 'vn-worker-pbx vn-textfield[ng-model="$ctrl.worker.sip.extension"]',
|
||||||
saveButton: 'vn-worker-pbx button[type=submit]'
|
saveButton: 'vn-worker-pbx button[type=submit]'
|
||||||
|
|
|
@ -90,7 +90,7 @@ describe('SmartTable SearchBar integration', () => {
|
||||||
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
await page.waitToClick(selectors.itemFixedPrice.orderColumnId);
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
expect(result).toEqual('13');
|
expect(result).toEqual('3');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload page and have same order', async() => {
|
it('should reload page and have same order', async() => {
|
||||||
|
@ -99,7 +99,7 @@ describe('SmartTable SearchBar integration', () => {
|
||||||
});
|
});
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.firstItemID, 'value');
|
||||||
|
|
||||||
expect(result).toEqual('13');
|
expect(result).toEqual('3');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
import selectors from '../../helpers/selectors';
|
||||||
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
|
describe('Worker Add notes path', () => {
|
||||||
|
let browser;
|
||||||
|
let page;
|
||||||
|
beforeAll(async() => {
|
||||||
|
browser = await getBrowser();
|
||||||
|
page = browser.page;
|
||||||
|
await page.loginAndModule('employee', 'worker');
|
||||||
|
await page.accessToSearchResult('Bruce Banner');
|
||||||
|
await page.accessToSection('worker.card.note.index');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should reach the notes index`, async() => {
|
||||||
|
await page.waitForState('worker.card.note.index');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should click on the add note button`, async() => {
|
||||||
|
await page.waitToClick(selectors.workerNotes.addNoteFloatButton);
|
||||||
|
await page.waitForState('worker.card.note.create');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should create a note`, async() => {
|
||||||
|
await page.waitForSelector(selectors.workerNotes.note);
|
||||||
|
await page.type(`${selectors.workerNotes.note} textarea`, 'Meeting with Black Widow 21st 9am');
|
||||||
|
await page.waitToClick(selectors.workerNotes.saveButton);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toContain('Data saved!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should confirm the note was created', async() => {
|
||||||
|
const result = await page.waitToGetProperty(selectors.workerNotes.firstNoteText, 'innerText');
|
||||||
|
|
||||||
|
expect(result).toEqual('Meeting with Black Widow 21st 9am');
|
||||||
|
});
|
||||||
|
});
|
|
@ -15,8 +15,9 @@ describe('Item fixed prices path', () => {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should click on the add new foxed price button', async() => {
|
it('should click on the add new fixed price button', async() => {
|
||||||
await page.doSearch();
|
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||||
|
await page.waitForSpinnerLoad();
|
||||||
await page.waitToClick(selectors.itemFixedPrice.add);
|
await page.waitToClick(selectors.itemFixedPrice.add);
|
||||||
await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
|
await page.waitForSelector(selectors.itemFixedPrice.fourthFixedPrice);
|
||||||
});
|
});
|
||||||
|
@ -37,7 +38,8 @@ describe('Item fixed prices path', () => {
|
||||||
it('should reload the section and check the created price has the expected ID', async() => {
|
it('should reload the section and check the created price has the expected ID', async() => {
|
||||||
await page.accessToSection('item.index');
|
await page.accessToSection('item.index');
|
||||||
await page.accessToSection('item.fixedPrice');
|
await page.accessToSection('item.fixedPrice');
|
||||||
await page.doSearch();
|
await page.waitToClick(selectors.itemFixedPrice.removeWarehouseFilter);
|
||||||
|
await page.waitForSpinnerLoad();
|
||||||
|
|
||||||
const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');
|
const result = await page.waitToGetProperty(selectors.itemFixedPrice.fourthItemID, 'value');
|
||||||
|
|
||||||
|
|
|
@ -276,5 +276,6 @@
|
||||||
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
"Added observation": "{{user}} añadió esta observacion: {{text}}",
|
||||||
"Comment added to client": "Observación añadida al cliente {{clientFk}}",
|
"Comment added to client": "Observación añadida al cliente {{clientFk}}",
|
||||||
"Invalid auth code": "Código de verificación incorrecto",
|
"Invalid auth code": "Código de verificación incorrecto",
|
||||||
"Invalid or expired verification code": "Invalid or expired verification code"
|
"Invalid or expired verification code": "Código de verificación incorrecto o expirado",
|
||||||
|
"Cannot create a new claimBeginning from a different ticket": "No se puede crear una línea de reclamación de un ticket diferente al origen"
|
||||||
}
|
}
|
|
@ -311,7 +311,7 @@ class VnMySQL extends MySQL {
|
||||||
return super[method].apply(this, args);
|
return super[method].apply(this, args);
|
||||||
|
|
||||||
this.invokeMethodP(method, [...args], model, ctx, opts)
|
this.invokeMethodP(method, [...args], model, ctx, opts)
|
||||||
.then(res => cb(...res), cb);
|
.then(res => cb(...[null].concat(res)), cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
async invokeMethodP(method, args, model, ctx, opts) {
|
async invokeMethodP(method, args, model, ctx, opts) {
|
||||||
|
@ -331,8 +331,7 @@ class VnMySQL extends MySQL {
|
||||||
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
const userId = opts.httpCtx && opts.httpCtx.active.accessToken.userId;
|
||||||
const user = await Model.app.models.Account.findById(userId, { fields: ['name'] }, opts);
|
const user = await Model.app.models.Account.findById(userId, { fields: ['name'] }, opts);
|
||||||
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
await this.executeP(`CALL account.myUser_loginWithName(?)`, [user.name], opts);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
where = ctx.where;
|
where = ctx.where;
|
||||||
id = ctx.id;
|
id = ctx.id;
|
||||||
data = ctx.data;
|
data = ctx.data;
|
||||||
|
@ -358,9 +357,12 @@ class VnMySQL extends MySQL {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await new Promise(resolve => {
|
const res = await new Promise((resolve, reject) => {
|
||||||
const fnArgs = args.slice(0, -2);
|
const fnArgs = args.slice(0, -2);
|
||||||
fnArgs.push(opts, (...args) => resolve(args));
|
fnArgs.push(opts, (err, ...args) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
resolve(args);
|
||||||
|
});
|
||||||
super[method].apply(this, fnArgs);
|
super[method].apply(this, fnArgs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -375,11 +377,11 @@ class VnMySQL extends MySQL {
|
||||||
case 'update': {
|
case 'update': {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'createAll':
|
case 'createAll':
|
||||||
for (const row of res[1])
|
for (const row of res[0])
|
||||||
ids.push(row[idName]);
|
ids.push(row[idName]);
|
||||||
break;
|
break;
|
||||||
case 'create':
|
case 'create':
|
||||||
ids.push(res[1]);
|
ids.push(res[0]);
|
||||||
break;
|
break;
|
||||||
case 'update':
|
case 'update':
|
||||||
if (data[idName] != null)
|
if (data[idName] != null)
|
||||||
|
@ -387,7 +389,7 @@ class VnMySQL extends MySQL {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newWhere = ids.length ? { [idName]: ids } : where;
|
const newWhere = ids.length ? {[idName]: {inq: ids}} : where;
|
||||||
|
|
||||||
const stmt = this.buildSelectStmt(op, data, idName, model, newWhere, limit);
|
const stmt = this.buildSelectStmt(op, data, idName, model, newWhere, limit);
|
||||||
newInstances = await this.executeStmt(stmt, opts);
|
newInstances = await this.executeStmt(stmt, opts);
|
||||||
|
|
|
@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('Claim createFromSales()', () => {
|
describe('Claim createFromSales()', () => {
|
||||||
const ticketId = 16;
|
const ticketId = 23;
|
||||||
const newSale = [{
|
const newSale = [{
|
||||||
id: 3,
|
id: 31,
|
||||||
instance: 0,
|
instance: 0,
|
||||||
quantity: 10
|
quantity: 10
|
||||||
}];
|
}];
|
||||||
|
|
|
@ -10,8 +10,16 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before save', async ctx => {
|
Self.observe('before save', async ctx => {
|
||||||
if (ctx.isNewInstance) return;
|
if (ctx.isNewInstance) {
|
||||||
//await claimIsEditable(ctx);
|
const models = Self.app.models;
|
||||||
|
const options = ctx.options;
|
||||||
|
const instance = ctx.instance;
|
||||||
|
const ticket = await models.Sale.findById(instance.saleFk, {fields: ['ticketFk']}, options);
|
||||||
|
const claim = await models.Claim.findById(instance.claimFk, {fields: ['ticketFk']}, options);
|
||||||
|
if (ticket.ticketFk != claim.ticketFk)
|
||||||
|
throw new UserError(`Cannot create a new claimBeginning from a different ticket`);
|
||||||
|
}
|
||||||
|
// await claimIsEditable(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before delete', async ctx => {
|
Self.observe('before delete', async ctx => {
|
||||||
|
|
|
@ -2,6 +2,10 @@ import ngModule from '../module';
|
||||||
import Section from 'salix/components/section';
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
|
$onInit() {
|
||||||
|
this.card.reload();
|
||||||
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const orgData = this.$.watcher.orgData;
|
const orgData = this.$.watcher.orgData;
|
||||||
delete this.client.despiteOfClient;
|
delete this.client.despiteOfClient;
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('editFixedPrice', {
|
||||||
|
description: 'Updates a column for one or more fixed price',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'field',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: `the column to edit`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'newValue',
|
||||||
|
type: 'any',
|
||||||
|
required: true,
|
||||||
|
description: `The new value to save`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'lines',
|
||||||
|
type: ['object'],
|
||||||
|
required: true,
|
||||||
|
description: `the buys which will be modified`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/editFixedPrice`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.editFixedPrice = async(ctx, field, newValue, lines, filter, options) => {
|
||||||
|
let tx;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
let modelName;
|
||||||
|
let identifier;
|
||||||
|
|
||||||
|
switch (field) {
|
||||||
|
case 'hasMinPrice':
|
||||||
|
case 'minPrice':
|
||||||
|
modelName = 'Item';
|
||||||
|
identifier = 'itemFk';
|
||||||
|
break;
|
||||||
|
case 'rate2':
|
||||||
|
case 'rate3':
|
||||||
|
case 'started':
|
||||||
|
case 'ended':
|
||||||
|
case 'warehouseFk':
|
||||||
|
modelName = 'FixedPrice';
|
||||||
|
identifier = 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
const models = Self.app.models;
|
||||||
|
const model = models[modelName];
|
||||||
|
try {
|
||||||
|
const promises = [];
|
||||||
|
const value = {};
|
||||||
|
value[field] = newValue;
|
||||||
|
|
||||||
|
if (filter) {
|
||||||
|
filter = {where: filter};
|
||||||
|
lines = await models.FixedPrice.filter(ctx, filter, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
const targets = lines.map(line => {
|
||||||
|
return line[identifier];
|
||||||
|
});
|
||||||
|
for (let target of targets)
|
||||||
|
promises.push(model.upsertWithWhere({id: target}, value, myOptions));
|
||||||
|
|
||||||
|
const result = await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -184,8 +184,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
stmt.merge(conn.makePagination(filter));
|
|
||||||
|
|
||||||
const fixedPriceIndex = stmts.push(stmt) - 1;
|
const fixedPriceIndex = stmts.push(stmt) - 1;
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Item editFixedPrice()', () => {
|
||||||
|
it('should change the value of a given column for the selected buys', async() => {
|
||||||
|
const tx = await models.FixedPrice.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
search: '1'
|
||||||
|
},
|
||||||
|
req: {accessToken: {userId: 1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const [original] = await models.FixedPrice.filter(ctx, null, options);
|
||||||
|
|
||||||
|
const field = 'rate2';
|
||||||
|
const newValue = 99;
|
||||||
|
const lines = [{itemFk: original.itemFk, id: original.id}];
|
||||||
|
|
||||||
|
await models.FixedPrice.editFixedPrice(ctx, field, newValue, lines, null, options);
|
||||||
|
|
||||||
|
const [result] = await models.FixedPrice.filter(ctx, null, options);
|
||||||
|
|
||||||
|
expect(result[field]).toEqual(newValue);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change the value of a given column for filter', async() => {
|
||||||
|
const tx = await models.FixedPrice.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const filter = {'it.categoryFk': 1};
|
||||||
|
const ctx = {
|
||||||
|
args: {
|
||||||
|
filter: filter
|
||||||
|
},
|
||||||
|
req: {accessToken: {userId: 1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
const field = 'rate2';
|
||||||
|
const newValue = 88;
|
||||||
|
|
||||||
|
await models.FixedPrice.editFixedPrice(ctx, field, newValue, null, filter, options);
|
||||||
|
|
||||||
|
const [result] = await models.FixedPrice.filter(ctx, filter, options);
|
||||||
|
|
||||||
|
expect(result[field]).toEqual(newValue);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -42,7 +42,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
|
|
||||||
delete ctx.args.started;
|
delete ctx.args.started;
|
||||||
delete ctx.args.ended;
|
delete ctx.args.ended;
|
||||||
ctx.args.hasMinPrice = true;
|
ctx.args.hasMinPrice = false;
|
||||||
|
|
||||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
|
|
||||||
delete ctx.args.started;
|
delete ctx.args.started;
|
||||||
delete ctx.args.ended;
|
delete ctx.args.ended;
|
||||||
ctx.args.hasMinPrice = false;
|
ctx.args.hasMinPrice = true;
|
||||||
|
|
||||||
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
expect(result).toEqual(jasmine.objectContaining(ctx.args));
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ describe('upsertFixedPrice()', () => {
|
||||||
rate2: rate2,
|
rate2: rate2,
|
||||||
rate3: firstRate3,
|
rate3: firstRate3,
|
||||||
minPrice: 0,
|
minPrice: 0,
|
||||||
hasMinPrice: false
|
hasMinPrice: true
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// create new fixed price
|
// create new fixed price
|
||||||
|
|
|
@ -87,7 +87,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
await targetItem.updateAttributes({
|
await targetItem.updateAttributes({
|
||||||
minPrice: args.minPrice,
|
minPrice: args.minPrice,
|
||||||
hasMinPrice: args.minPrice ? true : false
|
hasMinPrice: args.hasMinPrice
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const itemFields = [
|
const itemFields = [
|
||||||
|
|
|
@ -2,4 +2,5 @@ module.exports = Self => {
|
||||||
require('../methods/fixed-price/filter')(Self);
|
require('../methods/fixed-price/filter')(Self);
|
||||||
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
require('../methods/fixed-price/upsertFixedPrice')(Self);
|
||||||
require('../methods/fixed-price/getRate2')(Self);
|
require('../methods/fixed-price/getRate2')(Self);
|
||||||
|
require('../methods/fixed-price/editFixedPrice')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
|
},
|
||||||
|
"isChecked": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="FixedPrices/filter"
|
url="FixedPrices/filter"
|
||||||
|
user-params="::$ctrl.filterParams"
|
||||||
limit="20"
|
limit="20"
|
||||||
data="prices"
|
data="prices"
|
||||||
order="itemFk"
|
order="itemFk"
|
||||||
|
@ -17,6 +18,8 @@
|
||||||
auto-state="false"
|
auto-state="false"
|
||||||
panel="vn-fixed-price-search-panel"
|
panel="vn-fixed-price-search-panel"
|
||||||
info="Search prices by item ID or code"
|
info="Search prices by item ID or code"
|
||||||
|
suggested-filter="$ctrl.filterParams"
|
||||||
|
filter="$ctrl.filterParams"
|
||||||
placeholder="Search fixed prices"
|
placeholder="Search fixed prices"
|
||||||
model="model">
|
model="model">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
|
@ -31,15 +34,21 @@
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th shrink>
|
||||||
|
<vn-multi-check
|
||||||
|
model="model"
|
||||||
|
checked="$ctrl.checkAll"
|
||||||
|
check-field="checked"
|
||||||
|
check-dummy-enabled="true"
|
||||||
|
checked-dummy-count="$ctrl.checkedDummyCount">
|
||||||
|
</vn-multi-check>
|
||||||
|
</th>
|
||||||
<th field="itemFk">
|
<th field="itemFk">
|
||||||
<span translate>Item ID</span>
|
<span translate>Item ID</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="name">
|
<th field="name">
|
||||||
<span translate>Description</span>
|
<span translate>Description</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="warehouseFk">
|
|
||||||
<span translate>Warehouse</span>
|
|
||||||
</th>
|
|
||||||
<th
|
<th
|
||||||
field="rate2">
|
field="rate2">
|
||||||
<span translate>Grouping price</span>
|
<span translate>Grouping price</span>
|
||||||
|
@ -57,13 +66,24 @@
|
||||||
<th field="ended">
|
<th field="ended">
|
||||||
<span translate>Ended</span>
|
<span translate>Ended</span>
|
||||||
</th>
|
</th>
|
||||||
|
<th field="warehouseFk">
|
||||||
|
<span translate>Warehouse</span>
|
||||||
|
</th>
|
||||||
<th shrink></th>
|
<th shrink></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="price in prices">
|
<tr ng-repeat="price in prices">
|
||||||
|
<td>
|
||||||
|
<vn-check
|
||||||
|
ng-model="price.checked"
|
||||||
|
on-change="$ctrl.saveChecked(price.id)"
|
||||||
|
vn-click-stop>
|
||||||
|
</vn-check>
|
||||||
|
</td>
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
|
vn-id="itemFk"
|
||||||
class="dense"
|
class="dense"
|
||||||
url="Items/withName"
|
url="Items/withName"
|
||||||
ng-model="price.itemFk"
|
ng-model="price.itemFk"
|
||||||
|
@ -88,7 +108,7 @@
|
||||||
ng-if="price.itemFk"
|
ng-if="price.itemFk"
|
||||||
ng-click="itemDescriptor.show($event, price.itemFk)"
|
ng-click="itemDescriptor.show($event, price.itemFk)"
|
||||||
class="link">
|
class="link">
|
||||||
{{price.name}}
|
{{itemFk.selection.name}}
|
||||||
</span>
|
</span>
|
||||||
<vn-one ng-if="price.subName">
|
<vn-one ng-if="price.subName">
|
||||||
<h3 title="{{price.subName}}">{{price.subName}}</h3>
|
<h3 title="{{price.subName}}">{{price.subName}}</h3>
|
||||||
|
@ -100,18 +120,11 @@
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
</vn-fetched-tags>
|
</vn-fetched-tags>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-field-expand>
|
|
||||||
<vn-autocomplete
|
|
||||||
vn-one
|
|
||||||
ng-model="price.warehouseFk"
|
|
||||||
data="warehouses"
|
|
||||||
on-change="$ctrl.upsertPrice(price)"
|
|
||||||
tabindex="2">
|
|
||||||
</vn-autocomplete>
|
|
||||||
</td>
|
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-td-editable number>
|
<vn-td-editable number>
|
||||||
<text>{{price.rate2 | currency: 'EUR':2}}</text>
|
<text>
|
||||||
|
<strong>{{price.rate2 | currency: 'EUR':2}}</strong>
|
||||||
|
</text>
|
||||||
<field>
|
<field>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
class="dense"
|
class="dense"
|
||||||
|
@ -125,7 +138,9 @@
|
||||||
</td>
|
</td>
|
||||||
<td shrink-field>
|
<td shrink-field>
|
||||||
<vn-td-editable number>
|
<vn-td-editable number>
|
||||||
<text>{{price.rate3 | currency: 'EUR':2}}</text>
|
<text>
|
||||||
|
<strong>{{price.rate3 | currency: 'EUR':2}}</strong>
|
||||||
|
</text>
|
||||||
<field>
|
<field>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
class="dense"
|
class="dense"
|
||||||
|
@ -140,28 +155,42 @@
|
||||||
<td shrink-field-expand class="minPrice">
|
<td shrink-field-expand class="minPrice">
|
||||||
<vn-check
|
<vn-check
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="price.hasMinPrice">
|
ng-model="price.hasMinPrice"
|
||||||
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
</vn-check>
|
</vn-check>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
disabled="!price.hasMinPrice"
|
ng-class="{inactive: !price.hasMinPrice}"
|
||||||
ng-model="price.minPrice"
|
ng-model="price.minPrice"
|
||||||
on-change="$ctrl.upsertPrice(price)"
|
on-change="$ctrl.upsertPrice(price)"
|
||||||
step="0.01">
|
step="0.01">
|
||||||
</vn-input-number>
|
</vn-input-number>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-date>
|
<td shrink-date>
|
||||||
|
<vn-chip class="chip {{$ctrl.isBigger(price.started)}} transparent">
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="price.started"
|
ng-model="price.started"
|
||||||
on-change="$ctrl.upsertPrice(price)">
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
|
</vn-chip>
|
||||||
</td>
|
</td>
|
||||||
<td shrink-date>
|
<td shrink-date>
|
||||||
|
<vn-chip class="chip {{$ctrl.isLower(price.ended)}} transparent">
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="price.ended"
|
ng-model="price.ended"
|
||||||
on-change="$ctrl.upsertPrice(price)">
|
on-change="$ctrl.upsertPrice(price)">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
|
</vn-chip>
|
||||||
|
</td>
|
||||||
|
<td expand>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
ng-model="price.warehouseFk"
|
||||||
|
data="warehouses"
|
||||||
|
on-change="$ctrl.upsertPrice(price)"
|
||||||
|
tabindex="2">
|
||||||
|
</vn-autocomplete>
|
||||||
</td>
|
</td>
|
||||||
<td shrink>
|
<td shrink>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
|
@ -185,6 +214,69 @@
|
||||||
</smart-table>
|
</smart-table>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div fixed-bottom-right>
|
||||||
|
<vn-vertical style="align-items: center;">
|
||||||
|
<vn-button class="round sm vn-mb-sm"
|
||||||
|
icon="edit"
|
||||||
|
ng-show="$ctrl.totalChecked > 0"
|
||||||
|
ng-click="edit.show($event)"
|
||||||
|
vn-tooltip="Edit fixed price(s)"
|
||||||
|
tooltip-position="left">
|
||||||
|
</vn-button>
|
||||||
|
</vn-vertical>
|
||||||
|
</div>
|
||||||
|
<vn-dialog class="edit"
|
||||||
|
vn-id="edit"
|
||||||
|
on-accept="$ctrl.onEditAccept()"
|
||||||
|
on-close="$ctrl.editedColumn = null">
|
||||||
|
<tpl-body style="width: 400px;">
|
||||||
|
<span translate>Edit</span>
|
||||||
|
<span class="countLines">
|
||||||
|
{{::$ctrl.totalChecked}}
|
||||||
|
</span>
|
||||||
|
<span translate>buy(s)</span>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
ng-model="$ctrl.editedColumn.field"
|
||||||
|
data="$ctrl.columns"
|
||||||
|
value-field="field"
|
||||||
|
show-field="displayName"
|
||||||
|
label="Field to edit">
|
||||||
|
</vn-autocomplete>
|
||||||
|
<vn-input-number
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'rate2' || $ctrl.editedColumn.field == 'rate3' || $ctrl.editedColumn.field == 'minPrice'"
|
||||||
|
label="Value"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-input-number>
|
||||||
|
<vn-check
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'hasMinPrice'"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-check>
|
||||||
|
<vn-date-picker
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'started' || $ctrl.editedColumn.field == 'ended'"
|
||||||
|
label="Date"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue">
|
||||||
|
</vn-date-picker>
|
||||||
|
<vn-autocomplete
|
||||||
|
vn-one
|
||||||
|
ng-if="$ctrl.editedColumn.field == 'warehouseFk'"
|
||||||
|
label="Warehouse"
|
||||||
|
ng-model="$ctrl.editedColumn.newValue"
|
||||||
|
data="warehouses">
|
||||||
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
|
<button response="accept" translate>Save</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
||||||
|
|
||||||
<vn-item-descriptor-popover
|
<vn-item-descriptor-popover
|
||||||
vn-id="item-descriptor"
|
vn-id="item-descriptor"
|
||||||
warehouse-fk="$ctrl.vnConfig.warehouseFk">
|
warehouse-fk="$ctrl.vnConfig.warehouseFk">
|
||||||
|
|
|
@ -5,6 +5,9 @@ import './style.scss';
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
|
this.editedColumn;
|
||||||
|
this.checkAll = false;
|
||||||
|
this.checkedFixedPrices = [];
|
||||||
|
|
||||||
this.smartTableOptions = {
|
this.smartTableOptions = {
|
||||||
activeButtons: {
|
activeButtons: {
|
||||||
|
@ -30,13 +33,146 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.filterParams = {
|
||||||
|
warehouseFk: this.vnConfig.warehouseFk
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getFilterParams() {
|
||||||
|
return {
|
||||||
|
warehouseFk: this.vnConfig.warehouseFk
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get columns() {
|
||||||
|
if (this._columns) return this._columns;
|
||||||
|
|
||||||
|
this._columns = [
|
||||||
|
{field: 'rate2', displayName: this.$t('Grouping price')},
|
||||||
|
{field: 'rate3', displayName: this.$t('Packing price')},
|
||||||
|
{field: 'hasMinPrice', displayName: this.$t('Has min price')},
|
||||||
|
{field: 'minPrice', displayName: this.$t('Min price')},
|
||||||
|
{field: 'started', displayName: this.$t('Started')},
|
||||||
|
{field: 'ended', displayName: this.$t('Ended')},
|
||||||
|
{field: 'warehouseFk', displayName: this.$t('Warehouse')}
|
||||||
|
];
|
||||||
|
|
||||||
|
return this._columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
get checked() {
|
||||||
|
const fixedPrices = this.$.model.data || [];
|
||||||
|
const checkedBuys = [];
|
||||||
|
for (let fixedPrice of fixedPrices) {
|
||||||
|
if (fixedPrice.checked)
|
||||||
|
checkedBuys.push(fixedPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
return checkedBuys;
|
||||||
|
}
|
||||||
|
|
||||||
|
uncheck() {
|
||||||
|
this.checkAll = false;
|
||||||
|
this.checkedFixedPrices = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get totalChecked() {
|
||||||
|
if (this.checkedDummyCount)
|
||||||
|
return this.checkedDummyCount;
|
||||||
|
|
||||||
|
return this.checked.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveChecked(fixedPriceId) {
|
||||||
|
const index = this.checkedFixedPrices.indexOf(fixedPriceId);
|
||||||
|
if (index !== -1)
|
||||||
|
return this.checkedFixedPrices.splice(index, 1);
|
||||||
|
return this.checkedFixedPrices.push(fixedPriceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
reCheck() {
|
||||||
|
if (!this.$.model.data) return;
|
||||||
|
if (!this.checkedFixedPrices.length) return;
|
||||||
|
|
||||||
|
this.$.model.data.forEach(fixedPrice => {
|
||||||
|
if (this.checkedFixedPrices.includes(fixedPrice.id))
|
||||||
|
fixedPrice.checked = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onEditAccept() {
|
||||||
|
const rowsToEdit = [];
|
||||||
|
for (let row of this.checked)
|
||||||
|
rowsToEdit.push({id: row.id, itemFk: row.itemFk});
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
field: this.editedColumn.field,
|
||||||
|
newValue: this.editedColumn.newValue,
|
||||||
|
lines: rowsToEdit
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.checkedDummyCount && this.checkedDummyCount > 0) {
|
||||||
|
const params = {};
|
||||||
|
if (this.$.model.userParams) {
|
||||||
|
const userParams = this.$.model.userParams;
|
||||||
|
for (let param in userParams) {
|
||||||
|
let newParam = this.exprBuilder(param, userParams[param]);
|
||||||
|
if (!newParam)
|
||||||
|
newParam = {[param]: userParams[param]};
|
||||||
|
Object.assign(params, newParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.$.model.userFilter)
|
||||||
|
Object.assign(params, this.$.model.userFilter.where);
|
||||||
|
|
||||||
|
data.filter = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.$http.post('FixedPrices/editFixedPrice', data)
|
||||||
|
.then(() => {
|
||||||
|
this.uncheck();
|
||||||
|
this.$.model.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
isBigger(date) {
|
||||||
|
let today = Date.vnNew();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
date = new Date(date);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDifference = today - date;
|
||||||
|
if (timeDifference < 0) return 'warning';
|
||||||
|
}
|
||||||
|
|
||||||
|
isLower(date) {
|
||||||
|
let today = Date.vnNew();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
date = new Date(date);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDifference = today - date;
|
||||||
|
if (timeDifference > 0) return 'warning';
|
||||||
}
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
if (!this.$.model.data || this.$.model.data.length == 0) {
|
if (!this.$.model.data || this.$.model.data.length == 0) {
|
||||||
this.$.model.data = [];
|
this.$.model.data = [];
|
||||||
this.$.model.proxiedData = [];
|
this.$.model.proxiedData = [];
|
||||||
this.$.model.insert({});
|
|
||||||
|
const today = Date.vnNew();
|
||||||
|
|
||||||
|
const millisecsInDay = 86400000;
|
||||||
|
const daysInWeek = 7;
|
||||||
|
const nextWeek = new Date(today.getTime() + daysInWeek * millisecsInDay);
|
||||||
|
|
||||||
|
this.$.model.insert({
|
||||||
|
started: today,
|
||||||
|
ended: nextWeek
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,10 +202,8 @@ export default class Controller extends Section {
|
||||||
if (resetMinPrice)
|
if (resetMinPrice)
|
||||||
delete price['minPrice'];
|
delete price['minPrice'];
|
||||||
|
|
||||||
price.hasMinPrice = price.minPrice ? true : false;
|
const requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
||||||
|
for (const field of requiredFields)
|
||||||
let requiredFields = ['itemFk', 'started', 'ended', 'rate2', 'rate3'];
|
|
||||||
for (let field of requiredFields)
|
|
||||||
if (price[field] == undefined) return;
|
if (price[field] == undefined) return;
|
||||||
|
|
||||||
const query = 'FixedPrices/upsertFixedPrice';
|
const query = 'FixedPrices/upsertFixedPrice';
|
||||||
|
|
|
@ -12,8 +12,92 @@ describe('fixed price', () => {
|
||||||
const $scope = $rootScope.$new();
|
const $scope = $rootScope.$new();
|
||||||
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
||||||
controller = $componentController('vnFixedPrice', {$element, $scope});
|
controller = $componentController('vnFixedPrice', {$element, $scope});
|
||||||
|
controller.$ = {
|
||||||
|
model: {refresh: () => {}},
|
||||||
|
edit: {hide: () => {}}
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
describe('get columns', () => {
|
||||||
|
it(`should return a set of columns`, () => {
|
||||||
|
let result = controller.columns;
|
||||||
|
|
||||||
|
let length = result.length;
|
||||||
|
let anyColumn = Object.keys(result[Math.floor(Math.random() * Math.floor(length))]);
|
||||||
|
|
||||||
|
expect(anyColumn).toContain('field', 'displayName');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('get checked', () => {
|
||||||
|
it(`should return a set of checked lines`, () => {
|
||||||
|
controller.$.model.data = [
|
||||||
|
{checked: true, id: 1},
|
||||||
|
{checked: true, id: 2},
|
||||||
|
{checked: true, id: 3},
|
||||||
|
{checked: false, id: 4},
|
||||||
|
];
|
||||||
|
|
||||||
|
let result = controller.checked;
|
||||||
|
|
||||||
|
expect(result.length).toEqual(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('reCheck()', () => {
|
||||||
|
it(`should recheck buys`, () => {
|
||||||
|
controller.$.model.data = [
|
||||||
|
{checked: false, id: 1},
|
||||||
|
{checked: false, id: 2},
|
||||||
|
{checked: false, id: 3},
|
||||||
|
{checked: false, id: 4},
|
||||||
|
];
|
||||||
|
controller.checkedFixedPrices = [1, 2];
|
||||||
|
|
||||||
|
controller.reCheck();
|
||||||
|
|
||||||
|
expect(controller.$.model.data[0].checked).toEqual(true);
|
||||||
|
expect(controller.$.model.data[1].checked).toEqual(true);
|
||||||
|
expect(controller.$.model.data[2].checked).toEqual(false);
|
||||||
|
expect(controller.$.model.data[3].checked).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('saveChecked()', () => {
|
||||||
|
it(`should check buy`, () => {
|
||||||
|
const buyCheck = 3;
|
||||||
|
controller.checkedFixedPrices = [1, 2];
|
||||||
|
|
||||||
|
controller.saveChecked(buyCheck);
|
||||||
|
|
||||||
|
expect(controller.checkedFixedPrices[2]).toEqual(buyCheck);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should uncheck buy`, () => {
|
||||||
|
const buyUncheck = 3;
|
||||||
|
controller.checkedFixedPrices = [1, 2, 3];
|
||||||
|
|
||||||
|
controller.saveChecked(buyUncheck);
|
||||||
|
|
||||||
|
expect(controller.checkedFixedPrices[2]).toEqual(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onEditAccept()', () => {
|
||||||
|
it(`should perform a query to update columns`, () => {
|
||||||
|
controller.editedColumn = {field: 'my field', newValue: 'the new value'};
|
||||||
|
const query = 'FixedPrices/editFixedPrice';
|
||||||
|
|
||||||
|
$httpBackend.expectPOST(query).respond();
|
||||||
|
controller.onEditAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
const result = controller.checked;
|
||||||
|
|
||||||
|
expect(result.length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('upsertPrice()', () => {
|
describe('upsertPrice()', () => {
|
||||||
it('should do nothing if one or more required arguments are missing', () => {
|
it('should do nothing if one or more required arguments are missing', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
|
@ -3,3 +3,5 @@ Search prices by item ID or code: Buscar por ID de artículo o código
|
||||||
Search fixed prices: Buscar precios fijados
|
Search fixed prices: Buscar precios fijados
|
||||||
Add fixed price: Añadir precio fijado
|
Add fixed price: Añadir precio fijado
|
||||||
This row will be removed: Esta linea se eliminará
|
This row will be removed: Esta linea se eliminará
|
||||||
|
Edit fixed price(s): Editar precio(s) fijado(s)
|
||||||
|
Has min price: Tiene precio mínimo
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
@import "variables";
|
@import "variables";
|
||||||
smart-table table{
|
vn-fixed-price{
|
||||||
|
smart-table table{
|
||||||
[shrink-field]{
|
[shrink-field]{
|
||||||
width: 80px;
|
width: 80px;
|
||||||
max-width: 80px;
|
max-width: 80px;
|
||||||
|
@ -8,13 +9,38 @@ smart-table table{
|
||||||
width: 150px;
|
width: 150px;
|
||||||
max-width: 150px;
|
max-width: 150px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.minPrice {
|
.minPrice {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
vn-input-number {
|
vn-input-number {
|
||||||
width: 90px;
|
width: 90px;
|
||||||
max-width: 90px;
|
max-width: 90px;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td .chip {
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td{
|
||||||
|
padding: 0px;
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
smart-table table tbody > * > td .chip.warning {
|
||||||
|
color: $color-font-bg
|
||||||
|
}
|
||||||
|
|
||||||
|
.vn-field > .container > .infix > .control > input {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
vn-input-number.inactive{
|
||||||
|
input {
|
||||||
|
color: $color-font-light !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -51,6 +51,8 @@ module.exports = Self => {
|
||||||
if (response[0] && response[0].error)
|
if (response[0] && response[0].error)
|
||||||
throw new UserError(response[0].error);
|
throw new UserError(response[0].error);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, workerId, args.timed, myOptions);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,11 @@ module.exports = Self => {
|
||||||
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
return Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [
|
const response = await Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [
|
||||||
targetTimeEntry.userFk, targetTimeEntry.timed], myOptions);
|
targetTimeEntry.userFk, targetTimeEntry.timed], myOptions);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions);
|
||||||
|
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('resendWeeklyHourEmail', {
|
||||||
|
description: 'Adds a new hour registry',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'dated',
|
||||||
|
type: 'date',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: [{
|
||||||
|
type: 'Object',
|
||||||
|
root: true
|
||||||
|
}],
|
||||||
|
http: {
|
||||||
|
path: `/:id/resendWeeklyHourEmail`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.resendWeeklyHourEmail = async(ctx, workerId, dated, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const yearNumber = dated.getFullYear();
|
||||||
|
const weekNumber = getWeekNumber(dated);
|
||||||
|
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: workerId,
|
||||||
|
year: yearNumber,
|
||||||
|
week: weekNumber
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (workerTimeControlMail && workerTimeControlMail.state != 'SENDED') {
|
||||||
|
const worker = await models.EmailUser.findById(workerId, null, myOptions);
|
||||||
|
ctx.args = {
|
||||||
|
recipient: worker.email,
|
||||||
|
year: yearNumber,
|
||||||
|
week: weekNumber,
|
||||||
|
workerId: workerId,
|
||||||
|
state: 'SENDED'
|
||||||
|
};
|
||||||
|
return models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getWeekNumber(date) {
|
||||||
|
const tempDate = new Date(date);
|
||||||
|
let dayOfWeek = tempDate.getDay();
|
||||||
|
dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek;
|
||||||
|
const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1));
|
||||||
|
const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1);
|
||||||
|
const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime();
|
||||||
|
const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1;
|
||||||
|
return weekNumber;
|
||||||
|
}
|
||||||
|
};
|
|
@ -82,14 +82,9 @@ module.exports = Self => {
|
||||||
updated: Date.vnNew(), state: 'SENDED'
|
updated: Date.vnNew(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
|
||||||
`CALL vn.timeControl_calculateByUser(?, ?, ?)
|
|
||||||
`, [args.workerId, started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = ?', [args.workerId]);
|
||||||
stmt = new ParameterizedSQL(
|
|
||||||
`CALL vn.timeBusiness_calculateByUser(?, ?, ?)
|
|
||||||
`, [args.workerId, started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
} else {
|
} else {
|
||||||
await models.WorkerTimeControl.destroyAll({
|
await models.WorkerTimeControl.destroyAll({
|
||||||
|
@ -105,13 +100,38 @@ module.exports = Self => {
|
||||||
updated: Date.vnNew(), state: 'SENDED'
|
updated: Date.vnNew(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]);
|
stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.userFk WHERE userFk IS NOT NULL');
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeControl_calculate(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeBusiness_calculate(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeControl_getError(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(`INSERT INTO mail (receiver, subject, body)
|
||||||
|
SELECT CONCAT(u.name, '@verdnatura.es'),
|
||||||
|
CONCAT('Error registro de horas semana ', ?, ' año ', ?) ,
|
||||||
|
CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('<br>', w.id, ' ', w.firstName, ' ', w.lastName)))
|
||||||
|
FROM tmp.timeControlError tce
|
||||||
|
JOIN vn.workerTimeControl wtc ON wtc.id = tce.id
|
||||||
|
JOIN worker w ON w.id = wtc.userFK
|
||||||
|
JOIN account.user u ON u.id = w.bossFk
|
||||||
|
GROUP BY w.bossFk`, [args.week, args.year]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
SELECT CONCAT(u.name, '@verdnatura.es') receiver,
|
SELECT CONCAT(u.name, '@verdnatura.es') receiver,
|
||||||
u.id workerFk,
|
u.id workerFk,
|
||||||
|
@ -131,20 +151,16 @@ module.exports = Self => {
|
||||||
JOIN business b ON b.id = tb.businessFk
|
JOIN business b ON b.id = tb.businessFk
|
||||||
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated
|
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated
|
||||||
LEFT JOIN worker w ON w.id = u.id
|
LEFT JOIN worker w ON w.id = u.id
|
||||||
JOIN (SELECT tb.userFk,
|
LEFT JOIN (
|
||||||
SUM(IF(tb.type IS NULL,
|
SELECT DISTINCT wtc.userFk
|
||||||
IF(tc.timeWorkDecimal > 0, FALSE, IF(tb.timeWorkDecimal > 0, TRUE, FALSE)),
|
FROM tmp.timeControlError tce
|
||||||
TRUE))isTeleworkingWeek
|
JOIN vn.workerTimeControl wtc ON wtc.id = tce.id
|
||||||
FROM tmp.timeBusinessCalculate tb
|
)sub ON sub.userFk = tb.userFk
|
||||||
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk
|
WHERE sub.userFK IS NULL
|
||||||
AND tc.dated = tb.dated
|
|
||||||
GROUP BY tb.userFk
|
|
||||||
HAVING isTeleworkingWeek > 0
|
|
||||||
)sub ON sub.userFk = u.id
|
|
||||||
WHERE d.hasToRefill
|
|
||||||
AND IFNULL(?, u.id) = u.id
|
AND IFNULL(?, u.id) = u.id
|
||||||
AND b.companyCodeFk = 'VNL'
|
AND b.companyCodeFk = 'VNL'
|
||||||
AND w.businessFk
|
AND w.businessFk
|
||||||
|
AND d.isTeleworking
|
||||||
ORDER BY u.id, tb.dated
|
ORDER BY u.id, tb.dated
|
||||||
`, [args.workerId]);
|
`, [args.workerId]);
|
||||||
const index = stmts.push(stmt) - 1;
|
const index = stmts.push(stmt) - 1;
|
||||||
|
@ -332,17 +348,18 @@ module.exports = Self => {
|
||||||
|
|
||||||
const lastDay = days[index][days[index].length - 1];
|
const lastDay = days[index][days[index].length - 1];
|
||||||
if (day.workerFk != previousWorkerFk || day == lastDay) {
|
if (day.workerFk != previousWorkerFk || day == lastDay) {
|
||||||
const salix = await models.Url.findOne({
|
const query = `INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week)
|
||||||
where: {
|
VALUES(?, ?, ?);`;
|
||||||
appName: 'salix',
|
await Self.rawSql(query, [previousWorkerFk, args.year, args.week]);
|
||||||
environment: process.env.NODE_ENV || 'dev'
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const timestamp = started.getTime() / 1000;
|
ctx.args = {
|
||||||
const url = `${salix.url}worker/${previousWorkerFk}/time-control?timestamp=${timestamp}`;
|
recipient: previousReceiver,
|
||||||
|
year: args.year,
|
||||||
await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, previousReceiver, args.week, args.year, url);
|
week: args.week,
|
||||||
|
workerId: previousWorkerFk,
|
||||||
|
state: 'SENDED'
|
||||||
|
};
|
||||||
|
await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions);
|
||||||
|
|
||||||
previousWorkerFk = day.workerFk;
|
previousWorkerFk = day.workerFk;
|
||||||
previousReceiver = day.receiver;
|
previousReceiver = day.receiver;
|
||||||
|
|
|
@ -1,120 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('workerTimeControl sendMail()', () => {
|
|
||||||
const workerId = 18;
|
|
||||||
const activeCtx = {
|
|
||||||
getLocale: () => {
|
|
||||||
return 'en';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const ctx = {req: activeCtx, args: {}};
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and with rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(8);
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(9);
|
|
||||||
expect(`${workerTimeControl[2].timed.getHours()}:${workerTimeControl[2].timed.getMinutes()}`).toEqual('9:20');
|
|
||||||
expect(workerTimeControl[3].timed.getHours()).toEqual(16);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and without rest', async() => {
|
|
||||||
const workdayOf20Hours = 3;
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `UPDATE business b
|
|
||||||
SET b.calendarTypeFk = ?
|
|
||||||
WHERE b.workerFk = ?; `;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(8);
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(12);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker with records in Journey and with rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id)
|
|
||||||
VALUES
|
|
||||||
(1, 1, '09:00:00', '13:00:00', ?),
|
|
||||||
(2, 1, '14:00:00', '19:00:00', ?);`;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(9);
|
|
||||||
expect(workerTimeControl[2].timed.getHours()).toEqual(10);
|
|
||||||
expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20');
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(13);
|
|
||||||
expect(workerTimeControl[4].timed.getHours()).toEqual(14);
|
|
||||||
expect(workerTimeControl[5].timed.getHours()).toEqual(19);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker with records in Journey and without rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id)
|
|
||||||
VALUES
|
|
||||||
(1, 1, '12:30:00', '14:00:00', ?);`;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(`${workerTimeControl[0].timed.getHours()}:${workerTimeControl[0].timed.getMinutes()}`).toEqual('12:30');
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(14);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -46,8 +46,12 @@ module.exports = Self => {
|
||||||
if (notAllowed)
|
if (notAllowed)
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
return targetTimeEntry.updateAttributes({
|
const timeEntryUpdated = await targetTimeEntry.updateAttributes({
|
||||||
direction: args.direction
|
direction: args.direction
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions);
|
||||||
|
|
||||||
|
return timeEntryUpdated;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,10 +47,6 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const isHimself = userId == args.workerId;
|
|
||||||
if (!isHimself)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
||||||
where: {
|
where: {
|
||||||
workerFk: args.workerId,
|
workerFk: args.workerId,
|
||||||
|
@ -69,6 +65,12 @@ module.exports = Self => {
|
||||||
reason: args.reason || null
|
reason: args.reason || null
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
if (args.state == 'SENDED') {
|
||||||
|
await workerTimeControlMail.updateAttributes({
|
||||||
|
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
||||||
|
}, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
const logRecord = {
|
const logRecord = {
|
||||||
originFk: args.workerId,
|
originFk: args.workerId,
|
||||||
userFk: userId,
|
userFk: userId,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const {Email} = require('vn-print');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
||||||
description: 'Sends the weekly hour record',
|
description: 'Sends the weekly hour record',
|
||||||
|
@ -22,7 +20,12 @@ module.exports = Self => {
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'url',
|
arg: 'workerId',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'state',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
@ -37,17 +40,48 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.weeklyHourRecordEmail = async(ctx, recipient, week, year, url) => {
|
Self.weeklyHourRecordEmail = async(ctx, options) => {
|
||||||
const params = {
|
const models = Self.app.models;
|
||||||
recipient: recipient,
|
const args = ctx.args;
|
||||||
lang: ctx.req.getLocale(),
|
const myOptions = {};
|
||||||
week: week,
|
|
||||||
year: year,
|
if (typeof options == 'object')
|
||||||
url: url
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const salix = await models.Url.findOne({
|
||||||
|
where: {
|
||||||
|
appName: 'salix',
|
||||||
|
environment: process.env.NODE_ENV || 'dev'
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const dated = getMondayDateFromYearWeek(args.year, args.week);
|
||||||
|
const timestamp = dated.getTime() / 1000;
|
||||||
|
|
||||||
|
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||||
|
ctx.args.url = url;
|
||||||
|
|
||||||
|
Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
|
|
||||||
|
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
const email = new Email('weekly-hour-record', params);
|
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||||
|
const yearStart = new Date(yearNumber, 0, 1);
|
||||||
|
const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000);
|
||||||
|
const firstMondayWeekNumber = getWeekNumber(firstMonday);
|
||||||
|
|
||||||
return email.send();
|
if (firstMondayWeekNumber > 1)
|
||||||
};
|
firstMonday.setDate(firstMonday.getDate() + 7);
|
||||||
|
|
||||||
|
firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7);
|
||||||
|
|
||||||
|
return firstMonday;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWeekNumber(date) {
|
||||||
|
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
|
||||||
|
const daysPassed = (date - firstDayOfYear) / 86400000;
|
||||||
|
return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,6 +53,9 @@
|
||||||
"Worker": {
|
"Worker": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"WorkerObservation": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"WorkerConfig": {
|
"WorkerConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
module.exports = function(Self) {
|
||||||
|
Self.validatesPresenceOf('text', {
|
||||||
|
message: 'Description cannot be blank'
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.observe('before save', async function(ctx) {
|
||||||
|
ctx.instance.created = new Date();
|
||||||
|
let token = ctx.options.accessToken;
|
||||||
|
let userId = token && token.userId;
|
||||||
|
ctx.instance.userFk = userId;
|
||||||
|
});
|
||||||
|
};
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"name": "WorkerObservation",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "workerObservation"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"id": true,
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"workerFk": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"userFk": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"worker": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Worker",
|
||||||
|
"foreignKey": "workerFk"
|
||||||
|
},
|
||||||
|
"user":{
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Account",
|
||||||
|
"foreignKey": "userFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,9 @@
|
||||||
},
|
},
|
||||||
"reason": {
|
"reason": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sendedCounter": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
|
|
|
@ -9,6 +9,7 @@ module.exports = Self => {
|
||||||
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
||||||
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
||||||
require('../methods/worker-time-control/getMailStates')(Self);
|
require('../methods/worker-time-control/getMailStates')(Self);
|
||||||
|
require('../methods/worker-time-control/resendWeeklyHourEmail')(Self);
|
||||||
|
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
if (err.code === 'ER_DUP_ENTRY')
|
if (err.code === 'ER_DUP_ENTRY')
|
||||||
|
|
|
@ -18,3 +18,6 @@ import './log';
|
||||||
import './dms/index';
|
import './dms/index';
|
||||||
import './dms/create';
|
import './dms/create';
|
||||||
import './dms/edit';
|
import './dms/edit';
|
||||||
|
import './note/index';
|
||||||
|
import './note/create';
|
||||||
|
|
||||||
|
|
|
@ -31,3 +31,5 @@ Deallocate PDA: Desasignar PDA
|
||||||
PDA deallocated: PDA desasignada
|
PDA deallocated: PDA desasignada
|
||||||
PDA allocated: PDA asignada
|
PDA allocated: PDA asignada
|
||||||
New PDA: Nueva PDA
|
New PDA: Nueva PDA
|
||||||
|
Notes: Notas
|
||||||
|
New note: Nueva nota
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<vn-watcher
|
||||||
|
vn-id="watcher"
|
||||||
|
url="WorkerObservations"
|
||||||
|
id-field="id"
|
||||||
|
data="$ctrl.note"
|
||||||
|
insert-mode="true"
|
||||||
|
form="form">
|
||||||
|
</vn-watcher>
|
||||||
|
<form name="form" ng-submit="watcher.submitGo('worker.card.note.index')" class="vn-w-md">
|
||||||
|
<vn-card class="vn-pa-lg">
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-textarea
|
||||||
|
vn-one
|
||||||
|
label="Note"
|
||||||
|
ng-model="$ctrl.note.text"
|
||||||
|
vn-focus>
|
||||||
|
</vn-textarea>
|
||||||
|
</vn-horizontal>
|
||||||
|
</vn-card>
|
||||||
|
<vn-button-bar>
|
||||||
|
<vn-submit
|
||||||
|
ng-if="watcher.dataChanged()"
|
||||||
|
label="Save">
|
||||||
|
</vn-submit>
|
||||||
|
<vn-button
|
||||||
|
ng-click="$ctrl.cancel()"
|
||||||
|
label="Cancel">
|
||||||
|
</vn-button>
|
||||||
|
</vn-button-bar>
|
||||||
|
</form>
|
|
@ -0,0 +1,21 @@
|
||||||
|
import ngModule from '../../module';
|
||||||
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
|
export default class Controller extends Section {
|
||||||
|
constructor($element, $) {
|
||||||
|
super($element, $);
|
||||||
|
this.note = {
|
||||||
|
workerFk: parseInt(this.$params.id),
|
||||||
|
text: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
this.$state.go('worker.card.note.index', {id: this.$params.id});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnNoteWorkerCreate', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller
|
||||||
|
});
|
|
@ -0,0 +1,22 @@
|
||||||
|
import './index';
|
||||||
|
|
||||||
|
describe('Worker', () => {
|
||||||
|
describe('Component vnNoteWorkerCreate', () => {
|
||||||
|
let $state;
|
||||||
|
let controller;
|
||||||
|
|
||||||
|
beforeEach(ngModule('worker'));
|
||||||
|
|
||||||
|
beforeEach(inject(($componentController, _$state_) => {
|
||||||
|
$state = _$state_;
|
||||||
|
$state.params.id = '1234';
|
||||||
|
const $element = angular.element('<vn-note-create></vn-note-create>');
|
||||||
|
controller = $componentController('vnNoteWorkerCreate', {$element, $state});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should define workerFk using $state.params.id', () => {
|
||||||
|
expect(controller.note.workerFk).toBe(1234);
|
||||||
|
expect(controller.note.worker).toBe(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,2 @@
|
||||||
|
New note: Nueva nota
|
||||||
|
Note: Nota
|
|
@ -0,0 +1,32 @@
|
||||||
|
<vn-crud-model
|
||||||
|
vn-id="model"
|
||||||
|
url="WorkerObservations"
|
||||||
|
filter="$ctrl.filter"
|
||||||
|
link="{workerFk: $ctrl.$params.id}"
|
||||||
|
include="{relation: 'user'}"
|
||||||
|
data="notes"
|
||||||
|
auto-load="true">
|
||||||
|
</vn-crud-model>
|
||||||
|
<vn-data-viewer
|
||||||
|
model="model"
|
||||||
|
class="vn-w-md">
|
||||||
|
<vn-card class="vn-pa-md">
|
||||||
|
<div
|
||||||
|
ng-repeat="note in notes"
|
||||||
|
class="note vn-pa-sm border-solid border-radius vn-mb-md">
|
||||||
|
<vn-horizontal class="vn-mb-sm" style="color: #666">
|
||||||
|
<vn-one>{{::note.user.nickname}}</vn-one>
|
||||||
|
<vn-auto>{{::note.created | date:'dd/MM/yyyy HH:mm'}}</vn-auto>
|
||||||
|
</vn-horizontal>
|
||||||
|
<vn-horizontal class="text">
|
||||||
|
{{::note.text}}
|
||||||
|
</vn-horizontal>
|
||||||
|
</div>
|
||||||
|
</vn-card>
|
||||||
|
</vn-data-viewer>
|
||||||
|
<a vn-tooltip="New note"
|
||||||
|
ui-sref="worker.card.note.create({id: $ctrl.$params.id})"
|
||||||
|
vn-bind="+"
|
||||||
|
fixed-bottom-right>
|
||||||
|
<vn-float-button icon="add"></vn-float-button>
|
||||||
|
</a>
|
|
@ -0,0 +1,22 @@
|
||||||
|
import ngModule from '../../module';
|
||||||
|
import Section from 'salix/components/section';
|
||||||
|
import './style.scss';
|
||||||
|
|
||||||
|
export default class Controller extends Section {
|
||||||
|
constructor($element, $) {
|
||||||
|
super($element, $);
|
||||||
|
this.filter = {
|
||||||
|
order: 'created DESC',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.$inject = ['$element', '$scope'];
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnWorkerNote', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller,
|
||||||
|
bindings: {
|
||||||
|
worker: '<'
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
vn-worker-note {
|
||||||
|
.note:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,6 +11,7 @@
|
||||||
],
|
],
|
||||||
"card": [
|
"card": [
|
||||||
{"state": "worker.card.basicData", "icon": "settings"},
|
{"state": "worker.card.basicData", "icon": "settings"},
|
||||||
|
{"state": "worker.card.note.index", "icon": "insert_drive_file"},
|
||||||
{"state": "worker.card.timeControl", "icon": "access_time"},
|
{"state": "worker.card.timeControl", "icon": "access_time"},
|
||||||
{"state": "worker.card.calendar", "icon": "icon-calendar"},
|
{"state": "worker.card.calendar", "icon": "icon-calendar"},
|
||||||
{"state": "worker.card.pda", "icon": "phone_android"},
|
{"state": "worker.card.pda", "icon": "phone_android"},
|
||||||
|
@ -72,6 +73,24 @@
|
||||||
"component": "vn-worker-log",
|
"component": "vn-worker-log",
|
||||||
"description": "Log",
|
"description": "Log",
|
||||||
"acl": ["salesAssistant"]
|
"acl": ["salesAssistant"]
|
||||||
|
}, {
|
||||||
|
"url": "/note",
|
||||||
|
"state": "worker.card.note",
|
||||||
|
"component": "ui-view",
|
||||||
|
"abstract": true
|
||||||
|
}, {
|
||||||
|
"url": "/index",
|
||||||
|
"state": "worker.card.note.index",
|
||||||
|
"component": "vn-worker-note",
|
||||||
|
"description": "Notes",
|
||||||
|
"params": {
|
||||||
|
"worker": "$ctrl.worker"
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
"url": "/create",
|
||||||
|
"state": "worker.card.note.create",
|
||||||
|
"component": "vn-note-worker-create",
|
||||||
|
"description": "New note"
|
||||||
}, {
|
}, {
|
||||||
"url": "/pbx",
|
"url": "/pbx",
|
||||||
"state": "worker.card.pbx",
|
"state": "worker.card.pbx",
|
||||||
|
|
|
@ -204,7 +204,7 @@
|
||||||
vn-id="sendEmailConfirmation"
|
vn-id="sendEmailConfirmation"
|
||||||
on-accept="$ctrl.resendEmail()"
|
on-accept="$ctrl.resendEmail()"
|
||||||
message="Send time control email">
|
message="Send time control email">
|
||||||
<tpl-body style="min-width: 500px;">
|
<tpl-body>
|
||||||
<span translate>Are you sure you want to send it?</span>
|
<span translate>Are you sure you want to send it?</span>
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
|
|
|
@ -303,7 +303,10 @@ class Controller extends Section {
|
||||||
|
|
||||||
const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`;
|
const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`;
|
||||||
this.$http.post(query, entry)
|
this.$http.post(query, entry)
|
||||||
.then(() => this.fetchHours());
|
.then(() => {
|
||||||
|
this.fetchHours();
|
||||||
|
this.getMailStates(this.date);
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
return false;
|
return false;
|
||||||
|
@ -324,6 +327,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
this.$http.post(`WorkerTimeControls/${entryId}/deleteTimeEntry`).then(() => {
|
this.$http.post(`WorkerTimeControls/${entryId}/deleteTimeEntry`).then(() => {
|
||||||
this.fetchHours();
|
this.fetchHours();
|
||||||
|
this.getMailStates(this.date);
|
||||||
this.vnApp.showSuccess(this.$t('Entry removed'));
|
this.vnApp.showSuccess(this.$t('Entry removed'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -395,23 +399,24 @@ class Controller extends Section {
|
||||||
this.$http.post(query, {direction: entry.direction})
|
this.$http.post(query, {direction: entry.direction})
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||||
.then(() => this.$.editEntry.hide())
|
.then(() => this.$.editEntry.hide())
|
||||||
.then(() => this.fetchHours());
|
.then(() => this.fetchHours())
|
||||||
|
.then(() => this.getMailStates(this.date));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resendEmail() {
|
resendEmail() {
|
||||||
const timestamp = this.date.getTime() / 1000;
|
|
||||||
const url = `${window.location.origin}/#!/worker/${this.worker.id}/time-control?timestamp=${timestamp}`;
|
|
||||||
const params = {
|
const params = {
|
||||||
recipient: this.worker.user.emailUser.email,
|
recipient: this.worker.user.emailUser.email,
|
||||||
week: this.weekNumber,
|
week: this.weekNumber,
|
||||||
year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
url: url,
|
workerId: this.worker.id,
|
||||||
|
state: 'SENDED'
|
||||||
};
|
};
|
||||||
this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params)
|
this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.getMailStates(this.date);
|
||||||
this.vnApp.showSuccess(this.$t('Email sended'));
|
this.vnApp.showSuccess(this.$t('Email sended'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,13 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
|
|
||||||
describe('save() ', () => {
|
describe('save() ', () => {
|
||||||
it(`should make a query an then call to the fetchHours() method`, () => {
|
it(`should make a query an then call to the fetchHours() method`, () => {
|
||||||
|
const today = Date.vnNew();
|
||||||
|
|
||||||
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
|
|
||||||
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
controller.date = today;
|
||||||
controller.fetchHours = jest.fn();
|
controller.fetchHours = jest.fn();
|
||||||
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
||||||
controller.$.editEntry = {
|
controller.$.editEntry = {
|
||||||
|
@ -240,7 +247,9 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
describe('resendEmail() ', () => {
|
describe('resendEmail() ', () => {
|
||||||
it(`should make a query an then call showSuccess method`, () => {
|
it(`should make a query an then call showSuccess method`, () => {
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
|
|
||||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salix-back",
|
"name": "salix-back",
|
||||||
"version": "23.14.01",
|
"version": "23.16.01",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "Salix backend",
|
"description": "Salix backend",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
|
@ -12,7 +12,7 @@ SELECT ep.id palletFk,
|
||||||
JOIN vn.expedition e ON e.id = es.expeditionFk
|
JOIN vn.expedition e ON e.id = es.expeditionFk
|
||||||
JOIN vn.ticket t ON t.id = e.ticketFk
|
JOIN vn.ticket t ON t.id = e.ticketFk
|
||||||
JOIN vn.route r ON r.id = t.routeFk
|
JOIN vn.route r ON r.id = t.routeFk
|
||||||
LEFT JOIN vn2008.Rutas_monitor rm ON rm.Id_Ruta = r.id
|
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id
|
||||||
LEFT JOIN vn.expeditionTruck et2 ON et2.id = rm.expeditionTruckFk
|
LEFT JOIN vn.expeditionTruck et2 ON et2.id = rm.expeditionTruckFk
|
||||||
WHERE ep.id = ?
|
WHERE ep.id = ?
|
||||||
GROUP BY ep.id, t.routeFk
|
GROUP BY ep.id, t.routeFk
|
||||||
|
|
Loading…
Reference in New Issue