DROP FUNCTION IF EXISTS `fn_get_curdate_vid`;
CREATE FUNCTION fn_get_curdate_vid(VDT DATE) RETURNS INT(11)
DETERMINISTIC
BEGIN
    SELECT MAX(voucher_number) INTO @MAX_VDT FROM voucher_narration WHERE voucher_date = VDT;
    IF @MAX_VDT IS NULL THEN
        RETURN 1;
    ELSE
        RETURN @MAX_VDT + 1;
    END IF;
    
END;