#6321 - Negative tickets #1945

Open
jsegarra wants to merge 93 commits from 6321_negative_tickets into dev
9 changed files with 6 additions and 202 deletions
Showing only changes of commit d08535ac18 - Show all commits

View File

@ -18,7 +18,7 @@ const opts = getopts(process.argv.slice(2), {
let server;
const PARALLEL = false;
const SETUP_TIMEOUT = 15 * 60 * 1000;
const SPEC_TIMEOUT = 30 * 11000;
const SPEC_TIMEOUT = 30 * 1000;
process.on('exit', teardown);
process.on('uncaughtException', onError);

View File

@ -1,9 +0,0 @@
-- Auto-generated SQL script #202401191358
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Ticket','itemLack','READ','ALLOW','ROLE','employee');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Ticket','itemLackDetail','READ','ALLOW','ROLE','employee');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Ticket','itemLackOrigin','WRITE','ALLOW','ROLE','employee');

View File

@ -1,68 +0,0 @@
DROP PROCEDURE IF EXISTS vn.item_getLack;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getLack`(
IN vForce BOOLEAN DEFAULT TRUE,
IN vDays INT DEFAULT 2,
IN vCustomWhere TEXT,
)
BEGIN
/**
* Calcula una tabla con el máximo negativo visible para cada producto y almacen
*
* @param vForce Fuerza el recalculo del stock
* @param vDays Numero de dias a considerar
* @param vSearch Filtro items
**/
CALL `cache`.stock_refresh(vForce);
CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL);
CALL item_getMinETD();
CALL item_zoneClosure();
SET @sqlQuery = CONCAT(`SELECT i.id itemFk,
i.longName,
w.id warehouseFk,
p.`name` producer,
i.`size`,
i.category,
w.name warehouse,
SUM(IFNULL(sub.amount,0)) lack,
i.inkFk,
IFNULL(im.timed, util.midnight()) timed,
IFNULL(izc.timed, util.midnight()) minTimed
FROM (SELECT item_id,
warehouse_id,
amount
FROM cache.stock
WHERE amount > 0
UNION ALL
SELECT itemFk,
warehouseFk,
amount
FROM tmp.itemMinacum
) sub
JOIN warehouse w ON w.id = sub.warehouse_id
JOIN item i ON i.id = sub.item_id
LEFT JOIN producer p ON p.id = i.producerFk
JOIN itemType it ON it.id = i.typeFk
JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id
LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id
WHERE w.isForTicket
AND ic.display
AND it.code != 'GEN'
AND `,vCustomWhere,`
GROUP BY i.id, w.id
HAVING lack < 0;`);
CALL `exec`(@sqlQuery);
DROP TEMPORARY TABLE tmp.itemMinacum;
DROP TEMPORARY TABLE tmp.itemMinETD;
DROP TEMPORARY TABLE tmp.itemZoneClosure;
END
$$
DELIMITER ;

View File

@ -1,80 +0,0 @@
DROP PROCEDURE IF EXISTS vn.item_getLack;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getLack`(
IN vForce BOOLEAN DEFAULT TRUE,
IN vDays INT DEFAULT 2,
IN vId INT DEFAULT NULL,
IN vLongname INT DEFAULT NULL,
IN vSupplier VARCHAR DEFAULT NULL,
IN vColor VARCHAR DEFAULT NULL,
IN vSize INT DEFAULT NULL,
IN vOrigen VARCHAR DEFAULT NULL,
IN vLack INT DEFAULT NULL
)
BEGIN
/**
* Calcula una tabla con el máximo negativo visible para cada producto y almacen
*
* @param vForce Fuerza el recalculo del stock
* @param vDays Numero de dias a considerar
* @param vSearch Filtro items
**/
CALL `cache`.stock_refresh(vForce);
CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL);
CALL item_getMinETD();
CALL item_zoneClosure();
SELECT i.id itemFk,
i.longName,
w.id warehouseFk,
p.`name` producer,
i.`size`,
i.category,
w.name warehouse,
SUM(IFNULL(sub.amount,0)) lack,
i.inkFk,
IFNULL(im.timed, util.midnight()) timed,
IFNULL(izc.timed, util.midnight()) minTimed
FROM (SELECT item_id,
warehouse_id,
amount
FROM cache.stock
WHERE amount > 0
UNION ALL
SELECT itemFk,
warehouseFk,
amount
FROM tmp.itemMinacum
) sub
JOIN warehouse w ON w.id = sub.warehouse_id
JOIN item i ON i.id = sub.item_id
LEFT JOIN producer p ON p.id = i.producerFk
JOIN itemType it ON it.id = i.typeFk
JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id
LEFT JOIN tmp.itemZoneClosure izc ON izc.itemFk = i.id
WHERE w.isForTicket
AND ic.display
AND it.code != 'GEN'
AND (vId IS NULL OR i.id = vId)
AND (vLongname IS NULL OR i.longName = vLongname)
AND (vSupplier IS NULL OR p.`name` LIKE CONCAT('%', vSupplier, '%'))
AND (vColor IS NULL OR vColor = i.inkFk)
AND (vSize IS NULL OR vSize = i.`size`)
AND (vOrigen IS NULL OR vOrigen = w.name)
AND (vLack IS NULL OR vLack = lack)
GROUP BY i.id, w.id
HAVING lack < 0;
DROP TEMPORARY TABLE tmp.itemMinacum;
DROP TEMPORARY TABLE tmp.itemMinETD;
DROP TEMPORARY TABLE tmp.itemZoneClosure;
END
$$
DELIMITER ;

View File

@ -1,38 +0,0 @@
SELECT
s.id saleFk,
st.code,
t.id ticketFk,
t.nickname,
t.hour,
s.quantity,
ag.name,
ts.alertLevel alertLevel,
st.name stateName,
st.id stateId,
s.itemFk itemFk,
al.code alertLevelCode,
z.name,
z.hour theoreticalhour,
cn.isRookie,
sc.saleClonedFk turno,
tr.saleFk peticionCompra,
t.hour minTimed
FROM
vn.sale s
JOIN vn.ticket t ON t.id=s.ticketFk -- vn.ticket
LEFT JOIN vn.zone z ON z.id = t.zoneFk -- vn.zone
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk -- AND zc.dated = DateValue(t.Fecha)
JOIN vn.client c ON c.id=t.clientFk -- vn.client
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
JOIN vn.agencyMode agm ON agm.id=t.agencyModeFk -- vn.agencyMode
JOIN vn.agency ag ON ag.id=agm.id -- vn.agencyMode
JOIN vn.ticketState ts ON ts.ticketFk=t.id -- vn.sale
LEFT JOIN vn.state st ON st.id=ts.state
LEFT JOIN vn.alertLevel al ON al.id = st.alertLevel
LEFT JOIN vn.saleCloned sc ON sc.saleClonedFk = s.id
LEFT JOIN vn.ticketRequest tr ON tr.saleFk = s.id
WHERE
s.itemFk = ?
AND t.landed >= util.VN_CURDATE()
AND t.landed < INTERVAL util.VN_CURDATE() + INTERVAL ? + 1 DAY
`,

View File

@ -1,5 +1,5 @@
/* eslint-disable no-console */
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const {ParameterizedSQL} = require('loopback-connector');
module.exports = Self => {
Self.remoteMethod('itemLackDetail', {
description: 'Download a ticket delivery note document',
jsegarra marked this conversation as resolved Outdated

esta descripcion corresponde ?

esta descripcion corresponde ?

View File

@ -1,5 +1,5 @@
const {ParameterizedSQL} = require('loopback-connector');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('itemLackOrigin', {
description: 'Insert ticket negative into negativeOrigin',

View File

@ -1,5 +1,5 @@
const {ParameterizedSQL} = require('loopback-connector');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('negativeOrigin', {
description: 'Insert ticket negative into negativeOrigin',

View File

@ -32,8 +32,7 @@ module.exports = Self => {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
// const conn = Self.dataSource.connector;
// const stmts = [];
jsegarra marked this conversation as resolved Outdated

quitar comentarios

quitar comentarios

Resuelto

Resuelto
try {
const ticketsIds = tickets.map(({ticketFk}, index) => ticketFk);
const ticketsCount = await Self.rawSql(`
Review

si el objetivo es contar tickets te sobraria la tabla sale,
si el objetivo es contar sales te sobraria la tabla ticket

si el objetivo es contar tickets te sobraria la tabla sale, si el objetivo es contar sales te sobraria la tabla ticket