Parameters
| iiPaySelID | input | integer | |
| iiCompanyID | input | integer | |
| iiDCollectionID | input | integer | |
| iiCreationUserID | input | integer | |
| oiDocumentNum | output | integer | |
| odLocalCurrencySum | output | decimal | |
| odBaseCurrencySum | output | decimal | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bdcollection.p)
if iiPaySelID <> 0 and iiPaySelID <> ?
then do:
<Q-92 run DPaySelLineByID (all) (Read) (NoCache)
(input iiCompanyID, (CompanyId)
input iiPaySelID, (PaySelID)
output dataset tqDPaySelLineByID) in BDPaymentSelection>
if can-find(first tqDPaySellineByID)
then do:
/* ====================================================================================== *
* Get company's exchange rate shared set ID *
* ====================================================================================== */
<M-40 run StartCacher
(output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-58 run GetIntegerValueFromSession
(input viSessionID (iiSessionId),
input 'SharedSetForEXCHANGERATE':U (icDataItemName),
output viExchangeRateSharedSetId (oiValue),
output viFcReturnSuper (oiReturnStatus)) in Cacher>
if viFcReturnSuper < 0 or viLocalReturn = 0
then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
assign vcMessage = #T-78'System cannot get ID of the Exchange Rate Shared Set.':255(588817158)T-78#.
<M-33 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input 'viExchangeRateSharedSetId':U (icFieldName),
input viExchangeRateSharedSetId (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'qadfin-493899':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
assign oiREturnStatus = viLocalreturn.
return.
end.
end.
assign viDocCount = 0.
payselline:
for each tqDPaySelLineByID
where tqDPaySelLineByID.tiDPaySel_ID = iiPaySelID:
<Q-19 run DInvoiceByIDAllInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input tqDPaySelLineByID.tiDPaySelLineParentObject_ID, (DInvoiceID)
output dataset tqDInvoiceByIDAllInfo) in BDInvoice>
for first tqDInvoiceByIDAllInfo
where tqDInvoiceByIDAllInfo.tiDinvoice_ID = tqDPaySelLineByID.tiDPaySelLineParentObject_ID on error undo, throw:
vhBufferForProDataSet = dataset tqDInvoiceByIDAllInfo:get-buffer-handle(1).
create tDInvoice.
assign tDInvoice.tcActionType = tqDPaySelLineByID.tcDPaySelLineStatus.
<M-53 run BufferCopy
(input vhBufferForProDataSet (ihFrom),
input buffer tDInvoice:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave payselline.
assign tDInvoice.tdInterestRate = tqDPaySelLineByID.tdDPaySelLineIntRate.
/* assign tDInvoice.tcInternalRef = string(tDInvoice.DInvoiceInternalRef,'99999999') + '00'. */
/* Retrieve the legal document number - We are only interested in the first legal doc number */
/* kyn - changed legal number to shipper as per ISSUE I19-505*/
<Q-81 run DInvoiceOpInfoByInvoiceIDByType (all) (Read) (NoCache)
(input tDInvoice.DInvoice_ID, (InvoiceID)
input {&DINVOICEOPINFOTYPE-SHIPPER}, (Type)
output dataset tqDInvoiceOpInfoByInvoice) in BDInvoice>
for first tqDInvoiceOpInfoByInvoice
where tqDInvoiceOpInfoByInvoice.tcDInvoiceOpInfoType = {&DINVOICEOPINFOTYPE-SHIPPER}:
assign tDInvoice.tcLegalDocNumber = tqDInvoiceOpInfoByInvoice.tcDInvoiceOpInfoCode.
end.
<Q-36 run DPaySelLineStageByDPaySelLine (all) (Read) (NoCache)
(input tqDPaySelLineByID.tiDPaySelLine_ID, (DPaySelLineID)
output dataset tqDPaySelLineStageByDPaySelLine) in BDPaymentSelection>
assign vlStages = false.
for each tqDPaySelLineStageByDPaySelLine
where tqDPaySelLineStageByDPaySelLine.tiDPaySelLine_ID = tqDPaySelLineByID.tiDPaySelLine_ID on error undo, throw:
assign vlstages = true.
if tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgPaymAmtTC <> 0
then do:
vhBufferForProDataSet = dataset tqDPaySelLineStageByDPaySelLine:get-buffer-handle(1).
create tDInvoiceStage.
<M-8 run BufferCopy
(input vhBufferForProDataSet (ihFrom),
input buffer tDInvoiceStage:handle (ihTo),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave payselline.
assign
tDInvoiceStage.tdStagePayAmount = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgPaymAmtTC
tDInvoiceStage.tcInternalRef = tqDPaySelLineStageByDPaySelLine.tcDPaySelPayRefCode
tDInvoiceStage.tdInterestRate = tqDPaySelLineStageByDPaySelLine.tdDPaySelLineStgIntRate
tDInvoiceStage.tcBankReference = tqDPaySelLineStageByDPaySelLine.tcDPaySelPayRefBankRef
tDInvoiceStage.tcActionType = tqDPaySelLineStageByDPaySelLine.tcDPaySelLineStgStatus.
end.
end. /* End of stages */
if not vlStages
then do:
<Q-46 run DPaySelPayRefByPaySelLine (all) (Read) (NoCache)
(input tqDPaySelLineByID.tiDPaySelLine_ID, (PaySelLineID)
input 0, (PaySelLineStageID)
output dataset tqDPaySelPayRefByPaySelLine) in BDPaymentSelection>
for first tqDPaySelPayRefByPaySelLine
where tqDPaySelPayRefByPaySelLine.tiDPaySelLine_ID = tqDPaySelLineByID.tiDPaySelLine_ID
and tqDPaySelPayRefByPaySelLine.tiDPaySelLineStg_id = 0 on error undo, throw:
assign
tDInvoice.tcInternalRef = tqDPaySelPayRefByPaySelLine.tcDPaySelPayRefCode
tDInvoice.tcBankReference = tqDPaySelPayRefByPaySelLine.tcDPaySelPayRefBankRef.
end.
end. /*not stages */
create tDDocument.
assign vcInvoiceAmountCrDt = ""
tDDocument.tc_ParentRowid = ""
viDocCount = viDocCount - 1
tDDocument.tc_rowid = string(viDocCount)
tDDocument.DDocument_Id = tqDInvoiceByIDAllInfo.tiDInvoice_ID
tDInvoice.tiDDocumentID = tDDocument.DDocument_Id
tDDocument.Company_ID = tqDPaySelLineByID.tiCompany_id
tDDocument.DCollection_ID = iiDCollectionID
tDDocument.CreationUsr_ID = iiCreationUserID
tDDocument.DPaySel_ID = tqDPaySelLineByID.tiDPaySel_ID
tDDocument.BankNumber_ID = tqDPaySelLineByID.tiBankNumber_ID
tDDocument.DDocumentType = tqDPaySelLineByID.tcPayFormatTypePayInstrument
tDDocument.DDocumentSubType = {&DOCUMENTSUBTYPE-AUTO}
tDDocument.DDocumentYear = year(today)
tDDocument.DDocumentReference = "":U
tDDocument.DDocumentDueDate = tqDPaySelLineByID.ttDPaySelDate
tDDocument.DDocumentStatus = tqDPaySelLineByID.tcDPaySelStatus
tDDocument.DDocumentIncassoSelectCode = tqDPaySelLineByID.tcDPaySelCode
tDDocument.Debtor_ID = tqDInvoiceByIDAllInfo.tiDebtor_ID
tDDocument.gl_id = tqDPaySelLineByID.tiGL_ID
tDDocument.Currency_ID = tqDInvoiceByIDAllInfo.tiDInvoiceCurrency_ID
tDDocument.DDocumentIsOpen = true
tDDocument.DDocumentCreationDate = today
tDDocument.DDocumentTimesPrinted = 0
tDDocument.DDocumentCreationTime = time
tDDocument.DDocumentExchangeRate = tqDInvoiceByIDAllInfo.tdDInvoiceExchangeRate
tDDocument.DDocumentRateScale = tqDInvoiceByIDAllInfo.tdDInvoiceRateScale
tDDocument.DDocumentCCRate = tqDInvoiceByIDAllInfo.tdDInvoiceCCRate
tDDocument.DDocumentCCScale = tqDInvoiceByIDAllInfo.tdDInvoiceCCRate.
<Q-6 run DDocumentStatusByTypeStatusGL (all) (Read) (Cache)
(input iiCompanyID, (CompanyId)
input tDDocument.DDocumentType, (DDocumentStatusDocumentType)
input tDDocument.DDocumentStatus, (DDocumentStatusStatus)
input tDDocument.GL_ID, (BankGLId)
input ?, (BankGLCode)
output dataset tqDDocumentStatusByTypeStatusGL) in BDDocumentStatus>
for first tqDDocumentStatusByTypeStatusGL
where tqDDocumentStatusByTypeStatusGL.tcDDocumentStatusDocType = tDDocument.DDocumentType
and tqDDocumentStatusByTypeStatusGL.tcDDocumentStatusStatus = tDDocument.DDocumentStatus:
assign tDDocument.DDocumentValueDays = tqDDocumentStatusByTypeStatusGL.tiDDocumentStatusDefValDays.
end.
if tqDInvoiceByIDAllInfo.tdDInvoiceOriginalDebitTC <> 0
and tqDInvoiceByIDAllInfo.tdDInvoiceOriginalDebitTC <> ?
then
assign vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}.
else
assign vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}.
if vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign
tDDocument.DDocumentOriginalDebitTC = tqDPaySelLineByID.tdDPaySelLineAmountTC
tDDocument.DDocumentOriginalCreditTC = 0.
else
assign
tDDocument.DDocumentOriginalDebitTC = 0
tDDocument.DDocumentOriginalCreditTC = tqDPaySelLineByID.tdDPaySelLineAmountTC.
<Q-73 run CompanyForCurrencyDetSharedSet (all) (Read) (Cache)
(input tqDInvoiceByIDAllInfo.ticompany_id, (CompanyId)
input 'EXCHANGERATE', (SharedSetType)
output dataset tqCompanyForCurrencyDetSS) in BCompany>
for first tqCompanyForCurrencyDetSS
where tqCompanyForCurrencyDetSS.ticompany_id = tqDInvoiceByIDAllInfo.ticompany_id
and tqCompanyForCurrencyDetSS.tcSharedSetType = 'EXCHANGERATE':
/*Calculate LC totals */
if tqDInvoiceByIDAllInfo.tiDInvoiceCurrency_ID = viCompanyLCID
then assign vdLCExchangeRate = 1
vdLCRateScale = 1.
else if tqCompanyForCurrencyDetSS.tiCurrency_ID = viCompanyLCID
then assign vdLCExchangeRate = tqDInvoiceByIDAllInfo.tdDInvoiceExchangeRate
vdLCRateScale = tqDInvoiceByIDAllInfo.tdDInvoiceRateScale.
else do:
<M-13 run GetExchangeRate
(input ? (iiCompanyID),
input tqDInvoiceByIDAllInfo.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqDInvoiceByIDAllInfo.ttDInvoicePostingDate (itValidityDate),
output vdLCExchangeRate (odExchangeRate),
output vdLCRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave payselline.
end.
/*Calculate CC totals */
if tqDInvoiceByIDAllInfo.tiDInvoiceCurrency_ID = viCompanyCCID
then
assign
vdCCExchangeRate = 1
vdCCRateScale = 1.
else if tqCompanyForCurrencyDetSS.tiStatutoryCurrency_ID = viCompanyCCID
and tqCompanyForCurrencyDetSS.tiSharedSet_ID = viExchangeRateSharedSetId
then
assign
vdCCExchangeRate = tqDInvoiceByIDAllInfo.tdDInvoiceCCScale
vdCCRateScale = tqDInvoiceByIDAllInfo.tdDInvoiceCCRate.
else if not vlDomainIsStatutory
then
assign
vdCCExchangeRate = vdLCExchangeRate
vdCCRateScale = vdCCRateScale.
else do:
<M-85 run GetExchangeRate
(input ? (iiCompanyID),
input tqDInvoiceByIDAllInfo.tiDInvoiceCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyCCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqDInvoiceByIDAllInfo.ttDInvoicePostingDate (itValidityDate),
output vdCCExchangeRate (odExchangeRate),
output vdCCRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave payselline.
end.
if vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign
tDDocument.DDocumentOriginalDebitCC = <M-71 RoundAmount
(input tqDPaySelLineByID.tdDPaySelLineAmountTC * vdCCExchangeRate * vdCCRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDCollection>
tDDocument.DDocumentOriginalDebitLC = <M-18 RoundAmount
(input tqDPaySelLineByID.tdDPaySelLineAmountTC * vdLCExchangeRate * vdLCRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BDCollection>
tDDocument.DDocumentOriginalCreditCC = 0
tDDocument.DDocumentOriginalCreditLC = 0.
else
assign
tDDocument.DDocumentOriginalDebitCC = 0
tDDocument.DDocumentOriginalDebitLC = 0
tDDocument.DDocumentOriginalCreditCC = <M-94 RoundAmount
(input tqDPaySelLineByID.tdDPaySelLineAmountTC * vdCCExchangeRate * vdCCRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDCollection>
tDDocument.DDocumentOriginalCreditLC = <M-27 RoundAmount
(input tqDPaySelLineByID.tdDPaySelLineAmountTC * vdLCExchangeRate * vdLCRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BDCollection>.
/* Fill Document Amount in Bank Currency */
if (tqDPaySelLineByID.tiBankCurrency_ID = 0 or
tqDPaySelLineByID.tiBankCurrency_ID = ?) and
tqDPaySelLineByID.tlGLIsLocalCurrency
then assign tqDPaySelLineByID.tiBankCurrency_ID = viCompanyLCID .
if tqDPaySelLineByID.tiBankCurrency_ID = tDDocument.Currency_ID
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitTC.
else
if tqDPaySelLineByID.tiBankCurrency_ID = viCompanyLCID
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitLC.
else
if tqDPaySelLineByID.tiBankCurrency_ID = viCompanyCCID
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitCC.
else do:
<M-49 run GetExchangeRate
(input ? (iiCompanyID),
input tqDPaySelLineByID.tiBankCurrency_ID (iiFromCurrencyID),
input ? (icFromCurrencyCode),
input viCompanyLCId (iiToCurrencyID),
input ? (icToCurrencyCode),
input ? (iiExchangeRateTypeID),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tqDInvoiceByIDAllInfo.ttDInvoicePostingDate (itValidityDate),
output vdBCRate (odExchangeRate),
output vdBCRateScale (odExchangeScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave payselline.
if vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign tDDocument.DDocumentOriginalDebitBC = <M-48 RoundAmount
(input tDDocument.DDocumentOriginalDebitLC / (vdBCRate * vdBCRateScale) (idUnroundedAmount),
input tqDPaySelLineByID.tiBankCurrency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BDCollection>.
else
assign tDDocument.DDocumentOriginalCreditBC = <M-39 RoundAmount
(input tDDocument.DDocumentOriginalCreditLC / (vdBCRate * vdBCRateScale) (idUnroundedAmount),
input tqDPaySelLineByID.tiBankCurrency_ID (iiCurrencyID),
input ? (icCurrencyCode)) in BDCollection>.
end.
end. /* end currencies */
end. /* end invoice */
<M-90 run FillProDataSetDocument
(input tDDocument.DDocument_ID (iiDDocumentID),
input tqAddressTypeByCode.tiAddressType_ID (iiAddressTypeID),
output viFcReturnSuper (oiReturnStatus)) in BDCollection>
if vcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign oiDocumentNum = oiDocumentNum + 1
odLocalCurrencySum = odLocalCurrencySum + tDDocument.DDocumentOriginalDebitTC
odBaseCurrencySum = odBaseCurrencySum + tDDocument.DDocumentOriginalDebitTC * tDDocument.DDocumentExchangeRate.
else
assign oiDocumentNum = oiDocumentNum + 1
odLocalCurrencySum = odLocalCurrencySum - tDDocument.DDocumentOriginalCreditTC
odBaseCurrencySum = odBaseCurrencySum - tDDocument.DDocumentOriginalCreditTC * tDDocument.DDocumentExchangeRate.
end. /* end each paysel line*/
assign oiReturnStatus = viLocalReturn.
end.