project QadFinancials > class BAPMatching > method AdditionalUpdatesAllLinesPLAddPostingLineOpAllocCode
Description
This method creates a posting line for each gl linked to the Operational Allocation Code that is used. It will split the amounts according to the percentages used in the Operational Allocation Code setup.
Parameters
icAPMatchingPostingRowId | input | character | |
icGLCode | input | character | |
icDivisionCode | input | character | |
icCostCentreCode | input | character | |
icProjectCode | input | character | |
icOpAllocCode | input | character | Operational Allocation Code. If this parameter is passed several posting lines will be created based on the number of detail lines linked to the operational allocation code. The GL Code that is passed will not be used. |
idDebitTC | input | decimal | |
idDebitLC | input | decimal | |
idDebitCC | input | decimal | |
idCreditTC | input | decimal | |
idCreditLC | input | decimal | |
idCreditCC | input | decimal | |
icPostingText | input | character | |
idTCLCExchangeRate | input | decimal | |
idTCLCExchangeScale | input | decimal | |
idTCCCExchangeRate | input | decimal | |
idTCCCExchangeScale | input | decimal | |
tDefaultSafsAPM | input | temp-table | |
oiPostingLineId | output | integer | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bapmatching.p)
/* =========================================================== */
/* This method expects valid records in following tables */
/* =========================================================== */
if not available tAPMatching or
not available tAPMatchingLn or
(not available tqDomainForInterCompany and
tAPMatching.Company_ID <> tAPMatchingLn.APMatchingLnPvodCompID)
then do :
assign oiReturnStatus = -3
vcMessageText = trim(substitute(#T-58'Internal error: information that should have been available is not available.':255(999890799)T-58#)) + chr(10) +
trim(substitute(#T-60'Available matching header: &1.':234(49819)T-60#,available (tAPMatching))) + chr(10) +
trim(substitute(#T-39'Available matching details: &1.':234(49820)T-39#,available (tAPMatchingLn))).
if tAPMatching.Company_ID <> tAPMatchingLn.APMatchingLnPvodCompID
then assign vcMessageText = vcMessageText + chr(10) + trim(substitute(#T-11'Available cross-company information from the domain: &1.':234(63364)T-11#,available (tqDomainForInterCompany))).
<M-35 run SetMessage
(input vcMsgAPMatching (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-154839':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
return.
end. /* if not avail */
if icOpAllocCode = ? or
icOpAllocCode = '':U
then do:
assign vcMessageText = #T-565'The Operational Allocation Code needs to be filled in order to split the postings.':255(693735786)T-565#
oiReturnStatus = -3.
<M-29 run SetMessage
(input vcMessageText (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'S':U (icType),
input 2 (iiSeverity),
input tAPMatchingLn.tc_Rowid (icRowid),
input 'qadfin-91458':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
return.
end. /* if icOpAllocCode = ? or */
/* ===================================================================== */
/* Retrieve the GL structure based on the Operational Allocation Code */
/* ===================================================================== */
empty temp-table tOpAllocCodeStruct.
assign vdTotalDebitTC = 0
vdTotalDebitLC = 0
vdTotalDebitCC = 0
vdTotalCreditTC = 0
vdTotalCreditLC = 0
vdTotalCreditCC = 0.
assign vhFcComponent = ?.
<M-67 run GetAllocationAccountStructure
(input tAPMatchingLn.PvoDomain (icDomainCode),
input icOpAllocCode (icAllocationCode),
output tOpAllocCodeStruct (tAllocationStruct),
output viFcReturnSuper (oiReturnStatus)) in BMfgAllocationAccount>
for each tOpAllocCodeStruct break
by tOpAllocCodeStruct.tcGLCode
by tOpAllocCodeStruct.tcDivisionCode
by tOpAllocCodeStruct.tcCostCentreCode
by tOpAllocCodeStruct.tcProjectCode
by tOpAllocCodeStruct.tdPercentage
on error undo, throw:
/* ==================================================================== */
/* The analysis passed with this method takes priority over */
/* the default analysis defined on the operational allocation structure */
/* ==================================================================== */
if tOpAllocCodeStruct.tcDivisionCode <> ? and
tOpAllocCodeStruct.tcDivisionCode <> "":U and
icDivisionCode <> ? and
icDivisionCode <> "":U
then assign tOpAllocCodeStruct.tcDivisionCode = icDivisionCode.
if tOpAllocCodeStruct.tcCostCentreCode <> ? and
tOpAllocCodeStruct.tcCostCentreCode <> "":U and
icCostCentreCode <> ? and
icCostCentreCode <> "":U
then assign tOpAllocCodeStruct.tcCostCentreCode = icCostCentreCode.
if tOpAllocCodeStruct.tcProjectCode <> ? and
tOpAllocCodeStruct.tcProjectCode <> "":U and
icProjectCode <> ? and
icProjectCode <> "":U
then assign tOpAllocCodeStruct.tcProjectCode = icProjectCode.
/* =================================================================================== */
/* Calculate the amounts to post and make sure we don't introduce rounding differences */
/* =================================================================================== */
assign vdDebitTC = <M-96 RoundAmount
(input idDebitTC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input tAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching>
vdDebitLC = <M-80 RoundAmount
(input idDebitLC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BAPMatching>
vdDebitCC = <M-28 RoundAmount
(input idDebitCC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BAPMatching>
vdCreditTC = <M-57 RoundAmount
(input idCreditTC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input tAPMatching.tcCurrencyCode (icCurrencyCode)) in BAPMatching>
vdCreditLC = <M-40 RoundAmount
(input idCreditLC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BAPMatching>
vdCreditCC = <M-5 RoundAmount
(input idCreditCC * tOpAllocCodeStruct.tdPercentage / 100 (idUnroundedAmount),
input ? (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BAPMatching>.
assign vdTotalDebitTC = vdTotalDebitTC + vdDebitTC
vdTotalDebitLC = vdTotalDebitLC + vdDebitLC
vdTotalDebitCC = vdTotalDebitCC + vdDebitCC
vdTotalCreditTC = vdTotalCreditTC + vdCreditTC
vdTotalCreditLC = vdTotalCreditLC + vdCreditLC
vdTotalCreditCC = vdTotalCreditCC + vdCreditCC.
if last(tOpAllocCodeStruct.tdPercentage)
then do:
if vdTotalDebitTC <> idDebitTC
then assign vdDebitTC = vdDebitTC - (vdTotalDebitTC - idDebitTC).
if vdTotalDebitLC <> idDebitLC
then assign vdDebitLC = vdDebitLC - (vdTotalDebitLC - idDebitLC).
if vdTotalDebitCC <> idDebitCC
then assign vdDebitCC = vdDebitCC - (vdTotalDebitCC - idDebitCC).
if vdTotalCreditTC <> idCreditTC
then assign vdCreditTC = vdCreditTC - (vdTotalCreditTC - idCreditTC).
if vdTotalCreditLC <> idCreditLC
then assign vdCreditLC = vdCreditLC - (vdTotalCreditLC - idCreditLC).
if vdTotalCreditCC <> idCreditCC
then assign vdCreditCC = vdCreditCC - (vdTotalCreditCC - idCreditCC).
end. /* if last(tOpAllocCodeStruct.tdPercentage) */
if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID
then do:
/* ================================================================= */
/* Create the posting line for the GL in the Op Alloc Code structure */
/* ================================================================= */
<M-85 run AddStandardPosting
(input icAPMatchingPostingRowId (icPostingtcRowid),
input tOpAllocCodeStruct.tcGLCode (icGLCode),
input tOpAllocCodeStruct.tcDivisionCode (icDivisionCode),
input tOpAllocCodeStruct.tcCostCentreCode (icCostCentreCode),
input '':U (icCostCentreText),
input tOpAllocCodeStruct.tcProjectCode (icProjectCode),
input '':U (icProjectText),
input tAPMatching.tcBusinessRelationICCode (icIntercoBusinessRelationCode),
input tAPMatching.tcCurrencyCode (icCurrencyCode),
input vdDebitTC (idDebitTC),
input vdDebitLC (idDebitLC),
input vdDebitCC (idDebitCC),
input 0 (idDebitPC),
input vdCreditTC (idCreditTC),
input vdCreditLC (idCreditLC),
input vdCreditCC (idCreditCC),
input 0 (idCreditPC),
input 0 (idQty),
input icPostingText (icLineText),
input '':U (icSafText),
input tDefaultSafsAPM (tDefaultSafs),
input 0 (icExchangeRateType),
input idTCLCExchangeRate (idExchangeRate),
input idTCLCExchangeScale (idExchangeRateScale),
input idTCCCExchangeRate (idPostingLineCCRate),
input idTCCCExchangeScale (idPostingLineCCScale),
output oiPostingLineId (oiPostingLineId),
input 0 (iiSafStructureId),
input '':U (icSafStructureCode),
input '':U (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input ? (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* I19 requirement for Brazil =============================================================== */
/* If the AP matching is for the Legal document, all posting lines needs to contain reference */
/* to this legal document */
/* ========================================================================================== */
if vcLegalDocNbr <> ?
then do:
<M-92 run SetPostingLineLegalDocNumber
(input ? (icPostingLineTcRowID),
input oiPostingLineId (iiPostingLineID),
input vcLegalDocNbr (icLegalDocumentNumber),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if vcLegalDocNbr <> ? */
/* Add temp-table record to store the PostingLine ID in case the auto-created posting lines need to be removed (StopExternalInstances) */
create tOpAllocCodePostingLineIDs.
assign tOpAllocCodePostingLineIDs.tcAPMatchingRowID = tAPMatching.tc_Rowid
tOpAllocCodePostingLineIDs.tiPostingLineID = oiPostingLineId.
end. /* if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID */
/* =========================================================== */
/* Create */
/* 1. Posting line in current company which will be cross com- */
/* pany posting line pointing to another company */
/* 2. Create new request for cross company posting daemon for */
/* creation of posting in second company */
/* =========================================================== */
else do :
/* Find the Interco-Code (ICCode) of the company of the PVOD */
assign vcBusinessRelationInterCoCode = "":U.
<Q-69 run CompanyBusinessRelation (all) (Read) (Cache)
(input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
output dataset tqCompanyBusinessRelation) in BCompany>
find first tqCompanyBusinessRelation where
tqCompanyBusinessRelation.tiCompany_ID = tAPMatchingLn.APMatchingLnPvodCompID
no-error.
if available tqCompanyBusinessRelation
then assign vcBusinessRelationInterCoCode = tqCompanyBusinessRelation.tcBusinessRelationICCode
vcTargetCompanyCode = tqCompanyBusinessRelation.tcCompanyCode.
/* Create posting-line on the cross-cy account */
<M-76 run AddStandardPosting
(input icAPMatchingPostingRowId (icPostingtcRowid),
input tqDomainForInterCompany.tcIntercoAPGLCode (icGLCode),
input '':U (icDivisionCode),
input '':U (icCostCentreCode),
input '':U (icCostCentreText),
input '':U (icProjectCode),
input '':U (icProjectText),
input vcBusinessRelationInterCoCode (icIntercoBusinessRelationCode),
input tAPMatching.tcCurrencyCode (icCurrencyCode),
input vdDebitTC (idDebitTC),
input vdDebitLC (idDebitLC),
input vdDebitCC (idDebitCC),
input 0 (idDebitPC),
input vdCreditTC (idCreditTC),
input vdCreditLC (idCreditLC),
input vdCreditCC (idCreditCC),
input 0 (idCreditPC),
input 0 (idQty),
input icPostingText (icLineText),
input '':U (icSafText),
input tDefaultSafsAPM (tDefaultSafs),
input 0 (icExchangeRateType),
input idTCLCExchangeRate (idExchangeRate),
input idTCLCExchangeScale (idExchangeRateScale),
input idTCCCExchangeRate (idPostingLineCCRate),
input idTCCCExchangeScale (idPostingLineCCScale),
output oiPostingLineId (oiPostingLineId),
input 0 (iiSafStructureId),
input '':U (icSafStructureCode),
input '':U (icAllocationKey),
input true (ilLinkedCrCyDaemonReqExists),
input ? (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
/* I19 requirement for Brazil =============================================================== */
/* If the AP matching is for the Legal document, all posting lines needs to contain reference */
/* to this legal document */
/* ========================================================================================== */
if vcLegalDocNbr <> ?
then do:
<M-95 run SetPostingLineLegalDocNumber
(input ? (icPostingLineTcRowID),
input oiPostingLineId (iiPostingLineID),
input vcLegalDocNbr (icLegalDocumentNumber),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then return.
end. /* if vcLegalDocNbr <> ? */
/* Add temp-table record to store the PostingLine ID in case the auto-created posting lines need to be removed (StopExternalInstances) */
create tOpAllocCodePostingLineIDs.
assign tOpAllocCodePostingLineIDs.tcAPMatchingRowID = tAPMatching.tc_Rowid
tOpAllocCodePostingLineIDs.tiPostingLineID = oiPostingLineId.
/* Gather the ID of the GL and the other analytical details */
assign viCrossCompanyGLId = ?.
if tOpAllocCodeStruct.tcGLCode <> ? and
tOpAllocCodeStruct.tcGLCode <> '':U
then do:
<Q-20 run GLPrim (all) (Read) (NoCache)
(input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
input tOpAllocCodeStruct.tcGLCode, (GLCode)
input ?, (GLId)
output dataset tqGLPrim) in BGL>
find first tqGLPrim no-error.
if available tqGLPrim
then assign viCrossCompanyGLId = tqGLPrim.tiGL_ID.
end. /* if icGLCode <> ? and */
assign viCrossCompanyDivisionId = ?.
if tOpAllocCodeStruct.tcDivisionCode <> ? and
tOpAllocCodeStruct.tcDivisionCode <> '':U
then do:
<Q-94 run DivisionPrim (all) (Read) (NoCache)
(input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
input ?, (DivisionID)
input tOpAllocCodeStruct.tcDivisionCode, (DivisionCode)
output dataset tqDivisionPrim) in BDivision>
find first tqDivisionPrim no-error.
if available tqDivisionPrim
then assign viCrossCompanyDivisionId = tqDivisionPrim.tiDivision_ID.
end. /* if icDivisionCode <> ? and */
assign viCrossCompanyProjectId = ?.
if tOpAllocCodeStruct.tcProjectCode <> ? and
tOpAllocCodeStruct.tcProjectCode <> '':U
then do:
<Q-1 run ProjectPrim (all) (Read) (NoCache)
(input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
input ?, (ProjectID)
input tOpAllocCodeStruct.tcProjectCode, (ProjectCode)
output dataset tqProjectPrim) in BProject>
find first tqProjectPrim no-error .
if available tqProjectPrim
then assign viCrossCompanyProjectId = tqProjectPrim.tiProject_ID.
end. /* if icProjectCode */
assign viCrossCompanyCostCentreId = ?.
if tOpAllocCodeStruct.tcCostCentreCode <> ? and
tOpAllocCodeStruct.tcCostCentreCode <> '':U
then do:
<Q-21 run CostCentrePrim (all) (Read) (NoCache)
(input tAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
input ?, (CostCentreID)
input tOpAllocCodeStruct.tcCostCentreCode, (CostCentreCode)
output dataset tqCostCentrePrim) in BCostCentre>
find first tqCostCentrePrim no-error.
if available tqCostCentrePrim
then assign viCrossCompanyCostCentreId = tqCostCentrePrim.tiCostCentre_ID.
end. /* if icCostCentreCode <> ? or */
/* create temp-table record holding the cross company daemon request to create posting in second company */
/* Note that field QCrossCyPostingInfo is not just assigned to icPostingText as we want to see the company-code (and the voucher) as well in the cross-cy-daemon-request */
Create tExtQCrossCyPostingAPM.
Assign tExtQCrossCyPostingAPM.QCrossCyPosting_ID = 0
tExtQCrossCyPostingAPM.CrossCompanyGLIsCredit = (if vdCreditLC <> 0 and vdCreditLC <> ?
then false
else true)
tExtQCrossCyPostingAPM.QCrossCyPostingAmountTC = (if vdCreditTC <> 0 and vdCreditTC <> ?
then vdCreditTC
else vdDebitTC)
tExtQCrossCyPostingAPM.QCrossCyPostingAmountLC = (if vdCreditLC <> 0 and vdCreditLC <> ?
then vdCreditLC
else vdDebitLC)
tExtQCrossCyPostingAPM.QCrossCyPostingAmountCC = (if vdCreditCC <> 0 and vdCreditCC <> ?
then vdCreditCC
else vdDebitCC)
tExtQCrossCyPostingAPM.QCrossCyPostingQTY = 0
tExtQCrossCyPostingAPM.QCrossCyPostingCreateDate = Today
tExtQCrossCyPostingAPM.QCrossCyPostingCreateTime = Time
tExtQCrossCyPostingAPM.CInvoice_ID = 0
tExtQCrossCyPostingAPM.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID
tExtQCrossCyPostingAPM.CrossCompanyGL_ID = tqDomainForInterCompany.tiIntercoAPGL_ID
tExtQCrossCyPostingAPM.Currency_ID = tAPMatching.Currency_ID
tExtQCrossCyPostingAPM.DInvoice_ID = 0
tExtQCrossCyPostingAPM.OriginatorCompany_ID = tAPMatching.Company_ID
tExtQCrossCyPostingAPM.OriginatorPosting_ID = tAPMatching.Posting_ID
tExtQCrossCyPostingAPM.OriginatorJournal_ID = tAPMatching.Journal_ID
tExtQCrossCyPostingAPM.OriginatorPostingLine_ID = oiPostingLineId
tExtQCrossCyPostingAPM.QCrossCyPostingInfo = trim(#T-70'AP Matching':20(49266)T-70#) + ": ":U + trim(vcTargetCompanyCode) + "/":U + string(tAPMatching.tiPeriodYear, "9999":U) + "/":U + string(tAPMatching.tiPeriodPeriod, "99":U) + "/":U + tAPMatching.tcJournalCode + "/":U + string(tAPMatching.tiPostingVoucher)
tExtQCrossCyPostingAPM.APMatchingGL_ID = viCrossCompanyGLId
tExtQCrossCyPostingAPM.APMatchingDivision_ID = viCrossCompanyDivisionId
tExtQCrossCyPostingAPM.APMatchingProject_ID = viCrossCompanyProjectId
tExtQCrossCyPostingAPM.APMatchingCostCentre_ID = viCrossCompanyCostCentreId
tExtQCrossCyPostingAPM.tc_Rowid = string(- oiPostingLineId).
end. /* else do: of if tAPMatching.Company_ID = tAPMatchingLn.APMatchingLnPvodCompID */
end. /* for each tOpAllocCode */
/* Clear temp-tables to clear memory */
empty temp-table tOpAllocCodeStruct.