UFN_RESERVATION_ISDEPOSITPAID

Returns a bit describing if a deposit on a reservation has been paid.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@RESERVATIONID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_RESERVATION_ISDEPOSITPAID
(
    @RESERVATIONID uniqueidentifier
)
returns bit
with execute as caller
as begin
    declare @DEPOSITAMOUNT money;
    declare @DEPOSITREQUIRED bit;
    declare @AMOUNTPAID money;
    declare @AMOUNTREFUNDED money;

    select @DEPOSITAMOUNT = isnull(DEPOSITAMOUNT, 0),
        @DEPOSITREQUIRED = DEPOSITREQUIRED
    from dbo.RESERVATION
    where ID = @RESERVATIONID

    if @DEPOSITREQUIRED = 1 begin
        select
            @AMOUNTPAID = AMOUNTPAID,
            @AMOUNTREFUNDED = REFUNDS
        from
            dbo.UFN_SALESORDER_TOTALS(@RESERVATIONID);

        if @AMOUNTPAID - @AMOUNTREFUNDED < @DEPOSITAMOUNT or @DEPOSITAMOUNT = 0 begin
            return 0;
        end
    end

    return 1;
end