project QadFinancials > class BJournal > method ApiGenerateInitialJournals
Description
This method will create a new active journal record for each active journaltype that is defined with multi-journal. If there is already a journal defined for the journal type, the function will not create a new journal.
Following values will be assigned to the new records:
Journal code = Journal Type Code
Journal Type Code = Journal Type Code
Description = Translated value of the journaltype.
Layer = official layer.
PostCondition
After completion of the method an initial journal exists for every journal type.
PreCondition
- At least one active journaltype should exist.
- The layer of layertype 'OFFICIAL' should exist.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bjournal.p)
/*Load Journals if necessary*/
if not available tJournal
then do:
<M-2 run DataLoad
(input '':U (icRowids),
input '':U (icPkeys),
input '':U (icObjectIds),
input '' (icFreeform),
input false (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BJournal>
if viFcReturnSuper <> 0 and
viFcReturnSuper <> -4
then do:
assign oiReturnStatus = viFcReturnSuper.
return.
end.
end.
/*JournalType - Journals are generated only for active once */
<Q-10 run JournalTypeByNothing (all) (Read) (NoCache)
(output dataset tqJournalTypeByNothing) in BJournalType >
find first tqJournalTypeByNothing where
tqJournalTypeByNothing.tlJournalTypeIsActive = true no-error.
if not available tqJournalTypeByNothing
then do:
assign vcMessage = trim(#T-13'Cannot generate the initial daybooks.':100(2710)t-13#) +
trim(#T-14'No active daybook type found.':100(2711)T-14#) + chr(10) +
(if program-name(1) = ? then "":U else program-name(1))
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<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-403':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournal>
return.
end.
/*GetLayers*/
<Q-6 run LayerById (all) (Read) (NoCache)
(input ?, (LayerId)
output dataset tqLayerById) in BLayer >
find first tqLayerById no-error.
if not available tqLayerById
then do:
assign vcMessage = trim(#T-15'Cannot generate the initial daybooks.':100(2710)t-15#) +
trim(#T-16'Layers have not been defined.':100(2712)t-16#) + chr(10) +
(if program-name(1) = ? then "":U else program-name(1))
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<M-7 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-16':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournal>
return.
end.
assign viOfficialLayer = ?
viStockLayer = ?.
/*find Official layer*/
find first tqLayerById where
tqLayerById.tcLayerTypeCode = {&LAYERTYPECODE-OFFICIAL} no-error.
if available tqLayerById
then assign viOfficialLayer = tqLayerById.tiLayer_ID.
else do:
assign vcMessage = trim(#T-17'Cannot generate the initial daybooks.':100(2710)t-17#) +
trim(substitute(#T-18'&1 layer not defined.':100(2713)t-18#, {&LAYERTYPECODE-OFFICIAL-TR})) + chr(10) +
(if program-name(1) = ? then "":U else program-name(1))
oiReturnStatus = if oiReturnStatus < 0
then oiReturnStatus
else -1.
<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-21':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournal>
return.
end.
/*find Stock layer (can be Official or Management) - TO BE REVIEWED - for the moment always OFFICIAL*/
/*System.SystemStockLayer_id*/
assign viStockLayer = viOfficialLayer.
for each tqJournalTypeByNothing where
tqJournalTypeByNothing.tlJournalTypeIsMultiJournal = true:
if can-find (first tJournal where
tJournal.JournalTypeCode = tqJournalTypeByNothing.tcJournalTypeCode)
then next.
<M-4 run AddDetailLine (input 'Journal':U (icTable),
input '':U (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournal>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
if oiReturnStatus < 0
then return.
assign tJournal.JournalCode = tqJournalTypeByNothing.tcJournalTypeCode
tJournal.JournalDescription = tqJournalTypeByNothing.tcJournalTypeCodeTr
tJournal.JournalIsActive = tqJournalTypeByNothing.tlJournalTypeIsActive
tJournal.JournalTypeCode = tqJournalTypeByNothing.tcJournalTypeCode
tJournal.Layer_ID = if not tqJournalTypeByNothing.tlJournalTypeIsStock
then viOfficialLayer
else viStockLayer.
end.
/*Validations*/
<M-5 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BJournal>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
if oiReturnStatus < 0
then return.
<M-12 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BJournal>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
if oiReturnStatus < 0
then return.
/*DataSave*/
<M-8 run DataSave (output viFcReturnSuper (oiReturnStatus)) in BJournal>
assign oiReturnStatus = if (oiReturnStatus > 0 and
viFcReturnSuper = 0) or
oiReturnStatus < 0
then oiReturnStatus
else viFcReturnSuper.
if oiReturnStatus < 0
then return.
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 = "BJournal".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGenerateInitialJournals".
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 = "".
/* 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.