Parameters
icRowId | input | character | |
iiPostingYear | input | integer | |
bcJournalCode | input-output | character | |
icJournalTypeCode | input | character | |
icLayerTypeCode | input | character | |
ocLayerTypeCode | output | character | |
ocLayerCode | output | character | |
oiVoucher | output | integer | |
ocJournalSecondDescription | output | character | |
iiNewVoucher | input | integer | |
ilIsReversing | input | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program4/bjournalentry.p)
/* =========================== */
/* Validation - Normalisations */
/* =========================== */
if icRowId = ? then assign icRowId = "":U.
if icRowId = "":U then return.
if iiPostingYear = ? then assign iiPostingYear = 0.
if bcJournalCode = ? then assign bcJournalCode = "":U.
if icLayerTypeCode = ? then assign icLayerTypeCode = "":U.
if icJournalTypeCode = ? then assign icJournalTypeCode = "":U.
if iiNewVoucher = ? then assign iiNewVoucher = 0.
if ilIsReversing = ? then assign ilIsReversing = false.
find bPosting where
bPosting.tc_Rowid = icRowId
no-error.
if not available bPosting
then return.
/* The method is called even on change of date in the same year, hence cehck if the input is same then return*/
If bPosting.PostingYear = iiPostingYear And
bPosting.tcJournalCode = bcJournalCode And
bPosting.PostingVoucher <> 0 And
(if ilIsReversing
then bPosting.PostingVoucher = iiNewVoucher
else true)
then do:
assign oiVoucher = bPosting.PostingVoucher
ocLayerTypeCode = bPosting.tcLayerTypeCode
ocJournalSecondDescription = bposting.PostingSecondText.
return.
end.
/* =============================================================================================================== */
/* Start a block as we need to be sure that whenever we start BNumber, we also stop it - even in case errors occur */
/* =============================================================================================================== */
assign viBlockReturnStatus = 0.
BNUMBERDEFAULTYEARJRNLBLOCK : DO :
/* =============================================================================================== */
/* Release the voucher in case we have alrready had a voucher and the year or journal is different */
/* =============================================================================================== */
if (bPosting.PostingYear <> iiPostingYear or
bPosting.tcJournalCode <> bcJournalCode) and
bPosting.PostingVoucher <> 0
then do:
/* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
/* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop */
if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
then do :
<I-48 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
/* Release the number - Close&Stop BNumber will be done after the block */
<M-2 run ReleaseNumber
(input bPosting.Company_ID (iiCompanyId),
input bPosting.PostingYear (iiNumbrYear),
input bPosting.tcJournalCode (icNumbrType),
input bPosting.PostingVoucher (iiNumbr),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viExternalReturnStatus (oiReturnStatus)) in BNumber>
/* Error handling and voucher reset */
if viExternalReturnStatus <> 0 and
viExternalReturnStatus <> -4 /* -4 means an invalid read : thus the number-record does not yet even exists */
then assign viBlockReturnStatus = viExternalReturnStatus.
if viBlockReturnStatus < 0
then Leave BNUMBERDEFAULTYEARJRNLBLOCK.
assign bPosting.PostingVoucher = 0.
end. /* if (bPosting.PostingYear <> iiPostingYear or */
/* ======================================================================================= */
/* If the Year-Journal is empty then store it like that and leave the block without errors */
/* Else, simply store Year (when filled) and Journal (when filled) in the posting */
/* ======================================================================================= */
if iiPostingYear = 0 and
bcJournalCode = "":U
then do:
assign bPosting.PostingYear = 0
bPosting.tcJournalCode = "":U.
Leave BNUMBERDEFAULTYEARJRNLBLOCK.
end. /* if iiPostingYear = 0 and */
if bPosting.PostingYear <> iiPostingYear
then assign bPosting.PostingYear = iiPostingYear.
if bPosting.tcJournalCode <> bcJournalCode
then assign bPosting.tcJournalCode = bcJournalCode
bPosting.tcLayerTypeCode = "":U.
/* ======================================================================== */
/* Fill the LayerTypeCode when empty - Fill JournalCode when incomplete */
/* ======================================================================== */
if bPosting.tcLayerTypeCode = "":U
then do:
<Q-6 run JournalBeginsForJEDefault (all) (Read) (NoCache)
(input bPosting.Company_ID, (CompanyId)
input bcJournalCode, (JournalCode)
input {&JOURNALCONTROL-FINANCIAL}, (JournalControl)
input ?, (JournalTypeCode)
output dataset tqJournalBeginsForJEDefault) in BJournal >
find first tqJournalBeginsForJEDefault where
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-JOURNALENTRY} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-CIREC}
no-error.
if not available tqJournalBeginsForJEDefault
then do:
assign viBlockReturnStatus = -4.
Leave BNUMBERDEFAULTYEARJRNLBLOCK.
end. /* if not available tqJournalBeginsForJEDefault */
find first tqJournalBeginsForJEDefault where
tqJournalBeginsForJEDefault.tcJournalCode = bcJournalCode and
(tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-JOURNALENTRY} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-CIREC})
no-error.
if available tqJournalBeginsForJEDefault and
(tqJournalBeginsForJEDefault.tcLayerTypeCode = icLayerTypeCode or
icLayerTypeCode = "":U) and
(can-do(icJournalTypeCode, tqJournalBeginsForJEDefault.tcJournalTypeCode) or
icJournalTypeCode = "":U)
then do:
assign bPosting.tcLayerTypeCode = tqJournalBeginsForJEDefault.tcLayerTypeCode
ocLayerCode = tqJournalBeginsForJEDefault.tcLayerCode
ocJournalSecondDescription = tqJournalBeginsForJEDefault.tcJournalSecondDescription.
end. /* if available tqJournalBeginsForJEDefault and */
if available tqJournalBeginsForJEDefault and
tqJournalBeginsForJEDefault.tcLayerTypeCode <> {&LAYERTYPECODE-TRANSIENT} and
(vcActivityCode = 'transientmodify':U or
vcActivityCode = 'transientcreate':U or
vcActivityCode = 'transientreverse':U)
then do:
/* Raise an error if the user is creating/modifying a transient layer transaction */
/* and the new journal code is for a layer other than the transient layer. */
assign viBlockReturnStatus = -4.
Leave BNUMBERDEFAULTYEARJRNLBLOCK.
end. /* if available tqJournalBeginsForJEDefault ..... */
if not available tqJournalBeginsForJEDefault
then do:
find tqJournalBeginsForJEDefault where
tqJournalBeginsForJEDefault.tcJournalCode BEGINS bcJournalCode and
(tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-JOURNALENTRY} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-YEARLYCLOSING} or
tqJournalBeginsForJEDefault.tcJournalTypeCode = {&JOURNALTYPE-CIREC})
no-error.
/* if there's only one record then use it else reaise an ambiguous-error */
if available tqJournalBeginsForJEDefault
then assign bcJournalCode = tqJournalBeginsForJEDefault.tcJournalCode
bPosting.tcLayerTypeCode = tqJournalBeginsForJEDefault.tcLayerTypeCode
bPosting.tcJournalCode = bcJournalCode
ocJournalSecondDescription = tqJournalBeginsForJEDefault.tcJournalSecondDescription.
else do:
assign viBlockReturnStatus = -4. /* Ambiguous records will not be found and available will be false */
Leave BNUMBERDEFAULTYEARJRNLBLOCK.
end. /* Not if available tqJournalBeginsForJEDefault */
end. /* if not available tqJournalBeginsForJEDefault */
end. /* if bPosting.tcLayerTypeCode = "":U */
/* =================================================================== */
/* Get a new voucher-number in case year and journal are filled by now */
/* =================================================================== */
if iiPostingYear <> 0 and
bcJournalCode <> "":U
then do:
/* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
/* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop */
if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
then do :
<I-1 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
/* Get the new number */
<M-4 run GetNumber
(input bPosting.Company_ID (iiCompanyId),
input iiPostingYear (iiNumbrYear),
input bcJournalCode (icNumbrType),
output bPosting.PostingVoucher (oiNumber),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viExternalReturnStatus (oiReturnStatus)) in BNumber>
if viExternalReturnStatus <> 0
then assign viBlockReturnStatus = viExternalReturnStatus.
if viExternalReturnStatus < 0
then Leave BNUMBERDEFAULTYEARJRNLBLOCK.
if not can-find (tCommitNumber where
tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER} and
tCommitNumber.tcPostingRowID = bPosting.tc_Rowid)
then do :
create tCommitNumber.
assign tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER}
tCommitNumber.tcPostingRowID = bPosting.tc_Rowid.
end.
end. /* if iiPostingYear <> 0 and */
END. /* BNUMBERDEFAULTYEARJRNLBLOCK */
/* ==================================================================================== */
/* Close&Stop BNumber that is started with a different transaction in the previous loop */
/* ==================================================================================== */
if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
then do :
<I-28 {bFcCloseAndStopInstance
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */
/* ==================================================================================== */
/* Capture errors from block BNUMBERDEFAULTYEARJRNLBLOCK */
/* ==================================================================================== */
if viBlockReturnStatus <> 0
then assign oiReturnStatus = viBlockReturnStatus.
if viBlockReturnStatus < 0
then return.
/* ==================================================================================== */
/* Fill in the output params */
/* ==================================================================================== */
assign ocLayerTypeCode = bPosting.tcLayerTypeCode
oiVoucher = bPosting.PostingVoucher.