project QadFinancials > class BBankEntry > method AddBankEntryHeader

Description

This method creates bank entry header record


Parameters


icBankGLCodeinputcharacter
bcStatementNumberinput-outputcharacter
itTransactionDateinputdate
icInfoinputcharacter
icBankImpLineRefinputcharacterBank Importing Reference
oiBankStateIdoutputinteger
ocBankStateRowIdoutputcharacter
oiBankStateYearoutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.ProcessBankImpLineNewBankEntry
method BBankImportLine.CreateUnallocatedBankEntry

QadFitnesse
method BBankEntry.ApiBankingEntryCreate


program code (program6/bbankentry.p)

/* =================================================================================================== */
/* Method      : AddBankEntryHeader                                                                    */
/* Desc        : This method creates Banking Statement header                                          */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  BankGLCode           Code of GL account associated with bank number                   */
/*          (I)  StatementNumber      Statement number                                                 */
/*          (I)  TransactionDate      Transaction date                                                 */
/*          (I)  Info                 Transaction info                                                 */
/*          (O)  BankStateId          ID of created banking statement                                  */
/*          (O)  BankStateRowId       Row ID of created banking statement                              */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Default output values                                                                               */
/* =================================================================================================== */
assign oiBankStateId    = ?
       ocBankStateRowId = ?.

/* =================================================================================================== */
/* Normalize input parameters                                                                          */
/* =================================================================================================== */
if icBankGLCode      = "":U then assign icBankGLCode      = ?.
if bcStatementNumber = "":U then assign bcStatementNumber = ?.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if icBankGLCode      = ? or
   itTransactionDate = ?
then do:
    assign vcMessage = #T-1'You have not entered all the mandatory values.':255(63250)T-1#
           vcContext = 'icBankGLCode=&1|itTransactionDate=&2':U
           vcContext = substitute(vcContext, icBankGLCode, itTransactionDate)
           vcContext = replace(vcContext, '|':U, chr(2)).
    <M-2 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7558':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Get accounting period for transaction                                                               */
/* =================================================================================================== */
<Q-3 run PeriodByStartEndDate (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input itTransactionDate, (Date)
    output dataset tqPeriodByStartEndDate) in BPeriod >
find first tqPeriodByStartEndDate where
           tqPeriodByStartEndDate.ttPeriodStartDate <= itTransactionDate and
           tqPeriodByStartEndDate.ttPeriodEndDate   >= itTransactionDate and
           tqPeriodByStartEndDate.tcPeriodTypeCode  =  {&PERIODTYPECODE-NORMAL} no-error.
if not available tqPeriodByStartEndDate
then do:
    assign vcMessage = #T-5'Transaction date &1 does not belong to any period.':255(68008)T-5#
           vcMessage = substitute(vcMessage, itTransactionDate).   
    <M-4 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7559':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Check if BankStatement with same statement number exists if yes just do dataload                    */
/* =================================================================================================== */
if bcStatementNumber <> "":U and 
   bcStatementNumber <> ?    and
   icBankGLCode      <> "":U and 
   icBankGLCode      <> ?    and 
   itTransactionDate <> ?
then do :

    <M-51 run GetBankStateID
       (input  viCompanyId (iiCompanyID), 
        input  icBankGLCode (icGLCode), 
        input  tqPeriodByStartEndDate.tiPeriodYear (iiBankStateYear), 
        input  bcStatementNumber (icBankStateNumber), 
        output viBankState_ID (oiBankStateID), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry> 
    
    if viBankState_ID <> 0 and viBankState_ID <> ?
    then do:
        <M-10 run DataLoad
           (input  '':U (icRowids), 
            input  string(viBankState_ID) (icPkeys), 
            input  '':U (icObjectIds), 
            input  '':U (icFreeform), 
            input  true (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    end. /* if viBankState_ID <> 0 and viBankState_ID <> ? */
    /* In batch processing, bankstate will be stored in memory. It reduces to get empty bankstate id from datatable.
       In this case, dataload will not be executed. we could use find first to get it directly.
    */
    find first tBankState where 
                   tBankState.BankStateNumber = bcStatementNumber and
                   tBankState.Company_ID = viCompanyId and
                   tBankState.tcGLCode = icBankGLCode and
                   tBankState.BankStateYear = tqPeriodByStartEndDate.tiPeriodYear no-error.
     if available tBankState
     then do:
            assign oiBankStateId    = tBankState.BankState_ID
                   ocBankStateRowId = tBankState.tc_Rowid.
            if tBankState.tc_Status = "":U then  
            assign tBankState.tc_Status  = "C":U.
                   
            if oiReturnStatus = -98 then assign oiReturnStatus = 0.
            return.
     end. /* if available tBankState */ 
end. /* if bcStatementNumber <> "":U and */    


vlCreateBEFromBankImpLineBatch = yes.

/* =================================================================================================== */
/* Create banking entry header                                                                         */
/* =================================================================================================== */
<M-6 run AddDetailLine
   (input  'BankState':U (icTable), 
    input  '':U (icParentRowid), 
    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.

/* =================================================================================================== */
/* Assign values for header                                                                            */
/* =================================================================================================== */
assign tBankState.BankStateInfo              = icInfo
       tBankState.BankStateNumber            = bcStatementNumber
       tBankState.BankStatePostingDate       = itTransactionDate
       tBankState.BankStateTransactionType   = {&BANKSTATETRANSTYPE-BANK}
       tBankState.BankStateYear              = tqPeriodByStartEndDate.tiPeriodYear  /*Year(itTransactionDate)*/
       tBankState.Period_ID                  = tqPeriodByStartEndDate.tiPeriod_ID
       tBankState.tiPeriodYear               = tqPeriodByStartEndDate.tiPeriodYear
       tBankState.tiPeriodPeriod             = tqPeriodByStartEndDate.tiPeriodPeriod
       tBankState.tcGLCode                   = icBankGLCode
       tBankState.BankStateBankImpRef        = icBankImpLineRef.

/* assign gl_id */
if tBankState.GL_ID = 0 or tBankState.GL_ID = ? then
do:
    <Q-63 run GLPrim (all) (Read) (NoCache)
       (input viCompanyId, (CompanyId)
        input tBankState.tcGLCode, (GLCode)
        input ?, (GLId)
        output dataset tqGLPrim) in BGL>
    find first tqGLPrim where 
                   tqGLPrim.tcGLCode = icBankGLCode
                   no-lock no-error.
    if not available tqGLPrim then
    do:
           assign oiReturnStatus = -3
                   vcMessage      = trim(SUBSTITUTE(#T-15'An invalid bank account code (&1) was passed to generate a default bank statement number.':255(356)T-15#,tBankState.tcGLCode)) + chr(10) + 
                                    trim(SUBSTITUTE(#T-92'GL account: &1.':255(354)T-92#,tBankState.tcGLCode)).
            <M-91 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-213714':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
            Return.
    end.
    assign tBankState.GL_ID = tqGLPrim.tiGL_ID.
end.
/* =================================================================================================== */
/* Get next statement number                                                                           */
/* =================================================================================================== */
if tBankState.BankStateNumber = '':U or
   tBankState.BankStateNumber = ?
then do:
    <M-8 run GetNewBankStateNumber
       (input  viCompanyId (iiCompanyID), 
        input  tBankState.GL_ID (iiBankGLID), 
        input  tBankState.tcGLCode (icBankGLCode), 
        input  tBankState.BankStateYear (iiBankStateYear), 
        output tBankState.BankStateNumber (ocNewBankStateNumber), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    if viFcReturnSuper <> 0 then 
    do: 
        assign oiReturnStatus = viFcReturnSuper.
    end.
    if viFcReturnSuper <  0 then return.

    assign bcStatementNumber = tBankState.BankStateNumber.

    find first t_oBankState where t_oBankState.tc_Rowid = tBankState.tc_Rowid no-error.
    if available t_oBankState then
    do:
        assign t_oBankState.BankStateNumber = tBankState.BankStateNumber
                   t_oBankState.Company_ID    = viCompanyId 
                   t_oBankState.BankStateYear = tBankState.BankStateYear
                   t_oBankState.GL_ID         = tBankState.GL_ID.
    end. 
end.

/* =================================================================================================== */
/* Assign values related to Bank account                                                               */
/* =================================================================================================== */
<M-7 run CalculateBankState
   (input  viCompanyId (iiCompanyID), 
    input  ? (iiBankStateGLID), 
    input  tBankState.tcGLCode (icBankStateGLCode), 
    output tBankState.Currency_ID (oiGLCurrencyID), 
    output tBankState.tcCurrencyCode (ocGLCurrencyCode), 
    output tBankState.tcGLDescription (ocGLDescription), 
    output vdDummy (odGLBalanceLC), 
    output vdDummy (odGLBalanceCC), 
    output vdDummy (odGLBalanceGLCurr), 
    output tBankState.tcGLBankNumber (ocGLBankNumber), 
    output viDummy1 (oiGLJournalID), 
    output tBankState.tcGLJournalCode (ocGLJournalCode), 
    output tBankState.tcGLJournalLayerCode (ocGLJournalLayerCode), 
    output tBankState.tdGLUnallocStatBalance (odGLUnallocStatBalance), 
    output tBankState.BankStateOpeningBalance (odBankStateOpeningBalance), 
    output tBankState.tdGLBalance (odGLBalanceTC), 
    output tBankState.tiGLBankNumberId (oiGLBankNumberId), 
    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then 
do: 
    assign oiReturnStatus = viFcReturnSuper.
end.
if viFcReturnSuper <  0 then return.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
assign oiBankStateId    = tBankState.BankState_ID
       ocBankStateRowId = tBankState.tc_Rowid
       oiBankStateYear  = tBankState.tiPeriodYear.

if oiReturnStatus = -98 then assign oiReturnStatus = 0.