Description
Add code here to initialize the calculated fields of the class temp-tables after loading existing records from the application database.
Parameters
oiReturnStatus | output | integer | |
Internal usage
unused
program code (program/bdinvoice.p)
<ANCESTOR-CODE>
/* ================================================================================================================ */
/* Go through the invoices that have not yet been handled by this method - applicable when doing multiple DataLoads */
/* The field 'tcLocalCurrencyCode' is assigned in the loop */
/* ================================================================================================================ */
for each tDInvoice where
(tDInvoice.tcLocalCurrencyCode = "":U or
tDInvoice.tcLocalCurrencyCode = ?) and
tDInvoice.tc_Status = "":U :
if tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICE} or
tDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE} or
tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then do:
if tDInvoice.DInvoiceIsTaxExcluded = false
then assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceOriginalDebitTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceOriginalDebitLC.
else assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceVatBaseCreditTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceVatBaseCreditLC.
end.
else
if tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
then do:
if tDInvoice.DInvoiceIsTaxExcluded = false
then assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceOriginalCreditTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceOriginalCreditLC.
else assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceVatBaseDebitTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceVatBaseDebitLC.
end.
else do:
if tDInvoice.DInvoiceIsTaxExcluded = false
then if tDInvoice.DInvoiceOriginalCreditTC <> 0
then assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceOriginalCreditTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceOriginalCreditLC.
else assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceOriginalDebitTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceOriginalDebitLC.
else if tDInvoice.DInvoiceVatBaseDebitTC <> 0
then assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceVatBaseDebitTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceVatBaseDebitLC.
else assign tDInvoice.tdDInvoiceOriginalTC = tDInvoice.DInvoiceVatBaseCreditTC
tDInvoice.tdDInvoiceOriginalLC = tDInvoice.DInvoiceVatBaseCreditLC.
end.
assign tDInvoice.tcLocalCurrencyCode = vcCompanyLC
tDInvoice.tdTotalAmountDebitTC = tDInvoice.DInvoiceVatBaseDebitTC +
tDInvoice.DInvoiceVatDebitTC
tDInvoice.tdTotalAmountCreditTC = tDInvoice.DInvoiceVatBaseCreditTC +
tDInvoice.DInvoiceVatCreditTC
tDInvoice.tdTotalAmountWithTaxesTC = if tDInvoice.tdTotalAmountDebitTC <> 0 and tDInvoice.tdTotalAmountDebitTC <> ?
then tDInvoice.tdTotalAmountDebitTC
else tDInvoice.tdTotalAmountCreditTC
tDInvoice.tcDInvoiceNumber = string(tDInvoice.DInvoicePostingYear) + "/":U +
tDInvoice.tcJournalCode + "/":U +
string(tDInvoice.DInvoiceVoucher, "999999999":U)
tDInvoice.tdDInvoiceOriginalAmount = tDInvoice.DInvoiceOriginalDebitTC - tDInvoice.DInvoiceOriginalCreditTC
tDInvoice.tdDInvoiceOpenAmount = tDInvoice.DInvoiceBalanceDebitTC - tDInvoice.DInvoiceBalanceCreditTC
tDInvoice.tdDInvoiceOriginalAmountLC = tDInvoice.DInvoiceOriginalDebitLC - tDInvoice.DInvoiceOriginalCreditLC
tDInvoice.tdDInvoiceOpenAmountLC = tDInvoice.DInvoiceBalanceDebitLC - tDInvoice.DInvoiceBalanceCreditLC.
/* ============== */
/* fill DA Fields */
/* ============== */
if tDInvoice.LinkedDInvoice_ID <> 0 and
tDInvoice.LinkedDInvoice_ID <> ? and
(tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTE} or
tDInvoice.DInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or
tDInvoice.DInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION})
then do:
for each tDInvoiceMovement where
tDInvoiceMovement.DInvoice_Id = tDInvoice.DInvoice_ID :
<Q-2 run PostingLineByPostingLineId (all) (Read) (Cache)
(input viCompanyId, (CompanyId)
input tDInvoiceMovement.PostingLine_ID, (PostingLineId)
input {&JOURNALTYPE-DEBTORADJUSTMENT}, (JournalTypeCode)
output dataset tqPostingLineByPostingLineId) in BPosting>
find first tqPostingLineByPostingLineId no-error.
if available tqPostingLineByPostingLineId
then assign tDInvoice.tcDAJournalCode = tqPostingLineByPostingLineId.tcJournalCode
tDInvoice.tiDAVoucher = tqPostingLineByPostingLineId.tiPostingVoucher.
end. /* for each tDInvoiceMovement */
end. /* tDInvoice.LinkedDInvoice_ID */
if tDInvoice.DInvoiceDueDate <> ?
then do:
if today - tDInvoice.DInvoiceDueDate >= 0
then assign tDInvoice.tiOverdueDays = today - tDInvoice.DInvoiceDueDate.
else assign tDInvoice.tiOverdueDays = 0.
end.
/* fill the own vat number fields */
if tDInvoice.ShipFromAddress_ID <> ? and tDInvoice.ShipFromAddress_ID <> 0
then assign tDInvoice.tcOwnVatNumberCountryCode = tDInvoice.tcShipFromCountryCode.
/* fill the own vat number fields */
if tDInvoice.ShipToAddress_ID <> ? and tDInvoice.ShipToAddress_ID <> 0
then assign tDInvoice.tcDebVatNumberCountryCode = tDInvoice.tcShipToCountryCode.
/* determine if the invoice is used in payment */
assign tDInvoice.tlDInvoiceIsReferenced = tDInvoice.DInvoiceIsSelected.
if not tDInvoice.tlDInvoiceIsReferenced
then do:
<Q-15 assign vlFcQueryRecordsAvailable = DDocumentInvoiceXrefByDInvId (NoCache) (input tDInvoice.DInvoice_ID, (DInvoiceId)) in BDDocument>
if vlFcQueryRecordsAvailable = false
then do:
<Q-16 assign vlFcQueryRecordsAvailable = CDocumentInvoiceXrefByInvId (NoCache)
(input ?, (CInvoiceId)
input tDInvoice.DInvoice_ID, (DInvoiceId)) in BCDocument>
assign tDInvoice.tlDInvoiceIsReferenced = (vlFcQueryRecordsAvailable <> false).
end.
else assign tDInvoice.tlDInvoiceIsReferenced = true.
end.
end.
/* ================================================================================== */
/* Calculate values of DInvoiceVat */
/* ================================================================================== */
<M-8 run CalculateDInvoiceVat
(input ? (icRowid),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0
then do:
assign oiReturnStatus = viFcReturnSuper
viFcReturnSuper = 0.
return.
end.
<M-19 run CalculateDInvoiceBank (output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.