| tApiUpdateDeductionDetail | input-output | temp-table | Deduction Detail Information. |
| ilIsCalledFromFinancial | input | logical | This value is to identify the caller. Financial part will disable deduction category change from promotion to standard. TPM part will disable deduction category change from standard to promotion. True: called by financial part. False: called by TPM. |
| oiReturnStatus | output | integer | Return status of the method. |
QadFinancials
/* ===================================================================== */
/* It will be used for processing financial deductions.
1.Update detailed deduction information( deduction categories,
deduction detail amounts,reject/approve detailed deductions etc).
2.For approved deduction, it will debit on the expense
account,credit on the customer deduction control account.
3.Generate cross-company posting if deduction expensed entity
is not same as the entity that deduction invoice belongs to.
4.Support for multiple companies' deduction invoices processing in one case.
, which means the deduction invoices could not belong to the logged company.
5.User could provide DInvoice id or business key to load deduction invoices.
*/
/* ===================================================================== */
assign oiReturnStatus = -98
viTransactionBlockStatus = -98
viCrossCyPostingLineRowID = 0
vcDInvoice_Ids = '':U
viSourceCompanyId = viCompanyId
vcSourceCompanyCode = vcCompanyCode
viNewCompanyID = viCompanyId.
empty temp-table tInvolvedCompanies.
empty temp-table tPostingMultiCyDeduction.
empty temp-table tPostingLineMultiCyDeduction.
empty temp-table tPostingSafMultiCyDeduction.
empty temp-table tSourcePostingLines.
empty temp-table tDInvoiceByIds.
empty temp-table tApiUpdateDeductionDetailBk.
/*Fill in the tApiUpdateDeductionDetail.tiDInvoice_ID base on the DInvoice Business Key if possible*/
/*Business Key for DInvoice= Journal SharedsetCode + JournalCode + CompanyCode + Voucher + PostingYear + PostingPeriod*/
for each tApiUpdateDeductionDetail where tApiUpdateDeductionDetail.tiDInvoiceID = 0 or tApiUpdateDeductionDetail.tiDInvoiceID = ?:
<Q-13 run GetDInvoiceIDByBusinessKeys (first) (Read) (NoCache)
(input ?, (CompanyId)
input tApiUpdateDeductionDetail.tcDeductionCompanyCode, (CompanyCode)
input tApiUpdateDeductionDetail.tiDeductionVoucher, (DInvoiceVoucher)
input tApiUpdateDeductionDetail.tiDeductionInvoicePostingYear, (PostingYear)
input tApiUpdateDeductionDetail.tcDeductionJournalCode, (JournalCode)
output dataset tqGetDInvoiceIDByBusinessKeys) in BDInvoice>
find first tqGetDInvoiceIDByBusinessKeys no-error.
if available(tqGetDInvoiceIDByBusinessKeys) then
tApiUpdateDeductionDetail.tiDInvoiceID = tqGetDInvoiceIDByBusinessKeys.tiDInvoice_ID.
else
do:
assign viTransactionBlockStatus = -101
vcMessage = trim(substitute(#T-31'Invalid Customer Invoice Reference &1 of Company &2':255(663644630)T-31#,
string(tApiUpdateDeductionDetail.tiDeductionInvoicePostingYear) + "/" + tApiUpdateDeductionDetail.tcDeductionJournalCode + "/" + string(tApiUpdateDeductionDetail.tiDeductionVoucher),
tApiUpdateDeductionDetail.tcDeductionCompanyCode)).
<M-337 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-59791':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
end. /* End not available tqGetDInvoiceIDByBusinessKeys. */
end. /* End of tApiUpdateDeductionDetail. */
/* ============================================================== */
/* Build the InvolvedCompanies for customer deduction invoice */
/* ============================================================== */
for each tApiUpdateDeductionDetail:
if not can-do(vcDInvoice_Ids, string(tApiUpdateDeductionDetail.tiDInvoiceID)) then
do:
if vcDInvoice_Ids = '':U then vcDInvoice_Ids = string(tApiUpdateDeductionDetail.tiDInvoiceID).
else vcDInvoice_Ids = vcDInvoice_Ids + ',':U + string(tApiUpdateDeductionDetail.tiDInvoiceID).
end.
if ilIsCalledFromFinancial then
do:
/* GL account will be re-assigned in the DInvoice */
assign tApiUpdateDeductionDetail.tcGLCode = '':U
tApiUpdateDeductionDetail.tcCostCenter = '':U
tApiUpdateDeductionDetail.tcSubAccount = '':U
tApiUpdateDeductionDetail.tcProject = '':U
tApiUpdateDeductionDetail.tcSafCode1 = '':U
tApiUpdateDeductionDetail.tcSafCode2 = '':U
tApiUpdateDeductionDetail.tcSafCode3 = '':U
tApiUpdateDeductionDetail.tcSafCode4 = '':U
tApiUpdateDeductionDetail.tcSafCode5 = '':U
tApiUpdateDeductionDetail.tcSafConceptCode1 = '':U
tApiUpdateDeductionDetail.tcSafConceptCode2 = '':U
tApiUpdateDeductionDetail.tcSafConceptCode3 = '':U
tApiUpdateDeductionDetail.tcSafConceptCode4 = '':U
tApiUpdateDeductionDetail.tcSafConceptCode5 = '':U.
end. /* End of ilIsCalledFromFinancial */
end. /* End of tApiUpdateDeductionDetail */
if vcDInvoice_Ids='':U then
do:
assign oiReturnStatus = 0.
return.
end.
/* Build Involved companies from the invoices */
do viCounter = 1 to num-entries(vcDInvoice_Ids):
<Q-64 run DInvoiceByIds (all) (Read) (NoCache)
(input 0, (CompanyId)
input Entry(viCounter,vcDInvoice_Ids), (DInvoice_ID)
output dataset tqDInvoiceByIds) in BDInvoice>
for each tqDInvoiceByIds:
if not can-find (first tInvolvedCompanies where tInvolvedCompanies.tiCompanyId = tqDInvoiceByIds.tiCompany_ID) then
do:
create tInvolvedCompanies.
assign tInvolvedCompanies.tiCompanyId = tqDInvoiceByIds.tiCompany_ID
tInvolvedCompanies.tcCompanyCode = tqDInvoiceByIds.tcCompanyCode
tInvolvedCompanies.tiCompanySort = if tqDInvoiceByIds.tiCompany_ID = viCompanyId then 0 else 1.
end.
create tDInvoiceByIds.
buffer-copy tqDInvoiceByIds to tDInvoiceByIds.
end. /* End of tqDInvoiceByIds. */
end. /* End of num-entries(vcDInvoice_Ids)*/
/* Mainblog to process financial deductions. */
METHODBLOCK: DO on error undo, throw:
/* start the transaction instance. */
<I-85 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "yes"
&CLASS = "Transaction"}>
TRANSACTIONBLOCK: DO on error undo, throw:
/* Start the transaction */
<M-17 run StartTransaction (output viExternalStatus (oiReturnStatus)) in Transaction>
/* Close the transaction: needed before other components are added to the transaction */
<I-91 {bFcCloseInstance
&CLASS = "Transaction"}>
if viExternalStatus < 0 then
do:
assign viTransactionBlockStatus = viExternalStatus
vcMessage = trim(#T-7'An error occurred while starting a transaction.':255(895341038)T-7#).
<M-471 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-347727':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
leave TRANSACTIONBLOCK.
end.
/* ================================================================================== */
/* Update DInvoice and Generate posting on the invoice entity if approved-write off */
/* ================================================================================== */
for each tInvolvedCompanies by tInvolvedCompanies.tiCompanySort:
/* Group the deduction details by company. */
empty temp-table tApiUpdateDeductionDetailOneCy.
for each tDInvoiceByIds where tDInvoiceByIds.tiCompany_ID = tInvolvedCompanies.tiCompanyId:
for each tApiUpdateDeductionDetail where tApiUpdateDeductionDetail.tiDInvoiceID = tDInvoiceByIds.tiDInvoice_ID:
create tApiUpdateDeductionDetailOneCy.
buffer-copy tApiUpdateDeductionDetail to tApiUpdateDeductionDetailOneCy.
end.
end.
/* switch company */
if tInvolvedCompanies.tiCompanyId <> viCompanyId then
do:
/* Switch session to dinvoice company */
<I-23 {bFcOpenInstance
&CLASS = "Session"}>
<M-42 run SwitchCompany
(input '':U (icCompanyCode),
input tInvolvedCompanies.tiCompanyId (iiCompanyId),
output viExternalStatus (oiReturnStatus)) in Session>
<I-43 {bFcCloseInstance
&CLASS = "Session"}>
if viExternalStatus < 0 then
do:
assign viTransactionBlockStatus = viExternalStatus
vcMessage = trim(#T-49'The system failed to switch the entity.':255(334825313)T-49#).
<M-80 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input tInvolvedCompanies.tcCompanyCode (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-230189':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
leave TRANSACTIONBLOCK.
end.
end. /* End of tInvolvedCompanies.tiCompanyId <> viCompanyId */
/* after swtiching company, viCompanyID and viDomainID will be effective when the new instance started.
while in the current instance "BDInvoiceMultiCy", it always stays unchanged.
*/
assign viNewCompanyID = tInvolvedCompanies.tiCompanyId.
if not valid-handle(vhBDInvoiceForMultiCyInst) then
do:
<I-58 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "yes"
&CLASS = "BDInvoice"}>
assign vlBDInvoiceStarted = true.
end.
else do:
<I-54 {bFcOpenInstance
&CLASS = "BDInvoice"}>
end.
/* ======================================= */
/* Set the activity code to modify */
/* ======================================= */
<M-36 run SetPublicData
(input 'vcActivityCode':U (icDataList),
input 'Modify':U (icValueList),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 then
do:
assign viTransactionBlockStatus = viFcReturnSuper.
leave TRANSACTIONBLOCK.
end.
empty temp-table tCrossCyPostingDeduction.
<M-19 run UpdateDeductionDetail
(input-output tApiUpdateDeductionDetailOneCy (tApiUpdateDeduction),
output tCrossCyPostingDeduction (tNewCrossCyPostingDeduction),
input ilIsCalledFromFinancial (ilIsCalledFromFinancial),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 then
do:
assign viTransactionBlockStatus = viFcReturnSuper
vcMessage = trim(substitute(#T-72'An error happens while updating deduction invoices for the company &1.':255(393411558)T-72#,tInvolvedCompanies.tcCompanyCode)).
<M-79 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-170079':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
leave TRANSACTIONBLOCK.
end. /* End of viFcReturnSuper < 0. */
/* copy data back to input-output dataset */
for each tApiUpdateDeductionDetailOneCy:
create tApiUpdateDeductionDetailBk.
buffer-copy tApiUpdateDeductionDetailOneCy to tApiUpdateDeductionDetailBk.
end.
<I-98 {bFcCloseInstance
&CLASS = "BDInvoice"}>
assign vlBDInvoiceStarted = false.
/* =================================================== */
/* Process Cross-Compnay posting for Deduction detail. */
/* =================================================== */
for each tCrossCyPostingDeduction:
/* create posting */
/* Here PostingSystemDate and tcLocalCurrency is used as temp-variable. After using them, will reset their values.
PostingSystemDate: invoice posting date.
tcLocalCurrency: TC currency code.
These two values will not be saved to Database. Before saving, we will clear the values first.
*/
assign viCrossCyPostingLineRowID = viCrossCyPostingLineRowID - 2
vcPostingCrossExternalRef = guid.
create tPostingMultiCyDeduction.
assign tPostingMultiCyDeduction.Company_ID = tCrossCyPostingDeduction.tiCompanyID
tPostingMultiCyDeduction.tcJournalCode = tCrossCyPostingDeduction.tcJournalCode
tPostingMultiCyDeduction.PostingYear = tCrossCyPostingDeduction.tiDeductionPostingYear
tPostingMultiCyDeduction.PostingDate = tCrossCyPostingDeduction.ttDeductionPostingDate
tPostingMultiCyDeduction.PostingText = tCrossCyPostingDeduction.tcDInvoiceDescription
tPostingMultiCyDeduction.PostingPeriod = tCrossCyPostingDeduction.tiDeductionPostingPeriod
tPostingMultiCyDeduction.tc_Status = 'N':U
tPostingMultiCyDeduction.PostingSystemDate = tCrossCyPostingDeduction.ttDInvoicePostingDate
tPostingMultiCyDeduction.tcLocalCurrency = tCrossCyPostingDeduction.tcCurrencyTC /**/
tPostingMultiCyDeduction.PostingOriginIsExternal = true
tPostingMultiCyDeduction.tc_Rowid = tCrossCyPostingDeduction.tcRowid.
/* create posting line for deduction expense account */
create tPostingLineMultiCyDeduction.
assign tPostingLineMultiCyDeduction.tc_Rowid = string(viCrossCyPostingLineRowID + 1) + STRING(TIME,"HH:MM:SS":U)
tPostingLineMultiCyDeduction.tc_ParentRowid = tPostingMultiCyDeduction.tc_Rowid
tPostingLineMultiCyDeduction.tc_Status = 'N':U
tPostingLineMultiCyDeduction.tcGLCode = tCrossCyPostingDeduction.tcGLCode
tPostingLineMultiCyDeduction.tcCostCentreCode = tCrossCyPostingDeduction.tcAPMatchingCostCenterCode
tPostingLineMultiCyDeduction.tcDivisionCode = tCrossCyPostingDeduction.tcAPMatchingDivisionCode
tPostingLineMultiCyDeduction.tcProjectCode = tCrossCyPostingDeduction.tcAPMatchingProjectCode
tPostingLineMultiCyDeduction.Currency_ID = tCrossCyPostingDeduction.tiCurrencyID
tPostingLineMultiCyDeduction.tcCurrencyCode = tCrossCyPostingDeduction.tcCurrencyTC
tPostingLineMultiCyDeduction.PostingLineCCRate = tCrossCyPostingDeduction.tdExchangeRateCC
tPostingLineMultiCyDeduction.PostingLineCCScale = tCrossCyPostingDeduction.tdExchangeRateCCScale
tPostingLineMultiCyDeduction.PostingLineExchangeRate = tCrossCyPostingDeduction.tdExchangeRate
tPostingLineMultiCyDeduction.PostingLineRateScale = tCrossCyPostingDeduction.tdExchangeRateScale
tPostingLineMultiCyDeduction.PostingLineDebitTC = tCrossCyPostingDeduction.tdCrossCyPostingAmountTC
tPostingLineMultiCyDeduction.PostingLineDebitLC = tCrossCyPostingDeduction.tdCrossCyPostingAmountLC
tPostingLineMultiCyDeduction.PostingLineDebitCC = tCrossCyPostingDeduction.tdCrossCyPostingAmountCC
tPostingLineMultiCyDeduction.PostingLineText = tCrossCyPostingDeduction.tcDInvoiceDescription
tPostingLineMultiCyDeduction.PostingLineSequence = 1.
/* building saf */
if tCrossCyPostingDeduction.tcSafCode1 <> '' and tCrossCyPostingDeduction.tcSafCode1 <> ? then
do:
create tPostingSafMultiCyDeduction.
assign tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tc_Rowid = "-1" + tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tcSafCode = tCrossCyPostingDeduction.tcSafCode1
tPostingSafMultiCyDeduction.tcSafConceptCode = tCrossCyPostingDeduction.tcSafConceptCode1.
end.
if tCrossCyPostingDeduction.tcSafCode2 <> '' and tCrossCyPostingDeduction.tcSafCode2 <> ? then
do:
create tPostingSafMultiCyDeduction.
assign tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tc_Rowid = "-2" + tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tcSafCode = tCrossCyPostingDeduction.tcSafCode2
tPostingSafMultiCyDeduction.tcSafConceptCode = tCrossCyPostingDeduction.tcSafConceptCode2.
end.
if tCrossCyPostingDeduction.tcSafCode3 <> '' and tCrossCyPostingDeduction.tcSafCode3 <> ? then
do:
create tPostingSafMultiCyDeduction.
assign tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tc_Rowid = "-3" + tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tcSafCode = tCrossCyPostingDeduction.tcSafCode3
tPostingSafMultiCyDeduction.tcSafConceptCode = tCrossCyPostingDeduction.tcSafConceptCode3.
end.
if tCrossCyPostingDeduction.tcSafCode4 <> '' and tCrossCyPostingDeduction.tcSafCode4 <> ? then
do:
create tPostingSafMultiCyDeduction.
assign tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tc_Rowid = "-4" + tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tcSafCode = tCrossCyPostingDeduction.tcSafCode4
tPostingSafMultiCyDeduction.tcSafConceptCode = tCrossCyPostingDeduction.tcSafConceptCode4.
end.
if tCrossCyPostingDeduction.tcSafCode5 <> '' and tCrossCyPostingDeduction.tcSafCode5 <> ? then
do:
create tPostingSafMultiCyDeduction.
assign tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tc_Rowid = "-5" + tPostingLineMultiCyDeduction.tc_Rowid
tPostingSafMultiCyDeduction.tcSafCode = tCrossCyPostingDeduction.tcSafCode5
tPostingSafMultiCyDeduction.tcSafConceptCode = tCrossCyPostingDeduction.tcSafConceptCode5.
end.
/* create posting line for cross-company account */
create tPostingLineMultiCyDeduction.
assign tPostingLineMultiCyDeduction.tc_Rowid = string(viCrossCyPostingLineRowID) + STRING(TIME,"HH:MM:SS":U)
tPostingLineMultiCyDeduction.tc_ParentRowid = tPostingMultiCyDeduction.tc_Rowid
tPostingLineMultiCyDeduction.tc_Status = 'N':U
tPostingLineMultiCyDeduction.GL_ID = tCrossCyPostingDeduction.tiCrossCompanyGLID
tPostingLineMultiCyDeduction.tcGLCode = tCrossCyPostingDeduction.tcCrossCompanyGLCode
tPostingLineMultiCyDeduction.tcGLTypeCode = {&GLTYPECODE-CROSS}
tPostingLineMultiCyDeduction.tcDivisionCode = tCrossCyPostingDeduction.tcCrossCompanyDivisionCode
tPostingLineMultiCyDeduction.tcIntercoBusinessRelationCode = tCrossCyPostingDeduction.tcIntercoBusinessRelationCode
tPostingLineMultiCyDeduction.CrossCompany_ID = tCrossCyPostingDeduction.tiOriginatorCompanyID
tPostingLineMultiCyDeduction.CrossCompanyPosting_ID = tCrossCyPostingDeduction.tiOriginatorPostingID
tPostingLineMultiCyDeduction.CrossCompanyPostingLine_ID = tCrossCyPostingDeduction.tiOriginatorPostingLineID
tPostingLineMultiCyDeduction.PostingLineCrossExternRef = vcPostingCrossExternalRef
tPostingLineMultiCyDeduction.tcCrossCompanyCode = tCrossCyPostingDeduction.tcOriginatorCompnayCode
tPostingLineMultiCyDeduction.tcCrossCompanyCurrencyCode = tCrossCyPostingDeduction.tcCurrencyTC
tPostingLineMultiCyDeduction.Currency_ID = tCrossCyPostingDeduction.tiCurrencyID
tPostingLineMultiCyDeduction.tcCurrencyCode = tCrossCyPostingDeduction.tcCurrencyTC
tPostingLineMultiCyDeduction.PostingLineCCRate = tCrossCyPostingDeduction.tdExchangeRateCC
tPostingLineMultiCyDeduction.PostingLineCCScale = tCrossCyPostingDeduction.tdExchangeRateCCScale
tPostingLineMultiCyDeduction.PostingLineExchangeRate = tCrossCyPostingDeduction.tdExchangeRate
tPostingLineMultiCyDeduction.PostingLineRateScale = tCrossCyPostingDeduction.tdExchangeRateScale
tPostingLineMultiCyDeduction.PostingLineCreditTC = tCrossCyPostingDeduction.tdCrossCyPostingAmountTC
tPostingLineMultiCyDeduction.PostingLineCreditLC = tCrossCyPostingDeduction.tdCrossCyPostingAmountLC
tPostingLineMultiCyDeduction.PostingLineCreditCC = tCrossCyPostingDeduction.tdCrossCyPostingAmountCC
tPostingLineMultiCyDeduction.PostingLineText = trim(#T-37'Cross-Company Posting':30(57722)T-37#)
tPostingLineMultiCyDeduction.PostingLineSequence = 2.
end. /* End of tCrossCyPostingDeduction. */
end. /*End of tInvolvedCompanies. */
/* ==================================================================== */
/* process cross company expense postings for deduction details */
/* ==================================================================== */
empty temp-table tInvolvedCompanies.
for each tPostingMultiCyDeduction:
if not can-find(first tInvolvedCompanies where tInvolvedCompanies.tiCompanyId = tPostingMultiCyDeduction.Company_ID) then
do:
create tInvolvedCompanies.
assign tInvolvedCompanies.tiCompanyId = tPostingMultiCyDeduction.Company_ID
tInvolvedCompanies.tiCompanySort = if tPostingMultiCyDeduction.Company_ID = viNewCompanyID then 0 else 1.
end.
end.
for each tInvolvedCompanies by tiCompanySort:
/* ======================================================== */
/* build one company's posting data */
/* ======================================================== */
empty temp-table tPostingOneCyDed.
empty temp-table tPostingLineOneCyDed.
empty temp-table tPostingSafOneCyDed.
for each tPostingMultiCyDeduction where tPostingMultiCyDeduction.Company_ID = tInvolvedCompanies.tiCompanyId:
create tPostingOneCyDed.
buffer-copy tPostingMultiCyDeduction to tPostingOneCyDed.
for each tPostingLineMultiCyDeduction where tPostingLineMultiCyDeduction.tc_ParentRowid = tPostingMultiCyDeduction.tc_Rowid:
create tPostingLineOneCyDed.
buffer-copy tPostingLineMultiCyDeduction to tPostingLineOneCyDed.
for each tPostingSafMultiCyDeduction where tPostingSafMultiCyDeduction.tc_ParentRowid = tPostingLineMultiCyDeduction.tc_Rowid:
create tPostingSafOneCyDed.
buffer-copy tPostingSafMultiCyDeduction to tPostingSafOneCyDed.
end.
end.
end.
/* switch company */
if tInvolvedCompanies.tiCompanyId <> viNewCompanyID then
do:
/* Switch session to expense company */
<I-41 {bFcOpenInstance
&CLASS = "Session"}>
<M-12 run SwitchCompany
(input '':U (icCompanyCode),
input tInvolvedCompanies.tiCompanyId (iiCompanyId),
output viExternalStatus (oiReturnStatus)) in Session>
<I-24 {bFcCloseInstance
&CLASS = "Session"}>
if viExternalStatus < 0 then
do:
assign viTransactionBlockStatus = viExternalStatus
vcMessage = trim(#T-2'The system failed to switch the entity.':255(334825313)T-2#).
<M-55 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-658712':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
leave TRANSACTIONBLOCK.
end.
end. /* End of tInvolvedCompanies.tiCompanyId <> viNewCompanyID. */
assign viNewCompanyID = tInvolvedCompanies.tiCompanyId.
if not valid-handle(vhBJournalEntryForMultiCyInst) then
do:
<I-8 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "yes"
&CLASS = "BJournalEntry"}>
assign vlBJournalEntryStarted = true.
end.
else
do:
<I-20 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
end.
/* ======================================= */
/* Set the activity code to create */
/* ======================================= */
<M-69 run SetPublicData
(input 'vcActivityCode':U (icDataList),
input 'Create':U (icValueList),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0
then do:
assign viTransactionBlockStatus = viFcReturnSuper.
leave TRANSACTIONBLOCK.
end.
/* ===================================================================================== */
/* Set the exchange rate by invoice date, for cross-company posting, it uses the invoice */
/* posting date instead of the deduction invoice posting date. */
/* ------------------------------------------------------------------------------------- */
/* After switching company, the current varible (vcCompanyCode) in the instance will still */
/* be the swtich-from company, we create new method GetExchageRate in the BJournalEntry. In the */
/* instance of BJournalEntry, the variable (vcCompanyCode) will be swtich-to company. */
/* Although, we could leave the exchange rate be zero (later bjournalentry will update it). */
/* But in that scenario the performance will be not good, the BJournalEntry will retrieve rate */
/* every time. */
/* ===================================================================================== */
for each tPostingOneCyDed:
find first tDeductionDetailPostingRate where tDeductionDetailPostingRate.tiDomainID = tInvolvedCompanies.tiCompanyId
and tDeductionDetailPostingRate.ttPostingDate = tPostingOneCyDed.PostingSystemDate
and tDeductionDetailPostingRate.tcCurrencyTC = tPostingOneCyDed.tcLocalCurrency no-error.
if not available tDeductionDetailPostingRate then
do:
<M-9 run GetExchangeRates
(input viNewCompanyID (iiCompanyID),
input tPostingOneCyDed.PostingSystemDate (itPostingDate),
input tPostingOneCyDed.tcLocalCurrency (icCurrencyTC),
output vdExchangeRate (odExchangeRate),
output vdExchangeRateScale (odExchangeRateScale),
output vdExchangeRateCC (odExchangeRateCC),
output vdExchangeRateCCScale (odExchangeRateCCScale),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 then
do:
assign viTransactionBlockStatus = viFcReturnSuper.
leave TRANSACTIONBLOCK.
end.
create tDeductionDetailPostingRate.
assign tDeductionDetailPostingRate.tiDomainID = tInvolvedCompanies.tiCompanyId
tDeductionDetailPostingRate.tcCurrencyTC = tPostingOneCyDed.tcLocalCurrency
tDeductionDetailPostingRate.ttPostingDate = tPostingOneCyDed.PostingSystemDate
tDeductionDetailPostingRate.tdExchangeRate = vdExchangeRate
tDeductionDetailPostingRate.tdExchangeRateScale = vdExchangeRateScale
tDeductionDetailPostingRate.tdExchangeRateCC = vdExchangeRateCC
tDeductionDetailPostingRate.tdExchangeRateCCScale = vdExchangeRateCCScale.
end.
assign tPostingOneCyDed.PostingSystemDate = ?
tPostingOneCyDed.tcLocalCurrency = '':U.
for each tPostingLineOneCyDed where tPostingLineOneCyDed.tc_ParentRowid = tPostingOneCyDed.tc_Rowid:
assign tPostingLineOneCyDed.PostingLineExchangeRate = tDeductionDetailPostingRate.tdExchangeRate
tPostingLineOneCyDed.PostingLineRateScale = tDeductionDetailPostingRate.tdExchangeRateScale
tPostingLineOneCyDed.PostingLineCCRate = tDeductionDetailPostingRate.tdExchangeRateCC
tPostingLineOneCyDed.PostingLineCCScale = tDeductionDetailPostingRate.tdExchangeRateCCScale.
end.
end. /* End of tPostingOneCyDed.*/
/* ======================================= */
/* Post the posting for one entity */
/* ======================================= */
<M-801 run ApiStdMaintainMultiTT
(input tPostingOneCyDed (tApiPosting),
input tPostingLineOneCyDed (tApiPostingLine),
input tPostingSafOneCyDed (tApiPostingSaf),
input tPostingVatOneCyDed (tApiPostingVat),
input tPostingVatDelayOneCyDed (tApiPostingVatDelay),
input 'SAVE' (icAction),
output vcPrimaryKeys (ocLstPrimKey),
output vcReturnStatus (ocLstReturn),
output vcRowIDs (ocLstRowid),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0
then do:
assign viTransactionBlockStatus = viFcReturnSuper.
leave TRANSACTIONBLOCK.
end. /* viFcReturnSuper < 0 */
/* ============================================================ */
/* Prepare the original postingline's cross company info */
/* ============================================================ */
<M-47 run GetCrossCyPostingLines
(output tCrossCompanyPostingLinesDed (tApiPostingLine),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0
then do:
assign viTransactionBlockStatus = viFcReturnSuper
vcMessage = trim(substitute(#T-310'Error happens while retrieving the cross company postinglines.':255(88792541)T-310#)).
<M-87 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-285765':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
leave TRANSACTIONBLOCK.
end.
for each tCrossCompanyPostingLinesDed:
find first tSourcePostingLines where tSourcePostingLines.tiPostingLine_ID = tCrossCompanyPostingLinesDed.CrossCompanyPostingLine_ID no-error.
if not available tSourcePostingLines then
do:
create tSourcePostingLines.
assign tSourcePostingLines.tiCrossCyCompanyID = tCrossCompanyPostingLinesDed.Company_ID
tSourcePostingLines.tiCrossCyPostingID = tCrossCompanyPostingLinesDed.Posting_ID
tSourcePostingLines.tiCrossCyPostingLineID = tCrossCompanyPostingLinesDed.PostingLine_ID
tSourcePostingLines.tiPostingLine_ID = tCrossCompanyPostingLinesDed.CrossCompanyPostingLine_ID.
tSourcePostingLines.tiPosting_ID = tCrossCompanyPostingLinesDed.CrossCompanyPosting_ID.
end.
end. /* End of tCrossCompanyPostingLinesDed. */
<I-90 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
assign vlBJournalEntryStarted = false.
end. /* End of tInvolvedCompanies for additional cross company postings. */
/* ============================================================ */
/* Update the original postingline's cross company info */
/* ============================================================ */
assign viBJournalEntryForMultiCyID = 0.
for each tCrossCyPostingDeduction by tCrossCyPostingDeduction.tiBJournalEntrySourceID:
/* first row is same as viBJournalEntryForMultiCyID */
if viBJournalEntryForMultiCyID <> tCrossCyPostingDeduction.tiBJournalEntrySourceID then
do:
assign viBJournalEntryForMultiCyID = tCrossCyPostingDeduction.tiBJournalEntrySourceID.
end.
else do: /* Do nothing */
next.
end.
<I-60 {bFcOpenInstance
&CLASS = "BJournalEntry"}>
<M-73 run GetCrossCyPostingLines
(output tCrossCompanyPostingLinesDed (tApiPostingLine),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
for each tCrossCompanyPostingLinesDed:
find first tSourcePostingLines where tSourcePostingLines.tiPostingLine_ID = tCrossCompanyPostingLinesDed.PostingLine_ID no-error.
if not available tSourcePostingLines then
do:
assign viTransactionBlockStatus = -1
vcMessage = trim(substitute(#T-56'Cannot find the original PostingLine: &1':255(580917525)T-56#,string(tCrossCompanyPostingLinesDed.PostingLine_ID))).
<M-83 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-158991':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
<I-53 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
leave TRANSACTIONBLOCK.
end.
<M-62 run UpdateCrossCompanyInfo
(input tCrossCompanyPostingLinesDed.Company_ID (iiPostingCompanyID),
input tCrossCompanyPostingLinesDed.Posting_ID (iiPostingID),
input tCrossCompanyPostingLinesDed.PostingLine_ID (iiPostingLineID),
input tSourcePostingLines.tiCrossCyCompanyID (iiCrossCompanyID),
input tSourcePostingLines.tiCrossCyPostingID (iiCrossCompanyPostingID),
input tSourcePostingLines.tiCrossCyPostingLineID (iiCrossCompanyPostingLineID),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 then
do:
assign viTransactionBlockStatus = viFcReturnSuper.
<I-77 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
leave TRANSACTIONBLOCK.
end.
end. /* end each tCrossCompanyPostingLinesDed */
<I-26 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end. /* end each tCrossCyPostingDeduction */
assign viTransactionBlockStatus = 0.
END. /*End transaction.*/
/* ==================================================================================== */
/* In case of errors, we need to perform AbortTransaction: otherwise the components are */
/* not correctly closed (important for the reset of the Numbering-mechanism) */
/* ==================================================================================== */
<I-66 {bFcOpenInstance
&CLASS = "Transaction"}>
/* ==================================================================================== */
/* The remove is needed because otherwise the commit tries to execute some methods that */
/* our parent-class (BusinessComponent) doesn't have. This also implicates that with */
/* the call towards CommitTransaction we do not pass a value for 'ihParentInstance' */
/* ==================================================================================== */
if viTransactionBlockStatus <> 0 then
do:
if vlBDInvoiceStarted = true then
do:
<I-75 {bFcCloseInstance
&CLASS = "BDInvoice"}>
end.
if vlBJournalEntryStarted = true then
do:
<I-88 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
<M-1 run AbortTransaction
(input ? (ihParentInstance),
output vcDummy (ocInstances),
output viExternalStatus (oiReturnStatus)) in Transaction>
<I-14 {bFcCloseInstance
&CLASS = "Transaction"}>
if viExternalStatus < 0 then
do:
assign vcMessage = trim(substitute(#T-67'An error (&1) occurred while aborting the transaction.':100(4327)T-67#,string(viExternalStatus))).
<M-46 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-149140':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
end.
LEAVE METHODBLOCK.
end. /* End of viTransactionBlockStatus <> 0. */
<M-39 run RemoveInstance
(input viFcCurrentInstanceId (iiInstanceNr),
output viFcReturnSuper (oiReturnStatus)) in Transaction>
if viFcReturnSuper <> 0 then
do:
assign viExternalStatus = viFcReturnSuper
vcMessage = trim(substitute(#T-89'An error has occurred while removing the current instance from the transaction: &1. See other messages for further details.':255(915899591)T-89#,string(viFcReturnSuper))).
<M-95 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-629660':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
<M-52 run AbortTransaction
(input ? (ihParentInstance),
output vcDummy (ocInstances),
output viExternalStatus (oiReturnStatus)) in Transaction>
<I-3 {bFcCloseInstance
&CLASS = "Transaction"}>
if viExternalStatus < 0 then
do:
assign vcMessage = trim(substitute(#T-35'An error (&1) occurred while aborting the transaction.':100(4327)T-35#,string(viExternalStatus))).
<M-82 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-866655':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
end.
LEAVE METHODBLOCK.
end. /* End of viFcReturnSuper <> 0 for remove instance. */
/* Commit the transaction */
<M-94 run CommitTransaction
(input true (ilStop),
input ? (ihParentInstance),
output vcDummy (ocInstances),
output viExternalStatus (oiReturnStatus)) in Transaction>
if viExternalStatus < 0 then
do:
assign vcMessage = trim(substitute(#T-57'An error (&1) occurred while committing the transaction.':100(45511)T-57#, string(viExternalStatus))).
<M-663 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-316124':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
end. /* End of committing transaction failed. */
FINALLY:
/* Reset return temp table values */
empty temp-table tApiUpdateDeductionDetail.
for each tApiUpdateDeductionDetailBk:
create tApiUpdateDeductionDetail.
buffer-copy tApiUpdateDeductionDetailBk to tApiUpdateDeductionDetail.
end.
/* ================================================= */
/* Stop the transaction in case it was started here */
/* Mark the instance as we have no active transaction */
/* ================================================== */
if valid-handle(vhTransactionInst) = true
then do:
<I-6 {bFcCloseAndStopInstance
&CLASS = "Transaction"}>
end. /* if valid-handle(vhTransactionInst) */
else do:
<I-4 {bFcCloseInstance
&CLASS = "Transaction"}>
end. /* else - valid-handle(vhTransactionInst) */
if valid-handle(vhBDInvoiceForMultiCyInst) then
do:
<I-70 {bFcCloseAndStopInstance
&CLASS = "BDInvoice"}>
end.
if valid-handle(vhBJournalEntryForMultiCyInst) then
do:
<I-86 {bFcCloseAndStopInstance
&CLASS = "BJournalEntry"}>
end.
/* Ensure we switch session to original source company */
/* or the UI will get messed up and inconsistent */
if ilIsCalledFromFinancial and (viNewCompanyID <> viSourceCompanyID) then
do:
<I-25 {bFcOpenInstance
&CLASS = "Session"}>
<M-15 run SwitchCompany
(input vcSourceCompanyCode (icCompanyCode),
input ? (iiCompanyId),
output viExternalStatus (oiReturnStatus)) in Session>
<I-44 {bFcCloseInstance
&CLASS = "Session"}>
if viExternalStatus < 0 then
do:
assign oiReturnStatus = viExternalStatus
vcMessage = #T-753'The system failed to switch the entity.':255(334825313)T-753#.
<M-68 run SetMessage
(input vcMessage (icMessage),
input ? (icArguments),
input ? (icFieldName),
input ? (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input ? (icRowid),
input 'qadfin-171332':U (icFcMsgNumber),
input ? (icFcExplanation),
input ? (icFcIdentification),
input ? (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BDInvoiceMultiCy>
return.
end.
end. /* End of ilIsCalledFromFinancial and (viNewCompanyID <> viSourceCompanyID). */
END FINALLY.
END. /* END of METHODBLOCK */
if viTransactionBlockStatus <> 0 then
do:
assign oiReturnStatus = viTransactionBlockStatus.
return.
end.
if viExternalStatus <> 0 then
do:
assign oiReturnStatus = viExternalStatus.
return.
end.
assign oiReturnStatus = 0.