project QadFinancials > class BDInvoice > method CreateDIPostingSales
Parameters
| icGLCode | input | character | |
| icDInvoiceType | input | character | |
| idInvoiceAmountTC | input | decimal | |
| idInvoiceAmountCC | input | decimal | |
| idInvoiceAmountLC | input | decimal | |
| iiCurrencyId | input | integer | |
| icCurrencyCode | input | character | |
| idExchangeRate | input | decimal | |
| idExchangeRateScale | input | decimal | |
| iiDebtorSalesAccountGLProfileId | input | integer | |
| iiDivisionId | input | integer | |
| icDivisionCode | input | character | |
| icCostCentreCode | input | character | |
| icProjectCode | input | character | |
| icDIText | input | character | |
| icPostingType | input | character | |
| ilDInvoiceIsTaxExcluded | input | logical | Tax excluded flag of customer invoice |
| idExchangeRateCC | input | decimal | |
| idExchangeRateScaleCC | input | decimal | |
| itTaxPointDate | input | date | |
| oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bdinvoice.p)
/* ================================================================================================================ */
/* Create posting on Sales account */
/* ================================================================================================================ */
/* which exchange rate date to use? */
if vlCompanyPropertyIsARUseTaxDate = true
then
assign vtExchangeRateDate = itTaxPointDate.
else
assign vtExchangeRateDate = ?.
/* not defined Selas G/L account */
if icGLCode = "":U
then do:
/* cumulate values posting on VAT */
for each tApiDInvoiceVat:
accumulate tApiDInvoiceVat.DInvoiceVatVatDebitTC(TOTAL).
accumulate tApiDInvoiceVat.DInvoiceVatVatCreditTC(TOTAL).
end.
/* calculate remaining value to post */
assign vdDebitTC =
if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoicetype = {&INVOICETYPE-PREPAYMENT}
then 0
else if not ilDInvoiceIsTaxExcluded
then idInvoiceAmountTC - (accum total tApiDInvoiceVat.DInvoiceVatVatDebitTC) + (accum total tApiDInvoiceVat.DInvoiceVatVatCreditTC)
else idInvoiceAmountTC
vdCreditTC =
if icDInvoiceType = {&INVOICETYPE-INVOICE} or icDInvoiceType = {&INVOICETYPE-FINANCECHARGE} or icDInvoiceType = {&INVOICETYPE-INVOICECORRECTION} or icDInvoicetype = {&INVOICETYPE-PREPAYMENT}
then if not ilDInvoiceIsTaxExcluded
then idInvoiceAmountTC - (accum total tApiDInvoiceVat.DInvoiceVatVatCreditTC) + (accum total tApiDInvoiceVat.DInvoiceVatVatDebitTC)
else idInvoiceAmountTC
else 0.
/* recalculate value to post to local currency */
if iiCurrencyId = viCompanyLCId or
icCurrencyCode = vcCompanyLC
then assign vdDebitLC = vdDebitTC
vdCreditLC = vdCreditTC.
else assign vdDebitLC = <M-13 RoundAmount
(input vdDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>
vdCreditLC = <M-14 RoundAmount
(input vdCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>.
if idInvoiceAmountCC <> 0 and idInvoiceAmountCC <> ? then
do:
if viCompanyCCId = viCompanyLCId or
vcCompanyCC = vcCompanyLC
then assign vdDebitCC = vdDebitLC
vdCreditCC = vdCreditLC.
else
if viCompanyCCId = iiCurrencyId or
vcCompanyCC = icCurrencyCode
then assign vdDebitCC = vdDebitTC
vdCreditCC = vdCreditTC.
else
do:
assign vdExRateCC = idInvoiceAmountLC / idInvoiceAmountCC
vdExRateScaleCC = 1
vdDebitCC = <M-17 RoundAmount
(input vdDebitLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDInvoice>
vdCreditCC = <M-18 RoundAmount
(input vdCreditLC / (vdExRateCC * vdExRateScaleCC) (idUnroundedAmount),
input viCompanyCCId (iiCurrencyID),
input vcCompanyCC (icCurrencyCode)) in BDInvoice>.
end.
end. /* if idInvoiceAmountCC <> 0 and idInvoiceAmountCC <> ? then */
/* if Sales G/L account not known already, try to find sales G/L account */
if not can-find(first tDIAccount)
then do:
<Q-12 run ProfileLinkByGL (all) (Read) (NoCache)
(input iiDebtorSalesAccountGLProfileId, (GlProfileId)
input tDInvoice.Company_ID, (CompanyId)
output dataset tqProfileLinkByGL) in BProfile >
find first tqProfileLinkByGL no-error.
if available tqProfileLinkByGL
then do:
create tDIAccount.
assign tDIAccount.tiGLId = tqProfileLinkByGL.tiGL_ID
tDIAccount.tcGLCode = tqProfileLinkByGL.tcGLCode
tDIAccount.tdAmountDebitTC = vdDebitTC
tDIAccount.tdAmountCreditTC = vdCreditTC.
end.
else do:
<M-2 run CreateDIPostingSetMessage
(input trim(subst(#T-11'The specified sales account GL profile (ID = &1) is not defined in the system.':150(32021)T-11#, iiDebtorSalesAccountGLProfileId)) (icMessage),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
assign oiReturnStatus = -1.
return.
end.
end.
/* Set Sales amount to post - if there is only one sales posting, whole amount is posted on this account */
for each tDIAccount
break by tDIAccount.tcGLCode:
if first(tDIAccount.tcGLCode) and last(tDIAccount.tcGLCode)
then assign tDIAccount.tdAmountDebitTC = vdDebitTC
tDIAccount.tdAmountCreditTC = vdCreditTC.
end.
/* do posting on sales accounts */
for each tDIAccount:
/* calculate posting amount in local currency */
if icCurrencyCode = vcCompanyLC
then assign vdDebitLC = tDIAccount.tdAmountDebitTC
vdCreditLC = tDIAccount.tdAmountCreditTC.
else assign vdDebitLC = <M-15 RoundAmount
(input tDIAccount.tdAmountDebitTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>
vdCreditLC = <M-16 RoundAmount
(input tDIAccount.tdAmountCreditTC * idExchangeRate * idExchangeRateScale (idUnroundedAmount),
input viCompanyLCId (iiCurrencyID),
input vcCompanyLC (icCurrencyCode)) in business>.
<M-3 run CreateDIPostingGLAccount (input tDIAccount.tcGLCode (icGLCode),
input iiDivisionId (iiDivisionId),
input-output icDivisionCode (bcDivisionCode),
output vlGLIsDivisionAccount (olGLIsDivisionAcount),
input-output icCostCentreCode (bcCostCentreCode),
input-output icProjectCode (bcProjectCode),
output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
<I-4 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
/* if CC amount is not filled yet, assign it to ? to make sure it is generated automatically */
if vdDebitCC = 0 and vdCreditCC = 0
then assign vdDebitCC = ?
vdCreditCC = ?.
<M-5 run AddStandardPosting
(input vcPostingHeaderRowId (icPostingtcRowid),
input tDIAccount.tcGLCode (icGLCode),
input if vlGLIsDivisionAccount then icdivisionCode else '':U (icDivisionCode),
input icCostCentreCode (icCostCentreCode),
input icDIText (icCostCentreText),
input icProjectCode (icProjectCode),
input icDIText (icProjectText),
input vcDBusinessRelationInterCoCode (icIntercoBusinessRelationCode),
input icCurrencyCode (icCurrencyCode),
input tDIAccount.tdAmountDebitTC (idDebitTC),
input vdDebitLC (idDebitLC),
input vdDebitCC (idDebitCC),
input ? (idDebitPC),
input tDIAccount.tdAmountCreditTC (idCreditTC),
input vdCreditLC (idCreditLC),
input vdCreditCC (idCreditCC),
input ? (idCreditPC),
input 0 (idQty),
input icDIText (icLineText),
input icDIText (icSafText),
input tDefaultSafsDI (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input idExchangeRate (idExchangeRate),
input idExchangeRateScale (idExchangeRateScale),
input idExchangeRateCC (idPostingLineCCRate),
input idExchangeRateScaleCC (idPostingLineCCScale),
output viDummy (oiPostingLineId),
input ? (iiSafStructureId),
input ? (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input vtExchangeRateDate (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
<I-6 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
end.
end.
/* Sales G/L account send to this procerute as paramter, make whole posting on it */
else do:
<M-7 run CreateDIPostingCalculateAmounts
(input no (ilIsDebtorControlAccount),
input icDInvoiceType (icDInvoiceType),
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 BDInvoice>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
<I-8 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
<M-9 run AddStandardPosting
(input vcPostingHeaderRowId (icPostingtcRowid),
input icGLCode (icGLCode),
input icDivisionCode (icDivisionCode),
input icCostCentreCode (icCostCentreCode),
input icDIText (icCostCentreText),
input icProjectCode (icProjectCode),
input icDIText (icProjectText),
input vcDBusinessRelationInterCoCode (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 icDIText (icLineText),
input icDIText (icSafText),
input tDefaultSafsDI (tDefaultSafs),
input {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateType),
input idExchangeRate (idExchangeRate),
input idExchangeRateScale (idExchangeRateScale),
input idExchangeRateCC (idPostingLineCCRate),
input idExchangeRateScaleCC (idPostingLineCCScale),
output viDummy (oiPostingLineId),
input ? (iiSafStructureId),
input ? (icSafStructureCode),
input ? (icAllocationKey),
input false (ilLinkedCrCyDaemonReqExists),
input vtExchangeRateDate (itExchangeRateDate),
output viFcReturnSuper (oiReturnStatus)) in BJournalEntry>
if viFcReturnSuper < 0 or
oiReturnStatus = 0
then assign oiReturnStatus = viFcReturnSuper.
if oiReturnStatus < 0
then do:
<I-10 {bFcCloseInstance
&CLASS = "BJournalEntry"}>
return.
end.
end. /* Sales G/L account send to this procerute as paramter, make whole posting on it */