project QadFinancials > class BDebtorReport > method DebtorBillingNonBillInvoiceAAB
Parameters
itAgingDate | input | date | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bdebtorreport.p)
empty temp-table tqDebtorNonBillingAABMR.
/* Get Invoice which is not in Bill */
<Q-74 run DebtorNonBillingAABMR (all) (Read) (NoCache)
(input viDRCurrentCompany_ID, (CompanyId)
input vcFromDebtorCodeFilter, (FromDebtorCode)
input vcToDebtorCodeFilter, (ToDebtorCode)
input vcCandoDebtorCodeFilter, (CandoDebtorCode)
input vcFromBRCodeFilter, (FromBRCode)
input vcToBRCodeFilter, (ToBRCode)
input vcCandoBRCodeFilter, (CandoBRCode)
input vcFromDivisionCodeFilter, (FromDivisionCode)
input vcToDivisionCodeFilter, (ToDivisionCode)
input vcCandoDivisionCodeFilter, (CandoDivisionCode)
input vcFromJournalCodeFilter, (FromJournalCode)
input vcToJournalCodeFilter, (ToJournalCode)
input vcCandoJournalCodeFilter, (CandoJournalCode)
input vcCurrencyCodeFilter, (CurrencyCode)
input itAgingDate, (AgeingDate)
input vcCandoDContrGLCodeFilter, (CanDoGLCode)
input vcFromDContrGLCodeFilter, (FromGLCode)
input vcToDContrGLCodeFilter, (ToGLCode)
input vcCanDoCostCentreCodeFilter1, (CanDoCCCode)
input vcFromCostCentreCodeFilter1, (FromCCCode)
input vcToCostCentreCodeFilter1, (ToCCCode)
input vcCandoProjectCodeFilter, (CanDoProjectCode)
input vcFromProjectCodeFilter, (FromProjectCode)
input vcToProjectCodeFilter, (ToProjectCode)
input vcDebtorTypeFilter, (DebtorTypeCode)
input viToYearPeriodFilter, (EndOfYearPeriod)
input vcSalespersonFilter, (Salesperson)
input vcPaymentGroupFilter, (PaymentGroup)
output dataset tqDebtorNonBillingAABMR) in BDebtorReport>
/* Get invoice which belong to other Bill entity */
<Q-11 run DebtorBillingAABMRDifEntity (all) (Read) (NoCache)
(input viDRCurrentCompany_ID, (CompanyId)
input vcFromDebtorCodeFilter, (FromDebtorCode)
input vcToDebtorCodeFilter, (ToDebtorCode)
input vcCandoDebtorCodeFilter, (CandoDebtorCode)
input vcFromBRCodeFilter, (FromBRCode)
input vcToBRCodeFilter, (ToBRCode)
input vcCandoBRCodeFilter, (CandoBRCode)
input vcFromDivisionCodeFilter, (FromDivisionCode)
input vcToDivisionCodeFilter, (ToDivisionCode)
input vcCandoDivisionCodeFilter, (CandoDivisionCode)
input vcFromJournalCodeFilter, (FromJournalCode)
input vcToJournalCodeFilter, (ToJournalCode)
input vcCandoJournalCodeFilter, (CandoJournalCode)
input vcCurrencyCodeFilter, (CurrencyCode)
input itAgingDate, (AgeingDate)
input vcCandoDContrGLCodeFilter, (CanDoGLCode)
input vcFromDContrGLCodeFilter, (FromGLCode)
input vcToDContrGLCodeFilter, (ToGLCode)
input vcCanDoCostCentreCodeFilter1, (CanDoCCCode)
input vcFromCostCentreCodeFilter1, (FromCCCode)
input vcToCostCentreCodeFilter1, (ToCCCode)
input vcCandoProjectCodeFilter, (CanDoProjectCode)
input vcFromProjectCodeFilter, (FromProjectCode)
input vcToProjectCodeFilter, (ToProjectCode)
input vcDebtorTypeFilter, (DebtorTypeCode)
input viToYearPeriodFilter, (EndOfYearPeriod)
input vcSalespersonFilter, (Salesperson)
input vcPaymentGroupFilter, (PaymentGroup)
output dataset tqDebtorBillingAABMRDifEntity) in BDebtorReport>
/* Merge two query results together */
for each tqDebtorBillingAABMRDifEntity:
create tqDebtorNonBillingAABMR.
buffer-copy tqDebtorBillingAABMRDifEntity to tqDebtorNonBillingAABMR.
end.
/* Main Loop: Process each Invoice */
for each tqDebtorNonBillingAABMR
break by tqDebtorNonBillingAABMR.tiDInvoice_ID:
if first-of(tqDebtorNonBillingAABMR.tiDInvoice_ID)
then do:
assign vlSkip = false
vdBalanceCC = 0
vdBalanceLC = 0
vdBalanceTC = 0.
/* If "Within terms = no", skip all invoices that aren't due yet */
if vlInvoicesWithinTermsFilter = false
then do :
/* Prepayments and Adjustments: valid only if "Within terms = yes" */
if (tqDebtorNonBillingAABMR.tcDInvoiceType = {&INVOICETYPE-PREPAYMENT} or
tqDebtorNonBillingAABMR.tcDInvoiceType = {&INVOICETYPE-ADJUSTMENT})
then assign vlSkip = true.
else
if tqDebtorNonBillingAABMR.ttDInvoiceDueDate >= vtDateForAgeingCalcFilter
then assign vlSkip = true.
else
if tqDebtorNonBillingAABMR.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then do:
<Q-19 run DInvoiceStageByInvoice (all) (Read) (NoCache)
(input tqDebtorNonBillingAABMR.tiDInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceStageByInvoice) in BDebtorReport>
assign vlSkip = not can-find (first tqDInvoiceStageByInvoice where
tqDInvoiceStageByInvoice.tiDInvoice_ID = tqDebtorNonBillingAABMR.tiDInvoice_ID and
tqDInvoiceStageByInvoice.ttDInvoiceStageDueDate < vtDateForAgeingCalcFilter).
end. /* &PAYMENTCONDITIONPAYMENTTYPE-STAGED} */
end. /* if vlInvoicesWithinTermsFilter = false */
else
if tqDebtorNonBillingAABMR.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then do :
<Q-67 run DInvoiceStageByInvoice (all) (Read) (NoCache)
(input tqDebtorNonBillingAABMR.tiDInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceStageByInvoice) in BDebtorReport>
end.
end. /* if first-of(tqDebtorNonBillingAABMR.tiDInvoice_ID) */
if vlSkip then next.
assign vdBalanceTC = vdBalanceTC + tqDebtorNonBillingAABMR.tdPostingLineDebitTC - tqDebtorNonBillingAABMR.tdPostingLineCreditTC
vdBalanceLC = vdBalanceLC + tqDebtorNonBillingAABMR.tdPostingLineDebitLC - tqDebtorNonBillingAABMR.tdPostingLineCreditLC
vdBalanceCC = vdBalanceCC + tqDebtorNonBillingAABMR.tdPostingLineDebitCC - tqDebtorNonBillingAABMR.tdPostingLineCreditCC.
if last-of(tqDebtorNonBillingAABMR.tiDInvoice_ID)
then do:
assign vdOriginal1CC = tqDebtorNonBillingAABMR.tdDInvoiceOriginalDebitCC - tqDebtorNonBillingAABMR.tdDInvoiceOriginalCreditCC
vdOriginal1LC = tqDebtorNonBillingAABMR.tdDInvoiceOriginalDebitLC - tqDebtorNonBillingAABMR.tdDInvoiceOriginalCreditLC
vdOriginal1TC = tqDebtorNonBillingAABMR.tdDInvoiceOriginalDebitTC - tqDebtorNonBillingAABMR.tdDInvoiceOriginalCreditTC.
case vcReportingCurrencyFilter:
when {&CURRENCYTYPE-CC}
then assign vdBalanceXC = vdBalanceCC
vdOriginal1XC = vdOriginal1CC.
when {&CURRENCYTYPE-LC}
then assign vdBalanceXC = vdBalanceLC
vdOriginal1XC = vdOriginal1LC.
when {&CURRENCYTYPE-TC}
then assign vdBalanceXC = vdBalanceTC
vdOriginal1XC = vdOriginal1TC.
end.
if tqDebtorNonBillingAABMR.tcPaymentConditionPaymentTyp <> {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then do:
/* tcrDebtorBillingAAB */
create tqDebtorBillingAAB.
buffer-copy tqDebtorNonBillingAABMR to tqDebtorBillingAAB.
assign tqDebtorBillingAAB.tcControlGLCode = tqDebtorNonBillingAABMR.tcGLCode
tqDebtorBillingAAB.tcControlGLDescription = tqDebtorNonBillingAABMR.tcGLDescription
tqDebtorBillingAAB.tdBalanceXC = vdBalanceXC
tqDebtorBillingAAB.tdBalanceTC = vdBalanceTC
tqDebtorBillingAAB.tcDiscountType = "Y":U
tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC = 0
tqDebtorBillingAAB.tcBillGroup = "Non-Bill"
tqDebtorBillingAAB.tcBillCompanyCode = vcDRCompanyFilter
tqDebtorBillingAAB.tcBillSortKey = "9999999999999".
/* Determine the Ageing Column. For Prepayments/Adjustments there is an option to put them in first column */
if ((tqDebtorBillingAAB.tcDInvoiceType = {&INVOICETYPE-PREPAYMENT} or
tqDebtorBillingAAB.tcDInvoiceType = {&INVOICETYPE-ADJUSTMENT}) and
(not vlIsAgePrepayAdjFilter or vlIsAgePrepayAdjFilter = ?) and
vlIsAABGroup <> true)
then assign tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = vdBalanceXC.
else do:
find first tAgeingPeriod where
tAgeingPeriod.ttAgeingPeriodFromDate <= tqDebtorBillingAAB.ttDInvoiceDueDate and
tAgeingPeriod.ttAgeingPeriodToDate >= tqDebtorBillingAAB.ttDInvoiceDueDate
no-error.
if available tAgeingPeriod
then case tAgeingPeriod.tiAgeingPeriodSeq:
when 1
then assign tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = vdBalanceXC.
when 2
then assign tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC = vdBalanceXC.
when 3
then assign tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC = vdBalanceXC.
when 4
then assign tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC = vdBalanceXC.
when 5
then assign tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC = vdBalanceXC.
end case.
end. /*else do*/
if tqDebtorBillingAAB.tcDInvoiceType = {&INVOICETYPE-DEDUCTION} then
do:
<M-29 run CalDeductionStatus
(input tqDebtorBillingAAB.tiDInvoice_ID (iiDInvoiceID),
output tqDebtorBillingAAB.tcDInvoiceDeductionStatus (ocDeductionStatus),
input-output tqDebtorBillingAAB.tcDInvoiceType (bcDInvoiceType),
output oiReturnStatus (oiReturnStatus)) in BDebtorReport>
end.
end. /* NOT STAGED */
else do :
for each tqDInvoiceStageByInvoice where
tqDInvoiceStageByInvoice.tiDInvoice_ID = tqDebtorNonBillingAABMR.tiDInvoice_ID
by tqDInvoiceStageByInvoice.ttDInvoiceStageDueDate desc:
case vcReportingCurrencyFilter:
when {&CURRENCYTYPE-CC}
then assign vdStageAmountXC = if vdOriginal1XC * tqDInvoiceStageByInvoice.tdDInvoiceStageAmountCC > 0
then tqDInvoiceStageByInvoice.tdDInvoiceStageAmountCC
else - tqDInvoiceStageByInvoice.tdDInvoiceStageAmountCC.
when {&CURRENCYTYPE-LC}
then assign vdStageAmountXC = if vdOriginal1XC * tqDInvoiceStageByInvoice.tdDInvoiceStageAmountLC > 0
then tqDInvoiceStageByInvoice.tdDInvoiceStageAmountLC
else - tqDInvoiceStageByInvoice.tdDInvoiceStageAmountLC.
when {&CURRENCYTYPE-TC}
then assign vdStageAmountXC = if vdOriginal1XC * tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC > 0
then tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC
else - tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC.
end. /* case */
assign vdStageAmountTC = if vdOriginal1TC * tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC > 0
then tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC
else - tqDInvoiceStageByInvoice.tdDInvoiceStageAmountTC.
if vdBalanceXC * vdOriginal1XC > 0
then do:
/* tcrDebtorBillingAAB */
create tqDebtorBillingAAB.
buffer-copy tqDebtorNonBillingAABMR to tqDebtorBillingAAB.
assign tqDebtorBillingAAB.tcControlGLCode = tqDebtorNonBillingAABMR.tcGLCode
tqDebtorBillingAAB.tcControlGLDescription = tqDebtorNonBillingAABMR.tcGLDescription
tqDebtorBillingAAB.tcDiscountType = "Y":U
tqDebtorBillingAAB.ttDInvoiceDueDate = tqDInvoiceStageByInvoice.ttDInvoiceStageDueDate
tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC = 0
tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC = 0
tqDebtorBillingAAB.tcBillGroup = "Non-Bill"
tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC = 0
tqDebtorBillingAAB.tcBillSortKey = "9999999999999".
if (vdBalanceXC - vdStageAmountXC) * vdOriginal1XC > 0
then do:
assign vdBalanceXC = vdBalanceXC - vdStageAmountXC
vdBalanceTC = vdBalanceTC - vdStageAmountTC
tqDebtorBillingAAB.tdBalanceXC = vdStageAmountXC
tqDebtorBillingAAB.tdBalanceTC = vdStageAmountTC.
end.
else do:
assign tqDebtorBillingAAB.tdBalanceXC = vdBalanceXC
tqDebtorBillingAAB.tdBalanceTC = vdBalanceTC.
assign vdBalanceXC = vdBalanceXC - vdStageAmountXC
vdBalanceTC = vdBalanceTC - vdStageAmountTC.
end.
find first tAgeingPeriod where
tAgeingPeriod.ttAgeingPeriodFromDate <= tqDInvoiceStageByInvoice.ttDInvoiceStageDueDate and
tAgeingPeriod.ttAgeingPeriodToDate >= tqDInvoiceStageByInvoice.ttDInvoiceStageDueDate no-error.
if available tAgeingPeriod
then case tAgeingPeriod.tiAgeingPeriodSeq:
when 1
then assign tqDebtorBillingAAB.tdAgeingPeriod1BalanceXC = tqDebtorBillingAAB.tdBalanceXC.
when 2
then assign tqDebtorBillingAAB.tdAgeingPeriod2BalanceXC = tqDebtorBillingAAB.tdBalanceXC.
when 3
then assign tqDebtorBillingAAB.tdAgeingPeriod3BalanceXC = tqDebtorBillingAAB.tdBalanceXC.
when 4
then assign tqDebtorBillingAAB.tdAgeingPeriod4BalanceXC = tqDebtorBillingAAB.tdBalanceXC.
when 5
then assign tqDebtorBillingAAB.tdAgeingPeriod5BalanceXC = tqDebtorBillingAAB.tdBalanceXC.
end case.
end.
end. /* for each tqDInvoiceStageByInvoice */
end. /* STAGED */
end. /* if last-of(tqDebtorBillingAAB.tiDInvoice_ID) */
end. /* for each tqDebtorBillingAAB */