project QadFinancials > class BJournalEntry > method CreateRecEntryPostingReverse
Description
Create Recurring Entry PostingReverse
Parameters
icPostingTcRowid | input | character | posting Rowid of original posting |
icNewJournalCode | input | character | Journal Code of reversing posting |
iiNewPeriodPeriod | input | integer | Period for reversing posting |
iiNewPeriodYear | input | integer | Year of reversing posting |
itNewPostingDate | input | date | Posting Date of reversing posting |
icNewPostingText | input | character | New PostingText |
oiNewPostingID | output | integer | PostingID of reversing posting |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bjournalentry.p)
/* =================================================== */
/* Replace uhnknown values / validate input paramaters */
/* =================================================== */
if icPostingTcRowid = ? then assign icPostingTcRowid = "":U.
if iiNewPeriodYear = ? then assign iiNewPeriodYear = 0.
if iiNewPeriodPeriod = ? then assign iiNewPeriodPeriod = 0.
if icNewJournalCode = ? then assign icNewJournalCode = "":U.
if icPostingTcRowid = "":U or
iiNewPeriodYear = 0 or
iiNewPeriodPeriod = 0 or
icNewJournalCode = "":U
then do :
assign vcMsgJE = trim(#T-15'You must enter the GL calendar year, GL period, daybook, and ID of the original journal entry in order to reverse it.':255(2737)T-15#) + chr(10) +
trim(substitute(#T-16'Year: &1.':255(2738)T-16#,string(iiNewPeriodYear,"9999":U))) + chr(10) +
trim(substitute(#T-17'GL period: &1.':255(2739)T-17#,string(iiNewPeriodPeriod,">>99":U))) + chr(10) +
trim(substitute(#T-18'Daybook: &1.':255(2740)T-18#,string(icNewJournalCode,"9999":U))) + chr(10) +
trim(substitute(#T-19'Row ID of the originating journal entry: &1.':255(2741)T-19#,icPostingTcRowid))
oiReturnStatus = -1.
<M-1 run SetMessage (input vcMsgJE (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icPostingTcRowid (icRowid),
input 'QADFIN-1028':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
Return.
end. /* if icPostingTcRowid = "":U or */
find bPosting where
bPosting.tc_Rowid = icPostingTcRowid and
bPosting.tc_Status <> 'D':U
no-error.
if not available bPosting
then do :
assign vcMsgJE = trim(substitute(#T-20'Internal error: cannot find the originating journal entry based on its row ID &1.':255(2742)T-20#,icPostingTcRowid))
oiReturnStatus = -1.
<M-2 run SetMessage (input vcMsgJE (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input icPostingTcRowid (icRowid),
input 'QADFIN-1029':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
Return.
end. /* if not available bPosting */
<Q-3 run PeriodPrim (all) (Read) (NoCache)
(input bPosting.Company_ID, (CompanyId)
input ?, (PeriodId)
input iiNewPeriodYear, (PeriodYear)
input iiNewPeriodPeriod, (PeriodPeriod)
output dataset tqPeriodPrim) in BPeriod >
find first tqPeriodPrim no-lock no-error.
if not available tqPeriodPrim
then do :
assign vcMsgJE = trim(substitute(#T-21'The GL calendar year &1 and GL period &2 are invalid.':255(2743)T-21#,string(iiNewPeriodYear),string(iiNewPeriodPeriod)))
oiReturnStatus = -1.
<M-4 run SetMessage (input vcMsgJE (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icPostingTcRowid (icRowid),
input 'QADFIN-1030':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
Return.
end. /* if not available tqPeriodPrim */
<Q-5 run JournalByJournalLayer (all) (Read) (NoCache)
(input bPosting.Company_ID, (CompanyId)
input icNewJournalCode, (JournalCode)
input ?, (CandoJournalTypeCode)
input ?, (LayerCode)
input ?, (CandoLayerTypeCode)
input ?, (JournalID)
input ?, (JournalIsActive)
output dataset tqJournalByJournalAndLayer) in BJournal >
assign vcMsgJE = "":U.
find first tqJournalByJournalAndLayer no-lock no-error.
if not available tqJournalByJournalAndLayer
then assign vcMsgJE = trim(substitute(#T-22'The daybook &1 is invalid.':255(2744)T-22#,icNewJournalCode)).
else if tqJournalByJournalAndLayer.tcJournalTypeCode <> {&JOURNALTYPE-JOURNALENTRY}
then assign vcMsgJE = trim(substitute(#T-23'The daybook must be of type &1.':255(2745)T-23#,{&JOURNALTYPE-JOURNALENTRY-TR})) + chr(10) +
trim(substitute(#T-24'Daybook: &1.':255(2740)T-24#, icNewJournalCode)) + chr(10) +
trim(substitute(#T-25'The daybook &1 is of type &2.':255(2746)T-25#, tqJournalByJournalAndLayer.tcJournalCode,tqJournalByJournalAndLayer.tcJournalTypeCode)).
if vcMsgJE <> "":U
then do :
assign oiReturnStatus = -1.
<M-6 run SetMessage (input vcMsgJE (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input icPostingTcRowid (icRowid),
input 'QADFIN-1031':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
Return.
end. /* if vcMsgJE <> "":U */
/* ============================================================================ */
/* Copy the bPosting, bPostingLine, bPostingSaf, bPostingVat to new records. */
/* Get a number for the new journal and reverse Cr-Db */
/* ============================================================================ */
/* Create reversing posting */
<M-10 run AddDetailLine (input 'Posting':U (icTable),
input ? (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* Update the reversing posting data */
buffer-copy bPosting except bPosting.tc_ParentRowid
bPosting.tc_Rowid
bPosting.tc_Status
bPosting.Posting_ID
to tPosting
assign tPosting.PostingYear = iiNewPeriodYear
tPosting.PostingPeriod = iiNewPeriodPeriod
tPosting.PostingYearPeriod = iiNewPeriodYear * 100 + iiNewPeriodPeriod
tPosting.tcJournalCode = icNewJournalCode
tPosting.PostingDate = itNewPostingDate
tPosting.PostingAddGLNbrDate = itNewPostingDate
tPosting.PostingVoucher = 0
oiNewPostingID = tPosting.Posting_ID
vhFcComponent = ?
tPosting.PostingIsReversing = true
tPosting.PostingOriginatorReference = substitute("&1/&2/&3":U,
bPosting.PostingYear,
bPosting.tcJournalCode,
string(bPosting.PostingVoucher,"999999999":U)).
if icNewPostingText <> '':U and icNewPostingText <> ?
then assign tPosting.PostingText = icNewPostingText.
/* 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-46 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
<M-9 run GetNumber
(input tPosting.Company_ID (iiCompanyId),
input tPosting.PostingYear (iiNumbrYear),
input tPosting.tcJournalCode (icNumbrType),
output tPosting.PostingVoucher (oiNumber),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viExternalReturnStatus (oiReturnStatus)) in BNumber>
/* Close&Stop BNumber that is started with a different transaction before the previous loop */
if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
then do :
<I-12 {bFcCloseAndStopInstance
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */
if not can-find (tCommitNumber where
tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER} and
tCommitNumber.tcPostingRowID = tPosting.tc_Rowid)
then do :
create tCommitNumber.
assign tCommitNumber.tcNumberType = {&COMMITNUMBERTYPE-POSTINGVOUCHER}
tCommitNumber.tcPostingRowID = tPosting.tc_Rowid.
end.
if viExternalReturnStatus < 0 or (viExternalReturnStatus > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viExternalReturnStatus.
if viExternalReturnStatus < 0
then return.
/* Create and update posting-lines */
for each bPostingLine where
bPostingLine.tc_ParentRowid = bPosting.tc_Rowid and
bPostingLine.tc_Status <> 'D':U
no-lock:
<M-11 run AddDetailLine (input 'PostingLine':U (icTable),
input tPosting.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* Update the reversing posting data */
buffer-copy bPostingLine except bPostingLine.tc_ParentRowid
bPostingLine.tc_Rowid
bPostingLine.tc_Status
bPostingLine.Posting_ID
bPostingLine.PostingLine_ID
to tPostingLine.
assign tPostingLine.tlLinkedCrCyDaemonReqExists = false.
/* Turn New-OI-Allocations into Linked-OI-Allocations */
if tPostingLine.tcAllocationType = "N":U
then assign tPostingLine.tcAllocationType = "L":U.
assign vdDummy = tPostingLine.PostingLineCreditLC
tPostingLine.PostingLineCreditLC = tPostingLine.PostingLineDebitLC
tPostingLine.PostingLineDebitLC = vdDummy
vdDummy = tPostingLine.PostingLineCreditTC
tPostingLine.PostingLineCreditTC = tPostingLine.PostingLineDebitTC
tPostingLine.PostingLineDebitTC = vdDummy
vdDummy = tPostingLine.PostingLineCreditCC
tPostingLine.PostingLineCreditCC = tPostingLine.PostingLineDebitCC
tPostingLine.PostingLineDebitCC = vdDummy.
/* Create and update postingvat-records */
for each bPostingVat where
bPostingVat.tc_ParentRowid = bPostingLine.tc_Rowid and
bPostingVat.tc_Status <> 'D':U
no-lock:
<M-13 run AddDetailLine (input 'PostingVat':U (icTable),
input tPostingLine.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* Update the reversing posting data */
buffer-copy bPostingVat except bPostingVat.tc_ParentRowid
bPostingVat.tc_Rowid
bPostingVat.tc_Status
bPostingVat.PostingLine_ID
bPostingVat.PostingVat_ID
to tPostingVat.
assign vdDummy = tPostingVat.PostingVatBaseCreditLC
tPostingVat.PostingVatBaseCreditLC = tPostingVat.PostingVatBaseDebitLC
tPostingVat.PostingVatBaseDebitLC = vdDummy
vdDummy = tPostingVat.PostingVatBaseCreditTC
tPostingVat.PostingVatBaseCreditTC = tPostingVat.PostingVatBaseDebitTC
tPostingVat.PostingVatBaseDebitTC = vdDummy
vdDummy = tPostingVat.PostingVatBaseCreditCC
tPostingVat.PostingVatBaseCreditCC = tPostingVat.PostingVatBaseDebitCC
tPostingVat.PostingVatBaseDebitCC = vdDummy.
end. /* for each bPostingVat where*/
/* Create and update postingSaf-records */
for each bPostingSaf where
bPostingSaf.tc_ParentRowid = bPostingLine.tc_Rowid and
bPostingSaf.tc_Status <> 'D':U
no-lock:
<M-14 run AddDetailLine (input 'PostingSaf':U (icTable),
input tPostingLine.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
/* Update the reversing posting data */
buffer-copy bPostingSaf except bPostingSaf.tc_ParentRowid
bPostingSaf.tc_Rowid
bPostingSaf.tc_Status
bPostingSaf.PostingLine_ID
bPostingSaf.PostingSaf_ID
to tPostingSaf.
end. /* for each bPostingSaf where*/
end. /* for each bPostingLine where */