#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),
|
(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),
|
(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),
|
(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
|
-- 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
|
INSERT IGNORE INTO vn.inventoryConfig
|
||||||
SET id = 1,
|
SET id = 1,
|
||||||
supplierFk = 4;
|
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)
|
-- 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
|
-- 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);
|
-- (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
|
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);
|
(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) => {
|
Self.replaceItem = async(ctx, saleFk, substitutionFk, quantity, options) => {
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
let tx;
|
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')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -43,7 +47,20 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
|
@ -10,6 +10,11 @@ module.exports = Self => {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The item id',
|
description: 'The item id',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'warehouseFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The warehouse id',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'object',
|
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 conn = Self.dataSource.connector;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
@ -39,56 +44,106 @@ module.exports = Self => {
|
||||||
const stmt = new ParameterizedSQL(
|
const stmt = new ParameterizedSQL(
|
||||||
`
|
`
|
||||||
SELECT
|
SELECT
|
||||||
s.id saleFk,
|
s.id,
|
||||||
st.code,
|
st.code,
|
||||||
t.id ticketFk,
|
t.id,
|
||||||
t.nickname,
|
t.nickname,
|
||||||
t.shipped,
|
t.shipped,
|
||||||
t.hour,
|
|
||||||
s.quantity,
|
s.quantity,
|
||||||
ag.name agName,
|
ag.name,
|
||||||
ts.alertLevel alertLevel,
|
IF(ISNULL(tls.alertLevel),0,tls.alertLevel) alertLevel,
|
||||||
st.name stateName,
|
IF(ISNULL(st.name),'Libre',st.name) stateName,
|
||||||
st.id stateId,
|
s.id stateId,
|
||||||
s.itemFk itemFk,
|
s.itemFk,
|
||||||
s.price price,
|
al.code AS alertLevelCode,
|
||||||
al.code alertLevelCode,
|
z.name,
|
||||||
z.id zoneFk,
|
Format(z.hour, "hh:mm") theoreticalhour,
|
||||||
z.name zoneName,
|
|
||||||
z.hour theoreticalhour,
|
|
||||||
cn.isRookie,
|
cn.isRookie,
|
||||||
IF(sc.saleClonedFk, 1, 0 ) as turno,
|
IF(ISNULL(sc.saleClonedFk),0,1) turno,
|
||||||
IF(tr.saleFk , 1, 0 ) as peticionCompra,
|
IF(ISNULL(tr.saleFk),0,1) peticionCompra,
|
||||||
t.hour minTimed,
|
DATE_FORMAT(IF(HOUR(t.shipped), t.shipped, IF(zc.hour, zc.hour, z.hour)),'%H:%i') minTimed,
|
||||||
c.id customerId,
|
FALSE AS isBasket,
|
||||||
c.name customerName,
|
substitution.hasSubstitution,
|
||||||
ot.code observationTypeCode
|
IF(d.code = 'spainTeamVip', 1, 0) hasToIgnore
|
||||||
FROM
|
FROM sale s
|
||||||
vn.sale s
|
LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||||
JOIN vn.ticket t ON t.id=s.ticketFk
|
INNER JOIN ticket t ON t.id =s.ticketFk
|
||||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||||
JOIN vn.client c ON c.id=t.clientFk
|
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
|
LEFT JOIN bs.clientNewBorn cn ON cn.clientFk=c.id
|
||||||
JOIN vn.agencyMode agm ON agm.id=t.agencyModeFk
|
INNER JOIN agencyMode ag ON ag.id=t.agencyModeFk
|
||||||
JOIN vn.agency ag ON ag.id=agm.id
|
INNER JOIN ticketState tls ON tls.ticketFk=t.id
|
||||||
JOIN vn.ticketState ts ON ts.ticketFk=t.id
|
LEFT JOIN state st ON st.id=tls.state
|
||||||
LEFT JOIN vn.state st ON st.id=ts.state
|
LEFT JOIN alertLevel al ON al.id = st.alertLevel
|
||||||
LEFT JOIN vn.alertLevel al ON al.id = st.alertLevel
|
LEFT JOIN saleCloned sc ON sc.saleClonedFk = s.id
|
||||||
LEFT JOIN vn.saleCloned sc ON sc.saleClonedFk = s.id
|
LEFT JOIN ticketRequest tr ON tr.saleFk = s.id
|
||||||
LEFT JOIN vn.ticketRequest tr ON tr.saleFk = s.id
|
LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||||
LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id
|
LEFT JOIN department d ON d.id = wd.departmentFk
|
||||||
LEFT JOIN vn.observationType ot ON ot.id = tob.observationTypeFk
|
LEFT JOIN (
|
||||||
WHERE
|
SELECT co.clientFk, IF(COUNT(*) > 0, FALSE, TRUE) AS hasSubstitution
|
||||||
s.itemFk = ?
|
FROM clientObservation co
|
||||||
AND t.landed >= util.VN_CURDATE()
|
INNER JOIN observationType ot ON ot.id = co.observationTypeFk
|
||||||
AND t.landed < util.VN_CURDATE() + INTERVAL ? + 1 DAY
|
WHERE ot.code = 'substitution'
|
||||||
`,
|
GROUP BY co.clientFk
|
||||||
[itemFk, 2]);
|
) 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) {
|
// if (filter.where.alertLevel) {
|
||||||
stmt.merge({
|
// stmt.merge({
|
||||||
sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
|
// sql: `AND ${filter.where.alertLevel ? '' : 'NOT'} ts.alertLevel=?`, params: [0]});
|
||||||
// }
|
// }
|
||||||
// stmt.merge(conn.makeWhere(filter.where));
|
// stmt.merge(conn.makeWhere(filter.where));
|
||||||
const sql = ParameterizedSQL.join([stmt], ';');
|
const sql = ParameterizedSQL.join([stmt], ';');
|
||||||
|
|
Loading…
Reference in New Issue