Compare commits
No commits in common. "2b190047832c98592190e9ad6d0cc662249044f8" and "f2b14184193b88faf53057ab2147d5a264ac77da" have entirely different histories.
2b19004783
...
f2b1418419
|
@ -88,7 +88,7 @@ module.exports = Self => {
|
|||
warehouseFk: args.warehouseId,
|
||||
reference: args.reference,
|
||||
description: args.description,
|
||||
contentType: uploadedFile.type,
|
||||
contentType: args.contentType,
|
||||
hasFile: args.hasFile
|
||||
};
|
||||
const extension = await models.DmsContainer.getFileExtension(uploadedFile.name);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`doc`
|
||||
AS SELECT `g`.`id` AS `id`,
|
||||
`g`.`sref` AS `sref`,
|
||||
`g`.`brief` AS `brief`,
|
||||
`g`.`emp_id` AS `companyFk`,
|
||||
`g`.`orden` AS `order`,
|
||||
`g`.`file` AS `file`,
|
||||
`g`.`original` AS `original`,
|
||||
`g`.`trabajador_id` AS `workerFk`,
|
||||
`g`.`odbc_date` AS `created`,
|
||||
`g`.`warehouse_id` AS `warehouseFk`
|
||||
FROM `vn2008`.`gestdoc` `g`
|
|
@ -1,11 +1,9 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`credit`
|
||||
AS SELECT
|
||||
`c`.`id` AS `id`,
|
||||
`c`.`clientFk` AS `Id_Cliente`,
|
||||
`c`.`workerFk` AS `Id_Trabajador`,
|
||||
`c`.`amount` AS `amount`,
|
||||
`c`.`created` AS `odbc_date`
|
||||
FROM
|
||||
`vn`.`clientCredit` `c`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`credit`
|
||||
AS SELECT `c`.`id` AS `id`,
|
||||
`c`.`clientFk` AS `Id_Cliente`,
|
||||
`c`.`workerFk` AS `Id_Trabajador`,
|
||||
`c`.`amount` AS `amount`,
|
||||
`c`.`created` AS `odbc_date`
|
||||
FROM `vn`.`clientCredit` `c`
|
|
@ -1,8 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`versiones`
|
||||
AS SELECT `m`.`app` AS `programa`,
|
||||
`m`.`version` AS `version`,
|
||||
0 AS `critical`
|
||||
FROM `vn`.`mdbVersion` `m`
|
||||
WHERE `m`.`branchFk` = 'master'
|
|
@ -1,6 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`credit`AS
|
||||
SELECT 1;
|
||||
|
||||
GRANT SELECT ON TABLE vn2008.credit TO financialBoss;
|
|
@ -28,6 +28,7 @@ module.exports = Self => {
|
|||
Self.setRating = async function(ctx, id, rating, recommendedCredit, options) {
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
|
@ -41,7 +42,6 @@ module.exports = Self => {
|
|||
const clientUpdated = await client.updateAttributes({
|
||||
rating: rating,
|
||||
recommendedCredit: recommendedCredit
|
||||
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
|
|
@ -40,26 +40,4 @@ describe('Client setRating()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should change rating and recommendedCredit to 0', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const clientId = 1101;
|
||||
const newRating = 0;
|
||||
const newRecommendedCredit = 0;
|
||||
|
||||
const updatedClient = await models.Client.setRating(ctx, clientId, newRating, newRecommendedCredit, options);
|
||||
|
||||
expect(updatedClient.rating).toEqual(newRating);
|
||||
expect(updatedClient.recommendedCredit).toEqual(newRecommendedCredit);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -319,8 +319,7 @@ module.exports = Self => {
|
|||
await Self.changeCredit(ctx, finalState, changes);
|
||||
|
||||
// Credit management changes
|
||||
|
||||
if (changes?.rating >= 0 || changes?.recommendedCredit >= 0)
|
||||
if (changes?.rating || changes?.recommendedCredit)
|
||||
await Self.changeCreditManagement(ctx, finalState, changes);
|
||||
|
||||
const oldInstance = {};
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('sale usesMana()', () => {
|
||||
const ctx = {req: { accessToken: {userId: 18}}};
|
||||
const ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 18}
|
||||
}
|
||||
};
|
||||
|
||||
it('should return that the worker uses mana', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
@ -41,27 +45,4 @@ describe('sale usesMana()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return that the worker does not use mana because it is excluded', async() => {
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
const buyerId = 35;
|
||||
const franceDepartmentId = 133;
|
||||
const buyerCtx = {req: {accessToken: {userId: buyerId}}};
|
||||
|
||||
try {
|
||||
const options = {transaction: tx}
|
||||
|
||||
await models.WorkerManaExcluded.create({workerFk: buyerId}, options);
|
||||
await models.Business.updateAll({workerFk: buyerId}, {departmentFk: franceDepartmentId}, options);
|
||||
|
||||
const usesMana = await models.Sale.usesMana(buyerCtx, options);
|
||||
|
||||
expect(usesMana).toBe(false);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,9 +21,6 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const isManaExcluded = await models.WorkerManaExcluded.findById(userId, null, myOptions);
|
||||
if (isManaExcluded) return false;
|
||||
|
||||
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
|
||||
const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions);
|
||||
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
|
||||
|
|
|
@ -33,8 +33,8 @@ module.exports = Self => {
|
|||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
let dms;
|
||||
let gestDocCreated = false;
|
||||
let ticket;
|
||||
let externalTickets = [];
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -44,6 +44,11 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const dmsTypeTicket = await models.DmsType.findOne({
|
||||
where: {code: 'ticket'},
|
||||
fields: ['id']
|
||||
}, myOptions);
|
||||
|
||||
async function setLocation(ticketId) {
|
||||
await models.Delivery.create({
|
||||
ticketFk: ticketId,
|
||||
|
@ -53,102 +58,106 @@ module.exports = Self => {
|
|||
}, myOptions);
|
||||
}
|
||||
|
||||
async function gestDocExists(ticketId) {
|
||||
async function hasSignDms(ticketId) {
|
||||
const ticketDms = await models.TicketDms.findOne({
|
||||
where: {ticketFk: ticketId},
|
||||
fields: ['dmsFk']
|
||||
include: [
|
||||
{
|
||||
relation: 'dms',
|
||||
fields: ['id'],
|
||||
scope: {
|
||||
where: {dmsTypeFk: dmsTypeTicket.id}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, myOptions);
|
||||
|
||||
if (!ticketDms) return false;
|
||||
|
||||
const ticket = await models.Ticket.findById(ticketId, {fields: ['isSigned']}, myOptions);
|
||||
if (ticket.isSigned == true)
|
||||
return true;
|
||||
else
|
||||
await models.Dms.destroyAll({where: {reference: ticketId}}, myOptions);
|
||||
|
||||
return false;
|
||||
if (ticketDms?.dms()?.id) return true;
|
||||
}
|
||||
|
||||
async function createGestDoc(id) {
|
||||
const ticket = await models.Ticket.findById(id,
|
||||
{
|
||||
include: [
|
||||
{
|
||||
relation: 'warehouse',
|
||||
scope: {
|
||||
fields: ['id']
|
||||
}
|
||||
}, {
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['name']
|
||||
}
|
||||
}, {
|
||||
relation: 'route',
|
||||
scope: {
|
||||
fields: ['id']
|
||||
}
|
||||
}
|
||||
]
|
||||
}, myOptions);
|
||||
const dmsType = await models.DmsType.findOne({where: {code: 'Ticket'}, fields: ['id']}, myOptions);
|
||||
async function createGestDoc() {
|
||||
const ctxUploadFile = Object.assign({}, ctx);
|
||||
if (ticket.route() === null)
|
||||
throw new UserError('Ticket without route');
|
||||
ctxUploadFile.args = {
|
||||
warehouseId: ticket.warehouseFk,
|
||||
companyId: ticket.companyFk,
|
||||
dmsTypeId: dmsType.id,
|
||||
reference: '',
|
||||
dmsTypeId: dmsTypeTicket.id,
|
||||
reference: ticket.id,
|
||||
description: `Firma del cliente - Ruta ${ticket.route().id}`,
|
||||
hasFile: false
|
||||
contentType: 'image/png',
|
||||
hasFile: true
|
||||
};
|
||||
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
gestDocCreated = true;
|
||||
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions);
|
||||
}
|
||||
|
||||
try {
|
||||
for (const ticketId of tickets) {
|
||||
const ticketState = await models.TicketState.findOne(
|
||||
{where: {ticketFk: ticketId},
|
||||
fields: ['alertLevel']
|
||||
}, myOptions);
|
||||
ticket = await models.Ticket.findById(ticketId, {
|
||||
include: [{
|
||||
relation: 'address',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'province',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'country',
|
||||
scope: {
|
||||
fields: ['code']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
relation: 'route',
|
||||
scope: {
|
||||
fields: ['id']
|
||||
}
|
||||
}]
|
||||
}, myOptions);
|
||||
|
||||
const packedAlertLevel = await models.AlertLevel.findOne({where: {code: 'PACKED'},
|
||||
const ticketState = await models.TicketState.findOne({
|
||||
where: {ticketFk: ticketId},
|
||||
fields: ['alertLevel']
|
||||
}, myOptions);
|
||||
|
||||
const packedAlertLevel = await models.AlertLevel.findOne({
|
||||
where: {code: 'PACKED'},
|
||||
fields: ['id']
|
||||
}, myOptions);
|
||||
|
||||
if (!ticketState)
|
||||
throw new UserError('Ticket does not exist');
|
||||
if (!ticket.route())
|
||||
throw new UserError('Ticket without route');
|
||||
if (ticketState.alertLevel < packedAlertLevel.id)
|
||||
throw new UserError('This ticket cannot be signed because it has not been boxed');
|
||||
if (await gestDocExists(ticketId))
|
||||
if (await ticket.isSigned)
|
||||
throw new UserError('Ticket is already signed');
|
||||
|
||||
if (location) await setLocation(ticketId);
|
||||
if (!gestDocCreated) await createGestDoc(ticketId);
|
||||
await models.TicketDms.create({ticketFk: ticketId, dmsFk: dms[0].id}, myOptions);
|
||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||
if (!await hasSignDms(ticketId))
|
||||
await createGestDoc(ticketId);
|
||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||
|
||||
const deliveryState = await models.State.findOne({
|
||||
where: {
|
||||
code: 'DELIVERED'
|
||||
}
|
||||
where: {code: 'DELIVERED'}
|
||||
}, myOptions);
|
||||
|
||||
await models.Ticket.state(ctx, {
|
||||
ticketFk: ticketId,
|
||||
stateFk: deliveryState.id
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
if (ticket?.address()?.province()?.country()?.code != 'ES') {
|
||||
await models.Ticket.saveCmr(ctx, [ticketId], myOptions);
|
||||
externalTickets.push(ticketId);
|
||||
}
|
||||
}
|
||||
if (tx) await tx.commit();
|
||||
return;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
await models.Route.cmrEmail(ctx, externalTickets);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -137,8 +137,7 @@ module.exports = Self => {
|
|||
tb.type,
|
||||
tb.businessFk,
|
||||
tb.permissionRate,
|
||||
d.isTeleworking,
|
||||
d.hasToRefill
|
||||
d.isTeleworking
|
||||
FROM tmp.timeBusinessCalculate tb
|
||||
JOIN account.user u ON u.id = tb.userFk
|
||||
JOIN department d ON d.id = tb.departmentFk
|
||||
|
@ -175,7 +174,7 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
try {
|
||||
workerFk = day.workerFk;
|
||||
if (day.hasToRefill && day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
|
||||
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
|
||||
&& (day.permissionRate == null ? true : day.permissionRate)) {
|
||||
if (day.timeTable == null) {
|
||||
const timed = new Date(day.dated);
|
||||
|
|
|
@ -86,9 +86,6 @@
|
|||
"WorkerMana": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"WorkerManaExcluded": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"WorkerMistake": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "WorkerManaExcluded",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "workerManaExcluded"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"workerFk": {
|
||||
"id": true,
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
"worker": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "workerFk"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@
|
|||
"@babel/plugin-syntax-dynamic-import": "^7.7.4",
|
||||
"@babel/preset-env": "^7.11.0",
|
||||
"@babel/register": "^7.7.7",
|
||||
"@verdnatura/myt": "^1.6.8",
|
||||
"@verdnatura/myt": "^1.6.7",
|
||||
"angular-mocks": "^1.7.9",
|
||||
"babel-jest": "^26.0.1",
|
||||
"babel-loader": "^8.2.4",
|
||||
|
|
|
@ -131,8 +131,8 @@ devDependencies:
|
|||
specifier: ^7.7.7
|
||||
version: 7.23.7(@babel/core@7.23.9)
|
||||
'@verdnatura/myt':
|
||||
specifier: ^1.6.8
|
||||
version: 1.6.8
|
||||
specifier: ^1.6.7
|
||||
version: 1.6.7
|
||||
angular-mocks:
|
||||
specifier: ^1.7.9
|
||||
version: 1.8.3
|
||||
|
@ -2633,8 +2633,8 @@ packages:
|
|||
dev: false
|
||||
optional: true
|
||||
|
||||
/@verdnatura/myt@1.6.8:
|
||||
resolution: {integrity: sha512-jpadr6yAR9TQXPv+has5yOYAolR/YEzsxbLgMR7BoDrpLyVFLHJEy4Dfe+Hy11r3AmxCB/8lWM+La1YGvXMWOA==}
|
||||
/@verdnatura/myt@1.6.7:
|
||||
resolution: {integrity: sha512-t/Q1T3QzHpZFdxwIyQL/CV5g+HJvWE6Q65VeA9k0svZdX/vezgnQ21nkI+wuvIurIl6BXqq2Arx7EWYkAhGNNA==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@sqltools/formatter': 1.2.5
|
||||
|
|
Loading…
Reference in New Issue