project QadFinancials > class BRecurringEntry > method ApiPostRecEntryCommit

Description

Api Method that will execute the postings for the selected recurring entry lines (Temp-table).


Parameters


tProposedPostinginput-outputtemp-tableTemp-table to pass the selected Recurring Entry Lines that need to be posted (The remaining proposal lines will be returned in case an error occurs).
tChangedPostingLinesinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/brecurringentry.p)

/* ============================================================================= */
/* Purpose of this method                                                        */
/* ----------------------                                                        */
/* This method will receive a temp-table with all proposed postings              */
/*    (Based on the Recurring Entries and Recurring Entry Lines)                 */
/* A posting will be done for each of these tt-records when ToPost = true        */
/* A reverse posting will also be done if required.                              */
/* The status and amount of the Recurring Entry Line will be updated.            */
/* In case an error occurs: The correct posting will not be removed.             */
/* The method returns all proposed posting records that are not posted correctly */
/* ============================================================================= */

/* =============================================== */
/* check if there is at least one record available */
/* =============================================== */
find first tProposedPosting no-error.
if not available tProposedPosting
then do:
    assign vcMessageRE    = trim(#T-19'There must be at least one posting to run in the selection.':255(3515)t-19#)
           oiReturnStatus = -1.
    <M-3 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1000':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
    return.
end.

for each tProposedPosting no-lock:
    /* ================================ */
    /* Test for valid temp-table record */
    /* ================================ */
    
    /* Test if ToPost and IsUpdated are true/false */
    if tProposedPosting.tlPPToPost    = ? or
       tProposedPosting.tlPPIsUpdated = ?
    then do:
        assign vcMessageRE    = trim(#T-20'The To Post and Is Updated fields must be selected or cleared.':255(3516)T-20#)
               oiReturnStatus = -1.
        <M-9 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1004':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.
    
    /* Test if Mandatory records are modified */
    if tProposedPosting.tcPPRecEntryUpdate = {&RECENTRYUPDATE-MANDATORY} and
       tProposedPosting.tlPPIsUpdated      = false
    then do:
        assign vcMessageRE    = trim(#T-21'You must update lines with an update status of Mandatory.':255(3517)t-21#) + chr(10) +
                                trim(substitute(#T-22'Recurring entry line code: &1.':255(3518)T-22#, trim(tProposedPosting.tcPPRecEntryLineCode) ))
               oiReturnStatus = -1.
        <M-10 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1005':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.

    /* Test ID's for 0 or ? */
    if tProposedPosting.tiPPRecEntryID     = 0 or
       tProposedPosting.tiPPRecEntryID     = ? or
       tProposedPosting.tiPPRecEntryLineID = 0 or
       tProposedPosting.tiPPRecEntryLineID = ?
    then do:
        assign vcMessageRE    = trim(#T-23'The IDs of the recurring entries are not correct.':255(3519)T-23#) + chr(10) +
                                trim(substitute(#T-24'Recurring Entry Line Code: &1.':200(3520)t-24#, trim(tProposedPosting.tcPPRecEntryLineCode) ))
               oiReturnStatus = -1.
        <M-11 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'D':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1006':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.

    /* ================== */
    /* Clear the Instance */
    /* ================== */
    <M-1 run ClearData (output oiReturnStatus (oiReturnStatus)) in BRecurringEntry>
    if oiReturnStatus < 0 then return.

    /* ========================== */
    /* Run Stop External Instance */
    /* ========================== */
    <M-30 run StopExternalInstances
       (output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>

    /* ======== */
    /* Dataload */
    /* ======== */
    <M-5 run DataLoad
          (input  '':U (icRowids), 
           input  tProposedPosting.tiPPRecEntryID (icPkeys), 
           input  '':U (icObjectIds), 
           input  '' (icFreeform), 
           input  false (ilKeepPrevious), 
           output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
    if viFcReturnSuper <> 0
    then do:
        assign vcMessageRE    = trim(#T-25'The data could not be loaded. The system was unable to load the recurring entry.':255(3521)t-25#) + chr(10) +
                                trim(substitute("RecEntry_ID: &1.":U, string(tProposedPosting.tiPPRecEntryID)))
               oiReturnStatus = viFcReturnSuper.
        <M-6 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1001':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.

    /* =========================== */
    /* Update Recurring Entry Data */
    /* =========================== */
    
    /* Find recurring Entry */
    find tRecEntry where 
         tRecEntry.RecEntry_ID = tProposedPosting.tiPPRecEntryID
         no-error.
    if not available tRecEntry
    then do:
        assign vcMessageRE    = trim(#T-26'The recurring entry is not defined in the system.':255(3522)t-26#) + chr(10) +
                                trim(substitute("RecEntry_ID: &1.":U, string(tProposedPosting.tiPPRecEntryID)))
               oiReturnStatus = -3.
        <M-7 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1002':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.

    /* Find Recurring Entry Line */
    find tRecEntryLine where 
         tRecEntryLine.RecEntryLine_ID = tProposedPosting.tiPPRecEntryLineID
         no-error.
    if not available tRecEntryLine
    then do:
        assign vcMessageRE    = trim(#T-27'Recurring entry line not found.':255(3523)T-27#) + chr(10) +
                                trim(substitute("RecEntryLine_ID: &1.":U, string(tProposedPosting.tiPPRecEntryLineID)))
               oiReturnStatus = -3.
        <M-8 run SetMessage (input  vcMessageRE (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1003':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        leave.
    end.

    /* Update the Recurring Entry Line */
    if tProposedPosting.tlPPToPost = false
    then assign tRecEntryLine.tc_Status          = 'C':U.
    else do:
        assign tRecEntryLine.RecEntryLineStatus   = {&RECENTRYLINESTATUS-POSTED}
               tRecEntryLine.RecEntryLineAmountLC = tProposedPosting.tdPPRecEntryLineAmountLC
               tRecEntryLine.tc_Status            = 'C':U.
    
        /* ================================= */
        /* PERFORM POSTINGS IN JOURNAL ENTRY */
        /* ================================= */
        /* ================================================== */
        /* Start And Open Journal action (add to transaction) */
        /* ================================================== */      
        <I-12 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION = "true"
            &CLASS              = "BJournalEntry"}>
    
        /* =================================== */
        /* Create posting & Reversing posting  */
        /* Close or CloseAndStop BJournalEntry */
        /* =================================== */
        <M-13 run CreateRecEntryPosting
           (input  viCompanyId (iiCompanyId), 
            input  tRecEntryLine.Period_ID (iiPeriodID), 
            input  tRecEntry.tcJournalCode (icJournalCode), 
            input  tRecEntryLine.RecEntryLinePostingDate (itPostingDate), 
            input  tRecEntryLine.RecEntryLineCode (icPostingText), 
            input  tProposedPosting.tiPPRecEntryLineID (iiRecEntryLineId), 
            input  tRecEntry.tcPostingTemplateCode (icTemplateCode), 
            input  tRecEntryLine.RecEntryLineAmountLC (idAmountLC), 
            input  tRecEntry.tc_Rowid (icRowid), 
            input  tRecEntryLine.RecEntryLineReversingDate (itReversingDate), 
            input  tChangedPostingLines (tChangedEntryLine), 
            output viExternalReturnStatus (oiReturnStatus)) in BJournalEntry>
        <I-28 {bFcCloseInstance
            &CLASS           = "BJournalEntry"}>
        if viExternalReturnStatus < 0 or (viExternalReturnStatus > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viExternalReturnStatus.        
        if oiReturnStatus < 0
        then do :
            <I-29 {bFcCloseAndStopInstance
            &CLASS           = "BJournalEntry"}>
            return.
        end.
    end. /* if tProposedPosting.tlPPToPost = false */

    /* ================================================================ */
    /* Create new Recurring Entry Line for Open Ended Recurring Entries */
    /* ================================================================ */
    if tRecEntry.RecEntryIsOpenEnded = true
    then do:
        /* Get next posting-date                    */
        /* Period -> Start date of next period      */
        /* Quarterly -> Add three months, first day */
        /* Weekly -> Add 7 days                     */
        /* Monthly -> Add one month, same day       */
        if tRecEntry.RecEntryFreq = {&RECENTRYFREQ-PERIOD}
        then do:
            <M-17 run GetNextPeriod (input  tRecEntryLine.Period_ID (iiPeriodID), 
                         input  ? (iiPeriodYear), 
                         input  ? (iiPeriodPeriod), 
                         output viNextPeriodPeriodID (oiPeriodID), 
                         output viNextPeriodYear (oiPeriodYear), 
                         output viNextPeriodPeriod (oiPeriodPeriod), 
                         output vtPostingDate (otPeriodStartDate), 
                         output vtNextPeriodEndDate (otPeriodEndDate), 
                         output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
            if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
            then assign oiReturnStatus = viFcReturnSuper.
            if oiReturnStatus < 0
            then leave.     
        end.
    
        if tRecEntry.RecEntryFreq = {&RECENTRYFREQ-QUARTERLY} or
           tRecEntry.RecEntryFreq = {&RECENTRYFREQ-MONTHLY}
        then do:
            assign viNextDay   = day(tRecEntry.RecEntryStartDate)
                   viNextMonth = month(tRecEntryLine.RecEntryLinePostingDate) + (if tRecEntry.RecEntryFreq = {&RECENTRYFREQ-QUARTERLY} then 3 else 1) 
                   viNextYear  = year(tRecEntryLine.RecEntryLinePostingDate).
            if viNextMonth > 12
            then assign viNextMonth = viNextMonth - 12
                        viNextYear  = viNextYear + 1.
            repeat:
                assign vtPostingDate = date(viNextMonth, viNextDay, viNextYear) no-error. 
                if error-status:error
                then assign viNextDay = viNextDay - 1.
                else leave.
            end.
        end.
        
        if tRecEntry.RecEntryFreq = {&RECENTRYFREQ-WEEKLY}
        then assign vtPostingDate = tRecEntryLine.RecEntryLinePostingDate + 7.
        
        if vtPostingDate > tRecEntry.RecEntryEndDate
        then leave.
    
        <M-18 run GenerateCalendar
           (input  tRecEntry.tc_Rowid (icRecEntryRowid), 
            input  tRecEntry.RecEntryFreq (icRecEntryFreq), 
            input  vtPostingDate (itRecEntryStartDate), 
            input  tRecEntry.RecEntryIsOpenEnded (ilRecEntryIsOpenEnded), 
            input  tRecEntry.RecEntryEndDate (itRecEntryEndDate), 
            input  tRecEntry.RecEntryIsAmountApply (ilRecEntryIsAmountApply), 
            input  tRecEntry.RecEntryAmountLC (idRecEntryAmountLC), 
            input  tRecEntry.RecEntryIsReversing (ilRecEntryIsReversing), 
            input  tRecEntry.RecEntryCode (icRecEntryCode), 
            input  False (ilToBeDeleted), 
            input  tProposedPosting.tlPPToPost (ilToPost), 
            output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
        if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
        then assign oiReturnStatus = viFcReturnSuper.        
        if oiReturnStatus < 0
        then return.    
    end. /* if open end */

    /* ====================================== */
    /* Run Validate Component BRecurringEntry */
    /* ====================================== */
    assign vlSkipStopExternalInstances = true.
    <M-14 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
    assign vlSkipStopExternalInstances = false.
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    

    /* ==================== */
    /* Run Addition Updates */
    /* ==================== */
    <M-15 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    

    /* ============================================================== */
    /* Run Datasave for BRecurringEntry                               */
    /* This will also finalise the previous datasave of BJournalEntry */
    /* ============================================================== */
    <M-16 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BRecurringEntry>
    if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
    then assign oiReturnStatus = viFcReturnSuper.        
    if oiReturnStatus < 0
    then return.    

    /* ================================== */
    /* Delete the Proposed Posting record */
    /* ================================== */
    delete tProposedPosting.
end. /* for each tProposedPosting */