project QadFinancials > class BPostingTemplate > method UpdateTemplateTimesUsed

Description

Update the number of time a Template is used and the last-usage date


Parameters


iiCompanyIdinputinteger
icTemplateCodeinputcharacterTemplateCode
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.AdditionalUpdatesTemplate


program code (program1/bpostingtemplate.p)

/* ============================================================================== */
/* Normalize input parameters                                                     */
/* ============================================================================== */
if iiCompanyId = 0 then assign iiCompanyId = viCompanyId.
if iiCompanyId = ? then assign iiCompanyId = viCompanyId.

/* ============================================================================== */
/* Read data from database (if necessary)                                         */
/* ============================================================================== */
if not can-find(first tPostingTemplate where
                      tPostingTemplate.Company_ID          = iiCompanyId and
                      tPostingTemplate.PostingTemplateCode = icTemplateCode)
then do:
    empty temp-table tFcDynRel.
    create tFcDynRel.
    assign tFcDynRel.tcFcFrom    = ""
           tFcDynRel.tcFcTo      = "PostingTemplate":U
           tFcDynRel.tcFcRel     = "for each PostingTemplate where ":U +
                                            "PostingTemplate.PostingTemplateCode = '":U + icTemplateCode + "' and ":U +
                                            "PostingTemplate.Company_ID = ":U + string(iiCompanyId)
           tFcDynRel.thFcBuffer  = buffer t_oPostingTemplate:handle
           tFcDynRel.thFcIBuffer = buffer t_iPostingTemplate:handle.
    <M-1 run StartPersistence (output vhFcComponent (ohPersistence), 
                           output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
    <M-2 run ReadData
          (input  tFcDynRel (tDynRel), 
           input  {&TARGETPROCEDURE} (ihClass), 
           output oiReturnStatus (oiReturnStatus)) in persistence>
    if oiReturnStatus <> 0
    then return.
end.

find first tPostingTemplate where
           tPostingTemplate.Company_ID          = iiCompanyId and
           tPostingTemplate.PostingTemplateCode = icTemplateCode no-error.
if not available tPostingTemplate
then do:
    <M-3 run SetMessage (input  #T-4'The template code cannot be found.':100(2733)t-4# (icMessage),
                     input  '' (icArguments),
                     input  'tPosting.tcTemplateCode':U (icFieldName),
                     input  icTemplateCode (icFieldValue),
                     input  'E':U (icType),
                     input  3 (iiSeverity),
                     input  '' (icRowid),
                     input  'QADFIN-643':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BPostingTemplate>
    assign oiReturnStatus = -1.
    return.
end.

assign tPostingTemplate.PostingTemplateDateLastUse = today
       tPostingTemplate.PostingTemplateTimesUsed   = tPostingTemplate.PostingTemplateTimesUsed + 1.

if tPostingTemplate.tc_Status <> "N":U
then assign tPostingTemplate.tc_Status = "C":U.