test ok
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2021-01-21 13:39:40 +01:00
parent 4cdbb85e30
commit 3dc50e8a16
5 changed files with 31 additions and 47 deletions

View File

@ -1 +1 @@
12271-wisemen
10271-wisemen

View File

@ -0,0 +1,2 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES ('printServerQueue', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee');

View File

@ -1,5 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = function(Self) {
Self.remoteMethodCtx('makeInvoice', {
@ -26,7 +25,6 @@ module.exports = function(Self) {
});
Self.makeInvoice = async(ctx, id) => {
const conn = Self.dataSource.connector;
let userId = ctx.req.accessToken.userId;
let models = Self.app.models;
let tx = await Self.beginTransaction({});
@ -45,47 +43,36 @@ module.exports = function(Self) {
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;
let stmts = [];
await Self.rawSql('CALL invoiceFromTicket(?)', [id], options);
await Self.rawSql('CALL invoiceOut_new(?, CURDATE(), null, @invoiceId)', [serial], options);
let [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', options);
let [resultInvoice] = await Self.rawSql('SELECT @invoiceId id', [], options);
let invoiceId = resultInvoice.id;
if serial != 'R' && invoiceId && invoiceId > 0
{
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], options);
INSERT INTO printServerQueue(priorityFk, reportFk, param1, workerFk) VALUES(1, 3, vInvoiceId, account.myUser_getId());
let ticketInvoice = await models.Ticket.findById(id, {fields: ['refFk']}, options);
stmt = new ParameterizedSQL('CALL vn.invoiceOut_newFromTicket(?, ?, ?, @invoiceId)', [
ticket.id,
serial,
null
]);
stmts.push(stmt);
await models.TicketLog.create({
originFk: ticket.id,
userFk: userId,
action: 'insert',
changedModel: 'Ticket',
changedModelId: ticket.id,
newInstance: ticketInvoice
}, options);
let invoiceIndex = stmts.push(`SELECT @invoiceId AS invoiceId`) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
result = await conn.executeStmt(sql);
let invoiceId = result[invoiceIndex][0].invoiceId;
if (serial != 'R' && invoiceId) {
query = `CALL vn.invoiceOutBooking(?)`;
await Self.rawSql(query, [invoiceId], options);
await Self.rawSql('CALL invoiceOutBooking(?)', [invoiceId], options);
await models.PrintServerQueue.create({
reportFk: 3, // Tarea #2734 (Nueva): crear informe facturas
param1: invoiceId,
workerFk: userId
}, options);
}
let user = await models.Worker.findOne({where: {userFk: userId}}, options);
query = `INSERT INTO printServerQueue(reportFk, param1, workerFk) VALUES (?, ?, ?)`;
await Self.rawSql(query, [3, invoiceId, user.id], options);
await tx.commit();
return {invoiceFk: invoiceId, serial};

View File

@ -17,6 +17,9 @@
"Packaging": {
"dataSource": "vn"
},
"PrintServerQueue": {
"dataSource": "vn"
},
"Sale": {
"dataSource": "vn"
},

View File

@ -9,31 +9,23 @@
},
"properties": {
"id": {
"type": "number",
"type": "Number",
"id": true,
"description": "Identifier"
},
"priorityFk": {
"type": "number"
"type": "Number"
},
"reportFk": {
"type": "number",
"type": "Number",
"required": true
},
"param1": {
"type": "number"
"type": "Number"
},
"workerFk": {
"type": "number",
"type": "Number",
"required": true
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}
}