project QadFinancials > class BPosting > method PreSaveValidate

Description

Execute some extra validataions to ensure, there is not corrupted database


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.PreSave


program code (program5/bposting.p)

/* ====================================================================================== *
 * Method       : PreSaveValidate                                                         *
 * Description  : Implement new validations to ensure, there are really created those     *
 *                records which are expected.                                             *
 * -------------------------------------------------------------------------------------- *
 * Parameters   :                                                                         *
 * ====================================================================================== */
assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, return:
    
    /* =============================================================================== *
     * Get data from other components                                                  *
     * =============================================================================== */    
    /* Check which data from other components are needed */
    assign vlIsBCInvoiceNeeded = can-find(first tPostingLine where
                                                tPostingLine.tcGLTypeCode = {&GLTYPECODE-CRED} and
                                                tPostingLine.tc_Status    = "N":U)
           vlIsBDInvoiceNeeded = can-find(first tPostingLine where
                                                tPostingLine.tcGLTypeCode = {&GLTYPECODE-DEBT} and
                                                tPostingLine.tc_Status    = "N":U).

    
    /* Get handles to instances other needed components (During PreSave all components *
     * are instantiated)                                                               */
    if vlIsBCInvoiceNeeded or
       vlIsBDInvoiceNeeded
    then do:
        <I-47 {bFcOpenInstance
             &CLASS           = "Transaction"}>
        
        if vlIsBCInvoiceNeeded
        then do:
            /* Get handles to BJournalEntry component */
            <M-97 run GetInstanceDetails
               (input  'BCInvoice':U (icComponentShortName), 
                input  viCompanyId (iiCompanyIdOfInstance), 
                output viBCInvoiceID (oiInstanceId), 
                output vhBCInvoiceHandle (ohInstanceHandle), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
        end.
    
        if vlIsBDInvoiceNeeded
        then do:
            <M-66 run GetInstanceDetails
               (input  'BDInvoice':U (icComponentShortName), 
                input  viCompanyId (iiCompanyIdOfInstance), 
                output viBDInvoiceID (oiInstanceId), 
                output vhBDInvoiceHandle (ohInstanceHandle), 
                output viFcReturnSuper (oiReturnStatus)) in Transaction>
            if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
        end.
    
        <I-33 {bFcCloseInstance
             &CLASS           = "Transaction"}>
        if viLocalReturn < 0 then leave MAIN_BLOCK.
    end. /* Get data from other components */




    /* Get Supplier Invoice details  */
    empty temp-table tValCInvoiceRefBPost.
    empty temp-table tValCInvoiceMovementRefBPost.
    if valid-handle(vhBCInvoiceHandle)
    then do:
        assign vhFcComponent = vhBCInvoiceHandle.
        <M-75 run GetInstanceData
           (output tValCInvoiceRefBPost (tApiCInvoiceIns), 
            output tValCInvoiceMovementRefBPost (tApiCInvoiceMovementIns), 
            output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
        if viFcReturnSuper < 0 or viLocalReturn = 0 and viFcReturnSuper > 0 then assign viLocalReturn = 0.
        if viFcReturnSuper < 0 then leave MAIN_BLOCK.
    end.

    /* Get Customer Invoice details */
    empty temp-table tValDInvoiceRefBPost.
    empty temp-table tValDInvoiceMovementRefBPost.
    if valid-handle(vhBDInvoiceHandle)
    then do:
        assign vhFcComponent = vhBDInvoiceHandle.
        <M-57 run GetInstanceData
           (output tValDInvoiceRefBPost (tApiDInvoiceIns), 
            output tValDInvoiceMovementRefBPost (tApiDInvoiceMovementIns), 
            output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        if viFcReturnSuper < 0 or viLocalReturn = 0 and viFcReturnSuper > 0 then assign viLocalReturn = 0.
        if viFcReturnSuper < 0 then leave MAIN_BLOCK.
    end.

    /*Extra Consistency Validations should be skipped for Consolidation Entity. Find whether this
    entity is a consolidation entity*/
    if valid-handle(vhCacher)
    then do:
        assign vhFcComponent = vhCacher.
        
        <M-30 run GetLogicalValueFromSession
           (input  viSessionID (iiSessionId), 
            input  {&COMPANYPROPERTY-ISCONSOLID} (icDataItemName), 
            output vlCompanyPropertyIsConsolid (olValue), 
            output viFcReturnSuper (oiReturnStatus)) in Cacher>
        
        if viFcReturnSuper < 0 or 
           viLocalReturn   = 0 and 
           viFcReturnSuper > 0 
        then assign viLocalReturn = 0.
        
        if viFcReturnSuper < 0 
        then leave MAIN_BLOCK.
    end.
    else do:
        <Q-24 run CompanyPropertyForAllData (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            output dataset tqCompanyPropertyForAllData) in BCompanyProperty >
            
        find first tqCompanyPropertyForAllData where
            tqCompanyPropertyForAllData.tiCompany_ID = viCompanyId no-error.
        
        if available tqCompanyPropertyForAllData
        then  assign vlCompanyPropertyIsConsolid = tqCompanyPropertyForAllData.tlCompanyPropertyIsConsolid.     
    end.

    /* =============================================================================== *
     * Validate Postings                                                               *
     * =============================================================================== */

    if vcActivityCode              <> "JournalEntryExcelIntegrationRepair":U and
       vlCompanyPropertyIsConsolid <> true
    then do:     
    
        for each tPosting where
                 tPosting.tc_Status <> "D":U:
        
            /* Go through all posting lines */
            for each tPostingLine where
                     tPostingLine.tc_ParentRowid = tPosting.tc_Rowid:
            
                /*If the posting is part of year-end closing activites, then skip the v
                  extra consistency validations for this posting*/
                if tPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
                   then next.                
               
               
                /* Posting to Supplier control account have to have CInvoiceMovement linked to it */
                if tPostingLine.tc_Status    = "N":U              and
                   tPostingLine.tcGLTypeCode = {&GLTYPECODE-CRED} and
                   not can-find(tValCInvoiceMovementRefBPost where
                                tValCInvoiceMovementRefBPost.PostingLine_ID = tPostingLine.PostingLine_ID)
                then do:
                    assign vcMessage     = #T-59'You tried to create a posting on a Supplier Control account without posting the subledger Supplier Invoice - Activity. This is not allowed. (Posting = &1/&2/&3)':255(914478653)T-59#
                           vcMessage     = substitute(vcMessage, tPosting.PostingYear, tPosting.tcJournalCode, tPosting.PostingVoucher)
                           viLocalReturn = -1.
                    <M-61 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'S':U (icType), 
                        input  3 (iiSeverity), 
                        input  tPosting.tc_Rowid (icRowid), 
                        input  'QadFin-547273':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                end. /* Posting to Supplier control account have to have CInvoiceMovement linked to it */

                /* Posting to Customer control account have to have DInvoiceMovement linked to it */
                if tPostingLine.tc_Status    = "N":U              and
                   tPostingLine.tcGLTypeCode = {&GLTYPECODE-DEBT} and
                   not can-find(tValDInvoiceMovementRefBPost where
                                tValDInvoiceMovementRefBPost.PostingLine_ID = tPostingLine.PostingLine_ID)
                then do:
                    assign vcMessage     = #T-6'You tried to create a posting on a Customer Control account without posting the subledger Customer Invoice - Activity. This is not allowed. (Posting = &1/&2/&3)':255(950442691)T-6#
                           vcMessage     = substitute(vcMessage, tPosting.PostingYear, tPosting.tcJournalCode, tPosting.PostingVoucher)
                           viLocalReturn = -1.
                    <M-71 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'S':U (icType), 
                        input  3 (iiSeverity), 
                        input  tPosting.tc_Rowid (icRowid), 
                        input  'QadFin-401158':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                end. /* Posting to Customer control account have to have DInvoiceMovement linked to it */
            end. /* Go through all posting lines */
        end. /* for each tPosting */
    end. /* if vcActivityCode */     
end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.