Scalar-valued Functions [dbo].[IsVanLineStatementImportable]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inVanlineGroupExternalCodevarchar(10)10
@inStatementYearint4
@inStatementNumberint4
@inVanLineStatementDefaultEndDatedatetime8
@inDefaultImportablebit1
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/**
*
*  This function is called to see if a VanLine Statement is importable based upon
*  the van line group and statement year and number and the current date.
*
*  See also the GetVanLineStatementImportableDate() function which has the logic
*  that this function relies upon.
*/

CREATE FUNCTION [dbo].[IsVanLineStatementImportable](
    @inVanlineGroupExternalCode varchar(10),
    @inStatementYear int,
    @inStatementNumber int,
    @inVanLineStatementDefaultEndDate datetime,
    @inDefaultImportable bit )
returns bit as
begin
    declare @outIsImportable bit
    declare @theCurrentDate datetime = convert( date, dbo.GetMssDateTime() )
    declare @theVanLineStatementImportableDate datetime

    -- If @inDefaultImportable is already 1, then this statement is importable and nothing more needs to be done.
    if( isnull( @inDefaultImportable, 0 ) != 1 )
    begin
        set @theVanLineStatementImportableDate = dbo.GetVanLineStatementImportableDate( @inVanlineGroupExternalCode,
            @inStatementYear, @inStatementNumber, @inVanLineStatementDefaultEndDate )

        if( @inVanlineGroupExternalCode = 'SIRVA' )
        begin
            -- Sirva periods end on the 15th and end of the month.  Sirva statements send the posting tickets on
            -- the second (business) day after the end of the period.  We'll just assume a statement is importable
            -- once we reach the day after that.  Note that once the Posting Tickets download comes in on the
            -- second day, then that will mark the statement as being importable and we would never get here.
            set @outIsImportable = case
                when @theCurrentDate >= @theVanLineStatementImportableDate then 1
                else 0
            end
        end
    end

    return isnull( @outIsImportable, @inDefaultImportable )
end
GO
GRANT EXECUTE ON  [dbo].[IsVanLineStatementImportable] TO [MssExec]
GO
Uses