Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
2ba91a6cc2
|
@ -77,5 +77,7 @@
|
|||
"The extension must be unique": "La extensión debe ser unica",
|
||||
"The secret can't be blank": "La contraseña no puede estar en blanco",
|
||||
"EXTENSION_INVALID_FORMAT": "La extensión es invalida",
|
||||
"We weren't able to send this SMS": "No hemos podido enviar el SMS"
|
||||
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
|
||||
"This client can't be invoiced": "Este cliente no puede ser facturado",
|
||||
"This ticket can't be invoiced": "Este ticket no puede ser facturado"
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('canBeInvoiced', {
|
||||
description: 'Change property isEqualizated in all client addresses',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/canBeInvoiced`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.canBeInvoiced = async id => {
|
||||
let $ = Self.app.models;
|
||||
|
||||
let client = await $.Client.findById(id, {fields: ['id', 'isTaxDataChecked', 'hasToInvoice']});
|
||||
if (client.isTaxDataChecked && client.hasToInvoice)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
};
|
|
@ -19,6 +19,7 @@ module.exports = Self => {
|
|||
require('../methods/client/updateFiscalData')(Self);
|
||||
require('../methods/client/getTransactions')(Self);
|
||||
require('../methods/client/confirmTransaction')(Self);
|
||||
require('../methods/client/canBeInvoiced')(Self);
|
||||
|
||||
// Validations
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('canBeInvoiced', {
|
||||
description: 'Change property isEqualizated in all client addresses',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/canBeInvoiced`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.canBeInvoiced = async id => {
|
||||
let ticket = await Self.app.models.Ticket.findById(id, {fields: ['id', 'refFk', 'shipped']});
|
||||
let ticketTotal = await Self.app.models.Ticket.getTotal(id);
|
||||
|
||||
let query = `SELECT vn.hasSomeNegativeBase(?) AS hasSomeNegativeBase`;
|
||||
let [result] = await Self.rawSql(query, [id]);
|
||||
let hasSomeNegativeBase = result.hasSomeNegativeBase;
|
||||
|
||||
let today = new Date();
|
||||
let shipped = new Date(ticket.shipped);
|
||||
|
||||
if (ticket.refFk || ticketTotal == 0 || shipped.getTime() > today.getTime() || hasSomeNegativeBase)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
};
|
|
@ -0,0 +1,73 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = function(Self) {
|
||||
Self.remoteMethodCtx('makeInvoice', {
|
||||
description: 'Change property isEqualizated in all client addresses',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
http: {source: 'path'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
arg: 'data',
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/makeInvoice`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.makeInvoice = async(ctx, id) => {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let $ = Self.app.models;
|
||||
|
||||
let options = {};
|
||||
options.transaction = await Self.beginTransaction({});
|
||||
|
||||
try {
|
||||
let ticket = await $.Ticket.findById(id, {fields: ['id', 'clientFk', 'companyFk']});
|
||||
|
||||
let clientCanBeInvoiced = await $.Client.canBeInvoiced(ticket.clientFk);
|
||||
if (!clientCanBeInvoiced)
|
||||
throw new UserError(`This client can't be invoiced`);
|
||||
|
||||
let ticketCanBeInvoiced = await $.Ticket.canBeInvoiced(ticket.id);
|
||||
if (!ticketCanBeInvoiced)
|
||||
throw new UserError(`This ticket can't be invoiced`);
|
||||
|
||||
|
||||
let query = `SELECT vn.invoiceSerial(?, ?, ?) AS serial`;
|
||||
let [result] = await Self.rawSql(query, [ticket.clientFk, ticket.companyFk, 'R'], options);
|
||||
let serial = result.serial;
|
||||
|
||||
query = `CALL vn.invoiceFromTicket(?)`;
|
||||
await Self.rawSql(query, [ticket.id], options);
|
||||
|
||||
query = `CALL vn.invoiceOutMake(?, ?, @invoiceId);
|
||||
SELECT @invoiceId AS invoiceId;`;
|
||||
result = await Self.rawSql(query, [serial, null], options);
|
||||
let invoice = result[1].invoiceId;
|
||||
|
||||
if (serial != 'R' && invoice) {
|
||||
query = `CALL vn.invoiceOutBooking(?)`;
|
||||
await Self.rawSql(query, [invoice], options);
|
||||
}
|
||||
|
||||
let user = await Self.app.models.Worker.findOne({where: {userFk: userId}});
|
||||
|
||||
query = `INSERT INTO vn2008.Colas(Id_Informe,Cola,Id_Trabajador) VALUES (?, ?, ?)`;
|
||||
await Self.rawSql(query, [3, invoice, user.id], options);
|
||||
await options.transaction.commit();
|
||||
} catch (e) {
|
||||
options.transaction.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -18,4 +18,6 @@ module.exports = Self => {
|
|||
require('../methods/ticket/getLanded')(Self);
|
||||
require('../methods/ticket/filter')(Self);
|
||||
require('../methods/ticket/getPossibleStowaways')(Self);
|
||||
require('../methods/ticket/canBeInvoiced')(Self);
|
||||
require('../methods/ticket/makeInvoice')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue