DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_clone`(
	vSelf INT,
	OUT vOutputEntryFk INT
)
BEGIN
/**
 * clones an entry.
 *
 * @param vSelf The entry id
 * @param vOutputEntryFk The new entry id
 */
	DECLARE vNewEntryFk INT;

	DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
	DECLARE EXIT HANDLER FOR SQLEXCEPTION
	BEGIN
		CALL util.tx_rollback(vIsRequiredTx);
		RESIGNAL;
	END;

	CALL util.tx_start(vIsRequiredTx);

	CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL);
	CALL entry_copyBuys(vSelf, vNewEntryFk);

	CALL util.tx_commit(vIsRequiredTx);
	SET vOutputEntryFk = vNewEntryFk;

END$$
DELIMITER ;
