project QadFinancials > class BCInvoice > method UpdateCInvoiceBankNumber
Description
update the banknumber of the supplier invoice : search payment selection line for the old banknumber, if found, then update that line, subtract the CInvoiceBankToPayTC with the amount of payment selection line AND also create a new line for the new bank number ; if not found, then just update the banknumber_id of the cinvoicebank with the new banknumber_id
Parameters
ilClearData | input | logical | pass true if you want that bcinvoice is started from scratch again |
ilTransferUnallocatedAmount | input | logical | Option to transfer unallocated amount to new bank number |
tUpdateCInvoiceBankNumber | input | temp-table | temp table with updated cinvoice bank numbers in it |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bcinvoice.p)
assign oiReturnStatus = -98.
/* first clear the instance, otherwise problems when you execute it twice */
if ilClearData
then do:
<M-2 run ClearData (output oiReturnStatus (oiReturnStatus)) in BCInvoice>
if oiReturnStatus < 0 then return.
end. /* if ilClearData */
for each tUpdateCInvoiceBankNumber:
if not can-find (first tCInvoice where
tCInvoice.CInvoice_ID = tUpdateCInvoiceBankNumber.tiCInvoiceId)
then assign vcListCInvoiceIds = if vcListCInvoiceIds = "":U
then string(tUpdateCInvoiceBankNumber.tiCInvoiceId)
else
if lookup(string(tUpdateCInvoiceBankNumber.tiCInvoiceId), vcListCInvoiceIds, chr(4)) = 0
then vcListCInvoiceIds + chr(4) + string (tUpdateCInvoiceBankNumber.tiCInvoiceId)
else vcListCInvoiceIds.
end.
if vcListCInvoiceIds <> "":U
then do:
<M-1 run DataLoad
(input '':U (icRowids),
input vcListCinvoiceIds (icPkeys),
input '':U (icObjectIds),
input '':U (icFreeform),
input not ilClearData (ilKeepPrevious),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do :
assign vcMessage = trim(substitute(#T-4'Data could not be loaded: unable to load the list of supplier invoices (&1).':100(1107)T-4#, replace(vcListCInvoiceIds, chr(4), ",":U))).
<M-3 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7523':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* if vcListCInvoiceIds <> "":U */
for each tUpdateCInvoiceBankNumber:
find first tCInvoice where
tCInvoice.CInvoice_ID = tUpdateCInvoiceBankNumber.tiCInvoiceId
no-error.
if not available tCInvoice
then do:
assign vcMessage = trim(#T-7'The invoice was not found. The system cannot update it.':100(65684)t-7#).
<M-8 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 1 (iiSeverity),
input '':U (icRowid),
input 'QadFin-7524':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
Next.
end. /* if not available tDInvoice */
/* check if you find a payment selection line for the oldbanknumber and not the current record */
<Q-5 assign vlFcQueryRecordsAvailable = PaySelLineByBankNmbrCInvoice (NoCache)
(input tUpdateCInvoiceBankNumber.tiOldBankNumberId, (BankNumberId)
input tUpdateCInvoiceBankNumber.tcCurrentPaymSelLineRowId, (CurrentRowId)
input viCompanyId, (CompanyId)
input tUpdateCInvoiceBankNumber.tiCInvoiceId, (CInvoiceId)) in BPaymentSelection >
if not vlFcQueryRecordsAvailable
then do:
assign vlCreate = false.
/* if not payment selection line is found, just change the cinvoicebank record with new banknumber id */
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
no-lock no-error.
if available tCInvoiceBank
then do:
/* PWI ToDo if you change amount and payment format, then change amount of old line, and create new line */
if abs(tCInvoiceBank.CInvoiceBankToPayTC) <> abs(tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC) and
abs(tCInvoiceBank.CInvoiceBankToPayTC) <> abs(tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC + tCInvoice.CInvoiceHoldAmountTC)
then do:
assign vdOrigAmountToPay = tCInvoiceBank.CInvoiceBankToPayTC
tCInvoiceBank.CInvoiceBankToPayTC = if ilTransferUnallocatedAmount
then 0
else tCInvoiceBank.CInvoiceBankToPayTC - tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC
tCInvoiceBank.tlValidatePayment = false.
if tCInvoiceBank.tc_Status = "":U
then assign tCInvoiceBank.tc_Status = "C":U.
assign vlCreate = true.
end.
else do:
/* shx Check if there is same bank record already exist for the invoice this scenario could happen when the invoice pay to two different banknumber
and one of the banknumbers is the one we want to change */
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
no-lock no-error.
/*Same bankNumber found, consolidate to the new banknumber and delete the old one */
if available tCInvoiceBank
then do:
assign
tCInvoiceBank.tlValidatePayment = false.
if tCInvoiceBank.tc_Status = "":U
then assign tCInvoiceBank.tc_Status = "C":U.
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
no-lock no-error.
if available tCInvoiceBank
then do:
if tCInvoiceBank.tc_Status = "":U
then do:
assign tCInvoiceBank.tc_Status = "D":U.
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
no-lock no-error.
if available tCInvoiceBank
then do:
if tCInvoiceBank.CInvoiceBankToPayTC = 0
then tCInvoiceBank.CInvoiceBankToPayTC = tCInvoiceBank.CInvoiceBankToPayTC + tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC + tCInvoice.CInvoiceHoldAmountTC.
else tCInvoiceBank.CInvoiceBankToPayTC = tCInvoiceBank.CInvoiceBankToPayTC + tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC.
end.
end.
end.
end.
else do:
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
no-lock no-error.
assign tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId.
if tCInvoiceBank.tc_Status = "":U
then assign tCInvoiceBank.tc_Status = "C":U.
/* delete the Payment attributes if Payformat changed */
if tUpdateCInvoiceBankNumber.tlPayFormatChanged
then do:
for each tCInvoiceBankPayCode where
tCInvoiceBankPayCode.tc_ParentRowid = tCInvoiceBank.tc_Rowid and
tCInvoiceBankPayCode.tc_Status <> "D":U:
if tCInvoiceBankPayCode.tc_Status = "":U
then assign tCInvoiceBankPayCode.tc_Status = "D":U.
end.
end.
end.
end.
end.
if vlCreate
then do:
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
no-lock no-error.
if not available tCInvoiceBank
then do:
<M-10 run AddDetailLine
(input 'CInvoiceBank':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viFcReturnSuper.
end. /*if not available tCInvoiceBank*/
assign tCInvoiceBank.CInvoice_ID = tCInvoice.CInvoice_ID
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
tCInvoiceBank.CInvoiceBankToPayTC = tCInvoiceBank.CInvoiceBankToPayTC + if ilTransferUnallocatedAmount
then vdOrigAmountToPay
else tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC
tCInvoiceBank.tiParentObject_ID = tCInvoice.Creditor_ID.
if tCInvoiceBank.tc_Status = "":U
then assign tCInvoiceBank.tc_Status = "C":U.
<M-65 run DefaultValuesBankCreateCIBankPayCode1
(input tCInvoiceBank.tc_Rowid (icCInvoiceBankRowid),
input tCInvoiceBank.BankNumber_ID (iiBankNumberId),
input tCInvoiceBank.CInvoiceBank_ID (iiCInvoiceBankId),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
else do:
/* if payment selection line is found, change the amount of the old banknumber, with the
cinvoicebanktopaytc - payment selection amount AND create new cinvoicebank record with new banknumber id */
find first tCInvoiceBank where
tCInvoiceBank.tc_ParentRowid = tCInvoice.tc_Rowid and
tCInvoiceBank.tc_Status <> "D":U and
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiOldBankNumberId
no-lock no-error.
if available tCInvoiceBank
then do:
assign tCInvoiceBank.CInvoiceBankToPayTC = tCInvoiceBank.CInvoiceBankToPayTC - tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC
tCInvoiceBank.tlValidatePayment = false.
if tCInvoiceBank.tc_Status = "":U
then assign tCInvoiceBank.tc_Status = "C":U.
end.
<M-6 run AddDetailLine
(input 'CInvoiceBank':U (icTable),
input tCInvoice.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viFcReturnSuper.
assign tCInvoiceBank.CInvoice_ID = tCInvoice.CInvoice_ID
tCInvoiceBank.BankNumber_ID = tUpdateCInvoiceBankNumber.tiNewBankNumberId
tCInvoiceBank.CInvoiceBankToPayTC = tUpdateCInvoiceBankNumber.tdCInvoiceBankToPayTC
tCInvoiceBank.tiParentObject_ID = tCInvoice.Creditor_ID.
<M-75 run DefaultValuesBankCreateCIBankPayCode1
(input tCInvoiceBank.tc_Rowid (icCInvoiceBankRowid),
input tCInvoiceBank.BankNumber_ID (iiBankNumberId),
input tCInvoiceBank.CInvoiceBank_ID (iiCInvoiceBankId),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or (viFcReturnSuper > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viFcReturnSuper.
end.
end.
if oiReturnStatus = -98
then assign oiReturnStatus = 0.