Description
Method to create the Finance Charge Invoices
Parameters
icAction | input | character | |
icCurrencyFilter | input | character | |
itPostingDate | input | date | |
idMinimumFinanceCharge | input | decimal | |
icReasonCodeNAFinChg | input | character | |
itAsOfDate | input | date | |
idInterestRate | input | decimal | |
icCustomerFilter | input | character | |
dDebtorFinCharge | input | dataset | |
bcLstReturn | input-output | character | |
bcLstPrimKey | input-output | character | |
bcLstRowid | input-output | character | |
olSaveAsDraft | output | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bdebtorfinancecharge.p)
/* Set default return status */
assign oiReturnStatus = -98.
assign vdMinimumFinanceCharge = idMinimumFinanceCharge
vcReasonCodeNAFinChg = icReasonCodeNAFinChg
vtFCPostingDate = itPostingDate
vcFCCurrencyCode = icCurrencyFilter
vtFCAsOfDate = itAsOfDate
vdInterestRate = idInterestRate
vcFCCustomerFilter = icCustomerFilter
viFinChargeToCreateSeq = 0.
empty temp-table tUpdateDILastFinChargeDateFinC.
empty temp-table tApiFinChgDInvoice.
for each tDebtorFinChgMaster where
tDebtorFinChgMaster.tlIsDebtorSelected = true:
for each tDebtorFinanceCharge where
tDebtorFinanceCharge.tcCustomer = tDebtorFinChgMaster.tcCustomerCode AND
(tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-INVOICE} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-CREDITNOTE} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-INVOICECORRECTION} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-PREPAYMENT} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION} OR
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-ADJUSTMENT}) AND
tDebtorFinanceCharge.tiDInvoice_ID <> 0 AND
tDebtorFinanceCharge.tlSelectInvoice = true:
create tUpdateDILastFinChargeDateFinC.
assign tUpdateDILastFinChargeDateFinC.tiDInvoice_ID = tDebtorFinanceCharge.tiDInvoice_ID
tUpdateDILastFinChargeDateFinC.ttDInvoiceLastFinChargeDate = vtFCAsOfDate.
end. /* for each tDebtorFinanceCharge */
end. /* for each tDebtorFinChgMaster */
/* Recalculation of Finance Charges depending on users inclusion/exclusion of spedific Debtor/Invoices */
<M-32 run FCDInvoiceCommitCalculate
(output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* Check if there is a financecharge with an amount > 0. If not, leave */
if not can-find(first tDebtorFinanceCharge where
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} and
tDebtorFinanceCharge.tdFinanceCharge > 0)
then do:
assign vcMessage = trim(#T-23'There are no valid finance charges in your selection.':255(470290866)T-23#)
oiReturnStatus = -1.
<M-76 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-645237':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
return.
end. /* if not can-find(first tDebtorFinanceCharge where */
<Q-60 run PeriodByPeriodStartEndDate (Start) in BPeriod >
for each tDebtorFinanceCharge where
tDebtorFinanceCharge.tcInvoiceType = {&INVOICETYPE-FINANCECHARGE} AND
tDebtorFinanceCharge.tiDInvoice_ID = 0 AND
tDebtorFinanceCharge.tdFinanceCharge > 0 :
<Q-39 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input tDebtorFinanceCharge.tcEntity, (CompanyCode)
output dataset tqCompanyPrim) in BCompany >
find first tqCompanyPrim no-error.
if not available tqCompanyPrim
then do:
assign oiReturnStatus = -1.
vcMessage = trim(#T-57'Error in loading Company Data.':255(64892)T-57#).
<M-58 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-6824':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
Return.
end. /* if not available tqCompanyPrim */
else do:
/* To find the Ship-To Address */
<Q-31 run DebtorPrim (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDebtorFinanceCharge.tcCustomer, (DebtorCode)
input ?, (Debtor_ID)
output dataset tqDebtorPrim) in BDebtor>
find first tqDebtorPrim where
tqDebtorPrim.tcDebtorCode = tDebtorFinanceCharge.tcCustomer
no-error.
if available tqDebtorPrim
then assign viDebtorID1 = tqDebtorPrim.tiDebtor_ID.
<Q-54 run DebtorShiptoByDebtor (all) (Read) (NoCache)
(input viDebtorID1, (DebtorId)
input tqCompanyPrim.tiCompany_ID, (CompanyId)
output dataset tqDebtorShiptoByDebtor) in BDebtorShipTo>
find first tqDebtorShiptoByDebtor no-error.
if available tqDebtorShipToByDebtor
then assign viShipToAddressID = tqDebtorShiptoByDebtor.tiAddress_ID
vcShipToAddressCity = tqDebtorShiptoByDebtor.tcAddressCity
vcShipToAddressState = tqDebtorShiptoByDebtor.tcStateCode
vcShipToAddressStreet1 = tqDebtorShiptoByDebtor.tcAddressStreet1
vcShipToAddressStreet2 = tqDebtorShiptoByDebtor.tcAddressStreet2
vcShipToAddressStreet3 = tqDebtorShiptoByDebtor.tcAddressStreet3
vcShipToAddressTypeCode = tqDebtorShiptoByDebtor.tcAddressTypeCode
vcShipToAddressZip = tqDebtorShiptoByDebtor.tcAddressZip
vcShipToAddressBusinessRelnCode = tqDebtorShiptoByDebtor.tcBusinessRelationCode
vcShipToAddressCountryCode = tqDebtorShiptoByDebtor.tcCountryCode.
else do:
<Q-66 run DebtorByDebtor (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
input ?, (DebtorId)
input tDebtorFinanceCharge.tcCustomer, (DebtorCode)
output dataset tqDebtorByDebtor) in BDebtor >
find first tqDebtorByDebtor no-error.
if available tqDebtorByDebtor
then assign viShipToAddressID = tqDebtorByDebtor.tiAddress_ID
vcShipToAddressCity = tqDebtorByDebtor.tcAddressCity
vcShipToAddressState = tqDebtorByDebtor.tcAddressState
vcShipToAddressStreet1 = tqDebtorByDebtor.tcAddressStreet1
vcShipToAddressStreet2 = tqDebtorByDebtor.tcAddressStreet2
vcShipToAddressStreet3 = tqDebtorByDebtor.tcAddressStreet3
vcShipToAddressTypeCode = tqDebtorByDebtor.tcAddressTypeCode
vcShipToAddressZip = tqDebtorByDebtor.tcAddressZip
vcShipToAddressBusinessRelnCode = tqDebtorByDebtor.tcBusinessRelationCode
vcShipToAddressCountryCode = tqDebtorByDebtor.tcCountryCode.
end. /* else do: */
/* To find Exchange Rate */
if vcFCCurrencyCode <> vcCompanyLC
then do :
<M-88 run GetExchangeRate
(input ? (iiCompanyID),
input ? (iiFromCurrencyID),
input vcFCCurrencyCode (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input vtFCPostingDate (itValidityDate),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if vcFCCurrencyCode <> vcCompanyLC */
else assign vdExchangeRate = 1
vdExchangeRateScale = 1.
assign viFinChargeToCreateSeq = viFinChargeToCreateSeq + 1
vcFinChargeRowId = STRING(viFinChargeToCreateSeq).
/*FIND POSTING YEAR AND PERIOD*/
<Q-9 run PeriodByPeriodStartEndDate (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input vtFCPostingDate, (Date)
input ?, (PeriodId)
input ?, (PeriodYear)
input ?, (PeriodPeriod)
output dataset tqPeriodByPeriodStartEndDate) in BPeriod >
find first tqPeriodByPeriodStartEndDate
where tqPeriodByPeriodStartEndDate.ttPeriodStartDate <= vtFCPostingDate
and tqPeriodByPeriodStartEndDate.ttPeriodEndDate >= vtFCPostingDate
no-error.
if not available tqPeriodByPeriodStartEndDate
then do:
assign oiReturnStatus = -1.
<M-22 run SetMessage
(input #T-83'The posting date must be between start and end date of the GL period.':255(3634)T-83# (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input vtFCPostingDate (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-384571':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
return.
end. /*IF NOT AVAIABLE tqPeriodByPeriodStartEndDate*/
/* Create and populate DInvoice Table */
create tApiFinChgDInvoice.
assign tApiFinChgDInvoice.DInvoicePostingYear = tqPeriodByPeriodStartEndDate.tiPeriodYear
tApiFinChgDInvoice.DInvoicePostingPeriod = tqPeriodByPeriodStartEndDate.tiPeriodPeriod
tApiFinChgDInvoice.DInvoiceDueDate = vtFCPostingDate
tApiFinChgDInvoice.tcDebtorCode = tDebtorFinanceCharge.tcCustomer
tApiFinChgDInvoice.tcJournalCode = tDebtorFinanceCharge.tcSalesJournalReference
tApiFinChgDInvoice.DInvoicePostingDate = vtFCPostingDate
tApiFinChgDInvoice.DInvoiceType = {&INVOICETYPE-FINANCECHARGE}
tApiFinChgDInvoice.DInvoiceDate = vtFCPostingDate
tApiFinChgDInvoice.DInvoiceTaxPointDate = vtFCPostingDate
tApiFinChgDInvoice.DInvoiceDescription = trim(substitute(#T-48'Finance Charge for the month (&1)':50(61712)T-48#,string(Month(vtFCAsOfDate))))
tApiFinChgDInvoice.tcCurrencyCode = vcFCCurrencyCode
tApiFinChgDInvoice.Company_ID = tqCompanyPrim.tiCompany_ID
tApiFinChgDInvoice.tcReasonCode = tDebtorFinanceCharge.tcReasonCode
tApiFinChgDInvoice.DInvoiceDIText = trim(substitute(#T-49'Finance Charge for the month (&1)':50(61712)T-49#,string(Month(vtFCAsOfDate))))
tApiFinChgDInvoice.DInvoiceOriginalDebitTC = <M-64 RoundAmount
(input tDebtorFinanceCharge.tdFinanceCharge (idUnroundedAmount),
input ? (iiCurrencyID),
input vcFCCurrencyCode (icCurrencyCode)) in BDebtorFinanceCharge>
tApiFinChgDInvoice.DInvoiceOriginalDebitLC = <M-65 RoundAmount
(input tDebtorFinanceCharge.tdFinanceCharge * vdExchangeRate * vdExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input ? (icCurrencyCode)) in BDebtorFinanceCharge>
tApiFinChgDInvoice.tcCostCentreCode = tDebtorFinanceCharge.tcCostCentreCode
tApiFinChgDInvoice.tcProjectCode = tDebtorFinanceCharge.tcProjectCode
tApiFinChgDInvoice.tcDivisionCode = tDebtorFinanceCharge.tcDivisionCode
tApiFinChgDInvoice.ShipToAddress_ID = viShipToAddressID
tApiFinChgDInvoice.tcShipToAddressCity = vcShipToAddressCity
tApiFinChgDInvoice.tcShipToAddressStreet1 = vcShipToAddressStreet1
tApiFinChgDInvoice.tcShipToAddressStreet2 = vcShipToAddressStreet2
tApiFinChgDInvoice.tcShipToAddressStreet3 = vcShipToAddressStreet3
tApiFinChgDInvoice.tcShipToAddressTypeCode = vcShipToAddressTypeCode
tApiFinChgDInvoice.tcShipToAddressZip = vcShipToAddressZip
tApiFinChgDInvoice.tcShipToBusinessRelationCode = vcShipToAddressBusinessRelnCode
tApiFinChgDInvoice.DInvoiceExchangeRate = vdExchangeRate
tApiFinChgDInvoice.DInvoiceRateScale = vdExchangeRateScale
tApiFinChgDInvoice.tc_Rowid = vcFinChargeRowId.
end. /* else do: */
end. /* for each tDebtorFinanceCharge */
<Q-12 run PeriodByPeriodStartEndDate (Stop) in BPeriod >
/* Start & Open an instance of BDInvoice, when something goes wrong
further in this method, the BDInvoice method will be removed. */
find first tApiFinChgDInvoice no-error.
if available tApiFinChgDInvoice
then do:
if viDInvoiceFromBDebtorFinChgID EQ 0 or viDInvoiceFromBDebtorFinChgID EQ ?
then do:
<I-33 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BDInvoice"}>
end. /* if viDInvoiceFromBDebtorFinChargeID EQ 0 */
else do:
<I-34 {bFcOpenInstance
&CLASS = "BDInvoice"}>
end. /* else do */
/* Call method in BDInvoice that will do all processing
Clean-up instance and handle the return of the method */
assign icAction = {&DAEMONACTION-SAVE}.
<M-35 run ApiCreateDInvoicesFinCharge
(input icAction (icAction),
input tApiFinChgDInvoice (tApiDInvoice),
input tUpdateDILastFinChargeDateFinC (tUpdateDILastFinChargeDate),
input-output vcLstReturn (bcLstReturn),
input-output vcLstPrimKey (bcLstPrimKey),
input-output vcLstRowId (bcLstRowid),
output vlSaveAsDraft (olSaveAsDraft),
output viExternalReturnStatus (oiReturnStatus)) in BDInvoice>
<I-63 {bFcCloseInstance
&CLASS = "BDInvoice"}>
if viExternalReturnStatus <> 0
then assign viLocalReturnStatus = viExternalReturnStatus.
if viExternalReturnStatus < 0
then do:
<M-46 run StopExternalInstances
(output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
assign oiReturnStatus = viLocalReturnStatus.
return.
end. /* if viExternalReturnStatus < 0 */
end. /* if available tApiFinChgDInvoice */
else do:
assign oiReturnStatus = -1.
vcMessage = trim(#T-62'Error in populating APIDinvoice Table':50(64895)T-62#).
<M-61 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-6826':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtorFinanceCharge>
Return.
end. /* else do: */
/* ========================= */
/* Set return-status = OK */
/* ========================= */
if oiReturnStatus = -98
then assign oiReturnStatus = 0.