project QadFinancials > class BDDocument > method AdditionalUpdatesDCollectionCopy
Parameters
blStart6 | input-output | logical | |
blStart9 | input-output | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program5/bddocument.p)
/* If the document received status INCASSO or DISCONTO */
if (t_iDDocument.DDocumentStatus = tDDocument.DDocumentStatus and
( tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INCASSO} or
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-DISCONT})) or
( t_iDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INCASSO} and
tDDocument.DDocumentStatus = {&DOCUMENTSTATUS-DISCONT})
then do:
/* Get Currency of Bank Account */
<M-27 run AdditionalUpdatesGetBankGLInfo
(input false (ilErrorIfNoDiscountAccount),
input true (ilErrorIfNoCurrency),
output vcDiscountGLAccount (ocDiscountGLAccount),
output vcIntBankGLAccount (ocInterestGLAccount),
output viFcReturnSuper (oiReturnStatus)) in BDDocument>
/* Fill Document Amount in Bank Currency */
if tBankGLInfoDDoc.tcCurrencyCode = tDDocument.tcCurrencyCode
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitTC.
else
if tBankGLInfoDDoc.tcCurrencyCode = vcCompanyLC
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitLC.
else
if tBankGLInfoDDoc.tcCurrencyCode = vcCompanyCC
then assign tDDocument.DDocumentOriginalDebitBC = tDDocument.DDocumentOriginalDebitCC.
else do:
assign vhFcComponent = ?.
<M-41 run APIGetExchangeRate
(input 0 (iiFromCurrencyId),
input tBankGLInfoDDoc.tcCurrencyCode (icFromCurrencyCode),
input 0 (iiToCurrencyId),
input vcCompanyLC (icToCurrencyCode),
input 0 (iiExchangeRateTypeId),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode),
input tDDocument.ttPostingDate (itValidityDate),
output vdBCRate (odMultiplyExchangeRate),
output vdBCRateScale (odExchangeRateScaleFactor),
output viFcReturnSuper (oiReturnStatus)) in BExchangeRate>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then return.
assign tDDocument.DDocumentOriginalDebitBC = <M-19 RoundAmount
(input tDDocument.DDocumentOriginalDebitLC / (vdBCRate * vdBCRateScale) (idUnroundedAmount),
input '':U (iiCurrencyID),
input tBankGLInfoDDoc.tcCurrencyCode (icCurrencyCode)) in BDDocument>.
/* round(tDDocument.DDocumentOriginalDebitLC / (vdBCRate * vdBCRateScale),int(entry(lookup(tBankGLInfoDDoc.tcCurrencyCode, vcCurrencyDecimalsList) + 1, vcCurrencyDecimalsList))). */
end.
/* Add Document to Collection */
find tDCollectionDDoc where
tDCollectionDDoc.DCollection_ID = 0 and
tDCollectionDDoc.tcReference = tDDocument.DDocumentType + chr(2) + tDDocument.DDocumentSubType and
tDCollectionDDoc.tcGLCode = tDDocument.tcGLCode
no-error.
if not available tDCollectionDDoc
then do:
create tDCollectionDDoc.
assign viRowIdDDoc = viRowIdDDoc - 1
tDCollectionDDoc.DPaySel_ID = tDDocument.DPaySel_ID
tDCollectionDDoc.DCollectionBankFileFormat = tDDocument.tcPayFormatTypeCode
tDCollectionDDoc.DCollectionIsAutomatic = false
tDCollectionDDoc.DCollectionIsExecuted = false
tDCollectionDDoc.DCollectionName = <M-95 GetDDocumentTypeTranslation (input tDDocument.DDocumentType (icType)) in BDDocument> + " ":U +
<M-43 GetDDocumentSubTypeTranslation (input tDDocument.DDocumentSubType (icSubType)) in BDDocument>
tDCollectionDDoc.DCollectionRequestedDate = tDDocument.DDocumentDueDate
tDCollectionDDoc.DCollectionYear = year(tDCollectionDDoc.DCollectionRequestedDate)
tDCollectionDDoc.DCollection_ID = 0
tDCollectionDDoc.Company_ID = tDDocument.Company_ID
tDCollectionDDoc.GL_ID = tDDocument.GL_ID
tDCollectionDDoc.tcGLCode = tDDocument.tcGLCode
tDCollectionDDoc.tcReference = tDDocument.DDocumentType + chr(2) + tDDocument.DDocumentSubType
tDCollectionDDoc.tc_Rowid = string(viRowIdDDoc).
end.
assign tDCollectionDDoc.DCollectionBalanceDebitTC = tDCollectionDDoc.DCollectionBalanceDebitTC + tDDocument.DDocumentOriginalDebitBC
tDCollectionDDoc.DCollectionBalanceDebitLC = tDCollectionDDoc.DCollectionBalanceDebitLC + tDDocument.DDocumentOriginalDebitLC
tDCollectionDDoc.DCollectionBalanceDebitCC = tDCollectionDDoc.DCollectionBalanceDebitCC + tDDocument.DDocumentOriginalDebitCC
tDCollectionDDoc.DCollectionOrigDebitTC = tDCollectionDDoc.DCollectionOrigDebitTC + tDDocument.DDocumentOriginalDebitBC
tDCollectionDDoc.DCollectionOrigDebitLC = tDCollectionDDoc.DCollectionOrigDebitLC + tDDocument.DDocumentOriginalDebitLC
tDCollectionDDoc.DCollectionOrigDebitCC = tDCollectionDDoc.DCollectionOrigDebitCC + tDDocument.DDocumentOriginalDebitCC.
if tDDocument.DDocumentIncassoSelectCode <> "":U and
tDDocument.DDocumentIncassoSelectCode <> ? and
not can-do(tDCollectionDDoc.DCollectionIncSelCodeList, tDDocument.DDocumentIncassoSelectCode)
then do:
if tDCollectionDDoc.DCollectionIncSelCodeList <> "":U
then assign tDCollectionDDoc.DCollectionIncSelCodeList = tDCollectionDDoc.DCollectionIncSelCodeList + ",":U.
assign tDCollectionDDoc.DCollectionIncSelCodeList = tDCollectionDDoc.DCollectionIncSelCodeList + tDDocument.DDocumentIncassoSelectCode.
end.
if not tDCollectionDDoc.DCollectionIsAutomatic
then assign tDCollectionDDoc.DCollectionIsAutomatic = tDDocument.DDocumentType = {&PAYFORMATPAYINSTRUMENT-DIRECTDEBIT}.
vlDocsExist = false.
/* CHECK IF THERE ARE OTHER DOCUMENTS ATTACHED TO THIS COLLECTION */
<Q-87 run DDocumentByCollectionID (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDDocument.DCollection_ID, (DCollectionID)
input ?, (DDocumentID)
input ?, (DDocumentStatus)
output dataset tqDDocumentByCollectionID) in BDDocument>
for each tqDDocumentByCollectionID where
tqDDocumentByCollectionID.tiDCollection_ID = tDDocument.DCollection_ID
no-lock:
if not can-find(first tDDocument where
tDDocument.DDocument_ID = tqDDocumentByCollectionID.tiDDocument_ID)
then DO:
vlDocsExist = True.
leave.
end.
end. /* for each tqDDocumentByCollectionID */
/* NO MORE DOCUMENTS ATTACHED TO THE COLLECTION SO DELETE THE OLD COLLECTION*/
if not vlDocsExist
then do:
/* IF IN INSTANCE */
if can-find(first tDCollectionDDoc where tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID)
then do:
for first tDCollectionDDoc where tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID exclusive-lock:
assign tDCollectionDDoc.tc_Status = "D":U.
end.
end.
else do:
/* NOT IN THE INSTANCE SO CREATE AND DELETE */
create tDCollectionDDoc.
assign viRowIdDDoc = viRowIdDDoc - 1
tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID
tDCollectionDDoc.tc_Rowid = string(viRowIdDDoc)
tDCollectionDDoc.tc_Status = "D":U.
end.
end. /* if not vlDocsExist */
if vlDocsExist then do:
/* Adjust DCollection Balance */
find tDCollectionDDoc where
tDCollectionDDoc.DCollection_ID = tDDocument.DCollection_ID
no-error.
if not available tDCollectionDDoc
then do:
<Q-6 run DCollectionByIDAllInfo (all) (Read) (NoCache)
(input ?, (CompanyId)
input tDDocument.DCollection_ID, (DCollection_ID)
output dataset tqDCollectionByIDAllInfo) in BDCollection>
find first tqDCollectionByIDAllInfo where tqDCollectionByIDAllInfo.tiDCollection_ID = tDDocument.DCollection_ID no-lock no-error.
if available tqDCollectionByIDAllInfo
then do:
create tDCollectionDDoc.
assign viRowIdDDoc = viRowIdDDoc - 1
tDCollectionDDoc.DCollection_ID = tqDCollectionByIDAllInfo.tiDCollection_ID
tDCollectionDDoc.tc_Rowid = string(viRowIdDDoc).
end. /* if available tqDCollectionByIDAllInfo */
end. /* if not available tDCollectionDDoc */
assign tDCollectionDDoc.DCollectionBalanceDebitTC = tDCollectionDDoc.DCollectionBalanceDebitTC - tDDocument.DDocumentOriginalDebitBC
tDCollectionDDoc.DCollectionBalanceDebitLC = tDCollectionDDoc.DCollectionBalanceDebitLC - tDDocument.DDocumentOriginalDebitLC
tDCollectionDDoc.DCollectionBalanceDebitCC = tDCollectionDDoc.DCollectionBalanceDebitCC - tDDocument.DDocumentOriginalDebitCC.
end. /* if vlDocsExist then */
/* UPDATE DOCUMENT COLLECTION ID SINCE NEW COLLECTION IS CREATED */
assign tDDocument.DCollection_ID = 0.
end.