project QadFinancials > class BPeriod > method ApiActivatePeriodForPeriodicCosting

Description

ApiActivatePeriodForPeriodicCosting: Open a period specified by the domain, company, from-year and from-period for PeriodicCosting.
When the company is not specified, then all periods matching the other input will be opened for PeriodicCosting


Parameters


icDomainCodeinputcharacterParameter holding the domain of the periods. This has to be the current domain and if this parameter is empty then we will use the current domain for it
icCompanyCodeinputcharacterCompany: this parameter has to be either empty, either it has to point to a company in the current domain
iiFromPeriodYearinputintegerFrom Accounting year: mandatory
iiFromPeriodPeriodinputintegerFrom Accounting Period: mandatory
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program9/bperiod.p)

/* =============================== */
    /* Exception handling - main block */
    /* Default output                  */
    /* =============================== */
    assign oiReturnStatus                   = -98
           viLocalReturnStatus              = 0.
    MAINACTBLOCK: DO :
        
        /* ================== */
        /* Validate the input */
        /* ================== */
        if icDomainCode = "":U or 
           icDomainCode = ?
        then assign icDomainCode = vcDomainCode.
        if icCompanyCode = ? then assign icCompanyCode = "":U.
        if iiFromPeriodYear   = 0 or 
           iiFromPeriodYear   = ? or 
           iiFromPeriodPeriod = 0 or 
           iiFromPeriodPeriod = ?
        then do :
            assign viLocalReturnStatus = -1
                   vcMessage = trim(substitute(#T-65'The Year (&1) and Period (&2) are mandatory parameters for the API method.':255(733734752)T-65#, iiFromPeriodYear, iiFromPeriodPeriod)).
            <M-42 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-378817':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            Leave MAINACTBLOCK.
        end. /* if iiFromPeriodYear   = 0 or */
        if icDomainCode <> vcDomainCode
        then do :
            assign viLocalReturnStatus = -1
                   vcMessage = trim(substitute(#T-44'The Domain (&1) that was passed as parameter for the API method should either be the current domain either empty.':255(332051464)T-44#, icDomainCode)).
            <M-61 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-815349':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            Leave MAINACTBLOCK.
        end. /*  if icDomainCode <> vcDomainCode */
        <Q-35 run DomainForCompanyDomain (all) (Read) (NoCache)
           (input ?, (DomainID)
            input icDomainCode, (DomainCode)
            input ?, (CompanyID)
            input icCompanyCode, (CompanyCode)
            output dataset tqDomainForCompanyDomain) in BDomain >
        Find first tqDomainForCompanyDomain where 
                   tqDomainForCompanyDomain.tcDomainCode = icDomainCode
                   no-lock no-error.
        if not available tqDomainForCompanyDomain
        then do :
            assign viLocalReturnStatus = -1
                   vcMessage = trim(substitute(#T-74'Internal error: unable to find the current domain (&1).':255(413947993)T-74#, icDomainCode)).
            <M-28 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-479434':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            Leave MAINACTBLOCK.
        end. /* if not available tqDomainForCompanyDomain */
        if icCompanyCode <> "":U 
        then do :
            Find first tqDomainForCompanyDomain where 
                       tqDomainForCompanyDomain.tcDomainCode  = icDomainCode and 
                       tqDomainForCompanyDomain.tcCompanyCode = icCompanyCode
                       no-lock no-error.
            if not available tqDomainForCompanyDomain
            then do :
                assign viLocalReturnStatus = -1
                       vcMessage = trim(substitute(#T-69'The Entity (&1) that was passed as parameter for the API method should belong to the current domain (&2).':255(519388136)T-69#, icCompanyCode, icDomainCode)).
                <M-78 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-933182':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                Leave MAINACTBLOCK.
            end. /* if not available tqDomainForCompanyDomain */
        end. /* if icCompanyCode <> "":U  */
        
        /* ================================================================ */
        /* Run a ClearData to make sure we start from scratch               */
        /* ================================================================ */
        <M-57 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave MAINACTBLOCK.
        
        /* ========================================================================================================= */
        /* Call DataLoad with a free-form that will hold a where-clause for every record in tqDomainForCompanyDomain */
        /* All such where-clauses will be point to a single period record and they will be joint together with 'Or'  */
        /* We will just raise an error in case vcFreeForm gets longer than 30K: we can never have so many companies  */
        /* in a functional domain and this way we avoid going over the mnaximum length for character fields          */
        /* ========================================================================================================= */
        assign vcFreeForm = "":U.
        for each tqDomainForCompanyDomain where 
                 tqDomainForCompanyDomain.tcDomainCode  = icDomainCode:
            assign vcFreeForm = vcFreeForm + 
                                (if vcFreeForm = "":U 
                                 then "":U 
                                 else " Or ":U) + 
                                "(Period.Company_ID = ":U + string(tqDomainForCompanyDomain.tiCompany_ID) + " and ":U + 
                                " Period.PeriodYearPeriod >= ":U + string((iiFromPeriodYear * 100) + iiFromPeriodPeriod) + ") ":U.
            If length(vcFreeForm,'Character':U) > 30000
            then do : 
                assign viLocalReturnStatus = -1
                       vcMessage = trim(substitute(#T-10'The Domain (&1) contains to many entities to load all periods for the entities.':255(915889653)T-10#, icDomainCode)) + chr(10) + 
                                   trim(substitute(#T-72'Free-form sting for the DataLoad: &1':255(606042433)T-72#,vcFreeForm)).
                <M-20 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-501817':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                Leave MAINACTBLOCK.
            end. /* If length(vcFreeForm,'Character':U) > 30000 */
        end. /* for each tqDomainForCompanyDomain where */
        assign vcFreeForm = "For each Period where ":U + vcFreeForm.                            
        <M-86 run DataLoad
           (input  '':U (icRowids), 
            input  '':U (icPkeys), 
            input  '':U (icObjectIds), 
            input  vcFreeForm (icFreeform), 
            input  false (ilKeepPrevious), 
            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0 and viFcReturnSuper <> -4 /* ignore -4 -meaning nothing is read- as that is validated later on with a proper message */
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 and viFcReturnSuper <> -4 /* ignore -4 -meaning nothing is read- as that is validated later on with a proper message */
        then Leave MAINACTBLOCK.
        
        /* ======================================================================================================= */
        /* Raise a warning case no data was loaded and stop the processing                                         */
        /* Raise a warning in case the loaded once were already closed for PeriodicCosting and stop the processing */
        /* ======================================================================================================= */
        if not can-find (first tPeriod)
        then do :
            assign viLocalReturnStatus = +1
                   vcMessage = trim(substitute(#T-88'No periods were found based upon the parameters that were provided to this API method':255(52812481)T-88#)) + chr(10) + 
                               trim(substitute(#T-2'Domain: &1':255(998701350)T-2#,icDomainCode)) + chr(10) + 
                               trim(substitute(#T-79'Entity: &1':255(117782143)T-79#,icDomainCode)) + chr(10) + 
                               trim(substitute(#T-46'Year / Period: &1 / &2':255(693616044)T-46#,iiFromPeriodYear,iiFromPeriodPeriod)).
            <M-38 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'W':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-690867':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            Leave MAINACTBLOCK.
        end. /* if not can-find (first tPeriod) */
        if not can-find (first tPeriod where 
                               tPeriod.PeriodIsPostingPCAllowed = false)
        then do :
            assign viLocalReturnStatus = +1
                   vcMessage = trim(substitute(#T-40'All periods found based upon the parameters that were provided to this API method were already open for Periodic Costing.':255(116616031)T-40#)) + chr(10) + 
                               trim(substitute(#T-17'Domain: &1':255(998701350)T-17#,icDomainCode)) + chr(10) + 
                               trim(substitute(#T-66'Entity: &1':255(117782143)T-66#,icDomainCode)) + chr(10) + 
                               trim(substitute(#T-19'Year / Period: &1 / &2':255(693616044)T-19#,iiFromPeriodYear,iiFromPeriodPeriod)).
            <M-53 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'W':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-876623':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            Leave MAINACTBLOCK.
        end. /* if not can-find (first tPeriod) */
        
        /* ===================================================== */
        /* Mark all loaded periods as open for PeriodicCosting   */ 
        /* Call ValidateBC, AdditionalUpdate and DataSave        */
        /* ===================================================== */
        for each tPeriod where 
                 tPeriod.PeriodIsPostingPCAllowed = false :
            assign tPeriod.PeriodIsPostingPCAllowed = true
                   tPeriod.tc_status                = "C":U.
        end. /* for each tPeriod where  */
        <M-75 run ValidateBC  (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave MAINACTBLOCK.
        <M-23 run AdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave MAINACTBLOCK.
        <M-15 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then Leave MAINACTBLOCK.
        
    /* =============================== */
    /* Exception handling - main block */
    /* =============================== */
    END. /* MAINACTBLOCK */
    assign oiReturnStatus = viLocalReturnStatus.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BPeriod".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiActivatePeriodForPeriodicCosting".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bperiod.apiactivateperiodforperiodiccosting.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>
       vhParameter::icCompanyCode = <parameter value>
       vhParameter::iiFromPeriodYear = <parameter value>
       vhParameter::iiFromPeriodPeriod = <parameter value>.

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.