Merge branch 'dev' into 5690-redondeo_ticketProblems
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
2bde94a667
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -14,6 +14,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|
||||||
|
## [2330.01] - 2023-07-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- (Artículos -> Vista Previa) Añadido campo "Plástico reciclado"
|
||||||
|
- (Rutas -> Troncales) Nueva sección
|
||||||
|
- (Tickets -> Opciones) Opción establecer peso
|
||||||
|
- (Clientes -> SMS) Nueva sección
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- (General -> Iconos) Añadidos nuevos iconos
|
||||||
|
- (Clientes -> Razón social) Nuevas restricciones por pais
|
||||||
|
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
|
||||||
## [2328.01] - 2023-07-13
|
## [2328.01] - 2023-07-13
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('checkFile', {
|
Self.remoteMethod('checkFile', {
|
||||||
description: 'Check if exist docuware file',
|
description: 'Check if exist docuware file',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -17,12 +15,16 @@ module.exports = Self => {
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The fileCabinet name'
|
description: 'The fileCabinet name'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'The filter'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'signed',
|
arg: 'signed',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
required: true,
|
|
||||||
description: 'If pdf is necessary to be signed'
|
description: 'If pdf is necessary to be signed'
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -34,7 +36,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.checkFile = async function(ctx, id, fileCabinet, signed) {
|
Self.checkFile = async function(id, fileCabinet, filter, signed) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const action = 'find';
|
const action = 'find';
|
||||||
|
|
||||||
|
@ -45,11 +47,11 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchFilter = {
|
if (!filter) {
|
||||||
|
filter = {
|
||||||
condition: [
|
condition: [
|
||||||
{
|
{
|
||||||
DBName: docuwareInfo.findById,
|
DBName: docuwareInfo.findById,
|
||||||
|
|
||||||
Value: [id]
|
Value: [id]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -60,24 +62,19 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
if (signed) {
|
||||||
|
filter.condition.push({
|
||||||
|
DBName: 'ESTADO',
|
||||||
|
Value: ['Firmado']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = await Self.getOptions();
|
const response = await Self.get(fileCabinet, filter);
|
||||||
|
const [documents] = response.Items;
|
||||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
|
||||||
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
|
|
||||||
|
|
||||||
const response = await axios.post(
|
|
||||||
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
|
||||||
searchFilter,
|
|
||||||
options.headers
|
|
||||||
);
|
|
||||||
const [documents] = response.data.Items;
|
|
||||||
if (!documents) return false;
|
if (!documents) return false;
|
||||||
|
|
||||||
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
|
|
||||||
if (signed && state.Item != 'Firmado') return false;
|
|
||||||
|
|
||||||
return {id: documents.Id};
|
return {id: documents.Id};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,59 +1,6 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
/**
|
|
||||||
* Returns the dialog id
|
|
||||||
*
|
|
||||||
* @param {string} code - The fileCabinet name
|
|
||||||
* @param {string} action - The fileCabinet name
|
|
||||||
* @param {string} fileCabinetId - Optional The fileCabinet name
|
|
||||||
* @return {number} - The fileCabinet id
|
|
||||||
*/
|
|
||||||
Self.getDialog = async(code, action, fileCabinetId) => {
|
|
||||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
|
||||||
where: {
|
|
||||||
code: code,
|
|
||||||
action: action
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!fileCabinetId) fileCabinetId = await Self.getFileCabinet(code);
|
|
||||||
|
|
||||||
const options = await Self.getOptions();
|
|
||||||
|
|
||||||
if (!process.env.NODE_ENV)
|
|
||||||
return Math.round();
|
|
||||||
|
|
||||||
const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers);
|
|
||||||
const dialogs = response.data.Dialog;
|
|
||||||
const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id;
|
|
||||||
|
|
||||||
return dialogId;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the fileCabinetId
|
|
||||||
*
|
|
||||||
* @param {string} code - The fileCabinet code
|
|
||||||
* @return {number} - The fileCabinet id
|
|
||||||
*/
|
|
||||||
Self.getFileCabinet = async code => {
|
|
||||||
const options = await Self.getOptions();
|
|
||||||
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
|
||||||
where: {
|
|
||||||
code: code
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!process.env.NODE_ENV)
|
|
||||||
return Math.round();
|
|
||||||
|
|
||||||
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
|
|
||||||
const fileCabinets = fileCabinetResponse.data.FileCabinet;
|
|
||||||
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;
|
|
||||||
|
|
||||||
return fileCabinetId;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns basic headers
|
* Returns basic headers
|
||||||
*
|
*
|
||||||
|
@ -75,4 +22,139 @@ module.exports = Self => {
|
||||||
headers
|
headers
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the dialog id
|
||||||
|
*
|
||||||
|
* @param {string} code - The fileCabinet name
|
||||||
|
* @param {string} action - The fileCabinet name
|
||||||
|
* @param {string} fileCabinetId - Optional The fileCabinet name
|
||||||
|
* @return {number} - The fileCabinet id
|
||||||
|
*/
|
||||||
|
Self.getDialog = async(code, action, fileCabinetId) => {
|
||||||
|
if (!process.env.NODE_ENV)
|
||||||
|
return Math.floor(Math.random() + 100);
|
||||||
|
|
||||||
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
|
where: {
|
||||||
|
code,
|
||||||
|
action
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!fileCabinetId) fileCabinetId = await Self.getFileCabinet(code);
|
||||||
|
|
||||||
|
const options = await Self.getOptions();
|
||||||
|
|
||||||
|
const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers);
|
||||||
|
const dialogs = response.data.Dialog;
|
||||||
|
const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id;
|
||||||
|
|
||||||
|
return dialogId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the fileCabinetId
|
||||||
|
*
|
||||||
|
* @param {string} code - The fileCabinet code
|
||||||
|
* @return {number} - The fileCabinet id
|
||||||
|
*/
|
||||||
|
Self.getFileCabinet = async code => {
|
||||||
|
if (!process.env.NODE_ENV)
|
||||||
|
return Math.floor(Math.random() + 100);
|
||||||
|
|
||||||
|
const options = await Self.getOptions();
|
||||||
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
|
where: {
|
||||||
|
code
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers);
|
||||||
|
const fileCabinets = fileCabinetResponse.data.FileCabinet;
|
||||||
|
const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id;
|
||||||
|
|
||||||
|
return fileCabinetId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns docuware data
|
||||||
|
*
|
||||||
|
* @param {string} code - The fileCabinet code
|
||||||
|
* @param {object} filter - The filter for docuware
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data
|
||||||
|
*/
|
||||||
|
Self.get = async(code, filter, parse) => {
|
||||||
|
if (!process.env.NODE_ENV) return;
|
||||||
|
|
||||||
|
const options = await Self.getOptions();
|
||||||
|
const fileCabinetId = await Self.getFileCabinet(code);
|
||||||
|
const dialogId = await Self.getDialog(code, 'find', fileCabinetId);
|
||||||
|
|
||||||
|
const data = await axios.post(
|
||||||
|
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
|
||||||
|
filter,
|
||||||
|
options.headers
|
||||||
|
);
|
||||||
|
return parser(data.data, parse);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns docuware data
|
||||||
|
*
|
||||||
|
* @param {string} code - The fileCabinet code
|
||||||
|
* @param {any} id - The id of docuware
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data
|
||||||
|
*/
|
||||||
|
Self.getById = async(code, id, parse) => {
|
||||||
|
if (!process.env.NODE_ENV) return;
|
||||||
|
|
||||||
|
const docuwareInfo = await Self.app.models.Docuware.findOne({
|
||||||
|
fields: ['findById'],
|
||||||
|
where: {
|
||||||
|
code,
|
||||||
|
action: 'find'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const filter = {
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
DBName: docuwareInfo.findById,
|
||||||
|
Value: [id]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
return Self.get(code, filter, parse);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns docuware data filtered
|
||||||
|
*
|
||||||
|
* @param {array} data - The data
|
||||||
|
* @param {object} parse - The fields parsed
|
||||||
|
* @return {object} - The data parsed
|
||||||
|
*/
|
||||||
|
function parser(data, parse) {
|
||||||
|
if (!(data && data.Items)) return data;
|
||||||
|
|
||||||
|
const parsed = [];
|
||||||
|
for (item of data.Items) {
|
||||||
|
const itemParsed = {};
|
||||||
|
item.Fields.map(field => {
|
||||||
|
if (field.ItemElementName.includes('Date')) field.Item = toDate(field.Item);
|
||||||
|
if (!parse) return itemParsed[field.FieldLabel] = field.Item;
|
||||||
|
if (parse[field.FieldLabel])
|
||||||
|
itemParsed[parse[field.FieldLabel]] = field.Item;
|
||||||
|
});
|
||||||
|
parsed.push(itemParsed);
|
||||||
|
}
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDate(value) {
|
||||||
|
if (!value) return;
|
||||||
|
return new Date(Number(value.substring(6, 19)));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const axios = require('axios');
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('download', {
|
Self.remoteMethod('download', {
|
||||||
description: 'Download an docuware PDF',
|
description: 'Download an docuware PDF',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
@ -16,8 +16,12 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'fileCabinet',
|
arg: 'fileCabinet',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The file cabinet',
|
description: 'The file cabinet'
|
||||||
http: {source: 'path'}
|
},
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'The filter'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: [
|
returns: [
|
||||||
|
@ -36,14 +40,15 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/download/:fileCabinet`,
|
path: `/:id/download`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.download = async function(ctx, id, fileCabinet) {
|
Self.download = async function(id, fileCabinet, filter) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true);
|
|
||||||
|
const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, filter);
|
||||||
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists');
|
||||||
|
|
||||||
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
|
||||||
|
|
|
@ -1,57 +1,15 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
describe('docuware download()', () => {
|
describe('docuware download()', () => {
|
||||||
const ticketId = 1;
|
const ticketId = 1;
|
||||||
const userId = 9;
|
|
||||||
const ctx = {
|
|
||||||
req: {
|
|
||||||
|
|
||||||
accessToken: {userId: userId},
|
|
||||||
headers: {origin: 'http://localhost:5000'},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const docuwareModel = models.Docuware;
|
const docuwareModel = models.Docuware;
|
||||||
const fileCabinetName = 'deliveryNote';
|
const fileCabinetName = 'deliveryNote';
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
||||||
spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if there are no documents', async() => {
|
it('should return false if there are no documents', async() => {
|
||||||
const response = {
|
spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve({Items: []}))));
|
||||||
data: {
|
|
||||||
Items: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true);
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if the document is unsigned', async() => {
|
|
||||||
const response = {
|
|
||||||
data: {
|
|
||||||
Items: [
|
|
||||||
{
|
|
||||||
Id: 1,
|
|
||||||
Fields: [
|
|
||||||
{
|
|
||||||
FieldName: 'ESTADO',
|
|
||||||
Item: 'Unsigned'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toEqual(false);
|
||||||
});
|
});
|
||||||
|
@ -59,7 +17,6 @@ describe('docuware download()', () => {
|
||||||
it('should return the document data', async() => {
|
it('should return the document data', async() => {
|
||||||
const docuwareId = 1;
|
const docuwareId = 1;
|
||||||
const response = {
|
const response = {
|
||||||
data: {
|
|
||||||
Items: [
|
Items: [
|
||||||
{
|
{
|
||||||
Id: docuwareId,
|
Id: docuwareId,
|
||||||
|
@ -71,11 +28,10 @@ describe('docuware download()', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
};
|
};
|
||||||
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response)));
|
spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve(response))));
|
||||||
|
|
||||||
const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true);
|
const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true);
|
||||||
|
|
||||||
expect(result.id).toEqual(docuwareId);
|
expect(result.id).toEqual(docuwareId);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
const axios = require('axios');
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Docuware core', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
process.env.NODE_ENV = 'testing';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
delete process.env.NODE_ENV;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getOptions()', () => {
|
||||||
|
it('should return url and headers', async() => {
|
||||||
|
const result = await models.Docuware.getOptions();
|
||||||
|
|
||||||
|
expect(result.url).toBeDefined();
|
||||||
|
expect(result.headers).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getDialog()', () => {
|
||||||
|
it('should return dialogId', async() => {
|
||||||
|
const dialogs = {
|
||||||
|
data: {
|
||||||
|
Dialog: [
|
||||||
|
{
|
||||||
|
DisplayName: 'find',
|
||||||
|
Id: 'getDialogTest'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||||
|
const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId');
|
||||||
|
|
||||||
|
expect(result).toEqual('getDialogTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getFileCabinet()', () => {
|
||||||
|
it('should return fileCabinetId', async() => {
|
||||||
|
const code = 'deliveryNote';
|
||||||
|
const docuwareInfo = await models.Docuware.findOne({
|
||||||
|
where: {
|
||||||
|
code
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const dialogs = {
|
||||||
|
data: {
|
||||||
|
FileCabinet: [
|
||||||
|
{
|
||||||
|
Name: docuwareInfo.fileCabinetName,
|
||||||
|
Id: 'getFileCabinetTest'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs)));
|
||||||
|
const result = await models.Docuware.getFileCabinet(code);
|
||||||
|
|
||||||
|
expect(result).toEqual('getFileCabinetTest');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('get()', () => {
|
||||||
|
it('should return data without parse', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const result = await models.Docuware.get('deliveryNote');
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return data with parse', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
Items: [{
|
||||||
|
Fields: [
|
||||||
|
{
|
||||||
|
ItemElementName: 'integer',
|
||||||
|
FieldLabel: 'firstRequiredField',
|
||||||
|
Item: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ItemElementName: 'string',
|
||||||
|
FieldLabel: 'secondRequiredField',
|
||||||
|
Item: 'myName'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ItemElementName: 'integer',
|
||||||
|
FieldLabel: 'notRequiredField',
|
||||||
|
Item: 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const parse = {
|
||||||
|
'firstRequiredField': 'id',
|
||||||
|
'secondRequiredField': 'name',
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const [result] = await models.Docuware.get('deliveryNote', null, parse);
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
expect(result.name).toEqual('myName');
|
||||||
|
expect(result.notRequiredField).not.toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getById()', () => {
|
||||||
|
it('should return data', async() => {
|
||||||
|
spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random()))));
|
||||||
|
const data = {
|
||||||
|
data: {
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data)));
|
||||||
|
const result = await models.Docuware.getById('deliveryNote', 1);
|
||||||
|
|
||||||
|
expect(result.id).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -39,7 +39,7 @@ describe('docuware download()', () => {
|
||||||
spyOn(docuwareModel, 'checkFile').and.returnValue({});
|
spyOn(docuwareModel, 'checkFile').and.returnValue({});
|
||||||
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true}));
|
||||||
|
|
||||||
const result = await models.Docuware.download(ctx, ticketId, fileCabinetName);
|
const result = await models.Docuware.download(ticketId, fileCabinetName);
|
||||||
|
|
||||||
expect(result[1]).toEqual('application/pdf');
|
expect(result[1]).toEqual('application/pdf');
|
||||||
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
|
expect(result[2]).toEqual(`filename="${ticketId}.pdf"`);
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
const axios = require('axios');
|
||||||
|
const {DOMParser} = require('xmldom');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('internationalExpedition', {
|
||||||
|
description: 'Create an expedition and return a label',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'expeditionFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/internationalExpedition`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.internationalExpedition = async expeditionFk => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
||||||
|
fields: ['url']
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
||||||
|
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const xmlString = response.data;
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||||
|
const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0];
|
||||||
|
const referenciaVx = referenciaVxElement.textContent;
|
||||||
|
|
||||||
|
return referenciaVx;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,126 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const ejs = require('ejs');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('renderer', {
|
||||||
|
description: 'Renders the data from an XML',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'expeditionFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/renderer`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.renderer = async expeditionFk => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
||||||
|
fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType']
|
||||||
|
});
|
||||||
|
|
||||||
|
const expedition = await models.Expedition.findOne({
|
||||||
|
fields: ['id', 'ticketFk'],
|
||||||
|
where: {id: expeditionFk},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'ticket',
|
||||||
|
scope: {
|
||||||
|
fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
fields: ['mobile', 'phone', 'email']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'address',
|
||||||
|
scope: {
|
||||||
|
fields: [
|
||||||
|
'nickname',
|
||||||
|
'street',
|
||||||
|
'postalCode',
|
||||||
|
'city',
|
||||||
|
'mobile',
|
||||||
|
'phone',
|
||||||
|
'provinceFk'
|
||||||
|
],
|
||||||
|
include: {
|
||||||
|
relation: 'province',
|
||||||
|
scope: {
|
||||||
|
fields: ['name', 'countryFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'country',
|
||||||
|
scope: {
|
||||||
|
fields: ['code'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
relation: 'company',
|
||||||
|
scope: {
|
||||||
|
fields: ['clientFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
fields: ['socialName', 'mobile', 'phone', 'email', 'defaultAddressFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'defaultAddress',
|
||||||
|
scope: {
|
||||||
|
fields: [
|
||||||
|
'street',
|
||||||
|
'postalCode',
|
||||||
|
'city',
|
||||||
|
'mobile',
|
||||||
|
'phone',
|
||||||
|
'provinceFk'
|
||||||
|
],
|
||||||
|
include: {
|
||||||
|
relation: 'province',
|
||||||
|
scope: {
|
||||||
|
fields: ['name']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
const ticket = expedition.ticket();
|
||||||
|
const sender = ticket.company().client();
|
||||||
|
const shipped = ticket.shipped.toISOString();
|
||||||
|
const data = {
|
||||||
|
viaexpressConfig,
|
||||||
|
sender,
|
||||||
|
senderAddress: sender.defaultAddress(),
|
||||||
|
client: ticket.client(),
|
||||||
|
address: ticket.address(),
|
||||||
|
shipped
|
||||||
|
};
|
||||||
|
|
||||||
|
const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8');
|
||||||
|
const renderedXml = ejs.render(template, data);
|
||||||
|
return renderedXml;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
||||||
|
<soap12:Body>
|
||||||
|
<PutExpedicionInternacional xmlns="http://82.223.6.71:82">
|
||||||
|
<ObjetoEnvio>
|
||||||
|
<Peso><%= viaexpressConfig.defaultWeight %></Peso>
|
||||||
|
<Bultos>1</Bultos>
|
||||||
|
<Reembolso>0</Reembolso>
|
||||||
|
<Fecha><%= shipped %></Fecha>
|
||||||
|
<ConRetorno>0</ConRetorno>
|
||||||
|
<Tipo><%= viaexpressConfig.deliveryType %></Tipo>
|
||||||
|
<Debidos>0</Debidos>
|
||||||
|
<Asegurado>0</Asegurado>
|
||||||
|
<Imprimir>0</Imprimir>
|
||||||
|
<ConDevolucionAlbaran>0</ConDevolucionAlbaran>
|
||||||
|
<Intradia>0</Intradia>
|
||||||
|
<Observaciones></Observaciones>
|
||||||
|
<AlbaranRemitente></AlbaranRemitente>
|
||||||
|
<Modo>0</Modo>
|
||||||
|
<TextoAgencia></TextoAgencia>
|
||||||
|
<Terminal></Terminal>
|
||||||
|
<ObjetoRemitente>
|
||||||
|
<RazonSocial><%= sender.socialName %></RazonSocial>
|
||||||
|
<Domicilio><%= senderAddress.street %></Domicilio>
|
||||||
|
<Cpostal><%= senderAddress.postalCode %></Cpostal>
|
||||||
|
<Poblacion><%= senderAddress.city %></Poblacion>
|
||||||
|
<Provincia><%= senderAddress.province().name %></Provincia>
|
||||||
|
<Contacto></Contacto>
|
||||||
|
<Telefono><%= senderAddress.mobile || senderAddress.phone || sender.mobile || sender.phone %></Telefono>
|
||||||
|
<Email><%= sender.email %></Email>
|
||||||
|
</ObjetoRemitente>
|
||||||
|
<ObjetoDestinatario>
|
||||||
|
<RazonSocial><%= address.nickname %></RazonSocial>
|
||||||
|
<Domicilio><%= address.street %></Domicilio>
|
||||||
|
<Cpostal><%= address.postalCode %></Cpostal>
|
||||||
|
<Poblacion><%= address.city %></Poblacion>
|
||||||
|
<Municipio></Municipio>
|
||||||
|
<Provincia><%= address.province().name %></Provincia>
|
||||||
|
<Contacto></Contacto>
|
||||||
|
<Telefono><%= address.mobile || address.phone || client.mobile || client.phone %></Telefono>
|
||||||
|
<Email><%= client.email %></Email>
|
||||||
|
<Pais><%= address.province().country().code %></Pais>
|
||||||
|
</ObjetoDestinatario>
|
||||||
|
<ObjetoLogin>
|
||||||
|
<IdCliente><%= viaexpressConfig.client %></IdCliente>
|
||||||
|
<Usuario><%= viaexpressConfig.user %></Usuario>
|
||||||
|
<Password><%= viaexpressConfig.password %></Password>
|
||||||
|
</ObjetoLogin>
|
||||||
|
</ObjetoEnvio>
|
||||||
|
</PutExpedicionInternacional>
|
||||||
|
</soap12:Body>
|
||||||
|
</soap12:Envelope>
|
|
@ -1,68 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('addAlias', {
|
|
||||||
description: 'Add an alias if the user has the grant',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [
|
|
||||||
{
|
|
||||||
arg: 'ctx',
|
|
||||||
type: 'Object',
|
|
||||||
http: {source: 'context'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
required: true,
|
|
||||||
description: 'The user id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'mailAlias',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The new alias for user',
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
http: {
|
|
||||||
path: `/:id/addAlias`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.addAlias = async function(ctx, id, mailAlias, 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 Self.findById(userId, {fields: ['hasGrant']}, myOptions);
|
|
||||||
|
|
||||||
if (!user.hasGrant)
|
|
||||||
throw new UserError(`You don't have grant privilege`);
|
|
||||||
|
|
||||||
const account = await models.Account.findById(userId, {
|
|
||||||
fields: ['id'],
|
|
||||||
include: {
|
|
||||||
relation: 'aliases',
|
|
||||||
scope: {
|
|
||||||
fields: ['mailAlias']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const aliases = account.aliases().map(alias => alias.mailAlias);
|
|
||||||
|
|
||||||
const hasAlias = aliases.includes(mailAlias);
|
|
||||||
if (!hasAlias)
|
|
||||||
throw new UserError(`You cannot assign an alias that you are not assigned to`);
|
|
||||||
|
|
||||||
return models.MailAliasAccount.create({
|
|
||||||
mailAlias: mailAlias,
|
|
||||||
account: id
|
|
||||||
}, myOptions);
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,55 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('removeAlias', {
|
|
||||||
description: 'Remove alias if the user has the grant',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [
|
|
||||||
{
|
|
||||||
arg: 'ctx',
|
|
||||||
type: 'Object',
|
|
||||||
http: {source: 'context'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
required: true,
|
|
||||||
description: 'The user id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'mailAlias',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The alias to delete',
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
http: {
|
|
||||||
path: `/:id/removeAlias`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.removeAlias = async function(ctx, id, mailAlias, options) {
|
|
||||||
const models = Self.app.models;
|
|
||||||
const userId = ctx.req.accessToken.userId;
|
|
||||||
|
|
||||||
const myOptions = {};
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
const canRemoveAlias = await models.ACL.checkAccessAcl(ctx, 'VnUser', 'canRemoveAlias', 'WRITE');
|
|
||||||
|
|
||||||
if (userId != id && !canRemoveAlias) throw new UserError(`You don't have grant privilege`);
|
|
||||||
|
|
||||||
const mailAliasAccount = await models.MailAliasAccount.findOne({
|
|
||||||
where: {
|
|
||||||
mailAlias: mailAlias,
|
|
||||||
account: id
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
await mailAliasAccount.destroy(myOptions);
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -150,6 +150,9 @@
|
||||||
},
|
},
|
||||||
"PrintConfig": {
|
"PrintConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"ViaexpressConfig": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,21 @@
|
||||||
},
|
},
|
||||||
"expired": {
|
"expired": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
|
},
|
||||||
|
"supplierAccountFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scope": {
|
"scope": {
|
||||||
"where" :{
|
"where" :{
|
||||||
"expired": null
|
"expired": null
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"client": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Client",
|
||||||
|
"foreignKey": "clientFk"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
},
|
},
|
||||||
"isUeeMember": {
|
"isUeeMember": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"isSocialNameUnique": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -28,5 +28,12 @@
|
||||||
"findById": {
|
"findById": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"dmsType": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "DmsType",
|
||||||
|
"foreignKey": "dmsTypeFk"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/viaexpress-config/internationalExpedition')(Self);
|
||||||
|
require('../methods/viaexpress-config/renderer')(Self);
|
||||||
|
};
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"name": "ViaexpressConfig",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "viaexpressConfig"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"defaultWeight": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"deliveryType": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,8 +12,6 @@ module.exports = function(Self) {
|
||||||
require('../methods/vn-user/privileges')(Self);
|
require('../methods/vn-user/privileges')(Self);
|
||||||
require('../methods/vn-user/validate-auth')(Self);
|
require('../methods/vn-user/validate-auth')(Self);
|
||||||
require('../methods/vn-user/renew-token')(Self);
|
require('../methods/vn-user/renew-token')(Self);
|
||||||
require('../methods/vn-user/addAlias')(Self);
|
|
||||||
require('../methods/vn-user/removeAlias')(Self);
|
|
||||||
|
|
||||||
Self.definition.settings.acls = Self.definition.settings.acls.filter(acl => acl.property !== 'create');
|
Self.definition.settings.acls = Self.definition.settings.acls.filter(acl => acl.property !== 'create');
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalId`)
|
|
||||||
VALUES
|
|
||||||
('Vehicle','sorted','WRITE','ALLOW','employee');
|
|
|
@ -1,11 +0,0 @@
|
||||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
|
||||||
VALUES
|
|
||||||
('VnUser', 'addAlias', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
||||||
|
|
||||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
|
||||||
VALUES
|
|
||||||
('VnUser', 'removeAlias', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
||||||
|
|
||||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
|
||||||
VALUES
|
|
||||||
('VnUser', 'canRemoveAlias', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('ViaexpressConfig', 'internationalExpedition', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('ViaexpressConfig', 'renderer', 'READ', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,10 @@
|
||||||
|
CREATE TABLE `vn`.`viaexpressConfig` (
|
||||||
|
id int auto_increment NOT NULL,
|
||||||
|
url varchar(100) NOT NULL,
|
||||||
|
client varchar(100) NOT NULL,
|
||||||
|
user varchar(100) NOT NULL,
|
||||||
|
password varchar(100) NOT NULL,
|
||||||
|
defaultWeight decimal(10,2) NOT NULL,
|
||||||
|
deliveryType varchar(5) NOT NULL,
|
||||||
|
CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
@ -0,0 +1,8 @@
|
||||||
|
DELETE FROM `salix`.`ACL` WHERE model = 'MailAliasAccount';
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('MailAliasAccount', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('MailAliasAccount', 'create', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('MailAliasAccount', 'deleteById', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('MailAliasAccount', 'canEditAlias', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
|
@ -0,0 +1,4 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('WorkerDisableExcluded', '*', 'READ', 'ALLOW', 'ROLE', 'itManagement'),
|
||||||
|
('WorkerDisableExcluded', '*', 'WRITE', 'ALLOW', 'ROLE', 'itManagement');
|
|
@ -0,0 +1,15 @@
|
||||||
|
CREATE TABLE `vn`.`clientSms` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`clientFk` int(11) NOT NULL,
|
||||||
|
`smsFk` mediumint(8) unsigned NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `clientSms_FK` (`clientFk`),
|
||||||
|
KEY `clientSms_FK_1` (`smsFk`),
|
||||||
|
CONSTRAINT `clientSms_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `clientSms_FK_1` FOREIGN KEY (`smsFk`) REFERENCES `sms` (`id`) ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||||
|
VALUES
|
||||||
|
('ClientSms', 'find', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||||
|
('ClientSms', 'create', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE `vn`.`company` MODIFY COLUMN sage200Company int(2) DEFAULT 10 NOT NULL;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `vn`.`country`
|
||||||
|
ADD COLUMN `isSocialNameUnique` tinyint(1) NOT NULL DEFAULT 1;
|
|
@ -6,5 +6,3 @@ ALTER TABLE `vn`.`roadmap` CHANGE name name varchar(45) CHARACTER SET utf8mb3 CO
|
||||||
ALTER TABLE `vn`.`roadmap` MODIFY COLUMN etd datetime NOT NULL;
|
ALTER TABLE `vn`.`roadmap` MODIFY COLUMN etd datetime NOT NULL;
|
||||||
|
|
||||||
ALTER TABLE `vn`.`expeditionTruck` COMMENT='Distintas paradas que hacen los trocales';
|
ALTER TABLE `vn`.`expeditionTruck` COMMENT='Distintas paradas que hacen los trocales';
|
||||||
ALTER TABLE `vn`.`expeditionTruck` DROP FOREIGN KEY expeditionTruck_FK_2;
|
|
||||||
ALTER TABLE `vn`.`expeditionTruck` ADD CONSTRAINT expeditionTruck_FK_2 FOREIGN KEY (roadmapFk) REFERENCES vn.roadmap(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`)
|
||||||
|
VALUES ('Ticket','transferClient','WRITE','ALLOW','ROLE','administrative');
|
|
@ -0,0 +1,2 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`)
|
||||||
|
VALUES ('Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer');
|
|
@ -0,0 +1,10 @@
|
||||||
|
ALTER TABLE `vn`.`docuware` ADD dmsTypeFk INT(11) DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk)
|
||||||
|
VALUES
|
||||||
|
('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); -- set dmsTypeFk 3 when deploy in production
|
||||||
|
|
||||||
|
INSERT INTO `salix`.`url` (appName, environment, url)
|
||||||
|
VALUES
|
||||||
|
('docuware', 'production', 'https://verdnatura.docuware.cloud/DocuWare/Platform/');
|
||||||
|
|
|
@ -579,13 +579,13 @@ INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(241, 442, 'ES111122333344111122221111', 128);
|
(241, 442, 'ES111122333344111122221111', 128);
|
||||||
|
|
||||||
INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary`)
|
INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`)
|
||||||
VALUES
|
VALUES
|
||||||
(69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL),
|
(69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL , NULL),
|
||||||
(442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport'),
|
(442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport' , 1101),
|
||||||
(567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport'),
|
(567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport' , NULL),
|
||||||
(791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL),
|
(791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL , NULL),
|
||||||
(1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport');
|
(1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport' , NULL);
|
||||||
|
|
||||||
INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`)
|
INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -875,7 +875,7 @@ export default {
|
||||||
|
|
||||||
},
|
},
|
||||||
routeTickets: {
|
routeTickets: {
|
||||||
firstTicketPriority: 'vn-route-tickets vn-tr:nth-child(1) vn-input-number[ng-model="ticket.priority"]',
|
firstTicketPriority: 'vn-route-tickets vn-tr:nth-child(1) vn-td-editable',
|
||||||
firstTicketCheckbox: 'vn-route-tickets vn-tr:nth-child(1) vn-check',
|
firstTicketCheckbox: 'vn-route-tickets vn-tr:nth-child(1) vn-check',
|
||||||
buscamanButton: 'vn-route-tickets vn-button[icon="icon-buscaman"]',
|
buscamanButton: 'vn-route-tickets vn-button[icon="icon-buscaman"]',
|
||||||
firstTicketDeleteButton: 'vn-route-tickets vn-tr:nth-child(1) vn-icon[icon="delete"]',
|
firstTicketDeleteButton: 'vn-route-tickets vn-tr:nth-child(1) vn-icon[icon="delete"]',
|
||||||
|
|
|
@ -18,8 +18,7 @@ describe('Route tickets path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should modify the first ticket priority', async() => {
|
it('should modify the first ticket priority', async() => {
|
||||||
await page.clearInput(selectors.routeTickets.firstTicketPriority);
|
await page.writeOnEditableTD(selectors.routeTickets.firstTicketPriority, '9');
|
||||||
await page.type(selectors.routeTickets.firstTicketPriority, '9');
|
|
||||||
await page.keyboard.press('Enter');
|
await page.keyboard.press('Enter');
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,11 @@ export default class App {
|
||||||
|
|
||||||
return this.logger.$http.get('Urls/findOne', {filter})
|
return this.logger.$http.get('Urls/findOne', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
if (res && res.data)
|
||||||
return res.data.url + route;
|
return res.data.url + route;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.showError('Direction not found');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,3 +4,4 @@ Please enter your username: Por favor introduce tu nombre de usuario
|
||||||
It seems that the server has fall down: Parece que el servidor se ha caído, espera unos minutos e inténtalo de nuevo
|
It seems that the server has fall down: Parece que el servidor se ha caído, espera unos minutos e inténtalo de nuevo
|
||||||
Session has expired: Tu sesión ha expirado, por favor vuelve a iniciar sesión
|
Session has expired: Tu sesión ha expirado, por favor vuelve a iniciar sesión
|
||||||
Access denied: Acción no permitida
|
Access denied: Acción no permitida
|
||||||
|
Direction not found: Dirección no encontrada
|
||||||
|
|
|
@ -178,5 +178,9 @@
|
||||||
"The renew period has not been exceeded": "The renew period has not been exceeded",
|
"The renew period has not been exceeded": "The renew period has not been exceeded",
|
||||||
"You can not use the same password": "You can not use the same password",
|
"You can not use the same password": "You can not use the same password",
|
||||||
"Valid priorities": "Valid priorities: %d",
|
"Valid priorities": "Valid priorities: %d",
|
||||||
"Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}"
|
"Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}",
|
||||||
|
"You don't have enough privileges.": "You don't have enough privileges.",
|
||||||
|
"This ticket is locked.": "This ticket is locked.",
|
||||||
|
"This ticket is not editable.": "This ticket is not editable.",
|
||||||
|
"The ticket doesn't exist.": "The ticket doesn't exist."
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,5 +305,11 @@
|
||||||
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado",
|
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado",
|
||||||
"Valid priorities": "Prioridades válidas: %d",
|
"Valid priorities": "Prioridades válidas: %d",
|
||||||
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}",
|
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}",
|
||||||
"You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado"
|
"The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias",
|
||||||
|
"You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado",
|
||||||
|
"This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado",
|
||||||
|
"You don't have enough privileges.": "No tienes suficientes permisos.",
|
||||||
|
"This ticket is locked.": "Este ticket está bloqueado.",
|
||||||
|
"This ticket is not editable.": "Este ticket no es editable.",
|
||||||
|
"The ticket doesn't exist.": "No existe el ticket."
|
||||||
}
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.observe('before save', async ctx => {
|
||||||
|
const changes = ctx.currentInstance || ctx.instance;
|
||||||
|
|
||||||
|
await Self.hasGrant(ctx, changes.mailAlias);
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.observe('before delete', async ctx => {
|
||||||
|
const mailAliasAccount = await Self.findById(ctx.where.id);
|
||||||
|
|
||||||
|
await Self.hasGrant(ctx, mailAliasAccount.mailAlias);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if current user has
|
||||||
|
* grant to add/remove alias
|
||||||
|
*
|
||||||
|
* @param {Object} ctx - Request context
|
||||||
|
* @param {Interger} mailAlias - mailAlias id
|
||||||
|
* @return {Boolean} True for user with grant
|
||||||
|
*/
|
||||||
|
Self.hasGrant = async function(ctx, mailAlias) {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const accessToken = {req: {accessToken: ctx.options.accessToken}};
|
||||||
|
const userId = accessToken.req.accessToken.userId;
|
||||||
|
|
||||||
|
const canEditAlias = await models.ACL.checkAccessAcl(accessToken, 'MailAliasAccount', 'canEditAlias', 'WRITE');
|
||||||
|
if (canEditAlias) return true;
|
||||||
|
|
||||||
|
const user = await models.VnUser.findById(userId, {fields: ['hasGrant']});
|
||||||
|
if (!user.hasGrant)
|
||||||
|
throw new UserError(`You don't have grant privilege`);
|
||||||
|
|
||||||
|
const account = await models.Account.findById(userId, {
|
||||||
|
fields: ['id'],
|
||||||
|
include: {
|
||||||
|
relation: 'aliases',
|
||||||
|
scope: {
|
||||||
|
fields: ['mailAlias']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const aliases = account.aliases().map(alias => alias.mailAlias);
|
||||||
|
|
||||||
|
const hasAlias = aliases.includes(mailAlias);
|
||||||
|
if (!hasAlias)
|
||||||
|
throw new UserError(`You cannot assign/remove an alias that you are not assigned to`);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
|
@ -21,11 +21,12 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddClick() {
|
onAddClick() {
|
||||||
|
this.addData = {account: this.$params.id};
|
||||||
this.$.dialog.show();
|
this.$.dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddSave() {
|
onAddSave() {
|
||||||
return this.$http.post(`VnUsers/${this.$params.id}/addAlias`, this.addData)
|
return this.$http.post(`MailAliasAccounts`, this.addData)
|
||||||
.then(() => this.refresh())
|
.then(() => this.refresh())
|
||||||
.then(() => this.vnApp.showSuccess(
|
.then(() => this.vnApp.showSuccess(
|
||||||
this.$t('Subscribed to alias!'))
|
this.$t('Subscribed to alias!'))
|
||||||
|
@ -33,12 +34,11 @@ export default class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemove(row) {
|
onRemove(row) {
|
||||||
const params = {
|
return this.$http.delete(`MailAliasAccounts/${row.id}`)
|
||||||
mailAlias: row.mailAlias
|
.then(() => {
|
||||||
};
|
this.$.data.splice(this.$.data.indexOf(row), 1);
|
||||||
return this.$http.post(`VnUsers/${this.$params.id}/removeAlias`, params)
|
this.vnApp.showSuccess(this.$t('Unsubscribed from alias!'));
|
||||||
.then(() => this.refresh())
|
});
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,8 @@ describe('component vnUserAliases', () => {
|
||||||
describe('onAddSave()', () => {
|
describe('onAddSave()', () => {
|
||||||
it('should add the new row', () => {
|
it('should add the new row', () => {
|
||||||
controller.addData = {account: 1};
|
controller.addData = {account: 1};
|
||||||
controller.$params = {id: 1};
|
|
||||||
|
|
||||||
$httpBackend.expectPOST('VnUsers/1/addAlias').respond();
|
$httpBackend.expectPOST('MailAliasAccounts').respond();
|
||||||
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
|
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
|
||||||
controller.onAddSave();
|
controller.onAddSave();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
@ -42,14 +41,12 @@ describe('component vnUserAliases', () => {
|
||||||
{id: 1, alias: 'foo'},
|
{id: 1, alias: 'foo'},
|
||||||
{id: 2, alias: 'bar'}
|
{id: 2, alias: 'bar'}
|
||||||
];
|
];
|
||||||
controller.$params = {id: 1};
|
|
||||||
|
|
||||||
$httpBackend.expectPOST('VnUsers/1/removeAlias').respond();
|
$httpBackend.expectDELETE('MailAliasAccounts/1').respond();
|
||||||
$httpBackend.expectGET('MailAliasAccounts').respond(controller.$.data[1]);
|
|
||||||
controller.onRemove(controller.$.data[0]);
|
controller.onRemove(controller.$.data[0]);
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.$.data).toEqual({id: 2, alias: 'bar'});
|
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]);
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
Self.remoteMethodCtx('canBeInvoiced', {
|
Self.remoteMethodCtx('canBeInvoiced', {
|
||||||
description: 'Change property isEqualizated in all client addresses',
|
description: 'Change property isEqualizated in all client addresses',
|
||||||
|
@ -9,6 +11,12 @@ module.exports = function(Self) {
|
||||||
required: true,
|
required: true,
|
||||||
description: 'Client id',
|
description: 'Client id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'companyFk',
|
||||||
|
description: 'The company id',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -22,18 +30,29 @@ module.exports = function(Self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.canBeInvoiced = async(id, options) => {
|
Self.canBeInvoiced = async(id, companyFk, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const client = await models.Client.findById(id, {
|
const client = await models.Client.findById(id, {
|
||||||
fields: ['id', 'isTaxDataChecked', 'hasToInvoice']
|
fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk'],
|
||||||
|
include:
|
||||||
|
{
|
||||||
|
relation: 'payMethod',
|
||||||
|
scope: {
|
||||||
|
fields: ['code']
|
||||||
|
}
|
||||||
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
const company = await models.Company.findById(companyFk, {fields: ['supplierAccountFk']}, myOptions);
|
||||||
|
|
||||||
|
if (client.payMethod().code === 'wireTransfer' && !company.supplierAccountFk)
|
||||||
|
throw new UserError('The company has not informed the supplier account for bank transfers');
|
||||||
|
|
||||||
if (client.isTaxDataChecked && client.hasToInvoice)
|
if (client.isTaxDataChecked && client.hasToInvoice)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ module.exports = Self => {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The ticket id',
|
description: 'The client id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,12 @@ module.exports = Self => {
|
||||||
Self.sendSms = async(ctx, id, destination, message) => {
|
Self.sendSms = async(ctx, id, destination, message) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const sms = await models.Sms.send(ctx, destination, message);
|
const sms = await models.Sms.send(ctx, destination, message);
|
||||||
|
|
||||||
|
await models.ClientSms.create({
|
||||||
|
clientFk: id,
|
||||||
|
smsFk: sms.id
|
||||||
|
});
|
||||||
|
|
||||||
return sms;
|
return sms;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ const LoopBackContext = require('loopback-context');
|
||||||
describe('client canBeInvoiced()', () => {
|
describe('client canBeInvoiced()', () => {
|
||||||
const userId = 19;
|
const userId = 19;
|
||||||
const clientId = 1101;
|
const clientId = 1101;
|
||||||
|
const companyId = 442;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: userId}
|
accessToken: {userId: userId}
|
||||||
};
|
};
|
||||||
|
@ -23,7 +24,7 @@ describe('client canBeInvoiced()', () => {
|
||||||
const client = await models.Client.findById(clientId, null, options);
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await client.updateAttribute('isTaxDataChecked', false, options);
|
await client.updateAttribute('isTaxDataChecked', false, options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
expect(canBeInvoiced).toEqual(false);
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ describe('client canBeInvoiced()', () => {
|
||||||
const client = await models.Client.findById(clientId, null, options);
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await client.updateAttribute('hasToInvoice', false, options);
|
await client.updateAttribute('hasToInvoice', false, options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
expect(canBeInvoiced).toEqual(false);
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ describe('client canBeInvoiced()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(true);
|
expect(canBeInvoiced).toEqual(true);
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ module.exports = Self => {
|
||||||
c.creditInsurance,
|
c.creditInsurance,
|
||||||
d.defaulterSinced,
|
d.defaulterSinced,
|
||||||
cn.country,
|
cn.country,
|
||||||
|
c.countryFk,
|
||||||
pm.name payMethod
|
pm.name payMethod
|
||||||
FROM vn.defaulter d
|
FROM vn.defaulter d
|
||||||
JOIN vn.client c ON c.id = d.clientFk
|
JOIN vn.client c ON c.id = d.clientFk
|
||||||
|
|
|
@ -95,6 +95,9 @@
|
||||||
"ClientSample": {
|
"ClientSample": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"ClientSms": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"Sms": {
|
"Sms": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"name": "ClientSms",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "clientSms"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "number",
|
||||||
|
"id": true,
|
||||||
|
"description": "Identifier"
|
||||||
|
},
|
||||||
|
"clientFk": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"sms": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Sms",
|
||||||
|
"foreignKey": "smsFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,7 +41,18 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function socialNameIsUnique(err, done) {
|
async function socialNameIsUnique(err, done) {
|
||||||
|
if (!this.countryFk)
|
||||||
|
return done();
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
|
include: {
|
||||||
|
relation: 'country',
|
||||||
|
scope: {
|
||||||
|
fields: {
|
||||||
|
isSocialNameUnique: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
where: {
|
where: {
|
||||||
and: [
|
and: [
|
||||||
{socialName: this.socialName},
|
{socialName: this.socialName},
|
||||||
|
@ -50,9 +61,13 @@ module.exports = Self => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const client = await Self.app.models.Client.findOne(filter);
|
|
||||||
if (client)
|
const client = await Self.app.models.Country.findById(this.countryFk, {fields: ['isSocialNameUnique']});
|
||||||
|
const existingClient = await Self.findOne(filter);
|
||||||
|
|
||||||
|
if (existingClient && (existingClient.country().isSocialNameUnique || client.isSocialNameUnique))
|
||||||
err();
|
err();
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,6 +181,11 @@
|
||||||
"model": "Country",
|
"model": "Country",
|
||||||
"foreignKey": "countryFk"
|
"foreignKey": "countryFk"
|
||||||
},
|
},
|
||||||
|
"isSocialNameUnique": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Country",
|
||||||
|
"foreignKey": "countryFk"
|
||||||
|
},
|
||||||
"contactChannel": {
|
"contactChannel": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "ContactChannel",
|
"model": "ContactChannel",
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"country": {
|
"country": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Country",
|
"model": "Country",
|
||||||
"foreignKey": "country"
|
"foreignKey": "countryFk"
|
||||||
},
|
},
|
||||||
"payMethod": {
|
"payMethod": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<th field="salesPersonFk">
|
<th field="salesPersonFk">
|
||||||
<span translate>Comercial</span>
|
<span translate>Comercial</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="country">
|
<th field="countryFk">
|
||||||
<span translate>Country</span>
|
<span translate>Country</span>
|
||||||
</th>
|
</th>
|
||||||
<th field="payMethod"
|
<th field="payMethod"
|
||||||
|
|
|
@ -31,10 +31,11 @@ export default class Controller extends Section {
|
||||||
valueField: 'id',
|
valueField: 'id',
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
field: 'country',
|
field: 'countryFk',
|
||||||
autocomplete: {
|
autocomplete: {
|
||||||
|
url: 'Countries',
|
||||||
showField: 'country',
|
showField: 'country',
|
||||||
valueField: 'country'
|
valueField: 'id'
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
field: 'payMethodFk',
|
field: 'payMethodFk',
|
||||||
|
@ -167,7 +168,7 @@ export default class Controller extends Section {
|
||||||
case 'amount':
|
case 'amount':
|
||||||
case 'clientFk':
|
case 'clientFk':
|
||||||
case 'workerFk':
|
case 'workerFk':
|
||||||
case 'country':
|
case 'countryFk':
|
||||||
case 'payMethod':
|
case 'payMethod':
|
||||||
case 'salesPersonFk':
|
case 'salesPersonFk':
|
||||||
return {[`d.${param}`]: value};
|
return {[`d.${param}`]: value};
|
||||||
|
|
|
@ -48,4 +48,5 @@ import './notification';
|
||||||
import './unpaid';
|
import './unpaid';
|
||||||
import './extended-list';
|
import './extended-list';
|
||||||
import './credit-management';
|
import './credit-management';
|
||||||
|
import './sms';
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
{"state": "client.card.recovery.index", "icon": "icon-recovery"},
|
{"state": "client.card.recovery.index", "icon": "icon-recovery"},
|
||||||
{"state": "client.card.webAccess", "icon": "cloud"},
|
{"state": "client.card.webAccess", "icon": "cloud"},
|
||||||
{"state": "client.card.log", "icon": "history"},
|
{"state": "client.card.log", "icon": "history"},
|
||||||
|
{"state": "client.card.sms", "icon": "sms"},
|
||||||
{
|
{
|
||||||
"description": "Credit management",
|
"description": "Credit management",
|
||||||
"icon": "monetization_on",
|
"icon": "monetization_on",
|
||||||
|
@ -373,6 +374,12 @@
|
||||||
"component": "vn-client-log",
|
"component": "vn-client-log",
|
||||||
"description": "Log"
|
"description": "Log"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"url" : "/sms",
|
||||||
|
"state": "client.card.sms",
|
||||||
|
"component": "vn-client-sms",
|
||||||
|
"description": "Sms"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"url": "/dms",
|
"url": "/dms",
|
||||||
"state": "client.card.dms",
|
"state": "client.card.dms",
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<vn-crud-model
|
||||||
|
vn-id="model"
|
||||||
|
url="ClientSms"
|
||||||
|
link="{clientFk: $ctrl.$params.id}"
|
||||||
|
filter="::$ctrl.filter"
|
||||||
|
data="clientSmsList"
|
||||||
|
limit="20"
|
||||||
|
auto-load="true">
|
||||||
|
</vn-crud-model>
|
||||||
|
<vn-data-viewer model="model">
|
||||||
|
<vn-card class="vn-w-md">
|
||||||
|
<vn-table model="model" auto-load="false">
|
||||||
|
<vn-thead>
|
||||||
|
<vn-tr>
|
||||||
|
<vn-th field="senderFk">Sender</vn-th>
|
||||||
|
<vn-th field="destination" number>Destination</vn-th>
|
||||||
|
<vn-th field="message">Message</vn-th>
|
||||||
|
<vn-th field="status">Status</vn-th>
|
||||||
|
<vn-th field="created" expand>Created</vn-th>
|
||||||
|
</vn-tr>
|
||||||
|
</vn-thead>
|
||||||
|
<vn-tbody>
|
||||||
|
<vn-tr ng-repeat="clientSms in clientSmsList">
|
||||||
|
<vn-td>
|
||||||
|
<span class="link" ng-click="workerDescriptor.show($event, clientSms.sms.senderFk)">
|
||||||
|
{{::clientSms.sms.sender.name}}
|
||||||
|
</span>
|
||||||
|
</vn-td>
|
||||||
|
<vn-td number expand>{{::clientSms.sms.destination}}</vn-td>
|
||||||
|
<vn-td>{{::clientSms.sms.message}}</vn-td>
|
||||||
|
<vn-td>{{::clientSms.sms.status}}</vn-td>
|
||||||
|
<vn-td shrink-datetime>{{::clientSms.sms.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>
|
||||||
|
</vn-tr>
|
||||||
|
</vn-tbody>
|
||||||
|
</vn-table>
|
||||||
|
</vn-card>
|
||||||
|
</vn-data-viewer>
|
||||||
|
<vn-worker-descriptor-popover
|
||||||
|
vn-id="worker-descriptor">
|
||||||
|
</vn-worker-descriptor-popover>
|
|
@ -0,0 +1,39 @@
|
||||||
|
import ngModule from '../module';
|
||||||
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
|
export default class Controller extends Section {
|
||||||
|
constructor($element, $) {
|
||||||
|
super($element, $);
|
||||||
|
|
||||||
|
this.filter = {
|
||||||
|
fields: ['id', 'smsFk'],
|
||||||
|
include: {
|
||||||
|
relation: 'sms',
|
||||||
|
scope: {
|
||||||
|
fields: [
|
||||||
|
'senderFk',
|
||||||
|
'sender',
|
||||||
|
'destination',
|
||||||
|
'message',
|
||||||
|
'statusCode',
|
||||||
|
'status',
|
||||||
|
'created'],
|
||||||
|
include: {
|
||||||
|
relation: 'sender',
|
||||||
|
scope: {
|
||||||
|
fields: ['name']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnClientSms', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller,
|
||||||
|
bindings: {
|
||||||
|
client: '<'
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,2 @@
|
||||||
|
Sender: Remitente
|
||||||
|
Number sender: Número remitente
|
|
@ -1,3 +1,5 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/invoice-in/filter')(Self);
|
require('../methods/invoice-in/filter')(Self);
|
||||||
require('../methods/invoice-in/summary')(Self);
|
require('../methods/invoice-in/summary')(Self);
|
||||||
|
@ -7,4 +9,9 @@ module.exports = Self => {
|
||||||
require('../methods/invoice-in/invoiceInPdf')(Self);
|
require('../methods/invoice-in/invoiceInPdf')(Self);
|
||||||
require('../methods/invoice-in/invoiceInEmail')(Self);
|
require('../methods/invoice-in/invoiceInEmail')(Self);
|
||||||
require('../methods/invoice-in/getSerial')(Self);
|
require('../methods/invoice-in/getSerial')(Self);
|
||||||
|
Self.rewriteDbError(function(err) {
|
||||||
|
if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn'))
|
||||||
|
return new UserError(`This invoice has a linked vehicle.`);
|
||||||
|
return err;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
|
||||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('activeBuyers', {
|
|
||||||
description: 'Returns a list of buyers for the given item type',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'filter',
|
|
||||||
type: 'object',
|
|
||||||
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: ['object'],
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/activeBuyers`,
|
|
||||||
verb: 'GET'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.activeBuyers = async(filter, options) => {
|
|
||||||
const conn = Self.dataSource.connector;
|
|
||||||
const where = {isActive: true};
|
|
||||||
const myOptions = {};
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
filter = mergeFilters(filter, {where});
|
|
||||||
|
|
||||||
let stmt = new ParameterizedSQL(
|
|
||||||
`SELECT DISTINCT w.id workerFk, w.firstName, w.lastName, u.name, u.nickname
|
|
||||||
FROM worker w
|
|
||||||
JOIN itemType it ON it.workerFk = w.id
|
|
||||||
JOIN account.user u ON u.id = w.id
|
|
||||||
JOIN item i ON i.typeFk = it.id`,
|
|
||||||
null, myOptions);
|
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
|
||||||
|
|
||||||
return conn.executeStmt(stmt);
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,24 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('Worker activeBuyers', () => {
|
|
||||||
it('should return the buyers in itemType as result', async() => {
|
|
||||||
const tx = await models.Item.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const filter = {};
|
|
||||||
const result = await models.Item.activeBuyers(filter, options);
|
|
||||||
const firstWorker = result[0];
|
|
||||||
const secondWorker = result[1];
|
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
|
||||||
expect(firstWorker.nickname).toEqual('logisticBossNick');
|
|
||||||
expect(secondWorker.nickname).toEqual('buyerNick');
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -25,6 +25,9 @@
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"visible": {
|
"visible": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"userFk": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,6 @@ module.exports = Self => {
|
||||||
require('../methods/item/getWasteByWorker')(Self);
|
require('../methods/item/getWasteByWorker')(Self);
|
||||||
require('../methods/item/getWasteByItem')(Self);
|
require('../methods/item/getWasteByItem')(Self);
|
||||||
require('../methods/item/createIntrastat')(Self);
|
require('../methods/item/createIntrastat')(Self);
|
||||||
require('../methods/item/activeBuyers')(Self);
|
|
||||||
require('../methods/item/buyerWasteEmail')(Self);
|
require('../methods/item/buyerWasteEmail')(Self);
|
||||||
require('../methods/item/labelPdf')(Self);
|
require('../methods/item/labelPdf')(Self);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
search-function="{firstName: $search}"
|
search-function="{firstName: $search}"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
where="{role: {inq: ['logistic', 'buyer']}}"
|
where="{role: {inq: ['logistic', 'buyer']}}"
|
||||||
label="Atender">
|
label="Buyer">
|
||||||
<tpl-item>{{nickname}}</tpl-item>
|
<tpl-item>{{nickname}}</tpl-item>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
|
@ -41,10 +41,10 @@
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="filter.buyerFk"
|
ng-model="filter.buyerFk"
|
||||||
url="Items/activeBuyers"
|
url="TicketRequests/getItemTypeWorker"
|
||||||
|
search-function="{firstName: $search}"
|
||||||
show-field="nickname"
|
show-field="nickname"
|
||||||
search-function="{nickname: {like: '%'+ $search +'%'}}"
|
value-field="id"
|
||||||
value-field="workerFk"
|
|
||||||
label="Buyer">
|
label="Buyer">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
|
|
|
@ -84,14 +84,21 @@
|
||||||
tabindex="-1">
|
tabindex="-1">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-td>
|
</vn-td>
|
||||||
<vn-td>
|
<vn-td-editable number>
|
||||||
|
<text>
|
||||||
|
<strong>{{ticket.priority}}</strong>
|
||||||
|
</text>
|
||||||
|
<field>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
|
|
||||||
ng-model="ticket.priority"
|
|
||||||
rule="Ticket"
|
rule="Ticket"
|
||||||
class="dense">
|
ng-model="ticket.priority"
|
||||||
|
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
|
||||||
|
step="1"
|
||||||
|
class="dense"
|
||||||
|
vn-focus>
|
||||||
</vn-input-number>
|
</vn-input-number>
|
||||||
</vn-td>
|
</field>
|
||||||
|
</vn-td-editable>
|
||||||
<vn-td expand title="{{::ticket.street}}">{{::ticket.street}}</vn-td>
|
<vn-td expand title="{{::ticket.street}}">{{::ticket.street}}</vn-td>
|
||||||
<vn-td
|
<vn-td
|
||||||
expand
|
expand
|
||||||
|
|
|
@ -68,9 +68,9 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
const country = await Self.app.models.Country.findOne(filter);
|
const country = await Self.app.models.Country.findOne(filter);
|
||||||
const code = country ? country.code.toLowerCase() : null;
|
const code = country ? country.code.toLowerCase() : null;
|
||||||
const countryCode = this.nif.toLowerCase().substring(0, 2);
|
const countryCode = this.nif?.toLowerCase().substring(0, 2);
|
||||||
|
|
||||||
if (!this.nif || !validateTin(this.nif, code) || (this.isVies && countryCode == code))
|
if (!validateTin(this.nif, code) || (this.isVies && countryCode == code))
|
||||||
err();
|
err();
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function hasSupplierSameName(err, done) {
|
async function hasSupplierSameName(err, done) {
|
||||||
if (!this.name || !this.countryFk) done();
|
if (!this.name || !this.countryFk) return done();
|
||||||
const supplier = await Self.app.models.Supplier.findOne(
|
const supplier = await Self.app.models.Supplier.findOne(
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||||
|
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('getItemTypeWorker', {
|
Self.remoteMethod('getItemTypeWorker', {
|
||||||
description: 'Returns the workers that appear in itemType',
|
description: 'Returns the workers that appear in itemType',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
|
@ -20,38 +22,37 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getItemTypeWorker = async(ctx, filter, options) => {
|
Self.getItemTypeWorker = async filter => {
|
||||||
const myOptions = {};
|
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
let tx;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
const query =
|
const query =
|
||||||
`SELECT DISTINCT u.id, u.nickname
|
`SELECT DISTINCT u.id, u.nickname
|
||||||
FROM itemType it
|
FROM itemType it
|
||||||
JOIN worker w ON w.id = it.workerFk
|
JOIN worker w ON w.id = it.workerFk
|
||||||
JOIN account.user u ON u.id = w.id`;
|
JOIN account.user u ON u.id = w.id`;
|
||||||
|
const stmt = new ParameterizedSQL(query);
|
||||||
|
|
||||||
let stmt = new ParameterizedSQL(query);
|
filter.where = buildFilter(filter.where, (param, value) => {
|
||||||
|
switch (param) {
|
||||||
if (filter.where) {
|
case 'firstName':
|
||||||
const value = filter.where.firstName;
|
return {or: [
|
||||||
const myFilter = {
|
|
||||||
where: {or: [
|
|
||||||
{'w.firstName': {like: `%${value}%`}},
|
{'w.firstName': {like: `%${value}%`}},
|
||||||
{'w.lastName': {like: `%${value}%`}},
|
{'w.lastName': {like: `%${value}%`}},
|
||||||
{'u.name': {like: `%${value}%`}},
|
{'u.name': {like: `%${value}%`}},
|
||||||
{'u.nickname': {like: `%${value}%`}}
|
{'u.nickname': {like: `%${value}%`}}
|
||||||
]}
|
]};
|
||||||
|
case 'id':
|
||||||
|
return {'w.id': value};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let myFilter = {
|
||||||
|
where: {'u.active': true}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
myFilter = mergeFilters(myFilter, filter);
|
||||||
|
|
||||||
stmt.merge(conn.makeSuffix(myFilter));
|
stmt.merge(conn.makeSuffix(myFilter));
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
|
|
||||||
return conn.executeStmt(stmt);
|
return conn.executeStmt(stmt);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('ticket-request getItemTypeWorker()', () => {
|
describe('ticket-request getItemTypeWorker()', () => {
|
||||||
const ctx = {req: {accessToken: {userId: 18}}};
|
|
||||||
|
|
||||||
it('should return the buyer as result', async() => {
|
it('should return the buyer as result', async() => {
|
||||||
const filter = {where: {firstName: 'buyer'}};
|
const filter = {where: {firstName: 'buyer'}};
|
||||||
|
|
||||||
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
const result = await models.TicketRequest.getItemTypeWorker(filter);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
@ -14,7 +12,7 @@ describe('ticket-request getItemTypeWorker()', () => {
|
||||||
it('should return the workers at itemType as result', async() => {
|
it('should return the workers at itemType as result', async() => {
|
||||||
const filter = {};
|
const filter = {};
|
||||||
|
|
||||||
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
const result = await models.TicketRequest.getItemTypeWorker(filter);
|
||||||
|
|
||||||
expect(result.length).toBeGreaterThan(1);
|
expect(result.length).toBeGreaterThan(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
@ -47,9 +46,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, id, myOptions);
|
await models.Ticket.isEditableOrThrow(ctx, id, myOptions);
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
|
||||||
|
|
||||||
const item = await models.Item.findById(itemId, null, myOptions);
|
const item = await models.Item.findById(itemId, null, myOptions);
|
||||||
const ticket = await models.Ticket.findById(id, {
|
const ticket = await models.Ticket.findById(id, {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
const loggable = require('vn-loopback/util/log');
|
const loggable = require('vn-loopback/util/log');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
@ -116,10 +115,7 @@ module.exports = Self => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const $t = ctx.req.__; // $translate
|
const $t = ctx.req.__; // $translate
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, args.id, myOptions);
|
await models.Ticket.isEditableOrThrow(ctx, args.id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
|
||||||
|
|
||||||
const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE');
|
const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE');
|
||||||
if (!editZone) {
|
if (!editZone) {
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('docuwareDownload', {
|
||||||
|
description: 'Download a ticket delivery note document',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The document id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
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/docuwareDownload`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.docuwareDownload = async id => {
|
||||||
|
const filter = {
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
DBName: docuwareInfo.findById,
|
||||||
|
Value: [id]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DBName: 'ESTADO',
|
||||||
|
Value: ['Firmado']
|
||||||
|
}
|
||||||
|
],
|
||||||
|
sortOrder: [
|
||||||
|
{
|
||||||
|
Field: 'FILENAME',
|
||||||
|
Direction: 'Desc'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
return Self.app.models.Docuware.download(id, 'deliveryNote', filter);
|
||||||
|
};
|
||||||
|
};
|
|
@ -20,41 +20,12 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.isEditable = async(ctx, id, options) => {
|
Self.isEditable = async(ctx, id, options) => {
|
||||||
const models = Self.app.models;
|
try {
|
||||||
const myOptions = {};
|
await Self.isEditableOrThrow(ctx, id, options);
|
||||||
|
} catch (e) {
|
||||||
if (typeof options == 'object')
|
if (e.name === 'ForbiddenError') return false;
|
||||||
Object.assign(myOptions, options);
|
throw e;
|
||||||
|
|
||||||
const state = await models.TicketState.findOne({
|
|
||||||
where: {ticketFk: id}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*');
|
|
||||||
|
|
||||||
const alertLevel = state ? state.alertLevel : null;
|
|
||||||
const ticket = await models.Ticket.findById(id, {
|
|
||||||
fields: ['clientFk'],
|
|
||||||
include: [{
|
|
||||||
relation: 'client',
|
|
||||||
scope: {
|
|
||||||
include: {
|
|
||||||
relation: 'type'
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}]
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const isLocked = await models.Ticket.isLocked(id, myOptions);
|
|
||||||
const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions);
|
|
||||||
|
|
||||||
const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0);
|
|
||||||
const isNormalClient = ticket && ticket.client().type().code == 'normal';
|
|
||||||
const isEditable = !(alertLevelGreaterThanZero && isNormalClient);
|
|
||||||
|
|
||||||
if (ticket && (isEditable || isRoleAdvanced) && !isLocked && !isWeekly)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.isEditableOrThrow = async(ctx, id, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const state = await models.TicketState.findOne({
|
||||||
|
where: {ticketFk: id}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*');
|
||||||
|
const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'canEditWeekly', 'WRITE');
|
||||||
|
const alertLevel = state ? state.alertLevel : null;
|
||||||
|
const ticket = await models.Ticket.findById(id, {
|
||||||
|
fields: ['clientFk'],
|
||||||
|
include: [{
|
||||||
|
relation: 'client',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'type'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const isLocked = await models.Ticket.isLocked(id, myOptions);
|
||||||
|
const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions);
|
||||||
|
|
||||||
|
const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0);
|
||||||
|
const isNormalClient = ticket && ticket.client().type().code == 'normal';
|
||||||
|
const isEditable = !(alertLevelGreaterThanZero && isNormalClient);
|
||||||
|
|
||||||
|
if (!ticket)
|
||||||
|
throw new ForbiddenError(`The ticket doesn't exist.`);
|
||||||
|
|
||||||
|
if (!isEditable && !isRoleAdvanced)
|
||||||
|
throw new ForbiddenError(`This ticket is not editable.`);
|
||||||
|
|
||||||
|
if (isLocked)
|
||||||
|
throw new ForbiddenError(`This ticket is locked.`);
|
||||||
|
|
||||||
|
if (isWeekly && !canEditWeeklyTicket)
|
||||||
|
throw new ForbiddenError(`You don't have enough privileges.`);
|
||||||
|
};
|
||||||
|
};
|
|
@ -14,7 +14,7 @@ module.exports = function(Self) {
|
||||||
{
|
{
|
||||||
arg: 'companyFk',
|
arg: 'companyFk',
|
||||||
description: 'The company id',
|
description: 'The company id',
|
||||||
type: 'string',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
const [firstTicket] = tickets;
|
const [firstTicket] = tickets;
|
||||||
const clientId = firstTicket.clientFk;
|
const clientId = firstTicket.clientFk;
|
||||||
const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, myOptions);
|
const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, companyFk, myOptions);
|
||||||
if (!clientCanBeInvoiced)
|
if (!clientCanBeInvoiced)
|
||||||
throw new UserError(`This client can't be invoiced`);
|
throw new UserError(`This client can't be invoiced`);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('priceDifference', {
|
Self.remoteMethodCtx('priceDifference', {
|
||||||
description: 'Returns sales with price difference if the ticket is editable',
|
description: 'Returns sales with price difference if the ticket is editable',
|
||||||
|
@ -72,10 +70,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isEditable = await Self.isEditable(ctx, args.id, myOptions);
|
await Self.isEditableOrThrow(ctx, args.id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
|
||||||
|
|
||||||
const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE');
|
const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE');
|
||||||
if (!editZone) {
|
if (!editZone) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('recalculateComponents', {
|
Self.remoteMethodCtx('recalculateComponents', {
|
||||||
description: 'Calculates the price of a sale and its components',
|
description: 'Calculates the price of a sale and its components',
|
||||||
|
@ -33,10 +32,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isEditable = await Self.isEditable(ctx, id, myOptions);
|
await Self.isEditableOrThrow(ctx, id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The current ticket can't be modified`);
|
|
||||||
|
|
||||||
const recalculation = await Self.rawSql('CALL vn.ticket_recalcComponents(?, NULL)', [id], myOptions);
|
const recalculation = await Self.rawSql('CALL vn.ticket_recalcComponents(?, NULL)', [id], myOptions);
|
||||||
|
|
||||||
|
|
|
@ -39,10 +39,7 @@ module.exports = Self => {
|
||||||
const ticketToDelete = await models.Ticket.findById(id, {fields: ['isDeleted']}, myOptions);
|
const ticketToDelete = await models.Ticket.findById(id, {fields: ['isDeleted']}, myOptions);
|
||||||
if (ticketToDelete.isDeleted) return false;
|
if (ticketToDelete.isDeleted) return false;
|
||||||
|
|
||||||
const isEditable = await Self.isEditable(ctx, id, myOptions);
|
await Self.isEditableOrThrow(ctx, id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
|
||||||
|
|
||||||
// Check if ticket has refunds
|
// Check if ticket has refunds
|
||||||
const ticketRefunds = await models.TicketRefund.find({
|
const ticketRefunds = await models.TicketRefund.find({
|
||||||
|
|
|
@ -97,6 +97,6 @@ describe('ticket addSale()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`The sales of this ticket can't be modified`);
|
expect(error.message).toEqual(`This ticket is locked.`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -141,6 +141,7 @@ describe('ticket filter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the tickets that are not pending', async() => {
|
it('should return the tickets that are not pending', async() => {
|
||||||
|
pending('#6010 test intermitente');
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,156 +1,37 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('ticket isEditable()', () => {
|
describe('isEditable()', () => {
|
||||||
it('should return false if the given ticket does not exist', async() => {
|
it('should return false if It is able to edit', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const ctx = {
|
const ctx = {req: {accessToken: {userId: 35}}};
|
||||||
req: {accessToken: {userId: 9}}
|
result = await models.Ticket.isEditable(ctx, 5, options);
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, 9999, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should return false if the given ticket isn't invoiced but isDeleted`, async() => {
|
it('should return true if It is able to edit', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const deletedTicket = await models.Ticket.findOne({
|
const ctx = {req: {accessToken: {userId: 35}}};
|
||||||
where: {
|
result = await models.Ticket.isEditable(ctx, 15, options);
|
||||||
invoiceOut: null,
|
|
||||||
isDeleted: true
|
|
||||||
},
|
|
||||||
fields: ['id']
|
|
||||||
});
|
|
||||||
|
|
||||||
const ctx = {
|
|
||||||
req: {accessToken: {userId: 9}}
|
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, deletedTicket.id, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
expect(result).toBeTrue();
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if the given ticket is editable', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const ctx = {
|
|
||||||
req: {accessToken: {userId: 9}}
|
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, 16, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(result).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be able to edit a deleted or invoiced ticket even for salesAssistant', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const ctx = {
|
|
||||||
req: {accessToken: {userId: 21}}
|
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, 19, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be able to edit a deleted or invoiced ticket even for productionBoss', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const ctx = {
|
|
||||||
req: {accessToken: {userId: 50}}
|
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, 19, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be able to edit a deleted or invoiced ticket even for salesPerson', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
let result;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const ctx = {
|
|
||||||
req: {accessToken: {userId: 18}}
|
|
||||||
};
|
|
||||||
|
|
||||||
result = await models.Ticket.isEditable(ctx, 19, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not be able to edit if is a ticket weekly', async() => {
|
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const ctx = {req: {accessToken: {userId: 1}}};
|
|
||||||
|
|
||||||
const result = await models.Ticket.isEditable(ctx, 15, options);
|
|
||||||
|
|
||||||
expect(result).toEqual(false);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('ticket isEditableOrThrow()', () => {
|
||||||
|
it('should throw an error as the ticket does not exist', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: 9}}
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.Ticket.isEditableOrThrow(ctx, 9999, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`The ticket doesn't exist.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error as this ticket is not editable', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: 1}}
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.Ticket.isEditableOrThrow(ctx, 8, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`This ticket is not editable.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error as this ticket is locked.', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ctx = {
|
||||||
|
req: {accessToken: {userId: 18}}
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.Ticket.isEditableOrThrow(ctx, 19, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`This ticket is locked.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error as you do not have enough privileges.', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ctx = {req: {accessToken: {userId: 1}}};
|
||||||
|
|
||||||
|
await models.Ticket.isEditableOrThrow(ctx, 15, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`You don't have enough privileges.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined if It can be edited', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ctx = {req: {accessToken: {userId: 35}}};
|
||||||
|
|
||||||
|
result = await models.Ticket.isEditableOrThrow(ctx, 15, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,5 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
||||||
|
|
||||||
describe('sale priceDifference()', () => {
|
describe('sale priceDifference()', () => {
|
||||||
it('should return ticket price differences', async() => {
|
it('should return ticket price differences', async() => {
|
||||||
|
@ -59,7 +60,7 @@ describe('sale priceDifference()', () => {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toEqual(new UserError(`The sales of this ticket can't be modified`));
|
expect(error).toEqual(new ForbiddenError(`This ticket is not editable.`));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return ticket movable', async() => {
|
it('should return ticket movable', async() => {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const ForbiddenError = require('vn-loopback/util/forbiddenError');
|
||||||
|
|
||||||
describe('ticket recalculateComponents()', () => {
|
describe('ticket recalculateComponents()', () => {
|
||||||
const ticketId = 11;
|
const ticketId = 11;
|
||||||
|
@ -38,6 +39,6 @@ describe('ticket recalculateComponents()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error).toEqual(new Error(`The current ticket can't be modified`));
|
expect(error).toEqual(new ForbiddenError(`This ticket is locked.`));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Ticket transferClient()', () => {
|
||||||
|
const userId = 9;
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: userId},
|
||||||
|
};
|
||||||
|
const ctx = {req: activeCtx};
|
||||||
|
|
||||||
|
it('should throw an error as the ticket is not editable', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let error;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const ticketId = 4;
|
||||||
|
const clientId = 1;
|
||||||
|
await models.Ticket.transferClient(ctx, ticketId, clientId, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual(`This ticket is locked.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be assigned a different clientFk', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
let updatedTicket;
|
||||||
|
const ticketId = 10;
|
||||||
|
const clientId = 1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
await models.Ticket.transferClient(ctx, ticketId, clientId, options);
|
||||||
|
updatedTicket = await models.Ticket.findById(ticketId, {fields: ['clientFk']}, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(updatedTicket.clientFk).toEqual(clientId);
|
||||||
|
});
|
||||||
|
});
|
|
@ -33,7 +33,7 @@ describe('sale transferSales()', () => {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(error.message).toEqual(`The sales of this ticket can't be modified`);
|
expect(error.message).toEqual(`This ticket is not editable.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the receiving ticket is not editable', async() => {
|
it('should throw an error if the receiving ticket is not editable', async() => {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('transferClient', {
|
||||||
|
description: 'Transfering ticket to another client',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'the ticket id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'clientFk',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
http: {
|
||||||
|
path: `/:id/transferClient`,
|
||||||
|
verb: 'PATCH'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.transferClient = async(ctx, id, clientFk, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
await Self.isEditableOrThrow(ctx, id, myOptions);
|
||||||
|
|
||||||
|
const ticket = await models.Ticket.findById(
|
||||||
|
id,
|
||||||
|
{fields: ['id', 'shipped', 'clientFk', 'addressFk']},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions);
|
||||||
|
|
||||||
|
await ticket.updateAttributes({
|
||||||
|
clientFk,
|
||||||
|
addressFk: client.defaultAddressFk,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
let UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('transferSales', {
|
Self.remoteMethodCtx('transferSales', {
|
||||||
|
@ -48,9 +48,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, id, myOptions);
|
await models.Ticket.isEditableOrThrow(ctx, id, myOptions);
|
||||||
if (!isEditable)
|
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
|
||||||
|
|
||||||
if (ticketId) {
|
if (ticketId) {
|
||||||
const isReceiverEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions);
|
const isReceiverEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions);
|
||||||
|
|
|
@ -6,6 +6,7 @@ module.exports = function(Self) {
|
||||||
require('../methods/ticket/componentUpdate')(Self);
|
require('../methods/ticket/componentUpdate')(Self);
|
||||||
require('../methods/ticket/new')(Self);
|
require('../methods/ticket/new')(Self);
|
||||||
require('../methods/ticket/isEditable')(Self);
|
require('../methods/ticket/isEditable')(Self);
|
||||||
|
require('../methods/ticket/isEditableOrThrow')(Self);
|
||||||
require('../methods/ticket/setDeleted')(Self);
|
require('../methods/ticket/setDeleted')(Self);
|
||||||
require('../methods/ticket/restore')(Self);
|
require('../methods/ticket/restore')(Self);
|
||||||
require('../methods/ticket/getSales')(Self);
|
require('../methods/ticket/getSales')(Self);
|
||||||
|
@ -19,6 +20,7 @@ module.exports = function(Self) {
|
||||||
require('../methods/ticket/uploadFile')(Self);
|
require('../methods/ticket/uploadFile')(Self);
|
||||||
require('../methods/ticket/addSale')(Self);
|
require('../methods/ticket/addSale')(Self);
|
||||||
require('../methods/ticket/transferSales')(Self);
|
require('../methods/ticket/transferSales')(Self);
|
||||||
|
require('../methods/ticket/transferClient')(Self);
|
||||||
require('../methods/ticket/recalculateComponents')(Self);
|
require('../methods/ticket/recalculateComponents')(Self);
|
||||||
require('../methods/ticket/sendSms')(Self);
|
require('../methods/ticket/sendSms')(Self);
|
||||||
require('../methods/ticket/isLocked')(Self);
|
require('../methods/ticket/isLocked')(Self);
|
||||||
|
|
|
@ -36,13 +36,12 @@
|
||||||
translate>
|
translate>
|
||||||
as PDF without prices
|
as PDF without prices
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<a class="vn-item"
|
<vn-item
|
||||||
ng-if="$ctrl.hasDocuwareFile"
|
ng-if="$ctrl.hasDocuwareFile"
|
||||||
href='api/Docuwares/{{$ctrl.ticket.id}}/download/deliveryNote?access_token={{$ctrl.vnToken.token}}'
|
ng-click="$ctrl.docuwareDownload()"
|
||||||
target="_blank"
|
|
||||||
translate>
|
translate>
|
||||||
as PDF signed
|
as PDF signed
|
||||||
</a>
|
</vn-item>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="$ctrl.showCsvDeliveryNote()"
|
ng-click="$ctrl.showCsvDeliveryNote()"
|
||||||
translate>
|
translate>
|
||||||
|
|
|
@ -96,20 +96,14 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
transferClient() {
|
transferClient() {
|
||||||
this.$http.get(`Clients/${this.ticket.client.id}`).then(client => {
|
|
||||||
const ticket = this.ticket;
|
const ticket = this.ticket;
|
||||||
|
const clientFk = ticket.client.id;
|
||||||
|
|
||||||
const params =
|
this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientFk})
|
||||||
{
|
.then(() => {
|
||||||
clientFk: client.data.id,
|
|
||||||
addressFk: client.data.defaultAddressFk,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.$http.patch(`Tickets/${ticket.id}`, params).then(() => {
|
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
this.reload();
|
this.reload();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isTicketEditable() {
|
isTicketEditable() {
|
||||||
|
@ -327,6 +321,10 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docuwareDownload() {
|
||||||
|
this.vnFile.download(`api/Ticket/${this.ticket.id}/docuwareDownload`);
|
||||||
|
}
|
||||||
|
|
||||||
setTicketWeight(weight) {
|
setTicketWeight(weight) {
|
||||||
return this.$http.patch(`Tickets/${this.ticket.id}`, {weight})
|
return this.$http.patch(`Tickets/${this.ticket.id}`, {weight})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
|
@ -326,17 +326,4 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('transferClient()', () => {
|
|
||||||
it(`should perform two queries, a get to obtain the clientData and a patch to update the ticket`, () => {
|
|
||||||
const client =
|
|
||||||
{
|
|
||||||
clientFk: 1101,
|
|
||||||
addressFk: 1,
|
|
||||||
};
|
|
||||||
$httpBackend.expect('GET', `Clients/${ticket.client.id}`).respond(client);
|
|
||||||
$httpBackend.expect('PATCH', `Tickets/${ticket.id}`).respond();
|
|
||||||
controller.transferClient();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,10 +38,12 @@ class Controller extends SearchPanel {
|
||||||
|
|
||||||
applyFilters(param) {
|
applyFilters(param) {
|
||||||
if (typeof this.filter.scopeDays === 'number') {
|
if (typeof this.filter.scopeDays === 'number') {
|
||||||
const shippedFrom = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
|
const shippedFrom = new Date(today.getTime());
|
||||||
|
shippedFrom.setDate(today.getDate() - 30);
|
||||||
shippedFrom.setHours(0, 0, 0, 0);
|
shippedFrom.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
const shippedTo = new Date(shippedFrom.getTime());
|
const shippedTo = new Date(today.getTime());
|
||||||
shippedTo.setDate(shippedTo.getDate() + this.filter.scopeDays);
|
shippedTo.setDate(shippedTo.getDate() + this.filter.scopeDays);
|
||||||
shippedTo.setHours(23, 59, 59, 999);
|
shippedTo.setHours(23, 59, 59, 999);
|
||||||
Object.assign(this.filter, {shippedFrom, shippedTo});
|
Object.assign(this.filter, {shippedFrom, shippedTo});
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('docuwareDownload', {
|
||||||
|
description: 'Download a worker document',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The document id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
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/docuwareDownload`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.docuwareDownload = async id => {
|
||||||
|
const filter = {
|
||||||
|
condition: [
|
||||||
|
{
|
||||||
|
DBName: 'FILENAME',
|
||||||
|
Value: [id]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
return Self.app.models.Docuware.download(id, 'hr', filter);
|
||||||
|
};
|
||||||
|
};
|
|
@ -5,6 +5,12 @@ module.exports = Self => {
|
||||||
description: 'Find all instances of the model matched by filter from the data source.',
|
description: 'Find all instances of the model matched by filter from the data source.',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'Object',
|
||||||
|
@ -17,16 +23,17 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/filter`,
|
path: `/:id/filter`,
|
||||||
verb: 'GET'
|
verb: 'GET'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter) => {
|
Self.filter = async(ctx, id, filter) => {
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const models = Self.app.models;
|
||||||
|
|
||||||
const account = await Self.app.models.VnUser.findById(userId);
|
const account = await models.VnUser.findById(userId);
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile
|
`SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile
|
||||||
FROM workerDocument wd
|
FROM workerDocument wd
|
||||||
|
@ -47,7 +54,38 @@ module.exports = Self => {
|
||||||
}]
|
}]
|
||||||
}, oldWhere]};
|
}, oldWhere]};
|
||||||
stmt.merge(conn.makeSuffix(filter));
|
stmt.merge(conn.makeSuffix(filter));
|
||||||
|
const workerDms = await conn.executeStmt(stmt);
|
||||||
|
|
||||||
return await conn.executeStmt(stmt);
|
// Get docuware info
|
||||||
|
const docuware = await models.Docuware.findOne({
|
||||||
|
fields: ['dmsTypeFk'],
|
||||||
|
where: {code: 'hr', action: 'find'}
|
||||||
|
});
|
||||||
|
const docuwareDmsType = docuware.dmsTypeFk;
|
||||||
|
let workerDocuware = [];
|
||||||
|
if (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType))) {
|
||||||
|
const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']});
|
||||||
|
const docuwareParse = {
|
||||||
|
'Filename': 'dmsFk',
|
||||||
|
'Tipo Documento': 'description',
|
||||||
|
'Stored on': 'created',
|
||||||
|
'Document ID': 'id'
|
||||||
|
};
|
||||||
|
workerDocuware =
|
||||||
|
await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse) ?? [];
|
||||||
|
for (document of workerDocuware) {
|
||||||
|
const defaultData = {
|
||||||
|
file: 'dw' + document.id + '.png',
|
||||||
|
isDocuware: true,
|
||||||
|
hardCopyNumber: null,
|
||||||
|
hasFile: false,
|
||||||
|
reference: worker.fi,
|
||||||
|
dmsFk: 'DW' + document.id
|
||||||
|
};
|
||||||
|
|
||||||
|
document = Object.assign(document, defaultData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return workerDms.concat(workerDocuware);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@ module.exports = Self => {
|
||||||
require('../methods/worker-dms/downloadFile')(Self);
|
require('../methods/worker-dms/downloadFile')(Self);
|
||||||
require('../methods/worker-dms/removeFile')(Self);
|
require('../methods/worker-dms/removeFile')(Self);
|
||||||
require('../methods/worker-dms/filter')(Self);
|
require('../methods/worker-dms/filter')(Self);
|
||||||
|
require('../methods/worker-dms/docuwareDownload')(Self);
|
||||||
|
|
||||||
Self.isMine = async function(ctx, dmsId) {
|
Self.isMine = async function(ctx, dmsId) {
|
||||||
const myUserId = ctx.req.accessToken.userId;
|
const myUserId = ctx.req.accessToken.userId;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
data="absenceTypes"
|
data="absenceTypes"
|
||||||
auto-load="true">
|
auto-load="true">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<div ng-if="$ctrl.worker.hasWorkCenter">
|
<div ng-if="$ctrl.card.hasWorkCenter">
|
||||||
<div class="vn-w-lg">
|
<div class="vn-w-lg">
|
||||||
<vn-card class="vn-pa-sm calendars">
|
<vn-card class="vn-pa-sm calendars">
|
||||||
<vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal
|
<vn-icon ng-if="::$ctrl.isSubordinate" icon="info" color-marginal
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
ng-if="!$ctrl.worker.hasWorkCenter"
|
ng-if="!$ctrl.card.hasWorkCenter"
|
||||||
class="bg-title"
|
class="bg-title"
|
||||||
translate>
|
translate>
|
||||||
Autonomous worker
|
Autonomous worker
|
||||||
|
@ -82,16 +82,14 @@
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
</div>
|
</div>
|
||||||
<div name="absenceTypes" class="input vn-py-md" style="overflow: hidden;">
|
<div name="absenceTypes" class="input vn-py-md" style="overflow: hidden;">
|
||||||
<vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}"
|
<vn-chip ng-repeat="absenceType in absenceTypes" ng-class="::{'selectable': $ctrl.isSubordinate}" ng-click="$ctrl.pick(absenceType)">
|
||||||
ng-click="$ctrl.pick(absenceType)">
|
<vn-avatar ng-style="{backgroundColor: absenceType.rgb}">
|
||||||
<vn-avatar
|
|
||||||
ng-style="{backgroundColor: absenceType.rgb}">
|
|
||||||
<vn-icon icon="check" ng-if="absenceType.id == $ctrl.absenceType.id"></vn-icon>
|
<vn-icon icon="check" ng-if="absenceType.id == $ctrl.absenceType.id"></vn-icon>
|
||||||
</vn-avatar>
|
</vn-avatar>
|
||||||
{{absenceType.name}}
|
{{absenceType.name}}
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
</div>
|
</div>
|
||||||
<div class="vn-py-md">
|
<div class="vn-py-md">
|
||||||
<vn-chip>
|
<vn-chip>
|
||||||
<vn-avatar class="festive">
|
<vn-avatar class="festive">
|
||||||
</vn-avatar>
|
</vn-avatar>
|
||||||
|
@ -102,12 +100,12 @@
|
||||||
</vn-avatar>
|
</vn-avatar>
|
||||||
<span translate>Current day</span>
|
<span translate>Current day</span>
|
||||||
</vn-chip>
|
</vn-chip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</vn-side-menu>
|
</vn-side-menu>
|
||||||
|
|
||||||
<vn-confirm
|
<vn-confirm
|
||||||
vn-id="confirm"
|
vn-id="confirm"
|
||||||
message="This item will be deleted"
|
message="This item will be deleted"
|
||||||
question="Are you sure you want to continue?">
|
question="Are you sure you want to continue?">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
set businessId(value) {
|
set businessId(value) {
|
||||||
|
if (!this.card.hasWorkCenter) return;
|
||||||
|
|
||||||
this._businessId = value;
|
this._businessId = value;
|
||||||
if (value) {
|
if (value) {
|
||||||
this.refresh()
|
this.refresh()
|
||||||
|
@ -64,7 +66,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
if (value && value.hasWorkCenter) {
|
if (value) {
|
||||||
this.getIsSubordinate();
|
this.getIsSubordinate();
|
||||||
this.getActiveContract();
|
this.getActiveContract();
|
||||||
}
|
}
|
||||||
|
@ -293,5 +295,8 @@ ngModule.vnComponent('vnWorkerCalendar', {
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
worker: '<'
|
worker: '<'
|
||||||
|
},
|
||||||
|
require: {
|
||||||
|
card: '^vnWorkerCard'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue