#6321 - Negative tickets #1945
|
@ -2,5 +2,6 @@ INSERT INTO salix.ACL (model,property,accessType,permission,principalType,princi
|
|||
VALUES
|
||||
('Ticket','itemLack','READ','ALLOW','ROLE','employee'),
|
||||
('Ticket','itemLackDetail','READ','ALLOW','ROLE','employee'),
|
||||
('Ticket','itemLackOrigin','READ','ALLOW','ROLE','employee'),
|
||||
('Ticket','itemLackOrigin','WRITE','ALLOW','ROLE','employee'),
|
||||
('Ticket','split','WRITE','ALLOW','ROLE','employee'),
|
||||
('Ticket','negativeOrigin','READ','ALLOW','ROLE','employee');
|
||||
|
|
|
@ -15,7 +15,7 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/itemLack`,
|
||||
path: `/itemLackOrigin`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
const {ParameterizedSQL} = require('loopback-connector/lib/sql');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('split', {
|
||||
description: 'Split a ticket or n tickets',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
|
||||
type: ['Object'],
|
||||
required: true,
|
||||
http: {source: 'body'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/split`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.split = async(ctx, tickets, options) => {
|
||||
// const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
let results = [];
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
// const conn = Self.dataSource.connector;
|
||||
jgallego
commented
si el objetivo es contar tickets te sobraria la tabla sale, si el objetivo es contar tickets te sobraria la tabla sale,
si el objetivo es contar sales te sobraria la tabla ticket
|
||||
// const stmts = [];
|
||||
try {
|
||||
const ticketsIds = tickets.map(({id}, index) => id);
|
||||
const ticketsCount = await Self.rawSql(`
|
||||
Select t.id tid, s.id sid, count(s.id) count from
|
||||
vn.ticket t
|
||||
LEFT JOIN vn.sale s
|
||||
ON s.ticketFk = t.id
|
||||
WHERE t.id IN (?) GROUP BY t.id;`,
|
||||
[ticketsIds], myOptions);
|
||||
console.log(ticketsCount);
|
||||
|
||||
// stmts.push(stmt);
|
||||
// const sql = ParameterizedSQL.join(stmts, ';');
|
||||
// const result = await conn.executeStmt(sql, myOptions);
|
||||
for (const {tid, sid, count} of ticketsCount) {
|
||||
try {
|
||||
if (count === 1) {
|
||||
results.push({ticket: tid, message: 'noSplit'});
|
||||
continue;
|
||||
jgallego
commented
en que caso devuelve un ticket = 0? en que caso devuelve un ticket = 0?
jsegarra
commented
Diría que en ningún caso. Pero esta condición estaba en access y la puse Diría que en ningún caso. Pero esta condición estaba en access y la puse
|
||||
}
|
||||
const [, [{vNewTicket}]] = await Self.rawSql(`
|
||||
CALL vn.ticket_clone(?, @vNewTicket);
|
||||
SELECT @vNewTicket vNewTicket;`,
|
||||
[tid], myOptions);
|
||||
|
||||
if (vNewTicket === 0) continue;
|
||||
await Self.rawSql(`
|
||||
UPDATE vn.sale SET isPicked = (id = ?) WHERE ticketFk = ?`,
|
||||
[sid, tid], myOptions);
|
||||
await Self.transferSales(ctx, tid, vNewTicket, sid, myOptions);
|
||||
|
||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [tid, 'FIXING'], myOptions);
|
||||
results.push({ticket: tid, message: 'split'});
|
||||
} catch (error) {
|
||||
throw new UserError('You cannot close tickets for today');
|
||||
}
|
||||
}
|
||||
return results;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -52,4 +52,5 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/itemLackDetail')(Self);
|
||||
require('../methods/ticket/itemLackOrigin')(Self);
|
||||
require('../methods/ticket/negativeOrigin')(Self);
|
||||
require('../methods/ticket/split')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
quitar comentarios
Resuelto