project QadFinancials > class BPosting > method AddPostingSub

Description

sub


Parameters


icGLCodeinputcharacterGL Account
icDivisionCodeinputcharacterSub-Account Code
icCurrencyCodeinputcharacterCurrency Code
icBusinessRelationIntercoCodeinputcharacterBusinessRelationIntercoCode
ilLinkedCrCyDaemonReqExistsinputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.AddControlPosting
method BPosting.AddStandardPosting


program code (program1/bposting.p)

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

/* =================== */
/* Start Block         */
/* =================== */
ADDPOSTINGSUBBLOCK: DO :

    /* =================== */
    /* Param Valdiations   */
    /* =================== */
    if icGLCode = "":U or 
       icGLCode = ?
    then do:
        assign vcMessage           = trim(#T-14'You must enter the GL account to create a posting line.':150(999890614)T-14#)
               viLocalReturnStatus = -3.
        <M-10 run SetMessage (input  vcMessage (icMessage),
                         input  '':U (icArguments),
                         input  '':U (icFieldName),
                         input  '':U (icFieldValue),
                         input  'E':U (icType),
                         input  3 (iiSeverity),
                         input  '':U (icRowid),
                         input  'QADFIN-871':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDPOSTINGSUBBLOCK.
    end. /* if icGLCode = "":U or */
    
    /* =========================== */
    /* Retrieve the GL from the DB */
    /* =========================== */
    <Q-16 run GLForPostingLineCreation (all) (Read) (Cache)
       (input tPosting.Company_ID, (CompanyID)
        input icGLCode, (GLCode)
        input ?, (GLId)
        output dataset tqGLForPostingLineCreation) in BGL>

    find tqGLForPostingLineCreation where
         tqGLForPostingLineCreation.tcGLCode = icGLCode
         no-lock no-error.
    if not available tqGLForPostingLineCreation
    then do:
        assign vcMessage           = trim(substitute(#T-15'The GL account &1 cannot be found.':150(999890615)T-15#, icGLCode))
               viLocalReturnStatus = -3.
        <M-11 run SetMessage (input  vcMessage (icMessage),
                         input  '':U (icArguments),
                         input  '':U (icFieldName),
                         input  '':U (icFieldValue),
                         input  'E':U (icType),
                         input  3 (iiSeverity),
                         input  '':U (icRowid),
                         input  'QADFIN-872':U (icFcMsgNumber),
                         input  '' (icFcExplanation),
                         input  '' (icFcIdentification),
                         input  '' (icFcContext),
                         output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave ADDPOSTINGSUBBLOCK. 
    end. /* if not available tqGLForPostingLineCreation */    

    /* ================================================================================*/
    /* Get the first free sequence .Create a PostingLine and assign its main fields    */
    /* We use a find last + internal index to get the highest PostingLineSequence used */
    /* =============================================================================== */
    assign viCounter = 0.
    for last bPostingLine where 
             bPostingLine.tc_Status      <> "D":U and
             bPostingLine.Posting_ID = tPosting.Posting_ID
             use-index PostingIDLineSeq:
        assign viCounter = bPostingLine.PostingLineSequence.
    end. /* for each bPostingLine where */

    <M-2 run AddDetailLine
       (input  'PostingLine':U (icTable), 
        input  tPosting.tc_Rowid (icParentRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    if viFcReturnSuper <> 0
    then assign viLocalReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave ADDPOSTINGSUBBLOCK. 
    assign tPostingLine.PostingLineSequence    = viCounter + 1
           tPostingLine.Posting_ID             = tPosting.Posting_ID
           tPostingLine.GL_ID                  = tqGLForPostingLineCreation.tiGL_ID
           tPostingLine.tcGLCode               = tqGLForPostingLineCreation.tcGLCode
           tPostingLine.tcGLTypeCode           = tqGLForPostingLineCreation.tcGLTypeCode
           tPostingLine.tlGLIsAutomaticAccount = tqGLForPostingLineCreation.tlGLIsAutomaticAccount
           tPostingLine.tcGLDescription        = tqGLForPostingLineCreation.tcGLDescription
           tPostingLine.tlGLIsDebitAccount     = tqGLForPostingLineCreation.tlGLIsDebitAccount
           tPostingLine.tlLinkedCrCyDaemonReqExists     = ilLinkedCrCyDaemonReqExists.
    /*  The closing and re-open postings should be on GL level only  */
    if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING}
    then do:
        if tqGLForPostingLineCreation.tlGLIsDivisionAccount
        then do:
            if icDivisionCode = ""
            or icDivisionCode = ?
            then do:
                if (tqGLForPostingLineCreation.tiDivisionProfile_ID <> 0 and tqGLForPostingLineCreation.tiDivisionProfile_ID <> ?)
                then do:
                    <Q-3 run GetDivisionFromProfile (all) (Read) (Cache)
                       (input tPosting.Company_ID, (CompanyId)
                        input tqGLForPostingLineCreation.tiDivisionProfile_ID, (DivisionProfileId)
                        output dataset tqDivisionFromProfile) in BProfile>

                    find first tqDivisionFromProfile where
                               tqDivisionFromProfile.tiProfile_ID = tqGLForPostingLineCreation.tiDivisionProfile_ID
                               no-error.

                    if available tqDivisionFromProfile
                    then assign tPostingLine.Division_ID           = tqDivisionFromProfile.tiDivision_ID
                                tPostingLine.tcDivisionCode        = tqDivisionFromProfile.tcDivisionCode
                                tPostingLine.tcDivisionDescription = tqDivisionFromProfile.tcDivisionDescription.

                end. /* end of if (tqGLForPostingLineCreation.tiDivisionProfile_ID <> 0  */
            end. /* end of if icDivisionCode = "" */
            else do:
                <Q-4 run DivisionPrim (all) (Read) (Cache)
                   (input tPosting.Company_ID, (CompanyId)
                    input 0, (DivisionID)
                    input icDivisionCode, (DivisionCode)
                    output dataset tqDivisionPrim) in BDivision>

                find first tqDivisionPrim where
                           tqDivisionPrim.tcDivisionCode = icDivisionCode
                           no-error.
                if available tqDivisionPrim
                then assign tPostingLine.Division_ID           = tqDivisionPrim.tiDivision_ID
                            tPostingLine.tcDivisionCode        = tqDivisionPrim.tcDivisionCode
                            tPostingLine.tcDivisionDescription = tqDivisionPrim.tcDivisionDescription.
            end. /* end of else do */
        end. /* end of if tqGLForPostingLineCreation.tlGLIsDivisionAccount */
    end. /* end of if tPosting.tcPeriodTypeCode <> {&PERIODTYPECODE-YEARCLOSING} */
    
    /* fill in division code to the postingline if the year end closing posting needs */
    if tPosting.tcPeriodTypeCode                        = {&PERIODTYPECODE-YEARCLOSING} and
       tqGLForPostingLineCreation.tlGLIsDivisionAccount = true                          and
       icDivisionCode                                   <> ""                           and
       icDivisionCode                                   <> ?                           
    then do:
        <Q-17 run DivisionPrim (all) (Read) (Cache)
           (input tPosting.Company_ID, (CompanyId)
            input 0, (DivisionID)
            input icDivisionCode, (DivisionCode)
            output dataset tqDivisionPrim) in BDivision>

    find first tqDivisionPrim where
               tqDivisionPrim.tcDivisionCode = icDivisionCode
               no-error.
    if available tqDivisionPrim
    then assign tPostingLine.Division_ID           = tqDivisionPrim.tiDivision_ID
                tPostingLine.tcDivisionCode        = tqDivisionPrim.tcDivisionCode
                tPostingLine.tcDivisionDescription = tqDivisionPrim.tcDivisionDescription.           
    end.

    if icCurrencyCode = vcCompanyLC
    or icCurrencyCode = ""
    or icCurrencyCode = ?
    then assign tPostingLine.Currency_ID    = viCompanyLCId
                tPostingLine.tcCurrencyCode = vcCompanyLC
                tPostingLine.tlPostingLineIsLocalCurrency = yes.
    else do:
        <Q-5 run CurrencyPrim (all) (Read) (Cache)
           (input icCurrencyCode, (CurrencyCode)
            input 0, (Currency_ID)
            output dataset tqCurrencyPrim) in BCurrency>

        find first tqCurrencyPrim where
                   tqCurrencyPrim.tcCurrencyCode = icCurrencyCode
                   no-error.
        if available tqCurrencyPrim
        then assign tPostingLine.Currency_ID    = tqCurrencyPrim.tiCurrency_ID
                    tPostingLine.tcCurrencyCode = tqCurrencyPrim.tcCurrencyCode
                    tPostingLine.tlPostingLineIsLocalCurrency = no.
    end.
    
    if tqGLForPostingLineCreation.tlGLIsIntercoAccount
    then do:
        if tqGLForPostingLineCreation.tlGLIsFixedInterco
        or icBusinessRelationIntercoCode = ""
        or icBusinessRelationIntercoCode = ?
        then do:
            if tqGLForPostingLineCreation.tiBusinessRelation_ID <> 0 and 
               tqGLForPostingLineCreation.tiBusinessRelation_ID <> ?
            then do:
                <Q-12 run BusinessRelationByIDCodeIC (all) (Read) (Cache)
                   (input tqGLForPostingLineCreation.tiBusinessRelation_ID, (BusinessRelationID)
                    input ?, (BusinessRelationCode)
                    input ?, (BusinessRelationIntercoCode)
                    input true, (BusinessRelationIsActive)
                    output dataset tqBusinessRelationByIDCodeIC) in BBusinessRelation>

                find first tqBusinessRelationByIDCodeIC where
                           tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID = tqGLForPostingLineCreation.tiBusinessRelation_ID
                           no-error.
                if available tqBusinessRelationByIDCodeIC
                then assign tPostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID
                            tPostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode.                        
            end.
        end.
        else do:
             <Q-13 run BusinessRelationByIDCodeIC (all) (Read) (Cache)
                (input ?, (BusinessRelationID)
                 input ?, (BusinessRelationCode)
                 input icBusinessRelationIntercoCode, (BusinessRelationIntercoCode)
                 input true, (BusinessRelationIsActive)
                 output dataset tqBusinessRelationByIDCodeIC) in BBusinessRelation>

            find first tqBusinessRelationByIDCodeIC where
                           tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode = Icbusinessrelationintercocode
                       no-error.
            if available tqBusinessRelationByIDCodeIC 
            then assign tPostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID
                        tPostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationByIDCodeIC.tcBusinessRelationICCode.
        end.
    end.

END. /* ADDPOSTINGSUBBLOCK */

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