Description
This method bounced the payments of the paymen selection
Parameters
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bpaymentselection.p)
assign oiReturnStatus = -98
viLocalReturnStatus= 0
viArraySize = 0.
PROCESSBLOCK:
do:
empty temp-table tPaySelToUpdate.
empty temp-table tPaySelLineToUpdate.
empty temp-table tPayByPaySelLineToUpdate.
<Q-14 run CDocumentByIDAllInfo (Start) in BCDocument >
<Q-19 run CInvoiceByID (Start) in BCInvoice >
for each tPaySel where
tPaySel.tc_Status <> 'D':U and
(tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-REGISTERED} or
tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-TRANSFERRED} or
tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-PROCESSING} or
tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-PARTIALLY}):
/* Get current CDocument number */
for each tSupplierInvoiceGroups where tSupplierInvoiceGroups.tiGroupNumber = viLastInvGroupNbr
break by tSupplierInvoiceGroups.tiCDocument_ID:
if first-of(tSupplierInvoiceGroups.tiCDocument_ID) then
do:
assign vlCheckPrinted = false.
<Q-86 run CDocumentByIDAllInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input tPaySel.PaySel_ID, (PaySel_ID)
output dataset tqCDocumentByIDAllInfo) in BCDocument>
for each tqCDocumentByIDAllInfo where
tqCDocumentByIDAllInfo.tiPaySel_ID = tPaySel.PaySel_ID and
/*tqCDocumentByIDAllInfo.tiCDocument_ID = viCurrentCDocumentNumber and*/
tqCDocumentByIDAllInfo.tiCDocument_ID = tSupplierInvoiceGroups.tiCDocument_ID and
(tqCDocumentByIDAllInfo.tcCDocumentStatus = {&DOCUMENTSTATUS-INCASSO} or
tqCDocumentByIDAllInfo.tcCDocumentStatus = {&DOCUMENTSTATUS-PAID}) break by tqCDocumentByIDAllInfo.tiCDocumentNumber:
create tPaySelToUpdate.
assign tPaySelToUpdate.tcPaySelRef = tqCDocumentByIDAllInfo.tc_rowid
tPaySelToUpdate.tiPaySel_ID = tqCDocumentByIDAllInfo.tiPaySel_ID
tPaySelToUpdate.ttPostingDate = tPaySel.ttPostingDate.
if tqCDocumentByIDAllInfo.tiCDocumentPrePrintedNumber <> 0 and
tqCDocumentByIDAllInfo.tiCDocumentPrePrintedNumber <> ?
then assign vlCheckPrinted = true.
end.
end.
end.
for each tPaySelLine where
tPaySelLine.tc_ParentRowid = tPaySel.tc_Rowid:
/* Skip the payselLine which doesn't belong to current group */
<M-89 run IsValidPaySelIDInGroup
(input tPaySelLine.PaySelLine_ID (iiCurrentPaySelLineID),
output vlIsInCurrentInvoiceBatch (olIsValidPaySelLine),
input yes (ilChangeStatus),
output oiReturnStatus (oiReturnStatus)) in BPaymentSelection>
if vlIsInCurrentInvoiceBatch = no then
do:
next.
end.
if not can-find(first tPaySelLineToUpdate where
tPaySelLineToUpdate.tc_ParentRowid = tPaySelLine.tc_ParentRowid)
then do:
create tPaySelLineToUpdate.
assign tPaySelLineToUpdate.tiPaySelLineId = tPaySelLine.PaySelLine_ID.
end. /* if not can-find(first tPaySelLineToUpdate */
<Q-20 run CInvoiceByID (all) (Read) (NoCache)
(input ?, (CompanyId)
input tPaySelLine.PaySelLineParentObject_ID, (CInvoiceID)
output dataset tqCInvoiceByID) in BCInvoice >
find first tqCInvoiceById where tqCInvoiceByID.tiCInvoice_Id = tPaySelLine.PaySelLineParentObject_ID no-error.
if available tqCInvoiceByID and
tqCInvoiceByID.tcCInvoiceType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV}
then do:
assign tPaySelLine.PaySelLineObjectType = tqCInvoiceByID.tcCInvoiceType
tPaySelLine.tc_Status = 'C':U.
create tPaySelPrepayRefPS.
assign viPrepayment_ID = viPrepayment_ID - 1
tPaySelPrepayRefPS.PaySelPrepay_ID = viPrepayment_ID
tPaySelPrepayRefPS.tc_Rowid = string(viPrepayment_ID)
tPaySelLine.PaySelLineParentObject_ID = viPrepayment_ID
tPaySelPrepayRefPS.tcBusinessRelationCode = tPaySelLine.tcBusinessRelationCode
tPaySelPrepayRefPS.tcCurrencyCode = tPaySelLine.tcInvoiceCurrencyCode
tPaySelPrepayRefPS.tcCreditorCode = tPaySelLine.tcCreditorCode
tPaySelPrepayRefPS.PaySelPrepayReferenceText = tPaySelLine.tcExternalNumber
tPaySelPrepayRefPS.tc_Status = 'N':U
tPaySelPrepayRefPS.PaySelPrepayAmountToPayTC = tPaySelLine.PaySelLineAmountTC.
end.
/* Roll back PaySelLineIsConfirmed as false */
if tPaySelLine.PaySelLineIsConfirmed = yes
then do:
assign tPaySelLine.PaySelLineIsConfirmed = no
tPaySelLine.tc_status = "C":U.
end.
end.
/* If current group is the last one, update PaySel status as 'Initial', else 'Paritally Confirmed'. */
if viLastInvGroupNbr = 1 then assign tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-INITIAL}.
else assign tPaySel.PaySelStatus = {&PAYMENTSELECTIONSTATUS-PARTIALLY}.
assign tPaySel.tc_Status = 'C':U.
end. /* For each tpaysel */
<Q-15 run CDocumentByIDAllInfo (Stop) in BCDocument >
<Q-21 run CInvoiceByID (Stop) in BCInvoice >
if can-find (first tPaySelToUpdate where
tPaySelToUpdate.tiPaySel_ID <> ?)
then do:
for each tPaySelLineToUpdate:
<Q-13 run CPayByPaySelLine (all) (Read) (NoCache)
(input tPaySelLineToUpdate.tiPaySelLineId, (PaySelLineIds)
output dataset tqCPayByPaySelLine) in BCPay>
find first tqCPayByPaySelLine no-error.
if available tqCPayByPaySelLine
then do:
create tPayByPaySelLineToUpdate.
assign tPayByPaySelLineToUpdate.tc_Rowid = tqCPayByPaySelLine.tc_rowid.
end.
end. /* for each tPaySelLineToUpdate */
if viBCDocumentPaySelID = 0 or
viBCDocumentPaySelID = ?
then do:
<I-4 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "true"
&CLASS = "BCDocument"}>
assign vlBCDocIsStartedFromPaySel = true.
end.
else do:
<I-5 {bFcOpenInstance
&CLASS = "BCDocument"}>
end.
<M-3 run BouncePayments
(input viBCInvoicePaySelID (iiBCInvoiceID),
input tPaySelToUpdate (tPaySelToUpdateBPSel),
input tPayByPaySelLineToUpdate (tPayByPaySelLineToUpdateBPSel),
output viFcReturnSuper (oiReturnStatus)) in BCDocument>
if viFcReturnSuper = 0 and
vlBCDocIsStartedFromPaySel
then do:
/* Set a session value, it will be used in BCInvoice.CreateCInvoiceMovement for checking the source */
<I-16 {bFcOpenInstance
&CLASS = "Session"}>
<M-17 run SetLogicalValue
(input 'PaySelUnconfirm':U (icName),
input true (ilValue),
output viFcReturnSuper (oiReturnStatus)) in Session>
<I-18 {bFcCloseInstance
&CLASS = "Session"}>
<M-6 run ValidateBCAndAdditionalUpdates
(output vcDummy (ocCreatedPrePaymentForPaySel),
output viFcReturnSuper (oiReturnStatus)) in BCDocument>
end.
<I-7 {bFcCloseInstance
&CLASS = "BCDocument"}>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then leave PROCESSBLOCK.
end. /* if can-find (first tPaySelToUpdate */
end.
assign oiReturnStatus = viLocalReturnStatus.