Description
Create the CI Posting (Part 2 - Method too long)
Parameters
iiCInvoiceId | input | integer | CInvoice ID |
iiPeriodYear | input | integer | Accounting Year |
iiPeriodPeriod | input | integer | GL Period |
itPostingDate | input | date | posting date |
iiCreditorId | input | integer | Creditor ID |
icCreditorCode | input | character | Supplier Code |
icCInvoiceType | input | character | Type of the creditor invoice |
icDivisionCode | input | character | Sub-Account Code |
icJournalCode | input | character | Daybook Code |
iiVoucher | input | integer | Voucher |
itTaxPointDate | input | date | tax point date |
icReference | input | character | Reference |
icDescription | input | character | Description |
idInvoiceAmountTC | input | decimal | Invoice Amount in TC |
idInvoiceAmountLC | input | decimal | Invoice Amount in LC |
idInvoiceAmountCC | input | decimal | Invoice Amount in CC |
icCurrencyCode | input | character | Transactial Currency Code |
idExchangeRate | input | decimal | exchange rate |
idExchangeRateScale | input | decimal | |
icCIText | input | character | SI Text |
icPostingType | input | character | Posting Type |
icGlCode | input | character | gl account |
icCostCentreCode | input | character | Cost Center Code |
icProjectCode | input | character | Project Code |
ilOnlyControlAccount | input | logical | Posting only on the control account |
icShipToCountryCode | input | character | Country code of the ship to address |
icTxclTaxCls | input | character | Tax Class of the Tax tab if filled, otherwise the tax class of the creditor |
icTxuTaxUsage | input | character | Tax Usage of the Tax tab, if not filled, then pass the tax usage of the creditor |
icTxenvTaxEnv | input | character | Tax environment of the tax tab, if not filled, pass the default value of it |
icPaymentCondition | input | character | Payment Condition |
ilIsTaxInCityFromShipTo | input | logical | tax in city flag of the ship to address |
icPoNbr | input | character | Po number |
ilIsTaxable | input | logical | Is taxable flag |
icControlCostCentreCode | input | character | |
icControlProjectCode | input | character | |
iiShipFromAddressId | input | integer | Ship From Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries |
iiShipToAddressId | input | integer | Ship To Address ID : necessary to fill the federal tax, state tax, misc .... Not needed for manual journal entries |
ilIsLogisticMatching | input | logical | Is logistic matching ? |
ilGetDefaultSafs | input | logical | |
icBusinessRelationCode | input | character | |
iiPrePayControlGLProfileId | input | integer | |
iiInvControlGLProfileId | input | integer | |
iiCnControlGLProfileId | input | integer | |
icCInvoiceRowid | input | character | |
icBusinessRelationInterCoCode | input | character | |
icShipFromCountryCode | input | character | |
ilShipFromCountryIsEUCountry | input | logical | |
icCreditorTaxZone | input | character | |
ilIsInitialStatus | input | logical | at modify : pass the initial value of the IsInitialStatus flag, in all other cases pass false |
tApiCInvoiceVat | input-output | temp-table | temp table like cinvoicevat table |
tDefaultSafsCI | input | temp-table | |
ilHandleCommunicationWithJE | input | logical | do you want that this method handles the communication with the journal entry component or not ? If the instance of the journal entry is already started, pass false... |
biBJournalEntryId | input-output | integer | Instance of Journal Entry |
biPostingId | input-output | integer | ID of the CI Posting |
icRowId | input | character | |
iiControlPostingLineId | input | integer | |
itInvoiceDate | input | date | |
idCCExchangeRate | input | decimal | |
idCCExchangeRateScale | input | decimal | |
ilCInvoiceIsForLegalDoc | input | logical | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bcinvoice.p)
assign oiReturnStatus = -98
viLocalReturnStatus = 0.
if vlCompanyPropertyIsAPUseInvDate = true
then assign vtExchangeRateDate = itInvoiceDate.
else assign vtExchangeRateDate = ?.
POSTING2BLOCK: DO :
if not ilOnlyControlAccount /* SIREC or other a/c */
then do:
if icGlCode = "":U /* SIREC */
then do:
/* CC Amounts passed to addStandardPosting need to be ? instead of 0 */
assign vdCIRECDebitTC = ?
vdCIRECDebitLC = ?
vdCIRECDebitCC = ?
vdCIRECCreditTC = ?
vdCIRECCreditLC = ?
vdCIRECCreditCC = ?.
<Q-131 run GLByGLSystemType (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input {&GLSYSTEMTYPE-CIREC}, (GLSystemTypeCode)
input {&GLTYPECODE-SYST}, (GlTypeCode)
input ?, (GlIsDivisionAccount)
output dataset tqGLByGLSystemType) in BGL >
find first tqGLByGLSystemType where
tqGLByGLSystemType.tcGLSystemTypeCode = {&GLSYSTEMTYPE-CIREC} and
tqGLByGLSystemType.tcGLTypeCode = {&GLTYPECODE-SYST}
no-error.
if not available tqGLByGLSystemType
then do:
<M-127 run SetMessage
(input trim(#T-150'The system could not find an Unmatched Invoices account record.':150(1054)T-150#) (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input tCInvoice.tc_Rowid (icRowid),
input 'QadFin-9517':U (icFcMsgNumber),
input '':U (icFcExplanation),
input '':U (icFcIdentification),
input '':U (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
assign viLocalReturnStatus = -1.
if ilHandleCommunicationWithJE = true
then do:
<I-144 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
leave POSTING2BLOCK.
end. /* if not avail tqGLByGLSystemType */
assign vlTax = false.
for each tApiCInvoiceVat where
tApiCInvoiceVat.tc_ParentRowid = icCInvoiceRowid and
tApiCInvoiceVat.tc_Status <> "D":U:
if tApiCInvoiceVat.CInvoiceVatIsAccrRcpUs = false and
tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC <> ? and
(abs(tApiCInvoiceVat.CInvoiceVatVatDebitTC -
tApiCInvoiceVat.CInvoiceVatVatCreditTC) -
tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC) <> 0
then do:
accumulate tApiCInvoiceVat.CInvoiceVatVatDebitTC (total).
accumulate tApiCInvoiceVat.CInvoiceVatVatCreditTC (total).
accumulate tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC (total).
assign vlTax = true.
end. /* if tApiCInvoiceVat.CInvoiceVatIsAccrRcpUs = false and .. */
end. /* for each tApiCInvoiceVat where */
assign vdCIRECDebitTC = if icCInvoiceType = {&INVOICETYPE-INVOICE} or
icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then if vlTax
then idInvoiceAmountTC - ((accum total tApiCInvoiceVat.CInvoiceVatVatDebitTC) - (accum total tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC)) + (accum total tApiCInvoiceVat.CInvoiceVatVatCreditTC)
else idInvoiceAmountTC
else 0
vdCIRECCreditTC = if icCInvoiceType = {&INVOICETYPE-INVOICE} or
icCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
then 0
else if vlTax
then idInvoiceAmountTC - ((accum total tApiCInvoiceVat.CInvoiceVatVatCreditTC) - (accum total tApiCInvoiceVat.CInvoiceVatNonRecTaxAmtTC)) + (accum total tApiCInvoiceVat.CInvoiceVatVatDebitTC)
else idInvoiceAmountTC
vdCIRECDebitLC = if icCurrencyCode = vcCompanyLC
then vdCIRECDebitTC
else <M-122 RoundAmount
(input vdCIRECDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BCInvoice>
vdCIRECCreditLC = if icCurrencyCode = vcCompanyLC
then vdCIRECCreditTC
else <M-123 RoundAmount
(input vdCIRECCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in BCInvoice>
vdCIRECDebitCC = if icCurrencyCode = vcCompanyCC
then vdCIRECDebitTC
else if vdCIRECDebitCC = ? or
idCCExchangeRate = ? or
idCCExchangeRate = 0 or
idCCExchangeRateScale = ? or
idCCExchangeRateScale = 0
then ?
else <M-43 RoundAmount
(input vdCIRECDebitTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BCInvoice>
vdCIRECCreditCC = if icCurrencyCode = vcCompanyCC
then vdCIRECCreditTC
else if vdCIRECDebitCC = ? or
idCCExchangeRate = ? or
idCCExchangeRate = 0 or
idCCExchangeRateScale = ? or
idCCExchangeRateScale = 0
then ?
else <M-23 RoundAmount
(input vdCIRECCreditTC * idCCExchangeRate * idCCExchangeRateScale (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BCInvoice>
vlCIREC = true.
if idInvoiceAmountCC <> 0 and
idInvoiceAmountCC <> ?
then do:
if vcCompanyCC = icCurrencyCode
then assign vdCIRECDebitCC = vdCIRECDebitTC
vdCIRECCreditCC = vdCIRECCreditTC.
else if vcCompanyCC = vcCompanyLC
then assign vdCIRECDebitCC = vdCIRECDebitLC
vdCIRECCreditCC = vdCIRECCreditLC.
else do:
assign vdExRateCC = idInvoiceAmountLC / idInvoiceAmountCC
vdExRateScaleCC = 1
vdCIRECDebitCC = <M-147 RoundAmount
(input vdCIRECDebitLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BCInvoice>
vdCIRECCreditCC = <M-148 RoundAmount
(input vdCIRECCreditLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BCInvoice>.
end. /* else do: */
end. /* if idInvoiceAmountCC <> 0 and idInvoiceAmountCC <> ? */
<M-112 run AddStandardPosting
(input icRowId (icPostingtcRowid),
input tqGLByGLSystemType.tcGLCode (icGLCode),
input icDivisionCode (icDivisionCode),
input icCostCentreCode (icCostCentreCode),
input icCIText (icCostCentreText),
input icProjectCode (icProjectCode),
input icCIText (icProjectText),
input icBusinessRelationInterCoCode (icIntercoBusinessRelationCode),
input icCurrencyCode (icCurrencyCode),
input vdCIRECDebitTC (idDebitTC),
input vdCIRECDebitLC (idDebitLC),
input vdCIRECDebitCC (idDebitCC),
input 0 (idDebitPC),
input vdCIRECCreditTC (idCreditTC),
input vdCIRECCreditLC (idCreditLC),
input vdCIRECCreditCC (idCreditCC),
input 0 (idCreditPC),
input 0 (idQty),
input icCIText (icLineText),
input icCIText (icSafText),
input tDefaultSafsCI (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input idExchangeRate (idExchangeRate),
input idExchangeRateScale (idExchangeRateScale),
input idCCExchangeRate (idPostingLineCCRate),
input idCCExchangeRateScale (idPostingLineCCScale),
output viCIRECPostingLineId (oiPostingLineId),
input ? (iiSafStructureId),
input ? (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input vtExchangeRateDate (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then do:
if ilHandleCommunicationWithJE = true
then do:
<I-26 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
return.
end.
/* I19 requirement for Brazil ============================================================== */
/* Update posting line to control account to contain legal document number filled in */
/* ========================================================================================= */
if ilCInvoiceIsForLegalDoc
then do:
<M-18 run SetPostingLineLegalDocNumber
(input ? (icPostingLineTcRowID),
input viCIRECPostingLineId (iiPostingLineID),
input entry(1, icReference) (icLegalDocumentNumber),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then do:
if ilHandleCommunicationWithJE = true
then do:
<I-35 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
return.
end.
end. /* if ilCInvoiceIsForLegalDoc */
end. /* if icGlCode = "":U */
else do: /* Other ac */
<M-116 run CreateCIPostingCalculateAmounts
(input no (ilIsCreditorControlAccount),
input icCInvoiceType (icCInvoiceType),
input idInvoiceAmountTC (idInvoiceAmountTC),
input idInvoiceAmountLC (idInvoiceAmountLC),
input idInvoiceAmountCC (idInvoiceAmountCC),
input icPostingType (icPostingType),
output vdDebitTC (odDebitTC),
output vdDebitLC (odDebitLC),
output vdDebitCC (odDebitCC),
output vdCreditTC (odCreditTC),
output vdCreditLC (odCreditLC),
output vdCreditCC (odCreditCC),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then do:
if ilHandleCommunicationWithJE = true
then do:
<I-137 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
return.
end.
<M-113 run AddStandardPosting
(input icRowId (icPostingtcRowid),
input icGlCode (icGLCode),
input icDivisionCode (icDivisionCode),
input icCostCentreCode (icCostCentreCode),
input icCIText (icCostCentreText),
input icProjectCode (icProjectCode),
input icCIText (icProjectText),
input icBusinessRelationInterCoCode (icIntercoBusinessRelationCode),
input icCurrencyCode (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 icCIText (icLineText),
input icCIText (icSafText),
input tDefaultSafsCI (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input idExchangeRate (idExchangeRate),
input idExchangeRateScale (idExchangeRateScale),
input idCCExchangeRate (idPostingLineCCRate),
input idCCExchangeRateScale (idPostingLineCCScale),
output viPostingLineId (oiPostingLineId),
input ? (iiSafStructureId),
input ? (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input vtExchangeRateDate (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then do:
if ilHandleCommunicationWithJE = true
then do:
<I-8 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
leave POSTING2BLOCK.
end. /* if viLocalReturnStatus < 0 */
/* I19 requirement for Brazil ============================================================== */
/* Update posting line to control account to contain legal document number filled in */
/* ========================================================================================= */
if ilCInvoiceIsForLegalDoc
then do:
<M-75 run SetPostingLineLegalDocNumber
(input ? (icPostingLineTcRowID),
input viPostingLineId (iiPostingLineID),
input entry(1, icReference) (icLegalDocumentNumber),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then do:
if ilHandleCommunicationWithJE = true
then do:
<I-96 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end.
leave POSTING2BLOCK.
end. /* if viLocalReturnStatus < 0 */
end. /* if ilCInvoiceIsForLegalDoc */
end. /* if icGlCode = "":U */
end. /* if not ilOnlyControlAccount */
if ilHandleCommunicationWithJE = true
then do:
/* ========================================================================================================= */
/* Normally we would here close the communication to BJournalEntry but we will not do it for performance */
/* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it. */
/* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the */
/* appserver that is executed after each call to the appserver */
/* ========================================================================================================= */
/* In the special case BCI:CreareCIPosting2 we need to keep the CloseInstance of BJE in the code as The UI */
/* first opens the BJE-instance, then calls CreateCIPosting, then calls CreateMFPosting and then closes the */
/* BJE-instance. But after calling CreateCIPosting, the UI opens the BJE-instance itself and as such we need */
/* to close the instance in CreateCIPosting (and its sub-methods). */
/* ========================================================================================================= */
<I-17 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
end. /* if ilHandleCommunicationWithJE = true */
if viLocalReturnStatus < 0
then do:
<M-125 run StopExternalInstances (output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
leave POSTING2BLOCK.
end.
if viCIRECPostingLineId <> ? and
viCIRECPostingLineId <> 0
then do:
<M-117 run UpdateCInvoicePosting
(input tCInvoice.tc_Rowid (icCInvoiceRowId),
input iiCInvoiceId (iiCInvoiceId),
input biPostingId (iiPostingId),
input viCIRECPostingLineId (iiCIRECPostingLineId),
input {&INVOICEPOSTINGTYPE-INITIAL} (icCInvoicePostingType),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or
viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viLocalReturnStatus < 0
then leave POSTING2BLOCK.
end.
<M-120 run CreateCIPostingExt
(input iiCInvoiceId (iiCInvoiceId),
input icCInvoiceType (icCInvoiceType),
input idInvoiceAmountTC (idInvoiceAmountTC),
input idInvoiceAmountLC (idInvoiceAmountLC),
input idInvoiceAmountCC (idInvoiceAmountCC),
input icPostingType (icPostingType),
input iiControlPostingLineId (iiControlPostingLineId),
input ilIsInitialStatus (ilIsInitialStatus),
output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
if viFcReturnSuper < 0 or viLocalReturnStatus = 0
then assign viLocalReturnStatus = viFcReturnSuper.
end. /* POSTING2BLOCK */
assign oiReturnStatus = viLocalReturnStatus.