project QadFinancials > class BDDocument > method AdditionalUpdatesDCollection


Parameters


blStart6input-outputlogical
blStart9input-outputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDDocument.AdditionalUpdatesPosting


program code (program5/bddocument.p)

/* If the document received status INCASSO or DISCONTO */
if (tDDocument.DDocumentStatus    = {&DOCUMENTSTATUS-INCASSO}  or
    tDDocument.DDocumentStatus    = {&DOCUMENTSTATUS-DISCONT}) and
   (tDDocument.tc_Status          = "N":U                      or
    t_iDDocument.DDocumentStatus <> tDDocument.DDocumentStatus and
    t_iDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-INCASSO}  and
    t_iDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-DISCONT})
then do:
    /* Get Currency of Bank Account */
    <M-1 run AdditionalUpdatesGetBankGLInfo
       (input  false (ilErrorIfNoDiscountAccount), 
        input  true (ilErrorIfNoCurrency), 
        output vcDiscountGLAccount (ocDiscountGLAccount), 
        output vcIntBankGLAccount (ocInterestGLAccount), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>

    /* Fill Document Amount in Bank Currency */
    if tBankGLInfoDDoc.tcCurrencyCode = tDDocument.tcCurrencyCode
    then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitTC.
    else
    if tBankGLInfoDDoc.tcCurrencyCode = vcCompanyLC
    then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitLC.
    else
    if tBankGLInfoDDoc.tcCurrencyCode = vcCompanyCC
    then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitCC.
    else do:
        <M-91 run GetExchangeRate
           (input  ? (iiCompanyID), 
            input  ? (iiFromCurrencyID), 
            input  tBankGLInfoDDoc.tcCurrencyCode (icFromCurrencyCode), 
            input  viCompanyLCId (iiToCurrencyID), 
            input  ? (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
            input  tDDocument.ttPostingDate (itValidityDate), 
            output vdBCRate (odExchangeRate), 
            output vdBCRateScale (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>
        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        assign tDDocument.DDocumentOriginalDebitBC = <M-7 RoundAmount
          (input  tDDocument.DDocumentOriginalDebitLC / (vdBCRate * vdBCRateScale) (idUnroundedAmount), 
           input  '':U (iiCurrencyID), 
           input  tBankGLInfoDDoc.tcCurrencyCode (icCurrencyCode)) in business>.
            /* round(tDDocument.DDocumentOriginalDebitLC / (vdBCRate * vdBCRateScale),int(entry(lookup(tBankGLInfoDDoc.tcCurrencyCode, vcCurrencyDecimalsList) + 1, vcCurrencyDecimalsList))). */
    end.

    /* Add Document to Collection */
    find tDCollectionDDoc where
         tDCollectionDDoc.DCollection_ID = 0                                                               and
         tDCollectionDDoc.tcReference    = tDDocument.DDocumentType + chr(2) + tDDocument.DDocumentSubType and
         tDCollectionDDoc.tcGLCode       = tDDocument.tcGLCode
         no-error.

    if not available tDCollectionDDoc
    then do:
        create tDCollectionDDoc.

        assign viRowIdDDoc                                = viRowIdDDoc - 1
               tDCollectionDDoc.DPaySel_ID                = tDDocument.DPaySel_ID
               tDCollectionDDoc.DCollectionBankFileFormat = tDDocument.tcPayFormatTypeCode
               tDCollectionDDoc.DCollectionIsAutomatic    = false
               tDCollectionDDoc.DCollectionIsExecuted     = false
               tDCollectionDDoc.DCollectionName           = <M-3 GetDDocumentTypeTranslation (input  tDDocument.DDocumentType (icType)) in BDDocument> + " ":U +
                                                            <M-4 GetDDocumentSubTypeTranslation (input  tDDocument.DDocumentSubType (icSubType)) in BDDocument>
               tDCollectionDDoc.DCollectionRequestedDate  = tDDocument.DDocumentDueDate
               tDCollectionDDoc.DCollectionYear           = year(tDCollectionDDoc.DCollectionRequestedDate)
               tDCollectionDDoc.DCollection_ID            = 0
               tDCollectionDDoc.Company_ID                = tDDocument.Company_ID
               tDCollectionDDoc.GL_ID                     = tDDocument.GL_ID
               tDCollectionDDoc.tcGLCode                  = tDDocument.tcGLCode
               tDCollectionDDoc.tcReference               = tDDocument.DDocumentType + chr(2) + tDDocument.DDocumentSubType
               tDCollectionDDoc.tc_Rowid                  = string(viRowIdDDoc).
    end.

    assign tDCollectionDDoc.DCollectionBalanceDebitTC  = tDCollectionDDoc.DCollectionBalanceDebitTC + tDDocument.DDocumentOriginalDebitBC
           tDCollectionDDoc.DCollectionBalanceDebitLC  = tDCollectionDDoc.DCollectionBalanceDebitLC + tDDocument.DDocumentOriginalDebitLC
           tDCollectionDDoc.DCollectionBalanceDebitCC  = tDCollectionDDoc.DCollectionBalanceDebitCC + tDDocument.DDocumentOriginalDebitCC
           tDCollectionDDoc.DCollectionOrigDebitTC = tDCollectionDDoc.DCollectionOrigDebitTC + tDDocument.DDocumentOriginalDebitBC
           tDCollectionDDoc.DCollectionOrigDebitLC = tDCollectionDDoc.DCollectionOrigDebitLC + tDDocument.DDocumentOriginalDebitLC
           tDCollectionDDoc.DCollectionOrigDebitCC = tDCollectionDDoc.DCollectionOrigDebitCC + tDDocument.DDocumentOriginalDebitCC.

    if tDDocument.DDocumentIncassoSelectCode <> "":U and
       tDDocument.DDocumentIncassoSelectCode <> ?    and
       not can-do(tDCollectionDDoc.DCollectionIncSelCodeList, tDDocument.DDocumentIncassoSelectCode)
    then do:
        if tDCollectionDDoc.DCollectionIncSelCodeList <> "":U
        then assign tDCollectionDDoc.DCollectionIncSelCodeList = tDCollectionDDoc.DCollectionIncSelCodeList + ",":U.

        assign tDCollectionDDoc.DCollectionIncSelCodeList = tDCollectionDDoc.DCollectionIncSelCodeList + tDDocument.DDocumentIncassoSelectCode.
    end.

    if not tDCollectionDDoc.DCollectionIsAutomatic
    then assign tDCollectionDDoc.DCollectionIsAutomatic = tDDocument.DDocumentType = {&PAYFORMATPAYINSTRUMENT-DIRECTDEBIT}.
end.
else

/* If the document had status INCASSO or DISCONTO */
if tDDocument.tc_Status         = "C":U                        and
  (t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INCASSO}    or
   t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-DISCONT})   and
   tDDocument.DDocumentStatus  <> t_iDDocument.DDocumentStatus and
   tDDocument.DDocumentStatus  <> {&DOCUMENTSTATUS-INCASSO}    and
   tDDocument.DDocumentStatus  <> {&DOCUMENTSTATUS-DISCONT}
then do:
    /* Adjust DCollection Balance */
    find tDCollectionDDoc where
         tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID
         no-error.

    if not available tDCollectionDDoc
    then do:
        create tDCollectionDDoc.

        assign viRowIdDDoc                     = viRowIdDDoc - 1
               tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID
               tDCollectionDDoc.tc_Rowid       = string(viRowIdDDoc).
    end.

    assign tDCollectionDDoc.DCollectionBalanceDebitTC  = tDCollectionDDoc.DCollectionBalanceDebitTC - tDDocument.DDocumentOriginalDebitBC
           tDCollectionDDoc.DCollectionBalanceDebitLC  = tDCollectionDDoc.DCollectionBalanceDebitLC - tDDocument.DDocumentOriginalDebitLC
           tDCollectionDDoc.DCollectionBalanceDebitCC  = tDCollectionDDoc.DCollectionBalanceDebitCC - tDDocument.DDocumentOriginalDebitCC.

    /* Remove the document from the collection if status isn't PAID, PAIDCON or BOUNCED */
    if tDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-PAID}    and
       tDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-PAIDCON} and
       tDDocument.DDocumentStatus <> {&DOCUMENTSTATUS-BOUNCED}
    then do:
        assign tDDocument.DCollection_ID = 0.

        /* If the collection contains no more documents, 'remove' it (set balances to zero) */
        if not can-find(first bDDocument where
                              bDDocument.DCollection_ID = tDCollectionDDoc.DCollection_ID and
                              bDDocument.tc_Rowid      <> tDDocument.tc_Rowid             and
                              bDDocument.tc_Status     <> "D":U)
        then do:
            <Q-6 assign vlFcQueryRecordsAvailable = DDocumentByCollectionID (NoCache)
          (input ?, (CompanyId)
           input tDCollectionDDoc.DCollection_ID, (DCollectionID)
           input ?, (DDocumentID)
           input ?, (DDocumentStatus)) in BDDocument >

            if not vlFcQueryRecordsAvailable
            then assign tDCollectionDDoc.tc_Status = "D":U.
        end.
    end.
end.