project QadFinancials > class BPosting > method ValidateComponentPostPosting2

Description

Validate Component after ancestor tag: Validations for Posting Header (part 2)


Parameters


blQueryStartedPostingTemplateinput-outputlogical
blQueryStartedPeriodByIdinput-outputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentPost


program code (program4/bposting.p)

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

POSTINGBLOCK:
do:    
    if t_sPosting.tc_Status <> "N":U
    then do:
        find t_iPosting where
             t_iPosting.tc_Rowid = t_sPosting.tc_Rowid
             no-error.
        if not available t_iPosting
        then leave POSTINGBLOCK.    
    end. /* if t_sPosting.tc_Status <> "N":U */
    
    /* ======================================================= */                                               
    /* Origin fields can only be entered for external postings */
    /* ======================================================= */
    if t_sPosting.PostingOriginIsExternal    <> true and
     ((t_sPosting.PostingOriginDaybookCode   <> '':U and t_sPosting.PostingOriginDaybookCode   <> ?) or
      (t_sPosting.PostingOriginDaybookNumber <> '':U and t_sPosting.PostingOriginDaybookNumber <> ?) or
      (t_sPosting.PostingOriginDocument      <> '':U and t_sPosting.PostingOriginDocument      <> ?) or
      (t_sPosting.PostingOriginDocumentType  <> '':U and t_sPosting.PostingOriginDocumentType  <> ?) or
      (t_sPosting.PostingOriginReference     <> '':U and t_sPosting.PostingOriginReference     <> ?) or
      (t_sPosting.PostingOriginTransType     <> '':U and t_sPosting.PostingOriginTransType     <> ?) or
       can-find(first t_sPostingLine where
                      t_sPostingLine.tc_ParentRowid            = t_sPostingLine.tc_Rowid and
                      t_sPostingLine.PostingLineOriginLineNbr <> 0 and
                      t_sPostingLine.PostingLineOriginLineNbr <> ?))
    then do:
        assign vcMsgExplanation = <M-57 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  ? (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        assign vcMessage      = trim(#T-100'Origin fields can only be entered for external postings.':200(31841)T-100#) + chr(10) +
                                trim(substitute(#T-101'Origin Daybook Code: &1':100(31848)T-101#, trim(t_sPosting.PostingOriginDaybookCode) )) + chr(10) +
                                trim(substitute(#T-102'Origin Daybook Number: &1':100(31849)T-102#, trim(t_sPosting.PostingOriginDaybookNumber) )) + chr(10) +
                                trim(substitute(#T-103'Origin Document: &1':100(31844)T-103#, trim(t_sPosting.PostingOriginDocument) )) + chr(10) +
                                trim(substitute(#T-95'Origin Payment Type: &1':100(31845)T-95#, trim(t_sPosting.PostingOriginDocumentType) )) + chr(10) +
                                trim(substitute(#T-96'Origin Reference: &1':100(31846)T-96#, trim(t_sPosting.PostingOriginReference) )) + chr(10) +
                                trim(substitute(#T-97'Origin Transaction Type: &1':100(31847)T-97#, trim(t_sPosting.PostingOriginTransType) )) + chr(10) +
                                trim(substitute(#T-98'Posting lines found with origin line number &1':100(31850)T-98#, 
                                       string(can-find(first t_sPostingLine where
                                                      t_sPostingLine.tc_ParentRowid            = t_sPostingLine.tc_Rowid and
                                                      t_sPostingLine.PostingLineOriginLineNbr <> 0)) ))
               viLocalReturnStatus = -1.                                                       

        <M-109 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPosting.PostingOriginDaybookCode':U (icFieldName), 
            input  t_sPosting.PostingOriginDaybookCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPosting.tc_Rowid (icRowid), 
            input  'QadFin-7337':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>               

    end. /* Origin fields can only be entered for external postings */

    /*====================================================================================================== */
    /* Check on Uniqueness of PostingOriginReference within an entity in case of EAM transactions - Q1081549 */
    /* We only consider transactions for which PostingOriginReference begins 'MI'                            */
    /* We look in the db and in the instance data itself                                                     */
    /*====================================================================================================== */
    if t_sPosting.PostingOriginReference begins 'MI' and 
       t_sPosting.PostingOriginIsExternal = True and
       (t_sPosting.tc_Status = 'N' or (available t_iPosting and t_iPosting.PostingOriginReference <> t_sPosting.PostingOriginReference))
    then do:
        assign vlPostingWithSameReferenceFound = False.
        for each Posting where
                 Posting.Company_ID              = t_sPosting.Company_ID              and
                 Posting.PostingOriginReference  = t_sPosting.PostingOriginReference  and
                 Posting.PostingOriginIsExternal = True
                 no-lock:
            assign vlPostingWithSameReferenceFound = True.
            leave.
        end. /* for each Posting */

        if vlPostingWithSameReferenceFound = False
        then do:
            for each bt_sPosting where
                     bt_sPosting.Company_ID              = t_sPosting.Company_ID              and
                     bt_sPosting.PostingOriginReference  = t_sPosting.PostingOriginReference  and
                     bt_sPosting.PostingOriginIsExternal = True                               and
                     bt_sPosting.tc_Rowid                <> t_sPosting.tc_Rowid
                     :
                assign vlPostingWithSameReferenceFound = True.
                leave.
            end. /* for each bt_sPosting */
        end. /* if vlPostingWithSameReferenceFound = False */

        if vlPostingWithSameReferenceFound = True
        then do:
            assign vcMsgExplanation    = <M-68 GetErrorExplanation
                                            (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                             input  ? (icPostingLineRowId), 
                                             output viFcReturnSuper (oiReturnStatus)) in BPosting>.
            assign vcMessage           = trim(substitute(#T-49'A posting with this reference (&1) already exists.':255(215603978)T-49#, trim(t_sPosting.PostingOriginReference)))
                   viLocalReturnStatus = -1.    

            <M-70 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPosting.PostingOriginReference' (icFieldName), 
                input  t_sPosting.PostingOriginReference (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPosting.tc_Rowid (icRowid), 
                input  'qadfin-297275':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>       

        end. /* if vlPostingWithSameReferenceFound */

    end. /* if t_sPosting.PostingOriginReference begins 'MI' */

    /* ========================== */    
    /* Check unique template code */
    /* ========================== */
    if t_sPosting.tlSaveAsTemplate  = true             and 
       t_sPosting.tcTemplateCode   <> "":U             and
       t_sPosting.tcTemplateCode   <> ?                and
       (t_sPosting.tc_Status = "N":U  or
        (t_sPosting.tc_Status       = "C":U  and
         t_sPosting.tcTemplateCode <> t_iPosting.tcTemplateCode))
    then do:
        
        <Q-85 run PostingTemplatePrim (first) (Read) (NoCache)
           (input t_sPosting.Company_ID, (CompanyId)
            input ?, (TemplateID)
            input t_sPosting.tcTemplateCode, (TemplateCode)
            input ?, (PostingID)
            output dataset tqPostingTemplatePrim) in BPostingTemplate>
        find first tqPostingTemplatePrim no-error.
        if available tqPostingTemplatePrim then 
            assign vlFcQueryRecordsAvailable = yes.
        else 
            assign vlFcQueryRecordsAvailable = no.
        /* retrive tempalte code info to compare the posting id */
        /* if posting id is different , throw error message     */
        if (vlFcQueryRecordsAvailable and tqPostingTemplatePrim.tiPosting_ID <> t_sPosting.Posting_ID)
        then do:
            assign vcMsgExplanation = <M-71 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  ? (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            <M-86 run SetMessage
               (input  trim(#T-108'A template with code $1 already exists.':100(16547)T-108#) (icMessage), 
                input  t_sPosting.tcTemplateCode (icArguments), 
                input  'tPosting.tcTemplateCode':U (icFieldName), 
                input  t_sPosting.tcTemplateCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPosting.tc_Rowid (icRowid), 
                input  'QadFin-7334':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            assign viLocalReturnStatus = -1.
        end.
    end. /* if t_sPosting.tlSaveAsTemplate  = true             and  */

    /* ================================================================================== */
    /* The SaveAsTemplate flag should not be checked off for an existing template posting */
    /* ================================================================================== */
    /*
    if t_sPosting.tc_Status = "C":U        and
       t_iPosting.tlSaveAsTemplate  = true and
       t_sPosting.tlSaveAsTemplate <> true
    then do:
        assign vcMsgExplanation = <M-76 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  ? (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        assign vcMessage           = trim(#T-92'You cannot clear the Save As Template field for an existing posting template.':100(60963)T-92#)
               viLocalReturnStatus = -1.
        <M-80 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPosting.tlSaveAsTemplate':U (icFieldName), 
            input  t_sPosting.tlSaveAsTemplate (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPosting.tc_Rowid (icRowid), 
            input  'QadFin-7332':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    end. /* SaveAsTemplate can not be checked off */
    */
    /* ====================================================================== */    
    /* The template code for an existing template posting can not be modified */
    /* ====================================================================== */
    /*
    if t_sPosting.tc_Status       = "C":U and
       t_iPosting.tcTemplateCode <> "":U  and
       t_iPosting.tcTemplateCode <> ?     and
       t_sPosting.tcTemplateCode <> t_iPosting.tcTemplateCode
    then do:
         assign vcMsgExplanation = <M-37 GetErrorExplanation
                                      (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                       input  ? (icPostingLineRowId), 
                                       output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
         assign vcMessage           = trim(#T-93'You cannot change the template code for an existing posting template.':100(60945)T-93#) + chr(10) +
                                      trim(substitute(#T-94'The previous template code was &1. The new template code is &2.':100(60946)T-94#, trim(t_iPosting.tcTemplateCode), trim(t_sPosting.tcTemplateCode) ))
                viLocalReturnStatus = -1.
        <M-79 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPosting.tcTemplateCode':U (icFieldName), 
            input  t_sPosting.tcTemplateCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sPosting.tc_Rowid (icRowid), 
            input  'QadFin-7331':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    end. /* TemplateCode can not be changed */
    */
    /* ================================ */
    /* Validate Period                  */
    /* Validate PostingDate if possible */
    /* ================================ */
    if t_sPosting.Period_ID  <> 0     and
       t_sPosting.Period_ID  <> ?     and
       t_sPosting.Journal_ID <> 0     and
       t_sPosting.Journal_ID <> ?     and
      (t_sPosting.tc_Status   = "N":U or
       t_sPosting.tc_Status   = "C":U and
      (t_sPosting.Period_ID  <> t_iPosting.Period_ID or
       t_sPosting.Journal_ID <> t_iPosting.Journal_ID))
    then do:         
        <Q-89 run PeriodByID (all) (Read) (Cache)
           (input t_sPosting.Company_ID, (CompanyId)
            input t_sPosting.Period_ID, (PeriodID)
            output dataset tqPeriodByID) in BPeriod >

        find tqPeriodByID where
             tqPeriodByID.tiPeriod_ID = t_sPosting.Period_ID
             no-error.

        if available tqPeriodByID
        then do:
            <Q-77 run PeriodByPeriodStartEndDate (all) (Read) (Cache)
               (input viCompanyId, (CompanyId)
                input today, (Date)
                input ?, (PeriodId)
                input ?, (PeriodYear)
                input ?, (PeriodPeriod)
                output dataset tqPeriodByPeriodStartEndDate) in BPeriod>
                
            find tqPeriodByPeriodStartEndDate where
                 tqPeriodByPeriodStartEndDate.ttPeriodStartDate <= today and
                 tqPeriodByPeriodStartEndDate.ttPeriodEndDate   >= today
                 no-error.
                   

            /* ============================================================================================= */
            /* Year end closing postings                                                                     */
            /* ============================================================================================= */
            if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING}
            then do:
                /* Year end closing can be done to the normal period, but only if this is the last             *
                 * period of the year and there is no correction period or if the posting is created by the    *
                 * Year-end closing functionality                                                              */
                if tqPeriodByID.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
                   not vlBPostingIsStartedFromBYrClose
                then do:
                    /* Get the last normal period of the year */
                    assign viLastNormalPeriod = ?.
                    <Q-62 run PeriodByYearType (last) (Read) (NoCache)
                       (input t_sPosting.Company_ID, (CompanyId)
                        input t_sPosting.PostingYear, (PeriodYear)
                        input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode)
                        output dataset tqPeriodByYearType) in BPeriod>
                    find last tqPeriodByYearType where
                              tqPeriodByYearType.tiCompany_ID     = t_sPosting.Company_ID  and
                              tqPeriodByYearType.tiPeriodYear     = t_sPosting.PostingYear and
                              tqPeriodByYearType.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL}
                              no-error.
                    if available tqPeriodByYearType
                    then assign viLastNormalPeriod = tqPeriodByYearType.tiPeriodYearPeriod.

                    /* Get the last correction period of the year */
                    assign viLastCorrectionPeriod = ?.
                    <Q-32 run PeriodByYearType (last) (Read) (NoCache)
                       (input t_sPosting.Company_ID, (CompanyId)
                        input t_sPosting.PostingYear, (PeriodYear)
                        input {&PERIODTYPECODE-CORRECTION}, (PeriodTypeCode)
                        output dataset tqPeriodByYearType) in BPeriod>
                    find last tqPeriodByYearType where
                              tqPeriodByYearType.tiCompany_ID        = t_sPosting.Company_ID                         and
                              tqPeriodByYearType.tiPeriodYear        = t_sPosting.PostingYear                        and
                              (tqPeriodByYearType.tiPeriodYearPeriod > viLastNormalPeriod or viLastNormalPeriod = ?) and
                              tqPeriodByYearType.tcPeriodTypeCode    = {&PERIODTYPECODE-CORRECTION}
                              no-error.
                    if available tqPeriodByYearType
                    then assign viLastCorrectionPeriod = tqPeriodByYearType.tiPeriodYearPeriod.

                    /* If there is correction period or this is not the last normal period, raise error */
                    if viLastCorrectionPeriod <> ? or
                       viLastNormalPeriod      > tqPeriodByID.tiPeriodYearPeriod
                    then do:
                        assign vcMsgExplanation = <M-26 GetErrorExplanation
                                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                      input  ? (icPostingLineRowId), 
                                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>
                               vcMessage = #T-17'A year-end closing posting (&1/&2/&3) cannot occur in a normal period (&4/&5).':255(460124078)T-17#
                               vcMessage = substitute(vcMessage, t_sPosting.PostingYear, t_sPosting.tcJournalCode, t_sPosting.PostingVoucher, t_sPosting.PostingYear, t_sPosting.PostingPeriod).
                        <M-67 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  'tPosting.Period_ID':U (icFieldName), 
                            input  string(t_sPosting.PostingYear) + '/':U + string(t_sPosting.PostingPeriod) (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  t_sPosting.tc_Rowid (icRowid), 
                            input  'qadfin-382966':U (icFcMsgNumber), 
                            input  vcMsgExplanation (icFcExplanation), 
                            input  '':U (icFcIdentification), 
                            input  '':U (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                        assign viLocalReturnStatus = -1.
                    end. /* if viLastCorrectPeriod <> ? or */
                end. /* if tqPeriodByID.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL} */
            end. /* if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} */
            else do: /* else if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} */
                /* Period must be open */
                if (t_sPosting.tc_Status                        = "N":U                      or
                    t_sPosting.Period_ID                        <> t_iPosting.Period_ID      or
                    t_sPosting.Journal_ID                       <> t_iPosting.Journal_ID)    and
                   (tqPeriodByID.tcPeriodStatus                 <> {&PERIODSTATUS-OPEN}      or
                    tqPeriodByID.tlPeriodIsPostingGLAllowed     <> true)                     and        
                   (if available tqPeriodByPeriodStartEndDate                and
               t_sPosting.PostingAutoReversalType = {&POSTINGAUTOREVERSALTYPE-REVERSING}    and
               t_sPosting.PostingIsAutoReversal         =  true
                    then t_sPosting.PostingYearPeriod <= tqPeriodByPeriodStartEndDate.tiPeriodYearPeriod
           else  true)   
                    
                then do:
                    assign vcMsgExplanation = <M-8 GetErrorExplanation
                                                 (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                  input  ? (icPostingLineRowId), 
                                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                  
                    <M-90 run SetMessage
                       (input  #T-76'Only open accounting periods are allowed.':255(886789454)T-76# (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPosting.Period_ID':U (icFieldName), 
                        input  string(t_sPosting.PostingYear) + '/':U + string(t_sPosting.PostingPeriod) (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sPosting.tc_Rowid (icRowid), 
                        input  'QadFin-7336':U (icFcMsgNumber), 
                        input  vcMsgExplanation (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    assign viLocalReturnStatus = -1.
                end. /* if (t_sPosting.tc_Status                        = "N":U                      or */
    
                /* If period is closed for purchasing, no creditor invoices/credit notes allowed */
                /* If period is closed for sales     , no debtor   invoices/credit notes allowed */
                if tqPeriodByID.tlPeriodIsPostingPurchAllow <> true or
                   tqPeriodByID.tlPeriodIsPostingSalesAllow <> true
                then do:
                    if (tqPeriodByID.tlPeriodIsPostingPurchAllow    <> true                                     and
                       (t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTECORRECT} or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTE}        or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICECORRECT}    or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICE})          or
                        tqPeriodByID.tlPeriodIsPostingSalesAllow    <> true                                     and
                       (t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTECORRECT}   or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTE}          or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICECORRECT}      or
                        t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICE}))                            and
                        t_sPosting.PostingIsAutoReversal = false
                    then do:
                        assign vcMsgExplanation = <M-4 GetErrorExplanation
                                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                      input  ? (icPostingLineRowId), 
                                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                  
                        assign vcMessage           = "":U
                               viLocalReturnStatus = -1.
    
                        if tqPeriodByID.tlPeriodIsPostingPurchAllow <> true
                        then assign vcMessage = trim(#T-104'This GL period is closed for purchase transactions.':250(16607)T-104#).
    
                        if tqPeriodByID.tlPeriodIsPostingSalesAllow <> true
                        then do:
                            if vcMessage <> "":U
                            then assign vcMessage = vcMessage + chr(10).
    
                            assign vcMessage = trim(#T-105'This GL period is closed for sales transactions.':250(16608)T-105#).
                        end.
    
                        <M-75 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  'tPosting.Period_ID':U (icFieldName), 
                            input  string(t_sPosting.PostingYear) + '/':U + string(t_sPosting.PostingPeriod) (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  t_sPosting.tc_Rowid (icRowid), 
                            input  'QadFin-7330':U (icFcMsgNumber), 
                            input  vcMsgExplanation (icFcExplanation), 
                            input  '':U (icFcIdentification), 
                            input  '':U (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    end.
                end. /* If period is closed for purchasing, no creditor invoices/credit notes allowed */
    
                /* =================================================================================== */
                /* If period is closed for inventory, no postings on inventory or WIP accounts allowed */
                /* =================================================================================== */
                if tqPeriodByID.tlPeriodIsPostingInvAllowed <> true and
                   t_sPosting.PostingIsAutoReversal          = false and
                   t_sPosting.tcJournalTypeCode             <> {&JOURNALTYPE-PERIODICCOSTING} and 
                   can-find(first t_sPostingLine where
                                  t_sPostingLine.tc_ParentRowid = t_sPosting.tc_Rowid and
                                  t_sPostingLine.tc_Status     <> "D":U             and
                                 (t_sPostingLine.tcGLTypeCode   = {&GLTYPECODE-INVCTRL} or
                                  t_sPostingLine.tcGLTypeCode   = {&GLTYPECODE-WIPCTRL}))
                                  
                then do:
                    assign vcMsgExplanation = <M-5 GetErrorExplanation
                                                 (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                                  input  ? (icPostingLineRowId), 
                                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                  
                    <M-110 run SetMessage
                       (input  trim(#T-111'This period is closed for postings on inventory control accounts and work-in-process-accounts.':255(60838)T-111#) (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPosting.Period_ID':U (icFieldName), 
                        input  string(t_sPosting.PostingYear) + '/':U + string(t_sPosting.PostingPeriod, '99':U) (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sPosting.tc_Rowid (icRowid), 
                        input  'QadFin-7431':U (icFcMsgNumber), 
                        input  vcMsgExplanation (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPosting>
                    assign viLocalReturnStatus = -1.
                end. /* if tqPeriodByID.tlPeriodIsPostingInvAllowed <> true and */
            end. /* else if t_sPosting.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} */
        end. /* available tqPeriodByID and t_sPosting.tcJournalTypeCode <> {&JOURNALTYPE-YEARLYCLOSING} */

        /* =========================================== */
        /* Validate PostingDate if possible            */
        /* =========================================== */
        if available tqPeriodByID and
           t_sPosting.PostingDate <> ? 
        then do :
            if (t_sPosting.PostingDate < tqPeriodByID.ttPeriodStartDate or t_sPosting.PostingDate > tqPeriodByID.ttPeriodEndDate)
            then do:
                assign vcMsgExplanation = <M-10 GetErrorExplanation
                                             (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                              input  ? (icPostingLineRowId), 
                                              output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                                 
                assign vcDatetemp = <M-48 DisplayDate  (input  t_sPosting.PostingDate (itDate)) in BPosting>.
                <M-69 run SetMessage
                   (input  trim(#T-61'The posting date must be between the start and end date of GL period $1/$2.':250(65521)T-61#) (icMessage), 
                    input  string(t_sPosting.PostingYear) + chr(2) + string(t_sPosting.PostingPeriod) (icArguments), 
                    input  'tPosting.PostingDate':U (icFieldName), 
                    input  vcDatetemp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPosting.tc_Rowid (icRowid), 
                    input  'qadfin-492772':U (icFcMsgNumber), 
                    input  vcMsgExplanation (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>    
                assign viLocalReturnStatus = -1.        
            end.
            assign vlPostingDateValidated = true.
        end. /* PostingDate */        

    end. /* Validate Period */

    /* ====================================================================== */
    /* Posting Date must be situated between start and end date of the Period */
    /* ====================================================================== */
    if vlPostingDateValidated = false and
       t_sPosting.PostingDate <> ?                      and
       t_sPosting.Period_ID   <> 0                      and
       t_sPosting.Period_ID   <> ?                      and
      (t_sPosting.tc_Status    = "N":U                  or
       t_sPosting.tc_Status    = "C":U                  and
      (t_sPosting.PostingDate <> t_iPosting.PostingDate or
       t_sPosting.Period_ID   <> t_iPosting.Period_ID))
    then do:       
        <Q-55 assign vlFcQueryRecordsAvailable = PeriodByPeriodStartEndDate (NoCache)
           (input t_sPosting.Company_ID, (CompanyId)
            input t_sPosting.PostingDate, (Date)
            input t_sPosting.Period_ID, (PeriodId)
            input ?, (PeriodYear)
            input ?, (PeriodPeriod)) in BPeriod>

        if vlFcQueryRecordsAvailable = false
        then do:
            /* Also check the Instance */
            assign vlPeriodExists = false.
            if viBPeriodPostingID <> 0 and viBPeriodPostingID <> ?
            then do:    
                if vlOpenPeriodInstance = false
                then do:
                    <I-44 {bFcOpenInstance
                         &CLASS           = "BPeriod"}>
                    assign vlOpenPeriodInstance = true.                                          
                end.        
                
                <M-53 run CheckPeriodExistence
                   (input  t_sPosting.Company_ID (iiCompanyId), 
                    input  t_sPosting.PostingYear (iiPeriodYear), 
                    input  t_sPosting.PostingPeriod (iiPeriodPeriod), 
                    output vlPeriodExists (olDoesExist), 
                    output viPeriodID (oiPeriod_ID), 
                    output viPeriodMarkID (oiPeriodMark_ID), 
                    output vtStartDate (otStartDate), 
                    output vtEndDate (otEndDate), 
                    output vcPeriodTypeCode (ocPeriodTypeCode), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>

                if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
                then assign viLocalReturnStatus = viFcReturnSuper.                                
            end.
                        
            if vlPeriodExists = false or
              (vlPeriodExists = true and (t_sPosting.PostingDate < vtStartDate or t_sPosting.PostingDate > vtEndDate))
            then do:
                assign vcMsgExplanation = <M-51 GetErrorExplanation
                                             (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                              input  ? (icPostingLineRowId), 
                                              output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                               
                assign vcDatetemp = <M-91 DisplayDate  (input  t_sPosting.PostingDate (itDate)) in BPosting>.
                <M-585 run SetMessage
                   (input  trim(#T-1'The posting date must be between the start and end date of GL period $1/$2.':250(65521)T-1#) (icMessage), 
                    input  string(t_sPosting.PostingYear) + chr(2) + string(t_sPosting.PostingPeriod) (icArguments), 
                    input  'tPosting.PostingDate':U (icFieldName), 
                    input  vcDatetemp (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPosting.tc_Rowid (icRowid), 
                    input  'qadfin-142515':U (icFcMsgNumber), 
                    input  vcMsgExplanation (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPosting>    
                assign viLocalReturnStatus = -1.
            end. /* test on postingdate */                
        end. /* vlFcQueryRecordsAvailable */
    end. /* Posting Date */

end. /* POSTINGBLOCK */

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