project QadFinancials > class BPosting > method GetPostingNumber

Description

get a value for tPosting.PostingVoucher


Parameters


ictcRowidinputcharactervalue of tPosting.tc_Rowid
iiYearinputintegerCurrent selected accounting year for posting
icJournalCodeinputcharacterCurrent selected journal for posting
oiVoucheroutputintegervalue for tPosting.PostingVoucher
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.AddPostingHeader
method BPosting.ApiStdMaintainMultiTT
method BPosting.ApiStdMaintainTT
method BPosting.DataLoadByInput
method BPosting.StdMaintainTT
method BPosting.ValidateComponentPre
method BPosting.ValidateComponentReversingPostingCreate
method BPosting.ValidateComponentReversingPostingModifyOriginal
method BJournalEntry.CreateEntriesPostingTemplate
method BJournalEntry.CreateRecEntryPostingTemplate
method BJournalEntry.UpdateJournalDateInPostingInstance


program code (program1/bposting.p)

/* =============================== */
/* First; All kind of validations  */
/* =============================== */
/* A number can only be taken when year and journal is available. */
if iiYear        = 0    or
   iiYear        = ?    or
   icJournalCode = "":U or
   icJournalCode = ?
then return.

/* Find the posting in the class temp-tables. */
find first tPosting where
           tPosting.tc_Rowid = ictcRowid
           no-error.
if not available tPosting
then do:
    <M-1 run SetMessage
       (input  #T-6'Invalid posting.':100(3260)t-6# (icMessage), 
        input  '' (icArguments), 
        input  '' (icFieldName), 
        input  '' (icFieldValue), 
        input  'D':U (icType), 
        input  3 (iiSeverity), 
        input  '' (icRowid), 
        input  'QADFIN-45':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    assign oiReturnStatus = -3.
    return.
end.

/* Check if journal code exists */
<Q-7 run JournalPrim (all) (Read) (NoCache)
   (input tPosting.Company_ID, (CompanyId)
    input icJournalCode, (JournalCode)
    input ?, (JournalID)
    output dataset tqJournalPrim) in BJournal >

find first tqJournalPrim where
           tqJournalPrim.tcJournalCode = icJournalCode
           no-error.
if not available tqJournalPrim
then do:
    assign vcMsgExplanation = <M-43 GetErrorExplanation
                                 (input  tPosting.tc_Rowid (icPostingRowId), 
                                  input  ? (icPostingLineRowId), 
                                  output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
    <M-8 run SetMessage
       (input  trim(#T-7'Invalid journal code ($1) passed.':255(63241)T-7#) (icMessage), 
        input  icJournalCode (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  ictcRowid (icRowid), 
        input  'QadFin-6424':U (icFcMsgNumber), 
        input  vcMsgExplanation (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BPosting>
    assign oiReturnStatus = -1.
    return.
end. /*  if not available tqJournalPrim */

/* If a number is already available, return it and leave */
if  tPosting.tcJournalCode   = icJournalCode and
    tPosting.PostingYear     = iiYear        and
    tPosting.PostingVoucher <> 0
then do:
    assign oiVoucher = tPosting.PostingVoucher.
    return.
end. /* tPosting.tcJournalCode   = icJournalCode and */


/* =========================================================================================================== */
/* From here onwards, we will get a new number and optionaly reset the previous one. Note that we will use     */
/* proper instance-includes for accessing BNumber as this is more performing than always using vhFcComponent=? */
/* =========================================================================================================== */
BNUMBERBLOCKGET : DO :
    
    /* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
    /* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop      */
    if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
    then do :
        <I-42 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION   = "false"
             &CLASS                = "BNumber"}>
    end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
    
    /* Reserve a number for this Posting                                                                */
    /* This number will be released again by housekeeping if the transaction was not committed by then. */
    <M-2 run GetNumber
       (input  tPosting.Company_ID (iiCompanyId), 
        input  iiYear (iiNumbrYear), 
        input  icJournalCode (icNumbrType), 
        output oiVoucher (oiNumber), 
        input  viFcCurrentInstanceId (iiInstanceId), 
        input  vcFcComponentName (icClassName), 
        output viFcReturnSuper (oiReturnStatus)) in BNumber>

    if viFcReturnSuper <> 0
    then assign viBlockReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0 
    then Leave BNUMBERBLOCKGET.
    
    /* Release previously reserved number.                              */
    /* Only Release in case of :                                        */
    /* - new mode                                                       */
    /* - modify mode and the previous journal was not a TRANSIENT layer */
    /* Note that in modify mode tc_status is still empty!!!             */
    if tPosting.PostingVoucher  <> 0     and
      (tPosting.tc_Status        = "N":U or
       tPosting.tc_Status       <> "N":U and 
       tPosting.tcLayerTypeCode <> {&LAYERTYPECODE-TRANSIENT})
    then do:
        <M-3 run ReleaseNumber
           (input  tPosting.Company_ID (iiCompanyId), 
            input  tPosting.PostingYear (iiNumbrYear), 
            input  tPosting.tcJournalCode (icNumbrType), 
            input  tPosting.PostingVoucher (iiNumbr), 
            input  viFcCurrentInstanceId (iiInstanceId), 
            input  vcFcComponentName (icClassName), 
            output viFcReturnSuper (oiReturnStatus)) in BNumber>

        if viFcReturnSuper <> 0
        then assign viBlockReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave BNUMBERBLOCKGET.
    end. /* if tPosting.PostingVoucher  <> 0     and */
    
END. /* BNUMBERBLOCKGET */

/* ========================================================================================== */
/* Close&Stop BNumber that is started with a different transaction before the previous block  */
/* ========================================================================================== */
if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
then do :
    <I-61 {bFcCloseAndStopInstance
         &CLASS           = "BNumber"}>
end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */

/* ========================================================================================= */
/* Capture return-status of the code in the block                                            */
/* ========================================================================================= */
if viBlockReturnStatus <> 0 
then assign oiReturnStatus = viBlockReturnStatus.
if oiReturnStatus < 0 
then return.

/* ===================== */
/* Assign the new values */
/* ===================== */
assign tPosting.PostingYear     = iiYear
       tPosting.tcJournalCode   = icJournalCode
       tPosting.Journal_ID      = tqJournalPrim.tiJournal_ID
       tPosting.tcLayerTypeCode = tqJournalPrim.tcLayerTypeCode
       tPosting.PostingVoucher  = oiVoucher.

if not can-find (tCommitNumber where
                 tCommitNumber.tcNumberType   = {&COMMITNUMBERTYPE-POSTINGVOUCHER} and
                 tCommitNumber.tcPostingRowID = tPosting.tc_Rowid)
then do :
   create tCommitNumber.
   assign tCommitNumber.tcNumberType   = {&COMMITNUMBERTYPE-POSTINGVOUCHER}
          tCommitNumber.tcPostingRowID = tPosting.tc_Rowid.             
end.