#6321 - Negative tickets #1945

Open
jsegarra wants to merge 97 commits from 6321_negative_tickets into dev
3 changed files with 122 additions and 49 deletions
Showing only changes of commit 1560c48af2 - Show all commits

View File

@ -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);

View File

@ -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();

View File

@ -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,
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,
s.id stateId,
s.itemFk,
al.code AS alertLevelCode,
z.name,
Format(z.hour, "hh:mm") theoreticalhour,
cn.isRookie,
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,
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
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
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 (
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
) 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)
AND sgd.saleFk IS NULL
AND (al.code IN ('FREE', 'ON_PREVIOUS') OR al.code IS NULL)
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')
AND NOT o.confirmed
AND r.itemFk = ?
AND r.amount <> 0
ORDER BY hasToIgnore, isBasket;`,
[itemFk, warehouseFk, 2, 2, warehouseFk, itemFk]);
// if (filter.where.alertLevel) {
stmt.merge({
sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
// stmt.merge({
// sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
// }
// stmt.merge(conn.makeWhere(filter.where));
const sql = ParameterizedSQL.join([stmt], ';');