add new procedure agencyHourGetLanded
This commit is contained in:
parent
be132e33cb
commit
829f9d33cd
|
@ -0,0 +1,42 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `agencyHourGetLanded`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetLanded`(vDated DATE, vAddress INT, vAgency INT, vWarehouse INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve una tabla temporal con el dia de recepcion para vDated.
|
||||
*
|
||||
* @param vDated Fecha de preparacion de mercancia
|
||||
* @param vAddress Id de consignatario, %NULL para recogida
|
||||
* @param vAgency Id agencia
|
||||
* @table agencyHourGetLanded Datos de recepción
|
||||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS agencyHourGetLanded;
|
||||
CREATE TEMPORARY TABLE agencyHourGetLanded
|
||||
ENGINE = MEMORY
|
||||
SELECT vWarehouse warehouseFk, landed FROM (
|
||||
SELECT * FROM (
|
||||
SELECT vWarehouse, TIMESTAMPADD(DAY, ah.substractDay, vDated) landed, ah.substractDay, ah.maxHour
|
||||
FROM agencyHour ah
|
||||
LEFT JOIN address a ON a.id = vAddress
|
||||
WHERE (ah.weekDay = WEEKDAY(TIMESTAMPADD(DAY, ah.substractDay, vDated)) OR ah.weekDay IS NULL)
|
||||
AND (ah.agencyFk = vAgency OR ah.agencyFk IS NULL)
|
||||
AND ah.warehouseFk = vWarehouse
|
||||
AND (ah.provinceFk = a.provinceFk OR ah.provinceFk IS NULL OR vAddress IS NULL)
|
||||
ORDER BY (
|
||||
(ah.weekDay IS NOT NULL) +
|
||||
(ah.agencyFk IS NOT NULL) +
|
||||
(- ah.substractDay) +
|
||||
((ah.provinceFk IS NOT NULL)*3)
|
||||
) DESC
|
||||
) t
|
||||
LIMIT 1
|
||||
) t
|
||||
WHERE IF(vDated = CURDATE(), t.maxHour > HOUR(NOW()), TRUE) AND t.substractDay < 225;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
Loading…
Reference in New Issue