project QadFinancials > class BBudget > method BudgetPeriodCreateByAccPeriods

Description

This method will create some budget periods base on the input information (Company, AccountingYear) and return a temp-table


Parameters


iiBudgetIDinputintegerBudget ID
iiCompanyIDinputintegerCompany wherefor you want the Accounting periods to be used as default
iiAccountingYearinputintegerAccountingYear wherefor you want the Accounting periods to be used as default
tNewBudgetPeriodoutputtemp-tableNewBudgetPeriod: temp-table containing the newly created period records
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program6/bbudget.p)

if iiBudgetID = ? then assign iiBudgetID = 0.

    /* ================================================================================================= */                                                                                                           
    /* Note; in case iiBudgetID = 0 then this method is called from the Form for the BudgetCopy-activity */
    /* This means only the output-table will be filled but no actions on the instance-data are performed */
    /* ================================================================================================= */
    
    /* ========================= */
    /* Validations / DataReading */
    /* Find the tBudget record   */
    /* ========================= */
    if iiCompanyID      = 0 or iiCompanyID      = ? or
       iiAccountingYear = 0 or iiAccountingYear = ?
    then do :
        assign oiReturnStatus = -3
               vcMessage      = trim(#T-6'You must specify the entity and the GL calendar when creating budget periods based on GL periods.':255(663)t-6#).
        <M-1 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-445':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
        Return.
    end. /* if iiCompanyID = 0 or */
    if iiBudgetID <> 0
    then do :
        find tbudget where 
             tBudget.Budget_ID = iiBudgetID
             no-lock no-error.
        if not available tBudget
        then do :
            assign oiReturnStatus = -3
                   vcMessage      = trim(substitute(#T-7'Cannot find the budget &1.':255(658)t-7#,string(iiBudgetID))).
            <M-4 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-446':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BBudget>
            Return.
        end. /* if not available tBudget */
    end. /* if iiBudgetID <> 0 */
    <Q-3 run PeriodByYearPeriod (all) (Read) (NoCache)
          (input iiCompanyID, (CompanyId)
           input iiAccountingYear, (PeriodYear)
           input ?, (PeriodPeriod)
           input ?, (PeriodId)
           output dataset tqPeriodByYearPeriod) in BPeriod >
    if not can-find (first tqPeriodByYearPeriod) 
    then return.
    
    /* ========================================================================== */
    /* Reset the output temp-table                                                */
    /* Create records in our instance and create records in the output temp-table */
    /* ========================================================================== */
    empty temp-table tNewBudgetPeriod.
    for each tqPeriodByYearPeriod no-lock :
        if iiBudgetID <> 0 and
           (not can-find(first bBudgetPeriod where
                               bBudgetPeriod.BudgetPeriodFromDate = tqPeriodByYearPeriod.ttPeriodStartDate and
                               bBudgetPeriod.BudgetPeriodTillDate = tqPeriodByYearPeriod.ttPeriodEndDate   and
                               bBudgetPeriod.tc_ParentRowid       = tBudget.tc_Rowid                       and
                               bBudgetPeriod.tc_Status           <> 'D':U))
        then do :
            <M-5 run AddDetailLine (input  'BudgetPeriod':U (icTable), 
                        input  tBudget.tc_Rowid (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BBudget>
            if viFcReturnSuper < 0 
            then do :
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end. /* if viFcReturnSuper < 0  */
            assign tBudgetPeriod.BudgetPeriodFromDate = tqPeriodByYearPeriod.ttPeriodStartDate
                   tBudgetPeriod.BudgetPeriodTillDate = tqPeriodByYearPeriod.ttPeriodEndDate
                   tBudgetPeriod.BudgetPeriodCode     = trim(#T-8'Budget Pd':12(65468)T-8#) + " ":U + string(tqPeriodByYearPeriod.tiPeriodYear) + "/":U + string(tqPeriodByYearPeriod.tiPeriodPeriod).
            create tNewBudgetPeriod.
            buffer-copy tBudgetPeriod to tNewBudgetPeriod.
        end. /* if iiBudgetID <> 0 */
        if iiBudgetID = 0
        then do:
            create tNewBudgetPeriod.
            assign tNewBudgetPeriod.BudgetPeriodFromDate = tqPeriodByYearPeriod.ttPeriodStartDate
                   tNewBudgetPeriod.BudgetPeriodTillDate = tqPeriodByYearPeriod.ttPeriodEndDate
                   tNewBudgetPeriod.BudgetPeriodCode     = trim(#T-9'Budget Pd':12(65468)T-9#) + " ":U + string(tqPeriodByYearPeriod.tiPeriodYear) + "/":U + string(tqPeriodByYearPeriod.tiPeriodPeriod)
                   tNewBudgetPeriod.tc_Rowid             = tNewBudgetPeriod.BudgetPeriodCode + string(tqPeriodByYearPeriod.ttPeriodEndDate).
        end. /* if iiBudgetID = 0 */
    end. /* for each tqPeriodByYearPeriod no-lock */