project QadFinancials > class BPosting > method ValidateComponentReversingPostingCreate


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentReversingPosting


program code (program4/bposting.p)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
/* Creating the reversing entry for the original entry     */
/* Only create the reversing entry as a duplicate of the   */
/* original entry                                          */  
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Exception Handling */
assign oiReturnStatus = -98
       viLocalReturnStatus = 0.

<Q-54 run PeriodByStartEndDate  (Start) in BPeriod >

POSTINGBLOCK: DO:
    For each btsPosting where 
             btsPosting.PostingIsAutoReversal   = true and 
             btsPosting.PostingAutoReversalType = {&POSTINGAUTOREVERSALTYPE-ORIGINAL} and
             btsPosting.tc_status               = "N":U:

        /* Create the posting for the reversing entry */
        <M-1 run AddDetailLine
           (input  'Posting':U (icTable), 
            input  '':U (icParentRowid), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0 
        then do:
            assign vcMsgExplanation = <M-66 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  ? (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                          
           assign viLocalReturnStatus = viFcReturnSuper. 
           <M-56 run SetMessage
              (input  #T-58'Unable to add detail line to Posting table':100(999890294)T-58# (icMessage), 
               input  '':U (icArguments), 
               input  '':U (icFieldName), 
               input  '':U (icFieldValue), 
               input  'E':U (icType), 
               input  3 (iiSeverity), 
               input  t_sPosting.tc_Rowid (icRowid), 
               input  'QadFin-8992':U (icFcMsgNumber), 
               input  vcMsgExplanation (icFcExplanation), 
               input  '':U (icFcIdentification), 
               input  '':U (icFcContext), 
               output viFcReturnSuper (oiReturnStatus)) in BPosting>
            LEAVE POSTINGBLOCK.
        end. /* if viFcReturnSuper < 0 */   
        create t_sPosting.
        buffer-copy tPosting to t_sPosting.                
        buffer-copy btsPosting except tlSaveAsTemplate tcTemplateCode tc_rowid tc_parentrowid Posting_ID to t_sPosting.
        
        /* set the date on the revering entry according to the reversal posting date on the original entry */
        <Q-2 run PeriodByStartEndDate (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input btsPosting.PostingAutoReversalDate, (Date)
            output dataset tqPeriodByStartEndDate) in BPeriod >
    
        find first tqPeriodByStartEndDate no-error.
        if available tqPeriodByStartEndDate 
        then do:            
           assign t_sPosting.PostingYear             = tqPeriodByStartEndDate.tiPeriodYear
                  t_sPosting.PostingPeriod           = tqPeriodByStartEndDate.tiPeriodPeriod
                  t_sPosting.PostingYearPeriod       = tqPeriodByStartEndDate.tiPeriodYearPeriod
                  t_sPosting.Period_ID               = tqPeriodByStartEndDate.tiPeriod_ID
                  t_sPosting.PeriodMark_ID           = tqPeriodByStartEndDate.tiPeriodMark_ID
                  t_sPosting.tcPeriodTypeCode        = tqPeriodByStartEndDate.tcPeriodTypeCode.                  
        end.
                
        assign t_sPosting.AutoReversalPosting_ID     = btsPosting.Posting_ID
               t_sPosting.PostingDate                = btsPosting.PostingAutoReversalDate
               t_sPosting.PostingAutoReversalType    = {&POSTINGAUTOREVERSALTYPE-REVERSING}
               t_sPosting.PostingIsAutoReversal      = true
               t_sPosting.PostingOriginatorReference = trim(STRING(btsPosting.PostingYear) + "/" +
                                                            STRING(btsPosting.tcJournalCode) + "/" +
                                                            STRING(btsPosting.PostingVoucher, "999999999":U))
               t_sPosting.PostingAddGLNbrDate        = t_sPosting.PostingAddGLNbrRevDate
               tPosting.PostingAutoReversalType      = {&POSTINGAUTOREVERSALTYPE-REVERSING}
               tPosting.PostingIsAutoReversal        = true
               tPosting.AutoReversalPosting_ID       = btsPosting.Posting_ID.

        assign btsPosting.AutoReversalPosting_ID     = t_sPosting.Posting_ID. 
       
        <M-3 run GetPostingNumber
           (input  t_sPosting.tc_Rowid (ictcRowid), 
            input  t_sPosting.PostingYear (iiYear), 
            input  t_sPosting.tcJournalCode (icJournalCode), 
            output t_sPosting.PostingVoucher (oiVoucher), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0 
        then do:
           assign vcMsgExplanation = <M-89 GetErrorExplanation
                                        (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                         input  ? (icPostingLineRowId), 
                                         output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
           assign viLocalReturnStatus = viFcReturnSuper. 
           <M-4 run SetMessage
              (input  #T-7'Posting integration: an error occurred while retrieving a new number for the posting.':100(71377)T-7# (icMessage), 
               input  '':U (icArguments), 
               input  't_sPosting.PostingVoucher':U (icFieldName), 
               input  STRING(t_sPosting.PostingYear) + '/' + t_sPosting.tcJournalCode + '/' + STRING(t_sPosting.PostingVoucher) (icFieldValue), 
               input  'E':U (icType), 
               input  3 (iiSeverity), 
               input  t_sPosting.tc_Rowid (icRowid), 
               input  'QadFin-8808':U (icFcMsgNumber), 
               input  vcMsgExplanation (icFcExplanation), 
               input  '':U (icFcIdentification), 
               input  '':U (icFcContext), 
               output viFcReturnSuper (oiReturnStatus)) in BPosting>
            LEAVE POSTINGBLOCK.
        end. /* if viFcReturnSuper < 0 */
        
        /* Create the postinglines for the reversing entry */
        for each btsPostingLine where 
                 btsPostingLine.tc_parentrowid = btsPosting.tc_rowid :
            <M-5 run AddDetailLine
               (input  'PostingLine':U (icTable), 
                input  t_sPosting.tc_Rowid (icParentRowid), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if viFcReturnSuper <> 0 
            then do:
               assign vcMsgExplanation = <M-98 GetErrorExplanation
                                            (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                             input  ? (icPostingLineRowId), 
                                             output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
               assign viLocalReturnStatus = viFcReturnSuper. 
               <M-59 run SetMessage
                  (input  #T-61'Unable to add detail line to PostingLine table':100(999890295)T-61# (icMessage), 
                   input  '':U (icArguments), 
                   input  '':U (icFieldName), 
                   input  '':U (icFieldValue), 
                   input  'E':U (icType), 
                   input  3 (iiSeverity), 
                   input  t_sPosting.tc_Rowid (icRowid), 
                   input  'QadFin-8993':U (icFcMsgNumber), 
                   input  vcMsgExplanation (icFcExplanation), 
                   input  '':U (icFcIdentification), 
                   input  '':U (icFcContext), 
                   output viFcReturnSuper (oiReturnStatus)) in BPosting>
                LEAVE POSTINGBLOCK.
            end. /* if viFcReturnSuper < 0 */    
                
            create t_sPostingLine.
            buffer-copy tPostingLine to t_sPostingLine.                
            buffer-copy btsPostingLine except tc_rowid tc_parentrowid postingline_id to t_sPostingLine.
    
            if btsPosting.PostingIsCorrection
            then assign t_sPostingLine.PostingLineCreditTC = btsPostingLine.PostingLineCreditTC * -1
                        t_sPostingLine.PostingLineDebitTC  = btsPostingLine.PostingLineDebitTC * -1
                        t_sPostingLine.PostingLineCreditLC = btsPostingLine.PostingLineCreditLC * -1
                        t_sPostingLine.PostingLineDebitLC  = btsPostingLine.PostingLineDebitLC * -1
                        t_sPostingLine.PostingLineCreditCC = btsPostingLine.PostingLineCreditCC * -1
                        t_sPostingLine.PostingLineDebitCC  = btsPostingLine.PostingLineDebitCC * -1.
            
            else assign t_sPostingLine.PostingLineCreditTC = btsPostingLine.PostingLineDebitTC
                        t_sPostingLine.PostingLineDebitTC  = btsPostingLine.PostingLineCreditTC
                        t_sPostingLine.PostingLineCreditLC = btsPostingLine.PostingLineDebitLC
                        t_sPostingLine.PostingLineDebitLC  = btsPostingLine.PostingLineCreditLC
                        t_sPostingLine.PostingLineCreditCC = btsPostingLine.PostingLineDebitCC
                        t_sPostingLine.PostingLineDebitCC  = btsPostingLine.PostingLineCreditCC.
           if t_sPostingLine.tcAllocationType = {&ALLOCATIONTYPE-NEW} and
              (t_sPostingLine.tcAllocationKey = ? or
               t_sPostingLine.tcAllocationKey = "":U )
               then assign t_sPostingLine.tcAllocationKey = trim(string(btsPosting.PostingYear))    + "/":U +
                                                            trim(string(btsPosting.PostingPeriod))  + "/":U +
                                                            trim(btsPosting.tcJournalCode)          + "/":U +
                                                            trim(string(btsPosting.PostingVoucher)) + "/":U +
                                                            trim(string(btsPostingLine.PostingLineSequence)).            
            
            for each btsPostingVat where 
                     btsPostingVat.tc_parentrowid = btsPostingLine.tc_rowid:
                <M-6 run AddDetailLine
                   (input  'PostingVat':U (icTable), 
                    input  t_sPostingLine.tc_Rowid (icParentRowid), 
                    output viLocalReturnStatus (oiReturnStatus)) in BPosting>
                if viFcReturnSuper <> 0 
                then do:
                   assign vcMsgExplanation = <M-71 GetErrorExplanation
                                                (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                 input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                                 output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
                   assign viLocalReturnStatus = viFcReturnSuper. 
                   <M-63 run SetMessage
                      (input  #T-62'Unable to add detail line to PostingVat table':100(999890296)T-62# (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  t_sPosting.tc_Rowid (icRowid), 
                       input  'QadFin-8994':U (icFcMsgNumber), 
                       input  vcMsgExplanation (icFcExplanation), 
                       input  '':U (icFcIdentification), 
                       input  '':U (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    LEAVE POSTINGBLOCK.
                end. /* if viFcReturnSuper < 0 */                
        
                create t_sPostingVat.
                buffer-copy tPostingVat to t_sPostingVat.                
                buffer-copy btsPostingVat except tc_rowid tc_parentrowid postingline_id postingvat_ID to t_sPostingVat.
                if btsPosting.PostingIsCorrection
                then assign t_sPostingVat.PostingVatTaxCreditTC  = btsPostingVat.PostingVatTaxCreditTC * -1
                            t_sPostingVat.PostingVatTaxDebitTC   = btsPostingVat.PostingVatTaxDebitTC * -1
                            t_sPostingVat.PostingVatTaxCreditCC  = btsPostingVat.PostingVatTaxCreditCC * -1
                            t_sPostingVat.PostingVatTaxDebitCC   = btsPostingVat.PostingVatTaxDebitCC * -1
                            t_sPostingVat.PostingVatTaxCreditLC  = btsPostingVat.PostingVatTaxCreditLC * -1
                            t_sPostingVat.PostingVatTaxDebitLC   = btsPostingVat.PostingVatTaxDebitLC * -1
                            t_sPostingVat.PostingVatBaseCreditTC = btsPostingVat.PostingVatBaseCreditTC * -1
                            t_sPostingVat.PostingVatBaseDebitTC  = btsPostingVat.PostingVatBaseDebitTC * -1
                            t_sPostingVat.PostingVatBaseCreditCC = btsPostingVat.PostingVatBaseCreditCC * -1
                            t_sPostingVat.PostingVatBaseDebitCC  = btsPostingVat.PostingVatBaseDebitCC * -1
                            t_sPostingVat.PostingVatBaseCreditLC = btsPostingVat.PostingVatBaseCreditLC * -1
                            t_sPostingVat.PostingVatBaseDebitLC  = btsPostingVat.PostingVatBaseDebitLC * -1.
                else assign t_sPostingVat.PostingVatTaxCreditTC  = btsPostingVat.PostingVatTaxDebitTC
                            t_sPostingVat.PostingVatTaxDebitTC   = btsPostingVat.PostingVatTaxCreditTC
                            t_sPostingVat.PostingVatTaxCreditCC  = btsPostingVat.PostingVatTaxDebitCC
                            t_sPostingVat.PostingVatTaxDebitCC   = btsPostingVat.PostingVatTaxCreditCC                        
                            t_sPostingVat.PostingVatTaxCreditLC  = btsPostingVat.PostingVatTaxDebitLC
                            t_sPostingVat.PostingVatTaxDebitLC   = btsPostingVat.PostingVatTaxCreditLC
                            t_sPostingVat.PostingVatBaseCreditTC = btsPostingVat.PostingVatBaseDebitTC                        
                            t_sPostingVat.PostingVatBaseDebitTC  = btsPostingVat.PostingVatBaseCreditTC
                            t_sPostingVat.PostingVatBaseCreditCC = btsPostingVat.PostingVatBaseDebitCC
                            t_sPostingVat.PostingVatBaseDebitCC  = btsPostingVat.PostingVatBaseCreditCC
                            t_sPostingVat.PostingVatBaseCreditLC = btsPostingVat.PostingVatBaseDebitLC
                            t_sPostingVat.PostingVatBaseDebitLC  = btsPostingVat.PostingVatBaseCreditLC.
            end. /* for each btsPostingVat where  */
            
            for each btsPostingSaf where 
                     btsPostingSaf.tc_parentrowid = btsPostingLine.tc_rowid:
                <M-9 run AddDetailLine
                   (input  'PostingSaf':U (icTable), 
                    input  t_sPostingLine.tc_Rowid (icParentRowid), 
                    output viLocalReturnStatus (oiReturnStatus)) in BPosting>
                if viFcReturnSuper <> 0 
                then do:
                   assign vcMsgExplanation = <M-57 GetErrorExplanation
                                                (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                 input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                                 output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
                   assign viLocalReturnStatus = viFcReturnSuper. 
                   <M-65 run SetMessage
                      (input  #T-67'Unable to add detail line to PostingSaf table':100(999890297)T-67# (icMessage), 
                       input  '':U (icArguments), 
                       input  '':U (icFieldName), 
                       input  '':U (icFieldValue), 
                       input  'E':U (icType), 
                       input  3 (iiSeverity), 
                       input  t_sPosting.tc_Rowid (icRowid), 
                       input  'QadFin-8995':U (icFcMsgNumber), 
                       input  vcMsgExplanation (icFcExplanation), 
                       input  '':U (icFcIdentification), 
                       input  '':U (icFcContext), 
                       output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    LEAVE POSTINGBLOCK.
                end. /* if viFcReturnSuper < 0 */                
        
                create t_sPostingSaf.
                buffer-copy tPostingSaf to t_sPostingSaf.                
                buffer-copy btsPostingSaf except tc_rowid tc_parentrowid postingline_id postingsaf_ID to t_sPostingSaf.
            end. /* for each btsPostingSaf where  */
        end. /* for each btsPostingLine where  */
    end. /* For each btsPosting where */

END. /* POSTINGBLOCK */

<Q-55 run PeriodByStartEndDate  (Stop) in BPeriod >

/* Exception Handling */
assign oiReturnStatus = viLocalReturnStatus.