project QadFinancials > class BPeriod > method ApiDeactivatePeriodForPeriodicCosting
Description
ApiDeactivatePeriodForPeriodicCosting: close a period specified by the domain, company, year and period for PeriodicCosting.
When the company is not specified, then all periods matching the other input will be closed for PeriodicCosting
Parameters
icDomainCode | input | character | Parameter 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 |
icCompanyCode | input | character | Company: this parameter has to be either empty, either it has to point to a company in the current domain |
iiPeriodYear | input | integer | Accounting year: mandatory |
iiPeriodPeriod | input | integer | Accounting Period: mandatory |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bperiod.p)
/* =============================== */
/* Exception handling - main block */
/* Default output */
/* =============================== */
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
MAINDEACTBLOCK: DO :
/* ================== */
/* Validate the input */
/* ================== */
if icDomainCode = "":U or
icDomainCode = ?
then assign icDomainCode = vcDomainCode.
if icCompanyCode = ? then assign icCompanyCode = "":U.
if iiPeriodYear = 0 or
iiPeriodYear = ? or
iiPeriodPeriod = 0 or
iiPeriodPeriod = ?
then do :
assign viLocalReturnStatus = -1
vcMessage = trim(substitute(#T-4'The Year (&1) and Period (&2) are mandatory parameters for the API method.':255(733734752)T-4#, iiPeriodYear, iiPeriodPeriod)).
<M-3 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-9790':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* if iiPeriodYear = 0 or */
if icDomainCode <> vcDomainCode
then do :
assign viLocalReturnStatus = -1
vcMessage = trim(substitute(#T-12'The Domain (&1) that was passed as parameter for the API method should either be the current domain either empty.':255(332051464)T-12#, icDomainCode)).
<M-11 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-9793':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* if icDomainCode <> vcDomainCode */
<Q-6 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-10'Internal error: unable to find the current domain (&1).':255(413947993)T-10#, icDomainCode)).
<M-9 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-9792':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
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-16'The Entity (&1) that was passed as parameter for the API method should belong to the current domain (&2).':255(519388136)T-16#, icCompanyCode, icDomainCode)).
<M-15 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-9795':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* if not available tqDomainForCompanyDomain */
end. /* if icCompanyCode <> "":U */
/* ================================================================ */
/* Run a ClearData to make sure we start from scratch */
/* ================================================================ */
<M-2 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINDEACTBLOCK.
/* ========================================================================================================= */
/* 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.PeriodYear = ":U + string(iiPeriodYear) + " and ":U +
" Period.PeriodPeriod = ":U + string(iiPeriodPeriod) + ") ":U.
If length(vcFreeForm,'Character':U) > 30000
then do :
assign viLocalReturnStatus = -1
vcMessage = trim(substitute(#T-19'The Domain (&1) contains to many entities to load all periods for the entities.':255(915889653)T-19#, icDomainCode)) + chr(10) +
trim(substitute(#T-20'Free-form sting for the DataLoad: &1':255(606042433)T-20#,vcFreeForm)).
<M-18 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-9796':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* If length(vcFreeForm,'Character':U) > 30000 */
end. /* for each tqDomainForCompanyDomain where */
assign vcFreeForm = "For each Period where ":U + vcFreeForm.
<M-17 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 MAINDEACTBLOCK.
/* ======================================================================================================== */
/* 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-22'No periods were found based upon the parameters that were provided to this API method':255(52812481)T-22#)) + chr(10) +
trim(substitute(#T-23'Domain: &1':255(998701350)T-23#,icDomainCode)) + chr(10) +
trim(substitute(#T-24'Entity: &1':255(117782143)T-24#,icDomainCode)) + chr(10) +
trim(substitute(#T-25'Year / Period: &1 / &2':255(693616044)T-25#,iiPeriodYear,iiPeriodPeriod)).
<M-21 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-9797':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* if not can-find (first tPeriod) */
if not can-find (first tPeriod where
tPeriod.PeriodIsPostingPCAllowed = true)
then do :
assign viLocalReturnStatus = +1
vcMessage = trim(substitute(#T-27'All periods found based upon the parameters that were provided to this API method were already closed for Periodic Costing.':255(188964783)T-27#)) + chr(10) +
trim(substitute(#T-28'Domain: &1':255(998701350)T-28#,icDomainCode)) + chr(10) +
trim(substitute(#T-29'Entity: &1':255(117782143)T-29#,icDomainCode)) + chr(10) +
trim(substitute(#T-30'Year / Period: &1 / &2':255(693616044)T-30#,iiPeriodYear,iiPeriodPeriod)).
<M-26 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-9798':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPeriod>
Leave MAINDEACTBLOCK.
end. /* if not can-find (first tPeriod) */
/* ===================================================== */
/* Mark all loaded periods as closed for PeriodicCosting */
/* Call ValidateBC, AdditionalUpdate and DataSave */
/* ===================================================== */
for each tPeriod where
tPeriod.PeriodIsPostingPCAllowed = true :
assign tPeriod.PeriodIsPostingPCAllowed = false
tPeriod.tc_status = "C":U.
end. /* for each tPeriod where */
<M-31 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINDEACTBLOCK.
<M-32 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINDEACTBLOCK.
<M-33 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper <> 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave MAINDEACTBLOCK.
/* =============================== */
/* Exception handling - main block */
/* =============================== */
END. /* MAINDEACTBLOCK */
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 = "ApiDeactivatePeriodForPeriodicCosting".
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.apideactivateperiodforperiodiccosting.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icDomainCode = <parameter value>
vhParameter::icCompanyCode = <parameter value>
vhParameter::iiPeriodYear = <parameter value>
vhParameter::iiPeriodPeriod = <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.