USE `sakti`;
DROP FUNCTION IF EXISTS `generateIdAdk`;
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `generateIdAdk`(`PHEADER` CHAR(10), `PTANGGAL` DATE) RETURNS varchar(21) CHARSET latin1
    DETERMINISTIC
BEGIN
	INSERT INTO sakti.generate_id_adk(HEADER, TANGGAL)
	VALUES(PHEADER, PTANGGAL);
		
	RETURN CONCAT('548886', DATE_FORMAT(PTANGGAL, '%y%m%d'), LPAD(LAST_INSERT_ID(), 3, '0'));
END//
DELIMITER ;