project QadFinancials > class BPosting > method ValidateComponentPostPostingLine1

Description

Validate Component After ancestor tag for posting lines.


Parameters


blQueryStartedGLByIDinput-outputlogical
blQueryStartedProjectByIdinput-outputlogical
blQueryStartedCostCentreByIDinput-outputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentPost


program code (program4/bposting.p)

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

/* =================================================================================== */
/* Call a function (that is extended in sub-class BjournalEntry) that will return true */
/* in case the create/mod/del of the postings is performed by an external activity     */
/* =================================================================================== */
assign vlActivityIsExternal       = <M-27 ValidateComponentPostExternal  (input  vcActivityCode (icActivityCode)) in BPosting>
       vlIsInvoiceMatchingPosting = if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-CIREC}
                                    then true
                                    else false
       vlIsDebtorInvoicePosting   = if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICE}           or
                                       t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTE}        or
                                       t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICECORRECT}    or
                                       t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTECORRECT} or
                                       t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORFINANCECHARGE}
                                    then true
                                    else false.

if t_sPostingLine.tc_Status <> "D":U
then do:    
    /* ============================================================= */
    /* Default the Allocation Key for New Allocations when necessary */
    /* ============================================================= */
    if t_sPostingLine.tcAllocationType = {&ALLOCATIONTYPE-NEW} and
      (t_sPostingLine.tcAllocationKey = ? or
       t_sPostingLine.tcAllocationKey = "":U )
    then assign t_sPostingLine.tcAllocationKey = trim(string(t_sPosting.PostingYear))    + "/":U +
                                                 trim(string(t_sPosting.PostingPeriod))  + "/":U +
                                                 trim(t_sPosting.tcJournalCode)          + "/":U +
                                                 trim(string(t_sPosting.PostingVoucher)) + "/":U +
                                                 trim(string(t_sPostingLine.PostingLineSequence)).

    /* ======================================================== */
    /* Make sure the VAT-details are specified for VAT-accounts */
    /* ======================================================== */
    if t_sPostingLine.tcGLTypeCode = {&GLTYPECODE-VAT} and
       not can-find(first t_sPostingVat where
                          t_sPostingVat.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                          t_sPostingVat.tc_Status     <> "D":U) and
       not can-find(first t_sPostingWHT where
                          t_sPostingWHT.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                          t_sPostingWHT.tc_Status     <> "D":U)
    then do:
        assign vcMsgExplanation = <M-35 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        <M-47 run SetMessage
           (input  trim(#T-52'Tax details are missing for the GL account $1 (account type $2).':250(16577)T-52#) (icMessage), 
            input  t_sPostingLine.tcGLCode + chr(2) + {&GLTYPECODE-VAT-TR} (icArguments), 
            input  'tPostingLine.tcGLCode':U (icFieldName), 
            input  t_sPostingLine.tcGLCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPostingLine.tc_Rowid (icRowid), 
            input  'QadFin-7362':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        assign viLocalReturnStatus = -1.
    end.

    /* =========================================================== */
    /* Make sure no VAT-details are specified for non-VAT-accounts */
    /* =========================================================== */
    if t_sPostingLine.tcGLTypeCode <> {&GLTYPECODE-VAT} and
       can-find(first t_sPostingVat where
                      t_sPostingVat.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                      t_sPostingVat.tc_Status     <> "D":U) and
       can-find(first t_sPostingWHT where
                      t_sPostingWHT.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                      t_sPostingWHT.tc_Status     <> "D":U)
    then do:
        assign vcMsgExplanation = <M-92 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        <M-41 run SetMessage
           (input  trim(#T-53'GL account $1 is not a tax account. No tax lines will be created.':250(16578)T-53#) (icMessage), 
            input  t_sPostingLine.tcGLCode (icArguments), 
            input  'tPostingLine.tcGLCode':U (icFieldName), 
            input  t_sPostingLine.tcGLCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPostingLine.tc_Rowid (icRowid), 
            input  'QadFin-7360':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        assign viLocalReturnStatus = -1.
    end.


    /* ======================================================== */
    /* Make sure these GL accounts are not used for Matching    */
    /* ======================================================== */
    if vlIsInvoiceMatchingPosting    = true                and
       t_sPostingLine.tcGLTypeCode   = {&GLTYPECODE-FASS}
    then do:
        assign vcMsgExplanation = <M-2 GetErrorExplanation
                             (input  t_sPosting.tc_Rowid (icPostingRowId), 
                              input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                              output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        <M-6 run SetMessage
           (input  #T-70'This type of account cannot be used.':40(55695)T-70# (icMessage), 
            input  t_sPostingLine.tcGLCode (icArguments), 
            input  'tPostingLine.tcGLCode':U (icFieldName), 
            input  t_sPostingLine.tcGLCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPostingLine.tc_Rowid (icRowid), 
            input  'qadfin-317353':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        assign viLocalReturnStatus = -1.
    end.
     
    /* ================================================================================================ */
    /* Make sure warning is displayed for these GL accounts in Supplier Invoice and Customer Invoice    */
    /* ================================================================================================ */
    if (t_sPostingLine.tcGLTypeCode = {&GLTYPECODE-BANK}  or
        t_sPostingLine.tcGLTypeCode = {&GLTYPECODE-CASH}) and
       (vlIsInvoiceMatchingPosting                        or
        vlIsDebtorInvoicePosting)
    then do:
       
         assign vcMessage = trim(substitute(#T-89'This type of account (&1) cannot be used.':255(71121)T-89#,t_sPostingLine.tcGLTypeCode))
             viLocalReturnStatus = 1.

            <M-79 run SetMessage
               (input  vcMessage (icMessage), 
                input  t_sPostingLine.tcGLCode (icArguments), 
                input  'tPostingLine.tcGLCode':U (icFieldName), 
                input  t_sPostingLine.tcGLCode (icFieldValue), 
                input  'W':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingLine.tc_Rowid (icRowid), 
                input  'qadfin-407371':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>

    end.
 
    /* ======================================================= */
    /* If the GL is with SAF's, at least one SAF record needed */
    /* ======================================================= */
    if  t_sPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} and
        (t_sPostingLine.Project_ID   = 0     or
        t_sPostingLine.Project_ID    = ?)    and
       (t_sPostingLine.CostCentre_ID = 0     or
        t_sPostingLine.CostCentre_ID = ?)    and
       (t_sPostingLine.tc_Status     = "N":U or
        t_sPostingLine.tc_Status     = "C":U and
        can-find(t_iPostingLine where
                 t_iPostingLine.tc_Rowid = t_sPostingLine.tc_Rowid and
                 t_iPostingLine.GL_ID   <> t_sPostingLine.GL_ID))
    then do:
        if blQueryStartedGLByID = false
        then do:
            <Q-42 run GLById  (Start) in BGL >
            assign blQueryStartedGLByID = true.
        end.

        <Q-43 run GLById (all) (Read) (Cache)
           (input t_sPosting.Company_ID, (CompanyId)
            input t_sPostingLine.GL_ID, (GLId)
            output dataset tqGLById) in BGL >

        find tqGLById where
             tqGLById.tiGL_ID = t_sPostingLine.GL_ID
             no-error.

        if available tqGLById        and
           tqGLById.tlGLIsSafAccount and
           can-find(first t_sPostingSaf where
                          t_sPostingSaf.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                          t_sPostingSaf.tc_Status     = "D":U) and
           not can-find(first t_sPostingSaf where
                              t_sPostingSaf.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                              t_sPostingSaf.tc_Status      = "N":U)
        then do:
            assign vcMsgExplanation = <M-19 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            <M-44 run SetMessage
               (input  trim(#T-54'GL account $1 is defined with SAF analysis, but no SAF details can be found.':250(16621)T-54#) (icMessage), 
                input  t_sPostingLine.tcGLCode (icArguments), 
                input  'tPostingLine.tcGLCode':U (icFieldName), 
                input  t_sPostingLine.tcGLCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingLine.tc_Rowid (icRowid), 
                input  'QadFin-7361':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            assign viLocalReturnStatus = -1.
        end.
    end.
    
    /* =========================================================================== */
    /* Make sure the Posting Date is between the Start and End Date of the Project */
    /* If the Project is with SAF's, at least one SAF record needed                */
    /* =========================================================================== */
    if t_sPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} and
       t_sPostingLine.Project_ID <> 0     and
       t_sPostingLine.Project_ID <> ?     and
      (t_sPostingLine.tc_Status   = "N":U or
       t_sPostingLine.tc_Status   = "C":U and
       can-find(t_iPostingLine where
                t_iPostingLine.tc_Rowid    = t_sPostingLine.tc_Rowid and
                t_iPostingLine.Project_ID <> t_sPostingLine.Project_ID))
    then do:    
        if blQueryStartedProjectById = false
        then do:
            <Q-45 run ProjectById  (Start) in BProject >
            assign blQueryStartedProjectById = true.
        end. /* if blQueryStartedProjectById = false */

        <Q-46 run ProjectById (all) (Read) (Cache)
           (input ?, (CompanyId)
            input t_sPostingLine.Project_ID, (ProjectId)
            output dataset tqProjectById) in BProject >

        find tqProjectById where
             tqProjectById.tiProject_ID = t_sPostingLine.Project_ID
             no-error.

        if available tqProjectById                                 and
          (tqProjectById.ttProjectStartDate > t_sPosting.PostingDate or
           tqProjectById.ttProjectEndDate   < t_sPosting.PostingDate)
        then do:
            assign vcMsgExplanation = <M-88 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            assign vcFcMaskList        = <M-36 DisplayDate  (input  t_sPosting.PostingDate (itDate)) in BPosting>
                   vcMessage           = trim(subst(#T-55'The project &1 is not active on posting date &2.':150(3243)T-55#, t_sPostingLine.tcProjectCode, vcFcMaskList))
                   viLocalReturnStatus = -1.
            <M-37 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPostingLine.tcProjectCode':U (icFieldName), 
                input  t_sPostingLine.tcProjectCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingLine.tc_Rowid (icRowid), 
                input  'QadFin-7357':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
        end.

        if available tqProjectById                   and
           tqProjectById.tlProjectIsWithSaf          and
           not tqProjectById.tlProjectIsStructFromGL and
           not can-find(first t_sPostingSaf where
                              t_sPostingSaf.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                              t_sPostingSaf.tc_Status     <> "D":U)
        then do:
            assign vcMsgExplanation = <M-69 GetErrorExplanation
                             (input  t_sPosting.tc_Rowid (icPostingRowId), 
                              input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                              output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            <M-48 run SetMessage
               (input  trim(#T-56'Project $1 is defined with SAF analysis, but no SAF records can be found.':250(16619)T-56#) (icMessage), 
                input  t_sPostingLine.tcProjectCode (icArguments), 
                input  'tPostingLine.tcProjectCode':U (icFieldName), 
                input  t_sPostingLine.tcProjectCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingLine.tc_Rowid (icRowid), 
                input  'QadFin-7363':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            assign viLocalReturnStatus = -1.
        end.
    end. /* Posting Date is between the Start and End Date of the Project */
         
    /* ================================================================ */                
    /* If the Cost Centre is with SAF's, at least one SAF record needed */
    /* ================================================================ */
    if t_sPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} and
       t_sPostingLine.CostCentre_ID <> 0     and
       t_sPostingLine.CostCentre_ID <> ?     and
      (t_sPostingLine.tc_Status      = "N":U or
       t_sPostingLine.tc_Status      = "C":U and
       can-find(t_iPostingLine where
                t_iPostingLine.tc_Rowid       = t_sPostingLine.tc_Rowid and
                t_iPostingLine.CostCentre_ID <> t_sPostingLine.CostCentre_ID))
    then do:
        if blQueryStartedCostCentreByID = false
        then do:
            <Q-49 run CostCentreByID  (Start) in BCostCentre >
            assign blQueryStartedCostCentreByID = true.
        end. /* if blQueryStartedCostCentreByID = false */

        <Q-50 run CostCentreByID (all) (Read) (Cache)
           (input t_sPosting.Company_ID, (CompanyId)
            input t_sPostingLine.CostCentre_ID, (CostCentreID)
            output dataset tqCostCentreByID) in BCostCentre >

        find tqCostCentreByID where
             tqCostCentreByID.tiCostCentre_ID = t_sPostingLine.CostCentre_ID
             no-error.

        if available tqCostCentreByID                      and
           tqCostCentreByID.tlCostCentreIsWithSaf          and
           not tqCostCentreByID.tlCostCentreIsStructFromGL and
           not can-find(first t_sPostingSaf where
                              t_sPostingSaf.tc_ParentRowid = t_sPostingLine.tc_Rowid and
                              t_sPostingSaf.tc_Status     <> "D":U)
        then do:
            assign vcMsgExplanation = <M-30 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                              
            <M-51 run SetMessage
               (input  trim(#T-57'Cost center $1 is defined with SAF analysis, but no SAF records can be found.':250(16620)T-57#) (icMessage), 
                input  t_sPostingLine.tcCostCentreCode (icArguments), 
                input  'tPostingLine.tcCostCentreCode':U (icFieldName), 
                input  t_sPostingLine.tcCostCentreCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingLine.tc_Rowid (icRowid), 
                input  'QadFin-7364':U (icFcMsgNumber), 
                input  #T-58'You must check that the correct SAF structure is linked to the cost center.':200(16710)T-58# + chr(10) + vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            assign viLocalReturnStatus = -1.
        end.
    end. /* If the Cost Centre is with SAF's, at least one SAF record needed */
        
    /* ================================================================ */
    /* External actions on postings result in a number of restrictions: */
    /* - Every posting-line should have exchange-rate filled            */
    /* - Every posting-line should have exchange-rate-scale filled      */
    /* ================================================================ */
    if vlActivityIsExternal = true and
      (t_sPostingLine.PostingLineExchangeRate = 0 or
       t_sPostingLine.PostingLineExchangeRate = ?)
    then do: 
        assign vcMsgExplanation = <M-97 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                 
        assign vcMessage      = trim(subst(#T-65'Each externally created posting line must have an exchange rate specified.':255(14148)T-65#))                              + chr(10) +
                                trim(subst(#T-66'Posting: &1/&2/&3.':255(14145)T-66#, string(t_sPosting.PostingYear), t_sPosting.tcJournalCode, string(t_sPosting.PostingVoucher))) + chr(10) +
                                trim(subst(#T-63'Posting line sequence: &1.':255(14146)T-63#, string(t_sPostingLine.PostingLineSequence)))                                      + chr(10) +
                                trim(subst(#T-64'Posting line GL: &1.':255(14147)T-64#, string(t_sPostingLine.tcGLCode))).
               viLocalReturnStatus = -1.
        <M-39 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPostingLine.PostingLineExchangeRate':U (icFieldName), 
            input  t_sPostingLine.PostingLineExchangeRate (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPostingLine.tc_Rowid (icRowid), 
            input  'QadFin-7358':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    end. 
    
    if vlActivityIsExternal = true and
      (t_sPostingLine.PostingLineRateScale = 0 or
       t_sPostingLine.PostingLineRateScale = ?)
    then do:
        assign vcMsgExplanation = <M-34 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        assign vcMessage      = trim(subst(#T-59'A rate scale factor must be specified for the exchange rate for each externally created posting line.':255(14150)T-59#))           + chr(10) +
                                trim(subst(#T-60'Posting: &1/&2/&3.':255(14145)T-60#, string(t_sPosting.PostingYear), t_sPosting.tcJournalCode, string(t_sPosting.PostingVoucher))) + chr(10) +
                                trim(subst(#T-61'Posting line sequence: &1.':255(14146)T-61#, string(t_sPostingLine.PostingLineSequence)))                                      + chr(10) +
                                trim(subst(#T-62'Posting line GL: &1.':255(14147)T-62#,trim(string(t_sPostingLine.tcGLCode)))).
               viLocalReturnStatus = -1.
        <M-40 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPostingLine.PostingLineRateScale':U (icFieldName), 
            input  t_sPostingLine.PostingLineRateScale (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPostingLine.tc_Rowid (icRowid), 
            input  'QadFin-7359':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    end.
end. /* if t_sPostingLine.tc_Status <> "D":U */

/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.