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/bdebtor.p)
/* When doing multiple dataloads without clearing the instance, the code within the loop is performed much too many times. */
/* We will add the possibility to run the calculate method logic only once to gain performance. */
/* An example of this can be seen in DataLoadByInput. Setting the class data item will determine whether to run the logic */
<ANCESTOR-CODE>
empty temp-table tAddressRefDebtor.
empty temp-table tBankNumberRefDebtor.
empty temp-table tDBankNumberPayCodeRef.
empty temp-table tBankNumberSectionRefDebtor.
/*Start queries*/
<Q-7 run PaymentConditionByIdCode (Start) in BPaymentCondition >
<Q-9 run BankNumberByParentID (Start) in BBankNumber >
<Q-11 run BankNumberPayCodeByBankNbrID (Start) in BBankNumber >
<Q-12 run BankPayFormatByID (Start) in BBankPayFormat >
<Q-33 run DDocumentStatusPrim (Start) in BDDocumentStatus >
if viBBankNumber4ID = 0 or
viBBankNumber4ID = ?
then do:
<I-23 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BBankNumber"}>
end. /* if viBBankNumber4ID = 0 or */
else do:
<I-24 {bFcOpenInstance
&CLASS = "BBankNumber"}>
end. /* not if viBBankNumber4ID = 0 or */
debtors:
for each tDebtor:
if vlDataLoadKeepPrevious and
can-find (tAlreadyCalculatedRecords where
tAlreadyCalculatedRecords.tcTableName = "Debtor" and
tAlreadyCalculatedRecords.tc_Rowid = tDebtor.tc_Rowid)
then next.
/*calculate NormalPaymentConditionType*/
if tDebtor.NormalPaymentCondition_ID > 0
then do:
<Q-6 run PaymentConditionByIdCode (all) (Read) (NoCache)
(input tDebtor.NormalPaymentCondition_ID, (PaymentConditionId)
input ?, (PaymentConditionCode)
output dataset tqPaymentConditionByIdCode) in BPaymentCondition >
find first tqPaymentConditionByIdCode no-error.
if available tqPaymentConditionByIdCode
then assign tDebtor.tcNormalPaymentConditionType = tqPaymentConditionByIdCode.tcPaymentConditionPaymentTyp.
end.
/* Get the Businress Relation id for the Debtor and store it in the calculate field */
<Q-35 run DebtorPrim (all) (Read) (NoCache)
(input viCompanyID, (CompanyId)
input '', (DebtorCode)
input tDebtor.Debtor_ID, (Debtor_ID)
output dataset tqDebtorPrim) in BDebtor >
for first tqDebtorPrim:
assign tDebtor.tcBusinessRelationCode = tqDebtorPrim.tcBusinessRelationCode.
end.
/* Populates AddressRef */
<M-18 run DefaultValuesBusinessRelation
(input tDebtor.tc_Rowid (icRowId),
input tDebtor.tcBusinessRelationCode (icBusinessRelationCode),
input true (ilStartedFromCalculate),
output vlDummy (olDebtorIsTaxable),
output vlDummy (olDebtorIsTaxInCity),
output vcDummy (olDebtorIsTaxIncluded),
output tAddressRefDebtor (tAddressRefDebtor),
output tDebtor.TxzTaxZone (ocDebtorTaxZone),
output tDebtor.DebtorTaxIDFederal (ocDebtorTaxIDFederal),
output tDebtor.DebtorTaxIDState (ocDebtorTaxIDState),
output tDebtor.TxuTaxUsage (ocDebtorTaxUsage),
output tDebtor.TxclTaxCls (ocDebtorTaxClass),
output tDebtor.DebtorTaxIDMisc1 (ocDebtorTaxIDMisc1),
output tDebtor.DebtorTaxIDMisc2 (ocDebtorTaxIDMisc2),
output tDebtor.DebtorTaxIDMisc3 (ocDebtorTaxIDMisc3),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
/*Populates tBankNumberRefDebtor*/
if tDebtor.Debtor_ID > 0
then do:
assign vcBankNumberParentType = {&BANKNUMBERPARENTTYPE-DEBTOR}.
<Q-4 run BankNumberByParentID (all) (Read) (NoCache)
(input tDebtor.Debtor_ID, (ParentObjectId)
input vcBankNumberParentType, (BankNumberParentType)
input ?, (BankNumberIsDefault)
input ?, (CompanyId)
output dataset tqBankNumberByParentID) in BBankNumber >
for each tqBankNumberByParentID:
create tBankNumberRefDebtor.
<M-26 run BufferCopy
(input buffer tqBankNumberByParentID:handle (ihFrom),
input buffer tBankNumberRefDebtor:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if tBankNumberRefDebtor.DDocumentStatus_ID <> 0 and
tBankNumberRefDebtor.DDocumentStatus_ID <> ?
then do:
<Q-32 run DDocumentStatusPrim (all) (Read) (NoCache)
(input tBankNumberRefDebtor.DDocumentStatus_ID, (DDocumentStatusID)
input ?, (DDocumentStatusStatus)
input ?, (DDocumentStatusDocumentType)
input ?, (BankGLCode)
input viCompanyID, (CompanyId)
output dataset tqDDocumentStatusPrim) in BDDocumentStatus >
for first tqDDocumentStatusPrim where
tqDDocumentStatusPrim.tiDDocumentStatus_ID = tBankNumberRefDebtor.DDocumentStatus_ID:
assign tBankNumberRefDebtor.tcDDocumentStatusTr = <M-31 GetDDocumentStatusTranslation (input tqDDocumentStatusPrim.tcDDocumentStatusStatus (icStatus)) in BDebtor>.
end.
end. /* documentstatus_id <> 0 */
<Q-19 assign vlFcQueryRecordsAvailable = DInvoiceBankByBankNumberID (NoCache)
(input tqBankNumberByParentID.tiBankNumber_ID, (BankNumberID)) in BDInvoice >
if vlFcQueryRecordsAvailable <> false then
assign tBankNumberRefDebtor.tlBankNumberIsReferenced = true.
assign tBankNumberRefDebtor.BankNumber = tqBankNumberByParentID.tcBankNumberFormatted
tBankNumberRefDebtor.tc_Rowid = string(rowid(tBankNumberRefDebtor)).
/* Execute query only if BankPayFormat_ID <> 0 */
if tqBankNumberByParentID.tiBankPayFormat_ID <> 0 and
tqBankNumberByParentID.tiBankPayFormat_ID <> ?
then do:
<Q-28 run BankPayFormatByID (all) (Read) (NoCache)
(input tqBankNumberByParentID.tiBankPayFormat_ID, (BankPayFormatId)
input tqBankNumberByParentID.tiCompany_ID, (CompanyId)
output dataset tqBankPayFormatByID) in BBankPayFormat >
find first tqBankPayFormatByID no-error.
if available tqBankPayFormatByID
then assign tBankNumberRefDebtor.tcPayFormatTypeCode = tqBankPayFormatByID.tcPayFormatTypeCode
tBankNumberRefDebtor.tcPayFormatTypePaymentInstrument = tqBankPayFormatByID.tcPayFormatTypePayInstrument
tBankNumberRefDebtor.tcCompanyCode = tqBankPayFormatByID.tcCompanyCode
tBankNumberRefDebtor.tcOwnBankNumber = tqBankPayFormatByID.tcBankNumber
tBankNumberRefDebtor.tcOwnGLCode = tqBankPayFormatByID.tcGLCode.
end.
/* tDPayFormatTypeRef and tDBankNumberPayCodeRef */
<Q-14 run BankNumberPayCodeByBankNbrID (all) (Read) (NoCache)
(input tBankNumberRefDebtor.BankNumber_ID, (BankNumberId)
output dataset tqBankNumberPayCodeByBankNbrID) in BBankNumber >
for each tqBankNumberPayCodeByBankNbrID
break by tqBankNumberPayCodeByBankNbrID.tiBankNumber_ID:
create tDBankNumberPayCodeRef.
<M-15 run BufferCopy
(input buffer tqBankNumberPayCodeByBankNbrID:handle (ihFrom),
input buffer tDBankNumberPayCodeRef:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
assign tDBankNumberPayCodeRef.tc_ParentRowid = tBankNumberRefDebtor.tc_Rowid
tDBankNumberPayCodeRef.tc_Rowid = string(rowid(tDBankNumberPayCodeRef))
tDBankNumberPayCodeRef.tcPayFormatCodeValue = (if (tqBankNumberPayCodeByBankNbrID.tcPayFormatCode <> "" and
tqBankNumberPayCodeByBankNbrID.tcPayFormatCode <> ? and
tqBankNumberPayCodeByBankNbrID.tcPayFormatCode <> "?") then
tqBankNumberPayCodeByBankNbrID.tcPayFormatCode
else
tqBankNumberPayCodeByBankNbrID.tcBankNumberPayCodeValue).
end.
if tBankNumberRefDebtor.BankAccFormat_ID <> ?
and tBankNumberRefDebtor.BankAccFormat_ID <> 0 then do:
<Q-27 run BankAccFormatPrim (all) (Read) (NoCache)
(input tBankNumberRefDebtor.BankAccFormat_ID, (BankAcctFormatId)
input ?, (BankAcctFormatCode)
output dataset tqBankAccFormatPrim) in BBankAccountFormat >
find first tqBankAccFormatPrim no-error.
if available tqBankAccFormatPrim then
assign
tBankNumberRefDebtor.tcBankAccFormatCode = tqBankAccFormatPrim.tcBankAccFormatCode.
end.
/* Get the bank account format sections for each bank account number */
/* Data have to be stored in supportive temporary table then then copied to */
/* instance dependent temp table */
assign vhFcComponent = ?.
<M-22 run ApiGetBankNumberSections
(input tBankNumberRefDebtor.BankNumber (icBankAccountNumber),
input tBankNumberRefDebtor.tcBankAccFormatCode (icBankAccountFormat),
input tBankNumberRefDebtor.BankNumber_ID (iiBankAccountNumberId),
output tBankNumberSectionRefDebtorTem (tBankNumberSection),
output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave debtors.
for each tBankNumberSectionRefDebtorTem
by tBankNumberSectionRefDebtorTem.tiBankAccFormatSectSequence:
create tBankNumberSectionRefDebtor.
buffer-copy tBankNumberSectionRefDebtorTem
to tBankNumberSectionRefDebtor
assign tBankNumberSectionRefDebtor.tc_Rowid = tBankNumberRefDebtor.tc_Rowid + "."
+ string(tBankNumberSectionRefDebtorTem.tiBankAccFormatSectSequence)
tBankNumberSectionRefDebtor.tc_ParentRowid = tBankNumberRefDebtor.tc_Rowid.
end.
end.
end.
/* Make sure t_iDebtor is also up-to-date */
if tDebtor.tc_Status = " ":U or
tDebtor.tc_Status = ? or
tDebtor.tc_Status = "?":U
then do:
find t_iDebtor where
t_iDebtor.tc_Rowid = tDebtor.tc_Rowid
no-error.
if available t_iDebtor
then raw-transfer tDebtor to t_iDebtor.
end.
end. /* for each tdebtor */
/*Stop queries*/
<Q-8 run PaymentConditionByIdCode (Stop) in BPaymentCondition >
<Q-10 run BankNumberByParentID (Stop) in BBankNumber >
<Q-16 run BankNumberPayCodeByBankNbrID (Stop) in BBankNumber >
<Q-17 run BankPayFormatByID (Stop) in BBankPayFormat >
<Q-34 run DDocumentStatusPrim (Stop) in BDDocumentStatus >
<I-25 {bFcCloseInstance
&CLASS = "BBankNumber"}>