Description
Update daybook of posting
Parameters
iiPostingID | input | integer | |
icPostingRowId | input | character | |
iiNewPostingYear | input | integer | New year |
icNewJournalCode | input | character | |
ilIsReleaseOriginalVoucher | input | logical | Release original voucher number? |
oiNewVoucherNumber | output | integer | New voucher number |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bjournalentry.p)
assign oiReturnStatus = -98
viLocalReturn = 0.
MAIN_BLOCK:
do on error undo, leave:
/* ======================================================== */
/* Normalize input parameters */
/* ======================================================== */
if icPostingRowId = "":U then assign icPostingRowId = ?.
if iiPostingID = 0 then assign iiPostingID = ?.
if iiNewPostingYear = 0 then assign iiNewPostingYear = ?. /* No change of year */
if icNewJournalCode = "":U then assign icNewJournalCode = ?. /* No change of daybook */
if ilIsReleaseOriginalVoucher = ? then assign ilIsReleaseOriginalVoucher = false.
/* ======================================================== */
/* Validate input parameters */
/* ======================================================== */
if icPostingRowId = ? and
iiPostingID = ?
then do:
assign vcMessage = #T-46'Not all mandatory input parameters are populated or they have wrong value.':255(999890330)T-46#
vcContext = "icPostingRowId = &1|iiPostingID= &2":U
vcContext = substitute(vcContext, icPostingRowId, iiPostingID)
vcContext = replace(vcContext, "|":U, chr(2)).
<M-25 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-443328':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
find bPosting where
(bPosting.tc_Rowid = icPostingRowId or icPostingRowId = ?) and
(bPosting.Posting_ID = iiPostingID or iiPostingID = ?)
no-error.
if not available bPosting
then do:
assign vcMessage = #T-946'Missing record':255(69247)T-946#
vcContext = "icPostingRowId = &1|iiPostingID= &2":U
vcContext = substitute(vcContext, icPostingRowId, iiPostingID)
vcContext = replace(vcContext, "|":U, chr(2)).
<M-57 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-950098':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input vcContext (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
assign viLocalReturn = -1.
leave MAIN_BLOCK.
end.
/* Supply missing parameters if needed */
if iiNewPostingYear = ? then assign iiNewPostingYear = bPosting.PostingYear.
if icNewJournalCode = ? then assign icNewJournalCode = bPosting.tcJournalCode.
/* If there is no change, just finish */
if iiNewPostingYear = bPosting.PostingYear and
icNewJournalCode = bPosting.tcJournalCode
then leave MAIN_BLOCK.
/* =============================================================================================== */
/* Release the voucher in case we have alrready had a voucher and the year or journal is different */
/* =============================================================================================== */
if (bPosting.PostingYear <> iiNewPostingYear or
bPosting.tcJournalCode <> icNewJournalCode) and
bPosting.PostingVoucher <> 0 and
ilIsReleaseOriginalVoucher
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-97 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
else if not valid-handle(vhBNumberFromBPostingInst)
then do:
<I-93 {bFcOpenInstance
&CLASS = "BNumber"}>
end.
/* Release the number */
<M-73 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 viFcReturnSuper (oiReturnStatus)) in BNumber>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave MAIN_BLOCK.
assign bPosting.PostingVoucher = 0.
end. /* if (bPosting.PostingYear <> iiNewPostingYear or */
if bPosting.PostingYear <> iiNewPostingYear or
bPosting.tcJournalCode <> icNewJournalCode
then assign bPosting.PostingYear = iiNewPostingYear
bPosting.tcJournalCode = icNewJournalCode
bPosting.tcReportingJournalCode = icNewJournalCode
bPosting.tcLayerTypeCode = "":U
bPosting.tc_Status = if bPosting.tc_Status = "":U then "C":U else bPosting.tc_Status.
/* =================================================================== */
/* Get a new voucher-number in case year and journal are filled by now */
/* =================================================================== */
if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
then do :
<I-95 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
else if not valid-handle(vhBNumberFromBPostingInst)
then do:
<I-75 {bFcOpenInstance
&CLASS = "BNumber"}>
end.
/* Get the new number */
<M-24 run GetNumber
(input bPosting.Company_ID (iiCompanyId),
input bPosting.PostingYear (iiNumbrYear),
input bPosting.tcJournalCode (icNumbrType),
output bPosting.PostingVoucher (oiNumber),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viLocalReturn (oiReturnStatus)) in BNumber>
if viFcReturnSuper < 0 or viFcReturnSuper > 0 and viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viLocalReturn < 0 then leave MAIN_BLOCK.
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. /* MAIN_BLOCK */
/* ==================================================================================== */
/* Close&Stop BNumber that is started with a different transaction in the previous loop */
/* ==================================================================================== */
if valid-handle(vhBNumberFromBPostingInst)
then do :
<I-11 {bFcCloseAndStopInstance
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */
/* ==================================================================================== */
/* Fill in the output params */
/* ==================================================================================== */
assign oiNewVoucherNumber = if available bPosting then bPosting.PostingVoucher else ?
oiReturnStatus = viLocalReturn.