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

43 lines
780 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_cloneHeader`(
vSelf INT,
OUT vNewEntryFk INT,
vTravelFk INT
)
BEGIN
/**
* Clones an entry header.
*
* @param vSelf The entry id
* @param OUT vNewEntryFk The new entry id
* @param vTravelFk Travel for the new entry or %NULL to use the source entry travel
*/
INSERT INTO entry(
travelFk,
supplierFk,
dated,
isExcludedFromAvailable,
isRaid,
commission,
currencyFk,
companyFk,
clonedFrom,
typeFk
)
SELECT IFNULL(vTravelFk, travelFk),
supplierFk,
dated,
isExcludedFromAvailable,
isRaid,
commission,
currencyFk,
companyFk,
vSelf,
typeFk
FROM entry
WHERE id = vSelf;
SET vNewEntryFk = LAST_INSERT_ID();
END$$
DELIMITER ;