project QadFinancials > class BJournalEntry > method PostingLineGLUpdate

Description

updates on posting line for new G/L


Parameters


itPostingDateinputdateposting date
icProjectCodeinputcharacter
icCostCentreCodeinputcharacter
icComponentListinputcharacterChr(2) separated list of extra components to check during SAF defaulting.
icComponentValueListinputcharacterChr(2) separated list of extra component values to check during SAF defaulting.
icLayerTypeCodeinputcharacter
iiBusinessRelation_IDinputintegerBusiness Relation ID
icCurrencyCodeinputcharacter
icDivisionCodeinputcharacterSub-Account Code
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BJournalEntry.CreateManualPostingForGL
method BJournalEntry.UpdateManualPostingGL


program code (program6/bjournalentry.p)

empty temp-table tPostingLineSafStructures.

find first tPosting where
           tPosting.tc_Rowid = tUpdatePostingLine.tc_ParentRowid
           no-error.

if not available tPosting
then return.

if tUpdatePostingLine.tcGLCode = "":U or
   tUpdatePostingLine.tcGLCode = ?
then do:
    <M-3 run SetMessage
       (input  #T-30'You must enter the GL account code.':100(2728)T-30# (icMessage), 
        input  '' (icArguments), 
        input  'tPostingLine.tcGLCode':U (icFieldName), 
        input  '' (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  tUpdatePostingLine.tc_Rowid (icRowid), 
        input  'QADFIN-55':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    assign oiReturnStatus = -1.
    return.
end.

<M-26 run PostingLineGLEnabling
   (input  tPosting.Company_ID (iiCompanyId), 
    input  tUpdatePostingLine.tcGLCode (icGLCode), 
    input  tUpdatePostingLine.tc_Rowid (icRowid), 
    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

if viFcReturnSuper < 0 or
   oiReturnStatus  = 0
then assign oiReturnStatus = viFcReturnSuper.

if oiReturnStatus < 0
then return.

if tqGLBeginsUnitOnGLChange.tlGLIsAutomaticAccount
then do:
    <M-7 run SetMessage
       (input  #T-31'The GL account does not allow manual postings.':100(2729)T-31# (icMessage), 
        input  '' (icArguments), 
        input  'tPostingLine.tcGLCode':U (icFieldName), 
        input  tUpdatePostingLine.tcGLCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  tUpdatePostingLine.tc_Rowid (icRowid), 
        input  'QADFIN-56':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    assign oiReturnStatus = -1.
    return.
end.

if not tqGLBeginsUnitOnGLChange.tlGLIsActive
then do:
    <M-8 run SetMessage
       (input  #T-32'The GL account is not active.':100(2730)T-32# (icMessage), 
        input  '' (icArguments), 
        input  'tPostingLine.tcGLCode':U (icFieldName), 
        input  tUpdatePostingLine.tcGLCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  tUpdatePostingLine.tc_Rowid (icRowid), 
        input  'QADFIN-57':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    assign oiReturnStatus = -1.
    return.
end.

if icLayerTypeCode                      <> {&LAYERTYPECODE-OFFICIAL} and
   tqGLBeginsUnitOnGLChange.tcGLTypeCode = {&GLTYPECODE-VAT}
then do:
    <M-22 run SetMessage
       (input  #T-33'Tax postings can only be created in the official accounting layer.':100(2731)T-33# (icMessage), 
        input  '' (icArguments), 
        input  'tPostingLine.tcGLCode':U (icFieldName), 
        input  tUpdatePostingLine.tcGLCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  tUpdatePostingLine.tc_Rowid (icRowid), 
        input  'QadFin-9540':U:U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>

    assign oiReturnStatus = -1.
    return.
end.

if icLayerTypeCode                       =  {&LAYERTYPECODE-TRANSIENT} and
   tqGLBeginsUnitOnGLChange.tcGLTypeCode = {&GLTYPECODE-CROSS}
then do:
     assign vcMessage = #T-40'You cannot use a cross-company GL account &1 when posting to the transient layer.':255(617301066)T-40#
            vcMessage = substitute(vcMessage, tUpdatePostingLine.tcGLCode).
     <M-38 run SetMessage
        (input  vcMessage (icMessage), 
         input  '' (icArguments), 
         input  'tPostingLine.tcGLCode':U (icFieldName), 
         input  tUpdatePostingLine.tcGLCode (icFieldValue), 
         input  'E':U (icType), 
         input  3 (iiSeverity), 
         input  tUpdatePostingLine.tc_Rowid (icRowid), 
         input  'QadFin-8248':U (icFcMsgNumber), 
         input  '' (icFcExplanation), 
         input  '' (icFcIdentification), 
         input  '' (icFcContext), 
         output viFcReturnSuper (oiReturnStatus)) in BPosting>

    assign oiReturnStatus = -1.
    return.
end.


assign tUpdatePostingLine.GL_ID                  = tqGLBeginsUnitOnGLChange.tiGL_ID
       tUpdatePostingLine.tcGLDescription        = tqGLBeginsUnitOnGLChange.tcGLDescription
       tUpdatePostingLine.tcGLTypeCode           = tqGLBeginsUnitOnGLChange.tcGLTypeCode
       tUpdatePostingLine.tlGLIsAutomaticAccount = tqGLBeginsUnitOnGLChange.tlGLIsAutomaticAccount
       tUpdatePostingLine.tlGLIsDebitAccount     = tqGLBeginsUnitOnGLChange.tlGLIsDebitAccount
       tUpdatePostingLine.tlLinkedCrCyDaemonReqExists = false.

/* Quantity Account */
if tqGLBeginsUnitOnGLChange.tlGLIsQuantityAccount
then do:
    if tUpdatePostingLine.tcUnitCode = "":U
    then assign tUpdatePostingLine.tcUnitCode = tqGLBeginsUnitOnGLChange.tcUnitCode.
end.
else assign tUpdatePostingLine.tcUnitCode = "":U.

/* Division Account */
if tqGLBeginsUnitOnGLChange.tlGLIsDivisionAccount
then do:
   if (icDivisionCode = "":U or
       icDivisionCode = ?) and 
       tqGLBeginsUnitOnGLChange.tiDivisionProfile_ID <> 0 and 
       tqGLBeginsUnitOnGLChange.tiDivisionProfile_ID <> ?
   then do:
       <Q-4 run GetDivisionFromProfile (all) (Read) (NoCache)
          (input tPosting.Company_ID, (CompanyId)
           input tqGLBeginsUnitOnGLChange.tiDivisionProfile_ID, (DivisionProfileId)
           output dataset tqDivisionFromProfile) in BProfile >

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

       if available tqDivisionFromProfile
       then assign tUpdatePostingLine.tcDivisionCode        = tqDivisionFromProfile.tcDivisionCode
                   tUpdatePostingLine.tcDivisionDescription = tqDivisionFromProfile.tcDivisionDescription
                   tUpdatePostingLine.Division_ID           = tqDivisionFromProfile.tiDivision_ID. 
       else assign tUpdatePostingLine.tcDivisionCode        = "":U
                   tUpdatePostingLine.tcDivisionDescription = "":U
                   tUpdatePostingLine.Division_ID           = 0.               
   end.
end. /* if tqGLBeginsUnitOnGLChange.tlGLIsDivisionAccount */
else assign tUpdatePostingLine.tcDivisionCode        = "":U
            tUpdatePostingLine.tcDivisionDescription = "":U
            tUpdatePostingLine.Division_ID           = 0.

/* Cost Centre Account */
if tqGLBeginsUnitOnGLChange.tlGLIsCostCentreAccount
then do:
    if (icCostCentreCode = "":U or
        icCostCentreCode = ?) and 
       tqGLBeginsUnitOnGLChange.tiCostCentreProfile_ID <> 0 and 
       tqGLBeginsUnitOnGLChange.tiCostCentreProfile_ID <> ?
    then do:  
        <Q-5 run GetCostCentreFromProfile (all) (Read) (NoCache)
           (input tPosting.Company_ID, (CompanyId)
            input tqGLBeginsUnitOnGLChange.tiCostCentreProfile_ID, (CostCentreProfileId)
            output dataset tqCostCentreFromProfile) in BProfile >
    
        find first tqCostCentreFromProfile where
                   tqCostCentreFromProfile.tiProfile_ID = tqGLBeginsUnitOnGLChange.tiCostCentreProfile_ID
                   no-error.
    
        if available tqCostCentreFromProfile
        then do:
            assign tUpdatePostingLine.tcCostCentreCode        = tqCostCentreFromProfile.tcCostCentreCode
                   tUpdatePostingLine.tcCostCentreDescription = tqcostCentreFromProfile.tcCostCentreDescription
                   tUpdatePostingLine.CostCentre_ID           = tqCostCentreFromProfile.tiCostCentre_ID.
    
            <M-34 run GetSafStructureForCostCentre
               (input  tPosting.Company_ID (iiCompanyId), 
                input  tqGLBeginsUnitOnGLChange.tiGL_ID (iiGLId), 
                input  tqGLBeginsUnitOnGLChange.tcGLCode (icGLCode), 
                input  tUpdatePostingLine.CostCentre_ID (iiCostCentreId), 
                input  tUpdatePostingLine.tcCostCentreCode (icCostCentreCode), 
                output viDefaultSafStuctureId (oiSafStructureId), 
                output vcSafStructureCode (ocSafStructureCode), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
            if viDefaultSafStuctureId <> ? and
               viDefaultSafStuctureId <> 0 and
               vcSafStructureCode     <> ? and
               vcSafStructureCode     <> "":U
            then do:
                create tPostingLineSafStructures.
    
                assign tPostingLineSafStructures.tcSafStructureCode = vcSafStructureCode
                       tPostingLineSafStructures.tiSafStructureID   = viDefaultSafStuctureId
                       tPostingLineSafStructures.tcParentType       = {&POSTINGSAFPARENTTYPE-COSTCENTRE}.
            end.
    
            if viDefaultSafStuctureId > 0
            then do:
                <M-19 run PostingLineSafs
                   (input  viDefaultSafStuctureId (iiSafStructureID), 
                    input  vcSafStructureCode (icSafStructureCode), 
                    input  tUpdatePostingLine.tc_Rowid (icPostingLineRowid), 
                    input  {&POSTINGSAFPARENTTYPE-COSTCENTRE} (icParentType), 
                    input  tUpdatePostingLine.tcGLCode (icGLCode), 
                    input  tUpdatePostingLine.tcCostCentreCode (icCostCentreCode), 
                    input  '':U (icProjectCode), 
                    input  icComponentList (icComponentList), 
                    input  icComponentValueList (icComponentValueList), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
                if viFcReturnSuper < 0 or
                   oiReturnStatus  = 0
                then assign oiReturnStatus = viFcReturnSuper.
    
                if oiReturnStatus < 0
                then return.
            end. /*if viDefaultSafStuctureId > 0*/
        end. /*if available tqCostCentreFromProfile*/
        else assign tUpdatePostingLine.tcCostCentreCode        = "":U
                    tUpdatePostingLine.tcCostCentreDescription = "":U
                    tUpdatePostingLine.CostCentre_ID           = 0.
    end. /*if icCostCentreCode = ""*/     
    else do:
        if icCostCentreCode <> "":U and icCostCentreCode <> ?
        then do :
            <Q-43 run CostCentrePrim (all) (Read) (NoCache)
               (input tPosting.Company_ID, (CompanyId)
                input ?, (CostCentreID)
                input icCostCentreCode, (CostCentreCode)
                output dataset tqCostCentrePrim) in BCostCentre >         
            find first tqCostCentrePrim where 
                       tqCostCentrePrim.tcCostCentreCode = icCostCentreCode  
                       no-error.
            if available tqCostCentrePrim
            then assign tUpdatePostingLine.tcCostCentreCode = tqCostCentrePrim.tcCostCentreCode
                        tUpdatePostingLine.tcCostCentreDescription = tqCostCentrePrim.tcCostCentreDescription
                        tUpdatePostingLine.CostCentre_ID    = tqCostCentrePrim.tiCostCentre_ID.
            else assign tUpdatePostingLine.tcCostCentreCode = "":U
                        tUpdatePostingLine.tcCostCentreDescription = "":U
                        tUpdatePostingLine.CostCentre_ID    = 0.
        end.                        
        else assign tUpdatePostingLine.tcCostCentreCode = "":U
                    tUpdatePostingLine.tcCostCentreDescription = "":U
                    tUpdatePostingLine.CostCentre_ID    = 0.
    end. /* if icCostCentreCode <> "" */                    
end. /*if tqGLBeginsUnitOnGLChange.tlGLIsCostCentreAccount*/
else do:
    assign tUpdatePostingLine.tcCostCentreCode = "":U
           tUpdatePostingLine.tcCostCentreDescription = "":U
           tUpdatePostingLine.CostCentre_ID    = 0.
    for each tUpdatePostingSaf where
             tUpdatePostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-COSTCENTRE}:
        delete tUpdatePostingSaf.
    end.
    for each tPostingSaf where
             tPostingSaf.tc_ParentRowid       = tUpdatePostingLine.tc_Rowid and
             tPostingSaf.tc_Status           <> "D":U                       and
             tPostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-COSTCENTRE}:
        if tPostingSaf.tc_Status = "N":U
        then delete tPostingSaf.
        else assign tPostingSaf.tc_Status = "D":U.
    end.
end.

/* Project Account */
if tqGLBeginsUnitOnGLChange.tcGLAnalysisLimitation = {&GLANALYSISLIMITATION-EXCLEACHOTHER} and
   tUpdatePostingLine.tcCostCentreCode       <> "":U
then do:
    assign tUpdatePostingLine.tcProjectCode        = "":U
           tUpdatePostingLine.tcProjectDescription = "":U
           tUpdatePostingLine.Project_ID           = 0.

    for each tUpdatePostingSaf where
             tUpdatePostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-PROJECT}:
        delete tUpdatePostingSaf.
    end.

    for each tPostingSaf where
             tPostingSaf.tc_ParentRowid       = tUpdatePostingLine.tc_Rowid and
             tPostingSaf.tc_Status           <> "D":U                       and
             tPostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-PROJECT}:
        if tPostingSaf.tc_Status = "N":U
        then delete tPostingSaf.
        else assign tPostingSaf.tc_Status = "D":U.
    end.
end.
else
if tqGLBeginsUnitOnGLChange.tlGLIsProjectAccount
then do:
    if (icProjectCode = "":U or       
        icProjectCode = ?) and 
       tqGLBeginsUnitOnGLChange.tiProjectProfile_ID <> 0 and 
       tqGLBeginsUnitOnGLChange.tiProjectProfile_ID <> ?
    then do:   
        <Q-6 run GetProjectFromProfile (all) (Read) (NoCache)
           (input tPosting.Company_ID, (CompanyId)
            input tqGLBeginsUnitOnGLChange.tiProjectProfile_ID, (ProjectProfileID)
            output dataset tqProjectFromProfile) in BProfile >
    
        find first tqProjectFromProfile where 
                   tqProjectFromProfile.tiProfile_ID = tqGLBeginsUnitOnGLChange.tiProjectProfile_ID 
                   no-error.
    
        if available tqProjectFromProfile
        then do:
            assign tUpdatePostingLine.tcProjectCode        = tqProjectFromProfile.tcProjectCode
                   tUpdatePostingLine.tcProjectDescription = tqProjectFromProfile.tcProjectDescription
                   tUpdatePostingLine.Project_ID           = tqProjectFromProfile.tiProject_ID.
    
            <M-35 run GetSafStructureForProject
               (input  tPosting.Company_ID (iiCompanyId), 
                input  tqGLBeginsUnitOnGLChange.tiGL_ID (iiGLId), 
                input  tqGLBeginsUnitOnGLChange.tcGLCode (icGLCode), 
                input  tUpdatePostingLine.Project_ID (iiProjectId), 
                input  tUpdatePostingLine.tcProjectCode (icProjectCode), 
                output viDefaultSafStuctureId (oiSafStructureId), 
                output vcSafStructureCode (ocSafStructureCode), 
                output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
            if viDefaultSafStuctureId <> ? and
               viDefaultSafStuctureId <> 0 and
               vcSafStructureCode     <> ? and
               vcSafStructureCode     <> "":U
            then do:
                create tPostingLineSafStructures.
    
                assign tPostingLineSafStructures.tcSafStructureCode = vcSafStructureCode
                       tPostingLineSafStructures.tiSafStructureID   = viDefaultSafStuctureId
                       tPostingLineSafStructures.tcParentType       = {&POSTINGSAFPARENTTYPE-PROJECT}.
            end.
            
            if viDefaultSafStuctureId > 0
            then do:
                <M-21 run PostingLineSafs
                   (input  viDefaultSafStuctureId (iiSafStructureID), 
                    input  vcSafStructureCode (icSafStructureCode), 
                    input  tUpdatePostingLine.tc_Rowid (icPostingLineRowid), 
                    input  {&POSTINGSAFPARENTTYPE-PROJECT} (icParentType), 
                    input  tUpdatePostingLine.tcGLCode (icGLCode), 
                    input  '':U (icCostCentreCode), 
                    input  tUpdatePostingLine.tcProjectCode (icProjectCode), 
                    input  icComponentList (icComponentList), 
                    input  icComponentValueList (icComponentValueList), 
                    output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    
                if viFcReturnSuper < 0 or
                   oiReturnStatus  = 0
                then assign oiReturnStatus = viFcReturnSuper.
    
                if oiReturnStatus < 0
                then return.
            end. /*if viDefaultSafStuctureId > 0*/
        end. /*if available tqProjectFromProfile*/
        else assign tUpdatePostingLine.tcProjectCode        = "":U
                    tUpdatePostingLine.tcProjectDescription = "":U
                    tUpdatePostingLine.Project_ID           = 0.
    end. /* if icProjectCode = "" */    
    else do:
        if icProjectCode <> "":U and icProjectCode <> ?
        then do :
            <Q-44 run ProjectPrim (all) (Read) (NoCache)
               (input tPosting.Company_ID, (CompanyId)
                input ?, (ProjectID)
                input icProjectCode, (ProjectCode)
                output dataset tqProjectPrim) in BProject >    
            find first tqProjectPrim where 
                       tqProjectPrim.tcProjectCode = icProjectCode  
                       no-error.
            if available tqProjectPrim
            then assign tUpdatePostingLine.tcProjectCode = tqProjectPrim.tcProjectCode
                        tUpdatePostingLine.Project_ID    = tqProjectPrim.tiProject_ID.
            else assign tUpdatePostingLine.tcProjectCode        = "":U
                        tUpdatePostingLine.tcProjectDescription = "":U
                        tUpdatePostingLine.Project_ID           = 0.
        end.
        else assign tUpdatePostingLine.tcProjectCode        = "":U
                    tUpdatePostingLine.tcProjectDescription = "":U
                    tUpdatePostingLine.Project_ID           = 0.
    end. /*if icProjectCode <> ""*/                 
end. /*if tqGLBeginsUnitOnGLChange.tlGLIsProjectAccount*/
else do:
    assign tUpdatePostingLine.tcProjectCode        = "":U
           tUpdatePostingLine.tcProjectDescription = "":U
           tUpdatePostingLine.Project_ID           = 0.
    for each tUpdatePostingSaf where
             tUpdatePostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-PROJECT}:
        delete tUpdatePostingSaf.
    end.
    for each tPostingSaf where
             tPostingSaf.tc_ParentRowid       = tUpdatePostingLine.tc_Rowid and
             tPostingSaf.tc_Status           <> "D":U                       and
             tPostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-PROJECT}:
        if tPostingSaf.tc_Status = "N":U
        then delete tPostingSaf.
        else assign tPostingSaf.tc_Status = "D":U.
    end.
end.

/* InterCo Account */
if tqGLBeginsUnitOnGLChange.tlGLIsIntercoAccount
then do:
    if (iiBusinessRelation_ID <> 0 and
        iiBusinessRelation_ID <> ? )
    then do: 
    <Q-41 run BusinessRelationInterco (all) (Read) (NoCache)
       (input iiBusinessRelation_ID, (ID)
        input '':U, (Code)
        output dataset tqBusinessRelationInterco) in BBusinessRelation >
                
        find first tqBusinessRelationInterco where
                   tqBusinessRelationInterco.tiBusinessRelation_ID = iiBusinessRelation_ID no-error.                      
        if available tqBusinessRelationInterco and
                     tqBusinessRelationInterco.tlBusinessRelationIsActive
        then assign tUpdatePostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationInterco.tcBusinessRelationICCode
                    tUpdatePostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationInterco.tiBusinessRelation_ID.                                
        else assign tUpdatePostingLine.tcIntercoBusinessRelationCode = "":U
                    tUpdatePostingLine.IntercoBusinessRelation_ID    = 0.                                                                      
    end. /*IF BusinessRelation_ID <> 0 */
    else assign tUpdatePostingLine.tcIntercoBusinessRelationCode = "":U
                tUpdatePostingLine.IntercoBusinessRelation_ID    = 0.
    if (tUpdatePostingLine.tcIntercoBusinessRelationCode = "":U or
        tUpdatePostingLine.tcIntercoBusinessRelationCode = ?    or
        tqGLBeginsUnitOnGLChange.tlGLIsFixedInterco)            and
        tqGLBeginsUnitOnGLChange.tiBusinessRelation_ID <> 0     and
        tqGLBeginsUnitOnGLChange.tiBusinessRelation_ID <> ?
    then do:
        <Q-42 run BusinessRelationInterco (all) (Read) (NoCache)
           (input tqGLBeginsUnitOnGLChange.tiBusinessRelation_ID, (ID)
            input '':U, (Code)
            output dataset tqBusinessRelationInterco) in BBusinessRelation >
        find first tqBusinessRelationInterco where
                   tqBusinessRelationInterco.tiBusinessRelation_ID = tqGLBeginsUnitOnGLChange.tiBusinessRelation_ID no-error.
        if available tqBusinessRelationInterco and
                     tqBusinessRelationInterco.tlBusinessRelationIsActive
        then assign tUpdatePostingLine.tcIntercoBusinessRelationCode = tqBusinessRelationInterco.tcBusinessRelationICCode
                    tUpdatePostingLine.IntercoBusinessRelation_ID    = tqBusinessRelationInterco.tiBusinessRelation_ID.
    end. /*if (tUpdatePostingLine.tcIntercoBusinessRelationCode = "" */
end. /*if tqGLBeginsUnitOnGLChange.tlGLIsIntercoAccount*/
else assign tUpdatePostingLine.tcIntercoBusinessRelationCode = "":U
            tUpdatePostingLine.IntercoBusinessRelation_ID    = 0.

/* Foreign Currency Account */
if tqGLBeginsUnitOnGLChange.tlGLIsLocalCurrency or
   tqGLBeginsUnitOnGLChange.tiCurrency_ID = viCompanyLCId
then assign tUpdatePostingLine.tcCurrencyCode               = vcCompanyLC
            tUpdatePostingLine.Currency_ID                  = viCompanyLCId
            tUpdatePostingLine.PostingLineExchangeRate      = 1
            tUpdatePostingLine.PostingLineRateScale         = 1
            tUpdatePostingLine.tlPostingLineIsLocalCurrency = yes.
else
if tqGLBeginsUnitOnGLChange.tiCurrency_ID = 0
then assign tUpdatePostingLine.tlPostingLineIsLocalCurrency = no.  

if (icCurrencyCode                               <> "":U        and
    icCurrencyCode                               <> ?)          and
    icCurrencyCode                               <> vcCompanyLC and
    tqGLBeginsUnitOnGLChange.tlGLIsLocalCurrency =  no          and
    tqGLBeginsUnitOnGLChange.tiCurrency_ID       =  0
then do:
    <Q-45 run CurrencyPrim (all) (Read) (NoCache)
       (input icCurrencyCode, (CurrencyCode)
        input ?, (Currency_ID)
        output dataset tqCurrencyPrim) in BCurrency >
        
    find first tqCurrencyPrim where
               tqCurrencyPrim.tcCurrencyCode = icCurrencyCode
               no-error.

    if available tqCurrencyPrim 
    then assign tUpdatePostingLine.tcCurrencyCode = tqCurrencyPrim.tcCurrencyCode
                tUpdatePostingLine.Currency_ID    = tqCurrencyPrim.tiCurrency_ID.
                       
    else assign tUpdatePostingLine.tcCurrencyCode = "":U
                tUpdatePostingLine.Currency_ID    = 0.
                       
          
    assign tUpdatePostingLine.tlPostingLineIsLocalCurrency = no
           vhFcComponent                                   = ?.        
    
end. /* if icCurrencyCode */ 
     
else 
if tqGLBeginsUnitOnGLChange.tiCurrency_ID <> 0 and 
   tqGLBeginsUnitOnGLChange.tiCurrency_ID <> ?
then do : 
    <Q-9 run CurrencyById (all) (Read) (NoCache)
       (input tqGLBeginsUnitOnGLChange.tiCurrency_ID, (CurrencyId)
        output dataset tqCurrencyById) in BCurrency >

    find first tqCurrencyById where
               tqCurrencyById.tiCurrency_ID = tqGLBeginsUnitOnGLChange.tiCurrency_ID   
               no-error.

    if available tqCurrencyById and
       tUpdatePostingLine.tcCurrencyCode <> tqCurrencyById.tcCurrencyCode
    then do:
        assign tUpdatePostingLine.tcCurrencyCode               = tqCurrencyById.tcCurrencyCode
               tUpdatePostingLine.Currency_ID                  = tqCurrencyById.tiCurrency_ID
               tUpdatePostingLine.tlPostingLineIsLocalCurrency = tqCurrencyById.tiCurrency_ID = viCompanyLCId.
        
        <M-71 run GetExchangeRate
           (input  tPosting.Company_ID (iiCompanyID), 
            input  tUpdatePostingLine.Currency_ID (iiFromCurrencyID), 
            input  ? (icFromCurrencyCode), 
            input  viCompanyLCId (iiToCurrencyID), 
            input  ? (icToCurrencyCode), 
            input  ? (iiExchangeRateTypeID), 
            input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
            input  itPostingDate (itValidityDate), 
            output tUpdatePostingLine.PostingLineExchangeRate (odExchangeRate), 
            output tUpdatePostingLine.PostingLineRateScale (odExchangeScaleFactor), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>

        if viFcReturnSuper < 0 or
           oiReturnStatus  = 0
        then assign oiReturnStatus = viFcReturnSuper.

        if oiReturnStatus < 0
        then return.

        assign tUpdatePostingLine.PostingLineDebitLC  = <M-36 RoundAmount
                                                           (input  tUpdatePostingLine.PostingLineDebitTC * tUpdatePostingLine.PostingLineExchangeRate * tUpdatePostingLine.PostingLineRateScale (idUnroundedAmount), 
                                                            input  viCompanyLCId (iiCurrencyID), 
                                                            input  vcCompanyLC (icCurrencyCode)) in business>
               tUpdatePostingLine.PostingLineCreditLC = <M-37 RoundAmount
                                                           (input  tUpdatePostingLine.PostingLineCreditTC * tUpdatePostingLine.PostingLineExchangeRate * tUpdatePostingLine.PostingLineRateScale (idUnroundedAmount), 
                                                            input  viCompanyLCId (iiCurrencyID), 
                                                            input  vcCompanyLC (icCurrencyCode)) in business>.
    end.
end.

/* SAF Account */
if tqGLBeginsUnitOnGLChange.tlGLIsSafAccount
then do:
    <Q-12 run GetSafStructureLinkForGL (all) (Read) (NoCache)
       (input tqGLBeginsUnitOnGLChange.tiGL_ID, (GL_ID)
        output dataset tqSafStructureLinkForGL) in BSafStructureLink >
    find first tqSafStructureLinkForGL
               no-error.

    if available tqSafStructureLinkForGL
    then do:
        create tPostingLineSafStructures.

        assign tPostingLineSafStructures.tcParentType       = {&POSTINGSAFPARENTTYPE-GL}
               tPostingLineSafStructures.tcSafStructureCode = tqSafStructureLinkForGL.tcSafStructureCode
               tPostingLineSafStructures.tiSafStructureID   = tqSafStructureLinkForGL.tiSafStructure_ID.

        <M-11 run PostingLineSafs
           (input  tqSafStructureLinkForGL.tiSafStructure_ID (iiSafStructureID), 
            input  tqSafStructureLinkForGL.tcSafStructureCode (icSafStructureCode), 
            input  tUpdatePostingLine.tc_Rowid (icPostingLineRowid), 
            input  {&POSTINGSAFPARENTTYPE-GL} (icParentType), 
            input  tUpdatePostingLine.tcGLCode (icGLCode), 
            input  '':U (icCostCentreCode), 
            input  '':U (icProjectCode), 
            input  icComponentList (icComponentList), 
            input  icComponentValueList (icComponentValueList), 
            output oiReturnStatus (oiReturnStatus)) in BJournalEntry>
    end.
    else do:
        create tPostingLineSafStructures.

        assign tPostingLineSafStructures.tcParentType       = {&POSTINGSAFPARENTTYPE-GL}
               tPostingLineSafStructures.tcSafStructureCode = "":U
               tPostingLineSafStructures.tiSafStructureID   = ?.
    end.
end.
else do:
    for each tUpdatePostingSaf where
             tUpdatePostingSaf.PostingSafParentType  = {&POSTINGSAFPARENTTYPE-GL}:
        delete tUpdatePostingSaf.
    end.

    for each tPostingSaf where
             tPostingSaf.tc_ParentRowid       = tUpdatePostingLine.tc_Rowid and
             tPostingSaf.tc_Status           <> "D":U                       and
             tPostingSaf.PostingSafParentType = {&POSTINGSAFPARENTTYPE-GL}:
        if tPostingSaf.tc_Status = "N":U
        then delete tPostingSaf.
        else assign tPostingSaf.tc_Status = "D":U.
    end.
end.

/* Open Item Account */
if tqGLBeginsUnitOnGLChange.tcGLTypeCode = {&GLTYPECODE-OPEN}
then do:
    if tPostingLine.tcAllocationType = "":U or
        tPostingLine.tcAllocationType = ?
        then assign tUpdatePostingLine.tcAllocationType = {&ALLOCATIONTYPE-LATER}.
end.