ramthechosenone
9/10/2019 - 3:47 PM

SP to create a new batch

alter proc mk_NewBatch(
     @description varchar(60), 
     @cashaccount varchar(10), 
     @nextbatch varchar(15) output
) as

begin

     declare @thisbatch varchar(10)
     declare @lastbatchnum int
     declare @nextbatchnum int

     set nocount on

     select   top 1 @thisbatch = BATCH_NUM
     from      Batch 
     where     left(BATCH_NUM,6) = format(getDate(), 'yyMMdd')
     order by DATE_CREATED desc

     if (@thisbatch is null)
          begin
              set @nextbatchnum = 1
          end
     else
          begin
              select @lastbatchnum = convert(int,right(@thisbatch, len(@thisbatch)-patindex('%-%',@thisbatch)))
              set @nextbatchnum = @lastbatchnum + 1
          end

     set @nextbatch = format(getDate(),'yyMMdd') + '-' + convert(varchar(2), @nextbatchnum)

     insert into Batch (BATCH_NUM,ORG_CODE,STATUS,DESCRIPTION,DATE_CREATED,CREATED_BY,LAST_UPDATED,UPDATED_BY,CONTROLLED,CONTROL_COUNT,CONTROL_CASH,TRANS_COUNT,TRANS_CASH,CASH_PSUEDO,CASH_GL_ACCT,AR_PSUEDO,AR_GL_ACCT,EFFECTIVE_DATE,CASH_ENTITY,CASH_ACCOUNT_CODE,INTENT_TO_EDIT,SOURCE_SYSTEM,DUES_CYCLE_FLAG,MEETING,HAS_EXPORTED_TRANS,WEB_BATCH)
     values (
          @nextbatch,
          '',
          0,
          @description,
          getDate(),
          'MANAGER',
          getDate(),
          'MANAGER',
          0,
          0,
          0,
          0,
          0,
          '',
          (select GL_ACCOUNT from Cash_Accounts where CASH_ACCOUNT_CODE = @cashaccount),
          '',
          '',
          convert(varchar(10),getDate(),126),
          '',
          @cashaccount,
          '',
          '',
          0,
          '',
          0,
          0
     )
     
end