project QadFinancials > class BCInvoice > method AdditionalUpdatesAllQCInvoiceMovement
Description
This submethod of AdditionalUpdatesAll that handles all actions on the creation of QCinvoiceMovemnt records that will be used by the balance-daemon to keep the creditor-balances up-to-date.
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program8/bcinvoice.p)
/* ============================================================ */
/* Create a QCinvoicemovement record for every Cinvoicemovement */
/* => will be handled by daemon, to update debtor balance */
/* ============================================================ */
/* ============================================================ */
/* No new movements => no actions needed */
/* ============================================================ */
if not can-find (first tCInvoiceMovement where
tCInvoiceMovement.tc_Status = "N":U)
then Return.
/* ========================== */
/* Set default return-status */
/* ========================== */
assign oiReturnStatus = -98.
/* ======================================================================================= */
/* General note: BJournalEntry is already started and opened by the caller-method */
/* ======================================================================================= */
if can-find (first tCInvoiceMovement where
tCInvoiceMovement.tc_Status <> "":U) and
(viBJournalEntryCIID = 0 or
viBJournalEntryCIID = ? or
valid-handle(vhBJournalEntryCIInst) <> true)
then do :
assign vcMessage = trim(#T-13'Internal error: unexpected situation-no communication to the postings available':255(17891)T-13#) + chr(10) +
trim(substitute(#T-14'Instance ID = &1.':255(17892)T-14#,string(viBJournalEntryCIID))) + chr(10) +
trim(substitute(#T-15'Valid handle = &1.':255(17893)T-15#,string(valid-handle(vhBJournalEntryCIInst) = TRUE))) + chr(10) +
trim(substitute(#T-16'Handle value = &1.':255(17894)T-16#,string(vhBJournalEntryCIInst)))
oiReturnStatus = -3.
<M-12 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-4481':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
Return.
end. /* if */
/* =============== */
/* Initialisations */
/* =============== */
empty temp-table tQCInvoiceMovementToCreate.
assign viQCInvoiceMovementToCreateSeq = 0.
/* ============================ */
/* Go through all new movements */
/* ============================ */
for each tCInvoice where
tCInvoice.tc_Status <> "D":U,
each tCInvoiceMovement where
tCInvoiceMovement.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceMovement.tc_Status = "N":U :
/* ============================================================ */
/* Get the amounts out of the JE-instance */
/* ============================================================ */
find first tPostingPostingLineInfoCIJE where
tPostingPostingLineInfoCIJE.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID
no-error.
if not available tPostingPostingLineInfoCIJE
then do:
assign vcMessage = trim(#T-20'Internal error: unexpected situation - no postingline information available':255(999890248)T-20#) + chr(10) +
trim(substitute(#T-21'Posting Line ID = &1.':255(999890249)T-21#,string(tCInvoiceMovement.PostingLine_ID)))
oiReturnStatus = -3.
<M-19 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-8981':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
next.
end. /* if not available tPostingPostingLineInfoCIJE */
/* ============================================================================ */
/* Get the amounts out of the DB when we cannot get them out of the JE-instance */
/* ============================================================================ */
if tPostingPostingLineInfoCIJE.tdPostingLineDebitLC = 0 and
tPostingPostingLineInfoCIJE.tdPostingLineCreditLC = 0
then do:
/* if not in instance, look in db */
<Q-10 run PostingByPostingLineId (all) (Read) (NoCache)
(input tCInvoice.Company_ID, (CompanyId)
input tCInvoiceMovement.PostingLine_ID, (PostingLineId)
output dataset tqPostingByPostingLineId) in BPosting >
find tqPostingByPostingLineId where
tqPostingByPostingLineId.tiCompany_ID = tCInvoice.Company_ID and
tqPostingByPostingLineId.tiPostingLine_ID = tCInvoiceMovement.PostingLine_ID
no-lock no-error.
if available tqPostingByPostingLineId
then assign tPostingPostingLineInfoCIJE.tdPostingLineDebitTC = tqPostingByPostingLineId.tdPostingLineDebitTC
tPostingPostingLineInfoCIJE.tdPostingLineDebitLC = tqPostingByPostingLineId.tdPostingLineDebitLC
tPostingPostingLineInfoCIJE.tdPostingLineDebitCC = tqPostingByPostingLineId.tdPostingLineDebitCC
tPostingPostingLineInfoCIJE.tdPostingLineCreditTC = tqPostingByPostingLineId.tdPostingLineCreditTC
tPostingPostingLineInfoCIJE.tdPostingLineCreditLC = tqPostingByPostingLineId.tdPostingLineCreditLC
tPostingPostingLineInfoCIJE.tdPostingLineCreditCC = tqPostingByPostingLineId.tdPostingLineCreditCC
tPostingPostingLineInfoCIJE.tiGL_ID = tqPostingByPostingLineId.tiGL_ID
tPostingPostingLineInfoCIJE.tiDivision_ID = tqPostingByPostingLineId.tiDivision_ID
tPostingPostingLineInfoCIJE.tiProject_ID = tqPostingByPostingLineId.tiProject_ID
tPostingPostingLineInfoCIJE.tiJournal_ID = tqPostingByPostingLineId.tiJournal_ID
tPostingPostingLineInfoCIJE.tiCostCentre_ID = tqPostingByPostingLineId.tiCostCentre_ID.
end. /* if tPostingPostingLineInfoCIJE.tdPostingLineDebitLC = 0 and */
/* =============================== */
/* Create the temp-table records */
/* =============================== */
create tQCInvoiceMovementToCreate.
assign viQCInvoiceMovementToCreateSeq = viQCInvoiceMovementToCreateSeq + 1
tQCInvoiceMovementToCreate.tc_Rowid = string(viQCInvoiceMovementToCreateSeq)
tQCInvoiceMovementToCreate.CInvoiceMovementDebitLC = tPostingPostingLineInfoCIJE.tdPostingLineDebitLC
tQCInvoiceMovementToCreate.CInvoiceMovementCreditLC = tPostingPostingLineInfoCIJE.tdPostingLineCreditLC
tQCInvoiceMovementToCreate.CInvoiceMovementDebitTC = tPostingPostingLineInfoCIJE.tdPostingLineDebitTC
tQCInvoiceMovementToCreate.CInvoiceMovementCreditTC = tPostingPostingLineInfoCIJE.tdPostingLineCreditTC
tQCInvoiceMovementToCreate.CInvoiceMovementDebitCC = tPostingPostingLineInfoCIJE.tdPostingLineDebitCC
tQCInvoiceMovementToCreate.CInvoiceMovementCreditCC = tPostingPostingLineInfoCIJE.tdPostingLineCreditCC
tQCInvoiceMovementToCreate.CInvoiceMovementVatDebLC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatDebitLC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementVatCredLC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatCreditLC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementVatDebTC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatDebitTC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementVatCredTC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatCreditTC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementVatDebCC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatDebitCC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementVatCredCC = if tCInvoice.tc_Status = "N":U then tCInvoice.CInvoiceVatCreditCC else 0
tQCInvoiceMovementToCreate.CInvoiceMovementIsInvoice = if tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE} or tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION} then true else false
tQCInvoiceMovementToCreate.CInvoiceMovementIsCreditN = if tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} then true else false
tQCInvoiceMovementToCreate.CInvoiceMovementType = tCInvoiceMovement.CInvoiceMovementType
tQCInvoiceMovementToCreate.CInvoiceMovementInfo = trim(string(tCInvoice.CInvoicePostingYear)) + '/':U + trim(string(tCInvoice.CInvoicePostingPeriod)) + '/':U + trim(tCInvoice.tcJournalCode) + '/':U + trim(string(tCInvoice.CInvoiceVoucher))
tQCInvoiceMovementToCreate.MovementYearPeriod = tCInvoiceMovement.CInvoiceMovementYearPeriod
tQCInvoiceMovementToCreate.Company_ID = tCInvoice.Company_ID /* viCompanyId would also be okay as the company of the invoice is always the current company when making the CInvoiceMovements */
tQCInvoiceMovementToCreate.Currency_ID = tCInvoice.CInvoiceCurrency_ID
tQCInvoiceMovementToCreate.Creditor_ID = tCInvoice.Creditor_ID
tQCInvoiceMovementToCreate.Period_ID = tCInvoiceMovement.Period_ID
tQCInvoiceMovementToCreate.GL_ID = tPostingPostingLineInfoCIJE.tiGL_ID
tQCInvoiceMovementToCreate.Division_ID = tPostingPostingLineInfoCIJE.tiDivision_ID
tQCInvoiceMovementToCreate.Project_ID = tPostingPostingLineInfoCIJE.tiProject_ID
tQCInvoiceMovementToCreate.CostCentre_ID = tPostingPostingLineInfoCIJE.tiCostCentre_ID
tQCInvoiceMovementToCreate.Journal_ID = tPostingPostingLineInfoCIJE.tiJournal_ID
tQCInvoiceMovementToCreate.ttValidityDate = tCInvoice.CInvoiceTaxPointDate
tQCInvoiceMovementToCreate.tdExchangeRate = tCInvoice.CInvoiceExchangeRate
tQCInvoiceMovementToCreate.tdExchangeRateScale = tCInvoice.CinvoiceRateScale.
end. /* for each tCInvoice where tCInvoice.tc_Status <> "D":U, each tCInvoiceMovement where */
/* ====================================================================================================================== */
/* IMPORTANT NOTE: */
/* We will not go through the normal approach with Starting&Opening the external instance and then call a method in there */
/* as that decreases the performance too much. In stead, we stop here as we have the required tQCInvoiceMovementToCreate */
/* records and we will save them in BPosting:POSTSAVE using dynamic buffers as that will be much faster */
/* The program-code in here to call is kep in comments although it should never be executed anymore but we want to keep */
/* it like this so the 'Show Usage' still shows at least the correct calling class. */
/* SO: Please do note uncomment or remove this commented out program-code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* ====================================================================================================================== */
/* COMMENTED-OUT - See comments Above
/* Call a method in BQCInvoiceMov that will create these records */
if can-find (first tQCInvoiceMovementToCreate)
then do:
/* start and/or open the QCInvoiceMovement instance */
if viBQCInvoiceMovementID = 0 or
viBQCInvoiceMovementID = ?
then do:
<I-1 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BQCInvoiceMovement"}>
end. /* if viBQCInvoiceMovementID = 0 or */
else do:
<I-2 {bFcOpenInstance
&CLASS = "BQCInvoiceMovement"}>
end. /* Not if viBQCInvoiceMovementID = 0 or */
/* Call the method */
<M-3 run ApiCreateQCInvoiceMovement (input tQCInvoiceMovementToCreate (tAPIQCInvoiceMovement),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
output viExternalReturnStatus (oiReturnStatus)) in BQCInvoiceMovement>
/* close the bQCinvoiceMovement instance */
<I-4 {bFcCloseInstance
&CLASS = "BQCInvoiceMovement"}>
/* Check for errors in the method call */
if viExternalReturnStatus <> 0
then assign oiReturnStatus = 0.
if viExternalReturnStatus < 0
then Return.
end. /* if can-find */
COMMENTED-OUT - See comments Above
*/
/* ========================== */
/* Set default return-status */
/* ========================== */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.