Merge branch '4153-supplier.fiscal-data' of https://gitea.verdnatura.es/verdnatura/salix into 4153-supplier.fiscal-data
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
b1a792eb2d
|
@ -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 => {
|
||||
const tx = await Self.beginTransaction({});
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction)
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
|
@ -61,10 +63,9 @@ module.exports = Self => {
|
|||
const dstFolder = path.join(dmsContainer.client.root, pathHash);
|
||||
try {
|
||||
await fs.rmdir(dstFolder);
|
||||
await dms.destroy(myOptions);
|
||||
} catch (err) {
|
||||
await dms.destroy(myOptions);
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
await dms.destroy(myOptions);
|
||||
}
|
||||
if (tx) await tx.commit();
|
||||
} 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": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"PrintConfig": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
|||
require('../methods/account/change-password')(Self);
|
||||
require('../methods/account/set-password')(Self);
|
||||
require('../methods/account/validate-token')(Self);
|
||||
require('../methods/account/privileges')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
},
|
||||
"image": {
|
||||
"type": "string"
|
||||
},
|
||||
"hasGrant": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/osticket/osTicketReportEmail')(Self);
|
||||
require('../methods/osticket/closeTicket')(Self);
|
||||
};
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
{
|
||||
"name": "OsTicket",
|
||||
"base": "VnModel",
|
||||
"acls": [{
|
||||
"property": "validations",
|
||||
"accessType": "EXECUTE",
|
||||
"principalType": "ROLE",
|
||||
"principalId": "$everyone",
|
||||
"permission": "ALLOW"
|
||||
}]
|
||||
"base": "VnModel"
|
||||
}
|
||||
|
|
@ -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);
|
||||
});
|
||||
|
||||
process.on('exit', async function() {
|
||||
if (container) await container.rm();
|
||||
});
|
||||
|
||||
let container;
|
||||
async function test() {
|
||||
let isCI = false;
|
||||
|
||||
if (process.argv[2] === 'ci')
|
||||
isCI = true;
|
||||
|
||||
const container = new Docker();
|
||||
container = new Docker();
|
||||
|
||||
await container.run(isCI);
|
||||
dataSources = JSON.parse(JSON.stringify(dataSources));
|
||||
|
@ -46,6 +51,7 @@ async function test() {
|
|||
jasmine.addReporter(new JunitReporter.JUnitXmlReporter());
|
||||
|
||||
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
jasmine.exitOnCompletion = true;
|
||||
}
|
||||
|
||||
const backSpecs = [
|
||||
|
@ -60,11 +66,10 @@ async function test() {
|
|||
helpers: [],
|
||||
});
|
||||
|
||||
jasmine.exitOnCompletion = false;
|
||||
await jasmine.execute();
|
||||
if (app) await app.disconnect();
|
||||
if (container) await container.rm();
|
||||
console.log('app disconnected & container removed');
|
||||
console.log('App disconnected & container removed');
|
||||
}
|
||||
|
||||
test();
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
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)
|
||||
VALUES ('Sector','*','READ','ALLOW','ROLE','employee');
|
||||
INSERT INTO `salix`.`ACL` (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Sector','*','WRITE','ALLOW','ROLE','employee');
|
|
@ -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.
|
||||
*
|
||||
* @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 pad = v => v < 10 ? '0' + v : v;
|
||||
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 network = '';
|
||||
if (ci) network = `--network="${networkName}"`;
|
||||
|
||||
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();
|
||||
|
||||
try {
|
||||
|
@ -51,10 +60,11 @@ module.exports = class Docker {
|
|||
let inspect = await this.execP(`docker inspect -f "{{json .NetworkSettings}}" ${this.id}`);
|
||||
let netSettings = JSON.parse(inspect.stdout);
|
||||
|
||||
if (ci)
|
||||
this.dbConf.host = netSettings.Gateway;
|
||||
|
||||
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
||||
if (ci) {
|
||||
this.dbConf.host = netSettings.Networks[networkName].IPAddress;
|
||||
this.dbConf.port = 3306;
|
||||
} else
|
||||
this.dbConf.port = netSettings.Ports['3306/tcp'][0]['HostPort'];
|
||||
}
|
||||
|
||||
await this.wait();
|
||||
|
|
|
@ -13,6 +13,10 @@ INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`)
|
|||
VALUES
|
||||
('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`)
|
||||
VALUES
|
||||
('1', '6');
|
||||
|
@ -862,25 +866,25 @@ INSERT INTO `vn`.`itemFamily`(`code`, `description`)
|
|||
('VT', 'Sales');
|
||||
|
||||
INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `expenceFk`,
|
||||
`comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`)
|
||||
`comment`, `relevancy`, `image`, `subName`, `minPrice`, `stars`, `family`, `isFloramondo`, `genericFk`, `itemPackingTypeFk`, `hasMinPrice`, `packingShelve`, `weightByPiece`)
|
||||
VALUES
|
||||
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'VT', 0, NULL, 'V', 0, 15),
|
||||
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0, 10),
|
||||
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, 5),
|
||||
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL),
|
||||
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL),
|
||||
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1, NULL),
|
||||
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL),
|
||||
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL),
|
||||
(16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL),
|
||||
(71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0, NULL);
|
||||
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '1', NULL, 0, 1, 'VT', 0, NULL, 'V', 0, 15,3),
|
||||
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '2', NULL, 0, 2, 'VT', 0, NULL, 'H', 0, 10,2),
|
||||
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '3', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, 5,5),
|
||||
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 4751000000, NULL, 0, '4', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '5', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '6', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '7', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 2000000000, NULL, 0, '8', NULL, 0, 5, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 2000000000, NULL, 0, '9', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL),
|
||||
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 4751000000, NULL, 0, '10', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 4751000000, NULL, 0, '11', NULL, 0, 4, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 4751000000, NULL, 0, '12', NULL, 0, 3, 'VT', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '13', NULL, 1, 2, 'VT', 1, NULL, NULL, 1, NULL,NULL),
|
||||
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 4, 'VT', 1, NULL, NULL, 0, NULL,NULL),
|
||||
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(16, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'EMB', 0, NULL, NULL, 0, NULL,NULL),
|
||||
(71, 6, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 0, 'VT', 0, NULL, NULL, 0, NULL,NULL);
|
||||
|
||||
-- Update the taxClass after insert of the items
|
||||
UPDATE `vn`.`itemTaxCountry` SET `taxClassFk` = 2
|
||||
|
@ -916,16 +920,19 @@ INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`)
|
|||
|
||||
INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `created`, `itemFk`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`)
|
||||
VALUES
|
||||
(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),
|
||||
(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),
|
||||
(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),
|
||||
(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),
|
||||
(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);
|
||||
(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),
|
||||
(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),
|
||||
(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),
|
||||
(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),
|
||||
(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),
|
||||
(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`)
|
||||
|
@ -1778,6 +1785,11 @@ INSERT INTO `vn`.`claimEnd`(`id`, `saleFk`, `claimFk`, `workerFk`, `claimDestina
|
|||
(1, 31, 4, 21, 2),
|
||||
(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`)
|
||||
VALUES
|
||||
(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`)
|
||||
VALUES
|
||||
(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: {
|
||||
menuButton: 'vn-user-descriptor vn-icon-button[icon="more_vert"]',
|
||||
deleteAccount: '.vn-menu [name="deleteUser"]',
|
||||
changeRole: '.vn-menu [name="changeRole"]',
|
||||
setPassword: '.vn-menu [name="setPassword"]',
|
||||
activateAccount: '.vn-menu [name="enableAccount"]',
|
||||
activateUser: '.vn-menu [name="activateUser"]',
|
||||
deactivateUser: '.vn-menu [name="deactivateUser"]',
|
||||
newPassword: 'vn-textfield[ng-model="$ctrl.newPassword"]',
|
||||
repeatPassword: 'vn-textfield[ng-model="$ctrl.repeatPassword"]',
|
||||
newRole: 'vn-autocomplete[ng-model="$ctrl.newRole"]',
|
||||
activeAccountIcon: 'vn-icon[icon="contact_mail"]',
|
||||
activeUserIcon: 'vn-icon[icon="icon-disabled"]',
|
||||
acceptButton: 'button[response="accept"]',
|
||||
|
@ -143,6 +141,11 @@ export default {
|
|||
verifyCert: 'vn-account-samba vn-check[ng-model="$ctrl.config.verifyCert"]',
|
||||
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: {
|
||||
createClientButton: `vn-float-button`
|
||||
},
|
||||
|
@ -391,7 +394,7 @@ export default {
|
|||
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"]',
|
||||
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'
|
||||
},
|
||||
itemFixedPrice: {
|
||||
|
@ -835,14 +838,16 @@ export default {
|
|||
confirmButton: '.vn-confirm.shown button[response="accept"]',
|
||||
},
|
||||
routeIndex: {
|
||||
anyResult: 'vn-table a',
|
||||
firstRouteCheckbox: 'a:nth-child(1) vn-td:nth-child(1) > vn-check',
|
||||
anyResult: 'vn-route-index tbody > tr',
|
||||
firstRouteCheckbox: 'vn-route-index tbody > tr:nth-child(1) > td:nth-child(1) > vn-check',
|
||||
addNewRouteButton: 'vn-route-index a[ui-sref="route.create"]',
|
||||
cloneButton: 'vn-route-index button > vn-icon[icon="icon-clone"]',
|
||||
submitClonationButton: 'tpl-buttons > button[response="accept"]',
|
||||
openAdvancedSearchButton: 'vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
|
||||
searchAgencyAutocomlete: 'vn-route-search-panel vn-autocomplete[ng-model="filter.agencyModeFk"]',
|
||||
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: {
|
||||
worker: 'vn-route-create vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
||||
|
@ -862,6 +867,8 @@ export default {
|
|||
firstTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor',
|
||||
firstAlias: 'vn-route-summary vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(3) > span',
|
||||
firstClientDescriptor: '.vn-popover.shown vn-client-descriptor',
|
||||
goToRouteSummaryButton: 'vn-route-summary > vn-card > h5 > a',
|
||||
|
||||
},
|
||||
routeBasicData: {
|
||||
worker: 'vn-route-basic-data vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
|
||||
|
@ -1015,8 +1022,8 @@ export default {
|
|||
},
|
||||
travelExtraCommunity: {
|
||||
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"]',
|
||||
firstTravelLockedKg: 'vn-travel-extra-community tbody:nth-child(2) vn-input-number[ng-model="travel.kg"]',
|
||||
firstTravelReference: 'vn-travel-extra-community tbody:nth-child(2) vn-td-editable[name="reference"]',
|
||||
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'
|
||||
},
|
||||
travelBasicData: {
|
||||
|
|
|
@ -8,7 +8,7 @@ describe('Client Edit web access path', () => {
|
|||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('employee', 'client');
|
||||
await page.loginAndModule('salesPerson', 'client');
|
||||
await page.accessToSearchResult('max');
|
||||
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.originCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.densityCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.weightByPieceCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
|
@ -64,7 +64,7 @@ describe('Item index path', () => {
|
|||
await page.waitToClick(selectors.itemsIndex.intrastadCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.originCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.buyerCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.densityCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.weightByPieceCheckbox);
|
||||
await page.waitToClick(selectors.itemsIndex.saveFieldsButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ describe('Route summary path', () => {
|
|||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
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() => {
|
||||
|
@ -34,6 +35,8 @@ describe('Route summary path', () => {
|
|||
});
|
||||
|
||||
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.waitForSelector(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() => {
|
||||
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
||||
await page.waitForSpinnerLoad();
|
||||
await page.clearInput(selectors.travelExtraCommunity.firstTravelReference);
|
||||
await page.write(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
||||
await page.clearInput(selectors.travelExtraCommunity.firstTravelLockedKg);
|
||||
await page.write(selectors.travelExtraCommunity.firstTravelLockedKg, '1500');
|
||||
await page.writeOnEditableTD(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
||||
await page.waitForSpinnerLoad();
|
||||
await page.writeOnEditableTD(selectors.travelExtraCommunity.firstTravelLockedKg, '1500');
|
||||
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Data saved!');
|
||||
|
@ -32,9 +32,9 @@ describe('Travel extra community path', () => {
|
|||
await page.accessToSection('travel.index');
|
||||
await page.accessToSection('travel.extraCommunity');
|
||||
await page.waitToClick(selectors.travelExtraCommunity.removeContinentFilter);
|
||||
|
||||
const reference = await page.waitToGetProperty(selectors.travelExtraCommunity.firstTravelReference, 'value');
|
||||
const lockedKg = await page.waitToGetProperty(selectors.travelExtraCommunity.firstTravelLockedKg, 'value');
|
||||
await page.waitForTextInElement(selectors.travelExtraCommunity.firstTravelReference, 'edited reference');
|
||||
const reference = await page.getProperty(selectors.travelExtraCommunity.firstTravelReference, 'innerText');
|
||||
const lockedKg = await page.getProperty(selectors.travelExtraCommunity.firstTravelLockedKg, 'innerText');
|
||||
|
||||
expect(reference).toContain('edited reference');
|
||||
expect(lockedKg).toContain(1500);
|
||||
|
|
|
@ -62,27 +62,6 @@ describe('Account create and basic data path', () => {
|
|||
});
|
||||
|
||||
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', () => {
|
||||
it(`should check the active account icon isn't present in the descriptor`, async() => {
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -23,12 +23,15 @@ export default class InputTime extends Field {
|
|||
let date = null;
|
||||
let value = this.input.value;
|
||||
|
||||
if (this.field && !this.modelDate)
|
||||
this.modelDate = this.field;
|
||||
|
||||
if (value) {
|
||||
let split = value.split(':').map(i => parseInt(i) || null);
|
||||
|
||||
date = this.field instanceof Date
|
||||
? this.field
|
||||
: new Date(this.field || null);
|
||||
date = this.modelDate
|
||||
? new Date(this.modelDate)
|
||||
: new Date();
|
||||
date.setHours(split[0], split[1], 0, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,24 +10,12 @@ class Email {
|
|||
/**
|
||||
* 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
|
||||
* @return {Promise} Promise resolved when it's sent
|
||||
*/
|
||||
send(template, params) {
|
||||
return this.$http.get(`email/${template}`, {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})
|
||||
send(path, params) {
|
||||
return this.$http.post(path, params)
|
||||
.then(() => this.vnApp.showMessage(this.$t('Notification sent!')));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,30 +10,16 @@ class Report {
|
|||
* Shows a report in another window, automatically adds the authorization
|
||||
* token to params.
|
||||
*
|
||||
* @param {String} report The report name
|
||||
* @param {String} path The report name
|
||||
* @param {Object} params The report parameters
|
||||
*/
|
||||
show(report, params) {
|
||||
show(path, params) {
|
||||
params = Object.assign({
|
||||
authorization: this.vnToken.token
|
||||
access_token: this.vnToken.token
|
||||
}, params);
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
window.open(`api/report/${report}?${serializedParams}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}`);
|
||||
const query = serializedParams ? `?${serializedParams}` : '';
|
||||
window.open(`api/${path}${query}`);
|
||||
}
|
||||
}
|
||||
Report.$inject = ['$httpParamSerializer', 'vnToken'];
|
||||
|
|
|
@ -1,78 +1,215 @@
|
|||
{
|
||||
"name": "salix-front",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"lockfileVersion": 2,
|
||||
"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": {
|
||||
"@uirouter/angularjs": {
|
||||
"version": "1.0.29",
|
||||
"resolved": "https://registry.npmjs.org/@uirouter/angularjs/-/angularjs-1.0.29.tgz",
|
||||
"integrity": "sha512-RImWnBarNixkMto0o8stEaGwZmvhv5cnuOLXyMU2pY8MP2rgEF74ZNJTLeJCW14LR7XDUxVH8Mk8bPI6lxedmQ==",
|
||||
"requires": {
|
||||
"@uirouter/core": "6.0.7"
|
||||
}
|
||||
},
|
||||
"@uirouter/core": {
|
||||
"version": "6.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@uirouter/core/-/core-6.0.7.tgz",
|
||||
"integrity": "sha512-KUTJxL+6q0PiBnFx4/Z+Hsyg0pSGiaW5yZQeJmUxknecjpTbnXkLU8H2EqRn9N2B+qDRa7Jg8RcgeNDPY72O1w=="
|
||||
"version": "6.0.7"
|
||||
},
|
||||
"angular": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/angular/-/angular-1.8.2.tgz",
|
||||
"integrity": "sha512-IauMOej2xEe7/7Ennahkbb5qd/HFADiNuLSESz9Q27inmi32zB0lnAsFeLEWcox3Gd1F6YhNd1CP7/9IukJ0Gw=="
|
||||
"version": "1.8.2"
|
||||
},
|
||||
"angular-animate": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/angular-animate/-/angular-animate-1.8.2.tgz",
|
||||
"integrity": "sha512-Jbr9+grNMs9Kj57xuBU3Ju3NOPAjS1+g2UAwwDv7su1lt0/PLDy+9zEwDiu8C8xJceoTbmBNKiWGPJGBdCQLlA=="
|
||||
"version": "1.8.2"
|
||||
},
|
||||
"angular-moment": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/angular-moment/-/angular-moment-1.3.0.tgz",
|
||||
"integrity": "sha512-KG8rvO9MoaBLwtGnxTeUveSyNtrL+RNgGl1zqWN36+HDCCVGk2DGWOzqKWB6o+eTTbO3Opn4hupWKIElc8XETA==",
|
||||
"requires": {
|
||||
"moment": ">=2.8.0 <3.0.0"
|
||||
}
|
||||
},
|
||||
"angular-translate": {
|
||||
"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": {
|
||||
"angular": "^1.8.0"
|
||||
}
|
||||
},
|
||||
"angular-translate-loader-partial": {
|
||||
"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": {
|
||||
"angular-translate": "~2.18.4"
|
||||
}
|
||||
},
|
||||
"argparse": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
|
||||
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
|
||||
"requires": {
|
||||
"sprintf-js": "~1.0.2"
|
||||
}
|
||||
},
|
||||
"croppie": {
|
||||
"version": "2.6.5",
|
||||
"resolved": "https://registry.npmjs.org/croppie/-/croppie-2.6.5.tgz",
|
||||
"integrity": "sha512-IlChnVUGG5T3w2gRZIaQgBtlvyuYnlUWs2YZIXXR3H9KrlO1PtBT3j+ykxvy9eZIWhk+V5SpBmhCQz5UXKrEKQ=="
|
||||
"version": "2.6.5"
|
||||
},
|
||||
"esprima": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
||||
"version": "4.0.1"
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "3.14.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
|
||||
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
|
||||
"requires": {
|
||||
"argparse": "^1.0.7",
|
||||
"esprima": "^4.0.0"
|
||||
|
@ -80,39 +217,27 @@
|
|||
},
|
||||
"mg-crud": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/mg-crud/-/mg-crud-1.1.2.tgz",
|
||||
"integrity": "sha1-p6AWGzWSPK7/8ZpIBpS2V1vDggw=",
|
||||
"requires": {
|
||||
"angular": "^1.6.1"
|
||||
}
|
||||
},
|
||||
"moment": {
|
||||
"version": "2.29.1",
|
||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
|
||||
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
|
||||
"version": "2.29.1"
|
||||
},
|
||||
"oclazyload": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/oclazyload/-/oclazyload-0.6.3.tgz",
|
||||
"integrity": "sha1-Kjirv/QJDAihEBZxkZRbWfLoJ5w="
|
||||
"version": "0.6.3"
|
||||
},
|
||||
"require-yaml": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/require-yaml/-/require-yaml-0.0.1.tgz",
|
||||
"integrity": "sha1-LhsY2RPDuqcqWk03O28Tjd0sMr0=",
|
||||
"requires": {
|
||||
"js-yaml": "^4.1.0"
|
||||
"js-yaml": ""
|
||||
},
|
||||
"dependencies": {
|
||||
"argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
|
||||
"version": "2.0.1"
|
||||
},
|
||||
"js-yaml": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
|
||||
"integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
|
||||
"requires": {
|
||||
"argparse": "^2.0.1"
|
||||
}
|
||||
|
@ -120,14 +245,10 @@
|
|||
}
|
||||
},
|
||||
"sprintf-js": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
|
||||
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
|
||||
"version": "1.0.3"
|
||||
},
|
||||
"validator": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-6.3.0.tgz",
|
||||
"integrity": "sha1-R84j7Y1Ord+p1LjvAHG2zxB418g="
|
||||
"version": "6.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,5 +131,7 @@
|
|||
"Fichadas impares": "Odd signs",
|
||||
"Descanso diario 9h.": "Daily rest 9h.",
|
||||
"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",
|
||||
"Concept cannot be blank": "El concepto no puede quedar en blanco",
|
||||
"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",
|
||||
"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",
|
||||
|
@ -232,5 +232,8 @@
|
|||
"Fichadas impares": "Fichadas impares",
|
||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||
"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) {
|
||||
require('../../../print/boot.js')(app);
|
||||
require('vn-print').boot(app);
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/webp",
|
||||
"video/mp4"
|
||||
]
|
||||
},
|
||||
|
@ -60,7 +61,8 @@
|
|||
"multipart/x-zip",
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/jpg"
|
||||
"image/jpg",
|
||||
"image/webp"
|
||||
]
|
||||
},
|
||||
"imageStorage": {
|
||||
|
@ -72,7 +74,8 @@
|
|||
"allowedContentTypes": [
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/jpg"
|
||||
"image/jpg",
|
||||
"image/webp"
|
||||
]
|
||||
},
|
||||
"invoiceStorage": {
|
||||
|
@ -96,6 +99,7 @@
|
|||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/jpg",
|
||||
"image/webp",
|
||||
"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) {
|
||||
const [columns] = rows;
|
||||
let content = Object.keys(columns).join('\t');
|
|
@ -11,14 +11,6 @@
|
|||
translate>
|
||||
Delete
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="$ctrl.onChangeRole()"
|
||||
name="changeRole"
|
||||
vn-acl="hr"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Change role
|
||||
</vn-item>
|
||||
<vn-item
|
||||
ng-if="::$root.user.id == $ctrl.id"
|
||||
ng-click="$ctrl.onChangePassClick(true)"
|
||||
|
@ -128,22 +120,6 @@
|
|||
question="Are you sure you want to continue?"
|
||||
message="User will be deactivated">
|
||||
</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-id="changePass"
|
||||
on-accept="$ctrl.onPassChange()"
|
||||
|
|
|
@ -30,20 +30,6 @@ class Controller extends Descriptor {
|
|||
.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) {
|
||||
this.$http.get('UserPasswords/findOne')
|
||||
.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()', () => {
|
||||
it('should throw an error when password is empty', () => {
|
||||
expect(() => {
|
||||
|
|
|
@ -18,3 +18,4 @@ import './roles';
|
|||
import './ldap';
|
||||
import './samba';
|
||||
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.roles", "icon": "group"},
|
||||
{"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": [
|
||||
{"state": "account.role.card.basicData", "icon": "settings"},
|
||||
|
@ -99,6 +100,13 @@
|
|||
"description": "Mail aliases",
|
||||
"acl": ["marketing", "hr"]
|
||||
},
|
||||
{
|
||||
"url": "/privileges",
|
||||
"state": "account.card.privileges",
|
||||
"component": "vn-user-privileges",
|
||||
"description": "Privileges",
|
||||
"acl": ["hr"]
|
||||
},
|
||||
{
|
||||
"url": "/role?q",
|
||||
"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/updateClaimDestination')(Self);
|
||||
require('../methods/claim/downloadFile')(Self);
|
||||
require('../methods/claim/claimPickupPdf')(Self);
|
||||
require('../methods/claim/claimPickupEmail')(Self);
|
||||
};
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
</vn-item>
|
||||
<vn-item
|
||||
ng-click="confirmPickupOrder.show()"
|
||||
vn-acl="salesPerson"
|
||||
vn-acl-action="remove"
|
||||
translate>
|
||||
Send Pickup order
|
||||
</vn-item>
|
||||
|
|
|
@ -11,17 +11,15 @@ class Controller extends Descriptor {
|
|||
}
|
||||
|
||||
showPickupOrder() {
|
||||
this.vnReport.show('claim-pickup-order', {
|
||||
recipientId: this.claim.clientFk,
|
||||
claimId: this.claim.id
|
||||
this.vnReport.show(`Claims/${this.claim.id}/claim-pickup-pdf`, {
|
||||
recipientId: this.claim.clientFk
|
||||
});
|
||||
}
|
||||
|
||||
sendPickupOrder() {
|
||||
return this.vnEmail.send('claim-pickup-order', {
|
||||
return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, {
|
||||
recipient: this.claim.client.email,
|
||||
recipientId: this.claim.clientFk,
|
||||
claimId: this.claim.id
|
||||
recipientId: this.claim.clientFk
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,13 @@ describe('Item Component vnClaimDescriptor', () => {
|
|||
|
||||
window.open = jasmine.createSpy('open');
|
||||
const params = {
|
||||
recipientId: claim.clientFk,
|
||||
claimId: claim.id
|
||||
recipientId: claim.clientFk
|
||||
};
|
||||
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 = {
|
||||
recipient: claim.client.email,
|
||||
recipientId: claim.clientFk,
|
||||
claimId: claim.id
|
||||
recipientId: claim.clientFk
|
||||
};
|
||||
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 => {
|
||||
Self.remoteMethod('setPassword', {
|
||||
Self.remoteMethodCtx('setPassword', {
|
||||
description: 'Sets the password of a non-worker client',
|
||||
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 userId = ctx.req.accessToken.userId;
|
||||
|
||||
const isWorker = await models.Worker.findById(id);
|
||||
if (isWorker)
|
||||
throw new Error(`Can't change the password of another worker`);
|
||||
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
|
||||
|
||||
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;
|
||||
|
||||
describe('Client setPassword', () => {
|
||||
it('should throw an error the setPassword target is not just a client but a worker', async() => {
|
||||
let error;
|
||||
const salesPersonId = 19;
|
||||
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 {
|
||||
await models.Client.setPassword(1106, 'newPass?');
|
||||
await models.Client.setPassword(ctx, 1, 't0pl3v3l.p455w0rd!');
|
||||
} catch (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() => {
|
||||
let error;
|
||||
|
||||
try {
|
||||
await models.Client.setPassword(1101, 't0pl3v3l.p455w0rd!');
|
||||
await models.Client.setPassword(ctx, 1101, 't0pl3v3l.p455w0rd!');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ describe('Client updateUser', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
const salesPersonId = 19;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: employeeId}},
|
||||
req: {accessToken: {userId: salesPersonId}},
|
||||
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;
|
||||
const employeeId = 1;
|
||||
const ctx = {
|
||||
req: {accessToken: {userId: employeeId}},
|
||||
args: {name: 'test', active: true}
|
||||
};
|
||||
try {
|
||||
const clientID = 1106;
|
||||
await models.Client.updateUser(ctx, clientID);
|
||||
|
@ -30,7 +36,19 @@ describe('Client updateUser', () => {
|
|||
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() => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('updateUser', {
|
||||
description: 'Updates the user information',
|
||||
|
@ -5,8 +6,7 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
description: 'The user id',
|
||||
http: {source: 'path'}
|
||||
description: 'The user id'
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
type: 'any',
|
||||
description: 'the user email'
|
||||
},
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ module.exports = Self => {
|
|||
|
||||
Self.updateUser = async function(ctx, id, options) {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
|
@ -44,13 +45,19 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const isWorker = await models.Worker.findById(id, null, myOptions);
|
||||
if (isWorker)
|
||||
throw new Error(`Can't update the user details of another worker`);
|
||||
const isSalesPerson = await models.Account.hasRole(userId, 'salesPerson', myOptions);
|
||||
|
||||
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();
|
||||
} catch (e) {
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
"ClientCreditLimit": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ClientConsumptionQueue": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"ClientLog": {
|
||||
"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 LoopBackContext = require('loopback-context');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.validatesPresenceOf('typeFk', {
|
||||
|
@ -6,10 +7,10 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
let models = Self.app.models;
|
||||
let changes = ctx.data || ctx.instance;
|
||||
const models = Self.app.models;
|
||||
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)
|
||||
throw new UserError('Choose a company');
|
||||
|
@ -25,11 +26,11 @@ module.exports = Self => {
|
|||
|
||||
// Renew mandate
|
||||
if (mandate) {
|
||||
let mandateType = await models.MandateType.findOne({
|
||||
const mandateType = await models.MandateType.findOne({
|
||||
where: {name: mandate.type}
|
||||
});
|
||||
|
||||
let oldMandate = await models.Mandate.findOne({
|
||||
const oldMandate = await models.Mandate.findOne({
|
||||
where: {
|
||||
clientFk: changes.clientFk,
|
||||
companyFk: changes.companyFk,
|
||||
|
@ -50,10 +51,8 @@ module.exports = Self => {
|
|||
});
|
||||
}
|
||||
|
||||
// Apply workerFk
|
||||
let filter = {where: {userFk: ctx.options.accessToken.userId}};
|
||||
let worker = await Self.app.models.Worker.findOne(filter);
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
|
||||
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 getFinalState = require('vn-loopback/util/hook').getFinalState;
|
||||
const isMultiple = require('vn-loopback/util/hook').isMultiple;
|
||||
|
@ -8,32 +7,7 @@ const LoopBackContext = require('loopback-context');
|
|||
|
||||
module.exports = Self => {
|
||||
// Methods
|
||||
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('./client-methods')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
|
@ -317,23 +291,22 @@ module.exports = Self => {
|
|||
const $t = httpRequest.__;
|
||||
const headers = httpRequest.headers;
|
||||
const origin = headers.origin;
|
||||
const authorization = headers.authorization;
|
||||
|
||||
const salesPersonId = instance.salesPersonFk;
|
||||
|
||||
if (salesPersonId) {
|
||||
// Send email to client
|
||||
if (instance.email) {
|
||||
const {Email} = require('vn-print');
|
||||
const worker = await models.EmailUser.findById(salesPersonId);
|
||||
const params = {
|
||||
authorization: authorization,
|
||||
id: instance.id,
|
||||
recipientId: instance.id,
|
||||
recipient: instance.email,
|
||||
replyTo: worker.email
|
||||
};
|
||||
await got.get(`${origin}/api/email/payment-update`, {
|
||||
searchParams: params
|
||||
});
|
||||
const email = new Email('payment-update', params);
|
||||
await email.send();
|
||||
}
|
||||
|
||||
const fullUrl = `${origin}/#!/client/${instance.id}/billing-data`;
|
||||
|
|
|
@ -29,6 +29,9 @@
|
|||
},
|
||||
"datepickerEnabled": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"model": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"scopes": {
|
||||
|
|
|
@ -45,11 +45,13 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
showReport() {
|
||||
this.vnReport.show('campaign-metrics', this.reportParams);
|
||||
const path = `Clients/${this.client.id}/campaign-metrics-pdf`;
|
||||
this.vnReport.show(path, this.reportParams);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -34,15 +34,16 @@ describe('Client', () => {
|
|||
|
||||
controller.showReport();
|
||||
|
||||
const clientId = controller.client.id;
|
||||
const expectedParams = {
|
||||
recipientId: 1101,
|
||||
recipientId: clientId,
|
||||
from: now,
|
||||
to: now
|
||||
};
|
||||
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,
|
||||
to: now
|
||||
};
|
||||
const expectedParams = {
|
||||
recipientId: 1101,
|
||||
from: now,
|
||||
to: now
|
||||
};
|
||||
const clientId = controller.client.id;
|
||||
const expectedPath = `Clients/${clientId}/campaign-metrics-email`;
|
||||
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
const path = `email/campaign-metrics?${serializedParams}`;
|
||||
|
||||
$httpBackend.expect('GET', path).respond({});
|
||||
$httpBackend.expect('POST', expectedPath).respond({});
|
||||
controller.sendEmail();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
|
|
@ -77,13 +77,16 @@ export default class Controller extends Section {
|
|||
|
||||
onSendClientConsumption() {
|
||||
const clientIds = this.checked.map(client => client.id);
|
||||
const params = Object.assign({
|
||||
clientIds: clientIds
|
||||
}, this.campaign);
|
||||
const data = {
|
||||
clients: clientIds,
|
||||
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.vnApp.showSuccess(this.$t('Notifications sent!')));
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Notification sent!')));
|
||||
}
|
||||
|
||||
exprBuilder(param, value) {
|
||||
|
|
|
@ -61,7 +61,6 @@ describe('Client notification', () => {
|
|||
|
||||
controller.$.filters = {hide: () => {}};
|
||||
controller.campaign = {
|
||||
id: 1,
|
||||
from: new Date(),
|
||||
to: new Date()
|
||||
};
|
||||
|
@ -70,15 +69,16 @@ describe('Client notification', () => {
|
|||
data[0].$checked = true;
|
||||
data[1].$checked = true;
|
||||
|
||||
const params = Object.assign({
|
||||
clientIds: [1101, 1102]
|
||||
const args = Object.assign({
|
||||
clients: [1101, 1102]
|
||||
}, 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();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Notifications sent!');
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Notification sent!');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
<vn-crud-model
|
||||
auto-load="true"
|
||||
url="Samples/visible"
|
||||
fields="[
|
||||
'id',
|
||||
'code',
|
||||
'description',
|
||||
'model',
|
||||
'hasCompany',
|
||||
'hasPreview',
|
||||
'datepickerEnabled'
|
||||
]"
|
||||
data="samplesVisible"
|
||||
order="description">
|
||||
</vn-crud-model>
|
||||
|
@ -77,7 +86,7 @@
|
|||
<vn-button
|
||||
disabled="!sampleType.selection.hasPreview"
|
||||
label="Preview"
|
||||
ng-click="$ctrl.showPreview()">
|
||||
ng-click="$ctrl.preview()">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
class="cancel"
|
||||
|
|
|
@ -3,12 +3,13 @@ import Section from 'salix/components/section';
|
|||
import './style.scss';
|
||||
|
||||
class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
constructor($element, $, vnEmail) {
|
||||
super($element, $);
|
||||
this.clientSample = {
|
||||
clientFk: this.$params.id,
|
||||
companyId: this.vnConfig.companyFk
|
||||
};
|
||||
this.vnEmail = vnEmail;
|
||||
}
|
||||
|
||||
get client() {
|
||||
|
@ -36,61 +37,86 @@ class Controller extends Section {
|
|||
|
||||
onSubmit() {
|
||||
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() {
|
||||
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) {
|
||||
validate() {
|
||||
const sampleType = this.$.sampleType.selection;
|
||||
const params = {
|
||||
recipientId: this.$params.id,
|
||||
recipient: this.clientSample.recipient,
|
||||
replyTo: this.clientSample.replyTo
|
||||
};
|
||||
|
||||
if (!params.recipient)
|
||||
return this.vnApp.showError(this.$t('Email cannot be blank'));
|
||||
if (!this.clientSample.recipient)
|
||||
return 'Email cannot be blank';
|
||||
|
||||
if (!sampleType)
|
||||
return this.vnApp.showError(this.$t('Choose a sample'));
|
||||
return 'Choose a sample';
|
||||
|
||||
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)
|
||||
params.companyId = this.clientSample.companyFk;
|
||||
|
||||
if (sampleType.datepickerEnabled && !this.clientSample.from)
|
||||
return this.vnApp.showError(this.$t('Choose a date'));
|
||||
|
||||
if (sampleType.datepickerEnabled)
|
||||
params.from = this.clientSample.from;
|
||||
}
|
||||
|
||||
let query = `email/${sampleType.code}`;
|
||||
if (isPreview)
|
||||
query = `email/${sampleType.code}/preview`;
|
||||
preview() {
|
||||
const sampleType = this.$.sampleType.selection;
|
||||
|
||||
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() {
|
||||
|
@ -103,7 +129,7 @@ class Controller extends Section {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope'];
|
||||
Controller.$inject = ['$element', '$scope', 'vnEmail'];
|
||||
|
||||
ngModule.vnComponent('vnClientSampleCreate', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -40,6 +40,7 @@ describe('Client', () => {
|
|||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
|
||||
controller = $componentController('vnClientSampleCreate', {$element, $scope});
|
||||
controller._client = {id: 1101};
|
||||
const element = document.createElement('div');
|
||||
document.body.querySelector = () => {
|
||||
return {
|
||||
|
@ -48,14 +49,26 @@ describe('Client', () => {
|
|||
}
|
||||
};
|
||||
};
|
||||
// $httpBackend.expectGET('EmailUsers?filter=%7B%22where%22:%7B%7D%7D').respond();
|
||||
}));
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it(`should call sendSample() method`, () => {
|
||||
jest.spyOn(controller, 'sendSample');
|
||||
it(`should call send() method`, () => {
|
||||
controller.send = jest.fn();
|
||||
|
||||
controller.$.sampleType.selection = {
|
||||
hasCompany: false,
|
||||
code: 'MyReport',
|
||||
model: 'Clients'
|
||||
};
|
||||
|
||||
controller.clientSample = {
|
||||
recipient: 'email@email'
|
||||
};
|
||||
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.sendSample).toHaveBeenCalledWith();
|
||||
expect(controller.send).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -65,13 +78,14 @@ describe('Client', () => {
|
|||
|
||||
controller.$.sampleType.selection = {
|
||||
hasCompany: false,
|
||||
code: 'MyReport'
|
||||
code: 'MyReport',
|
||||
model: 'Clients'
|
||||
};
|
||||
controller.clientSample = {
|
||||
recipientId: 1101
|
||||
};
|
||||
|
||||
controller.send(false, () => {});
|
||||
controller.send();
|
||||
|
||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||
});
|
||||
|
@ -85,7 +99,7 @@ describe('Client', () => {
|
|||
recipient: 'client@email.com'
|
||||
};
|
||||
|
||||
controller.send(false, () => {});
|
||||
controller.send();
|
||||
|
||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||
});
|
||||
|
@ -102,84 +116,81 @@ describe('Client', () => {
|
|||
recipient: 'client@email.com'
|
||||
};
|
||||
|
||||
controller.send(false, () => {});
|
||||
controller.send();
|
||||
|
||||
expect(controller.$http.get).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it(`should perform an HTTP query without passing companyFk param`, () => {
|
||||
$state.go = jest.fn();
|
||||
|
||||
controller.$.sampleType.selection = {
|
||||
hasCompany: false,
|
||||
code: 'MyReport'
|
||||
code: 'my-report',
|
||||
model: 'Clients'
|
||||
};
|
||||
controller.clientSample = {
|
||||
recipientId: 1101,
|
||||
recipient: 'client@email.com'
|
||||
};
|
||||
const expectedParams = {
|
||||
recipientId: 1101,
|
||||
recipient: 'client@email.com'
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
|
||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
|
||||
controller.send(false, () => {});
|
||||
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
||||
$httpBackend.expect('POST', expectedPath).respond(true);
|
||||
controller.send();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it(`should perform an HTTP query passing companyFk param`, () => {
|
||||
$state.go = jest.fn();
|
||||
|
||||
controller.$.sampleType.selection = {
|
||||
hasCompany: true,
|
||||
code: 'MyReport'
|
||||
code: 'my-report',
|
||||
model: 'Clients'
|
||||
};
|
||||
controller.clientSample = {
|
||||
recipientId: 1101,
|
||||
recipient: 'client@email.com',
|
||||
companyFk: 442
|
||||
};
|
||||
const expectedParams = {
|
||||
recipientId: 1101,
|
||||
recipient: 'client@email.com',
|
||||
companyId: 442
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
|
||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
|
||||
controller.send(false, () => {});
|
||||
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
||||
$httpBackend.expect('POST', expectedPath).respond(true);
|
||||
controller.send();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('showPreview()', () => {
|
||||
describe('preview()', () => {
|
||||
it(`should open a sample preview`, () => {
|
||||
jest.spyOn(controller.$.showPreview, 'show');
|
||||
|
||||
controller.send = (isPreview, cb) => {
|
||||
cb({
|
||||
data: '<div></div>'
|
||||
});
|
||||
controller.$.sampleType.selection = {
|
||||
hasCompany: true,
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
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()', () => {
|
||||
it(`should perform a query and then set the replyTo property to the clientSample object`, () => {
|
||||
const expectedEmail = 'batman@arkhamcity.com';
|
||||
|
|
|
@ -52,7 +52,7 @@ module.exports = Self => {
|
|||
|
||||
switch (field) {
|
||||
case 'size':
|
||||
case 'density':
|
||||
case 'weightByPiece':
|
||||
case 'description':
|
||||
case 'packingOut':
|
||||
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.id AS itemFk,
|
||||
i.size,
|
||||
i.density,
|
||||
i.weightByPiece,
|
||||
it.code,
|
||||
i.typeFk,
|
||||
i.family,
|
||||
|
|
|
@ -6,4 +6,5 @@ module.exports = Self => {
|
|||
require('../methods/entry/importBuys')(Self);
|
||||
require('../methods/entry/importBuysPreview')(Self);
|
||||
require('../methods/entry/lastItemBuys')(Self);
|
||||
require('../methods/entry/entryOrderPdf')(Self);
|
||||
};
|
||||
|
|
|
@ -86,9 +86,7 @@ class Controller extends Descriptor {
|
|||
}
|
||||
|
||||
showEntryReport() {
|
||||
this.vnReport.show('entry-order', {
|
||||
entryId: this.entry.id
|
||||
});
|
||||
this.vnReport.show(`Entries/${this.id}/entry-order-pdf`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,10 @@ describe('Entry Component vnEntryDescriptor', () => {
|
|||
jest.spyOn(controller.vnReport, 'show');
|
||||
|
||||
window.open = jasmine.createSpy('open');
|
||||
const params = {
|
||||
clientId: controller.vnConfig.storage.currentUserWorkerId,
|
||||
entryId: entry.id
|
||||
};
|
||||
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">
|
||||
<span translate>Origin</span>
|
||||
</th>
|
||||
<th field="density">
|
||||
<span translate>Density</span>
|
||||
<th field="weightByPiece">
|
||||
<span translate>Weight/Piece</span>
|
||||
</th>
|
||||
<th field="isActive">
|
||||
<span translate>Active</span>
|
||||
|
@ -183,7 +183,7 @@
|
|||
{{::buy.intrastat}}
|
||||
</td>
|
||||
<td>{{::buy.origin}}</td>
|
||||
<td>{{::buy.density}}</td>
|
||||
<td>{{::buy.weightByPiece}}</td>
|
||||
<td>
|
||||
<vn-check
|
||||
disabled="true"
|
||||
|
|
|
@ -80,7 +80,7 @@ export default class Controller extends Section {
|
|||
{field: 'weight', displayName: this.$t('Weight')},
|
||||
{field: 'description', displayName: this.$t('Description')},
|
||||
{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: 'landing', displayName: this.$t('Landing')}
|
||||
];
|
||||
|
@ -103,7 +103,7 @@ export default class Controller extends Section {
|
|||
switch (param) {
|
||||
case 'id':
|
||||
case 'size':
|
||||
case 'density':
|
||||
case 'weightByPiece':
|
||||
case 'isActive':
|
||||
case 'family':
|
||||
case 'minPrice':
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const axios = require('axios');
|
||||
const print = require('vn-print');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('createPdf', {
|
||||
|
@ -27,9 +25,7 @@ module.exports = Self => {
|
|||
|
||||
Self.createPdf = async function(ctx, id, options) {
|
||||
const models = Self.app.models;
|
||||
const headers = ctx.req.headers;
|
||||
const origin = headers.origin;
|
||||
const auth = ctx.req.accessToken;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
throw new UserError(`Action not allowed on the test environment`);
|
||||
|
@ -45,10 +41,9 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
let fileSrc;
|
||||
try {
|
||||
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)
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
@ -57,35 +52,27 @@ module.exports = Self => {
|
|||
hasPdf: true
|
||||
}, myOptions);
|
||||
|
||||
return axios.get(`${origin}/api/report/invoice`, {
|
||||
responseType: 'stream',
|
||||
params: {
|
||||
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 invoiceReport = new print.Report('invoice', {
|
||||
reference: invoiceOut.ref,
|
||||
recipientId: invoiceOut.clientFk
|
||||
});
|
||||
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) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -62,8 +62,14 @@ module.exports = Self => {
|
|||
name: fileName
|
||||
};
|
||||
|
||||
await fs.access(file.path);
|
||||
let stream = fs.createReadStream(file.path);
|
||||
try {
|
||||
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}"`];
|
||||
} catch (error) {
|
||||
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