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

41 lines
757 B
SQL

DELIMITER $$
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,
commission,
currencyFk,
companyFk,
clonedFrom,
typeFk
)
SELECT IFNULL(vTravelFk, travelFk),
supplierFk,
dated,
isExcludedFromAvailable,
commission,
currencyFk,
companyFk,
vSelf,
typeFk
FROM entry
WHERE id = vSelf;
SET vNewEntryFk = LAST_INSERT_ID();
END$$
DELIMITER ;