salix/db/routines/vn/procedures/company_getFiscaldata.sql

26 lines
581 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`company_getFiscaldata`(workerFk INT)
BEGIN
DECLARE vCompanyFk INT;
SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk)
INTO vCompanyFk
FROM vn.routeConfig rc
LEFT JOIN userMultiConfig uc ON uc.userFk = workerFk;
SELECT
s.name AS name ,
s.NIF AS nif ,
s.street AS street ,
s.city AS city ,
s.postCode AS postCode
FROM vn.company c
JOIN vn.worker w ON w.id = c.workerManagerFk
JOIN vn.supplier s ON s.id = c.id
WHERE c.id = vCompanyFk;
END$$
DELIMITER ;