project QadFinancials > class BJournalEntry > method CreateReverseEntry

Description

CreateReverseEntry; this method can be called to mark a loaded instance as 'New' with the possibility to have another year/period/postingdate/journal then loaded one.


Parameters


icPostingTcRowidinputcharacterPostingTcRowid; rowid of the already loaded instance wherefor a new, reversing entry is required.
iiNewPeriodYearinputintegerNewPeriodYear; Year of the reverse entry
iiNewPeriodPeriodinputintegerNewPeriodPeriod; Period of the reverse entry
icNewJournalCodeinputcharacterNewJournalCode; JournalCode of the reverse entry
iiNewVoucherinputinteger
itNewPostingDateinputdateNewPostingDate; posting-date of the reverse posting
icNewPostingTextinputcharacterNewPostingText; posting-text of the reverse posting
oiNewPostingIDoutputintegerPosting_ID of the new, reversed posting
ilReverseBySigninputlogical
iiOriginVoucherinputinteger
ilIsValidateJournalTypeinputlogicalThis parameter is used, to identify, whether method is executed from User Interface by user or not. If this method is executed from UI, additional validations for type of journal is executed.
icReportingJournalCodeinputcharacter
iiBQCrossCyPostingIDinputintegerInstance of BQCrossCyPosting
ilCallFromDaemoninputlogical
oiNewPostingLineIDoutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ReverseCInvoicePosting
method BQCrossCyPosting.ApiProcessQCrossCyPostingForReverse


program code (program9/bjournalentry.p)

    
    /* =================================================== */
    /* Replace uhnknown values / validate input paramaters */
    /* =================================================== */
    if icPostingTcRowid       = ? then assign icPostingTcRowid       = "":U.
    if iiNewPeriodYear        = ? then assign iiNewPeriodYear        = 0.
    if iiNewPeriodPeriod      = ? then assign iiNewPeriodPeriod      = 0.
    if icNewJournalCode       = ? then assign icNewJournalCode       = "":U.
    if iiNewVoucher           = ? then assign iiNewVoucher           = 0.
    if icNewPostingText       = ? then assign icNewPostingText       = "":U.
    if icReportingJournalCode = ? then assign icReportingJournalCode = "":U.
    
    if iiBQCrossCyPostingID <> 0 and 
       iiBQCrossCyPostingID <> ? and
       ( viBQCrossCyPostingFromPostingID = 0 or
         viBQCrossCyPostingFromPostingID = ? )
    then assign viBQCrossCyPostingFromPostingID = iiBQCrossCyPostingID.         
    
    if icPostingTcRowid  = "":U or
       iiNewPeriodYear   = 0    or
       iiNewPeriodPeriod = 0    or 
       icNewJournalCode  = "":U
    then do :
        assign vcMsgJE        = trim(#T-10'You must enter the GL calendar year, GL period, daybook, and ID of the original journal entry in order to reverse it.':255(2737)T-10#) + chr(10) + 
                                trim(substitute(#T-11'Year: &1.':255(2738)T-11#,string(iiNewPeriodYear,"9999":U))) + chr(10) + 
                                trim(substitute(#T-12'GL period: &1.':255(2739)T-12#,string(iiNewPeriodPeriod,">>99":U))) + chr(10) + 
                                trim(substitute(#T-13'Daybook: &1.':255(2740)T-13#,string(icNewJournalCode,"9999":U))) + chr(10) + 
                                trim(substitute(#T-14'Row ID of the originating journal entry: &1.':255(2741)T-14#,icPostingTcRowid))
               oiReturnStatus = -1.
        <M-1 run SetMessage (input  vcMsgJE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  icPostingTcRowid (icRowid),
                     input  'QADFIN-883':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        Return.
    end. /* if icPostingTcRowid    = "":U or */
    find tPosting where 
         tPosting.tc_Rowid = icPostingTcRowid
         no-error.
    if not available tPosting
    then do :
        assign vcMsgJE        = trim(substitute(#T-15'Internal error: cannot find the originating journal entry based on its row ID &1.':255(2742)T-15#,icPostingTcRowid))
               oiReturnStatus = -1.
        <M-2 run SetMessage (input  vcMsgJE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'S':U (icType),
                     input  3 (iiSeverity),
                     input  icPostingTcRowid (icRowid),
                     input  'QADFIN-884':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        Return.
    end. /* if not available tPosting */
    assign viPostingId = tPosting.Posting_ID.

    <Q-3 run PeriodPrim (all) (Read) (NoCache)
          (input tPosting.Company_ID, (CompanyId)
           input ?, (PeriodId)
           input iiNewPeriodYear, (PeriodYear)
           input iiNewPeriodPeriod, (PeriodPeriod)
           output dataset tqPeriodPrim) in BPeriod >
    find first tqPeriodPrim no-lock no-error.
    if not available tqPeriodPrim
    then do :
        assign vcMsgJE        = trim(substitute(#T-16'The GL calendar year &1 and GL period &2 are invalid.':255(2743)T-16#,string(iiNewPeriodYear),string(iiNewPeriodPeriod)))
               oiReturnStatus = -1.
        <M-4 run SetMessage (input  vcMsgJE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  icPostingTcRowid (icRowid),
                     input  'QADFIN-885':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        Return.
    end. /* if not available tqPeriodPrim */
    
    /* ==================================================================================================== */
    /* Validate type of journal, which is reversed. Do this validation only from those tasks, controled     */
    /* by end user. If this is called from bussiness, he should be aware of all aspects of this operation   */
    /* ==================================================================================================== */
    if ilIsValidateJournalType = true
    then do:
         assign vcMsgJE = "":U.
         
         <Q-5 run JournalByJournalLayer (all) (Read) (NoCache)
           (input tPosting.Company_ID, (CompanyId)
            input icNewJournalCode, (JournalCode)
            input ?, (CandoJournalTypeCode)
            input ?, (LayerCode)
            input ?, (CandoLayerTypeCode)
            input ?, (JournalID)
            input ?, (JournalIsActive)
            output dataset tqJournalByJournalAndLayer) in BJournal >
        
        find first tqJournalByJournalAndLayer no-error.
        
        if not available tqJournalByJournalAndLayer
        then assign vcMsgJE = trim(substitute(#T-17'The daybook &1 is invalid.':255(2744)T-17#, icNewJournalCode)).
        else do:
            if tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-JOURNALENTRY} and
               tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-REVALCREDITORDOC} and
               tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-REVALCREDITOR} and
               tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-REVALDEBTORDOC} and
               tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-REVALDEBTOR} and
               tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-REVALGL}
             then assign vcMsgJE = trim(substitute(#T-18'The daybook must be of type &1.':255(2745)T-18#,{&JOURNALTYPE-JOURNALENTRY-TR}, {&JOURNALTYPE-REVALCREDITORDOC-TR}, {&JOURNALTYPE-REVALCREDITOR-TR}, {&JOURNALTYPE-REVALDEBTORDOC-TR}, {&JOURNALTYPE-REVALDEBTOR-TR})) + chr(10) + 
                                   trim(substitute(#T-19'Daybook: &1.':255(2740)T-19#, icNewJournalCode)) + chr(10) + 
                                   trim(substitute(#T-20'The daybook &1 is of type &2.':255(2746)T-20#, tqJournalByJournalAndLayer.tcJournalCode,tqJournalByJournalAndLayer.tcJournalTypeCode)).
        end.

        if vcMsgJE <> "":U
        then do :
            <M-22 run SetMessage
               (input  vcMsgJE (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  icPostingTcRowid (icRowid), 
                input  'QadFin-7922':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
            assign oiReturnStatus = -1.
            Return.
        end. /* if vcMsgJE <> "":U */
    end. /* if ilIsCalledFromUI = true */         

    /* ============================================================================ */
    /* Create new posting based on original one                                     */
    /* ============================================================================ */
    <M-28 run CopyPostingToNew
       (input  icPostingTcRowid (icPostingRowId), 
        output vcNewPostingRowId (ocNewPostingRowId), 
        input  false (ilLinkedCrCyDaemonReqExists), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper <  0 then return.

    /* ============================================================================ */
    /* Update values of new posting                                                 */
    /* ============================================================================ */
    find tPosting where
         tPosting.tc_Rowid = vcNewPostingRowId no-error.
    if not available tqPeriodPrim
    then do :
        assign vcMsgJE = substitute(#T-30'Cannot find newly created posting with RowId = &1.':255(69154)T-30#,vcNewPostingRowId).
        <M-29 run SetMessage
           (input  vcMsgJE (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  icPostingTcRowid (icRowid), 
            input  'QadFin-7923':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        assign oiReturnStatus = -1.
        return.
    end.

    assign tPosting.PostingOriginatorReference = substitute("&1/&2/&3":U, tPosting.PostingYear,
                                                                          tPosting.tcJournalCode,
                                                                          string(tPosting.PostingVoucher,"999999999":U))
           tPosting.PostingSystemDate          = today                                                                          
           tPosting.PostingYear                = iiNewPeriodYear
           tPosting.PostingPeriod              = iiNewPeriodPeriod
           tPosting.Period_ID                  = tqPeriodPrim.tiPeriod_ID                                      
           tPosting.PostingYearPeriod          = tqPeriodPrim.tiPeriodYear * 100 + tqPeriodPrim.tiPeriodPeriod 
           tPosting.tcJournalCode              = icNewJournalCode
           tPosting.tcReportingJournalCode     = icReportingJournalCode
           tPosting.PostingText                = icNewPostingText
           tPosting.PostingDate                = itNewPostingDate
           tPosting.PostingAddGLNbrDate        = itNewPostingDate
           tPosting.PostingVoucher             = 0 
           tPosting.PostingIsReversingBySign   = ilReverseBySign
           tPosting.PostingIsReversing         = true
           tPosting.PostingIsReplacement       = false           
           tPosting.tiOriginVoucher            = iiOriginVoucher
           oiNewPostingID                      = tPosting.Posting_ID.
 
    /* assign new posting voucher */
    if iiNewVoucher <> 0
    then assign tPosting.PostingVoucher = iiNewVoucher.
    else do:
        /* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
        /* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop      */
        if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
        then do :
            <I-53 {bFcStartAndOpenInstance
                 &ADD-TO-TRANSACTION   = "false"
                 &CLASS                = "BNumber"}>
        end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
        /* Get the new number */
        <M-9 run GetNumber
           (input  tPosting.Company_ID (iiCompanyId), 
            input  tPosting.PostingYear (iiNumbrYear), 
            input  tPosting.tcJournalCode (icNumbrType), 
            output tPosting.PostingVoucher (oiNumber), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viExternalReturnStatus (oiReturnStatus)) in BNumber>
        /* Close&Stop BNumber that is started with a different transaction before the previous loop   */
        if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
        then do :
            <I-95 {bFcCloseAndStopInstance
                 &CLASS           = "BNumber"}>
        end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */
        if viExternalReturnStatus <> 0 then assign oiReturnStatus = viExternalReturnStatus.
        if viExternalReturnStatus < 0 then return.
    end. /* Not if iiNewVoucher <> 0 */

    if not can-find (tCommitNumber where
                     tCommitNumber.tcNumberType   = {&COMMITNUMBERTYPE-POSTINGVOUCHER} and
                     tCommitNumber.tcPostingRowID = tPosting.tc_Rowid)
    then do :
        create tCommitNumber.
        assign tCommitNumber.tcNumberType   = {&COMMITNUMBERTYPE-POSTINGVOUCHER}
               tCommitNumber.tcPostingRowID = tPosting.tc_Rowid.             
    end.

    /* If Cross-Company Posting exists then create cross company daemon request to create reverse cross-company posting */
    if NOT ilCallFromDaemon 
    then do:
        for each tPostingLine where
                 tPostingLine.tc_ParentRowid = tPosting.tc_Rowid :

            /* Check if PostingLine is for Cross-company Account */   
            <Q-52 run GLById (all) (Read) (NoCache)
               (input tPosting.Company_ID, (CompanyId)
                input tPostingLine.GL_ID, (GLId)
                output dataset tqGLById) in BGL >  

            find first tqGLById where 
                       tqGLById.tiGL_ID = tPostingLine.GL_ID 
                       no-error.    
            if available tqGLById and tqGLById.tcGLTypeCode = {&GLTYPECODE-CROSS} 
            then do:
                if tPostingLine.CrossCompanyPostingLine_ID = 0 or tPostingLine.CrossCompanyPostingLine_ID = ?
                then do :
                    assign vcMsgJE = trim (#T-35'The Cross-Company information is not available yet, reversing the invoice is not possible. Please check the Cross-Company Daemon queue.':255(95096510)T-35#)
                           oiReturnStatus = -1.
                    <M-51 run SetMessage
                       (input  vcMsgJE (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  icPostingTcRowid (icRowid), 
                        input  'qadfin-124765':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                    return.
                end.
                else do:
                    /* Get the cross-Company PostingLine Detail*/ 
                    <Q-82 run PostingLineByPostingLineId (all) (Read) (NoCache)
                       (input ?, (CompanyId)
                        input tPostingLine.CrossCompanyPostingLine_ID, (PostingLineId)
                        input ?, (JournalTypeCode)
                        output dataset tqPostingLineByPostingLineId) in BPosting>

                    find first tqPostingLineByPostingLineId where 
                               tqPostingLineByPostingLineId.tiPostingLine_ID = tPostingLine.CrossCompanyPostingLine_ID 
                               no-error.                
    
                    if not available tqPostingLineByPostingLineId
                    then do :
                        assign vcMsgJE        = trim (substitute( #T-45'Internal error: the Cross-Company transaction line with ID = &1 was not found.':255(286884953)T-45#,tPostingLine.CrossCompanyPostingLine_ID))
                               vcContextText  = substitute("PostingLine_ID=&1|CrossCompanyPostingLine_ID=&2":U, tPostingLine.PostingLine_ID , tPostingLine.CrossCompanyPostingLine_ID )
                               vcContextText  = replace(vcContextText,"|":U,chr(2))
                               oiReturnStatus = -1.
                        <M-64 run SetMessage
                           (input  vcMsgJE (icMessage), 
                            input  '':U (icArguments), 
                            input  '':U (icFieldName), 
                            input  '':U (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  icPostingTcRowid (icRowid), 
                            input  'qadfin-300921':U (icFcMsgNumber), 
                            input  '' (icFcExplanation), 
                            input  '' (icFcIdentification), 
                            input  vcContextText (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
                        return.

                    end.
                    else do:
                        Create tQCrossCyPostingFromBPosting.
                        Assign tQCrossCyPostingFromBPosting.Company_ID                = tPostingLine.CrossCompany_ID
                               tQCrossCyPostingFromBPosting.CrossCompanyGL_ID         = if available tqPostingLineByPostingLineId then tqPostingLineByPostingLineId.tiGL_ID else 0
                               tQCrossCyPostingFromBPosting.CrossCompanyGLIsCredit    = tPosting.PostingIsReversingBySign
                               tQCrossCyPostingFromBPosting.Currency_ID               = tPostingLine.Currency_ID
                               tQCrossCyPostingFromBPosting.OriginatorCompany_ID      = tPostingLine.Company_ID
                               tQCrossCyPostingFromBPosting.OriginatorPosting_ID      = tPostingLine.Posting_ID
                               tQCrossCyPostingFromBPosting.OriginatorPostingLine_ID  = tPostingLine.PostingLine_ID
                               tQCrossCyPostingFromBPosting.QCrossCyPostingInfo       = trim(tqPostingLineByPostingLineId.tcCompanyCode) + "/":U + tPosting.PostingText
                               tQCrossCyPostingFromBPosting.QCrossCyPosting_ID        = tPostingLine.CrossCompanyPosting_ID
                               tQCrossCyPostingFromBPosting.QCrossCyPostingAmountTC   = if(tPostingLine.PostingLineCreditTC <> 0 and tPostingLine.PostingLineCreditTC <> ?) then - tPostingLine.PostingLineCreditTC else - tPostingLine.PostingLineDebitTC
                               tQCrossCyPostingFromBPosting.QCrossCyPostingCreateDate = today
                               tQCrossCyPostingFromBPosting.QCrossCyPostingCreateTime = Time
                               tQCrossCyPostingFromBPosting.tc_Rowid                  = string(- tPostingLine.PostingLine_ID)
                               tQCrossCyPostingFromBPosting.CInvoice_ID               = 0
                               tQCrossCyPostingFromBPosting.DInvoice_ID               = 0
                               tQCrossCyPostingFromBPosting.APMatchingGL_ID           = 0
                               tQCrossCyPostingFromBPosting.ComplPostingRevPosting_ID = tPostingLine.CrossCompanyPosting_ID
                               tQCrossCyPostingFromBPosting.APMatchingDivision_ID     = 0
                               tQCrossCyPostingFromBPosting.APMatchingCostCentre_ID   = 0
                               tQCrossCyPostingFromBPosting.APMatchingProject_ID      = 0.
                    end. /* else do: */

                end. /* tPostingLine.CrossCompanyPosting_ID <> 0 and tPostingLine.CrossCompanyPosting_ID <> ? */

            end.  /* if available tqGLById and tqGLById.tcGLTypeCode = {&GLTYPECODE-CROSS} */          

        end.  /* for each tPostingLine */    

    end. /* if NOT ilCallFromDaemon */

    /* Reverse amount of posting */
    if tPosting.PostingIsReversingBySign = true
    then do:        
        for each tPostingLine where
                 tPostingLine.tc_ParentRowid = tPosting.tc_Rowid:
            assign tPostingLine.Posting_ID          = tPosting.Posting_ID
                   tPostingLine.PostingLineCreditLC = - tPostingLine.PostingLineCreditLC
                   tPostingLine.PostingLineDebitLC  = - tPostingLine.PostingLineDebitLC
                   tPostingLine.PostingLineCreditTC = - tPostingLine.PostingLineCreditTC
                   tPostingLine.PostingLineDebitTC  = - tPostingLine.PostingLineDebitTC
                   tPostingLine.PostingLineCreditCC = - tPostingLine.PostingLineCreditCC
                   tPostingLine.PostingLineDebitCC  = - tPostingLine.PostingLineDebitCC.
                /* tPostingLine.PostingLineText     =   icNewPostingText.*/
            for each tPostingVat where 
                     tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid:
                assign tPostingVat.PostingLine_ID         = tPostingLine.PostingLine_ID
                       tPostingVat.Posting_ID             = tPostingLine.Posting_ID
                       tPostingVat.PostingVatBaseCreditLC = - tPostingVat.PostingVatBaseCreditLC
                       tPostingVat.PostingVatBaseDebitLC  = - tPostingVat.PostingVatBaseDebitLC
                       tPostingVat.PostingVatBaseCreditTC = - tPostingVat.PostingVatBaseCreditTC
                       tPostingVat.PostingVatBaseDebitTC  = - tPostingVat.PostingVatBaseDebitTC
                       tPostingVat.PostingVatBaseCreditCC = - tPostingVat.PostingVatBaseCreditCC
                       tPostingVat.PostingVatBaseDebitCC  = - tPostingVat.PostingVatBaseDebitCC
                       tPostingVat.PostingVatTaxDebitLC   = - tPostingVat.PostingVatTaxDebitLC
                       tPostingVat.PostingVatTaxCreditLC  = - tPostingVat.PostingVatTaxCreditLC
                       tPostingVat.PostingVatTaxDebitTC   = - tPostingVat.PostingVatTaxDebitTC
                       tPostingVat.PostingVatTaxCreditTC  = - tPostingVat.PostingVatTaxCreditTC
                       tPostingVat.PostingVatTaxDebitCC   = - tPostingVat.PostingVatTaxDebitCC
                       tPostingVat.PostingVatTaxCreditCC  = - tPostingVat.PostingVatTaxCreditCC
                       tPostingVat.PostingVatTaxPointDate = itNewPostingDate.
            end. /* for each tPostingVat where*/

            for each tPostingWHT where 
                     tPostingWHT.tc_ParentRowid = tPostingLine.tc_Rowid:
                assign tPostingWHT.PostingLine_ID         = tPostingLine.PostingLine_ID
                       tPostingWHT.Posting_ID             = tPostingLine.Posting_ID
                       tPostingWHT.PostingWHTBaseCreditLC = - tPostingWHT.PostingWHTBaseCreditLC
                       tPostingWHT.PostingWHTBaseDebitLC  = - tPostingWHT.PostingWHTBaseDebitLC
                       tPostingWHT.PostingWHTBaseCreditTC = - tPostingWHT.PostingWHTBaseCreditTC
                       tPostingWHT.PostingWHTBaseDebitTC  = - tPostingWHT.PostingWHTBaseDebitTC
                       tPostingWHT.PostingWHTBaseCreditCC = - tPostingWHT.PostingWHTBaseCreditCC
                       tPostingWHT.PostingWHTBaseDebitCC  = - tPostingWHT.PostingWHTBaseDebitCC
                       tPostingWHT.PostingWHTTaxDebitLC   = - tPostingWHT.PostingWHTTaxDebitLC
                       tPostingWHT.PostingWHTTaxCreditLC  = - tPostingWHT.PostingWHTTaxCreditLC
                       tPostingWHT.PostingWHTTaxDebitTC   = - tPostingWHT.PostingWHTTaxDebitTC
                       tPostingWHT.PostingWHTTaxCreditTC  = - tPostingWHT.PostingWHTTaxCreditTC
                       tPostingWHT.PostingWHTTaxDebitCC   = - tPostingWHT.PostingWHTTaxDebitCC
                       tPostingWHT.PostingWHTTaxCreditCC  = - tPostingWHT.PostingWHTTaxCreditCC
                       tPostingWHT.PostingWHTTaxPointDate = itNewPostingDate.
            end. /* for each tPostingWHT where*/

            for each tPostingSaf where
                     tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
                assign tPostingSaf.PostingLine_ID = tPostingLine.PostingLine_ID.
            end. /* for each tPostingSaf where */
        end. /* for each tPostingLine where */
    end. /* reverse by sign */
    else do:        
        for each tPostingLine where
                 tPostingLine.tc_ParentRowid = tPosting.tc_Rowid :
            assign tPostingLine.Posting_ID          = tPosting.Posting_ID
                   vdDummy                          = tPostingLine.PostingLineCreditLC
                   tPostingLine.PostingLineCreditLC = tPostingLine.PostingLineDebitLC
                   tPostingLine.PostingLineDebitLC  = vdDummy
                   vdDummy                          = tPostingLine.PostingLineCreditTC
                   tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineDebitTC 
                   tPostingLine.PostingLineDebitTC  = vdDummy
                   vdDummy                          = tPostingLine.PostingLineCreditCC
                   tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineDebitCC 
                   tPostingLine.PostingLineDebitCC  = vdDummy.
                /* tPostingLine.PostingLineText     =   icNewPostingText.*/
            for each tPostingVat where 
                     tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid :
                assign tPostingVat.PostingLine_ID         = tPostingLine.PostingLine_ID
                       tPostingVat.Posting_ID             = tPostingLine.Posting_ID
                       vdDummy                            = tPostingVat.PostingVatBaseCreditLC
                       tPostingVat.PostingVatBaseCreditLC = tPostingVat.PostingVatBaseDebitLC
                       tPostingVat.PostingVatBaseDebitLC  = vdDummy
                       vdDummy                            = tPostingVat.PostingVatBaseCreditTC
                       tPostingVat.PostingVatBaseCreditTC = tPostingVat.PostingVatBaseDebitTC
                       tPostingVat.PostingVatBaseDebitTC  = vdDummy
                       vdDummy                            = tPostingVat.PostingVatBaseCreditCC
                       tPostingVat.PostingVatBaseCreditCC = tPostingVat.PostingVatBaseDebitCC
                       tPostingVat.PostingVatBaseDebitCC  = vdDummy
                       vdDummy                            = tPostingVat.PostingVatTaxCreditLC
                       tPostingVat.PostingVatTaxCreditLC  = tPostingVat.PostingVatTaxDebitLC
                       tPostingVat.PostingVatTaxDebitLC   = vdDummy
                       vdDummy                            = tPostingVat.PostingVatTaxCreditTC
                       tPostingVat.PostingVatTaxCreditTC  = tPostingVat.PostingVatTaxDebitTC
                       tPostingVat.PostingVatTaxDebitTC   = vdDummy
                       vdDummy                            = tPostingVat.PostingVatTaxCreditCC
                       tPostingVat.PostingVatTaxCreditCC  = tPostingVat.PostingVatTaxDebitCC
                       tPostingVat.PostingVatTaxDebitCC   = vdDummy
                       tPostingVat.PostingVatTaxPointDate = itNewPostingDate.
            end. /* for each tPostingVat where*/

            for each tPostingWHT where 
                     tPostingWHT.tc_ParentRowid = tPostingLine.tc_Rowid :
                assign tPostingWHT.PostingLine_ID         = tPostingLine.PostingLine_ID
                       tPostingWHT.Posting_ID             = tPostingLine.Posting_ID
                       vdDummy                            = tPostingWHT.PostingWHTBaseCreditLC
                       tPostingWHT.PostingWHTBaseCreditLC = tPostingWHT.PostingWHTBaseDebitLC
                       tPostingWHT.PostingWHTBaseDebitLC  = vdDummy
                       vdDummy                            = tPostingWHT.PostingWHTBaseCreditTC
                       tPostingWHT.PostingWHTBaseCreditTC = tPostingWHT.PostingWHTBaseDebitTC
                       tPostingWHT.PostingWHTBaseDebitTC  = vdDummy
                       vdDummy                            = tPostingWHT.PostingWHTBaseCreditCC
                       tPostingWHT.PostingWHTBaseCreditCC = tPostingWHT.PostingWHTBaseDebitCC
                       tPostingWHT.PostingWHTBaseDebitCC  = vdDummy
                       vdDummy                            = tPostingWHT.PostingWHTTaxCreditLC
                       tPostingWHT.PostingWHTTaxCreditLC  = tPostingWHT.PostingWHTTaxDebitLC
                       tPostingWHT.PostingWHTTaxDebitLC   = vdDummy
                       vdDummy                            = tPostingWHT.PostingWHTTaxCreditTC
                       tPostingWHT.PostingWHTTaxCreditTC  = tPostingWHT.PostingWHTTaxDebitTC
                       tPostingWHT.PostingWHTTaxDebitTC   = vdDummy
                       vdDummy                            = tPostingWHT.PostingWHTTaxCreditCC
                       tPostingWHT.PostingWHTTaxCreditCC  = tPostingWHT.PostingWHTTaxDebitCC
                       tPostingWHT.PostingWHTTaxDebitCC   = vdDummy
                       tPostingWHT.PostingWHTTaxPointDate = itNewPostingDate.
            end. /* for each tPostingWHT where*/

            for each tPostingSaf where
                     tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
                assign tPostingSaf.PostingLine_ID = tPostingLine.PostingLine_ID.
            end. /* for each tPostingSaf where */
        end. /* for each tPostingLine where */ 
    end. /* change CR/DR side */
                      
    /* ================================================== */
    /* Turn New-OI-Allocations into Linked-OI-Allocations */
    /* ================================================== */
    for each tPostingLine where
             tPostingLine.tc_ParentRowid   = tPosting.tc_Rowid and 
             tPostingLine.tcAllocationType = "N":U :
        assign tPostingLine.tcAllocationType = "L":U.
    end. /* for each tPostingLine where */

    /* get the postingline_id for the cross-company Account */
    for each tPostingLine where
             tPostingLine.tc_ParentRowid = tPosting.tc_Rowid :
        <Q-90 run GLById (all) (Read) (NoCache)
           (input tPosting.Company_ID, (CompanyId)
            input tPostingLine.GL_ID, (GLId)
            output dataset tqGLById) in BGL >     
        find first tqGLById where 
            tqGLById.tiGL_ID = tPostingLine.GL_ID no-error.    
        if available tqGLById and 
            tqGLById.tcGLTypeCode = {&GLTYPECODE-CROSS} 
        then do:
            assign oiNewPostingLineID = tPostingLine.PostingLine_ID.

            /* Reset Cross-company IDs after reversing entries and daemon queues are created */
            if ilCallFromDaemon = false
            then assign tPostingLine.CrossCompany_ID            = 0
                        tPostingLine.CrossCompanyPosting_ID     = 0
                        tPostingLine.CrossCompanyPostingLine_ID = 0.
        end.
    end. 

    /* ================================================== */
    /* Remove original (reversed) posting from instance   */
    /* ================================================== */
    <M-32 run RemovePostingFromInstance
       (input  viPostingId (iiPostingID), 
        output oiReturnStatus (oiReturnStatus)) in BJournalEntry>
    if oiReturnStatus < 0 then return.