project QadFinancials > class BPosting > method ApiStdMaintainTTSub1
Description
ApiStdMaintainTTSub1; Sub-method of ApiStdMaintainTT
Parameters
icAction | input | character | |
bcLstReturn | input-output | character | |
bcLstPrimKey | input-output | character | |
bcLstRowid | input-output | character | |
blSaveAsDraft | input-output | logical | |
blQStartedVatRuleByVatIDCode | input-output | logical | QStartedVatRuleByVatIDCode: true in case query VatRuleByVatIDCode is started alreay |
blQStartedGetSafConceptsForStr | input-output | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program9/bposting.p)
/* ===================================================================== */
/* Prerequisits: a tPosting record and a tApiPosting record is available */
/* and the tApiPostingLine, tApiPostingSaf, tApiPostingVat and */
/* tApiPostingXRef records can be accessed */
/* NOTE: Postings are always in new-mode from external creation. */
/* ===================================================================== */
/* ============================ */
/* Go through all posting-lines */
/* ============================ */
for each tApiPostingLine where
tApiPostingLine.tc_ParentRowid = tApiPosting.tc_Rowid and
tApiPostingLine.tcGLCode <> "":U
by tApiPostingLine.tc_Rowid :
if tApiPostingLine.PostingLineDebitLC = ?
then assign tApiPostingLine.PostingLineDebitLC = 0.
if tApiPostingLine.PostingLineCreditLC = ?
then assign tApiPostingLine.PostingLineCreditLC = 0.
if tApiPostingLine.PostingLineDebitCC = ?
then assign tApiPostingLine.PostingLineDebitCC = 0.
if tApiPostingLine.PostingLineCreditCC = ?
then assign tApiPostingLine.PostingLineCreditCC = 0.
if tApiPostingLine.Company_ID <> 0 and tApiPostingLine.Company_ID <> ?
then vicompID = tApiPostingLine.Company_ID.
else vicompID = viCompanyID.
<Q-41 run GetGLIDBasedOnGLCode (all) (Read) (Cache)
(input vicompID, (CompanyID)
input tApiPostingLine.tcGLCode, (GLCode)
output dataset tqGLIDBasedOnGLCode) in BGL>
for first tqGLIDBasedOnGLCode where
tqGLIDBasedOnGLCode.tcGLCode = tApiPostingLine.tcGLCode
no-lock:
if tqGLIDBasedOnGLCode.tlGLIsIntercoAccount = no
then assign tApiPostingLine.tcIntercoBusinessRelationCode = "":U
tApiPostingLine.IntercoBusinessRelation_ID = 0.
else
if tqGLIDBasedOnGLCode.tlGLIsIntercoAccount and
(tApiPostingLine.tcIntercoBusinessRelationCode = "" or tApiPostingLine.tcIntercoBusinessRelationCode = ?) and
(tApiPostingLine.IntercoBusinessRelation_ID = 0 or tApiPostingLine.IntercoBusinessRelation_ID = ?)
then do:
if tApiPostingLine.CustomShort9 <> "" and tApiPostingLine.CustomShort9 <> ?
then do:
<Q-42 run BusinessRelationByIDCodeIC (all) (Read) (NoCache)
(input ?, (BusinessRelationID)
input tApiPostingLine.CustomShort9, (BusinessRelationCode)
input ?, (BusinessRelationIntercoCode)
input ?, (BusinessRelationIsActive)
output dataset tqBusinessRelationByIDCodeIC) in BBusinessRelation >
find first tqBusinessRelationByIDCodeIC no-lock no-error.
if available tqBusinessRelationByIDCodeIC
then
assign tApiPostingLine.IntercoBusinessRelation_ID = tqBusinessRelationByIDCodeIC.tiBusinessRelation_ID
tApiPostingLine.tcIntercoBusinessRelationCode = ?
tApiPostingLine.CustomShort9 = ''.
end. /*IF tApiPostingLine.CustomShort0 <> "" AND tApiPostingLine.CustomShort0 <> ? */
if tApiPostingLine.IntercoBusinessRelation_ID = 0 or tApiPostingLine.IntercoBusinessRelation_ID = ?
then
assign tApiPostingLine.IntercoBusinessRelation_ID = tqGLIDBasedOnGLCode.tiBusinessRelation_ID
tApiPostingLine.tcIntercoBusinessRelationCode = ?.
end. /* ELSE IF tqGLById.tlGLIsIntercoAccount... */
end. /* FOR FIRST tqGLByID */
/* ========================================== */
/* Create a new PostingLine and copy all data */
/* ========================================== */
<M-1 run AddDetailLine
(input 'PostingLine':U (icTable),
input tPosting.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper > 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0 then do:
<M-43 run SetRowidConvert
(input tApiPostingLine.tc_Rowid (icOldRowid),
input tPostingLine.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
end.
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
buffer-copy tApiPostingLine
except PostingLine_ID
Posting_ID
Company_ID
tc_rowid
tc_ParentRowid
tc_status
to tPostingLine.
assign tPostingLine.tlLinkedCrCyDaemonReqExists = false.
/* =========================================== */
/* Fill AllocationKey in case it is not filled */
/* =========================================== */
if tPostingLine.tcAllocationKey <> '':U and
tPostingLine.tcAllocationKey <> ?
then assign tPostingLine.tcAllocationPostingLine = trim(string(tPosting.PostingYear)) + '/':U +
trim(string(tPosting.PostingPeriod)) + '/':U +
trim(tPosting.tcJournalCode) + '/':U +
trim(string(tPosting.PostingVoucher)).
/* ============================================================================================================ */
/* New extention only applicable for the interfaces: */
/* - Note: normal situation: TC * Rate * Scale = LC (there is no validation on this */
/* When Currency<>Local and ExchangeRate and ScaleFactor and TC and LC are filled then we will here check if */
/* - LC (rounded by viCompanyLCDec) */
/* - TC * Rate * Scale (rounded by viCompanyLCDec) */
/* Are the same with an excption on the last significant digit */
/* ============================================================================================================ */
if ((tPostingLine.PostingLineCreditLC <> 0 and
tPostingLine.PostingLineCreditLC <> ?) or
(tPostingLine.PostingLineDebitLC <> 0 and
tPostingLine.PostingLineDebitLC <> ?)) and
((tPostingLine.PostingLineCreditTC <> 0 and
tPostingLine.PostingLineCreditTC <> ?) or
(tPostingLine.PostingLineDebitTC <> 0 and
tPostingLine.PostingLineDebitTC <> ?)) and
tPostingLine.PostingLineExchangeRate <> 0 and
tPostingLine.PostingLineExchangeRate <> ? and
tPostingLine.PostingLineRateScale <> 0 and
tPostingLine.PostingLineRateScale <> ? and
tPostingLine.tcCurrencyCode <> vcCompanyLC
then do :
/* Check if the passed LC is acceptable */
assign vdPostingAmountInputLC = tPostingLine.PostingLineCreditLC - tPostingLine.PostingLineDebitLC
vdPostingAmountCalcLC = <M-46 RoundAmount
(input (tPostingLine.PostingLineCreditTC - tPostingLine.PostingLineDebitTC) * tPostingLine.PostingLineExchangeRate * tPostingLine.PostingLineRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>.
if viCompanyLCDec = 0 or viCompanyLCDec = ?
then assign vdTolerance = 1.
else assign vdTolerance = 1 / (10 * viCompanyLCDec).
if ABS (vdPostingAmountInputLC - vdPostingAmountCalcLC) > vdTolerance
then do :
assign vcMsgExplanation = <M-94 GetErrorExplanation
(input tPosting.tc_Rowid (icPostingRowId),
input tPostingLine.tc_Rowid (icPostingLineRowId),
output viFcReturnSuper (oiReturnStatus)) in BPosting>.
assign vcMessage = trim(substitute(#T-23'The rounded values for the BC Amount and the TC Amount (multiplied by the Exchange Rate and the Rate Scale) should be the same (except the last significant character)':255(73470646)T-23#)) + chr(10) +
trim(substitute(#T-25'When you pass amounts and exchange rates for posting lines in foreign currency, the allowed differences between the TC amount (plus rates) and BC amount is limited':255(413962953)T-25#)) + chr(10) +
trim(substitute(#T-24'TC Credit Amount in posting line: &1.':255(31341)T-24#, trim(string(tPostingLine.PostingLineCreditTC)))) + chr(10) +
trim(substitute(#T-26'TC Debit Amount in posting line: &1.':255(31343)T-26#, trim(string(tPostingLine.PostingLineDebitTC)))) + chr(10) +
trim(substitute(#T-27'BC Credit Amount in posting line: &1.':255(31344)T-27#, trim(string(tPostingLine.PostingLineCreditLC)))) + chr(10) +
trim(substitute(#T-28'BC Debit Amount in posting line: &1.':255(31345)T-28#, trim(string(tPostingLine.PostingLineDebitLC)))) + chr(10) +
trim(substitute(#T-47'BC Amount in posting line: &1':255(733740406)T-47#,trim(string(abs (tPostingLine.PostingLineCreditLC - tPostingLine.PostingLineDebitLC))))) + chr(10) +
trim(substitute(#T-48'Tolerance Value: &1':255(73460411)T-48#,string (vdTolerance))) +
trim(substitute(#T-31'Exchange Rate in posting line: &1.':255(31352)T-31#, trim(string(tPostingLine.PostingLineExchangeRate)))) + chr(10) +
trim(substitute(#T-32'Rate Scale in posting line : &1.':255(591285913)T-32#, trim(string(tPostingLine.PostingLineRateScale)))) + chr(10) +
trim(substitute(#T-33'Number of decimals for BC amounts: &1.':255(31354)T-33#, trim(string(viCompanyLCDec)))) + chr(10) +
trim(substitute(#T-37'Daybook code: &1':222(31365)T-37#, tPosting.tcJournalCode)) + ' ' +
trim(substitute(#T-92'Daybook type: &1':255(64046)T-92#, tPosting.tcJournalTypeCode)).
/* Get some properties of the daybook and cache them in local data items for performance reasons */
if tPosting.tcJournalCode <> ? and
tPosting.tcJournalCode <> ''
then do:
/* Get some properties of the daybook */
<Q-7 run JournalByJournalCode (all) (Read) (Cache)
(input tPosting.Company_ID, (CompanyId)
input tPosting.tcJournalCode, (JournalCode)
output dataset tqJournalByJournalCode) in BJournal>
find first tqJournalByJournalCode where
tqJournalByJournalCode.tcJournalCode = tPosting.tcJournalCode
no-error.
end.
/* ============================================================================================================================= */
/* In case the transaction has an Operational Sales Invoice Daybook, the validation is considered as a warning and nnot an error */
/* ============================================================================================================================= */
if tPosting.tcJournalCode <> ? and
tPosting.tcJournalCode <> '' and
available tqJournalByJournalCode and
tqJournalByJournalCode.tcJournalCode = tPosting.tcJournalCode and
tqJournalByJournalCode.tcJournalControl = {&JOURNALCONTROL-LOGISTIC} and
(tqJournalByJournalCode.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICE} or
tqJournalByJournalCode.tcJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICECORRECT} or
tqJournalByJournalCode.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTE} or
tqJournalByJournalCode.tcJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTECORRECT})
then do:
<M-65 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'qadfin-446124':U (icFcMsgNumber),
input vcMsgExplanation (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if oiReturnStatus = 0
then assign oiReturnStatus = +1.
end. /* Warning */
else do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(-1)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
<M-22 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-4798':U (icFcMsgNumber),
input vcMsgExplanation (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
assign oiReturnStatus = -1.
Return.
end. /* Error */
end. /* if vdPostingLineAmountTC <> vdPostingLineAmountLC */
end. /* if */
/* ===================================================================================== */
/* If the SAF Structure is not specified then use tApiPostingSaf as a source of SAF code */
/* Call ApiStdMaintainTTSub11 to determine SAF Structures and processing SAF */
/* ===================================================================================== */
if can-find (first tApiPostingSaf where
tApiPostingSaf.tc_ParentRowid = tApiPostingLine.tc_Rowid and
tApiPostingSaf.tc_status <> "D":U and
tApiPostingSaf.tcSafConceptCode <> "":U and
tApiPostingSaf.tcSafConceptCode <> ? and
(tApiPostingSaf.tcSafStructureCode = "":U or
tApiPostingSaf.tcSafStructureCode = ?)) or
not can-find(first tApiPostingSaf where
tApiPostingSaf.tc_ParentRowid = tApiPostingLine.tc_Rowid and
tApiPostingSaf.tc_status <> "D":U)
then do:
/* Update the postingline_id so that the record can be found in ApiStdMaintainTTSub11 */
for each tApiPostingSaf where
tApiPostingSaf.tc_ParentRowid = tApiPostingLine.tc_Rowid :
assign tApiPostingSaf.PostingLine_ID = tPostingLine.PostingLine_ID.
end.
<M-34 run ApiStdMaintainTTSub11
(input-output blQStartedGetSafConceptsForStr (blQStartedGetSafConceptsForStr),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
end. /* if can-find (first tApiPostingSaf where */
else do:
/* ============================================= */
/* Go through all PostingSAFs */
/* ============================================= */
for each tApiPostingSaf where
tApiPostingSaf.tc_ParentRowid = tApiPostingLine.tc_Rowid
by tApiPostingSaf.tc_Rowid :
/* ============================================= */
/* Create PostingSAF and copy the data */
/* ============================================= */
<M-2 run AddDetailLine
(input 'PostingSAF':U (icTable),
input tPostingLine.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper > 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0 then do:
<M-44 run SetRowidConvert
(input tApiPostingSaf.tc_Rowid (icOldRowid),
input tPostingSaf.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
end.
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
buffer-copy tApiPostingSaf
except PostingSaf_ID
PostingLine_ID
tc_rowid
tc_ParentRowid
tc_status
to tPostingSaf.
end. /* for each tApiPostingSaf where */
end. /* else do */
/* ============================================= */
/* Go through all PostingVATs */
/* ============================================= */
for each tApiPostingVat where
tApiPostingVat.tc_ParentRowid = tApiPostingLine.tc_Rowid
by tApiPostingVat.tc_Rowid :
/* ============================================= */
/* Create PostingVAT and copy the data */
/* ============================================= */
<M-3 run AddDetailLine (input 'PostingVat':U (icTable),
input tPostingLine.tc_Rowid (icParentRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper > 0 then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper >= 0 then do:
<M-45 run SetRowidConvert
(input tApiPostingVat.tc_Rowid (icOldRowid),
input tPostingVat.tc_Rowid (icNewRowid),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
end.
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
assign blSaveAsDraft = (icAction <> {&DAEMONACTION-SAVE} and icAction <> {&DAEMONACTION-VALIDATE})
bcLstReturn = bcLstReturn + chr(4) + string(viFcReturnSuper)
bcLstPrimKey = bcLstPrimKey + chr(4) + "*":U
bcLstRowid = bcLstRowid + chr(4) + "*":U.
return.
end. /* if oiReturnStatus < 0 */
end. /* if viFcReturnSuper <> 0 */
buffer-copy tApiPostingVat
except PostingVat_ID
PostingLine_ID
tc_rowid
tc_ParentRowid
tc_status
to tPostingVat.
/* ========================================================== */
/* Ensure that the date is set */
/* Copy from the posting line if not set */
/* ========================================================== */
if tPostingVat.PostingVatTaxPointDate = ?
then assign tPostingVat.PostingVatTaxPointDate = tPosting.PostingDate.
/* ========================================================== */
/* Fill in bVatRule_id */
/* Get all VatRules for this Vat_id and use the same sequence */
/* ========================================================== */
if tPostingVat.tcVatCode = "":U or
tPostingVat.tcVatCode = ?
then next.
if blQStartedVatRuleByVatIDCode = false
then do :
<Q-38 run VatRuleByVatIDCode (Start) in BVAT >
assign blQStartedVatRuleByVatIDCode = true.
end. /* if blQStartedVatRuleByVatIDCode = false */
<Q-5 run VatRuleByVatIDCode (all) (Read) (Cache)
(input tPostingVat.tcVatCode, (VatCode)
input ?, (VatID)
input {&VATRULEBASE-FULL}, (VatRuleBaseFull)
input tPostingVat.tcVatInOut, (VatInOut)
input tPostingVat.tcDomainCode, (DomainCode)
output dataset tqVatRuleByVatIDCode) in BVAT >
if tPostingVat.PostingVatIsAbsRet = true
then find last tqVatRuleByVatIDCode where
tqVatRuleByVatIDCode.tcVatCode = tPostingVat.tcVatCode and
tqVatRuleByVatIDCode.tcVatInOut = tPostingVat.tcVatInOut and
tqVatRuleByVatIDCode.tcDomainCode = tPostingVat.tcDomainCode and
tqVatRuleByVatIDCode.tcVatRuleBaseFull = {&VATRULEBASE-FULL}
no-error. /* First one gives the normal tax - the second one gives the one for retained and absorbed taxes: this needs to be made conditional (first-lat) based upon a new field in PostingVat */
else find first tqVatRuleByVatIDCode where
tqVatRuleByVatIDCode.tcVatCode = tPostingVat.tcVatCode and
tqVatRuleByVatIDCode.tcVatInOut = tPostingVat.tcVatInOut and
tqVatRuleByVatIDCode.tcDomainCode = tPostingVat.tcDomainCode and
tqVatRuleByVatIDCode.tcVatRuleBaseFull = {&VATRULEBASE-FULL}
no-error. /* First one gives the normal tax - the second one gives the one for retained and absorbed taxes: this needs to be made conditional (first-lat) based upon a new field in PostingVat */
if not available tqVatRuleByVatIDCode
then do:
assign vcMsgExplanation = <M-98 GetErrorExplanation
(input tPosting.tc_Rowid (icPostingRowId),
input tPostingLine.tc_Rowid (icPostingLineRowId),
output viFcReturnSuper (oiReturnStatus)) in BPosting>.
assign vcMessage = trim(substitute(#T-40'Internal error: the tax-posting-line cannot be created as the Vat-rule cannot be found based upon the Domain (&1), Tax-code (&2) and Tax-direction (&3).':255(332065953)T-40#,tPostingVat.tcDomainCode,tPostingVat.tcVatCode,tPostingVat.tcVatInOut))
oiReturnStatus = -3.
<M-39 run SetMessage
(input vcMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QadFin-8022':U (icFcMsgNumber),
input vcMsgExplanation (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
Return.
end. /* if not available tqVatRuleByVatIDCode */
assign tPostingVat.VatRule_ID = tqVatRuleByVatIDCode.tiVatRule_ID.
end. /* for each tApiPostingVat where */
end. /* for each tApiPostingLine where */