project QadFinancials > class BDebtor > method GetDebtorInvoiceData
Description
This method is called from the Activity Dashboard to get the list of invoices for the selected Customer.
Parameters
icCompanyListID | input | character | Comma-seperated list of company-IDs |
iiDebtorID | input | integer | |
itDInvoiceStartDate | input | date | |
itDInvoiceEndDate | input | date | |
ilDInvoiceIsOpen | input | logical | |
tDInvoiceSales | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bdebtor.p)
empty temp-table tDInvoiceSales.
if iiDebtorID <> ? and iiDebtorID <> 0 and
icCompanyListID <> ? and icCompanyListID <> '':U
then do:
/* For each on company list to improve performance */
COMPANYBLOCK:
do viCompanyCnt = num-entries(icCompanyListID, ',':U) to 1 by -1:
assign viTempCompanyID = integer(entry(viCompanyCnt, icCompanyListID)) no-error.
if error-status:error
then do:
assign vcMessage = trim(#T-7'Could not retrieve the company ID from the company ID list.':255(65177)T-7#)
oiReturnStatus = -3.
<M-6 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-6950':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
leave COMPANYBLOCK.
end. /* if error-status:error */
/* ================================================================================= */
/* 1- Get the Base currency */
/* ================================================================================= */
<Q-46 run CompanyByCodeCurrActiveID (all) (Read) (NoCache)
(input viTempCompanyID, (CompanyId)
input ?, (CompanyCode)
input ?, (CompanyIsActive)
input ?, (CurrencyID)
output dataset tqCompanyByCodeCurrActiveID) in BCompany>
find first tqCompanyByCodeCurrActiveID where
tqCompanyByCodeCurrActiveID.tiCompany_ID = viTempCompanyID
no-error.
if not available tqCompanyByCodeCurrActiveID
then next.
assign vcBaseCurrencyCode = tqCompanyByCodeCurrActiveID.tcCurrencyCode
vcCompanyCodeTemp = tqCompanyByCodeCurrActiveID.tcCompanyCode.
/* ========================================================================================= */
/* 2- Get the Customer Invoices */
/* For Open invoices, we take the index on Open. */
/* For Closed invoices we take the index on date */
/* ========================================================================================= */
assign vcTemp = {&OIADJUSTLNTYPE-DINEW}.
<Q-1 run DinvoiceByDebtor (all) (Read) (NoCache)
(input viTempCompanyID, (CompanyId)
input iiDebtorID, (DebtorID)
input itDInvoiceStartDate, (InvoicStartDate)
input itDInvoiceEndDate, (InvoiceEndDate)
input (if ildInvoiceIsOpen = true then true else ?), (DInvoiceIsOpenEQUALS)
input vcTemp, (OIAdjustLnInvType)
input (if ildInvoiceIsOpen = false then true else ?), (DInvoiceIsOpenDIFFERSFROM)
output dataset tqDInvoiceByDebtor) in BDInvoice>
define buffer btqDInvoiceByDebtor for tqDInvoiceByDebtor.
/* get all record from tqDInvoiceByDebotr. */
for each tqDInvoiceByDebtor
break by tqDInvoiceByDebtor.tiDInvoice_ID :
/* We can only show each invoice once ... */
if not first-of (tqDInvoiceByDebtor.tiDInvoice_ID)
then next.
create tDInvoiceSales.
buffer-copy tqDInvoiceByDebtor to tDInvoiceSales no-error.
for each btqDInvoiceByDebtor
where btqDInvoiceByDebtor.tiDInvoice_ID = tqDInvoiceByDebtor.tiDInvoice_ID
break by btqDInvoiceByDebtor.tiDInvoice_ID:
if first-of (btqDInvoiceByDebtor.tiDInvoice_ID) then
tDInvoiceSales.tcDInvoiceOpInfoCode = btqDInvoiceByDebtor.tcDInvoiceOpInfoCode.
else
tDInvoiceSales.tcDInvoiceOpInfoCode = tDInvoiceSales.tcDInvoiceOpInfoCode + "," + btqDInvoiceByDebtor.tcDInvoiceOpInfoCode.
end.
assign tDInvoiceSales.tcDInvoiceNumber = if tqDInvoiceByDebtor.tcDInvoiceDIText = "" or
tqDInvoiceByDebtor.tcDInvoiceDIText = ""
then tqDInvoiceByDebtor.tcDInvoiceNumberForSales
else tqDInvoiceByDebtor.tcDInvoiceDIText
tDInvoiceSales.tcDInvoiceType = tqDInvoiceByDebtor.tcDInvoiceTypeForSales
tDInvoiceSales.tcOIAdjustDescription = tqDInvoiceByDebtor.tcOIAdjustDescription
tDInvoiceSales.tcBaseCurrencyCode = Vcbasecurrencycode
tDInvoiceSales.tcCurrCompanyCode = vcCompanyCodeTemp.
if tDInvoiceSales.tcDInvoiceType = {&INVOICETYPE-DEDUCTION} then
do:
<Q-64 run DInvoiceDedStatusByDInvoiceID (all) (Read) (NoCache)
(input viTempCompanyID, (CompanyId)
input tqDInvoiceByDebtor.tiDInvoice_ID, (DInvoiceID)
output dataset tqDInvoiceDedStatusByDInvoiceID) in BDInvoice>
for each tqDInvoiceDedStatusByDInvoiceID:
case tqDInvoiceDedStatusByDInvoiceID.tcDInvoiceDeductionStatus:
when {&INVOICEDEDUCTSTATUS-PENDING}
then do:
assign tDInvoiceSales.tcDInvoiceDedStatus = {&INVOICEDEDUCTSTATUS-PENDING-TR}.
leave.
end.
when {&INVOICEDEDUCTSTATUS-REJECTED}
then do:
assign tDInvoiceSales.tcDInvoiceDedStatus = {&INVOICEDEDUCTSTATUS-REJECTED-TR}.
leave.
end.
when {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT}
then do:
assign tDInvoiceSales.tcDInvoiceDedStatus = {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT-TR}.
end.
otherwise
if tDInvoiceSales.tcDInvoiceDedStatus <> {&INVOICEDEDUCTSTATUS-APPROVEDCREDIT-TR} then
assign tDInvoiceSales.tcDInvoiceDedStatus = "Written-Off/Credited".
end case.
end.
end.
if error-status:error
then do:
assign oiReturnStatus = -3
vcMessage = trim(#T-8'Internal error: buffer copy of data to another buffer failed.':255(65615)T-8#).
if ERROR-STATUS:NUM-MESSAGES > 0
then assign vcMessage = vcMessage + chr(10) +
trim(substitute(#T-9'Detailed info: &1 (&2)':252(49824)T-9#,ERROR-STATUS:GET-MESSAGE(1),string(ERROR-STATUS:GET-NUMBER(1)))).
<M-10 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-7220':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDebtor>
leave COMPANYBLOCK.
end. /* if error-status:error */
end. /* for each tqDInvoiceByDebtor. */
end. /* do viCompanyCnt = num-entries(icCompanyListID, ',':U) to 1 by -1: */
end. /* if iiDebtorID <> ? and iiDebtorID <> 0 */