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/bddocument.p)
<ANCESTOR-CODE>
for each tDDocument where
tDDocument.tc_status <> "N":U :
if vlDataLoadKeepPrevious and
can-find (tAlreadyCalculatedRecords where
tAlreadyCalculatedRecords.tcTableName = "DDocument" and
tAlreadyCalculatedRecords.tc_Rowid = tDDocument.tc_Rowid)
then next.
<Q-2 run DebtorPrim (all) (Read) (NoCache)
(input tDDocument.Company_ID, (CompanyId)
input ?, (DebtorCode)
input tDDocument.Debtor_ID, (Debtor_ID)
output dataset tqDebtorPrim) in BDebtor >
find first tqDebtorPrim where
tqDebtorPrim.tiDebtor_ID = tDDocument.Debtor_ID
no-error.
if not available tqDebtorPrim
then next.
assign tDDocument.tcBusinessRelationCode = tqDebtorPrim.tcBusinessRelationCode
tDDocument.tcBusinessRelationName = tqDebtorPrim.tcBusinessRelationName1
tDDocument.tcBusinessRelationSearch = tqDebtorPrim.tcBusinessRelationSearchName
tDDocument.ttPostingDate = today.
<Q-16 run BankNumberPrim (all) (Read) (NoCache)
(input tDDocument.BankNumber_ID, (BankNumberId)
input ?, (ParentObjectId)
input ?, (BankNumber)
input ?, (BankNumberExtension)
input ?, (BankPayFormatID)
output dataset tqBankNumberPrim) in BBankNumber >
find first tqBankNumberPrim where
tqBankNumberPrim.tiBankNumber_ID = tDDocument.BankNumber_ID
no-error.
if not available tqBankNumberPrim
then next.
assign tDDocument.tcDebtorBankNumber = tqBankNumberPrim.tcBankNumber.
<Q-20 run BankNumberOwnBankGLByID (all) (Read) (Cache)
(input tqBankNumberPrim.tiBankNumber_ID, (BankNumber_ID)
input ?, (CompanyId)
output dataset tqBankNumberOwnBankGLByID) in BBankNumber>
find first tqBankNumberOwnBankGLByID where
tqBankNumberOwnBankGLByID.tiBankNumber_ID = tqBankNumberPrim.tiBankNumber_ID
no-error.
if not available tqBankNumberOwnBankGLByID
then next.
assign tDDocument.tcPayFormatTypeCode = tqBankNumberOwnBankGLByID.tcPayFormatTypeCode
tDDocument.tcOwnBankNumber = tqBankNumberOwnBankGLByID.tcOwnBankNumber.
for each tDDocumentInvoiceXref where
tDDocumentInvoiceXref.tc_ParentRowid = tDDocument.tc_Rowid:
find t_iDDocumentInvoiceXref where
t_iDDocumentInvoiceXref.tc_Rowid = tDDocumentInvoiceXref.tc_Rowid
no-error.
if not available t_iDDocumentInvoiceXref
then do:
<M-3 run SetMessage
(input trim(#T-8'Initial values not found for customer payment invoice cross-reference with row ID $1.':250(1658)T-8#) (icMessage),
input tDDocumentInvoiceXref.tc_Rowid (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-2558':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
assign oiReturnStatus = -1.
leave.
end. /* if not available t_iDDocumentInvoiceXref */
<Q-5 run DInvoiceByAllocationInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (BusinessRelationCode)
input tDDocumentInvoiceXref.DInvoice_ID, (DInvoiceID)
input ?, (DInvoiceDescription)
input ?, (DebtorCode)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceAmountTCMinimum)
input ?, (DInvoiceAmountTCMaximum)
input ?, (PeriodYearMinimum)
input ?, (JournalCode)
input ?, (PeriodYear)
input ?, (Voucher)
input ?, (DInvoiceTSMNumber)
input ?, (ShipperCode)
input ?, (CorporateGroupCode)
input ?, (CompIsOICrossCy)
input ?, (Debtor_ID)
input ?, (DInvoiceIsSelected)
input ?, (BillNumber)
input ?, (BillYear)
output dataset tqDInvoiceByAllocationInfo) in BDInvoice>
/* assign shipper info */
define buffer btqDInvoiceByAllocationInfo for tqDInvoiceByAllocationInfo.
assign vcDDocumentOpInfo = "".
for each btqDInvoiceByAllocationInfo where
btqDInvoiceByAllocationInfo.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID
no-lock
break by btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoType
by btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode:
assign vcDDocumentOpInfo = if vcDDocumentOpInfo = "":U then btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode
else vcDDocumentOpInfo + ",":U + btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode.
end.
find first tqDInvoiceByAllocationInfo where
tqDInvoiceByAllocationInfo.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID
no-error.
if not available tqDInvoiceByAllocationInfo
then next.
/* =================================================================================== */
/* Update credit/debit signs and amounts depending on invoice type */
/* INVOICE and NEGATIVE --> CREDIT and reverse sign of allocated amount */
/* CREDIT NOTE and NEGATIVE --> CREDIT and reverse sign of allocated amount */
/* DEDUCTION and NEGATIVE --> CREDIT and reverse sign of allocated amount */
/* INVOICE CORRECTION and POSITIVE --> CREDIT and reverse sign of allocated amount */
/* CREDIT NOTE CORRECTION and POSITIVE --> CREDIT and reverse sign of allocated amount */
/* =================================================================================== */
if (tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-INVOICE} and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-CREDITNOTE} and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-DEDUCTION} and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC < 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC > 0) or
(tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} and
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC > 0)
then assign tDDocumentInvoiceXRef.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC = - tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
t_iDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC = - t_iDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC.
else assign tDDocumentInvoiceXRef.tcAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}.
assign tDDocumentInvoiceXRef.tcDInvoiceType = tqDInvoiceByAllocationInfo.tcDInvoiceType
tDDocumentInvoiceXRef.tcBusinessRelationCode = tqDInvoiceByAllocationInfo.tcBusinessRelationCode
tDDocumentInvoiceXref.tcCorporateGroupCode = tqDInvoiceByAllocationInfo.tcCorporateGroupCode
tDDocumentInvoiceXRef.tcDInvoiceBalanceCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> ?
then {&CREDITDEBITABBREVIATION-CREDIT}
else {&CREDITDEBITABBREVIATION-DEBIT}
tDDocumentInvoiceXRef.tcDInvoiceReference = if tqDInvoiceByAllocationInfo.tcDInvoiceType = {&INVOICETYPE-DEDUCTION}
then string(tqDInvoiceByAllocationInfo.tiPeriodYear) + "/":U +
tqDInvoiceByAllocationInfo.tcJournalCode + "/":U +
string(tqDInvoiceByAllocationInfo.tiDInvoiceVoucher, "999999999":U) + "/":U +
entry(4, tqDInvoiceByAllocationInfo.tcDInvoiceDescription, "/":U)
else string(tqDInvoiceByAllocationInfo.tiPeriodYear) + "/":U +
tqDInvoiceByAllocationInfo.tcJournalCode + "/":U +
string(tqDInvoiceByAllocationInfo.tiDInvoiceVoucher, "999999999":U) + "/":U +
tqDInvoiceByAllocationInfo.tcDInvoiceDescription
tDDocumentInvoiceXref.tcDInvoiceTSMNumber = tqDInvoiceByAllocationInfo.tcDInvoiceTSMNumber
tDDocumentInvoiceXRef.tcCompanyCode = tqDInvoiceByAllocationInfo.tcCompanyCode
tDDocumentInvoiceXref.tcDebtorCode = tqDInvoiceByAllocationInfo.tcDebtorCode
tDDocumentInvoiceXRef.tcCurrencyCode = tqDInvoiceByAllocationInfo.tcCurrencyCode
tDDocumentInvoiceXref.tcDivisionCode = tqDInvoiceByAllocationInfo.tcDivisionCode
tDDocumentInvoiceXRef.tcNewBalanceCrDt = tDDocumentInvoiceXRef.tcDInvoiceBalanceCrDt
tDDocumentInvoiceXRef.tdDInvoiceBalance = if tDDocumentInvoiceXref.tcAllocAmountCrDt = tDDocumentInvoiceXref.tcDInvoiceBalanceCrDt
then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
else
if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> ?
then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
tDDocumentInvoiceXRef.tdDiscountPercentage = if /*tqDInvoiceByAllocationInfo.tiDiscPaymentCondition_ID <> 0 and
tqDInvoiceByAllocationInfo.tiDiscPaymentCondition_ID <> ? and*/
tDDocument.DDocumentDueDate <= tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
then tqDInvoiceByAllocationInfo.tdPaymentConditionPercentage
else 0
tDDocumentInvoiceXRef.tdNewBalance = if tDDocumentInvoiceXref.tcAllocAmountCrDt = tDDocumentInvoiceXref.tcDInvoiceBalanceCrDt
then 0
else
if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> 0 and
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC <> ?
then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC
tDDocumentInvoiceXRef.tlUIFullAllocation = tDDocumentInvoiceXRef.tdNewBalance = 0
tDDocumentInvoiceXRef.ttDInvoiceDate = tqDInvoiceByAllocationInfo.ttDInvoiceDate
tDDocumentInvoiceXRef.ttDInvoiceDiscountDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
tDDocumentInvoiceXRef.ttDInvoiceDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDueDate
tDDocumentInvoiceXref.tiDInvoicePostingId = tqDInvoiceByAllocationInfo.tiPosting_ID
tDDocumentInvoiceXref.tdVatBaseTC = if tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseCreditTC
tDDocumentInvoiceXref.tcVatBaseCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
tDDocumentInvoiceXref.tdVatTC = if tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC
tDDocumentInvoiceXref.tcVatCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
tDDocumentInvoiceXref.tcDInvoiceDIText = tqDInvoiceByAllocationInfo.tcDInvoiceDIText
tDDocumentInvoiceXref.tdDDocumentInvoiceXrefPaidTC = tDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC - tDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC + tDDocumentInvoiceXref.DDocumentInvoiceXrefIntTC
tDDocumentInvoiceXref.tdNonDiscAmtTC = tqDInvoiceByAllocationInfo.tdDInvoiceNonDiscAmtTC
tDDocumentInvoiceXref.tdDeductionTC = 0
tDDocumentInvoiceXref.tcDeductionCatCode = '':U
tDDocumentInvoiceXref.tcDInvoiceDeductionStatus = '':U
tDDocumentInvoiceXref.tcShipperCode = vcDDocumentOpInfo.
assign tDDocumentInvoiceXref.tlDiscountTaxAtPayment = false.
/*assign deduction information*/
<Q-70 run GetDeductionDetailByInvoiceID (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDDocumentInvoiceXref.DInvoice_ID, (InvoiceID)
output dataset tqGetDeductionDetailByInvoiceID) in BDInvoice>
for each tqGetDeductionDetailByInvoiceID no-lock:
assign tDDocumentInvoiceXref.tdDeductionTC = tDDocumentInvoiceXref.tdDeductionTC + tqGetDeductionDetailByInvoiceID.tdDInvoiceDeductionTC
tDDocumentInvoiceXref.tcDeductionCatCode = if tDDocumentInvoiceXref.tcDeductionCatCode = '':U then tqGetDeductionDetailByInvoiceID.tcDeductionCatCode
else trim(#T-68'See details':20(648722267)T-68#)
tDDocumentInvoiceXref.tcDInvoiceDeductionStatus = if tDDocumentInvoiceXref.tcDInvoiceDeductionStatus = '':U then tqGetDeductionDetailByInvoiceID.tcDInvoiceDeductionStatus
else trim(#T-85'See details':20(648722267)T-85#).
find tApiDInvoiceDeduction where
tApiDInvoiceDeduction.DInvoiceDeduction_ID = tqGetDeductionDetailByInvoiceID.tiDInvoiceDeduction_ID no-lock no-error.
if available tApiDInvoiceDeduction
then next.
end. /* for each tqGetDeductionDetailByInvoiceID */
<Q-18 run DInvoiceVatByDInvoiceId (all) (Read) (NoCache)
(input tDDocumentInvoiceXref.DInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceVatByDInvoiceId) in BDInvoice>
for each tqDInvoiceVatByDInvoiceId where
tqDInvoiceVatByDInvoiceId.tiDInvoice_ID = tDDocumentInvoiceXref.DInvoice_ID :
<Q-19 assign vlFcQueryRecordsAvailable = MfgTaxCodeByTaxCode (NoCache)
(input tqDInvoiceVatByDInvoiceId.tcVatCode, (TaxCode)
input tqDInvoiceVatByDInvoiceId.tcDomainCode, (DomainCode)
input true, (DiscountAtPayment)
input ?, (IsTaxByLine)) in BMfgTaxCode>
if vlFcQueryRecordsAvailable = yes or
vlFcQueryRecordsAvailable = ?
then do:
assign tDDocumentInvoiceXref.tlDiscountTaxAtPayment = true.
leave.
end. /* if vlFcQueryRecordsAvailable = yes or */
end. /* for each tqDInvoiceVatByDInvoiceId where */
if tDDocument.DDocumentDueDate <= tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
then assign vdBalance = (tDDocumentInvoiceXRef.tdDInvoiceBalance - tDDocumentInvoiceXref.tdVatTC) *
((abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC -
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC) -
abs(tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC -
tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC)) /
abs(tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC -
tqDInvoiceByAllocationInfo.tdDInvoiceOriginalCreditTC))
vdDiscountBaseTC = if tDDocumentInvoiceXref.tlDiscountTaxAtPayment = true then tDDocumentInvoiceXRef.tdDInvoiceBalance else vdBalance
tDDocumentInvoiceXRef.tdDefaultDiscountAmount = vdDiscountBaseTC * (1 - tqDInvoiceByAllocationInfo.tdPaymentConditionPercentage / 100)
tDDocumentInvoiceXRef.tdDefaultPaymentAmount = tDDocumentInvoiceXRef.tdDInvoiceBalance -
tDDocumentInvoiceXRef.tdDefaultDiscountAmount.
else assign tDDocumentInvoiceXRef.tdDefaultPaymentAmount = tDDocumentInvoiceXRef.tdDInvoiceBalance
tDDocumentInvoiceXRef.tdDefaultDiscountAmount = 0.
assign tDDocumentInvoiceXref.tdDefaultDiscountAmount = <M-14 RoundAmount
(input tDDocumentInvoiceXref.tdDefaultDiscountAmount (idUnroundedAmount),
input '':U (iiCurrencyID),
input tDDocumentInvoiceXref.tcCurrencyCode (icCurrencyCode)) in BApplicationProperty>
tDDocumentInvoiceXref.tdDefaultPaymentAmount = <M-15 RoundAmount
(input tDDocumentInvoiceXref.tdDefaultPaymentAmount (idUnroundedAmount),
input '':U (iiCurrencyID),
input tDDocumentInvoiceXref.tcCurrencyCode (icCurrencyCode)) in BApplicationProperty>.
for each tDDocInvoiceXrefStage where
tDDocInvoiceXrefStage.tc_ParentRowid = tDDocumentInvoiceXref.tc_Rowid:
/* Get Stage details from Customer invoice */
if tDDocInvoiceXrefStage.DDocInvoiceXrefStage_ID <> ? and
tDDocInvoiceXrefStage.DDocInvoiceXrefStage_ID <> 0
then do:
<Q-50 run DInvoiceStageByID (all) (Read) (NoCache)
(input tDDocInvoiceXrefStage.DInvoiceStage_ID, (DInvoiceStageID)
output dataset tqDInvoiceStageByID) in BDInvoice>
find first tqDinvoiceStageByID where
tqDinvoiceStageByID.tiDInvoiceStage_ID = tDDocInvoiceXrefStage.DInvoiceStage_ID
no-error.
if available tqDinvoiceStageByID
then assign tDDocInvoiceXrefStage.ttDefaultDueDate = tqDinvoiceStageByID.ttDInvoiceStageDueDate
tDDocInvoiceXrefStage.ttDefaultDiscDate = tqDinvoiceStageByID.ttDInvoiceStageDiscDate.
end. /* tDDocInvoiceXrefStage.DDocInvoiceXrefStage_ID <> ? and */
end. /* for each tDDocInvoiceXrefStage */
end. /* for each tDDocumentInvoiceXref where */
assign tDDocument.tlInvoicesLinked = can-find(first tDDocumentInvoiceXRef where
tDDocumentInvoiceXRef.tc_ParentRowid = tDDocument.tc_Rowid).
for each tDDocumentPostingLine where
tDDocumentPostingLine.tc_ParentRowid = tDDocument.tc_Rowid
by tDDocumentPostingLine.DDocumentPostingLine_ID desc:
<Q-11 run PostingByPostingLineId (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDDocumentPostingLine.PostingLine_ID, (PostingLineId)
output dataset tqPostingByPostingLineId) in BPosting>
find first tqPostingByPostingLineId where
tqPostingByPostingLineId.tiPostingLine_ID = tDDocumentPostingLine.PostingLine_ID
no-error.
if available tqPostingByPostingLineId
then do:
assign tDDocument.ttPostingDate = tqPostingByPostingLineId.ttPostingDate.
leave.
end.
end. /* for each tDDocumentPostingLine */
end. /* for each tDDocument: */