project QadFinancials > class BBankEntry > method CalculateBankStateAlloc
Description
CalculateBankStateAlloc; Fill in field tBankStateAlloc.tcAllocationInformation; Prerequisite: tBankStateAlloc must be available.
Parameters
| iiCInvoiceID | input | integer | CInvoice |
| iiDInvoiceID | input | integer | DInvoiceID |
| iiCCollectionID | input | integer | CCollectionID |
| iiDCollectionID | input | integer | DCollectionID |
| iiPostingId | input | integer | Posting ID |
| iiGLId | input | integer | GL id |
| ocDocNumberReference | output | character | DocNumnerReference |
| ocDocBusinessRelationCode | output | character | DocBusienssRelationCode |
| otDocDueDate | output | date | DocDueDate |
| otDocDiscountDueDate | output | date | DocDiscountDueDate |
| otDocInvDate | output | date | DocInvDate |
| odDocBalance | output | decimal | DocBalance |
| ocDocBalanceCrDt | output | character | Credit or Debit |
| ocDocCurrencyCode | output | character | |
| oiCollNumber | output | integer | Collection number |
| ocCollReference | output | character | Coll Reference |
| odCollBalance | output | decimal | CollBalance |
| ocCollBalanceCrDt | output | character | Credit or Debit |
| otCollRequestedDate | output | date | CollRequestedDate |
| ocAllocAmountCrDt | output | character | Credit or Debit for Alloc Amount |
| ocNewBalanceCrDt | output | character | Credit Or Debit for New Balance |
| odDocExchangeRate | output | decimal | Document Exchange Rate |
| odDocExchangeRateScale | output | decimal | |
| odDocVatBase | output | decimal | |
| ocDocVatBaseCrDt | output | character | |
| odDocVat | output | decimal | |
| ocDocVatCrDt | output | character | |
| oiDocPostingID | output | integer | |
| ocVatCountryCode | output | character | |
| olDiscountTaxAtPayment | output | logical | discount at payment |
| ocDInvoiceDescription | output | character | Invoice Description |
| odOpenBalTCSign | output | decimal | |
| odNonDiscAmt | output | decimal | Non Discount Amount |
| ocReasonCode | output | character | |
| otDocPostingDate | output | date | |
| oiBillNumber | output | integer | |
| oiBillYear | output | integer | |
| ocBillStatus | output | character | |
| ocCustomerInvoiceNumber | output | character | |
| ocShipperCode | output | character | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program4/bbankentry.p)
/* ============================ */
/* For CInv/DInv: Doc-Fields */
/* For CColl/DColl: Coll-Fields */
/* ============================ */
if iiCInvoiceID <> 0 and iiCInvoiceID <> ?
then do :
<Q-12 run CInvoiceByAllocationInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (BusinessRelationCode)
input ?, (CreditorCode)
input ?, (CInvoiceRefererence)
input ?, (CurrencyCode)
input iiCInvoiceID, (CInvoiceID)
input ?, (CInvoiceIsOpen)
input ?, (CInvoiceAmountTCMinimum)
input ?, (CInvoiceAmountTCMaximum)
input ?, (PeriodYearMinimum)
input ?, (PeriodYear)
input ?, (JournalCode)
input ?, (Voucher)
input {&MOVEMENTTYPE-INITIAL}, (CInvoiceMovementType)
input ?, (CInvoiceIsSelected)
input ?, (CInvoiceTSMNumber)
input ?, (CorporateGroupCode)
input ?, (ReasonIsLockPayment)
input ?, (CompIsOICrossCy)
output dataset tqCInvoiceByAllocationInfo) in BCInvoice>
find first tqCInvoiceByAllocationInfo no-lock no-error.
if not available tqCInvoiceByAllocationInfo
then return.
assign ocDocNumberReference = trim(string(tqCInvoiceByAllocationInfo.tiPeriodYear)) + "/":U + trim(tqCInvoiceByAllocationInfo.tcJournalCode) + "/":U + string(tqCInvoiceByAllocationInfo.tiCInvoiceVoucher,"999999999":U) + "/":U + tqCInvoiceByAllocationInfo.tcCInvoiceReference
ocDocBusinessRelationCode = tqCInvoiceByAllocationInfo.tcBusinessRelationCode
otDocDueDate = tqCInvoiceByAllocationInfo.ttCInvoiceDueDate
otDocDiscountDueDate = tqCInvoiceByAllocationInfo.ttCInvoiceDiscountDueDate
otDocInvDate = tqCInvoiceByAllocationInfo.ttCInvoiceDate
odDocBalance = if tqCInvoiceByAllocationInfo.tdCInvoiceBalanceDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceBalanceDebitTC <> ? then tqCInvoiceByAllocationInfo.tdCInvoiceBalanceDebitTC else tqCInvoiceByAllocationInfo.tdCInvoiceBalanceCreditTC
ocDocBalanceCrDt = if tqCInvoiceByAllocationInfo.tdCInvoiceOriginalDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceOriginalDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
odDocVatBase = if tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseDebitTC <> ? then tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseDebitTC else tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseCreditTC
ocDocVatBaseCrDt = if tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceVatBaseDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
odDocVat = if tqCInvoiceByAllocationInfo.tdCInvoiceVatDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceVatDebitTC <> ? then tqCInvoiceByAllocationInfo.tdCInvoiceVatDebitTC else tqCInvoiceByAllocationInfo.tdCInvoiceVatCreditTC
ocDocVatCrDt = if tqCInvoiceByAllocationInfo.tdCInvoiceVatDebitTC <> 0 and tqCInvoiceByAllocationInfo.tdCInvoiceVatDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
ocDocCurrencyCode = tqCInvoiceByAllocationInfo.tcCurrencyCode
oiDocPostingID = tqCInvoiceByAllocationInfo.tiPosting_ID
odDocExchangeRate = tqCInvoiceByAllocationInfo.tdCInvoiceExchangeRate
odDocExchangeRateScale = tqCInvoiceByAllocationInfo.tdCinvoiceRateScale
ocAllocAmountCrDt = if ocDocBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT} then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
ocNewBalanceCrDt = ocDocBalanceCrDt
odNonDiscAmt = tqCInvoiceByAllocationInfo.tdCInvoiceNonDiscAmtTC
ocDInvoiceDescription = tqCInvoiceByAllocationInfo.tcCInvoiceDescription
ocReasonCode = tqCInvoiceByAllocationInfo.tcReasonCode
odOpenBalTCSign = if ocDocBalanceCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
then odDocBalance
else (0 - odDocBalance)
otDocPostingDate = tqCInvoiceByAllocationInfo.ttCInvoicePostingDate
ocCustomerInvoiceNumber = "":U
ocShipperCode = "":U.
<Q-20 run CInvoiceVatByCInvoiceId (all) (Read) (NoCache)
(input tqCInvoiceByAllocationInfo.tiCInvoice_ID, (CInvoiceId)
output dataset tqCInvoiceVatByCInvoiceId) in BCInvoice>
for each tqCInvoiceVatByCInvoiceId where
tqCInvoiceVatByCInvoiceId.tiCInvoice_ID = tqCInvoiceByAllocationInfo.tiCInvoice_ID :
<Q-21 assign vlFcQueryRecordsAvailable = MfgTaxCodeByTaxCode (NoCache)
(input tqCInvoiceVatByCInvoiceId.tcVatCode, (TaxCode)
input tqCInvoiceVatByCInvoiceId.tcDomainCode, (DomainCode)
input true, (DiscountAtPayment)
input ?, (IsTaxByLine)) in BMfgTaxCode >
if vlFcQueryRecordsAvailable = yes or vlFcQueryRecordsAvailable = ?
then do:
assign olDiscountTaxAtPayment = true.
leave.
end.
end. /* for each tqCInvoiceVatByCInvoiceId */
<Q-93 run WHTByCInvoice (all) (Read) (NoCache)
(input ?, (CompanyId)
input iiCInvoiceID, (CInvoiceId)
input ?, (WHTStatusDiffersFrom)
input ?, (WHTStatus)
output dataset tqWHTByCInvoice) in BWithholdingTax>
for each tqWHTByCInvoice where
tqWHTByCInvoice.tiCInvoice_ID = iiCInvoiceID:
if tqWHTByCInvoice.tcWHTStatus = {&WHTSTATUS-INIT}
then assign tBankStateAlloc.tdInitiallyAllocatedWHTAmntTC = tBankStateAlloc.tdInitiallyAllocatedWHTAmntTC +
abs(tqWHTByCInvoice.tdWHTAmtDebitTC - tqWHTByCInvoice.tdWHTAmtCreditTC).
end. /* end for each tqWHTByCInvoice .. */
end. /* if iiCInvoiceID <> 0 and iiCInvoiceID <> ? */
if iiDInvoiceID <> 0 and iiDInvoiceID <> ?
then do :
<Q-14 run DInvoiceByAllocationInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (BusinessRelationCode)
input iiDInvoiceID, (DInvoiceID)
input ?, (DInvoiceDescription)
input ?, (DebtorCode)
input ?, (CurrencyCode)
input ?, (DInvoiceIsOpen)
input ?, (DInvoiceAmountTCMinimum)
input ?, (DInvoiceAmountTCMaximum)
input ?, (PeriodYearMinimum)
input ?, (JournalCode)
input ?, (PeriodYear)
input ?, (Voucher)
input ?, (DInvoiceTSMNumber)
input ?, (ShipperCode)
input ?, (CorporateGroupCode)
input ?, (CompIsOICrossCy)
input ?, (Debtor_ID)
input ?, (DInvoiceIsSelected)
input ?, (BillNumber)
input ?, (BillYear)
output dataset tqDInvoiceByAllocationInfo) in BDInvoice>
/* Assign shipper code */
define buffer btqDInvoiceByAllocationInfo for tqDInvoiceByAllocationInfo.
assign ocShipperCode = "":U.
for each btqDInvoiceByAllocationInfo no-lock
break by btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoType
by btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode:
assign ocShipperCode = if ocShipperCode = "":U then btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode
else ocShipperCode + ",":U + btqDInvoiceByAllocationInfo.tcDInvoiceOpInfoCode.
end.
find first tqDInvoiceByAllocationInfo no-lock no-error.
if not available tqDInvoiceByAllocationInfo
then return.
assign ocDocNumberReference = trim(string(tqDInvoiceByAllocationInfo.tiPeriodYear )) + "/":U + trim(tqDInvoiceByAllocationInfo.tcJournalCode ) + "/":U + string(tqDInvoiceByAllocationInfo.tiDInvoiceVoucher ,"999999999":U)
ocDocBusinessRelationCode = tqDInvoiceByAllocationInfo.tcBusinessRelationCode
otDocDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDueDate
otDocDiscountDueDate = tqDInvoiceByAllocationInfo.ttDInvoiceDiscountDueDate
otDocInvDate = tqDInvoiceByAllocationInfo.ttDInvoiceDate
odDocBalance = if tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceBalanceDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceBalanceCreditTC
ocDocBalanceCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceOriginalDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
odDocVatBase = if tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseCreditTC
ocDocVatBaseCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatBaseDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
odDocVat = if tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> ? then tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC else tqDInvoiceByAllocationInfo.tdDInvoiceVatCreditTC
ocDocVatCrDt = if tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> 0 and tqDInvoiceByAllocationInfo.tdDInvoiceVatDebitTC <> ? then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
ocDocCurrencyCode = tqDInvoiceByAllocationInfo.tcCurrencyCode
oiDocPostingID = tqDInvoiceByAllocationInfo.tiPosting_ID
odDocExchangeRate = tqDInvoiceByAllocationInfo.tdDInvoiceExchangeRate
odDocExchangeRateScale = tqDInvoiceByAllocationInfo.tdDInvoiceRateScale
ocDInvoiceDescription = tqDInvoiceByAllocationInfo.tcDInvoiceDescription
ocAllocAmountCrDt = if ocDocBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT} then {&CREDITDEBITABBREVIATION-DEBIT} else {&CREDITDEBITABBREVIATION-CREDIT}
ocNewBalanceCrDt = ocDocBalanceCrDt
odNonDiscAmt = tqDInvoiceByAllocationInfo.tdDInvoiceNonDiscAmtTC
ocReasonCode = tqDInvoiceByAllocationInfo.tcReasonCode
odOpenBalTCSign = if ocDocBalanceCrDt = {&CREDITDEBITABBREVIATION-DEBIT} then odDocBalance
else (0 - odDocBalance)
otDocPostingDate = tqDInvoiceByAllocationInfo.ttDInvoicePostingDate
ocCustomerInvoiceNumber = tqDInvoiceByAllocationInfo.tcDInvoiceDIText
oiBillYear = tqDInvoiceByAllocationInfo.tiBillYear
oiBillNumber = tqDInvoiceByAllocationInfo.tiBillNumber
ocBillStatus = tqDInvoiceByAllocationInfo.tcBillStatus.
<Q-18 run DInvoiceVatByDInvoiceId (all) (Read) (NoCache)
(input tqDInvoiceByAllocationInfo.tiDInvoice_ID, (DInvoiceId)
output dataset tqDInvoiceVatByDInvoiceId) in BDInvoice >
for each tqDInvoiceVatByDInvoiceId where
tqDInvoiceVatByDInvoiceId.tiDInvoice_ID = tqDInvoiceByAllocationInfo.tiDInvoice_ID :
<Q-19 assign vlFcQueryRecordsAvailable = MfgTaxCodeByTaxCode (NoCache)
(input tqDInvoiceVatByDInvoiceId.tcVatCode, (TaxCode)
input tqDInvoiceVatByDInvoiceId.tcDomainCode, (DomainCode)
input true, (DiscountAtPayment)
input ?, (IsTaxByLine)) in BMfgTaxCode >
if vlFcQueryRecordsAvailable = yes or vlFcQueryRecordsAvailable = ?
then do:
assign olDiscountTaxAtPayment = true.
leave.
end.
end.
end. /* if iiDInvoiceID <> 0 and iiDInvoiceID <> ? */
if iiCCollectionID <> 0 and iiCCollectionID <> ?
then do :
<Q-15 run CCollectionByAllocation (all) (Read) (NoCache)
(input ?, (CompanyId)
input ?, (CCollectionReference)
input ?, (FromRequestedDate)
input ?, (CCollectionOriginalTC)
input iiCCollectionID, (CCollectionID)
input ?, (GLCode)
input iiGLId, (GLId)
input ?, (PaySelCode)
output dataset tqCCollectionByAllocation) in BCCollection >
find first tqCCollectionByAllocation no-lock no-error.
if not available tqCCollectionByAllocation
then return.
assign oiCollNumber = tqCCollectionByAllocation.tiCCollectionNumber
ocCollReference = tqCCollectionByAllocation.tcCCollectionReference
odCollBalance = tqCCollectionByAllocation.tdCCollectionBalanceCreditTC
ocCollBalanceCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
ocAllocAmountCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
otCollRequestedDate = tqCCollectionByAllocation.ttCCollectionRequestedDate
ocDocNumberReference = trim(string(tqCCollectionByAllocation.tiCCollectionYear)) + "/":U + trim(string(tqCCollectionByAllocation.tiCCollectionNumber)) + "/":U + string(tqCCollectionByAllocation.tcCCollectionReference)
ocNewBalanceCrDt = ocCollBalanceCrDt.
end. /* if iiCCollectionID <> 0 and iiCCollectionID <> ? */
if iiDCollectionID <> 0 and iiDCollectionID <> ?
then do :
<Q-17 run DCollectionByAllocation (all) (Read) (NoCache)
(input ?, (CompanyId)
input iiDCollectionID, (DCollectionID)
input ?, (DCollectionReference)
input ?, (DCollectionOriginalTC)
input ?, (FromRequestedDate)
input ?, (GLId)
input ?, (GLCode)
input ?, (IncSelCode)
output dataset tqDCollectionByAllocation) in BDCollection>
find first tqDCollectionByAllocation no-lock no-error.
if not available tqDCollectionByAllocation
then return.
assign oiCollNumber = tqDCollectionByAllocation.tiDCollectionNumber
ocCollReference = tqDCollectionByAllocation.tcDCollectionReference
odCollBalance = tqDCollectionByAllocation.tdDCollectionBalanceDebitTC
ocCollBalanceCrDt = {&CREDITDEBITABBREVIATION-DEBIT}
ocAllocAmountCrDt = {&CREDITDEBITABBREVIATION-CREDIT}
otCollRequestedDate = tqDCollectionByAllocation.ttDCollectionRequestedDate
ocDocNumberReference = trim(string(tqDCollectionByAllocation.tiDCollectionYear)) + "/":U + trim(string(tqDCollectionByAllocation.tiDCollectionNumber)) + "/":U + string(tqDCollectionByAllocation.tcDCollectionReference)
ocNewBalanceCrDt = ocCollBalanceCrDt.
end. /* if iiDCollectionID <> 0 and iiDCollectionID <> ? */