project QadFinancials > class BBankEntry > method ApiStdMaintainTTSub

Description

apiStdMaintainTTSub : submethod of ApiStdMaintainTT


Parameters


icActioninputcharacterThis parameter defines what should happen with the input data : -SAVE: Save the data if there were no errors, -SAVESTORE : Save the data if there were no errors. If there were errors, save as draft. -STORE : Save the data as draft -VALIDATE : Validate the input data, but do no save the data.
bcLstReturninput-outputcharacterChar 4 separated list with the return status of the newly created main-table records. Zero means not errors occurred.
bcLstPrimKeyinput-outputcharacterCharacter 4 separated list with the primary keys of the newly created main-table records. The fields of the primary key are separated with Character 2.
bcLstRowidinput-outputcharacterChar 4 separated list with the temporarely rowids (negative for new ones) of the newly created main-table records.
blSaveAsDraftinput-outputlogicalSave As Draft ?
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.ApiCreateBankEntryFromImport
method BBankEntry.ApiStdMaintainTT


program code (program9/bbankentry.p)

/*JBA BTS 4906 use the correct exchange rate type*/
assign vcExchangeRateType = <M-20 GetExchangeRateType () in BBankEntry>.
    
/* ================================== */
/* Go through all BankStateLine-lines */
/* ================================== */
for each tApiBankStateLine where 
         tApiBankStateLine.tc_ParentRowid = tApiBankState.tc_Rowid
         by tApiBankStateLine.tc_Rowid :

    /* Next if the record already exists */
    find tBankStateLine where
         tBankStateLine.tc_ParentRowid      = tBankState.tc_Rowid                and
         tBankStateLine.BankStateLine_ID    = tApiBankStateLine.BankStateLine_ID and
         tApiBankStateLine.BankStateLine_ID <> ? and
         tApiBankStateLine.BankStateLine_ID <> 0
         no-error.
    if available tBankStateLine
    then do:     
        assign tBankStateLine.tc_Status = '':U.
        buffer-compare tApiBankStateLine except 
            BankStateLine_ID 
            BankState_ID 
            tc_Rowid 
            tc_ParentRowid 
            tc_Status             
            to tBankStateLine save vlBufferCompareResult.       
        if vlBufferCompareResult = true
        then next.
        assign tBankStateLine.tc_Status = "C":U.
    end.
    else do:
        /* ========================================== */
        /* Create a new BankStateLine  and copy all data           */
        /* ========================================== */        
        <M-13 run AddDetailLine (input  'BankStateLine':U (icTable), 
                         input  tBankState.tc_Rowid (icParentRowid), 
                         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        
        if viFcReturnSuper <> 0
        then do :
            assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0
            then do:
                assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
                       bcLstReturn   = bcLstReturn  + chr(4) + string(viFcReturnSuper)
                       bcLstPrimKey  = bcLstPrimKey + chr(4) + '*':U
                       bcLstRowid    = bcLstRowid   + chr(4) + '*':U.
                return.
            end.
        end. /* viFcReturnSuper <> 0 */        
    end.

    /************************************************************************************************/
    /* If the BankStateLineAmountTC has an unknown value the calculate it using the exchangerate    */
    /* of the VAlueDate                                                                             */
    /************************************************************************************************/
    if tApiBankStateLine.BankStateLineExtCurrency = '' or
       tApiBankStateLine.BankStateLineExtCurrency = ? 
    then assign tApiBankStateLine.BankStateLineExtCurrency = tApiBankState.tcCurrencyCode.

    if (tApiBankStateLine.BankStateLineAmountTC = 0 or
        tApiBankStateLine.BankStateLineAmountTC = ?) and
       (tApiBankStateLine.BankStateLineExtOriginalTC <> 0 and
        tApiBankStateLine.BankStateLineExtOriginalTC <> ?)
    then do:
        /*  get the exchange rate of the valuedate */ 
        <M-76 run GetExchangeRate
           (input  tBankState.Company_ID (iiCompanyID), 
            input  ? (iiFromCurrencyID), 
            input  tApiBankStateLine.BankStateLineExtCurrency (icFromCurrencyCode), 
            input  tApiBankState.Currency_ID (iiToCurrencyID), 
            input  ? (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  vcExchangeRateType (icExchangeRateTypeCode), 
            input  tApiBankStateLine.BankStateLineValueDate (itValidityDate), 
            output vdExchangeRate (odExchangeRate), 
            output vdExchangeRateScale (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
        if viFcReturnSuper < 0 or 
          (viFcReturnSuper > 0 and
           oiReturnStatus  = 0)
        then assign oiReturnStatus = viFcReturnSuper.        

        assign tApiBankStateLine.BankStateLineAmountTC     = <M-21 RoundAmount
                                                                (input  tApiBankStateLine.BankStateLineExtOriginalTC * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount), 
                                                                 input  0 (iiCurrencyID), 
                                                                 input  tApiBankStateLine.BankStateLineExtCurrency (icCurrencyCode)) in business>
               tApiBankStateLine.BankStateLineExtBankRate  = vdExchangeRate
               tApiBankStateLine.BankStateLineExtRateScale = vdExchangeRateScale.

        if oiReturnStatus < 0 THEN DO:
            assign vcMsgApi       = trim(#T-16'Bank statement integration: no exchange rate found for this value date.':255(14333)T-16#)
                   oiReturnStatus = -1.
            <M-17 run SetMessage (input  vcMsgApi (icMessage), 
                      input  '':U (icArguments), 
                      input  '':U (icFieldName), 
                      input  '':U (icFieldValue), 
                      input  'E':U (icType), 
                      input  1 (iiSeverity), 
                      input  '':U (icRowid), 
                      input  'QADFIN-3263':U (icFcMsgNumber), 
                      input  '' (icFcExplanation), 
                      input  '' (icFcIdentification), 
                      input  '' (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BBankEntry>            
        end.
    end.
 
    buffer-copy tApiBankStateLine except 
        BankStateLine_ID 
        BankState_ID 
        tc_Rowid 
        tc_ParentRowid 
        tc_Status 
        to tBankStateLine.

    if tBankStateLine.Company_ID = 0 or
       tBankStateLine.Company_ID = ?
    then assign tBankStateLine.Company_ID = tBankState.Company_ID.  

    /* Update the balances */
    if tBankStateLine.BankStateLineAmountTC <> ?
    then assign tBankState.BankStateMovement       = tBankState.BankStateMovement       + tBankStateLine.BankStateLineAmountTC
                tBankState.BankStateClosingBalance = tBankState.BankStateClosingBalance + tBankStateLine.BankStateLineAmountTC.
                                                           
    /* ==================================== */
    /* Go through all BankState-Alloc-lines */
    /* ==================================== */
    for each tApiBankAlloc where 
             tApiBankAlloc.tc_ParentRowid = tApiBankStateLine.tc_Rowid
             by tApiBankAlloc.tc_Rowid :

        /* Next if the record already exists */
        find tBankStateAlloc where
             tBankStateAlloc.tc_ParentRowid       = tBankStateLine.tc_Rowid         and  
             tBankStateAlloc.tcDocNumberReference = tApiBankAlloc.tcDocNumberReference     
             no-error.
        if not available tBankStateAlloc
        then find tBankStateAlloc where
              tBankStateAlloc.tc_ParentRowid    = tBankStateLine.tc_Rowid         and  
              tBankStateAlloc.BankStateAlloc_ID = tApiBankAlloc.BankStateAlloc_ID
             no-error.
        if available tBankStateAlloc
        then do:
            assign tBankStateAlloc.tc_Status = '':U.
            buffer-compare tApiBankAlloc except 
                BankStateLine_ID 
                BankStateAlloc_ID 
                tc_Rowid 
                tc_ParentRowid 
                tc_Status 
                to tBankStateAlloc save vlBufferCompareResult.
            if vlBufferCompareResult = true
            then next.
            assign tBankStateAlloc.tc_Status = "C":U.
        end.

        else do:
            /* =============================================== */
            /* Create a new BankState-Alloc and copy all data                   */
            /* =============================================== */
            <M-18 run AddDetailLine (input  'BankStateAlloc':U (icTable), 
                         input  tBankStateLine.tc_Rowid (icParentRowid), 
                         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>        

            if viFcReturnSuper <> 0
            then do :
                assign oiReturnStatus = viFcReturnSuper.
                if oiReturnStatus < 0
                then do:
                    assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
                           bcLstReturn   = bcLstReturn  + chr(4) + string(viFcReturnSuper)
                           bcLstPrimKey  = bcLstPrimKey + chr(4) + '*':U
                           bcLstRowid    = bcLstRowid   + chr(4) + '*':U.
                    return.
                end.
            end. /* viFcReturnSuper <> 0 */
        end.

        buffer-copy tApiBankAlloc except 
            BankStateAlloc_ID 
            BankStateLine_ID  
            tc_Rowid 
            tc_ParentRowid 
            tc_Status 
            to tBankStateAlloc.

        if tBankStateAlloc.Company_ID = 0 or
           tBankStateAlloc.Company_ID = ?
        then assign tBankStateAlloc.Company_ID = tBankStateLine.Company_ID. 

        /* ======================================== */
        /* Go through all BankState-AllocColl-lines */
        /* ======================================== */     
        for each tApiBankStateAllocColl where 
                 tApiBankStateAllocColl.tc_ParentRowid = tApiBankAlloc.tc_Rowid
                 by tApiBankStateAllocColl.tc_Rowid :

            /* Next if the record already exists */
            find tBankStateAllocColl WHERE                
                 tBankStateAllocColl.tc_ParentRowid    = tBankStateAlloc.tc_Rowid                 and
                 tBankStateAllocColl.tcCDocumentType   = tApiBankStateAllocColl.tcCDocumentType   and
                 tBankStateAllocColl.tiCDocumentNumber = tApiBankStateAllocColl.tiCDocumentNumber and
                 tBankStateAllocColl.tiCDocumentYear   = tApiBankStateAllocColl.tiCDocumentYear   and
                 tBankStateAllocColl.tcDDocumentType   = tApiBankStateAllocColl.tcDDocumentType   and
                 tBankStateAllocColl.tiDDocumentNumber = tApiBankStateAllocColl.tiDDocumentNumber and
                 tBankStateAllocColl.tiDDocumentYear   = tApiBankStateAllocColl.tiDDocumentYear      
                 no-error.
            if available tBankStateAllocColl
            then find tBankStateAllocColl WHERE                
                 tBankStateAllocColl.tc_ParentRowid        = tBankStateAlloc.tc_Rowid            and
                 tBankStateAllocColl.BankStateAllocColl_ID = tApiBankStateAllocColl.BankStateAllocColl_ID
                 no-error.
            if available tBankStateAllocColl
            then do:
                assign tBankStateAllocColl.tc_Status = '':U.
                buffer-compare tApiBankStateAllocColl except 
                    BankStateAlloc_ID 
                    BankStateAllocColl_ID 
                    tc_Rowid 
                    tc_ParentRowid 
                    tc_Status 
                    to tBankStateAllocColl save vlBufferCompareResult.
                if vlBufferCompareResult = true
                then next.
                assign tBankStateAllocColl.tc_Status = "C":U.
            end.
            else do:
                /* =============================================== */
                /* Create a new BankState-AllocColl and copy all data                   */
                /* =============================================== */
                <M-19 run AddDetailLine (input  'BankStateAllocColl':U (icTable), 
                         input  tBankStateAlloc.tc_Rowid (icParentRowid), 
                         output viFcReturnSuper (oiReturnStatus)) in BBankEntry>                        

                if viFcReturnSuper <> 0
                then do :
                    assign oiReturnStatus = viFcReturnSuper.
                    if oiReturnStatus < 0
                    then do:
                        assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
                               bcLstReturn   = bcLstReturn  + chr(4) + string(viFcReturnSuper)
                               bcLstPrimKey  = bcLstPrimKey + chr(4) + '*':U
                               bcLstRowid    = bcLstRowid   + chr(4) + '*':U.
                        return.
                    end.
                end. /* viFcReturnSuper <> 0 */
            end.
    
            buffer-copy tApiBankStateAllocColl except 
                BankStateAlloc_ID 
                BankStateAllocColl_ID 
                tc_Rowid 
                tc_ParentRowid 
                tc_Status 
                to tBankStateAllocColl.

            if tBankStateAllocColl.Company_ID = 0 or
               tBankStateAllocColl.Company_ID = ?
            then assign tBankStateAllocColl.Company_ID = tBankStateAlloc.Company_ID. 
        end.

        /* ======================================== */
        /* Go through all BankStateStageAlloc-lines */
        /* ======================================== */     
        for each tApiBankStateStageAlloc where 
                 tApiBankStateStageAlloc.tc_ParentRowid = tApiBankAlloc.tc_Rowid
                 by tApiBankStateStageAlloc.tc_Rowid :

            /* Next if the record already exists */
            find tBankStateStageAlloc WHERE                
                 tBankStateStageAlloc.tc_ParentRowid         = tBankStateAlloc.tc_Rowid            and
                 tBankStateStageAlloc.BankStateStageAlloc_ID = tApiBankStateStageAlloc.BankStateStageAlloc_ID
                 no-error.
            if available tBankStateStageAlloc
            then do:
                assign tBankStateStageAlloc.tc_Status = '':U.
                buffer-compare tApiBankStateStageAlloc except 
                    BankStateStageAlloc_ID
                    BankStateAlloc_ID
                    tc_Rowid 
                    tc_ParentRowid 
                    tc_Status 
                    to tBankStateStageAlloc save vlBufferCompareResult.
                if vlBufferCompareResult = true
                then next.
                assign tBankStateStageAlloc.tc_Status = "C":U.
            end.
            else do:
                /* =============================================== */
                /* Create a new BankState-AllocColl and copy all data                   */
                /* =============================================== */
                <M-22 run AddDetailLine
                   (input  'BankStateStageAlloc':U (icTable), 
                    input  tBankStateAlloc.tc_Rowid (icParentRowid), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>                        

                if viFcReturnSuper <> 0
                then do :
                    assign oiReturnStatus = viFcReturnSuper.
                    if oiReturnStatus < 0
                    then do:
                        assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
                               bcLstReturn   = bcLstReturn  + chr(4) + string(viFcReturnSuper)
                               bcLstPrimKey  = bcLstPrimKey + chr(4) + '*':U
                               bcLstRowid    = bcLstRowid   + chr(4) + '*':U.
                        return.
                    end.
                end. /* viFcReturnSuper <> 0 */
            end.
    
            buffer-copy tApiBankStateStageAlloc except 
                BankStateStageAlloc_ID
                BankStateAlloc_ID
                tc_Rowid 
                tc_ParentRowid 
                tc_Status 
                to tBankStateStageAlloc. 
        end.        

        /*Remove the no longer used BankStateStageAlloc*/
        for each tBankStateStageAlloc where
            tBankStateStageAlloc.tc_ParentRowid = tBankStateAlloc.tc_Rowid:

            find first tApiBankStateStageAlloc where
                 tApiBankStateStageAlloc.tc_ParentRowid    = tApiBankAlloc.tc_Rowid and
                 tApiBankStateStageAlloc.BankStateStageAlloc_ID = tBankStateStageAlloc.BankStateStageAlloc_ID
                no-error.
            if not available tApiBankStateStageAlloc
            then if tBankStateStageAlloc.tc_Status = 'N':U
            then delete tBankStateStageAlloc.
            else assign tBankStateStageAlloc.tc_Status = 'D':U.
        end.        
        
          
        /*Remove the no longer used BankStateAllocColl*/
        for each tBankStateAllocColl where
            tBankStateAllocColl.tc_ParentRowid = tBankStateAlloc.tc_Rowid:

            find first tApiBankStateAllocColl where
                 tApiBankStateAllocColl.tc_ParentRowid    = tApiBankAlloc.tc_Rowid and
                 tApiBankStateAllocColl.tcCDocumentType   = tBankStateAllocColl.tcCDocumentType   and
                 tApiBankStateAllocColl.tiCDocumentNumber = tBankStateAllocColl.tiCDocumentNumber and
                 tApiBankStateAllocColl.tiCDocumentYear   = tBankStateAllocColl.tiCDocumentYear   and
                 tApiBankStateAllocColl.tcDDocumentType   = tBankStateAllocColl.tcDDocumentType   and
                 tApiBankStateAllocColl.tiDDocumentNumber = tBankStateAllocColl.tiDDocumentNumber and
                 tApiBankStateAllocColl.tiDDocumentYear   = tBankStateAllocColl.tiDDocumentYear  
                no-error.
            if not available tApiBankStateAllocColl
            then find first tApiBankStateAllocColl where
                tApiBankStateAllocColl.tc_ParentRowid        = tApiBankAlloc.tc_Rowid and
                tApiBankStateAllocColl.BankStateAllocColl_ID = tBankStateAllocColl.BankStateAllocColl_ID
                no-error.
            if not available tApiBankStateAllocColl
            then if tBankStateAllocColl.tc_Status = 'N':U
            then delete tBankStateAllocColl.
            else assign tBankStateAllocColl.tc_Status = 'D':U.
        end.
    end.        
    /*Remove the no longer used BankStateAlloc*/
    for each tBankStateAlloc where
        tBankStateAlloc.tc_ParentRowid = tBankStateLine.tc_Rowid:

        find first tApiBankAlloc where
            tApiBankAlloc.tc_ParentRowid       = tApiBankStateLine.tc_Rowid        and
            tApiBankAlloc.tcDocNumberReference = tBankStateAlloc.tcDocNumberReference
            no-error.
        if not available tApiBankStateAllocColl
        then find first tApiBankStateAllocColl where
            tApiBankAlloc.tc_ParentRowid    = tApiBankStateLine.tc_Rowid and
            tApiBankAlloc.BankStateAlloc_ID = tBankStateAlloc.BankStateAlloc_ID
            no-error.
        if not available tApiBankAlloc
        then if tBankStateAlloc.tc_Status = 'N':U
        then delete tBankStateAlloc.
        else assign tBankStateAlloc.tc_Status = 'D':U.
    end.
end.