USP_DATAFORMTEMPLATE_ADJUSTLOAD_STOCKSALEGLDISTRIBUTION

The load procedure used by the edit dataform template "Stock Sale GL Distribution Adjust Form"

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter used to load the fields defined on the form.
@DATALOADED bit INOUT Output parameter indicating whether or not data was actually loaded.
@GLDISTRIBUTION xml INOUT Sold Stock GL distribution
@CAPTION nvarchar(10) INOUT Stock Or Property
@TSLONG bigint INOUT Output parameter indicating the TSLONG value of the record being edited. This is used to manage multi-user concurrency issues when multiple users access the same record.
@ADJUSTMENTDATE datetime INOUT Adjusted Date
@ADJUSTMENTPOSTDATE datetime INOUT Adjusted Post Date
@ADJUSTMENTPOSTSTATUSCODE tinyint INOUT Post Status Code
@ADJUSTMENTREASON nvarchar(300) INOUT Adjustment reason

Definition

Copy


                CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADJUSTLOAD_STOCKSALEGLDISTRIBUTION
                (
                    @ID uniqueidentifier,
                    @DATALOADED bit = 0 output,
                    @GLDISTRIBUTION xml = null output,
                    @CAPTION nvarchar(10) = null output,
                    @TSLONG bigint = 0 output,
                    @ADJUSTMENTDATE datetime = null output,
                    @ADJUSTMENTPOSTDATE datetime = null output,
                    @ADJUSTMENTPOSTSTATUSCODE tinyint = null output,
                    @ADJUSTMENTREASON nvarchar(300) = null output
                )
                as
                begin
                    set nocount on;

                    set @DATALOADED = 0;
                    set @TSLONG = 0;

                    select @GLDISTRIBUTION = dbo.UFN_REVENUE_GETSTOCKSALEGLDISTRIBUTION_TOITEMLISTXML(@ID),
                           @CAPTION = 'stock',
                           @ADJUSTMENTDATE = getdate(),
                           @ADJUSTMENTPOSTDATE = getdate(),
                           @ADJUSTMENTPOSTSTATUSCODE = 0;                    

                    -- if adjustment already exists for this sold stock detail

                    select top 1
                        @ADJUSTMENTDATE = DATE,
                        @ADJUSTMENTPOSTDATE = POSTDATE,
                        @ADJUSTMENTPOSTSTATUSCODE = 1,
                        @ADJUSTMENTREASON = REASON
                    from dbo.STOCKSALEADJUSTMENT
                    where STOCKSALEID = @ID and POSTSTATUSCODE = 1;

                    if @GLDISTRIBUTION is not null 
                        begin                          
                            set @DATALOADED = 1;        
                            select 
                                @TSLONG = max(STOCKSALEGLDISTRIBUTION.TSLONG) 
                            from 
                                dbo.STOCKSALEGLDISTRIBUTION 
                            where 
                                STOCKSALEGLDISTRIBUTION.STOCKSALEID = @ID;
                        end

                    return 0;                    
                end