project QadFinancials > class BBankEntry > method AddBankEntryAllocateDocument

Description

This procedure allocates DDocument to Bank Entry


Parameters


icBankStateLineRowIdinputcharacter
iiDDocumentYearinputinteger
icDDocumentTypeinputcharacter
iiDDocumentNumberinputinteger
iiCDocumentYearinputinteger
icCDocumentTypeinputcharacter
iiCDocumentNumberinputinteger
icBankImpLineRefinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.ProcessBankImpLineNewBankEntry


program code (program6/bbankentry.p)

/* =================================================================================================== */
/* Method      : AddBankEntryAllocateDDocument                                                         */
/* Desc        : This method does allocation of Debtor Document for bank entry                         */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  icBankStateLineRowId Row Id of the bank statement line record                          */
/*          (O)  Name                 Description                                                      */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Normalize input parameters                                                                          */
/* =================================================================================================== */
if icBankStateLineRowId = '':U then assign icBankStateLineRowId = ?.
if iiDDocumentYear      = 0    then assign iiDDocumentYear      = ?.
if icDDocumentType      = '':U then assign icDDocumentType      = ?.
if iiDDocumentNumber    = 0    then assign iiDDocumentNumber    = ?.
if iiCDocumentYear      = 0    then assign iiCDocumentYear      = ?.
if icCDocumentType      = '':U then assign icCDocumentType      = ?.
if iiCDocumentNumber    = 0    then assign iiCDocumentNumber    = ?.


/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if icBankStateLineRowId = ? or
   ((iiDDocumentYear    = ? or
     icDDocumentType    = ? or
     iiDDocumentNumber  = ?) and
    (iiCDocumentYear    = ? or
     icCDocumentType    = ? or
     iiCDocumentNumber  = ?))
then do:
    assign vcMessage = #T-6'You have not entered all the mandatory values.':255(63250)t-6#
           vcContext = 'icBankStateLineRowId=&1|iiDDocumentYear=&2|icDDocumentType=&3|iiDDocumentNumber=&4|iiCDocumentYear=&5|icCDocumentType=&6|iiCDocumentNumber=&7':U
           vcContext = substitute(vcContext, icBankStateLineRowId, iiDDocumentYear, icDDocumentType, iiDDocumentNumber, iiCDocumentYear, icCDocumentType, iiCDocumentNumber)
           vcContext = replace(vcContext, '|':U, chr(2)).
    <M-5 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-7600':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    assign oiReturnStatus = -1.
    return.
end.

find tBankStateLine where
     tBankStateLine.tc_Rowid = icBankStateLineRowId no-error.
if not available tBankStateLine
then do:
    assign vcMessage = #T-4'The bank state line definition is missing':255(68264)t-4#
           vcContext = 'icBankStateLineRowId=&1':U
           vcContext = substitute(vcContext, icBankStateLineRowId).
    <M-3 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-7599':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  vcContext (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* We have unique identification of the DDocument, so lets get information to populate BankStateAlloc  */
/* and BankStateAllocColl                                                                              */
/* =================================================================================================== */
assign vlIncludeDebtor   = (if iiDDocumentYear <> ? then true else false)
       vlIncludeCreditor = (if vlIncludeDebtor then false else true)
       viDocumentYear    = (if vlIncludeDebtor then iiDDocumentYear   else iiCDocumentYear)
       vcDocumentType    = (if vlIncludeDebtor then icDDocumentType   else icCDocumentType)
       viDocumentNumber  = (if vlIncludeDebtor then iiDDocumentNumber else iiCDocumentNumber).

<M-7 run GetPossibleCollAllocations
   (input  viCompanyId (iiCompanyID), 
    input  tBankStateLine.BankStateLine_ID (iiBankStateLineID), 
    input  tBankStateLine.tc_Rowid (icBankStateLineTcRowid), 
    input  ? (itFromRequestedDate), 
    input  ? (idTotalCollectionAmountTC), 
    input  vlIncludeDebtor (ilIncludeDebtor), 
    input  vlIncludeCreditor (ilIncludeCreditor), 
    input  tBankState.tcCurrencyCode (icBankCurrencyCode), 
    input  tBankState.tcGLCode (icGLCode), 
    input  ? (itBankStateLineValueDate), 
    input  viDocumentYear (iiDocumentYear), 
    input  vcDocumentType (icDocumentType), 
    input  viDocumentNumber (iiDocumentNumber), 
    input  ? (iiCDocumentPrePrintedNumber), 
    input  ? (icDocumentReference), 
    input  ? (icSelectionCode), 
    output tPossibleBankStateAlloc (tPossibleBankStateAlloc), 
    output tPossibleBankStateCollAlloc (tPossibleBankStateCollAlloc), 
    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper <  0 then return.


/* =================================================================================================== */
/* Create Bank state allocation records                                                                */
/* =================================================================================================== */
assign vdAllocatedAmountTC = 0.

for each tPossibleBankStateAlloc:
    <M-8 run AddDetailLine
       (input  'BankStateAlloc':U (icTable), 
        input  tBankStateLine.tc_Rowid (icParentRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.

    buffer-copy tPossibleBankStateAlloc 
        except BankStateAlloc_ID BankStateLine_ID tc_ParentRowid tc_Rowid tc_Status
        to tBankStateAlloc.
    /* In this case, all the records for tPossibleBankStateCollAlloc are set allocated later.
       So we can directly set allocated amount as the total amount of alloccoll.
    */
    assign tBankStateAlloc.BankStateAllocAmountTC = 0.
    for each tPossibleBankStateCollAlloc where
             tPossibleBankStateCollAlloc.tc_ParentRowid = tPossibleBankStateAlloc.tc_Rowid:
        assign tBankStateAlloc.BankStateAllocAmountTC = tBankStateAlloc.BankStateAllocAmountTC + tPossibleBankStateCollAlloc.tdDocAmount.
      
    end.
    
    /* calculate allocated amount */
    assign /* tBankStateAlloc.BankStateAllocAmountTC   = tBankStateAlloc.tdCollBalance */
           tBankStateAlloc.tdNewBalanceTC           = tBankStateAlloc.tdNewBalanceTC
                                                    - tBankStateAlloc.BankStateAllocAmountTC
           tBankStateAlloc.tlUIFullAllocation       = true
           tBankStateAlloc.tiBankStateAllocSequence = 1
           tBankStateAlloc.Posting_ID               = tBankStateLine.Posting_ID
           tBankStateAlloc.BankStateAllocBankImpRef = icBankImpLineRef.
    if vlIncludeDebtor 
    then do:
        assign vdAllocatedAmountTC                  = vdAllocatedAmountTC 
                                                    + tBankStateAlloc.BankStateAllocAmountTC.
    end.
    else do:
        assign vdAllocatedAmountTC                  = vdAllocatedAmountTC 
                                                    - tBankStateAlloc.BankStateAllocAmountTC.
    end.

    /* sequence of the line */
    for first bLastBankStateAlloc where
              bLastBankStateAlloc.tc_ParentRowid = tBankStateAlloc.tc_ParentRowid and
              bLastBankStateAlloc.tc_Rowid      <> tBankStateAlloc.tc_Rowid
           by bLastBankStateAlloc.tiBankStateAllocSequence DESCENDING:
        assign tBankStateAlloc.tiBankStateAllocSequence = bLastBankStateAlloc.tiBankStateAllocSequence + 1.
    end.

    /* Calculate allocated amount in local currency */
    if tBankStateAlloc.tcDocCurrencyCode = vcCompanyLC
    then assign tBankStateAlloc.BankStateAllocAmountLC = tBankStateAlloc.BankStateAllocAmountTC.
    else do:
        assign vcExchangeRateType = <M-19 GetExchangeRateType () in BBankEntry>.
        <M-49 run GetExchangeRate
           (input  tBankStateLine.Company_ID (iiCompanyID), 
            input  ? (iiFromCurrencyID), 
            input  tBankStateAlloc.tcDocCurrencyCode (icFromCurrencyCode), 
            input  viCompanyLCId (iiToCurrencyID), 
            input  ? (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  vcExchangeRateType (icExchangeRateTypeCode), 
            input  tBankStateLine.BankStateLineValueDate (itValidityDate), 
            output vdBankStateAllocExchangeRate (odExchangeRate), 
            output vdBankStateAllocExchRateScale (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.

        assign tBankStateAlloc.BankStateAllocAmountLC = <M-21 RoundAmount
                                                           (input  tBankStateAlloc.BankStateAllocAmountTC * vdBankStateAllocExchangeRate * vdBankStateAllocExchRateScale (idUnroundedAmount), 
                                                            input  viCompanyLCId (iiCurrencyID), 
                                                            input  vcCompanyLC (icCurrencyCode)) in business>.
    end.

    /* Calculate default allocation amount for tBankStateAlloc*/
    <M-15 run DefaultBankStateAllocBank
       (input  tBankStateAlloc.tcDocCurrencyCode (icDocCurrencyCode), 
        input  tBankStateAlloc.tcCurrencyCode (icCurrencyCode), 
        input  tBankStateLine.BankStateLineExtBankRate (idBankStateLineExtBankRate), 
        input  tBankStateLine.BankStateLineExtRateScale (idBankStateLineExtBankRateScale), 
        input  tBankStateLine.BankStateLineExtCurrency (icBankStateLineExtCurrency), 
        input  tBankStateAlloc.BankStateAllocAmountTC (idBankStateAllocAmountTC), 
        input  0 (idBankStateAllocAmountLC), 
        input  tBankStateAlloc.BankStateAllocDiscountTC (idBankStateAllocDiscountTC), 
        input  0 (idBankStateAllocDiscountLC), 
        input  tBankStateLine.BankStateLineValueDate (itBankStateLineValueDate), 
        input  0 (idDocExchangeRate), 
        input  0 (idDocExchangeRateScale), 
        input  false (ilIsPrepayment), 
        input  tBankStateAlloc.BankStateAllocWHTAmtTC (idBankStateAllocWHTAmtTC), 
        output tBankStateAlloc.BankStateAllocBankAmountTC (odBankStateAllocBankAmountTC), 
        output tBankStateAlloc.BankStateAllocBankAmountLC (odBankStateAllocBankAmountLC), 
        output tBankStateAlloc.BankStateAllocBankRate (odBankStateAllocBankRate), 
        output tBankStateAlloc.BankStateAllocBankValDate (otBankStateAllocBankValueDate), 
        output tBankStateAlloc.BankStateAllocBankDiscTC (odBankStateAllocBankDiscTC), 
        output tBankStateAlloc.BankStateAllocBankDiscLC (odBankStateAllocBankDiscLC), 
        output tBankStateAlloc.BankStateAllocBankRteScale (odBankStateAllocBankRateScale), 
        output tBankStateAlloc.tdBankStateAllocBankWhtAmtTC (odBankStateAllocBankWHTAmtTC), 
        output tBankStateAlloc.BankStateAllocWHTAmtLC (odBankStateAllocBankWHTAmtLC), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.

    /* Get GL for currency reference */
    <M-16 run GetGLForCurrencyReferenceLC
       (input  tBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
        input  tBankStateAlloc.BankStateAllocAmountLC (idAllocationAmountLCForDocCurr), 
        input  tBankStateAlloc.BankStateAllocBankAmountLC (idAllocationAmountLCForBankCurr), 
        output tBankStateAlloc.tcCurrencyDifferenceGLCode (ocGLCode), 
        input  viCompanyId (iiCompanyId), 
        output tBankStateAlloc.BankStateAllocDifferenceLC (odBankStateAllocDifferenceLC), 
        output tBankStateAlloc.tcCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.


    /* Create bank state collection alloc lines */
    for each tPossibleBankStateCollAlloc where
             tPossibleBankStateCollAlloc.tc_ParentRowid = tPossibleBankStateAlloc.tc_Rowid:
                          
        <M-10 run AddDetailLine
           (input  'BankStateAllocColl':U (icTable), 
            input  tBankStateAlloc.tc_Rowid (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.
    
        buffer-copy tPossibleBankStateCollAlloc 
            except BankStateAllocColl_ID BankStateAlloc_ID tc_ParentRowid tc_Rowid tc_Status
            to tBankStateAllocColl.
        
        assign tBankStateAllocColl.BankStateAllocCollIsAlloc  = yes
               tBankStateAllocColl.BankStateAllocCollBankAmTC = tBankStateAllocColl.tdDocAmount.
               
        /* Calculate allocation amount */
        <M-9 run DefaultBankStateAllocBank
           (input  tBankStateAllocColl.tcDocCurrencyCode (icDocCurrencyCode), 
            input  tBankStateAlloc.tcCurrencyCode (icCurrencyCode), 
            input  tBankStateLine.BankStateLineExtBankRate (idBankStateLineExtBankRate), 
            input  tBankStateLine.BankStateLineExtRateScale (idBankStateLineExtBankRateScale), 
            input  tBankStateLine.BankStateLineExtCurrency (icBankStateLineExtCurrency), 
            input  tBankStateAllocColl.BankStateAllocCollBankAmTC (idBankStateAllocAmountTC), 
            input  0 (idBankStateAllocAmountLC), 
            input  0 (idBankStateAllocDiscountTC), 
            input  0 (idBankStateAllocDiscountLC), 
            input  tBankStateLine.BankStateLineValueDate (itBankStateLineValueDate), 
            input  tBankStateAllocColl.tdDocExchangeRate (idDocExchangeRate), 
            input  tBankStateAllocColl.tdDocExchangeRateScale (idDocExchangeRateScale), 
            input  false (ilIsPrepayment), 
            input  0 (idBankStateAllocWHTAmtTC), 
            output tBankStateAllocColl.BankStateAllocCollBankAmTC (odBankStateAllocBankAmountTC), 
            output tBankStateAllocColl.BankStateAllocCollBankAmLC (odBankStateAllocBankAmountLC), 
            output tBankStateAllocColl.BankStateAllocCollBankRate (odBankStateAllocBankRate), 
            output tBankStateAllocColl.BankStateAllocCollBankDate (otBankStateAllocBankValueDate), 
            output vdDummy (odBankStateAllocBankDiscTC), 
            output vdDummy (odBankStateAllocBankDiscLC), 
            output tBankStateAllocColl.BankStateAllocCollRteScale (odBankStateAllocBankRateScale), 
            output vdDummy (odBankStateAllocBankWHTAmtTC), 
            output vdDummy (odBankStateAllocBankWHTAmtLC), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.

        /* Get GL for currency reference */
        <M-17 run GetGLForCurrencyReferenceLC
           (input  tBankStateAlloc.tcAllocAmountCrDt (icAllocationCrDt), 
            input  tBankStateAllocColl.tdDocAmount * tbankstatealloccoll.tddocexchangeRate * tbankstatealloccoll.BankStateAllocCollRteScale (idAllocationAmountLCForDocCurr), 
            input  tBankStateAllocColl.BankStateAllocCollBankAmLC (idAllocationAmountLCForBankCurr), 
            output tBankStateAllocColl.tcCurrencyDifferenceGLCode (ocGLCode), 
            input  viCompanyId (iiCompanyId), 
            output tBankStateAllocColl.BankStateAllocCollDiffLC (odBankStateAllocDifferenceLC), 
            output tBankStateAllocColl.tcCurrDifferenceCrDt (ocCurrDifferenceCrDt), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper <  0 then return.

    end. /* for each tPossibleBankStateCollAlloc where */
    
    /* If there is not allocated amount left, just finish */
    if vdAllocatedAmountTC = tBankStateLine.BankStateLineAmountTC
    then leave.
end.

/* =================================================================================================== */
/* Update allocation status of bank statement line                                                     */
/* =================================================================================================== */
if vdAllocatedAmountTC = 0
then assign tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-UNALLOC}.
else if vdAllocatedAmountTC = tBankStateLine.BankStateLineAmountTC
then assign tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-ALLOC}.
else assign tBankStateLine.BankStateLineStatus = {&BANKSTATELINESTATUS-PARTALLOC}.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.