project QadFinancials > class BPosting > method ValidateComponentReversingPostingModifyReversing


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentReversingPosting


program code (program4/bposting.p)

/* ====================================================================================== *
 * Modify reverse journal entry - counterpart posting if this is in transient layer       *
 *                                                                                        *
 * In case user does change of the "auto-reversal posting"                                *
 * - posting modification is disabled except following fields:                            *
 *   Year, Period, Posting Date, Daybook and Description                                  *
 * - validate for "Daybook layer" remains there (so the Daybook layer of the original and *
 *    reversal postings have to the the same).                                            *
 * - no any date are synchronized to "original" posting. Unless Posting date is changed,  *
 *   then this values is stored in the "Original posting" in field "Auto reversal posting *
 *    date".                                                                              *
 * ====================================================================================== */


/* Modifying the reversing entry */
for each btsPosting where
         btsPosting.PostingIsAutoReversal   = true                                 and 
         btsPosting.PostingAutoReversalType = {&POSTINGAUTOREVERSALTYPE-REVERSING} and
         btsPosting.AutoReversalPosting_ID <> 0                                    and
         btsPosting.AutoReversalPosting_ID <> ?                                    and
         btsPosting.tc_status               = "C":U:

    /* DO NOT PROCEED IF THE METHOD IS CALLED DURING APPROVE/VERIFY ACTIVITY */     
    find first t_iPosting where 
               t_iPosting.Posting_ID = btsPosting.Posting_ID no-error.

    if not available t_iPosting
    then do:
        assign vcMsgExplanation = <M-51 GetErrorExplanation
                                     (input  btsPosting.tc_Rowid (icPostingRowId), 
                                      input  ? (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        assign vcMessage = #T-24'Cannot read expected data.':255(178762645)T-24#
               vcContent = "System cannot read Original version of Posting data" + chr(10) + vcMsgExplanation.

        <M-41 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'Posting.Posting_ID':U (icFieldName), 
            input  btsPosting.Posting_ID (icFieldValue), 
            input  'S':U (icType), 
            input  3 (iiSeverity), 
            input  btsPosting.tc_Rowid (icRowid), 
            input  'qadfin-870982':U (icFcMsgNumber), 
            input  vcContent (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if oiReturnStatus >= 0 then assign oiReturnStatus = -1.
        next.
    end.

    /* if the user does change of Approve status, skipp all other steps */
    if t_iPosting.PostingApproveStatus <>  btsPosting.PostingApproveStatus or
       t_iPosting.PostingVerifyStatus  <>  btsPosting.PostingVerifyStatus
    then next.

    /* If the posting was loaded as part of the change of counterpart posting, *
     * skipp processing of it                                                  */
    if lookup(string(btsPosting.Posting_Id), vcAutoLoadReversingPostingIDs) > 0
    then next.

    /* User can change only couple of fields - include the Journal-related fields about the Layer in the except-phrase as those are checked separately further on in this method */
    buffer-compare btsPosting 
           except PostingDate
                  PostingAddGLNbrDate
                  PostingAddGLNbrRevDate
                  PostingAutoReversalDate
                  PostingText
                  PostingSecondText
                  PostingYear
                  PostingPeriod
                  PostingYearPeriod
                  PostingVoucher
                  Journal_ID
                  tlJournalAccessAllowed
                  tcJournalCode
                  tcLayerTypeCode
                  tcJournalTypeCode                  
                  tcReportingJournalCode
                  tc_Status
           to t_iPosting 
           save vcBufferCompareResult
           no-error.
    if vcBufferCompareResult <> "":U and 
       vcBufferCompareResult <> ?
    then do:
        assign vcMsgExplanation = <M-63 GetErrorExplanation
                                     (input  btsPosting.tc_Rowid (icPostingRowId), 
                                      input  ? (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
        assign vcMessage = trim(#T-22'For counter part posting of Reverse Journal Create only following fields can be updated: Year, Period, Date, Daybook and Description.':255(409295748)T-22#) + chr(10) + 
                           trim(substitute(#T-64'Posting &1/&2/&3':255(798482986)T-64#, btsPosting.PostingYear, btsPosting.tcJournalCode, btsPosting.PostingVoucher)) + 
                           trim(substitute(#T-81'This field has been changed: &1':200(31091661)T-81#,vcBufferCompareResult)).
        <M-57 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  btsPosting.tc_Rowid (icRowid), 
            input  'qadfin-399682':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if oiReturnStatus >= 0 then assign oiReturnStatus = -1.
        next.
    end. /* if vcBufferCompareResult <> "":U and  */
    
    /* If user does change of the Daybook, this daybook has to be in the same  *
     * layer type as daybook of original posting                               */
    if btsPosting.tcJournalCode <> t_iPosting.tcJournalCode
    then do:
        /* Get layer type of the original posting */
        <Q-31 run PostingByPostingId (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input btsPosting.AutoReversalPosting_ID, (PostingId)
            input ?, (JournalTypeCode)
            output dataset tqPostingByPostingId) in BPosting>

        find first tqPostingByPostingId where
                   tqPostingByPostingId.tiPosting_ID = btsPosting.AutoReversalPosting_ID
                   no-error.

        /* Posting layer cannot be different to one on the original posting */
        if available tqPostingByPostingId     and
           tqPostingByPostingId.tcLayerTypeCode <> btsPosting.tcLayerTypeCode
        then do:
            assign vcMsgExplanation = <M-74 GetErrorExplanation
                                         (input  btsPosting.tc_Rowid (icPostingRowId), 
                                          input  ? (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            assign vcMessage = #T-70'Daybook of the auto-reversed posting has to belong to same Posting Layer as daybook of original Posting.':255(623509103)T-70#
                             + chr(10) + #T-72'Posting &1/&2/&3':255(798482986)T-72#
                   vcMessage = substitute (vcMessage, btsPosting.PostingYear, btsPosting.tcJournalCode, btsPosting.PostingVoucher).
            <M-36 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPosting.tcJournalCode':U (icFieldName), 
                input  btsPosting.tcJournalCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  btsPosting.tc_ParentRowid (icRowid), 
                input  'qadfin-738834':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if oiReturnStatus >= 0 then assign oiReturnStatus = -1.    
            next.     
        end. /* if available tqPostingByPostingId */
    end. /* if btsPosting.tcJournalCode <> t_iPosting.tcJournalCode */

    /* If user does cchange of the Posting Date, this value also has to be stored on the original posting  */
    if btsPosting.PostingDate <> t_iPosting.PostingDate
    then do:

        /* Get the original posting from Database */
        find first t_sPosting where
                   t_sPosting.Posting_ID = btsPosting.AutoReversalPosting_ID
                   no-error.
            
        if not available t_sPosting
        then do:
            assign vcAutoLoadReversingPostingIDs = substitute("&1,&2",
                                                              vcAutoLoadReversingPostingIDs,
                                                              btsPosting.AutoReversalPosting_ID).

            <M-96 run DataLoad
               (input  '':U (icRowids), 
                input  btsPosting.AutoReversalPosting_ID (icPkeys), 
                input  '':U (icObjectIds), 
                input  '':U (icFreeform), 
                input  true (ilKeepPrevious), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            if viFcReturnSuper < 0 or oiReturnStatus = 0 and viFcReturnSuper < 0 then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0 
            then do:
                assign vcMsgExplanation = <M-20 GetErrorExplanation
                                             (input  btsPosting.tc_Rowid (icPostingRowId), 
                                              input  ? (icPostingLineRowId), 
                                              output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
                assign vcMsg = #T-33'The system cannot read details about the details of posting ID &1.':255(69152)T-33#
                       vcMsg = substitute(vcMsg, btsPosting.AutoReversalPosting_ID).
                <M-38 run SetMessage
                   (input  vcMsg (icMessage), 
                    input  '':U (icArguments), 
                    input  'btsPosting.AutoReversalPosting_ID':U (icFieldName), 
                    input  btsPosting.AutoReversalPosting_ID (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  btsPosting.tc_Rowid (icRowid), 
                    input  'qadfin-231275':U (icFcMsgNumber), 
                    input  vcMsgExplanation (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>
                next.
            end. /* if viFcReturnSuper <> 0 */   

            /* Create t_s records for the newly loaded Counterpart posting */
            for each tPosting where
                     tPosting.Posting_ID = btsPosting.AutoReversalPosting_ID:
                for each tPostingLine where
                         tPostingLine.tc_ParentRowid = tPosting.tc_Rowid:
                    
                    for each tPostingSaf where
                             tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
                        create t_sPostingSaf.
                        buffer-copy tPostingSaf to t_sPostingSaf.
                    end.

                    for each tPostingVat where
                             tPostingVat.tc_ParentRowid = tPostingLine.tc_Rowid:
                        create t_sPostingVat.
                        buffer-copy tPostingVat to t_sPostingVat.
                    end.
                    
                    for each tPostingVatDelay where
                             tPostingVatDelay.tc_ParentRowid = tPostingLine.tc_Rowid:
                        create t_sPostingVatDelay.
                        buffer-copy tPostingVatDelay to t_sPostingVatDelay.
                    end.

                    create t_sPostingLine.
                    buffer-copy tPostingLine to t_sPostingLine.
                end. /* for tPostingLine where */

                create t_sPosting.
                buffer-copy tPosting to t_sPosting.
            end. /* for each tPosting where */

            find first t_sPosting where
                       t_sPosting.Posting_ID = btsPosting.AutoReversalPosting_ID
                       no-error.
        end. /* if not available t_sPosting */

        /* Assign Auto-reversal posting date into original posting */
        assign t_sPosting.PostingAutoReversalDate = btsPosting.PostingDate
               t_sPosting.PostingAddGLNbrRevDate  = btsPosting.PostingAddGLNbrDate
               t_sPosting.tc_Status               = (if t_sPosting.tc_Status = '':U then 'C':U else t_sPosting.tc_Status).
    end. /* if btsPosting.PostingDate <> t_iPosting.PostingDate */
end. /* For each btsPosting where */