Merge branch 'dev' into 4590-Refactor-isBox-freightItemFk
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
commit
8b07180890
|
@ -0,0 +1,58 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('privileges', {
|
||||||
|
description: 'Change role and hasGrant if user has privileges',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The user id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'roleFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The new role for user',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'hasGrant',
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Whether to has grant'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: `/:id/privileges`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.privileges = async function(ctx, id, roleFk, hasGrant, options) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const user = await models.Account.findById(userId, null, myOptions);
|
||||||
|
|
||||||
|
if (!user.hasGrant)
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
const userToUpdate = await models.Account.findById(id);
|
||||||
|
if (hasGrant != null)
|
||||||
|
return await userToUpdate.updateAttribute('hasGrant', hasGrant, myOptions);
|
||||||
|
if (!roleFk) return;
|
||||||
|
|
||||||
|
const role = await models.Role.findById(roleFk, null, myOptions);
|
||||||
|
const hasRole = await models.Account.hasRole(userId, role.name, myOptions);
|
||||||
|
|
||||||
|
if (!hasRole)
|
||||||
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
|
await userToUpdate.updateAttribute('roleFk', roleFk, myOptions);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,99 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('account privileges()', () => {
|
||||||
|
const employeeId = 1;
|
||||||
|
const developerId = 9;
|
||||||
|
const sysadminId = 66;
|
||||||
|
const bruceWayneId = 1101;
|
||||||
|
|
||||||
|
it('should throw an error when user not has privileges', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: developerId}}};
|
||||||
|
const tx = await models.Account.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
await models.Account.privileges(ctx, employeeId, null, true, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toContain(`You don't have enough privileges`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when user has privileges but not has the role', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: sysadminId}}};
|
||||||
|
const tx = await models.Account.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const root = await models.Role.findOne({
|
||||||
|
where: {
|
||||||
|
name: 'root'
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
await models.Account.privileges(ctx, employeeId, root.id, null, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toContain(`You don't have enough privileges`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change role', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: sysadminId}}};
|
||||||
|
const tx = await models.Account.beginTransaction({});
|
||||||
|
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const agency = await models.Role.findOne({
|
||||||
|
where: {
|
||||||
|
name: 'agency'
|
||||||
|
}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
let error;
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
await models.Account.privileges(ctx, bruceWayneId, agency.id, null, options);
|
||||||
|
result = await models.Account.findById(bruceWayneId, null, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).not.toBeDefined();
|
||||||
|
expect(result.roleFk).toEqual(agency.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change hasGrant', async() => {
|
||||||
|
const ctx = {req: {accessToken: {userId: sysadminId}}};
|
||||||
|
const tx = await models.Account.beginTransaction({});
|
||||||
|
|
||||||
|
let error;
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
await models.Account.privileges(ctx, bruceWayneId, null, true, options);
|
||||||
|
result = await models.Account.findById(bruceWayneId, null, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error).not.toBeDefined();
|
||||||
|
expect(result.hasGrant).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -17,14 +17,16 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deleteTrashFiles = async options => {
|
Self.deleteTrashFiles = async options => {
|
||||||
const tx = await Self.beginTransaction({});
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction)
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (process.env.NODE_ENV == 'test')
|
if (process.env.NODE_ENV == 'test')
|
||||||
|
@ -61,10 +63,9 @@ module.exports = Self => {
|
||||||
const dstFolder = path.join(dmsContainer.client.root, pathHash);
|
const dstFolder = path.join(dmsContainer.client.root, pathHash);
|
||||||
try {
|
try {
|
||||||
await fs.rmdir(dstFolder);
|
await fs.rmdir(dstFolder);
|
||||||
await dms.destroy(myOptions);
|
} catch (err) {}
|
||||||
} catch (err) {
|
|
||||||
await dms.destroy(myOptions);
|
await dms.destroy(myOptions);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('osTicketReportEmail', {
|
||||||
|
description: 'Sends the buyer waste email',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/osticket-report-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.osTicketReportEmail = async ctx => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const printConfig = await models.PrintConfig.findOne();
|
||||||
|
|
||||||
|
const email = new Email('osticket-report', {
|
||||||
|
recipient: printConfig.itRecipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
});
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -121,6 +121,9 @@
|
||||||
},
|
},
|
||||||
"Edi": {
|
"Edi": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"PrintConfig": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
||||||
require('../methods/account/change-password')(Self);
|
require('../methods/account/change-password')(Self);
|
||||||
require('../methods/account/set-password')(Self);
|
require('../methods/account/set-password')(Self);
|
||||||
require('../methods/account/validate-token')(Self);
|
require('../methods/account/validate-token')(Self);
|
||||||
|
require('../methods/account/privileges')(Self);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@
|
||||||
},
|
},
|
||||||
"image": {
|
"image": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"hasGrant": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
require('../methods/osticket/osTicketReportEmail')(Self);
|
||||||
require('../methods/osticket/closeTicket')(Self);
|
require('../methods/osticket/closeTicket')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "OsTicket",
|
"name": "OsTicket",
|
||||||
"base": "VnModel",
|
"base": "VnModel"
|
||||||
"acls": [{
|
|
||||||
"property": "validations",
|
|
||||||
"accessType": "EXECUTE",
|
|
||||||
"principalType": "ROLE",
|
|
||||||
"principalId": "$everyone",
|
|
||||||
"permission": "ALLOW"
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "PrintConfig",
|
||||||
|
"description": "Print config",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "salix.printConfig"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"id": true,
|
||||||
|
"type": "number",
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"itRecipient": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"incidencesEmail": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acls": [{
|
||||||
|
"accessType": "READ",
|
||||||
|
"principalType": "ROLE",
|
||||||
|
"principalId": "$everyone",
|
||||||
|
"permission": "ALLOW"
|
||||||
|
}]
|
||||||
|
}
|
|
@ -7,13 +7,18 @@ process.on('warning', warning => {
|
||||||
console.log(warning.stack);
|
console.log(warning.stack);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
process.on('exit', async function() {
|
||||||
|
if (container) await container.rm();
|
||||||
|
});
|
||||||
|
|
||||||
|
let container;
|
||||||
async function test() {
|
async function test() {
|
||||||
let isCI = false;
|
let isCI = false;
|
||||||
|
|
||||||
if (process.argv[2] === 'ci')
|
if (process.argv[2] === 'ci')
|
||||||
isCI = true;
|
isCI = true;
|
||||||
|
|
||||||
const container = new Docker();
|
container = new Docker();
|
||||||
|
|
||||||
await container.run(isCI);
|
await container.run(isCI);
|
||||||
dataSources = JSON.parse(JSON.stringify(dataSources));
|
dataSources = JSON.parse(JSON.stringify(dataSources));
|
||||||
|
@ -46,6 +51,7 @@ async function test() {
|
||||||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||||
|
|
||||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||||
|
jasmine.exitOnCompletion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const backSpecs = [
|
const backSpecs = [
|
||||||
|
@ -60,11 +66,10 @@ async function test() {
|
||||||
helpers: [],
|
helpers: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
jasmine.exitOnCompletion = false;
|
|
||||||
await jasmine.execute();
|
await jasmine.execute();
|
||||||
if (app) await app.disconnect();
|
if (app) await app.disconnect();
|
||||||
if (container) await container.rm();
|
if (container) await container.rm();
|
||||||
console.log('app disconnected & container removed');
|
console.log('App disconnected & container removed');
|
||||||
}
|
}
|
||||||
|
|
||||||
test();
|
test();
|
||||||
|
|
|
@ -1,3 +1,48 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('ClientConsumptionQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'deliveryNotePdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'deliveryNoteEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'deliveryNoteCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'deliveryNoteCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'clientWelcomeHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'clientWelcomeEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'creditRequestPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'creditRequestHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'creditRequestEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'printerSetupHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'printerSetupEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'sepaCoreEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'letterDebtorPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'letterDebtorStHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'letterDebtorStEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'letterDebtorNdHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'letterDebtorNdEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'clientDebtStatementPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'clientDebtStatementHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'clientDebtStatementEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'incotermsAuthorizationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'incotermsAuthorizationHtml', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'incotermsAuthorizationEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Client', 'consumptionSendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'),
|
||||||
|
('InvoiceOut', 'invoiceEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('InvoiceOut', 'exportationPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('InvoiceOut', 'sendQueued', 'WRITE', 'ALLOW', 'ROLE', 'system'),
|
||||||
|
('Ticket', 'invoiceCsvPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Ticket', 'invoiceCsvEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Supplier', 'campaignMetricsPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Supplier', 'campaignMetricsEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Travel', 'extraCommunityPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Travel', 'extraCommunityEmail', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Entry', 'entryOrderPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('OsTicket', 'osTicketReportEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'),
|
||||||
|
('Item', 'buyerWasteEmail', 'WRITE', 'ALLOW', 'ROLE', 'system'),
|
||||||
|
('Claim', 'claimPickupPdf', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('Claim', 'claimPickupEmail', 'WRITE', 'ALLOW', 'ROLE', 'claimManager'),
|
||||||
|
('Item', 'labelPdf', 'READ', 'ALLOW', 'ROLE', 'employee');
|
||||||
|
|
||||||
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
||||||
VALUES ('Sector','*','READ','ALLOW','ROLE','employee');
|
VALUES ('Sector','*','READ','ALLOW','ROLE','employee');
|
||||||
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
create table `vn`.`clientConsumptionQueue`
|
||||||
|
(
|
||||||
|
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
params json not null,
|
||||||
|
queued datetime default current_timestamp() not null,
|
||||||
|
printed datetime null,
|
||||||
|
status varchar(50) default '' null
|
||||||
|
)
|
||||||
|
comment 'Queue for client consumption PDF mailing';
|
|
@ -0,0 +1 @@
|
||||||
|
rename table `vn`.`invoiceOut_queue` to `vn`.`invoiceOutQueue`;
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE `vn`.`itemConfig`
|
||||||
|
ADD id int null PRIMARY KEY first;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`itemConfig`
|
||||||
|
ADD wasteRecipients VARCHAR(50) NOT NULL comment 'Weekly waste report schedule recipients';
|
|
@ -0,0 +1,10 @@
|
||||||
|
create table `salix`.`printConfig`
|
||||||
|
(
|
||||||
|
id int auto_increment,
|
||||||
|
itRecipient varchar(50) null comment 'IT recipients for report mailing',
|
||||||
|
incidencesEmail varchar(50) null comment 'CAU destinatary email',
|
||||||
|
constraint printConfig_pk
|
||||||
|
primary key (id)
|
||||||
|
)
|
||||||
|
comment 'Print service config';
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
alter table `vn`.`sample`
|
||||||
|
add model VARCHAR(25) null comment 'Model name in plural';
|
||||||
|
|
||||||
|
UPDATE vn.sample t
|
||||||
|
SET t.model = 'Clients'
|
||||||
|
WHERE t.id IN(12, 13, 14, 15, 16, 18, 19, 20);
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE `account`.`user` ADD hasGrant TINYINT(1) NOT NULL;
|
22
db/docker.js
22
db/docker.js
|
@ -19,8 +19,9 @@ module.exports = class Docker {
|
||||||
* to avoid a bug with OverlayFS driver on MacOS.
|
* to avoid a bug with OverlayFS driver on MacOS.
|
||||||
*
|
*
|
||||||
* @param {Boolean} ci continuous integration environment argument
|
* @param {Boolean} ci continuous integration environment argument
|
||||||
|
* @param {String} networkName Name of the container network
|
||||||
*/
|
*/
|
||||||
async run(ci) {
|
async run(ci, networkName = 'jenkins') {
|
||||||
let d = new Date();
|
let d = new Date();
|
||||||
let pad = v => v < 10 ? '0' + v : v;
|
let pad = v => v < 10 ? '0' + v : v;
|
||||||
let stamp = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
let stamp = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||||
|
@ -42,8 +43,16 @@ module.exports = class Docker {
|
||||||
|
|
||||||
let runChown = process.platform != 'linux';
|
let runChown = process.platform != 'linux';
|
||||||
|
|
||||||
|
let network = '';
|
||||||
|
if (ci) network = `--network="${networkName}"`;
|
||||||
|
|
||||||
log('Starting container...');
|
log('Starting container...');
|
||||||
const container = await this.execP(`docker run --env RUN_CHOWN=${runChown} -d ${dockerArgs} salix-db`);
|
const container = await this.execP(`
|
||||||
|
docker run \
|
||||||
|
${network} \
|
||||||
|
--env RUN_CHOWN=${runChown} \
|
||||||
|
-d ${dockerArgs} salix-db
|
||||||
|
`);
|
||||||
this.id = container.stdout.trim();
|
this.id = container.stdout.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -51,10 +60,11 @@ module.exports = class Docker {
|
||||||
let inspect = await this.execP(`docker inspect -f "{{json .NetworkSettings}}" ${this.id}`);
|
let inspect = await this.execP(`docker inspect -f "{{json .NetworkSettings}}" ${this.id}`);
|
||||||
let netSettings = JSON.parse(inspect.stdout);
|
let netSettings = JSON.parse(inspect.stdout);
|
||||||
|
|
||||||
if (ci)
|
if (ci) {
|
||||||
this.dbConf.host = netSettings.Gateway;
|
this.dbConf.host = netSettings.Networks[networkName].IPAddress;
|
||||||
|
this.dbConf.port = 3306;
|
||||||
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
} else
|
||||||
|
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.wait();
|
await this.wait();
|
||||||
|
|
|
@ -13,6 +13,10 @@ INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`)
|
||||||
VALUES
|
VALUES
|
||||||
('DEFAULT_TOKEN', '1209600', util.VN_CURDATE(), 66);
|
('DEFAULT_TOKEN', '1209600', util.VN_CURDATE(), 66);
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`printConfig` (`id`, `itRecipient`, `incidencesEmail`)
|
||||||
|
VALUES
|
||||||
|
(1, 'it@gotamcity.com', 'incidences@gotamcity.com');
|
||||||
|
|
||||||
INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`)
|
INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`)
|
||||||
VALUES
|
VALUES
|
||||||
('1', '6');
|
('1', '6');
|
||||||
|
@ -916,16 +920,19 @@ INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`)
|
||||||
|
|
||||||
INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `itemFk`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`)
|
INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `itemFk`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 15, 1, 18, 'UR9000006041', 94, 1),
|
(1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 15, 1, 18, 'UR9000006041', 94, 1),
|
||||||
(2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 16, 2, 18, 'UR9000006041', 94, 1),
|
(2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 16, 2, 18, 'UR9000006041', 94, 1),
|
||||||
(3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 3, 18, 'UR9000006041', 94, 2),
|
(3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 3, 18, 'UR9000006041', 94, 2),
|
||||||
(4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 4, 18, 'UR9000006041', 94, 2),
|
(4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 4, 18, 'UR9000006041', 94, 2),
|
||||||
(5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 3),
|
(5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||||
(6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 1, 18, NULL, 94, 3),
|
(6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), NULL, 1, 18, NULL, 94, 3),
|
||||||
(7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, 1, 18, NULL, 94, NULL),
|
(7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), NULL, 1, 18, NULL, 94, NULL),
|
||||||
(8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, 1, 18, NULL, 94, 1),
|
(8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), NULL, 1, 18, NULL, 94, 1),
|
||||||
(9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 2),
|
(9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), NULL, 1, 18, NULL, 94, 2),
|
||||||
(10, 7, 7, 71, NOW(), NULL, 1, 18, NULL, 94, 3);
|
(10, 7, 7, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||||
|
(11, 7, 8, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||||
|
(12, 7, 9, 71, NOW(), NULL, 1, 18, NULL, 94, 3),
|
||||||
|
(13, 1, 10, 71, NOW(), NULL, 1, 18, NULL, 94, 3);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`)
|
INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`)
|
||||||
|
@ -1778,6 +1785,11 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
||||||
(1, 31, 4, 21, 2),
|
(1, 31, 4, 21, 2),
|
||||||
(2, 32, 3, 21, 3);
|
(2, 32, 3, 21, 3);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`claimConfig`(`id`, `pickupContact`, `maxResponsibility`)
|
||||||
|
VALUES
|
||||||
|
(1, 'Contact description', 50),
|
||||||
|
(2, 'Contact description', 30);
|
||||||
|
|
||||||
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
|
INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `secretKey`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
|
(1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
|
||||||
|
@ -2651,3 +2663,7 @@ INSERT INTO `vn`.`collection` (`id`, `created`, `workerFk`, `stateFk`, `itemPack
|
||||||
INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`)
|
INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `created`, `level`, `wagon`, `smartTagFk`, `usedShelves`, `itemCount`, `liters`)
|
||||||
VALUES
|
VALUES
|
||||||
(9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL);
|
(9, 3, util.VN_NOW(), NULL, 0, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
UPDATE `account`.`user`
|
||||||
|
SET `hasGrant` = 1
|
||||||
|
WHERE `id` = 66;
|
||||||
|
|
|
@ -51,14 +51,12 @@ export default {
|
||||||
accountDescriptor: {
|
accountDescriptor: {
|
||||||
menuButton: 'vn-user-descriptor vn-icon-button[icon="more_vert"]',
|
menuButton: 'vn-user-descriptor vn-icon-button[icon="more_vert"]',
|
||||||
deleteAccount: '.vn-menu [name="deleteUser"]',
|
deleteAccount: '.vn-menu [name="deleteUser"]',
|
||||||
changeRole: '.vn-menu [name="changeRole"]',
|
|
||||||
setPassword: '.vn-menu [name="setPassword"]',
|
setPassword: '.vn-menu [name="setPassword"]',
|
||||||
activateAccount: '.vn-menu [name="enableAccount"]',
|
activateAccount: '.vn-menu [name="enableAccount"]',
|
||||||
activateUser: '.vn-menu [name="activateUser"]',
|
activateUser: '.vn-menu [name="activateUser"]',
|
||||||
deactivateUser: '.vn-menu [name="deactivateUser"]',
|
deactivateUser: '.vn-menu [name="deactivateUser"]',
|
||||||
newPassword: 'vn-textfield[ng-model="$ctrl.newPassword"]',
|
newPassword: 'vn-textfield[ng-model="$ctrl.newPassword"]',
|
||||||
repeatPassword: 'vn-textfield[ng-model="$ctrl.repeatPassword"]',
|
repeatPassword: 'vn-textfield[ng-model="$ctrl.repeatPassword"]',
|
||||||
newRole: 'vn-autocomplete[ng-model="$ctrl.newRole"]',
|
|
||||||
activeAccountIcon: 'vn-icon[icon="contact_mail"]',
|
activeAccountIcon: 'vn-icon[icon="contact_mail"]',
|
||||||
activeUserIcon: 'vn-icon[icon="icon-disabled"]',
|
activeUserIcon: 'vn-icon[icon="icon-disabled"]',
|
||||||
acceptButton: 'button[response="accept"]',
|
acceptButton: 'button[response="accept"]',
|
||||||
|
@ -143,6 +141,11 @@ export default {
|
||||||
verifyCert: 'vn-account-samba vn-check[ng-model="$ctrl.config.verifyCert"]',
|
verifyCert: 'vn-account-samba vn-check[ng-model="$ctrl.config.verifyCert"]',
|
||||||
save: 'vn-account-samba vn-submit'
|
save: 'vn-account-samba vn-submit'
|
||||||
},
|
},
|
||||||
|
accountPrivileges: {
|
||||||
|
checkHasGrant: 'vn-user-privileges vn-check[ng-model="$ctrl.user.hasGrant"]',
|
||||||
|
role: 'vn-user-privileges vn-autocomplete[ng-model="$ctrl.user.roleFk"]',
|
||||||
|
save: 'vn-user-privileges vn-submit'
|
||||||
|
},
|
||||||
clientsIndex: {
|
clientsIndex: {
|
||||||
createClientButton: `vn-float-button`
|
createClientButton: `vn-float-button`
|
||||||
},
|
},
|
||||||
|
@ -391,7 +394,7 @@ export default {
|
||||||
intrastadCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Intrastat"]',
|
intrastadCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Intrastat"]',
|
||||||
originCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Origin"]',
|
originCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Origin"]',
|
||||||
buyerCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Buyer"]',
|
buyerCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Buyer"]',
|
||||||
densityCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Density"]',
|
weightByPieceCheckbox: '.vn-popover.shown vn-horizontal:nth-child(3) > vn-check[label="Weight/Piece"]',
|
||||||
saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button'
|
saveFieldsButton: '.vn-popover.shown vn-button[label="Save"] > button'
|
||||||
},
|
},
|
||||||
itemFixedPrice: {
|
itemFixedPrice: {
|
||||||
|
@ -835,14 +838,16 @@ export default {
|
||||||
confirmButton: '.vn-confirm.shown button[response="accept"]',
|
confirmButton: '.vn-confirm.shown button[response="accept"]',
|
||||||
},
|
},
|
||||||
routeIndex: {
|
routeIndex: {
|
||||||
anyResult: 'vn-table a',
|
anyResult: 'vn-route-index tbody > tr',
|
||||||
firstRouteCheckbox: 'a:nth-child(1) vn-td:nth-child(1) > vn-check',
|
firstRouteCheckbox: 'vn-route-index tbody > tr:nth-child(1) > td:nth-child(1) > vn-check',
|
||||||
addNewRouteButton: 'vn-route-index a[ui-sref="route.create"]',
|
addNewRouteButton: 'vn-route-index a[ui-sref="route.create"]',
|
||||||
cloneButton: 'vn-route-index button > vn-icon[icon="icon-clone"]',
|
cloneButton: 'vn-route-index button > vn-icon[icon="icon-clone"]',
|
||||||
submitClonationButton: 'tpl-buttons > button[response="accept"]',
|
submitClonationButton: 'tpl-buttons > button[response="accept"]',
|
||||||
openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
|
openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
|
||||||
searchAgencyAutocomlete: 'vn-route-search-panel vn-autocomplete[ng-model="filter.agencyModeFk"]',
|
searchAgencyAutocomlete: 'vn-route-search-panel vn-autocomplete[ng-model="filter.agencyModeFk"]',
|
||||||
advancedSearchButton: 'vn-route-search-panel button[type=submit]',
|
advancedSearchButton: 'vn-route-search-panel button[type=submit]',
|
||||||
|
previewButton: 'vn-route-index tbody > tr:nth-child(7) > td:nth-child(11) > vn-icon-button[icon="preview"]',
|
||||||
|
|
||||||
},
|
},
|
||||||
createRouteView: {
|
createRouteView: {
|
||||||
worker: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
worker: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
||||||
|
@ -862,6 +867,8 @@ export default {
|
||||||
firstTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor',
|
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(3) > span',
|
||||||
firstClientDescriptor: '.vn-popover.shown vn-client-descriptor',
|
firstClientDescriptor: '.vn-popover.shown vn-client-descriptor',
|
||||||
|
goToRouteSummaryButton: 'vn-route-summary > vn-card > h5 > a',
|
||||||
|
|
||||||
},
|
},
|
||||||
routeBasicData: {
|
routeBasicData: {
|
||||||
worker: 'vn-route-basic-data vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
worker: 'vn-route-basic-data vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
||||||
|
@ -1015,8 +1022,8 @@ export default {
|
||||||
},
|
},
|
||||||
travelExtraCommunity: {
|
travelExtraCommunity: {
|
||||||
anySearchResult: 'vn-travel-extra-community > vn-card div > tbody > tr[ng-attr-id="{{::travel.id}}"]',
|
anySearchResult: 'vn-travel-extra-community > vn-card div > tbody > tr[ng-attr-id="{{::travel.id}}"]',
|
||||||
firstTravelReference: 'vn-travel-extra-community tbody:nth-child(2) vn-textfield[ng-model="travel.ref"]',
|
firstTravelReference: 'vn-travel-extra-community tbody:nth-child(2) vn-td-editable[name="reference"]',
|
||||||
firstTravelLockedKg: 'vn-travel-extra-community tbody:nth-child(2) vn-input-number[ng-model="travel.kg"]',
|
firstTravelLockedKg: 'vn-travel-extra-community tbody:nth-child(2) vn-td-editable[name="lockedKg"]',
|
||||||
removeContinentFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(3) > vn-icon > i'
|
removeContinentFilter: 'vn-searchbar > form > vn-textfield > div.container > div.prepend > prepend > div > span:nth-child(3) > vn-icon > i'
|
||||||
},
|
},
|
||||||
travelBasicData: {
|
travelBasicData: {
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('Client Edit web access path', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
browser = await getBrowser();
|
browser = await getBrowser();
|
||||||
page = browser.page;
|
page = browser.page;
|
||||||
await page.loginAndModule('employee', 'client');
|
await page.loginAndModule('salesPerson', 'client');
|
||||||
await page.accessToSearchResult('max');
|
await page.accessToSearchResult('max');
|
||||||
await page.accessToSection('client.card.webAccess');
|
await page.accessToSection('client.card.webAccess');
|
||||||
});
|
});
|
||||||
|
|
|
@ -31,7 +31,7 @@ describe('Item index path', () => {
|
||||||
await page.waitToClick(selectors.itemsIndex.intrastadCheckbox);
|
await page.waitToClick(selectors.itemsIndex.intrastadCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.originCheckbox);
|
await page.waitToClick(selectors.itemsIndex.originCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.densityCheckbox);
|
await page.waitToClick(selectors.itemsIndex.weightByPieceCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ describe('Item index path', () => {
|
||||||
await page.waitToClick(selectors.itemsIndex.intrastadCheckbox);
|
await page.waitToClick(selectors.itemsIndex.intrastadCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.originCheckbox);
|
await page.waitToClick(selectors.itemsIndex.originCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.densityCheckbox);
|
await page.waitToClick(selectors.itemsIndex.weightByPieceCheckbox);
|
||||||
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ describe('Route summary path', () => {
|
||||||
browser = await getBrowser();
|
browser = await getBrowser();
|
||||||
page = browser.page;
|
page = browser.page;
|
||||||
await page.loginAndModule('employee', 'route');
|
await page.loginAndModule('employee', 'route');
|
||||||
await page.waitToClick('vn-route-index vn-tbody > a:nth-child(7)');
|
await page.waitToClick(selectors.routeIndex.previewButton);
|
||||||
|
await page.waitToClick(selectors.routeSummary.goToRouteSummaryButton);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async() => {
|
afterAll(async() => {
|
||||||
|
@ -34,6 +35,8 @@ describe('Route summary path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should click on the first ticket ID making the descriptor popover visible', async() => {
|
it('should click on the first ticket ID making the descriptor popover visible', async() => {
|
||||||
|
await page.waitForState('route.card.summary');
|
||||||
|
await page.waitForTimeout(250);
|
||||||
await page.waitToClick(selectors.routeSummary.firstTicketID);
|
await page.waitToClick(selectors.routeSummary.firstTicketID);
|
||||||
await page.waitForSelector(selectors.routeSummary.firstTicketDescriptor);
|
await page.waitForSelector(selectors.routeSummary.firstTicketDescriptor);
|
||||||
const visible = await page.isVisible(selectors.routeSummary.firstTicketDescriptor);
|
const visible = await page.isVisible(selectors.routeSummary.firstTicketDescriptor);
|
||||||
|
|
|
@ -19,10 +19,10 @@ describe('Travel extra community path', () => {
|
||||||
it('should edit the travel reference and the locked kilograms', async() => {
|
it('should edit the travel reference and the locked kilograms', async() => {
|
||||||
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
||||||
await page.waitForSpinnerLoad();
|
await page.waitForSpinnerLoad();
|
||||||
await page.clearInput(selectors.travelExtraCommunity.firstTravelReference);
|
await page.writeOnEditableTD(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
||||||
await page.write(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
await page.waitForSpinnerLoad();
|
||||||
await page.clearInput(selectors.travelExtraCommunity.firstTravelLockedKg);
|
await page.writeOnEditableTD(selectors.travelExtraCommunity.firstTravelLockedKg, '1500');
|
||||||
await page.write(selectors.travelExtraCommunity.firstTravelLockedKg, '1500');
|
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
expect(message.text).toContain('Data saved!');
|
||||||
|
@ -32,9 +32,9 @@ describe('Travel extra community path', () => {
|
||||||
await page.accessToSection('travel.index');
|
await page.accessToSection('travel.index');
|
||||||
await page.accessToSection('travel.extraCommunity');
|
await page.accessToSection('travel.extraCommunity');
|
||||||
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
||||||
|
await page.waitForTextInElement(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
||||||
const reference = await page.waitToGetProperty(selectors.travelExtraCommunity.firstTravelReference, 'value');
|
const reference = await page.getProperty(selectors.travelExtraCommunity.firstTravelReference, 'innerText');
|
||||||
const lockedKg = await page.waitToGetProperty(selectors.travelExtraCommunity.firstTravelLockedKg, 'value');
|
const lockedKg = await page.getProperty(selectors.travelExtraCommunity.firstTravelLockedKg, 'innerText');
|
||||||
|
|
||||||
expect(reference).toContain('edited reference');
|
expect(reference).toContain('edited reference');
|
||||||
expect(lockedKg).toContain(1500);
|
expect(lockedKg).toContain(1500);
|
||||||
|
|
|
@ -62,27 +62,6 @@ describe('Account create and basic data path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Descriptor option', () => {
|
describe('Descriptor option', () => {
|
||||||
describe('Edit role', () => {
|
|
||||||
it('should edit the role using the descriptor menu', async() => {
|
|
||||||
await page.waitToClick(selectors.accountDescriptor.menuButton);
|
|
||||||
await page.waitToClick(selectors.accountDescriptor.changeRole);
|
|
||||||
await page.autocompleteSearch(selectors.accountDescriptor.newRole, 'adminBoss');
|
|
||||||
await page.waitToClick(selectors.accountDescriptor.acceptButton);
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Role changed succesfully!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should reload the roles section to see now there are more roles', async() => {
|
|
||||||
// when role updates db takes time to return changes, without this timeout the result would have been 3
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
await page.reloadSection('account.card.roles');
|
|
||||||
const rolesCount = await page.countElement(selectors.accountRoles.anyResult);
|
|
||||||
|
|
||||||
expect(rolesCount).toEqual(61);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('activate account', () => {
|
describe('activate account', () => {
|
||||||
it(`should check the active account icon isn't present in the descriptor`, async() => {
|
it(`should check the active account icon isn't present in the descriptor`, async() => {
|
||||||
await page.waitForNumberOfElements(selectors.accountDescriptor.activeAccountIcon, 0);
|
await page.waitForNumberOfElements(selectors.accountDescriptor.activeAccountIcon, 0);
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
import selectors from '../../helpers/selectors.js';
|
||||||
|
import getBrowser from '../../helpers/puppeteer';
|
||||||
|
|
||||||
|
describe('Account privileges path', () => {
|
||||||
|
let browser;
|
||||||
|
let page;
|
||||||
|
|
||||||
|
beforeAll(async() => {
|
||||||
|
browser = await getBrowser();
|
||||||
|
page = browser.page;
|
||||||
|
await page.loginAndModule('developer', 'account');
|
||||||
|
await page.accessToSearchResult('1101');
|
||||||
|
await page.accessToSection('account.card.privileges');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('as developer', () => {
|
||||||
|
it('should throw error when give privileges', async() => {
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.checkHasGrant);
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.save);
|
||||||
|
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toContain(`You don't have enough privileges`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw error when change role', async() => {
|
||||||
|
await page.autocompleteSearch(selectors.accountPrivileges.role, 'employee');
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.save);
|
||||||
|
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toContain(`You don't have enough privileges`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('as sysadmin', () => {
|
||||||
|
beforeAll(async() => {
|
||||||
|
await page.loginAndModule('sysadmin', 'account');
|
||||||
|
await page.accessToSearchResult('9');
|
||||||
|
await page.accessToSection('account.card.privileges');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should give privileges', async() => {
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.checkHasGrant);
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.save);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
await page.reloadSection('account.card.privileges');
|
||||||
|
const result = await page.checkboxState(selectors.accountPrivileges.checkHasGrant);
|
||||||
|
|
||||||
|
expect(message.text).toContain(`Data saved!`);
|
||||||
|
expect(result).toBe('checked');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change role', async() => {
|
||||||
|
await page.autocompleteSearch(selectors.accountPrivileges.role, 'employee');
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.save);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
await page.reloadSection('account.card.privileges');
|
||||||
|
const result = await page.waitToGetProperty(selectors.accountPrivileges.role, 'value');
|
||||||
|
|
||||||
|
expect(message.text).toContain(`Data saved!`);
|
||||||
|
expect(result).toContain('employee');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('as developer again', () => {
|
||||||
|
it('should remove privileges', async() => {
|
||||||
|
await page.accessToSearchResult('9');
|
||||||
|
await page.accessToSection('account.card.privileges');
|
||||||
|
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.checkHasGrant);
|
||||||
|
await page.waitToClick(selectors.accountPrivileges.save);
|
||||||
|
|
||||||
|
await page.reloadSection('account.card.privileges');
|
||||||
|
const result = await page.checkboxState(selectors.accountPrivileges.checkHasGrant);
|
||||||
|
|
||||||
|
expect(result).toBe('unchecked');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -6,8 +6,98 @@ export default class Textfield extends Field {
|
||||||
super($element, $scope, $compile);
|
super($element, $scope, $compile);
|
||||||
this.buildInput('text');
|
this.buildInput('text');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set maxLength(value) {
|
||||||
|
this.input.maxLength = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get maxLength() {
|
||||||
|
return this.input.maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
set insertable(value) {
|
||||||
|
if (this._insertable === value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this._insertable)
|
||||||
|
this.input.removeEventListener('keypress', this.keyPressListener);
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
this.keyPressListener = async e => await this.onKeyPress(e);
|
||||||
|
this.input.addEventListener('keypress', this.keyPressListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._insertable = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get insertable() {
|
||||||
|
return this._insertable;
|
||||||
|
}
|
||||||
|
|
||||||
|
async onKeyPress(e) {
|
||||||
|
if (e.key == 'Enter')
|
||||||
|
return; // If the enter key is pressed dismiss it
|
||||||
|
|
||||||
|
let maxLength = this.maxLength;
|
||||||
|
|
||||||
|
// Call the function that obtains the current cursor position
|
||||||
|
let pointerPosition = getCaretPosition(e.target);
|
||||||
|
|
||||||
|
// If the cursor position is on the last allowed character,
|
||||||
|
// prevent any keystroke from doing anything
|
||||||
|
if (pointerPosition >= maxLength) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case by any ways the input is longer than the max especified size, cut it to it.
|
||||||
|
let currentArrValue = e.target.value.slice(0, maxLength);
|
||||||
|
|
||||||
|
// Transform said input to a array with each character on one position
|
||||||
|
currentArrValue = currentArrValue.split('');
|
||||||
|
|
||||||
|
// Cut the array in 2 parts, one with everything right of the caret,
|
||||||
|
// and one with everything left to it
|
||||||
|
let rightToTheCaret = currentArrValue.slice(pointerPosition);
|
||||||
|
|
||||||
|
let leftToTheCaret = currentArrValue.slice(0, pointerPosition);
|
||||||
|
|
||||||
|
// Remove the first number on the array that was right of the caret
|
||||||
|
rightToTheCaret.shift();
|
||||||
|
|
||||||
|
// The part that was left to the caret is not modified in any way and is put back into the textField
|
||||||
|
e.target.value = leftToTheCaret.join('');
|
||||||
|
|
||||||
|
// Add one millisecond of delay to give the UI time to update,
|
||||||
|
// so that it detects the changes on the textField
|
||||||
|
await new Promise(r => setTimeout(r, 1));
|
||||||
|
|
||||||
|
// Add the values that should be right to the Caret back in the textField
|
||||||
|
e.target.value = e.target.value + rightToTheCaret.join('');
|
||||||
|
|
||||||
|
// Update the current pointer position so that it moves 1 position to the right
|
||||||
|
pointerPosition++;
|
||||||
|
e.target.setSelectionRange(pointerPosition, pointerPosition);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCaretPosition(targetElement) {
|
||||||
|
let caretPosition = 0;
|
||||||
|
|
||||||
|
if (targetElement.selectionStart || targetElement.selectionStart == 0) // Firefox Support
|
||||||
|
caretPosition = targetElement.selectionStart;
|
||||||
|
|
||||||
|
return caretPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnTextfield', {
|
ngModule.vnComponent('vnTextfield', {
|
||||||
controller: Textfield
|
controller: Textfield,
|
||||||
|
bindings: {
|
||||||
|
maxLength: '<?',
|
||||||
|
insertable: '<?'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,24 +10,12 @@ class Email {
|
||||||
/**
|
/**
|
||||||
* Sends an email displaying a notification when it's sent.
|
* Sends an email displaying a notification when it's sent.
|
||||||
*
|
*
|
||||||
* @param {String} template The email report name
|
* @param {String} path The email report name
|
||||||
* @param {Object} params The email parameters
|
* @param {Object} params The email parameters
|
||||||
* @return {Promise} Promise resolved when it's sent
|
* @return {Promise} Promise resolved when it's sent
|
||||||
*/
|
*/
|
||||||
send(template, params) {
|
send(path, params) {
|
||||||
return this.$http.get(`email/${template}`, {params})
|
return this.$http.post(path, params)
|
||||||
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends an email displaying a notification when it's sent.
|
|
||||||
*
|
|
||||||
* @param {String} template The email report name
|
|
||||||
* @param {Object} params The email parameters
|
|
||||||
* @return {Promise} Promise resolved when it's sent
|
|
||||||
*/
|
|
||||||
sendCsv(template, params) {
|
|
||||||
return this.$http.get(`csv/${template}/send`, {params})
|
|
||||||
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,30 +10,16 @@ class Report {
|
||||||
* Shows a report in another window, automatically adds the authorization
|
* Shows a report in another window, automatically adds the authorization
|
||||||
* token to params.
|
* token to params.
|
||||||
*
|
*
|
||||||
* @param {String} report The report name
|
* @param {String} path The report name
|
||||||
* @param {Object} params The report parameters
|
* @param {Object} params The report parameters
|
||||||
*/
|
*/
|
||||||
show(report, params) {
|
show(path, params) {
|
||||||
params = Object.assign({
|
params = Object.assign({
|
||||||
authorization: this.vnToken.token
|
access_token: this.vnToken.token
|
||||||
}, params);
|
}, params);
|
||||||
const serializedParams = this.$httpParamSerializer(params);
|
const serializedParams = this.$httpParamSerializer(params);
|
||||||
window.open(`api/report/${report}?${serializedParams}`);
|
const query = serializedParams ? `?${serializedParams}` : '';
|
||||||
}
|
window.open(`api/${path}${query}`);
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows a report in another window, automatically adds the authorization
|
|
||||||
* token to params.
|
|
||||||
*
|
|
||||||
* @param {String} report The report name
|
|
||||||
* @param {Object} params The report parameters
|
|
||||||
*/
|
|
||||||
showCsv(report, params) {
|
|
||||||
params = Object.assign({
|
|
||||||
authorization: this.vnToken.token
|
|
||||||
}, params);
|
|
||||||
const serializedParams = this.$httpParamSerializer(params);
|
|
||||||
window.open(`api/csv/${report}/download?${serializedParams}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Report.$inject = ['$httpParamSerializer', 'vnToken'];
|
Report.$inject = ['$httpParamSerializer', 'vnToken'];
|
||||||
|
|
|
@ -1,78 +1,215 @@
|
||||||
{
|
{
|
||||||
"name": "salix-front",
|
"name": "salix-front",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "salix-front",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "GPL-3.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@uirouter/angularjs": "^1.0.20",
|
||||||
|
"angular": "^1.7.5",
|
||||||
|
"angular-animate": "^1.7.8",
|
||||||
|
"angular-moment": "^1.3.0",
|
||||||
|
"angular-translate": "^2.18.1",
|
||||||
|
"angular-translate-loader-partial": "^2.18.1",
|
||||||
|
"croppie": "^2.6.5",
|
||||||
|
"js-yaml": "^3.13.1",
|
||||||
|
"mg-crud": "^1.1.2",
|
||||||
|
"oclazyload": "^0.6.3",
|
||||||
|
"require-yaml": "0.0.1",
|
||||||
|
"validator": "^6.3.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@uirouter/angularjs": {
|
||||||
|
"version": "1.0.29",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@uirouter/core": "6.0.7"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"angular": ">=1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@uirouter/core": {
|
||||||
|
"version": "6.0.7",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/angular": {
|
||||||
|
"version": "1.8.2",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/angular-animate": {
|
||||||
|
"version": "1.8.2",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/angular-moment": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"moment": ">=2.8.0 <3.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/angular-translate": {
|
||||||
|
"version": "2.18.4",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"angular": "^1.8.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/angular-translate-loader-partial": {
|
||||||
|
"version": "2.18.4",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"angular-translate": "~2.18.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/argparse": {
|
||||||
|
"version": "1.0.10",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"sprintf-js": "~1.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/croppie": {
|
||||||
|
"version": "2.6.5",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/esprima": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"bin": {
|
||||||
|
"esparse": "bin/esparse.js",
|
||||||
|
"esvalidate": "bin/esvalidate.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/js-yaml": {
|
||||||
|
"version": "3.14.1",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"argparse": "^1.0.7",
|
||||||
|
"esprima": "^4.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"js-yaml": "bin/js-yaml.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mg-crud": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"angular": "^1.6.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/moment": {
|
||||||
|
"version": "2.29.1",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/oclazyload": {
|
||||||
|
"version": "0.6.3",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/require-yaml": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"license": "BSD",
|
||||||
|
"dependencies": {
|
||||||
|
"js-yaml": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/require-yaml/node_modules/argparse": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"license": "Python-2.0"
|
||||||
|
},
|
||||||
|
"node_modules/require-yaml/node_modules/js-yaml": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"argparse": "^2.0.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"js-yaml": "bin/js-yaml.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/sprintf-js": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"license": "BSD-3-Clause"
|
||||||
|
},
|
||||||
|
"node_modules/validator": {
|
||||||
|
"version": "6.3.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uirouter/angularjs": {
|
"@uirouter/angularjs": {
|
||||||
"version": "1.0.29",
|
"version": "1.0.29",
|
||||||
"resolved": "https://registry.npmjs.org/@uirouter/angularjs/-/angularjs-1.0.29.tgz",
|
|
||||||
"integrity": "sha512-RImWnBarNixkMto0o8stEaGwZmvhv5cnuOLXyMU2pY8MP2rgEF74ZNJTLeJCW14LR7XDUxVH8Mk8bPI6lxedmQ==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@uirouter/core": "6.0.7"
|
"@uirouter/core": "6.0.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@uirouter/core": {
|
"@uirouter/core": {
|
||||||
"version": "6.0.7",
|
"version": "6.0.7"
|
||||||
"resolved": "https://registry.npmjs.org/@uirouter/core/-/core-6.0.7.tgz",
|
|
||||||
"integrity": "sha512-KUTJxL+6q0PiBnFx4/Z+Hsyg0pSGiaW5yZQeJmUxknecjpTbnXkLU8H2EqRn9N2B+qDRa7Jg8RcgeNDPY72O1w=="
|
|
||||||
},
|
},
|
||||||
"angular": {
|
"angular": {
|
||||||
"version": "1.8.2",
|
"version": "1.8.2"
|
||||||
"resolved": "https://registry.npmjs.org/angular/-/angular-1.8.2.tgz",
|
|
||||||
"integrity": "sha512-IauMOej2xEe7/7Ennahkbb5qd/HFADiNuLSESz9Q27inmi32zB0lnAsFeLEWcox3Gd1F6YhNd1CP7/9IukJ0Gw=="
|
|
||||||
},
|
},
|
||||||
"angular-animate": {
|
"angular-animate": {
|
||||||
"version": "1.8.2",
|
"version": "1.8.2"
|
||||||
"resolved": "https://registry.npmjs.org/angular-animate/-/angular-animate-1.8.2.tgz",
|
|
||||||
"integrity": "sha512-Jbr9+grNMs9Kj57xuBU3Ju3NOPAjS1+g2UAwwDv7su1lt0/PLDy+9zEwDiu8C8xJceoTbmBNKiWGPJGBdCQLlA=="
|
|
||||||
},
|
},
|
||||||
"angular-moment": {
|
"angular-moment": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/angular-moment/-/angular-moment-1.3.0.tgz",
|
|
||||||
"integrity": "sha512-KG8rvO9MoaBLwtGnxTeUveSyNtrL+RNgGl1zqWN36+HDCCVGk2DGWOzqKWB6o+eTTbO3Opn4hupWKIElc8XETA==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"moment": ">=2.8.0 <3.0.0"
|
"moment": ">=2.8.0 <3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"angular-translate": {
|
"angular-translate": {
|
||||||
"version": "2.18.4",
|
"version": "2.18.4",
|
||||||
"resolved": "https://registry.npmjs.org/angular-translate/-/angular-translate-2.18.4.tgz",
|
|
||||||
"integrity": "sha512-KohNrkH6J9PK+VW0L/nsRTcg5Fw70Ajwwe3Jbfm54Pf9u9Fd+wuingoKv+h45mKf38eT+Ouu51FPua8VmZNoCw==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"angular": "^1.8.0"
|
"angular": "^1.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"angular-translate-loader-partial": {
|
"angular-translate-loader-partial": {
|
||||||
"version": "2.18.4",
|
"version": "2.18.4",
|
||||||
"resolved": "https://registry.npmjs.org/angular-translate-loader-partial/-/angular-translate-loader-partial-2.18.4.tgz",
|
|
||||||
"integrity": "sha512-bsjR+FbB0sdA2528E/ugwKdlPPQhA1looxLxI3otayBTFXBpED33besfSZhYAISLgNMSL038vSssfRUen9qD8w==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"angular-translate": "~2.18.4"
|
"angular-translate": "~2.18.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"argparse": {
|
"argparse": {
|
||||||
"version": "1.0.10",
|
"version": "1.0.10",
|
||||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
|
||||||
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"sprintf-js": "~1.0.2"
|
"sprintf-js": "~1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"croppie": {
|
"croppie": {
|
||||||
"version": "2.6.5",
|
"version": "2.6.5"
|
||||||
"resolved": "https://registry.npmjs.org/croppie/-/croppie-2.6.5.tgz",
|
|
||||||
"integrity": "sha512-IlChnVUGG5T3w2gRZIaQgBtlvyuYnlUWs2YZIXXR3H9KrlO1PtBT3j+ykxvy9eZIWhk+V5SpBmhCQz5UXKrEKQ=="
|
|
||||||
},
|
},
|
||||||
"esprima": {
|
"esprima": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1"
|
||||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
|
||||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "3.14.1",
|
"version": "3.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
|
|
||||||
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"argparse": "^1.0.7",
|
"argparse": "^1.0.7",
|
||||||
"esprima": "^4.0.0"
|
"esprima": "^4.0.0"
|
||||||
|
@ -80,39 +217,27 @@
|
||||||
},
|
},
|
||||||
"mg-crud": {
|
"mg-crud": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/mg-crud/-/mg-crud-1.1.2.tgz",
|
|
||||||
"integrity": "sha1-p6AWGzWSPK7/8ZpIBpS2V1vDggw=",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"angular": "^1.6.1"
|
"angular": "^1.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.29.1",
|
"version": "2.29.1"
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
|
||||||
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
|
|
||||||
},
|
},
|
||||||
"oclazyload": {
|
"oclazyload": {
|
||||||
"version": "0.6.3",
|
"version": "0.6.3"
|
||||||
"resolved": "https://registry.npmjs.org/oclazyload/-/oclazyload-0.6.3.tgz",
|
|
||||||
"integrity": "sha1-Kjirv/QJDAihEBZxkZRbWfLoJ5w="
|
|
||||||
},
|
},
|
||||||
"require-yaml": {
|
"require-yaml": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/require-yaml/-/require-yaml-0.0.1.tgz",
|
|
||||||
"integrity": "sha1-LhsY2RPDuqcqWk03O28Tjd0sMr0=",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": ""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"argparse": {
|
"argparse": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1"
|
||||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
|
||||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"argparse": "^2.0.1"
|
"argparse": "^2.0.1"
|
||||||
}
|
}
|
||||||
|
@ -120,14 +245,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sprintf-js": {
|
"sprintf-js": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3"
|
||||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
|
|
||||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
|
|
||||||
},
|
},
|
||||||
"validator": {
|
"validator": {
|
||||||
"version": "6.3.0",
|
"version": "6.3.0"
|
||||||
"resolved": "https://registry.npmjs.org/validator/-/validator-6.3.0.tgz",
|
|
||||||
"integrity": "sha1-R84j7Y1Ord+p1LjvAHG2zxB418g="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,5 +131,7 @@
|
||||||
"Fichadas impares": "Odd signs",
|
"Fichadas impares": "Odd signs",
|
||||||
"Descanso diario 9h.": "Daily rest 9h.",
|
"Descanso diario 9h.": "Daily rest 9h.",
|
||||||
"Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.",
|
"Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.",
|
||||||
"Password does not meet requirements": "Password does not meet requirements"
|
"Password does not meet requirements": "Password does not meet requirements",
|
||||||
|
"You don't have privileges to change the zone": "You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies",
|
||||||
|
"Not enough privileges to edit a client": "Not enough privileges to edit a client"
|
||||||
}
|
}
|
|
@ -96,7 +96,7 @@
|
||||||
"This postcode already exists": "Este código postal ya existe",
|
"This postcode already exists": "Este código postal ya existe",
|
||||||
"Concept cannot be blank": "El concepto no puede quedar en blanco",
|
"Concept cannot be blank": "El concepto no puede quedar en blanco",
|
||||||
"File doesn't exists": "El archivo no existe",
|
"File doesn't exists": "El archivo no existe",
|
||||||
"You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies": "No tienes permisos para cambiar la zona o para esos parámetros hay más de una opción de envío, hable con las agencias",
|
"You don't have privileges to change the zone": "No tienes permisos para cambiar la zona o para esos parámetros hay más de una opción de envío, hable con las agencias",
|
||||||
"This ticket is already on weekly tickets": "Este ticket ya está en tickets programados",
|
"This ticket is already on weekly tickets": "Este ticket ya está en tickets programados",
|
||||||
"Ticket id cannot be blank": "El id de ticket no puede quedar en blanco",
|
"Ticket id cannot be blank": "El id de ticket no puede quedar en blanco",
|
||||||
"Weekday cannot be blank": "El día de la semana no puede quedar en blanco",
|
"Weekday cannot be blank": "El día de la semana no puede quedar en blanco",
|
||||||
|
@ -232,5 +232,8 @@
|
||||||
"Fichadas impares": "Fichadas impares",
|
"Fichadas impares": "Fichadas impares",
|
||||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||||
"Dirección incorrecta": "Dirección incorrecta"
|
"Dirección incorrecta": "Dirección incorrecta",
|
||||||
|
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
|
||||||
|
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
|
||||||
|
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente"
|
||||||
}
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
require('../../../print/boot.js')(app);
|
require('vn-print').boot(app);
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/jpg",
|
"image/jpg",
|
||||||
|
"image/webp",
|
||||||
"video/mp4"
|
"video/mp4"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -60,7 +61,8 @@
|
||||||
"multipart/x-zip",
|
"multipart/x-zip",
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/jpg"
|
"image/jpg",
|
||||||
|
"image/webp"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"imageStorage": {
|
"imageStorage": {
|
||||||
|
@ -72,7 +74,8 @@
|
||||||
"allowedContentTypes": [
|
"allowedContentTypes": [
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/jpg"
|
"image/jpg",
|
||||||
|
"image/webp"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"invoiceStorage": {
|
"invoiceStorage": {
|
||||||
|
@ -96,6 +99,7 @@
|
||||||
"image/png",
|
"image/png",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
"image/jpg",
|
"image/jpg",
|
||||||
|
"image/webp",
|
||||||
"video/mp4"
|
"video/mp4"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
/**
|
||||||
|
* Transforms an object to a raw data CSV file.
|
||||||
|
*
|
||||||
|
* @param {Object} rows Data
|
||||||
|
* @return {String} Formatted CSV data
|
||||||
|
*/
|
||||||
function toCSV(rows) {
|
function toCSV(rows) {
|
||||||
const [columns] = rows;
|
const [columns] = rows;
|
||||||
let content = Object.keys(columns).join('\t');
|
let content = Object.keys(columns).join('\t');
|
|
@ -11,14 +11,6 @@
|
||||||
translate>
|
translate>
|
||||||
Delete
|
Delete
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item
|
|
||||||
ng-click="$ctrl.onChangeRole()"
|
|
||||||
name="changeRole"
|
|
||||||
vn-acl="hr"
|
|
||||||
vn-acl-action="remove"
|
|
||||||
translate>
|
|
||||||
Change role
|
|
||||||
</vn-item>
|
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-if="::$root.user.id == $ctrl.id"
|
ng-if="::$root.user.id == $ctrl.id"
|
||||||
ng-click="$ctrl.onChangePassClick(true)"
|
ng-click="$ctrl.onChangePassClick(true)"
|
||||||
|
@ -128,22 +120,6 @@
|
||||||
question="Are you sure you want to continue?"
|
question="Are you sure you want to continue?"
|
||||||
message="User will be deactivated">
|
message="User will be deactivated">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
<vn-dialog
|
|
||||||
vn-id="changeRole"
|
|
||||||
on-accept="$ctrl.onChangeRoleAccept()">
|
|
||||||
<tpl-body>
|
|
||||||
<vn-autocomplete
|
|
||||||
label="Role"
|
|
||||||
ng-model="$ctrl.newRole"
|
|
||||||
url="Roles"
|
|
||||||
vn-focus>
|
|
||||||
</vn-autocomplete>
|
|
||||||
</tpl-body>
|
|
||||||
<tpl-buttons>
|
|
||||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
|
||||||
<button response="accept" translate>Accept</button>
|
|
||||||
</tpl-buttons>
|
|
||||||
</vn-dialog>
|
|
||||||
<vn-dialog
|
<vn-dialog
|
||||||
vn-id="changePass"
|
vn-id="changePass"
|
||||||
on-accept="$ctrl.onPassChange()"
|
on-accept="$ctrl.onPassChange()"
|
||||||
|
|
|
@ -30,20 +30,6 @@ class Controller extends Descriptor {
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('User removed')));
|
.then(() => this.vnApp.showSuccess(this.$t('User removed')));
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeRole() {
|
|
||||||
this.newRole = this.user.role.id;
|
|
||||||
this.$.changeRole.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
onChangeRoleAccept() {
|
|
||||||
const params = {roleFk: this.newRole};
|
|
||||||
return this.$http.patch(`Accounts/${this.id}`, params)
|
|
||||||
.then(() => {
|
|
||||||
this.emit('change');
|
|
||||||
this.vnApp.showSuccess(this.$t('Role changed succesfully!'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
onChangePassClick(askOldPass) {
|
onChangePassClick(askOldPass) {
|
||||||
this.$http.get('UserPasswords/findOne')
|
this.$http.get('UserPasswords/findOne')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
|
|
@ -30,17 +30,6 @@ describe('component vnUserDescriptor', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onChangeRoleAccept()', () => {
|
|
||||||
it('should call backend method to change role', () => {
|
|
||||||
$httpBackend.expectPATCH('Accounts/1').respond();
|
|
||||||
controller.onChangeRoleAccept();
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
||||||
expect(controller.emit).toHaveBeenCalledWith('change');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('onPassChange()', () => {
|
describe('onPassChange()', () => {
|
||||||
it('should throw an error when password is empty', () => {
|
it('should throw an error when password is empty', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
|
|
@ -18,3 +18,4 @@ import './roles';
|
||||||
import './ldap';
|
import './ldap';
|
||||||
import './samba';
|
import './samba';
|
||||||
import './accounts';
|
import './accounts';
|
||||||
|
import './privileges';
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<mg-ajax path="Accounts/{{post.params.id}}/privileges" options="vnPost"></mg-ajax>
|
||||||
|
<vn-watcher
|
||||||
|
vn-id="watcher"
|
||||||
|
url="Accounts"
|
||||||
|
data="$ctrl.user"
|
||||||
|
id-value="$ctrl.$params.id"
|
||||||
|
form="form"
|
||||||
|
save="post">
|
||||||
|
</vn-watcher>
|
||||||
|
<form
|
||||||
|
name="form"
|
||||||
|
ng-submit="watcher.submit()"
|
||||||
|
class="vn-w-md">
|
||||||
|
<vn-card class="vn-pa-lg" vn-focus>
|
||||||
|
<vn-vertical>
|
||||||
|
<vn-check
|
||||||
|
label="Has grant"
|
||||||
|
ng-model="$ctrl.user.hasGrant">
|
||||||
|
</vn-check>
|
||||||
|
</vn-vertical>
|
||||||
|
<vn-vertical
|
||||||
|
class="vn-mt-md">
|
||||||
|
<vn-autocomplete
|
||||||
|
label="Role"
|
||||||
|
ng-model="$ctrl.user.roleFk"
|
||||||
|
url="Roles">
|
||||||
|
</vn-autocomplete>
|
||||||
|
</vn-vertical>
|
||||||
|
</vn-card>
|
||||||
|
<vn-button-bar>
|
||||||
|
<vn-submit
|
||||||
|
disabled="!watcher.dataChanged()"
|
||||||
|
label="Save">
|
||||||
|
</vn-submit>
|
||||||
|
<vn-button
|
||||||
|
class="cancel"
|
||||||
|
label="Undo changes"
|
||||||
|
disabled="!watcher.dataChanged()"
|
||||||
|
ng-click="watcher.loadOriginalData()">
|
||||||
|
</vn-button>
|
||||||
|
</vn-button-bar>
|
||||||
|
</form>
|
|
@ -0,0 +1,9 @@
|
||||||
|
import ngModule from '../module';
|
||||||
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
|
export default class Controller extends Section {}
|
||||||
|
|
||||||
|
ngModule.component('vnUserPrivileges', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller
|
||||||
|
});
|
|
@ -0,0 +1,2 @@
|
||||||
|
Privileges: Privilegios
|
||||||
|
Has grant: Tiene privilegios
|
|
@ -19,7 +19,8 @@
|
||||||
{"state": "account.card.basicData", "icon": "settings"},
|
{"state": "account.card.basicData", "icon": "settings"},
|
||||||
{"state": "account.card.roles", "icon": "group"},
|
{"state": "account.card.roles", "icon": "group"},
|
||||||
{"state": "account.card.mailForwarding", "icon": "forward"},
|
{"state": "account.card.mailForwarding", "icon": "forward"},
|
||||||
{"state": "account.card.aliases", "icon": "email"}
|
{"state": "account.card.aliases", "icon": "email"},
|
||||||
|
{"state": "account.card.privileges", "icon": "badge"}
|
||||||
],
|
],
|
||||||
"role": [
|
"role": [
|
||||||
{"state": "account.role.card.basicData", "icon": "settings"},
|
{"state": "account.role.card.basicData", "icon": "settings"},
|
||||||
|
@ -99,6 +100,13 @@
|
||||||
"description": "Mail aliases",
|
"description": "Mail aliases",
|
||||||
"acl": ["marketing", "hr"]
|
"acl": ["marketing", "hr"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"url": "/privileges",
|
||||||
|
"state": "account.card.privileges",
|
||||||
|
"component": "vn-user-privileges",
|
||||||
|
"description": "Privileges",
|
||||||
|
"acl": ["hr"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"url": "/role?q",
|
"url": "/role?q",
|
||||||
"state": "account.role",
|
"state": "account.role",
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('claimPickupEmail', {
|
||||||
|
description: 'Sends the the claim pickup order email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/claim-pickup-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.claimPickupEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('claim-pickup-order', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,55 @@
|
||||||
|
const { Report } = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('claimPickupPdf', {
|
||||||
|
description: 'Returns the claim pickup order pdf',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The claim id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/claim-pickup-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.claimPickupPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('claim-pickup-order', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -9,4 +9,6 @@ module.exports = Self => {
|
||||||
require('../methods/claim/isEditable')(Self);
|
require('../methods/claim/isEditable')(Self);
|
||||||
require('../methods/claim/updateClaimDestination')(Self);
|
require('../methods/claim/updateClaimDestination')(Self);
|
||||||
require('../methods/claim/downloadFile')(Self);
|
require('../methods/claim/downloadFile')(Self);
|
||||||
|
require('../methods/claim/claimPickupPdf')(Self);
|
||||||
|
require('../methods/claim/claimPickupEmail')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="confirmPickupOrder.show()"
|
ng-click="confirmPickupOrder.show()"
|
||||||
|
vn-acl="salesPerson"
|
||||||
|
vn-acl-action="remove"
|
||||||
translate>
|
translate>
|
||||||
Send Pickup order
|
Send Pickup order
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
|
|
@ -11,17 +11,15 @@ class Controller extends Descriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
showPickupOrder() {
|
showPickupOrder() {
|
||||||
this.vnReport.show('claim-pickup-order', {
|
this.vnReport.show(`Claims/${this.claim.id}/claim-pickup-pdf`, {
|
||||||
recipientId: this.claim.clientFk,
|
recipientId: this.claim.clientFk
|
||||||
claimId: this.claim.id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPickupOrder() {
|
sendPickupOrder() {
|
||||||
return this.vnEmail.send('claim-pickup-order', {
|
return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, {
|
||||||
recipient: this.claim.client.email,
|
recipient: this.claim.client.email,
|
||||||
recipientId: this.claim.clientFk,
|
recipientId: this.claim.clientFk
|
||||||
claimId: this.claim.id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,13 @@ describe('Item Component vnClaimDescriptor', () => {
|
||||||
|
|
||||||
window.open = jasmine.createSpy('open');
|
window.open = jasmine.createSpy('open');
|
||||||
const params = {
|
const params = {
|
||||||
recipientId: claim.clientFk,
|
recipientId: claim.clientFk
|
||||||
claimId: claim.id
|
|
||||||
};
|
};
|
||||||
controller.showPickupOrder();
|
controller.showPickupOrder();
|
||||||
|
|
||||||
expect(controller.vnReport.show).toHaveBeenCalledWith('claim-pickup-order', params);
|
const expectedPath = `Claims/${claim.id}/claim-pickup-pdf`;
|
||||||
|
|
||||||
|
expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath, params);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,12 +40,13 @@ describe('Item Component vnClaimDescriptor', () => {
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
recipient: claim.client.email,
|
recipient: claim.client.email,
|
||||||
recipientId: claim.clientFk,
|
recipientId: claim.clientFk
|
||||||
claimId: claim.id
|
|
||||||
};
|
};
|
||||||
controller.sendPickupOrder();
|
controller.sendPickupOrder();
|
||||||
|
|
||||||
expect(controller.vnEmail.send).toHaveBeenCalledWith('claim-pickup-order', params);
|
const expectedPath = `Claims/${claim.id}/claim-pickup-email`;
|
||||||
|
|
||||||
|
expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('campaignMetricsEmail', {
|
||||||
|
description: 'Sends the campaign metrics email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'to',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/campaign-metrics-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.campaignMetricsEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('campaign-metrics', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,66 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('campaignMetricsPdf', {
|
||||||
|
description: 'Returns the campaign metrics pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'to',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/campaign-metrics-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.campaignMetricsPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('campaign-metrics', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,64 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientDebtStatementEmail', {
|
||||||
|
description: 'Sends the client debt statement email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/client-debt-statement-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientDebtStatementEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('client-debt-statement', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientDebtStatementHtml', {
|
||||||
|
description: 'Returns the client debt statement email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/client-debt-statement-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientDebtStatementHtml = async(ctx, id) => {
|
||||||
|
const {accessToken} = ctx.req;
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
params.access_token = accessToken.id;
|
||||||
|
|
||||||
|
const report = new Email('client-debt-statement', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,61 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientDebtStatementPdf', {
|
||||||
|
description: 'Returns the client debt statement pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'from',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/client-debt-statement-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientDebtStatementPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('client-debt-statement', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,59 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientWelcomeEmail', {
|
||||||
|
description: 'Sends the client welcome email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/client-welcome-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientWelcomeEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('client-welcome', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,58 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientWelcomeHtml', {
|
||||||
|
description: 'Returns the client welcome email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/client-welcome-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientWelcomeHtml = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
|
||||||
|
const report = new Email('client-welcome', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,80 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('consumptionSendQueued', {
|
||||||
|
description: 'Send all queued invoices',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [],
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/consumption-send-queued',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.consumptionSendQueued = async() => {
|
||||||
|
const queues = await Self.rawSql(`
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
params
|
||||||
|
FROM clientConsumptionQueue
|
||||||
|
WHERE status = ''`);
|
||||||
|
|
||||||
|
for (const queue of queues) {
|
||||||
|
try {
|
||||||
|
const params = JSON.parse(queue.params);
|
||||||
|
|
||||||
|
const clients = await Self.rawSql(`
|
||||||
|
SELECT
|
||||||
|
c.id AS clientFk,
|
||||||
|
c.email AS clientEmail,
|
||||||
|
eu.email salesPersonEmail
|
||||||
|
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
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
|
WHERE c.id IN(?)
|
||||||
|
AND it.isPackaging = FALSE
|
||||||
|
AND DATE(t.shipped) BETWEEN ? AND ?
|
||||||
|
GROUP BY c.id`, [params.clients, params.from, params.to]);
|
||||||
|
|
||||||
|
for (const client of clients) {
|
||||||
|
const args = {
|
||||||
|
id: client.clientFk,
|
||||||
|
recipient: client.clientEmail,
|
||||||
|
replyTo: client.salesPersonEmail,
|
||||||
|
from: params.from,
|
||||||
|
to: params.to
|
||||||
|
};
|
||||||
|
|
||||||
|
const email = new Email('campaign-metrics', args);
|
||||||
|
await email.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
await Self.rawSql(`
|
||||||
|
UPDATE clientConsumptionQueue
|
||||||
|
SET status = 'printed',
|
||||||
|
printed = ?
|
||||||
|
WHERE id = ?`,
|
||||||
|
[new Date(), queue.id]);
|
||||||
|
} catch (error) {
|
||||||
|
await Self.rawSql(`
|
||||||
|
UPDATE clientConsumptionQueue
|
||||||
|
SET status = ?
|
||||||
|
WHERE id = ?`,
|
||||||
|
[error.message, queue.id]);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: 'Success'
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,59 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('clientCreditEmail', {
|
||||||
|
description: 'Sends the credit request email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/credit-request-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.clientCreditEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('credit-request', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,60 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('creditRequestHtml', {
|
||||||
|
description: 'Returns the credit request email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/credit-request-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.creditRequestHtml = async(ctx, id) => {
|
||||||
|
const {accessToken} = ctx.req;
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
params.access_token = accessToken.id;
|
||||||
|
|
||||||
|
const report = new Email('credit-request', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,56 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('creditRequestPdf', {
|
||||||
|
description: 'Returns the credit request pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/credit-request-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.creditRequestPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('credit-request', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('incotermsAuthorizationEmail', {
|
||||||
|
description: 'Sends the incoterms authorization email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/incoterms-authorization-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.incotermsAuthorizationEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('incoterms-authorization', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,66 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('incotermsAuthorizationHtml', {
|
||||||
|
description: 'Returns the incoterms authorization email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/incoterms-authorization-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.incotermsAuthorizationHtml = async(ctx, id) => {
|
||||||
|
const {accessToken} = ctx.req;
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
params.access_token = accessToken.id;
|
||||||
|
|
||||||
|
const report = new Email('incoterms-authorization', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,62 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('incotermsAuthorizationPdf', {
|
||||||
|
description: 'Returns the incoterms authorization pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/incoterms-authorization-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.incotermsAuthorizationPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('incoterms-authorization', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('letterDebtorNdEmail', {
|
||||||
|
description: 'Sends the second debtor letter email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/letter-debtor-nd-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.letterDebtorNdEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('letter-debtor-nd', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,66 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('letterDebtorNdHtml', {
|
||||||
|
description: 'Returns the second letter debtor email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/letter-debtor-nd-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.letterDebtorNdHtml = async(ctx, id) => {
|
||||||
|
const {accessToken} = ctx.req;
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
params.access_token = accessToken.id;
|
||||||
|
|
||||||
|
const report = new Email('letter-debtor-nd', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,62 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('letterDebtorPdf', {
|
||||||
|
description: 'Returns the letter debtor pdf',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/letter-debtor-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.letterDebtorPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('letter-debtor', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('letterDebtorStEmail', {
|
||||||
|
description: 'Sends the printer setup email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/letter-debtor-st-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.letterDebtorStEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('letter-debtor-st', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,66 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('letterDebtorStHtml', {
|
||||||
|
description: 'Returns the letter debtor email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/letter-debtor-st-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.letterDebtorStHtml = async(ctx, id) => {
|
||||||
|
const {accessToken} = ctx.req;
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
params.access_token = accessToken.id;
|
||||||
|
|
||||||
|
const report = new Email('letter-debtor-st', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,59 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('printerSetupEmail', {
|
||||||
|
description: 'Sends the printer setup email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/printer-setup-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.printerSetupEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('printer-setup', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,58 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('printerSetupHtml', {
|
||||||
|
description: 'Returns the printer setup email preview',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/printer-setup-html',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.printerSetupHtml = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
params.isPreview = true;
|
||||||
|
|
||||||
|
const report = new Email('printer-setup', params);
|
||||||
|
const html = await report.render();
|
||||||
|
|
||||||
|
return [html, 'text/html', `filename="mail-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('sepaCoreEmail', {
|
||||||
|
description: 'Sends the campaign metrics email with an attached PDF',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The client id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'replyTo',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The sender email to reply to',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id to send to the recipient preferred language',
|
||||||
|
required: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The company id',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/sepa-core-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.sepaCoreEmail = async ctx => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {
|
||||||
|
recipient: args.recipient,
|
||||||
|
lang: ctx.req.getLocale()
|
||||||
|
};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const email = new Email('sepa-core', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('setPassword', {
|
Self.remoteMethodCtx('setPassword', {
|
||||||
description: 'Sets the password of a non-worker client',
|
description: 'Sets the password of a non-worker client',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
|
@ -20,13 +21,21 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.setPassword = async function(id, newPassword) {
|
Self.setPassword = async function(ctx, id, newPassword) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
|
||||||
const isWorker = await models.Worker.findById(id);
|
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||||
if (isWorker)
|
|
||||||
throw new Error(`Can't change the password of another worker`);
|
|
||||||
|
|
||||||
await models.Account.setPassword(id, newPassword);
|
if (!isSalesPerson)
|
||||||
|
throw new UserError(`Not enough privileges to edit a client`);
|
||||||
|
|
||||||
|
const isClient = await models.Client.findById(id, null);
|
||||||
|
const isUserAccount = await models.UserAccount.findById(id, null);
|
||||||
|
|
||||||
|
if (isClient && !isUserAccount)
|
||||||
|
await models.Account.setPassword(id, newPassword);
|
||||||
|
else
|
||||||
|
throw new UserError(`Modifiable password only via recovery or by an administrator`);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,23 +1,43 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Client setPassword', () => {
|
describe('Client setPassword', () => {
|
||||||
it('should throw an error the setPassword target is not just a client but a worker', async() => {
|
const salesPersonId = 19;
|
||||||
let error;
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: salesPersonId}}
|
||||||
|
};
|
||||||
|
|
||||||
|
it(`should throw an error if you don't have enough permissions`, async() => {
|
||||||
|
let error;
|
||||||
|
const employeeId = 1;
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: employeeId}}
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
await models.Client.setPassword(1106, 'newPass?');
|
await models.Client.setPassword(ctx, 1, 't0pl3v3l.p455w0rd!');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`Can't change the password of another worker`);
|
expect(error.message).toEqual(`Not enough privileges to edit a client`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error the setPassword target is not just a client but a worker', async() => {
|
||||||
|
let error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.Client.setPassword(ctx, 1, 't0pl3v3l.p455w0rd!');
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`Modifiable password only via recovery or by an administrator`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should change the password of the client', async() => {
|
it('should change the password of the client', async() => {
|
||||||
let error;
|
let error;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.Client.setPassword(1101, 't0pl3v3l.p455w0rd!');
|
await models.Client.setPassword(ctx, 1101, 't0pl3v3l.p455w0rd!');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ describe('Client updateUser', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const salesPersonId = 19;
|
||||||
const ctx = {
|
const ctx = {
|
||||||
req: {accessToken: {userId: employeeId}},
|
req: {accessToken: {userId: salesPersonId}},
|
||||||
args: {name: 'test', active: true}
|
args: {name: 'test', active: true}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,8 +22,13 @@ describe('Client updateUser', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error the target user is not just a client but a worker', async() => {
|
it(`should throw an error if you don't have enough permissions`, async() => {
|
||||||
let error;
|
let error;
|
||||||
|
const employeeId = 1;
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: employeeId}},
|
||||||
|
args: {name: 'test', active: true}
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
const clientID = 1106;
|
const clientID = 1106;
|
||||||
await models.Client.updateUser(ctx, clientID);
|
await models.Client.updateUser(ctx, clientID);
|
||||||
|
@ -30,7 +36,19 @@ describe('Client updateUser', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`Can't update the user details of another worker`);
|
expect(error.message).toEqual(`Not enough privileges to edit a client`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error the target user is not just a client but a worker', async() => {
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const clientID = 1;
|
||||||
|
await models.Client.updateUser(ctx, clientID);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`Modifiable user details only by an administrator`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the user data', async() => {
|
it('should update the user data', async() => {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('updateUser', {
|
Self.remoteMethodCtx('updateUser', {
|
||||||
description: 'Updates the user information',
|
description: 'Updates the user information',
|
||||||
|
@ -5,8 +6,7 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The user id',
|
description: 'The user id'
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'name',
|
arg: 'name',
|
||||||
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'email',
|
arg: 'email',
|
||||||
type: 'string',
|
type: 'any',
|
||||||
description: 'the user email'
|
description: 'the user email'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.updateUser = async function(ctx, id, options) {
|
Self.updateUser = async function(ctx, id, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
|
@ -44,13 +45,19 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isWorker = await models.Worker.findById(id, null, myOptions);
|
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions);
|
||||||
if (isWorker)
|
|
||||||
throw new Error(`Can't update the user details of another worker`);
|
|
||||||
|
|
||||||
const user = await models.Account.findById(id, null, myOptions);
|
if (!isSalesPerson)
|
||||||
|
throw new UserError(`Not enough privileges to edit a client`);
|
||||||
|
|
||||||
await user.updateAttributes(ctx.args, myOptions);
|
const isClient = await models.Client.findById(id, null, myOptions);
|
||||||
|
const isUserAccount = await models.UserAccount.findById(id, null, myOptions);
|
||||||
|
|
||||||
|
if (isClient && !isUserAccount) {
|
||||||
|
const user = await models.Account.findById(id, null, myOptions);
|
||||||
|
await user.updateAttributes(ctx.args, myOptions);
|
||||||
|
} else
|
||||||
|
throw new UserError(`Modifiable user details only by an administrator`);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
"ClientCreditLimit": {
|
"ClientCreditLimit": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"ClientConsumptionQueue": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"ClientLog": {
|
"ClientLog": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"name": "ClientConsumptionQueue",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "clientConsumptionQueue"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"params": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"queued": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"printed": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"client": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Client",
|
||||||
|
"foreignKey": "clientFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/client/addressesPropagateRe')(Self);
|
||||||
|
require('../methods/client/canBeInvoiced')(Self);
|
||||||
|
require('../methods/client/canCreateTicket')(Self);
|
||||||
|
require('../methods/client/checkDuplicated')(Self);
|
||||||
|
require('../methods/client/confirmTransaction')(Self);
|
||||||
|
require('../methods/client/consumption')(Self);
|
||||||
|
require('../methods/client/createAddress')(Self);
|
||||||
|
require('../methods/client/createReceipt')(Self);
|
||||||
|
require('../methods/client/createWithUser')(Self);
|
||||||
|
require('../methods/client/extendedListFilter')(Self);
|
||||||
|
require('../methods/client/getAverageInvoiced')(Self);
|
||||||
|
require('../methods/client/getCard')(Self);
|
||||||
|
require('../methods/client/getDebt')(Self);
|
||||||
|
require('../methods/client/getMana')(Self);
|
||||||
|
require('../methods/client/getTransactions')(Self);
|
||||||
|
require('../methods/client/hasCustomerRole')(Self);
|
||||||
|
require('../methods/client/isValidClient')(Self);
|
||||||
|
require('../methods/client/lastActiveTickets')(Self);
|
||||||
|
require('../methods/client/sendSms')(Self);
|
||||||
|
require('../methods/client/setPassword')(Self);
|
||||||
|
require('../methods/client/summary')(Self);
|
||||||
|
require('../methods/client/updateAddress')(Self);
|
||||||
|
require('../methods/client/updateFiscalData')(Self);
|
||||||
|
require('../methods/client/updatePortfolio')(Self);
|
||||||
|
require('../methods/client/updateUser')(Self);
|
||||||
|
require('../methods/client/uploadFile')(Self);
|
||||||
|
require('../methods/client/campaignMetricsPdf')(Self);
|
||||||
|
require('../methods/client/campaignMetricsEmail')(Self);
|
||||||
|
require('../methods/client/clientWelcomeHtml')(Self);
|
||||||
|
require('../methods/client/clientWelcomeEmail')(Self);
|
||||||
|
require('../methods/client/printerSetupHtml')(Self);
|
||||||
|
require('../methods/client/printerSetupEmail')(Self);
|
||||||
|
require('../methods/client/sepaCoreEmail')(Self);
|
||||||
|
require('../methods/client/letterDebtorPdf')(Self);
|
||||||
|
require('../methods/client/letterDebtorStHtml')(Self);
|
||||||
|
require('../methods/client/letterDebtorStEmail')(Self);
|
||||||
|
require('../methods/client/letterDebtorNdHtml')(Self);
|
||||||
|
require('../methods/client/letterDebtorNdEmail')(Self);
|
||||||
|
require('../methods/client/clientDebtStatementPdf')(Self);
|
||||||
|
require('../methods/client/clientDebtStatementHtml')(Self);
|
||||||
|
require('../methods/client/clientDebtStatementEmail')(Self);
|
||||||
|
require('../methods/client/creditRequestPdf')(Self);
|
||||||
|
require('../methods/client/creditRequestHtml')(Self);
|
||||||
|
require('../methods/client/creditRequestEmail')(Self);
|
||||||
|
require('../methods/client/incotermsAuthorizationPdf')(Self);
|
||||||
|
require('../methods/client/incotermsAuthorizationHtml')(Self);
|
||||||
|
require('../methods/client/incotermsAuthorizationEmail')(Self);
|
||||||
|
require('../methods/client/consumptionSendQueued')(Self);
|
||||||
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.validatesPresenceOf('typeFk', {
|
Self.validatesPresenceOf('typeFk', {
|
||||||
|
@ -6,10 +7,10 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
let models = Self.app.models;
|
const models = Self.app.models;
|
||||||
let changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
|
|
||||||
let sample = await models.Sample.findById(changes.typeFk);
|
const sample = await models.Sample.findById(changes.typeFk);
|
||||||
|
|
||||||
if (sample.hasCompany && !changes.companyFk)
|
if (sample.hasCompany && !changes.companyFk)
|
||||||
throw new UserError('Choose a company');
|
throw new UserError('Choose a company');
|
||||||
|
@ -25,11 +26,11 @@ module.exports = Self => {
|
||||||
|
|
||||||
// Renew mandate
|
// Renew mandate
|
||||||
if (mandate) {
|
if (mandate) {
|
||||||
let mandateType = await models.MandateType.findOne({
|
const mandateType = await models.MandateType.findOne({
|
||||||
where: {name: mandate.type}
|
where: {name: mandate.type}
|
||||||
});
|
});
|
||||||
|
|
||||||
let oldMandate = await models.Mandate.findOne({
|
const oldMandate = await models.Mandate.findOne({
|
||||||
where: {
|
where: {
|
||||||
clientFk: changes.clientFk,
|
clientFk: changes.clientFk,
|
||||||
companyFk: changes.companyFk,
|
companyFk: changes.companyFk,
|
||||||
|
@ -50,10 +51,8 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply workerFk
|
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||||
let filter = {where: {userFk: ctx.options.accessToken.userId}};
|
|
||||||
let worker = await Self.app.models.Worker.findOne(filter);
|
|
||||||
|
|
||||||
changes.workerFk = worker.id;
|
changes.userFk = loopBackContext.active.accessToken.userId;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const got = require('got');
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const getFinalState = require('vn-loopback/util/hook').getFinalState;
|
const getFinalState = require('vn-loopback/util/hook').getFinalState;
|
||||||
const isMultiple = require('vn-loopback/util/hook').isMultiple;
|
const isMultiple = require('vn-loopback/util/hook').isMultiple;
|
||||||
|
@ -8,32 +7,7 @@ const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
// Methods
|
// Methods
|
||||||
require('../methods/client/addressesPropagateRe')(Self);
|
require('./client-methods')(Self);
|
||||||
require('../methods/client/canBeInvoiced')(Self);
|
|
||||||
require('../methods/client/canCreateTicket')(Self);
|
|
||||||
require('../methods/client/checkDuplicated')(Self);
|
|
||||||
require('../methods/client/confirmTransaction')(Self);
|
|
||||||
require('../methods/client/consumption')(Self);
|
|
||||||
require('../methods/client/createAddress')(Self);
|
|
||||||
require('../methods/client/createReceipt')(Self);
|
|
||||||
require('../methods/client/createWithUser')(Self);
|
|
||||||
require('../methods/client/extendedListFilter')(Self);
|
|
||||||
require('../methods/client/getAverageInvoiced')(Self);
|
|
||||||
require('../methods/client/getCard')(Self);
|
|
||||||
require('../methods/client/getDebt')(Self);
|
|
||||||
require('../methods/client/getMana')(Self);
|
|
||||||
require('../methods/client/getTransactions')(Self);
|
|
||||||
require('../methods/client/hasCustomerRole')(Self);
|
|
||||||
require('../methods/client/isValidClient')(Self);
|
|
||||||
require('../methods/client/lastActiveTickets')(Self);
|
|
||||||
require('../methods/client/sendSms')(Self);
|
|
||||||
require('../methods/client/setPassword')(Self);
|
|
||||||
require('../methods/client/summary')(Self);
|
|
||||||
require('../methods/client/updateAddress')(Self);
|
|
||||||
require('../methods/client/updateFiscalData')(Self);
|
|
||||||
require('../methods/client/updatePortfolio')(Self);
|
|
||||||
require('../methods/client/updateUser')(Self);
|
|
||||||
require('../methods/client/uploadFile')(Self);
|
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
@ -317,23 +291,22 @@ module.exports = Self => {
|
||||||
const $t = httpRequest.__;
|
const $t = httpRequest.__;
|
||||||
const headers = httpRequest.headers;
|
const headers = httpRequest.headers;
|
||||||
const origin = headers.origin;
|
const origin = headers.origin;
|
||||||
const authorization = headers.authorization;
|
|
||||||
|
|
||||||
const salesPersonId = instance.salesPersonFk;
|
const salesPersonId = instance.salesPersonFk;
|
||||||
|
|
||||||
if (salesPersonId) {
|
if (salesPersonId) {
|
||||||
// Send email to client
|
// Send email to client
|
||||||
if (instance.email) {
|
if (instance.email) {
|
||||||
|
const {Email} = require('vn-print');
|
||||||
const worker = await models.EmailUser.findById(salesPersonId);
|
const worker = await models.EmailUser.findById(salesPersonId);
|
||||||
const params = {
|
const params = {
|
||||||
authorization: authorization,
|
id: instance.id,
|
||||||
recipientId: instance.id,
|
recipientId: instance.id,
|
||||||
recipient: instance.email,
|
recipient: instance.email,
|
||||||
replyTo: worker.email
|
replyTo: worker.email
|
||||||
};
|
};
|
||||||
await got.get(`${origin}/api/email/payment-update`, {
|
const email = new Email('payment-update', params);
|
||||||
searchParams: params
|
await email.send();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullUrl = `${origin}/#!/client/${instance.id}/billing-data`;
|
const fullUrl = `${origin}/#!/client/${instance.id}/billing-data`;
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
},
|
},
|
||||||
"datepickerEnabled": {
|
"datepickerEnabled": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scopes": {
|
"scopes": {
|
||||||
|
|
|
@ -45,11 +45,13 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
showReport() {
|
showReport() {
|
||||||
this.vnReport.show('campaign-metrics', this.reportParams);
|
const path = `Clients/${this.client.id}/campaign-metrics-pdf`;
|
||||||
|
this.vnReport.show(path, this.reportParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail() {
|
sendEmail() {
|
||||||
this.vnEmail.send('campaign-metrics', this.reportParams);
|
const path = `Clients/${this.client.id}/campaign-metrics-email`;
|
||||||
|
this.vnEmail.send(path, this.reportParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeGrouped(value) {
|
changeGrouped(value) {
|
||||||
|
|
|
@ -34,15 +34,16 @@ describe('Client', () => {
|
||||||
|
|
||||||
controller.showReport();
|
controller.showReport();
|
||||||
|
|
||||||
|
const clientId = controller.client.id;
|
||||||
const expectedParams = {
|
const expectedParams = {
|
||||||
recipientId: 1101,
|
recipientId: clientId,
|
||||||
from: now,
|
from: now,
|
||||||
to: now
|
to: now
|
||||||
};
|
};
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
const serializedParams = $httpParamSerializer(expectedParams);
|
||||||
const path = `api/report/campaign-metrics?${serializedParams}`;
|
const expectedPath = `api/Clients/${clientId}/campaign-metrics-pdf?${serializedParams}`;
|
||||||
|
|
||||||
expect(window.open).toHaveBeenCalledWith(path);
|
expect(window.open).toHaveBeenCalledWith(expectedPath);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,16 +54,10 @@ describe('Client', () => {
|
||||||
from: now,
|
from: now,
|
||||||
to: now
|
to: now
|
||||||
};
|
};
|
||||||
const expectedParams = {
|
const clientId = controller.client.id;
|
||||||
recipientId: 1101,
|
const expectedPath = `Clients/${clientId}/campaign-metrics-email`;
|
||||||
from: now,
|
|
||||||
to: now
|
|
||||||
};
|
|
||||||
|
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
$httpBackend.expect('POST', expectedPath).respond({});
|
||||||
const path = `email/campaign-metrics?${serializedParams}`;
|
|
||||||
|
|
||||||
$httpBackend.expect('GET', path).respond({});
|
|
||||||
controller.sendEmail();
|
controller.sendEmail();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
|
@ -77,13 +77,16 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onSendClientConsumption() {
|
onSendClientConsumption() {
|
||||||
const clientIds = this.checked.map(client => client.id);
|
const clientIds = this.checked.map(client => client.id);
|
||||||
const params = Object.assign({
|
const data = {
|
||||||
clientIds: clientIds
|
clients: clientIds,
|
||||||
}, this.campaign);
|
from: this.campaign.from,
|
||||||
|
to: this.campaign.to
|
||||||
|
};
|
||||||
|
|
||||||
this.$http.post('schedule/consumption', params)
|
const params = JSON.stringify(data);
|
||||||
|
this.$http.post('ClientConsumptionQueues', {params})
|
||||||
.then(() => this.$.filters.hide())
|
.then(() => this.$.filters.hide())
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Notifications sent!')));
|
.then(() => this.vnApp.showSuccess(this.$t('Notification sent!')));
|
||||||
}
|
}
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
exprBuilder(param, value) {
|
||||||
|
|
|
@ -61,7 +61,6 @@ describe('Client notification', () => {
|
||||||
|
|
||||||
controller.$.filters = {hide: () => {}};
|
controller.$.filters = {hide: () => {}};
|
||||||
controller.campaign = {
|
controller.campaign = {
|
||||||
id: 1,
|
|
||||||
from: new Date(),
|
from: new Date(),
|
||||||
to: new Date()
|
to: new Date()
|
||||||
};
|
};
|
||||||
|
@ -70,15 +69,16 @@ describe('Client notification', () => {
|
||||||
data[0].$checked = true;
|
data[0].$checked = true;
|
||||||
data[1].$checked = true;
|
data[1].$checked = true;
|
||||||
|
|
||||||
const params = Object.assign({
|
const args = Object.assign({
|
||||||
clientIds: [1101, 1102]
|
clients: [1101, 1102]
|
||||||
}, controller.campaign);
|
}, controller.campaign);
|
||||||
|
const params = JSON.stringify(args);
|
||||||
|
|
||||||
$httpBackend.expect('POST', `schedule/consumption`, params).respond(200, params);
|
$httpBackend.expect('POST', `ClientConsumptionQueues`, {params}).respond(200, params);
|
||||||
controller.onSendClientConsumption();
|
controller.onSendClientConsumption();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Notifications sent!');
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Notification sent!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,15 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
auto-load="true"
|
auto-load="true"
|
||||||
url="Samples/visible"
|
url="Samples/visible"
|
||||||
|
fields="[
|
||||||
|
'id',
|
||||||
|
'code',
|
||||||
|
'description',
|
||||||
|
'model',
|
||||||
|
'hasCompany',
|
||||||
|
'hasPreview',
|
||||||
|
'datepickerEnabled'
|
||||||
|
]"
|
||||||
data="samplesVisible"
|
data="samplesVisible"
|
||||||
order="description">
|
order="description">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
|
@ -77,7 +86,7 @@
|
||||||
<vn-button
|
<vn-button
|
||||||
disabled="!sampleType.selection.hasPreview"
|
disabled="!sampleType.selection.hasPreview"
|
||||||
label="Preview"
|
label="Preview"
|
||||||
ng-click="$ctrl.showPreview()">
|
ng-click="$ctrl.preview()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
class="cancel"
|
class="cancel"
|
||||||
|
|
|
@ -3,12 +3,13 @@ import Section from 'salix/components/section';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $, vnEmail) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.clientSample = {
|
this.clientSample = {
|
||||||
clientFk: this.$params.id,
|
clientFk: this.$params.id,
|
||||||
companyId: this.vnConfig.companyFk
|
companyId: this.vnConfig.companyFk
|
||||||
};
|
};
|
||||||
|
this.vnEmail = vnEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
get client() {
|
get client() {
|
||||||
|
@ -36,61 +37,86 @@ class Controller extends Section {
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.$.watcher.check();
|
this.$.watcher.check();
|
||||||
this.$.watcher.realSubmit().then(() =>
|
|
||||||
this.sendSample()
|
const validationMessage = this.validate();
|
||||||
);
|
if (validationMessage)
|
||||||
|
return this.vnApp.showError(this.$t(validationMessage));
|
||||||
|
|
||||||
|
this.$.watcher.realSubmit().then(() => this.send());
|
||||||
}
|
}
|
||||||
|
|
||||||
showPreview() {
|
validate() {
|
||||||
this.send(true, res => {
|
|
||||||
this.$.showPreview.show();
|
|
||||||
const dialog = document.body.querySelector('div.vn-dialog');
|
|
||||||
const body = dialog.querySelector('tpl-body');
|
|
||||||
const scroll = dialog.querySelector('div:first-child');
|
|
||||||
|
|
||||||
body.innerHTML = res.data;
|
|
||||||
scroll.scrollTop = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
sendSample() {
|
|
||||||
this.send(false, () => {
|
|
||||||
this.vnApp.showSuccess(this.$t('Notification sent!'));
|
|
||||||
this.$state.go('client.card.sample.index');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
send(isPreview, cb) {
|
|
||||||
const sampleType = this.$.sampleType.selection;
|
const sampleType = this.$.sampleType.selection;
|
||||||
const params = {
|
|
||||||
recipientId: this.$params.id,
|
|
||||||
recipient: this.clientSample.recipient,
|
|
||||||
replyTo: this.clientSample.replyTo
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!params.recipient)
|
if (!this.clientSample.recipient)
|
||||||
return this.vnApp.showError(this.$t('Email cannot be blank'));
|
return 'Email cannot be blank';
|
||||||
|
|
||||||
if (!sampleType)
|
if (!sampleType)
|
||||||
return this.vnApp.showError(this.$t('Choose a sample'));
|
return 'Choose a sample';
|
||||||
|
|
||||||
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
||||||
return this.vnApp.showError(this.$t('Choose a company'));
|
return 'Choose a company';
|
||||||
|
|
||||||
|
if (sampleType.datepickerEnabled && !this.clientSample.from)
|
||||||
|
return 'Choose a date';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setParams(params) {
|
||||||
|
const sampleType = this.$.sampleType.selection;
|
||||||
|
|
||||||
if (sampleType.hasCompany)
|
if (sampleType.hasCompany)
|
||||||
params.companyId = this.clientSample.companyFk;
|
params.companyId = this.clientSample.companyFk;
|
||||||
|
|
||||||
if (sampleType.datepickerEnabled && !this.clientSample.from)
|
|
||||||
return this.vnApp.showError(this.$t('Choose a date'));
|
|
||||||
|
|
||||||
if (sampleType.datepickerEnabled)
|
if (sampleType.datepickerEnabled)
|
||||||
params.from = this.clientSample.from;
|
params.from = this.clientSample.from;
|
||||||
|
}
|
||||||
|
|
||||||
let query = `email/${sampleType.code}`;
|
preview() {
|
||||||
if (isPreview)
|
const sampleType = this.$.sampleType.selection;
|
||||||
query = `email/${sampleType.code}/preview`;
|
|
||||||
|
|
||||||
this.$http.get(query, {params}).then(cb);
|
const params = {
|
||||||
|
recipientId: this.$params.id
|
||||||
|
};
|
||||||
|
|
||||||
|
const validationMessage = this.validate();
|
||||||
|
if (validationMessage)
|
||||||
|
return this.vnApp.showError(this.$t(validationMessage));
|
||||||
|
|
||||||
|
this.setParams(params);
|
||||||
|
|
||||||
|
const path = `${sampleType.model}/${this.$params.id}/${sampleType.code}-html`;
|
||||||
|
this.$http.get(path, {params})
|
||||||
|
.then(response => {
|
||||||
|
this.$.showPreview.show();
|
||||||
|
const dialog = document.body.querySelector('div.vn-dialog');
|
||||||
|
const body = dialog.querySelector('tpl-body');
|
||||||
|
const scroll = dialog.querySelector('div:first-child');
|
||||||
|
|
||||||
|
body.innerHTML = response.data;
|
||||||
|
scroll.scrollTop = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
send() {
|
||||||
|
const sampleType = this.$.sampleType.selection;
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
recipientId: this.client.id,
|
||||||
|
recipient: this.clientSample.recipient,
|
||||||
|
replyTo: this.clientSample.replyTo
|
||||||
|
};
|
||||||
|
|
||||||
|
const validationMessage = this.validate();
|
||||||
|
if (validationMessage)
|
||||||
|
return this.vnApp.showError(this.$t(validationMessage));
|
||||||
|
|
||||||
|
this.setParams(params);
|
||||||
|
|
||||||
|
const path = `${sampleType.model}/${this.$params.id}/${sampleType.code}-email`;
|
||||||
|
this.vnEmail.send(path, params)
|
||||||
|
.then(() => this.$state.go('client.card.sample.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
getWorkerEmail() {
|
getWorkerEmail() {
|
||||||
|
@ -103,7 +129,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$element', '$scope'];
|
Controller.$inject = ['$element', '$scope', 'vnEmail'];
|
||||||
|
|
||||||
ngModule.vnComponent('vnClientSampleCreate', {
|
ngModule.vnComponent('vnClientSampleCreate', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -40,6 +40,7 @@ describe('Client', () => {
|
||||||
$httpParamSerializer = _$httpParamSerializer_;
|
$httpParamSerializer = _$httpParamSerializer_;
|
||||||
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
|
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
|
||||||
controller = $componentController('vnClientSampleCreate', {$element, $scope});
|
controller = $componentController('vnClientSampleCreate', {$element, $scope});
|
||||||
|
controller._client = {id: 1101};
|
||||||
const element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
document.body.querySelector = () => {
|
document.body.querySelector = () => {
|
||||||
return {
|
return {
|
||||||
|
@ -48,14 +49,26 @@ describe('Client', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
// $httpBackend.expectGET('EmailUsers?filter=%7B%22where%22:%7B%7D%7D').respond();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('onSubmit()', () => {
|
describe('onSubmit()', () => {
|
||||||
it(`should call sendSample() method`, () => {
|
it(`should call send() method`, () => {
|
||||||
jest.spyOn(controller, 'sendSample');
|
controller.send = jest.fn();
|
||||||
|
|
||||||
|
controller.$.sampleType.selection = {
|
||||||
|
hasCompany: false,
|
||||||
|
code: 'MyReport',
|
||||||
|
model: 'Clients'
|
||||||
|
};
|
||||||
|
|
||||||
|
controller.clientSample = {
|
||||||
|
recipient: 'email@email'
|
||||||
|
};
|
||||||
|
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.sendSample).toHaveBeenCalledWith();
|
expect(controller.send).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,13 +78,14 @@ describe('Client', () => {
|
||||||
|
|
||||||
controller.$.sampleType.selection = {
|
controller.$.sampleType.selection = {
|
||||||
hasCompany: false,
|
hasCompany: false,
|
||||||
code: 'MyReport'
|
code: 'MyReport',
|
||||||
|
model: 'Clients'
|
||||||
};
|
};
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
recipientId: 1101
|
recipientId: 1101
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.send(false, () => {});
|
controller.send();
|
||||||
|
|
||||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
@ -85,7 +99,7 @@ describe('Client', () => {
|
||||||
recipient: 'client@email.com'
|
recipient: 'client@email.com'
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.send(false, () => {});
|
controller.send();
|
||||||
|
|
||||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
@ -102,84 +116,81 @@ describe('Client', () => {
|
||||||
recipient: 'client@email.com'
|
recipient: 'client@email.com'
|
||||||
};
|
};
|
||||||
|
|
||||||
controller.send(false, () => {});
|
controller.send();
|
||||||
|
|
||||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should perform an HTTP query without passing companyFk param`, () => {
|
it(`should perform an HTTP query without passing companyFk param`, () => {
|
||||||
|
$state.go = jest.fn();
|
||||||
|
|
||||||
controller.$.sampleType.selection = {
|
controller.$.sampleType.selection = {
|
||||||
hasCompany: false,
|
hasCompany: false,
|
||||||
code: 'MyReport'
|
code: 'my-report',
|
||||||
|
model: 'Clients'
|
||||||
};
|
};
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
recipientId: 1101,
|
recipientId: 1101,
|
||||||
recipient: 'client@email.com'
|
recipient: 'client@email.com'
|
||||||
};
|
};
|
||||||
const expectedParams = {
|
|
||||||
recipientId: 1101,
|
|
||||||
recipient: 'client@email.com'
|
|
||||||
};
|
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
|
||||||
|
|
||||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
|
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
||||||
controller.send(false, () => {});
|
$httpBackend.expect('POST', expectedPath).respond(true);
|
||||||
|
controller.send();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should perform an HTTP query passing companyFk param`, () => {
|
it(`should perform an HTTP query passing companyFk param`, () => {
|
||||||
|
$state.go = jest.fn();
|
||||||
|
|
||||||
controller.$.sampleType.selection = {
|
controller.$.sampleType.selection = {
|
||||||
hasCompany: true,
|
hasCompany: true,
|
||||||
code: 'MyReport'
|
code: 'my-report',
|
||||||
|
model: 'Clients'
|
||||||
};
|
};
|
||||||
controller.clientSample = {
|
controller.clientSample = {
|
||||||
recipientId: 1101,
|
recipientId: 1101,
|
||||||
recipient: 'client@email.com',
|
recipient: 'client@email.com',
|
||||||
companyFk: 442
|
companyFk: 442
|
||||||
};
|
};
|
||||||
const expectedParams = {
|
|
||||||
recipientId: 1101,
|
|
||||||
recipient: 'client@email.com',
|
|
||||||
companyId: 442
|
|
||||||
};
|
|
||||||
const serializedParams = $httpParamSerializer(expectedParams);
|
|
||||||
|
|
||||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
|
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
||||||
controller.send(false, () => {});
|
$httpBackend.expect('POST', expectedPath).respond(true);
|
||||||
|
controller.send();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('showPreview()', () => {
|
describe('preview()', () => {
|
||||||
it(`should open a sample preview`, () => {
|
it(`should open a sample preview`, () => {
|
||||||
jest.spyOn(controller.$.showPreview, 'show');
|
jest.spyOn(controller.$.showPreview, 'show');
|
||||||
|
|
||||||
controller.send = (isPreview, cb) => {
|
controller.$.sampleType.selection = {
|
||||||
cb({
|
hasCompany: true,
|
||||||
data: '<div></div>'
|
code: 'my-report',
|
||||||
});
|
model: 'Clients'
|
||||||
};
|
};
|
||||||
controller.showPreview();
|
controller.clientSample = {
|
||||||
|
recipientId: 1101,
|
||||||
|
recipient: 'client@email.com',
|
||||||
|
companyFk: 442
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedParams = {
|
||||||
|
companyId: 442,
|
||||||
|
recipientId: 1101
|
||||||
|
};
|
||||||
|
const serializedParams = $httpParamSerializer(expectedParams);
|
||||||
|
|
||||||
|
const expectedPath = `Clients/${controller.client.id}/my-report-html?${serializedParams}`;
|
||||||
|
$httpBackend.expect('GET', expectedPath).respond(true);
|
||||||
|
controller.preview();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.$.showPreview.show).toHaveBeenCalledWith();
|
expect(controller.$.showPreview.show).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sendSample()', () => {
|
|
||||||
it(`should perform a query (GET) and call go() method`, () => {
|
|
||||||
jest.spyOn(controller.$state, 'go');
|
|
||||||
|
|
||||||
controller.send = (isPreview, cb) => {
|
|
||||||
cb({
|
|
||||||
data: true
|
|
||||||
});
|
|
||||||
};
|
|
||||||
controller.sendSample();
|
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getWorkerEmail()', () => {
|
describe('getWorkerEmail()', () => {
|
||||||
it(`should perform a query and then set the replyTo property to the clientSample object`, () => {
|
it(`should perform a query and then set the replyTo property to the clientSample object`, () => {
|
||||||
const expectedEmail = 'batman@arkhamcity.com';
|
const expectedEmail = 'batman@arkhamcity.com';
|
||||||
|
|
|
@ -52,7 +52,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'size':
|
case 'size':
|
||||||
case 'density':
|
case 'weightByPiece':
|
||||||
case 'description':
|
case 'description':
|
||||||
case 'packingOut':
|
case 'packingOut':
|
||||||
modelName = 'Item';
|
modelName = 'Item';
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
const {Report} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('entryOrderPdf', {
|
||||||
|
description: 'Returns the entry order pdf',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipientId',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The recipient id',
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: [
|
||||||
|
{
|
||||||
|
arg: 'body',
|
||||||
|
type: 'file',
|
||||||
|
root: true
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Type',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}, {
|
||||||
|
arg: 'Content-Disposition',
|
||||||
|
type: 'String',
|
||||||
|
http: {target: 'header'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: '/:id/entry-order-pdf',
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.entryOrderPdf = async(ctx, id) => {
|
||||||
|
const args = Object.assign({}, ctx.args);
|
||||||
|
const params = {lang: ctx.req.getLocale()};
|
||||||
|
|
||||||
|
delete args.ctx;
|
||||||
|
for (const param in args)
|
||||||
|
params[param] = args[param];
|
||||||
|
|
||||||
|
const report = new Report('entry-order', params);
|
||||||
|
const stream = await report.toPdfStream();
|
||||||
|
|
||||||
|
return [stream, 'application/pdf', `filename="doc-${id}.pdf"`];
|
||||||
|
};
|
||||||
|
};
|
|
@ -157,7 +157,7 @@ module.exports = Self => {
|
||||||
i.image,
|
i.image,
|
||||||
i.id AS itemFk,
|
i.id AS itemFk,
|
||||||
i.size,
|
i.size,
|
||||||
i.density,
|
i.weightByPiece,
|
||||||
it.code,
|
it.code,
|
||||||
i.typeFk,
|
i.typeFk,
|
||||||
i.family,
|
i.family,
|
||||||
|
|
|
@ -6,4 +6,5 @@ module.exports = Self => {
|
||||||
require('../methods/entry/importBuys')(Self);
|
require('../methods/entry/importBuys')(Self);
|
||||||
require('../methods/entry/importBuysPreview')(Self);
|
require('../methods/entry/importBuysPreview')(Self);
|
||||||
require('../methods/entry/lastItemBuys')(Self);
|
require('../methods/entry/lastItemBuys')(Self);
|
||||||
|
require('../methods/entry/entryOrderPdf')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -86,9 +86,7 @@ class Controller extends Descriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
showEntryReport() {
|
showEntryReport() {
|
||||||
this.vnReport.show('entry-order', {
|
this.vnReport.show(`Entries/${this.id}/entry-order-pdf`);
|
||||||
entryId: this.entry.id
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,10 @@ describe('Entry Component vnEntryDescriptor', () => {
|
||||||
jest.spyOn(controller.vnReport, 'show');
|
jest.spyOn(controller.vnReport, 'show');
|
||||||
|
|
||||||
window.open = jasmine.createSpy('open');
|
window.open = jasmine.createSpy('open');
|
||||||
const params = {
|
|
||||||
clientId: controller.vnConfig.storage.currentUserWorkerId,
|
|
||||||
entryId: entry.id
|
|
||||||
};
|
|
||||||
controller.showEntryReport();
|
controller.showEntryReport();
|
||||||
|
const expectedPath = `Entries/${entry.id}/entry-order-pdf`;
|
||||||
|
|
||||||
expect(controller.vnReport.show).toHaveBeenCalledWith('entry-order', params);
|
expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,8 @@
|
||||||
<th field="origin">
|
<th field="origin">
|
||||||
<span translate>Origin</span>
|
<span translate>Origin</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="density">
|
<th field="weightByPiece">
|
||||||
<span translate>Density</span>
|
<span translate>Weight/Piece</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="isActive">
|
<th field="isActive">
|
||||||
<span translate>Active</span>
|
<span translate>Active</span>
|
||||||
|
@ -183,7 +183,7 @@
|
||||||
{{::buy.intrastat}}
|
{{::buy.intrastat}}
|
||||||
</td>
|
</td>
|
||||||
<td>{{::buy.origin}}</td>
|
<td>{{::buy.origin}}</td>
|
||||||
<td>{{::buy.density}}</td>
|
<td>{{::buy.weightByPiece}}</td>
|
||||||
<td>
|
<td>
|
||||||
<vn-check
|
<vn-check
|
||||||
disabled="true"
|
disabled="true"
|
||||||
|
|
|
@ -80,7 +80,7 @@ export default class Controller extends Section {
|
||||||
{field: 'weight', displayName: this.$t('Weight')},
|
{field: 'weight', displayName: this.$t('Weight')},
|
||||||
{field: 'description', displayName: this.$t('Description')},
|
{field: 'description', displayName: this.$t('Description')},
|
||||||
{field: 'size', displayName: this.$t('Size')},
|
{field: 'size', displayName: this.$t('Size')},
|
||||||
{field: 'density', displayName: this.$t('Density')},
|
{field: 'weightByPiece', displayName: this.$t('weight/Piece')},
|
||||||
{field: 'packingOut', displayName: this.$t('PackingOut')},
|
{field: 'packingOut', displayName: this.$t('PackingOut')},
|
||||||
{field: 'landing', displayName: this.$t('Landing')}
|
{field: 'landing', displayName: this.$t('Landing')}
|
||||||
];
|
];
|
||||||
|
@ -103,7 +103,7 @@ export default class Controller extends Section {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'id':
|
case 'id':
|
||||||
case 'size':
|
case 'size':
|
||||||
case 'density':
|
case 'weightByPiece':
|
||||||
case 'isActive':
|
case 'isActive':
|
||||||
case 'family':
|
case 'family':
|
||||||
case 'minPrice':
|
case 'minPrice':
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
const fs = require('fs-extra');
|
const print = require('vn-print');
|
||||||
const path = require('path');
|
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('createPdf', {
|
Self.remoteMethodCtx('createPdf', {
|
||||||
|
@ -27,9 +25,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.createPdf = async function(ctx, id, options) {
|
Self.createPdf = async function(ctx, id, options) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const headers = ctx.req.headers;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const origin = headers.origin;
|
|
||||||
const auth = ctx.req.accessToken;
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV == 'test')
|
if (process.env.NODE_ENV == 'test')
|
||||||
throw new UserError(`Action not allowed on the test environment`);
|
throw new UserError(`Action not allowed on the test environment`);
|
||||||
|
@ -45,10 +41,9 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileSrc;
|
|
||||||
try {
|
try {
|
||||||
const invoiceOut = await Self.findById(id, null, myOptions);
|
const invoiceOut = await Self.findById(id, null, myOptions);
|
||||||
const hasInvoicing = await models.Account.hasRole(auth.userId, 'invoicing', myOptions);
|
const hasInvoicing = await models.Account.hasRole(userId, 'invoicing', myOptions);
|
||||||
|
|
||||||
if (invoiceOut.hasPdf && !hasInvoicing)
|
if (invoiceOut.hasPdf && !hasInvoicing)
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
@ -57,35 +52,27 @@ module.exports = Self => {
|
||||||
hasPdf: true
|
hasPdf: true
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
return axios.get(`${origin}/api/report/invoice`, {
|
const invoiceReport = new print.Report('invoice', {
|
||||||
responseType: 'stream',
|
reference: invoiceOut.ref,
|
||||||
params: {
|
recipientId: invoiceOut.clientFk
|
||||||
authorization: auth.id,
|
|
||||||
refFk: invoiceOut.ref
|
|
||||||
}
|
|
||||||
}).then(async response => {
|
|
||||||
const issued = invoiceOut.issued;
|
|
||||||
const year = issued.getFullYear().toString();
|
|
||||||
const month = (issued.getMonth() + 1).toString();
|
|
||||||
const day = issued.getDate().toString();
|
|
||||||
|
|
||||||
const container = await models.InvoiceContainer.container(year);
|
|
||||||
const rootPath = container.client.root;
|
|
||||||
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
|
||||||
const src = path.join(rootPath, year, month, day);
|
|
||||||
fileSrc = path.join(src, fileName);
|
|
||||||
|
|
||||||
await fs.mkdir(src, {recursive: true});
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
|
|
||||||
response.data.pipe(fs.createWriteStream(fileSrc));
|
|
||||||
}).catch(async e => {
|
|
||||||
if (fs.existsSync(fileSrc))
|
|
||||||
await fs.unlink(fileSrc);
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
});
|
});
|
||||||
|
const stream = await invoiceReport.toPdfStream();
|
||||||
|
|
||||||
|
const issued = invoiceOut.issued;
|
||||||
|
const year = issued.getFullYear().toString();
|
||||||
|
const month = (issued.getMonth() + 1).toString();
|
||||||
|
const day = issued.getDate().toString();
|
||||||
|
|
||||||
|
const fileName = `${year}${invoiceOut.ref}.pdf`;
|
||||||
|
|
||||||
|
// Store invoice
|
||||||
|
print.storage.write(stream, {
|
||||||
|
type: 'invoice',
|
||||||
|
path: `${year}/${month}/${day}`,
|
||||||
|
fileName: fileName
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -62,8 +62,14 @@ module.exports = Self => {
|
||||||
name: fileName
|
name: fileName
|
||||||
};
|
};
|
||||||
|
|
||||||
await fs.access(file.path);
|
try {
|
||||||
let stream = fs.createReadStream(file.path);
|
await fs.access(file.path);
|
||||||
|
} catch (error) {
|
||||||
|
await Self.createPdf(ctx, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const stream = fs.createReadStream(file.path);
|
||||||
|
|
||||||
return [stream, file.contentType, `filename="${file.name}"`];
|
return [stream, file.contentType, `filename="${file.name}"`];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT')
|
if (error.code === 'ENOENT')
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue