project QadFinancials > class BPosting > method AdditionalUpdatesFACapital

Description

AdditionalUpdatesBQBudgetActual; Extra method run in additional updates.
This will run an Api-method in BQBudgetActual to create the QBudgetLinkActual records that will be processed by the daemon to keep the actuals for budgets up-to-date..


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program5/bposting.p)

empty temp-table tFACapitalPosting.
assign vlStart1 = false.

for each tPosting where
        (tPosting.tc_Status       = "N":U  or
         tPosting.tc_Status       = "C":U) 
     /* Also the other layers are supported 
     and tPosting.tcLayerTypeCode = {&LAYERTYPECODE-OFFICIAL}
     */
     :
    /* Only create records for PostingLines with a FixedAsset GL. */
    if not can-find(first tPostingLine where
                          tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
                          tPostingLine.tc_Status     <> "D":U             and
                          tPostingLine.tcGLTypeCode   = {&GLTYPECODE-FASS})
    then next.

    /* Create FACapital records only when the Journal is on an Official Layer or */
    /* when changing to an Official Layer Journal.                               */
    if tPosting.tc_Status = "C":U
    then do:
        find t_iPosting where
             t_iPosting.tc_Rowid = tPosting.tc_Rowid
             no-error.

        if not available t_iPosting
        then do:
            assign vcMsgExplanation = <M-29 GetErrorExplanation
                                         (input  tPosting.tc_Rowid (icPostingRowId), 
                                          input  ? (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            <M-15 run SetMessage
               (input  trim(#T-14'Initial values cannot be found for posting $1 $2 $3.':250(16643)t-14#) (icMessage), 
                input  string(tPosting.PostingYear) + chr(2) + tPosting.tcJournalCode + chr(2) + string(tPosting.PostingVoucher) (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QADFIN-4149':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>

            assign oiReturnStatus = -1.
            return.
        end.

        if tPosting.tcLayerTypeCode = t_iPosting.tcLayerTypeCode
        then next.
    end.

    /* When disposing or revaluating an Asset or at yearly closing, */
    /* don't start creating new Capitalization records.             */
    if not vlStart1
    then do:
        <Q-16 run JournalByJournalIDCodeType  (Start) in BJournal >
        assign vlStart1 = true.
    end.

    <Q-12 run JournalByJournalIDCodeType (first) (Read) (Cache)
       (input tPosting.Company_ID, (CompanyId)
        input tPosting.Journal_ID, (JournalID)
        input ?, (JournalCode)
        input ?, (JournalTypeCode)
        output dataset tqJournalByJournalIDCodeType) in BJournal >

    find tqJournalByJournalIDCodeType where
         tqJournalByJournalIDCodeType.tiJournal_ID = tPosting.Journal_ID
         no-error.

    if not available tqJournalByJournalIDCodeType                                         or
       tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-DISPOSALFIXEDASSET} or
       tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-REVALFIXEDASSET}    or
       tqJournalByJournalIDCodeType.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
    then next.

    /* Updates for FixedAsset GLs only.                                                  */
    /* Also, only update for PostingLine that have a Debet balance or else new FACapital */
    /* records would get created when depreciating or disposing an existing asset.       */
    for each tPostingLine where
             tPostingLine.tc_ParentRowid = tPosting.tc_Rowid and
             tPostingLine.tc_Status     <> "D":U             and
             tPostingLine.tcGLTypeCode   = {&GLTYPECODE-FASS}:
        create tFACapitalPosting.

        assign viRowid                                = viRowid - 1
               tFACapitalPosting.Company_ID           = tPosting.Company_ID
               tFACapitalPosting.FACapitalAmountLC    = tPostingLine.PostingLineDebitLC - tPostingLine.PostingLineCreditLC
               tFACapitalPosting.FACapitalAmountTC    = tPostingLine.PostingLineDebitTC - tPostingLine.PostingLineCreditTC
               tFACapitalPosting.FACapitalDescription = tPosting.PostingBusinessRelationTxt + " ":U + tPostingLine.PostingLineText
               tFACapitalPosting.FACapitalPostingRef  = string(tPosting.PostingYear)   + "/":U +
                                                        string(tPosting.PostingPeriod) + "/":U +
                                                        tPosting.tcJournalCode         + "/":U +
                                                        string(tPosting.PostingVoucher)
               tFACapitalPosting.FACapitalStatus      = {&CAPITALIZATIONSTATUS-NOTCAPITALIZED}
               tFACapitalPosting.PostingLine_ID       = tPostingLine.PostingLine_ID
               tFACapitalPosting.tcCurrencyCode       = tPostingLine.tcCurrencyCode
               tFACapitalPosting.tcFAAssetCode        = "":U
               tFACapitalPosting.tcGLCode             = tPostingLine.tcGLCode
               tFACapitalPosting.tcJournalCode        = tPosting.tcJournalCode
               tFACapitalPosting.tcLocalCurrencyCode  = vcCompanyLC
               tFACapitalPosting.tiPeriodPeriod       = tPosting.PostingPeriod
               tFACapitalPosting.tiPeriodYear         = tPosting.PostingYear
               tFACapitalPosting.tiPostingVoucher     = tPosting.PostingVoucher
               tFACapitalPosting.tc_ParentRowid       = "":U
               tFACapitalPosting.tc_Rowid             = string(viRowid)
               tFACapitalPosting.tc_Status            = "N":U.
    end.
end.

if vlStart1
then do:
    <Q-17 run JournalByJournalIDCodeType  (Stop) in BJournal >
end.

if not can-find(first tFACapitalPosting)
then return.

if viBFACapitalPostingID = 0 or
   viBFACapitalPostingID = ?
then do:
    <I-18 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BFixedAssetCapital"}>
end.
else do:
    <I-19 {bFcOpenInstance
            &CLASS           = "BFixedAssetCapital"}>
end.

<M-20 run ApiCreateFACapital (input  tFACapitalPosting (tApiFACapital), 
                              input  {&DAEMONACTION-SAVE} (icAction), 
                              output vcLstPrimKey (ocLstPrimKey), 
                              output vcLstReturn (ocLstReturn), 
                              output vcLstRowId (ocLstRowid), 
                              output viReturn (oiReturnStatus)) in BFixedAssetCapital>

<I-23 {bFcCloseInstance
            &CLASS           = "BFixedAssetCapital"}>

if viReturn        < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viReturn.

if oiReturnStatus < 0
then return.