Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/bdpaymentselection.p)
assign
vdPaySelLineTotalTC = 0
vdPaySelLineTotalLC = 0
vdPaySelLineTotalCC = 0.
paysel:
do on error undo, throw:
if tDPaySel.DPaySelStatus <> {&DOCUMENTSTATUS-INIT}
then return.
if tDPaySel.tc_Status = "N"
then do:
find first tDCollectionPaySel
where tDCollectionPaySel.tcReference = tDPaySel.tcPayFormatTypePayInstrument + {&DOCUMENTSUBTYPE-AUTO}
and tDCollectionPaySel.tcGLCode = tDPaySel.tcGLCode no-error.
if not available tDCollectionPaySel
then do:
create tDCollectionPaySel.
assign
viCollRowid = viCollRowid - 1
tDCollectionPaySel.tcReference = tDPaySel.tcPayFormatTypePayInstrument + {&DOCUMENTSUBTYPE-AUTO}
tDCollectionPaySel.tcGLCode = tDPaySel.tcGLCode
tDCollectionPaySel.DPaySel_ID = tDPaySel.DPaySel_ID
tDCollectionPaySel.DCollectionBankFileFormat = tDPaySel.tcPayFormatTypeCode
tDCollectionPaySel.DCollectionIsExecuted = false
tDCollectionPaySel.DCollectionRequestedDate = tDPaySel.DPaySelDate
tDCollectionPaySel.DCollectionYear = year(tDCollectionPaySel.DCollectionRequestedDate)
tDCollectionPaySel.Company_ID = tDPaySel.Company_ID
tDCollectionPaySel.GL_ID = tDPaySel.GL_ID
tDCollectionPaySel.tc_rowid = string(viCollRowid).
tDCollectionPaySel.DCollectionIsAutomatic = tDPaySel.tcPayFormatTypePayInstrument = {&PAYFORMATPAYINSTRUMENT-DIRECTDEBIT}.
if viBDDocument9ID = 0 or
viBDDocument9ID = ?
then do:
<I-12 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BDDocument"}>
end. /* if viBBankNumber4ID = 0 or */
else if not valid-handle(vhBDDocument9Inst)
then do:
<I-17 {bFcOpenInstance
&CLASS = "BDDocument"}>
end. /* not if viDDocument9ID = 0 or */
assign tDCollectionPaySel.DCollectionName = <M-61 GetDDocumentTypeTranslation (input tDPaySel.tcPayFormatTypePayInstrument (icType)) in BDDocument>
+ " ":U + {&DOCUMENTSUBTYPE-AUTO-TR}.
if valid-handle(vhBDDocument9Inst)
then do:
<I-18 {bFcCloseInstance
&CLASS = "BDDocument"}>
end. /* if valid-handle */
end. /* if not available tDCollectionPaySel */
/* ====================================================================================== *
* Get company's exchange rate shared set ID *
* ====================================================================================== */
<M-78 run StartCacher
(output vhFcComponent (ohCacher),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
<M-31 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-73'System cannot get ID of the Exchange Rate Shared Set.':255(588817158)T-73#.
<M-40 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-502181':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
leave paysel.
end. /* if viFcReturnSuper < 0 */
if tDPaySel.DPaySelCode <> "":U and
tDPaySel.DPaySelCode <> ? and
not can-do(tDCollectionPaySel.DCollectionIncSelCodeList, tDPaySel.DPaySelCode)
then do:
if tDCollectionPaySel.DCollectionIncSelCodeList <> "":U
then assign tDCollectionPaySel.DCollectionIncSelCodeList = tDCollectionPaySel.DCollectionIncSelCodeList + ",":U.
assign tDCollectionPaySel.DCollectionIncSelCodeList = tDCollectionPaySel.DCollectionIncSelCodeList + tDPaySel.DPaySelCode.
end. /* if tDPaySel.DPaySelCode <> "" */
/* go through each pay sel line to build up the collection totals */
for each tDPaySelLine
where tDPaySelline.tc_parentrowid = tDPaySel.tc_rowid on error undo, throw:
<M-56 run GetPaymentCurrencyAmounts
(input tDPaySelLine.DPaySelLineParentObject_ID (iiInvoiceID),
input viExchangeRateSharedSetId (iiExchangeRateSharedSetID),
input tDPaySelLine.DPaySelLineAmountTC (idPaymentAmountTC),
input tDPaySel.tcBankCurrencyCode (icBankCurrencyCode),
input 0 (idBankRate),
input 0 (idBankRateScale),
output vdInvoiceCCTotal (odInvoiceCCTotal),
output vdInvoiceLCTotal (odInvoiceLCTotal),
output vdInvoiceBCTotal (odInvoiceBCTotal),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave paysel.
if tDPaySelLine.tcInvoiceCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign
vdPaySelLineTotalTC = vdPaySelLineTotalTC + tDPaySelLine.DPaySelLineAmountTC
vdPaySelLineTotalLC = vdPaySelLineTotalLC + vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC + vdInvoiceCCTotal.
else
assign
vdPaySelLineTotalTC = vdPaySelLineTotalTC - tDPaySelLine.DPaySelLineAmountTC
vdPaySelLineTotalLC = vdPaySelLineTotalLC - vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC - vdInvoiceCCTotal.
end. /* for each tDPaySelLine */
assign
tDCollectionPaySel.DCollectionBalanceDebitTC = tDPaySel.tdDPaySelTotalAmountBC
tDCollectionPaySel.DCollectionBalanceDebitLC = vdPaySelLineTotalLC
tDCollectionPaySel.DCollectionBalanceDebitCC = vdPaySelLineTotalCC
tDCollectionPaySel.DCollectionOrigDebitTC = tDPaySel.tdDPaySelTotalAmountBC
tDCollectionPaySel.DCollectionOrigDebitLC = vdPaySelLineTotalLC
tDCollectionPaySel.DCollectionOrigDebitCC = vdPaySelLineTotalCC.
end. /* status = N */
else if tDPaySel.tc_Status = "C"
then do:
/* find the Collection */
<Q-81 run DCollectionByPaySel (all) (Read) (NoCache)
(input tDPaySel.Company_ID, (CompanyId)
input tDPaySel.DPaySel_ID, (PaySelId)
input ?, (Executed)
output dataset tqDCollectionByPaySel) in BDCollection>
find first tqDCollectionByPaySel where tqDCollectionByPaySel.tiDPaySel_ID = tDPaySel.DPaySel_ID no-error.
if not available tqDCollectionByPaySel
then do:
assign viFcReturnSuper = -1.
assign vcMessage = #T-77'System cannot find the payment collection associated with this selection':255(384486122)T-77#.
<M-80 run SetMessage
(input vcMessage (icMessage),
input ' ':U (icArguments),
input 'tDPaySel.DPaySelCode':U (icFieldName),
input tDPaySel.DPaySelCode (icFieldValue),
input 'S':U (icType),
input 3 (iiSeverity),
input ' ':U (icRowid),
input 'qadfin-223993':U (icFcMsgNumber),
input ' ':U (icFcExplanation),
input ' ':U (icFcIdentification),
input ' ':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
return.
/* leave paysel. */
end. /*if not available */
create tDCollectionPaySel.
assign
viCollRowid = viCollRowid - 1
tDCollectionPaySel.DCollection_ID = tqDCollectionByPaySel.tiDCollection_ID
tDCollectionPaySel.DPaySel_ID = tDPaySel.DPaySel_ID
tDCollectionPaySel.Company_ID = tDPaySel.Company_ID
tDCollectionPaySel.tc_rowid = string(viCollRowid).
/* ====================================================================================== *
* If this tDPaySel is executed then it is the current DPaySel, if it is not executed *
* then it is the existing DPaySel that the cancelled DPaySelLines are being moved to *
* ====================================================================================== */
if tDPaySel.tlPaySelIsExecuted
then do:
/* go through each of the removed lines to subtract from the collection totals */
assign
vdPaySelLineTotalTC = 0
vdPaySelLineTotalLC = 0
vdPaySelLineTotalCC = 0.
for each tRemovedDIncSelLine
where tRemovedDIncSelLine.tc_ParentRowid = tDPaySel.tc_rowid on error undo, throw:
assign vdRemovedPaymentTC = 0.
/* get the amount - first check if stage */
if tRemovedDIncSelLine.tcPaymentConditionPayType = {&PAYMENTCONDITIONPAYMENTTYPE-STAGED}
then do:
for each tRemovedDIncSelLineStg
where tRemovedDIncSelLineStg.tc_ParentRowid = tRemovedDIncSelLine.tc_rowid on error undo, throw:
assign vdRemovedPaymentTC = vdRemovedPaymentTC + tRemovedDIncSelLineStg.tdStagePaymentAmountTC.
end. /* for each tRemovedDIncSelLineStg */
end. /* if tRemovedDIncSelLine.tcPaymentConditionPayType */
else do:
assign vdRemovedPaymentTC = tRemovedDIncSelLine.tdIncSelLineAmountTC.
end. /* else */
<M-39 run GetPaymentCurrencyAmounts
(input tRemovedDIncSelLine.tiDInvoiceId (iiInvoiceID),
input viExchangeRateSharedSetId (iiExchangeRateSharedSetID),
input vdRemovedPaymentTC (idPaymentAmountTC),
input tDPaySel.tcBankCurrencyCode (icBankCurrencyCode),
input tRemovedDIncSelLine.tdBankRate (idBankRate),
input tRemovedDIncSelLine.tdBankRateScale (idBankRateScale),
output vdInvoiceCCTotal (odInvoiceCCTotal),
output vdInvoiceLCTotal (odInvoiceLCTotal),
output vdInvoiceBCTotal (odInvoiceBCTotal),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave paysel.
if tRemovedDIncSelLine.tcInvoiceAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign
vdPaySelLineTotalBC = vdPaySelLineTotalBC + vdInvoiceBCTotal
vdPaySelLineTotalLC = vdPaySelLineTotalLC + vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC + vdInvoiceCCTotal.
else
assign
vdPaySelLineTotalBC = vdPaySelLineTotalTC - vdInvoiceBCTotal
vdPaySelLineTotalLC = vdPaySelLineTotalLC - vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC - vdInvoiceCCTotal.
end. /* for each tRemovedDIncSelLines */
assign
tDCollectionPaySel.DCollectionBalanceDebitTC = vdPaySelLineTotalBC * -1
tDCollectionPaySel.DCollectionBalanceDebitLC = vdPaySelLineTotalLC * -1
tDCollectionPaySel.DCollectionBalanceDebitCC = vdPaySelLineTotalCC * -1
tDCollectionPaySel.DCollectionOrigDebitTC = vdPaySelLineTotalBC * -1
tDCollectionPaySel.DCollectionOrigDebitLC = vdPaySelLineTotalLC * -1
tDCollectionPaySel.DCollectionOrigDebitCC = vdPaySelLineTotalCC * -1.
end. /* if tDPaySel.tlPaySelIsExecuted */
if not tDPaySel.tlPaySelIsExecuted
then do:
assign
vdPaySelLineTotalTC = 0
vdPaySelLineTotalLC = 0
vdPaySelLineTotalCC = 0.
/* go through each of the removed lines to subtract from the collection totals */
for each tDPaySelLine
where tDPaySelLine.tc_ParentRowid = tDPaySel.tc_rowid and
tDPaySelLine.tc_Status = "C" on error undo, throw:
<M-2 run GetPaymentCurrencyAmounts
(input tDPaySelLine.DPaySelLineParentObject_ID (iiInvoiceID),
input viExchangeRateSharedSetId (iiExchangeRateSharedSetID),
input tDPaySelLine.DPaySelLineAmountTC (idPaymentAmountTC),
input tDPaySelLine.tcCurrencyCode (icBankCurrencyCode),
input 0 (idBankRate),
input 0 (idBankRateScale),
output vdInvoiceCCTotal (odInvoiceCCTotal),
output vdInvoiceLCTotal (odInvoiceLCTotal),
output vdInvoiceBCTotal (odInvoiceBCTotal),
output viFcReturnSuper (oiReturnStatus)) in BDPaymentSelection>
if viFcReturnSuper < 0 or viLocalReturn = 0 then assign viLocalReturn = viFcReturnSuper.
if viFcReturnSuper < 0 then leave paysel.
if tDPaySelLine.tcInvoiceCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then
assign
vdPaySelLineTotalTC = vdPaySelLineTotalTC + tDPaySelLine.DPaySelLineAmountTC
vdPaySelLineTotalLC = vdPaySelLineTotalLC + vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC + vdInvoiceCCTotal.
else
assign
vdPaySelLineTotalTC = vdPaySelLineTotalTC - tDPaySelLine.DPaySelLineAmountTC
vdPaySelLineTotalLC = vdPaySelLineTotalLC - vdInvoiceLCTotal
vdPaySelLineTotalCC = vdPaySelLineTotalCC - vdInvoiceCCTotal.
end. /* for each tDPaySelLine */
assign
tDCollectionPaySel.DCollectionBalanceDebitTC = tDPaySel.tdDPaySelTotalAmountBC
tDCollectionPaySel.DCollectionBalanceDebitLC = vdPaySelLineTotalLC
tDCollectionPaySel.DCollectionBalanceDebitCC = vdPaySelLineTotalCC
tDCollectionPaySel.DCollectionOrigDebitTC = tDPaySel.tdDPaySelTotalAmountBC
tDCollectionPaySel.DCollectionOrigDebitLC = vdPaySelLineTotalLC
tDCollectionPaySel.DCollectionOrigDebitCC = vdPaySelLineTotalCC.
end. /* if not tDPaySel.tlPaySelIsExecuted */
end. /* status = C */
end. /* do on error */
assign oiReturnStatus = viLocalReturn.