2024-02-09 10:40:20 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`travel_getDetailFromContinent`(
|
2024-02-14 10:16:52 +00:00
|
|
|
vContinentFk INT
|
2024-02-13 10:14:35 +00:00
|
|
|
)
|
2024-02-09 10:40:20 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Devuelve los detalles de los vuelos que tienen
|
2024-02-13 10:14:35 +00:00
|
|
|
* un almacén de salida de un continente.
|
|
|
|
*
|
2024-02-14 10:16:52 +00:00
|
|
|
* @param vContinentFk Id de continente
|
2024-02-09 10:40:20 +00:00
|
|
|
*/
|
|
|
|
DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK;
|
|
|
|
SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry,
|
|
|
|
sub.*
|
|
|
|
FROM (
|
|
|
|
SELECT tr.id travelFk,
|
|
|
|
NULL entryFk,
|
|
|
|
TRUE isTravel,
|
|
|
|
am.name agency,
|
|
|
|
tr.ref,
|
|
|
|
tr.shipped,
|
|
|
|
wOut.name originBoxes,
|
|
|
|
tr.landed,
|
|
|
|
wIn.name destination,
|
|
|
|
SUM(b.stickers) stickers,
|
|
|
|
NULL evaNotes,
|
|
|
|
tr.kg,
|
|
|
|
CAST(SUM(b.weight * b.stickers) AS INT) loadedkg,
|
|
|
|
CAST(
|
|
|
|
SUM(vc.aerealVolumetricDensity *
|
|
|
|
b.stickers *
|
|
|
|
IF(p.volume,
|
|
|
|
p.volume,
|
|
|
|
p.width * p.depth * p.height
|
|
|
|
) / 1000000
|
|
|
|
) AS INT
|
|
|
|
) volumeKg,
|
|
|
|
NULL loadPriority,
|
|
|
|
NULL invoiceAmount,
|
|
|
|
s.nickname freighter,
|
|
|
|
NULL reference
|
|
|
|
FROM travel tr
|
|
|
|
LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk
|
|
|
|
LEFT JOIN entry e ON e.travelFk = tr.id
|
|
|
|
LEFT JOIN buy b ON b.entryFk = e.id
|
|
|
|
LEFT JOIN packaging p ON p.id = b.packagingFk
|
|
|
|
LEFT JOIN item i ON i.id = b.itemFk
|
|
|
|
LEFT JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN warehouse wIn ON wIn.id = tr.warehouseInFk
|
|
|
|
JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk
|
2024-02-13 10:14:35 +00:00
|
|
|
JOIN country co ON co.id = wOut.countryFk
|
2024-02-09 10:40:20 +00:00
|
|
|
JOIN agencyMode am ON am.id = tr.agencyModeFk
|
|
|
|
JOIN volumeConfig vc
|
|
|
|
WHERE tr.landed >= vDateFrom
|
2024-02-14 10:16:52 +00:00
|
|
|
AND co.continentFk = vContinentFk
|
2024-02-09 10:40:20 +00:00
|
|
|
GROUP BY tr.id
|
|
|
|
UNION ALL
|
|
|
|
SELECT e.travelFk,
|
|
|
|
e.id,
|
|
|
|
FALSE,
|
|
|
|
s.name,
|
|
|
|
e.invoiceNumber,
|
|
|
|
tr.shipped,
|
|
|
|
wOut.name,
|
|
|
|
tr.landed,
|
|
|
|
wIn.name,
|
|
|
|
SUM(b.stickers),
|
|
|
|
e.evaNotes,
|
|
|
|
NULL,
|
|
|
|
CAST(SUM(b.weight * b.stickers) AS INT),
|
|
|
|
CAST(
|
|
|
|
SUM(vc.aerealVolumetricDensity *
|
|
|
|
b.stickers *
|
|
|
|
IF(p.volume,
|
|
|
|
p.volume,
|
|
|
|
p.width * p.depth * p.height
|
|
|
|
) / 1000000
|
|
|
|
) AS INT
|
|
|
|
),
|
|
|
|
loadPriority,
|
|
|
|
e.invoiceAmount,
|
|
|
|
s2.nickname,
|
|
|
|
e.reference
|
|
|
|
FROM entry e
|
|
|
|
JOIN buy b ON b.entryFk = e.id
|
|
|
|
JOIN packaging p ON p.id = b.packagingFk
|
|
|
|
JOIN item i ON i.id = b.itemFk
|
|
|
|
JOIN itemType it ON it.id = i.typeFk
|
|
|
|
JOIN supplier s ON s.id = e.supplierFk
|
|
|
|
JOIN travel tr ON tr.id = e.travelFk
|
|
|
|
LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk
|
|
|
|
JOIN warehouse wIn ON wIn.id = tr.warehouseInFk
|
|
|
|
JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk
|
2024-02-13 10:14:35 +00:00
|
|
|
JOIN country co ON co.id = wOut.countryFk
|
2024-02-09 10:40:20 +00:00
|
|
|
JOIN volumeConfig vc
|
|
|
|
WHERE tr.landed >= vDateFrom
|
2024-02-14 10:16:52 +00:00
|
|
|
AND co.continentFk = vContinentFk
|
2024-02-09 10:40:20 +00:00
|
|
|
GROUP BY e.id
|
|
|
|
) sub
|
|
|
|
ORDER BY landed ASC,
|
|
|
|
shipped ASC,
|
|
|
|
travelFk,
|
|
|
|
isTravel DESC,
|
|
|
|
(loadPriority > 0) DESC,
|
|
|
|
loadPriority,
|
|
|
|
agency,
|
|
|
|
evaNotes;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|