project QadFinancials > class BDInvoice > method AdditionalUpdatesAllAssignments
Description
This submethod of AdditionalUpdatesAll holds all program-code for some assigments and the run of the validations in BJE
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program8/bdinvoice.p)
/* ========================== */
/* Set default return-status */
/* ========================== */
assign oiReturnStatus = -98.
/* ======================================================================================= */
/* General note: BJournalEntry is already started and opened by the caller-method */
/* ======================================================================================= */
if can-find (first tDInvoiceMovement where
tDInvoiceMovement.tc_Status <> "":U) and
(viBJournalEntryDIID = 0 or
viBJournalEntryDIID = ? or
valid-handle(vhBJournalEntryDIInst) <> true)
then do :
assign vcMessage = trim(#T-1'Internal error: unexpected situation-no communication to the postings available':255(17891)t-1#) + chr(10) +
trim(substitute(#T-2'Instance ID = &1.':255(17892)T-2#,string(viBJournalEntryDIID))) + chr(10) +
trim(substitute(#T-3'Valid handle = &1.':255(17893)T-3#,string(valid-handle(vhBJournalEntryDIInst) = TRUE))) + chr(10) +
trim(substitute(#T-4'Handle value = &1.':255(17894)T-4#,string(vhBJournalEntryDIInst)))
oiReturnStatus = -3.
<M-5 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-4512':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
Return.
end. /* if */
for each tDInvoice where
tDInvoice.tc_status <> "D":U,
each tDInvoiceMovement where
tDInvoiceMovement.tc_ParentRowid = tDInvoice.tc_Rowid and
(tDInvoiceMovement.tc_Status = "N":U or
tDInvoiceMovement.tc_Status = "C":U)
no-lock:
if not can-find(first tPostingPostingLineInfoDIJE where
tPostingPostingLineInfoDIJE.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID)
then do:
create tPostingPostingLineInfoDIJE.
assign tPostingPostingLineInfoDIJE.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID.
end. /* if not can-find(first tPostingPostingLineInfoDIJE where */
end. /* for each tDInvoice where */
if can-find(first tPostingPostingLineInfoDIJE)
then do:
<M-41 run GetPostingInfoByPostingLineIDTT
(input-output tPostingPostingLineInfoDIJE (tPostingPostingLineInfo),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if can-find(first tPostingPostingLineInfoDIJE) */
/* =============================== */
/* Go through all non-deleted CI's */
/* =============================== */
for each tDInvoice where
tDInvoice.tc_status <> "D":U :
/* =========================================== */
/* Assign some fields in the CInvoiceMovements */
/* =========================================== */
for each tDInvoiceMovement where
tDInvoiceMovement.tc_ParentRowid = tDInvoice.tc_Rowid and
(tDInvoiceMovement.tc_Status = "N":U or
tDInvoiceMovement.tc_Status = "C":U) :
/* Check in the JE-instance */
find first tPostingPostingLineInfoDIJE where
tPostingPostingLineInfoDIJE.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID
no-error.
if not available tPostingPostingLineInfoDIJE
then do:
assign vcMessage = trim(#T-43'Internal error: unexpected situation - no posting line information available':255(999890251)T-43#) + chr(10) +
trim(substitute(#T-44'Posting Line ID = &1.':255(999890249)T-44#,string(tDInvoiceMovement.PostingLine_ID)))
oiReturnStatus = -3.
<M-42 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-8982':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
next.
end. /* if not available tPostingPostingLineInfoDIJE */
assign tDInvoiceMovement.Company_ID = tDInvoice.Company_ID
tDInvoiceMovement.Period_ID = tPostingPostingLineInfoDIJE.tiPeriod_ID
tDInvoiceMovement.Debtor_ID = tDInvoice.Debtor_ID
tDInvoiceMovement.DInvoiceMovementYearPeriod = tPostingPostingLineInfoDIJE.tiPostingYearPeriod
tDInvoiceMovement.DInvoiceMovementPostDate = tPostingPostingLineInfoDIJE.ttPostingDate.
end. /* for each tDInvoiceMovement */
if tDInvoice.tdDInvoiceOriginalTC = 0
then do:
/* DI Posting */
find first tDInvoicePosting where
tDInvoicePosting.tc_ParentRowid = tDInvoice.tc_Rowid and
tDInvoicePosting.tc_Status = "N":U
no-error.
if available tDinvoicePosting
then do:
<M-38 run SetPostingIsZeroValueAllowed
(input ? (icPostingRowId),
input tDInvoicePosting.Posting_ID (iiPostingId),
input true (ilPostingIsZeroValueAllowed),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave.
end. /* if available tDinvoicePosting */
end. /* if tDInvoice.tdDInvoiceOriginalTC = 0 */
/* ================================ */
/* State the closing Date if the CI */
/* ================================ */
if tDInvoice.DInvoiceIsOpen = true
then assign tDInvoice.DInvoiceClosingDate = 12/31/9999.
else do :
assign vtLastDateOfInvoice = ?.
find t_iDInvoice where
t_iDInvoice.tc_Rowid = tDInvoice.tc_Rowid
no-lock no-error.
if available t_iDInvoice = false or
(available t_iDInvoice and t_iDInvoice.DInvoiceIsOpen = true)
then do :
for each tDInvoiceMovement where
tDInvoiceMovement.tc_ParentRowid = tDInvoice.tc_Rowid no-lock :
/* Check in the db / if foudn then next */
if not vlStartPostingByPostingLineId
then do:
<Q-39 run PostingByPostingLineId (Start) in BPosting >
assign vlStartPostingByPostingLineId = true.
end. /* if not vlStartPostingByPostingLineId */
<Q-12 run PostingByPostingLineId (all) (Read) (NoCache)
(input tDInvoice.Company_ID, (CompanyId)
input tDInvoiceMovement.PostingLine_ID, (PostingLineId)
output dataset tqPostingByPostingLineId) in BPosting >
find tqPostingByPostingLineId where
tqPostingByPostingLineId.tiCompany_ID = tDInvoice.Company_ID and
tqPostingByPostingLineId.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID
no-lock no-error.
if available tqPostingByPostingLineId
then do :
if tqPostingByPostingLineId.ttPostingDate > vtLastDateOfInvoice or
vtLastDateOfInvoice = ?
then assign vtLastDateOfInvoice = tqPostingByPostingLineId.ttPostingDate.
assign tDInvoiceMovement.Company_ID = tDInvoice.Company_ID
tDInvoiceMovement.Period_ID = tqPostingByPostingLineId.tiPeriod_ID
tDInvoiceMovement.Debtor_ID = tDInvoice.Debtor_ID
tDInvoiceMovement.DInvoiceMovementYearPeriod = tqPostingByPostingLineId.tiPeriodYearPeriod
tDInvoiceMovement.DInvoiceMovementPostDate = tqPostingByPostingLineId.ttPostingDate.
next.
end. /* if available tqPostingByPostingLineId */
/* Check in the instance */
find first tPostingPostingLineInfoDIJE where
tPostingPostingLineInfoDIJE.tiPostingLine_ID = tDInvoiceMovement.PostingLine_ID
no-error.
if available tPostingPostingLineInfoDIJE
then do:
if tPostingPostingLineInfoDIJE.ttPostingDate <> ? and
(tPostingPostingLineInfoDIJE.ttPostingDate > vtLastDateOfInvoice or /* BTS 4681 */
vtLastDateOfInvoice = ?)
then assign vtLastDateOfInvoice = tPostingPostingLineInfoDIJE.ttPostingDate.
end. /* if available tPostingPostingLineInfoDIJE */
end. /* for each tDInvoiceMovement where */
assign tDInvoice.DInvoiceClosingDate = (if vtLastDateOfInvoice = ? then today else vtLastDateOfInvoice).
end. /* if available t_iDInvoice = false or */
end. /* if tDInvoice.DInvoiceIsOpen = false */
/* Update of the postinglines if the invoice is linked to another invoice with a different CC rate */
if tDInvoice.LinkedDInvoice_ID <> 0
then do:
/* Check if the bjournalentry instance is open or not. If not open, then open an instance. */
if not valid-handle(vhBJournalEntryDIInst)
then do:
<I-31 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
assign vlBJournalEntryOpenInThisMethod = TRUE.
end. /* if not valid-handle(vhBJournalEntryCIInst) */
/* Get the linked invoice */
<Q-17 run DInvoiceByInvoiceNumber (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input tDInvoice.tiLinkedPeriodYear, (DInvoicePostingYear)
input tDInvoice.tiLinkedDInvoiceVoucher, (DInvoiceVoucher)
input tDInvoice.tcLinkedJournalCode, (JournalCode)
output dataset tqDInvoiceByInvoiceNumber) in BDInvoice >
find first tqDInvoiceByInvoiceNumber where
tqDInvoiceByInvoiceNumber.tiDInvoicePostingYear = tDInvoice.tiLinkedPeriodYear and
tqDInvoiceByInvoiceNumber.tiDInvoiceVoucher = tDInvoice.tiLinkedDInvoiceVoucher and
tqDInvoiceByInvoiceNumber.tcJournalCode = tDInvoice.tcLinkedJournalCode and
tqDInvoiceByInvoiceNumber.tiCompany_ID = viCompanyId
no-lock no-error.
if available tqDInvoiceByInvoiceNumber and
tqDInvoiceByInvoiceNumber.ttDInvoicePostingDate <> tDInvoice.DInvoicePostingDate
then do:
<M-51 run UpdatePostinglineCCAmts
(input-output tPostingPostingLineInfoDIJE (tPostingPostingLineInfo),
input tqDInvoiceByInvoiceNumber.tdDInvoiceCCRate (idRateCC),
input tqDInvoiceByInvoiceNumber.tdDInvoiceCCScale (idRateScaleCC),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then Leave.
end. /* if available tqDInvoiceByInvoiceNumber */
end. /* if tDInvoice.LinkedDInvoice_ID <> 0 */
end. /* for each tDInvoice */
if vlStartPostingByPostingLineId
then do:
<Q-40 run PostingByPostingLineId (Stop) in BPosting >
end. /* if vlStartPostingByPostingLineId */
/* Check if the instance to BournalEntry needs to be closed. */
if vlBJournalEntryOpenInThisMethod = TRUE
then. /* ========================================================================================================= */
/* Normally we would here close BJournalEntry we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
/* ========================== */
/* Set default return-status */
/* ========================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.