refactor: refs #4502 Deleted zoneEstimatedDelivery #1844
|
@ -168,14 +168,13 @@ module.exports = Self => {
|
||||||
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
|
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
|
||||||
stmts.push(`SET SESSION optimizer_search_depth = 0`);
|
stmts.push(`SET SESSION optimizer_search_depth = 0`);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(`
|
||||||
`CREATE TEMPORARY TABLE tmp.filter
|
CREATE TEMPORARY TABLE tmp.filter
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT
|
SELECT t.id,
|
||||||
t.id,
|
|
||||||
t.shipped,
|
t.shipped,
|
||||||
CAST(DATE(t.shipped) AS CHAR) AS shippedDate,
|
CAST(DATE(t.shipped) AS CHAR) shippedDate,
|
||||||
t.nickname,
|
t.nickname,
|
||||||
t.refFk,
|
t.refFk,
|
||||||
t.routeFk,
|
t.routeFk,
|
||||||
|
@ -183,27 +182,27 @@ module.exports = Self => {
|
||||||
t.clientFk,
|
t.clientFk,
|
||||||
t.totalWithoutVat,
|
t.totalWithoutVat,
|
||||||
t.totalWithVat,
|
t.totalWithVat,
|
||||||
io.id AS invoiceOutId,
|
io.id invoiceOutId,
|
||||||
a.provinceFk,
|
a.provinceFk,
|
||||||
p.name AS province,
|
p.name province,
|
||||||
w.name AS warehouse,
|
w.name warehouse,
|
||||||
am.name AS agencyMode,
|
am.name agencyMode,
|
||||||
am.id AS agencyModeFk,
|
am.id agencyModeFk,
|
||||||
st.name AS state,
|
st.name state,
|
||||||
wk.lastName AS salesPerson,
|
wk.lastName salesPerson,
|
||||||
ts.stateFk AS stateFk,
|
ts.stateFk stateFk,
|
||||||
ts.alertLevel AS alertLevel,
|
ts.alertLevel alertLevel,
|
||||||
ts.code AS alertLevelCode,
|
ts.code alertLevelCode,
|
||||||
u.name AS userName,
|
u.name userName,
|
||||||
c.salesPersonFk,
|
c.salesPersonFk,
|
||||||
c.credit,
|
c.credit,
|
||||||
z.hour AS zoneLanding,
|
z.hour zoneLanding,
|
||||||
z.name AS zoneName,
|
z.name zoneName,
|
||||||
z.id AS zoneFk,
|
z.id zoneFk,
|
||||||
st.classColor,
|
st.classColor,
|
||||||
TIME_FORMAT(t.shipped, '%H:%i') AS preparationHour,
|
TIME_FORMAT(t.shipped, '%H:%i') preparationHour,
|
||||||
TIME_FORMAT(z.hour, '%H:%i') AS theoreticalhour,
|
TIME_FORMAT(z.hour, '%H:%i') theoreticalhour,
|
||||||
TIME_FORMAT(zed.etc, '%H:%i') AS practicalHour
|
TIME_FORMAT(zed.etc, '%H:%i') practicalHour
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
||||||
LEFT JOIN zone z ON z.id = t.zoneFk
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
|
@ -216,7 +215,18 @@ module.exports = Self => {
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
LEFT JOIN account.user u ON u.id = wk.id
|
LEFT JOIN account.user u ON u.id = wk.id
|
||||||
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
|
LEFT JOIN (
|
||||||
|
SELECT zoneFk,
|
||||||
|
CAST(
|
||||||
|
IFNULL(zoneClosureHour, zoneHour) +
|
||||||
|
SUM(IF(hasToRecalcPrice, volume, 0)) * 60 /
|
||||||
|
GREATEST(IFNULL(m3, 0), IFNULL(minSpeed, 0))
|
||||||
|
AS time
|
||||||
|
) etc
|
||||||
|
FROM zoneEstimatedDelivery
|
||||||
|
GROUP BY zoneFk
|
||||||
|
) zed ON zed.zoneFk = t.zoneFk
|
||||||
|
`);
|
||||||
|
|
||||||
if (args.orderFk) {
|
if (args.orderFk) {
|
||||||
stmt.merge({
|
stmt.merge({
|
||||||
|
|
|
@ -140,12 +140,11 @@ module.exports = Self => {
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(`
|
||||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
(INDEX (id))
|
(INDEX (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT
|
SELECT o.id,
|
||||||
o.id,
|
|
||||||
o.total,
|
o.total,
|
||||||
o.date_send landed,
|
o.date_send landed,
|
||||||
o.date_make created,
|
o.date_make created,
|
||||||
|
@ -163,7 +162,7 @@ module.exports = Self => {
|
||||||
zed.zoneFk,
|
zed.zoneFk,
|
||||||
zed.hourTheoretical,
|
zed.hourTheoretical,
|
||||||
zed.hourEffective,
|
zed.hourEffective,
|
||||||
am.name AS agencyName
|
am.name agencyName
|
||||||
FROM hedera.order o
|
FROM hedera.order o
|
||||||
LEFT JOIN address a ON a.id = o.address_id
|
LEFT JOIN address a ON a.id = o.address_id
|
||||||
LEFT JOIN agencyMode am ON am.id = o.agency_id
|
LEFT JOIN agencyMode am ON am.id = o.agency_id
|
||||||
|
@ -173,7 +172,24 @@ module.exports = Self => {
|
||||||
LEFT JOIN company co ON co.id = o.company_id
|
LEFT JOIN company co ON co.id = o.company_id
|
||||||
LEFT JOIN orderTicket ot ON ot.orderFk = o.id
|
LEFT JOIN orderTicket ot ON ot.orderFk = o.id
|
||||||
LEFT JOIN ticket t ON t.id = ot.ticketFk
|
LEFT JOIN ticket t ON t.id = ot.ticketFk
|
||||||
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
|
LEFT JOIN (
|
||||||
|
SELECT zoneFk,
|
||||||
|
CAST(
|
||||||
|
util.VN_CURDATE() +
|
||||||
|
INTERVAL HOUR(IFNULL(zoneClosureHour, zoneHour)) * 60 +
|
||||||
|
MINUTE(IFNULL(zoneClosureHour, zoneHour)) MINUTE
|
||||||
|
AS time
|
||||||
|
) hourTheoretical,
|
||||||
|
CAST(
|
||||||
|
IFNULL(zoneClosureHour, zoneHour) +
|
||||||
|
SUM(IF(hasToRecalcPrice, volume, 0)) * 60 /
|
||||||
|
GREATEST(IFNULL(m3, 0), IFNULL(minSpeed, 0))
|
||||||
|
AS time
|
||||||
|
) hourEffective
|
||||||
|
FROM zoneEstimatedDelivery
|
||||||
|
GROUP BY zoneFk
|
||||||
|
) zed ON zed.zoneFk = t.zoneFk
|
||||||
|
`);
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
stmt.merge(`GROUP BY id`);
|
stmt.merge(`GROUP BY id`);
|
||||||
|
|
|
@ -11,28 +11,24 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"hourTheoretical": {
|
"zoneClosureHour": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
},
|
},
|
||||||
"totalVolume": {
|
"zoneHour": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"volume": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"remainingVolume": {
|
"hasToRecalcPrice": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"m3": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"speed": {
|
"minSpeed": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
|
||||||
"hourEffective": {
|
|
||||||
"type": "date"
|
|
||||||
},
|
|
||||||
"minutesLess": {
|
|
||||||
"type": "date"
|
|
||||||
},
|
|
||||||
"etc": {
|
|
||||||
"type": "date"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"zone": {
|
"zone": {
|
||||||
|
|
Loading…
Reference in New Issue