project QadFinancials > class BPosting > method CreatePostingsFromImport
Description
Method to add a set of new posting entries into the current instance. It works as buffer-copy. A vantage is that validations can be run only once after all records are added.
Parameters
Internal usage
QadFinancials
program code (program6/bposting.p)
POSTING_BLOCK:
for each tApiPosting
by tApiPosting.tc_Rowid:
<M-11 run AddPostingHeader
(input tApiPosting.Company_ID (iiCompanyId),
input tApiPosting.PostingYear (iiPeriodYear),
input tApiPosting.PostingPeriod (iiPeriodPeriod),
input tApiPosting.tcJournalCode (icJournalCode),
input '':U (icReportingJournalCode),
input tApiPosting.PostingVoucher (iiVoucher),
input tApiPosting.PostingDate (itPostingDate),
input tApiPosting.PostingValueDate (itValueDate),
input tApiPosting.PostingText (icPostingText),
input tApiPosting.PostingBusinessRelationTxt (icPostingBusinessRelationText),
input tApiPosting.PostingInvoiceReferenceTxt (icPostingInvoiceReferenceText),
input tApiPosting.PostingParentText (icPostingParentText),
input tApiPosting.Period_ID (iiBPeriodId),
input tApiPosting.PostingOriginAddressCode (icPostingOriginAddressCode),
input tApiPosting.PostingOriginDocument (icPostingOriginDocument),
input tApiPosting.PostingOriginDocumentType (icPostingOriginDocumentType),
input tApiPosting.PostingBatchNumber (icBatchNumber),
input ? (icBankImpLineRef),
output viPostingId (oiPostingId),
output vcPostingRowId (ocRowid),
output viPostingVoucher (oiPostingVoucher),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave POSTING_BLOCK.
find first tPosting where tPosting.tc_Rowid = vcPostingRowId no-error.
if not available tPosting
then next.
if tPosting.PostingOriginIsExternal = ?
then assign tPosting.PostingOriginIsExternal = false.
/* Store the new ID */
assign tApiPosting.Posting_ID = tPosting.Posting_ID.
tApiPosting.PostingVoucher = tPosting.PostingVoucher.
for each tApiPostingLine where
tApiPostingLine.tc_ParentRowid = tApiPosting.tc_Rowid
by tApiPostingLine.tc_Rowid:
empty temp-table tDefaultSafs . /* new tdefaluts saf should be created */
/* in most of cases, the safs need to be retrieved from the AddStandardPosting method itself */
for each tApiPostingSaf where
tApiPostingSaf.tc_ParentRowid = tApiPostingLine.tc_Rowid
by tApiPostingSaf.tc_Rowid:
create tDefaultSafs.
assign tDefaultSafs.tcSafCode = tApiPostingSaf.tcSafCode
tDefaultSafs.tcSafConceptCode = tApiPostingSaf.tcSafConceptCode.
end. /* end of for each tApiPostingSaf */
<M-10 run AddStandardPosting
(input vcPostingRowId (icPostingtcRowid),
input tApiPostingLine.tcGLCode (icGLCode),
input tApiPostingLine.tcDivisionCode (icDivisionCode),
input tApiPostingLine.tcCostCentreCode (icCostCentreCode),
input '':U (icCostCentreText),
input tApiPostingLine.tcProjectCode (icProjectCode),
input tApiPostingLine.tcProjectDescription (icProjectText),
input tApiPostingLine.tcIntercoBusinessRelationCode (icIntercoBusinessRelationCode),
input tApiPostingLine.tcCurrencyCode (icCurrencyCode),
input tApiPostingLine.PostingLineDebitTC (idDebitTC),
input tApiPostingLine.PostingLineDebitLC (idDebitLC),
input tApiPostingLine.PostingLineDebitCC (idDebitCC),
input tApiPostingLine.PostingLineDebitPC (idDebitPC),
input tApiPostingLine.PostingLineCreditTC (idCreditTC),
input tApiPostingLine.PostingLineCreditLC (idCreditLC),
input tApiPostingLine.PostingLineCreditCC (idCreditCC),
input tApiPostingLine.PostingLineCreditPC (idCreditPC),
input tApiPostingLine.PostingLineQTY (idQty),
input tApiPostingLine.PostingLineText (icLineText),
input tApiPostingLine.PostingLineSafText (icSafText),
input tDefaultSafs (tDefaultSafs),
input '':U (icExchangeRateType),
input tApiPostingLine.PostingLineExchangeRate (idExchangeRate),
input tApiPostingLine.PostingLineRateScale (idExchangeRateScale),
input tApiPostingLine.PostingLineCCRate (idPostingLineCCRate),
input tApiPostingLine.PostingLineCCScale (idPostingLineCCScale),
output viPostingLineId (oiPostingLineId),
input 0 (iiSafStructureId),
input '':U (icSafStructureCode),
input '':U (icAllocationKey),
output viFcReturnSuper (oiReturnStatus)) in BPosting>
if viFcReturnSuper <> 0
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then Leave POSTING_BLOCK.
for each tApiPostingVat where
tApiPostingVat.tc_ParentRowid = tApiPostingLine.tc_Rowid
by tApiPostingVat.tc_Rowid:
<M-4 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 Leave POSTING_BLOCK.
buffer-copy tApiPostingVat
except tApiPostingVat.PostingLine_ID
tApiPostingVat.PostingVat_ID
tApiPostingVat.tc_Rowid
tApiPostingVat.tc_ParentRowid
tApiPostingVat.tc_Status
to tPostingVat.
end.
end.
end.
/* Release Numbers */
if oiReturnStatus <> 0
then do :
for each tApiPosting where
tApiPosting.PostingVoucher > 0:
/* Start&Open BNumber (AddToTrx=false) as in a loop below we will be calling BNumber repetively and this */
/* is more performing then using vhFcComponent=?. BNumber will be closed and stopped after the loop */
if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ?
then do :
<I-30 {bFcStartAndOpenInstance
&ADD-TO-TRANSACTION = "false"
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID = 0 or viBNumberFromBPostingID = ? */
/* Free up the number */
<M-9 run ReleaseNumber
(input tApiPosting.Company_ID (iiCompanyId),
input tApiPosting.PostingYear (iiNumbrYear),
input tApiPosting.tcJournalCode (icNumbrType),
input tApiPosting.PostingVoucher (iiNumbr),
input viFcCurrentInstanceId (iiInstanceId),
input vcFcComponentName (icClassName),
output viFcReturnSuper (oiReturnStatus)) in BNumber>
end. /* for each tApiPosting where */
/* Close&Stop BNumber that is started with a different transaction before the previous loop */
if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ?
then do :
<I-27 {bFcCloseAndStopInstance
&CLASS = "BNumber"}>
end. /* if viBNumberFromBPostingID <> 0 and viBNumberFromBPostingID <> ? */
end. /* if oiReturnStatus <> 0 */
/* added for assigning originatorReference for revesal posting in both tPosting and tApiPosting */
for each tApiPosting where
tApiPosting.PostingIsReversing = true:
find first bPosting where
bPosting.tc_Rowid = tApiPosting.PostingoriginatorReference and
bPosting.PostingIsReversing = false
no-error.
if available bPosting
then do:
assign tApiPosting.PostingOriginatorReference =
substitute("&1/&2/&3":U,
bPosting.PostingYear,
bPosting.tcJournalCode,
string(bPosting.PostingVoucher,"999999999":U)).
find first tPosting where
tPosting.Posting_id = tApiPosting.Posting_ID
no-error.
if available tPosting
then assign tPosting.PostingOriginatorReference = tApiPosting.PostingOriginatorReference.
end.
end.