project QadFinancials > class BJournalEntry > method CreateManualPostingForGL

Description

Create a posting line and initialise the g/l account


Parameters


bcGLCodeinput-outputcharacterGL code
icProjectCodeinputcharacter
icCostCentreCodeinputcharacter
icPostingRowidinputcharactervalue of tPosting.tc_Rowid
iiSequenceinputintegerposting line sequence number (0 = add at end of journal entry)
itPostingDateinputdateposting date
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
tUpdatePostingLineoutputtemp-tableposting line
tUpdatePostingSafoutputtemp-tablesaf
tUpdatePostingLineEnablingoutputtemp-tableenabling
tPostingLineSafStructuresoutputtemp-tableSAF Structures
iiBusinessRelation_IDinputintegerBusiness Relation ID
icCurrencyCodeinputcharacter
icDivisionCodeinputcharacterSub-Account Code
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bjournalentry.p)

assign oiReturnStatus = -98
       viLocalReturn  = 0.

empty temp-table tUpdatePostingLine.
empty temp-table tUpdatePostingSaf.

/* Get Posting Header of line to be created */
find first tFcRowidConvert where
           tFcRowidConvert.tcFcOldRowid = icPostingRowid and
           tFcRowidConvert.tlFcOk no-error.
if available tFcRowidConvert
then assign icPostingRowid = tFcRowidConvert.tcFcNewRowid.


find tPosting where
     tPosting.tc_Rowid = icPostingRowid
     no-error.
if not available tPosting
then do:
    assign vcMsgJE = #T-4'Internal error: cannot create manual posting.':255(59276)T-4#.
    <M-5 run SetMessage
       (input  vcMsgJE (icMessage), 
        input  '':U (icArguments), 
        input  'icPostingRowid':U (icFieldName), 
        input  icPostingRowid (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-5952':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
    assign oiReturnStatus = -1.
    return.
end.

POSTING_LINE_BLOCK:
do:
    /* Create new posting line row*/
    <M-1 run AddDetailLine
       (input  'PostingLine':U (icTable), 
        input  icPostingRowid (icParentRowid), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    
    if viFcReturnSuper < 0 or
       viFcReturnSuper > 0 and viLocalReturn = 0
    then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then leave POSTING_LINE_BLOCK.
    
    /* Assign posting line sequence, change sequence of highers */
    if iiSequence <> 0
    then do:
        for each bline where
                 bline.PostingLineSequence >= iiSequence and
                 bline.PostingLineSequence  < tPostingLine.PostingLineSequence:
            
            assign bline.PostingLineSequence = bline.PostingLineSequence + 1.
            if bline.tc_Status = ""
            then assign bline.tc_Status = "C":U.
        end.
        assign tPostingLine.PostingLineSequence = iiSequence.
    end.
    
    /* Create output record for update of UI */
    create tUpdatePostingLine.
    raw-transfer tPostingLine to tUpdatePostingLine.
    assign tUpdatePostingLine.tcGLCode       = bcGLCode
           tUpdatePostingLine.tcDivisionCode = icDivisionCode.
    
    if bcGLCode <> "":U
    then do:
        <Q-7 run GLBeginsUnitOnGLChange (all) (Read) (NoCache)
           (input tPostingLine.Company_ID, (CompanyID)
            input bcGLCode, (GLCode)
            output dataset tqGLBeginsUnitOnGLChange) in BGL >
        
        /* Try exact match of G/L account */
        find tqGLBeginsUnitOnGLChange where
             tqGLBeginsUnitOnGLChange.tcGLCode = bcGLCode no-error.
        
        /* Try if there is only one account beggining with enetered value */
        if not available tqGLBeginsUnitOnGLChange
        then find tqGLBeginsUnitOnGLChange where
                  tqGLBeginsUnitOnGLChange.tcGLCode BEGINS bcGLCode no-error.
        
        /* If still there is not any account -> Error */
        if not available tqGLBeginsUnitOnGLChange
        then do:
            assign viLocalReturn = -4.
            leave POSTING_LINE_BLOCK.
        end.
                    
        assign bcGLCode                      = tqGLBeginsUnitOnGLChange.tcGLCode
               tUpdatePostingLine.tcUnitCode = tqGLBeginsUnitOnGLChange.tcUnitCode
               tUpdatePostingLine.tcGLCode   = bcGLCode.
        
        <M-2 run PostingLineGLUpdate
           (input  itPostingDate (itPostingDate), 
            input  icProjectCode (icProjectCode), 
            input  icCostCentreCode (icCostCentreCode), 
            input  icComponentList (icComponentList), 
            input  icComponentValueList (icComponentValueList), 
            input  icLayerTypeCode (icLayerTypeCode), 
            input  iiBusinessRelation_ID (iiBusinessRelation_ID), 
            input  icCurrencyCode (icCurrencyCode), 
            input  icDivisionCode (icDivisionCode), 
            output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
        if viFcReturnSuper < 0 or
           viFcReturnSuper > 0 and viLocalReturn = 0
        then assign viLocalReturn = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then leave POSTING_LINE_BLOCK.
    end.
end. /* POSTING_LINE_ROW: */

/* If there was any error, delete created posting line */
if viLocalReturn < 0
then do:
    for each tPostingSaf where 
             tPostingSaf.tc_ParentRowid = tPostingLine.tc_Rowid:
        delete tPostingSaf.
    end.
    delete tPostingLine.

    empty temp-table tUpdatePostingSaf.
    delete tUpdatePostingLine.
end.

/* Return handling */
assign oiReturnStatus = viLocalReturn.