#6321 - Negative tickets #1945
|
@ -996,7 +996,8 @@ VALUES
|
|||
(14, 5, 1, 2, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 1, NULL, NULL, 0, NULL, 0),
|
||||
(15, 4, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL, 0),
|
||||
(16, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'EMB', 0, NULL, NULL, 0, NULL, 0),
|
||||
(71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0);
|
||||
(71, 6, NULL, 1, NULL, NULL, 06021010, 4751000000, NULL, 0, '', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0),
|
||||
(88, 1, NULL, 1, 'Lack negative origin', 1, 06021010, 4751000000, NULL, 0, '1', NULL, 0, 'VT', 0, NULL, NULL, 0, NULL, 0);
|
||||
|
||||
|
||||
-- Update the taxClass after insert of the items
|
||||
|
@ -4056,9 +4057,9 @@ INSERT IGNORE INTO vn.osrmConfig (id,url,tolerance)
|
|||
INSERT IGNORE INTO vn.inventoryConfig
|
||||
SET id = 1,
|
||||
supplierFk = 4;
|
||||
INSERT INTO `vn`.`item` (id,name,`size`,stems,minPrice,isToPrint,family,box,originFk,doPhoto,image,inkFk,intrastatFk,hasMinPrice,created,typeFk,generic,density,relevancy,expenseFk,isActive,longName,subName,tag5,value5,tag6,value6,tag7,value7,minimum,upToDown,hasKgPrice,isFloramondo,isFragile,stemMultiplier,isLaid,lastUsed,editorFk,isBoxPickingMode)
|
||||
VALUES
|
||||
(88,'Lack negative',200,1,10.0,0,'VT',0,2,0,'','WHT',6021010,1,'2024-07-19 11:27:32.000',1,0,167,0,'4751000000',1,'Lack negative origin','Stark Industries','Color','White','Categoria','supply','Tallos','1',3,0,0,0,0,1.0,0,'2024-07-19 11:27:32.000',100,0);
|
||||
-- INSERT INTO `vn`.`item` (id,name,`size`,stems,minPrice,isToPrint,family,box,originFk,doPhoto,image,inkFk,intrastatFk,hasMinPrice,created,typeFk,generic,density,relevancy,expenseFk,isActive,longName,subName,tag5,value5,tag6,value6,tag7,value7,minimum,upToDown,hasKgPrice,isFloramondo,isFragile,stemMultiplier,isLaid,lastUsed,editorFk,isBoxPickingMode)
|
||||
-- VALUES
|
||||
-- (88,'Lack negative',200,1,10.0,0,'VT',0,2,0,'','WHT',6021010,1,'2024-07-19 11:27:32.000',1,0,167,0,'4751000000',1,'Lack negative origin','Stark Industries','Color','White','Categoria','supply','Tallos','1',3,0,0,0,0,1.0,0,'2024-07-19 11:27:32.000',100,0);
|
||||
|
||||
INSERT INTO `vn`.`ticket` (id, clientFk,warehouseFk,shipped,nickname,refFk,addressFk,workerFk,observations,isSigned,isLabeled,isPrinted,packages,location,`hour`,created,isBlocked,solution,routeFk,priority,hasPriority,companyFk,agencyModeFk,landed,isBoxed,isDeleted,zoneFk,zonePrice,zoneBonus,totalWithVat,totalWithoutVat,weight,clonedFrom,cmrFk,editorFk,problem,risk) VALUES
|
||||
(1000000, 1,1,'2001-01-01 00:00:00.000','employee',NULL,131,NULL,NULL,0,0,0,0,NULL,0,'2024-07-19 23:32:48.000',1,NULL,NULL,NULL,1,442,1,'2001-01-01',0,0,1,1.00,0.00,0.00,NULL,NULL,NULL,NULL,9,'',NULL);
|
||||
|
|
|
@ -32,7 +32,11 @@ module.exports = Self => {
|
|||
Self.replaceItem = async(ctx, saleFk, substitutionFk, quantity, options) => {
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
const {_saleFk, _substitutionFk, _quantity} = ctx.args;
|
||||
const $t = ctx.req.__;
|
||||
|
||||
const models = Self.app.models;
|
||||
|
||||
// const {_saleFk, _substitutionFk, _quantity} = ctx.args;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
@ -43,7 +47,20 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const result = await Self.rawSql('CALL sale_replaceItem(?,?,?)', [saleFk, substitutionFk, quantity], myOptions);
|
||||
const _replaceItem = {sql: 'CALL sale_replaceItem(?,?,?)', query: [saleFk, substitutionFk, quantity]};
|
||||
const result = await Self.rawSql(_replaceItem.sql, _replaceItem.query, myOptions);
|
||||
const _salesPerson = {sql: 'SELECT vn.client_getSalesPersonByTicket(?)', query: [saleFk.ticket.id]};
|
||||
const salesPerson = await Self.rawSql(_salesPerson.query, _salesPerson.sql, myOptions);
|
||||
const message = $t('negativeReplaced', {
|
||||
old: itemFk,
|
||||
oldUrl: `${url}item/${itemFk}/summary`,
|
||||
new: itemFk,
|
||||
newUrl: `${url}item/${itemFk}/summary`,
|
||||
ticket: ticketFk,
|
||||
ticketUrl: `${url}ticket/${ticketFk}/sale`,
|
||||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -10,6 +10,11 @@ module.exports = Self => {
|
|||
type: 'number',
|
||||
description: 'The item id',
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number',
|
||||
description: 'The warehouse id',
|
||||
},
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'object',
|
||||
|
@ -30,7 +35,7 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.itemLackDetail = async(itemFk, filter, options) => {
|
||||
Self.itemLackDetail = async(itemFk, warehouseFk, filter, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
|
||||
|
||||
const myOptions = {};
|
||||
|
@ -39,56 +44,106 @@ module.exports = Self => {
|
|||
const stmt = new ParameterizedSQL(
|
||||
`
|
||||
SELECT
|
||||
s.id saleFk,
|
||||
s.id,
|
||||
st.code,
|
||||
t.id ticketFk,
|
||||
t.id,
|
||||
t.nickname,
|
||||
t.shipped,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
yo estoy cambiando los alertLevel, no podemos poner numero en el codigo, si no hay ..null yo estoy cambiando los alertLevel, no podemos poner numero en el codigo, si no hay ..null
jsegarra
commented
ok, lo reviso ok, lo reviso
jsegarra
commented
Lo he valorado con otros compañeros y esto de momento lo dejamos así Lo he valorado con otros compañeros y esto de momento lo dejamos así
|
||||
t.hour,
|
||||
s.quantity,
|
||||
ag.name agName,
|
||||
ts.alertLevel alertLevel,
|
||||
st.name stateName,
|
||||
st.id stateId,
|
||||
s.itemFk itemFk,
|
||||
s.price price,
|
||||
al.code alertLevelCode,
|
||||
z.id zoneFk,
|
||||
z.name zoneName,
|
||||
z.hour theoreticalhour,
|
||||
ag.name,
|
||||
IF(ISNULL(tls.alertLevel),0,tls.alertLevel) alertLevel,
|
||||
IF(ISNULL(st.name),'Libre',st.name) stateName,
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
es una chorrada pero comovas a cambiar cosas, no solemos poner los AS en los select es una chorrada pero comovas a cambiar cosas, no solemos poner los AS en los select
|
||||
s.id stateId,
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
tls.alertLevel tls.alertLevel
|
||||
s.itemFk,
|
||||
al.code AS alertLevelCode,
|
||||
z.name,
|
||||
Format(z.hour, "hh:mm") theoreticalhour,
|
||||
cn.isRookie,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
aqui puedes devolver el codigo y en front gestionas como necesites, sino estas haciendo 2 funciones por cada linea..lo cual tiene un coste en velocidad al select aqui puedes devolver el codigo y en front gestionas como necesites, sino estas haciendo 2 funciones por cada linea..lo cual tiene un coste en velocidad al select
jsegarra
commented
cual select? al de zona? El siguiente es de hora y a continuación son booleanos cual select? al de zona? El siguiente es de hora y a continuación son booleanos
jsegarra
commented
cambiado cambiado
|
||||
IF(sc.saleClonedFk, 1, 0 ) as turno,
|
||||
IF(tr.saleFk , 1, 0 ) as peticionCompra,
|
||||
t.hour minTimed,
|
||||
c.id customerId,
|
||||
c.name customerName,
|
||||
ot.code observationTypeCode
|
||||
FROM
|
||||
vn.sale s
|
||||
JOIN vn.ticket t ON t.id=s.ticketFk
|
||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
||||
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
JOIN vn.client c ON c.id=t.clientFk
|
||||
IF(ISNULL(sc.saleClonedFk),0,1) turno,
|
||||
IF(ISNULL(tr.saleFk),0,1) peticionCompra,
|
||||
DATE_FORMAT(IF(HOUR(t.shipped), t.shipped, IF(zc.hour, zc.hour, z.hour)),'%H:%i') minTimed,
|
||||
FALSE AS isBasket,
|
||||
substitution.hasSubstitution,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
esto lo confirmamos con ellos, yo intentaria llevarlo a front sin este campo hasToIgnore y que se lo filtren, de lo contrario..mañana cuando cambien codigos esto habra que cambiarlo esto lo confirmamos con ellos, yo intentaria llevarlo a front sin este campo hasToIgnore y que se lo filtren, de lo contrario..mañana cuando cambien codigos esto habra que cambiarlo
jsegarra
commented
La consulta que estas viendo está copiada y traducida desde access La consulta que estas viendo está copiada y traducida desde access
Solo la he migrado.
Este campo sirve para ordenar los resultados
jsegarra
commented
cambiado cambiado
|
||||
IF(d.code = 'spainTeamVip', 1, 0) hasToIgnore
|
||||
FROM sale s
|
||||
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||
INNER JOIN ticket t ON t.id =s.ticketFk
|
||||
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
(d.code = 'spainTeamVip') hasToIgnore (d.code = 'spainTeamVip') hasToIgnore
|
||||
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
jgallego marked this conversation as resolved
jgallego
commented
esto hace que las consultas sean muy lentas, hay que buscar alternativa, busca si encuentras otra consulta similar por la BBDD esto hace que las consultas sean muy lentas, hay que buscar alternativa, busca si encuentras otra consulta similar por la BBDD
jsegarra
commented
cambiado cambiado
|
||||
AND zc.dated = DATE(t.shipped)
|
||||
INNER JOIN client c ON c.id=t.clientFk
|
||||
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
|
||||
JOIN vn.agencyMode agm ON agm.id=t.agencyModeFk
|
||||
JOIN vn.agency ag ON ag.id=agm.id
|
||||
JOIN vn.ticketState ts ON ts.ticketFk=t.id
|
||||
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
|
||||
LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id
|
||||
LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
|
||||
WHERE
|
||||
s.itemFk = ?
|
||||
AND t.landed >= util.VN_CURDATE()
|
||||
AND t.landed < util.VN_CURDATE() + INTERVAL ? + 1 DAY
|
||||
`,
|
||||
[itemFk, 2]);
|
||||
INNER JOIN agencyMode ag ON ag.id=t.agencyModeFk
|
||||
INNER JOIN ticketState tls ON tls.ticketFk=t.id
|
||||
LEFT JOIN state st ON st.id=tls.state
|
||||
LEFT JOIN alertLevel al ON al.id = st.alertLevel
|
||||
LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id
|
||||
LEFT JOIN ticketRequest tr ON tr.saleFk = s.id
|
||||
LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||
LEFT JOIN department d ON d.id = wd.departmentFk
|
||||
LEFT JOIN (
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
esto seria hasObservation esto seria hasObservation
jsegarra
commented
Okey, reemplazaré Okey, reemplazaré
jsegarra
commented
cambiado cambiado
|
||||
SELECT co.clientFk, IF(COUNT(*) > 0, FALSE, TRUE) AS hasSubstitution
|
||||
FROM clientObservation co
|
||||
INNER JOIN observationType ot ON ot.id = co.observationTypeFk
|
||||
WHERE ot.code = 'substitution'
|
||||
GROUP BY co.clientFk
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
aqui falta el alias de la tabla, probablemente t.warehouse aqui falta el alias de la tabla, probablemente t.warehouse
jgallego
commented
, COUNT(*) hasObservation Hemos invertido este booleano, ahora hay que mostrar el icono si aqui hay valor , COUNT(*) hasObservation
Hemos invertido este booleano, ahora hay que mostrar el icono si aqui hay valor
|
||||
) AS substitution ON substitution.clientFk = c.id
|
||||
WHERE warehouseFk = ?
|
||||
AND s.itemFk = ?
|
||||
AND s.quantity <> 0
|
||||
AND t.shipped >= CURDATE()
|
||||
AND t.shipped < DATE_ADD(CURDATE(), INTERVAL ? DAY)
|
||||
jgallego marked this conversation as resolved
Outdated
jsegarra
commented
Valores como estos lo dejamos así o lo movemos a variables/consultas? Valores como estos lo dejamos así o lo movemos a variables/consultas?
jgallego
commented
si es alertLevel hay que usar el codigo, no el numero, en este caso 'ON_PREPARATION' o 'DELIVERED' si es alertLevel hay que usar el codigo, no el numero, en este caso 'ON_PREPARATION' o 'DELIVERED'
jsegarra
commented
Okey, hago la modificación aqui y en el front para que se pueda enviar array desde el VnSelect Okey, hago la modificación aqui y en el front para que se pueda enviar array desde el VnSelect
jsegarra
commented
Resuelto Resuelto
jsegarra
commented
Y he creado un registro en TicketConfig con valor default a FREE (por si cambian de criterio a futuro) Y he creado un registro en TicketConfig con valor default a FREE (por si cambian de criterio a futuro)
|
||||
AND sgd.saleFk IS NULL
|
||||
AND (al.code IN ('FREE', 'ON_PREVIOUS') OR al.code IS NULL)
|
||||
jgallego
commented
AND s.quantity AND s.quantity
para proximas
|
||||
UNION ALL
|
||||
SELECT r.id,
|
||||
NULL,
|
||||
r.orderFk,
|
||||
c.name,
|
||||
r.shipment,
|
||||
r.amount,
|
||||
ag.name,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
r.itemFk,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
cn.isRookie,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
TRUE,
|
||||
substitution.hasSubstitution,
|
||||
IF(d.code = 'spainTeamVip', 1, 0)
|
||||
FROM hedera.orderRow r
|
||||
INNER JOIN hedera.order o ON o.id = r.orderFk
|
||||
INNER JOIN client c ON c.id = o.customer_id
|
||||
INNER JOIN agencyMode ag ON ag.id=o.agency_id
|
||||
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
|
||||
LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||
LEFT JOIN department d ON d.id = wd.departmentFk
|
||||
LEFT JOIN (
|
||||
SELECT co.clientFk, IF(COUNT(*) > 0, FALSE, TRUE) hasSubstitution
|
||||
FROM clientObservation co
|
||||
INNER JOIN observationType ot ON ot.id = co.observationTypeFk
|
||||
WHERE ot.code = 'substitution'
|
||||
GROUP BY co.clientFk
|
||||
) AS substitution ON substitution.clientFk = c.id
|
||||
WHERE r.shipment >= CURDATE()
|
||||
AND r.shipment < DATE_ADD(CURDATE(), INTERVAL ? DAY)
|
||||
AND r.warehouseFk = ?
|
||||
AND r.created >= STR_TO_DATE(CURDATE(), '%Y-%m-%d %H:%i:%s')
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
cambiar este tb cambiar este tb
|
||||
AND NOT o.confirmed
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
igual que arriba, comparar esto es lentitud en el select, ahi puedes poner (util) curdate o now lo que tenga que ser igual que arriba, comparar esto es lentitud en el select, ahi puedes poner (util) curdate o now lo que tenga que ser
jsegarra
commented
cambiado cambiado
|
||||
AND r.itemFk = ?
|
||||
AND r.amount <> 0
|
||||
ORDER BY hasToIgnore, isBasket;`,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
asumiendo que el amount es unsigned, deja AND r.amount asumiendo que el amount es unsigned, deja AND r.amount
jsegarra
commented
cambiado cambiado
|
||||
[itemFk, warehouseFk, 2, 2, warehouseFk, itemFk]);
|
||||
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
aqui lo dicho, sin numero los ids de los estados van a cambiar en breve aqui lo dicho, sin numero los ids de los estados van a cambiar en breve
jsegarra
commented
Ahora se usa el código Ahora se usa el código
|
||||
// if (filter.where.alertLevel) {
|
||||
stmt.merge({
|
||||
sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
|
||||
// stmt.merge({
|
||||
jsegarra marked this conversation as resolved
Outdated
jsegarra
commented
verias mejor mover el select a un procedimiento? y nos evitamos esta condición? verias mejor mover el select a un procedimiento? y nos evitamos esta condición?
@jgallego
jgallego
commented
no, con la funcion nativa de loopback va bien no, con la funcion nativa de loopback va bien
jsegarra
commented
Ok Ok
|
||||
// sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
|
||||
// }
|
||||
// stmt.merge(conn.makeWhere(filter.where));
|
||||
const sql = ParameterizedSQL.join([stmt], ';');
|
||||
|
|
este dos?
Este 2 lo he puesto para que cuando filter.where no tenga scopeDays no de error la consulta, sin embargo, para ser lo mas agnóstico posible a quien lo llame, si no me lo pasas, asigno un 0 que es más lógico
Si lo ves correcto, te pido fusionar
mejora aun, no pases nada si no pasan nada.