UFN_RESERVATION_GETDEPOSITBALANCE

Returns the current deposit balance due.

Return

Return Type
money

Parameters

Parameter Parameter Type Mode Description
@RESERVATIONID uniqueidentifier IN
@DEPOSITAMOUNT money IN

Definition

Copy


            create function dbo.UFN_RESERVATION_GETDEPOSITBALANCE(@RESERVATIONID uniqueidentifier, @DEPOSITAMOUNT money)
            returns money
            with execute as caller
            as begin

                declare @BALANCE money;
                declare @AMOUNTPAID money = null
                select @AMOUNTPAID = coalesce(sum(SALESORDERPAYMENT.AMOUNTTENDERED), 0)
                from dbo.[SALESORDERPAYMENT]
                where [SALESORDERPAYMENT].[SALESORDERID] = @RESERVATIONID;

                set @BALANCE = @DEPOSITAMOUNT - @AMOUNTPAID
                if @BALANCE < 0
                    set @BALANCE = 0

                return @BALANCE
            end