Description
Assign the Statutory Currency amounts based on the amounts in TC and the exchange rate between TC and the newly entered SC.
Parameters
biPostingLineCounter | input-output | integer | |
olPostingIsProcessed | output | logical | |
ocPostCCBalanceTo | output | character | |
ocErrorMessage | output | character | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program1/tsetstatutorycurrency.p)
assign oiReturnStatus = -98
viLocalReturnStatus = 0
olPostingIsProcessed = false
ocPostCCBalanceTo = ?.
STATCURRBLOCK:
do on error undo, return:
/* Check if this posting is related to supplier payment */
if Journal.JournalTypeCode <> {&JOURNALTYPE-DEBTORPAYMENT}
then leave STATCURRBLOCK.
/* Assign type of GL account to be used for posting of any SC balances */
assign ocPostCCBalanceTo = {&GLSYSTEMTYPE-ROUND}.
/* Calculate allocated amount of the Customer payment by Division, this calculated CC rate is used on PIP account */
assign viDDocumentId = ?
vlIsCrossCompany = false.
for each PostingLine of Posting no-lock:
if PostingLine.CrossCompanyPostingLine_ID <> 0 and
PostingLine.CrossCompanyPostingLine_ID <> ?
then assign vlIsCrossCompany = true.
for first DDocumentPostingLine of PostingLine no-lock:
assign viDDocumentId = DDocumentPostingLine.DDocument_ID.
end.
end.
/* ======================================================================= *
* If this is cross company posting and there is not payment linked to it, *
* then this is the counterpart posting with 2 lines only. One for inv *
* movement and second for Cross company account *
* In this case exchange rate is used in both cases from the Invoice *
* ======================================================================= */
if vlIsCrossCompany = true and
(viDDocumentId = ? or viDDocumentId = 0)
then do:
<M-14 run PostingForCrossCompanyCounterPart
(input-output biPostingLineCounter (biPostingLineCounter),
output olPostingIsProcessed (olPostingIsProcessed),
output ocPostCCBalanceTo (ocPostCCBalanceTo),
output vcTempErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
assign vlIsPostingLineProcessed = true.
leave STATCURRBLOCK.
end.
if viDDocumentId = ? or viDDocumentId = 0
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForDDocument - Cannot find DDocument of Posting &1/&2/&3", Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end.
empty temp-table tDocumentByDivision.
/* If there are no links from DDocument to the invoices then we cannot process this posting like a DDoc-posting */
if not can-find (first DDocumentInvoiceXref where
DDocumentInvoiceXref.DDocument_ID = viDDocumentId)
then leave STATCURRBLOCK.
for each DDocumentInvoiceXref where
DDocumentInvoiceXref.DDocument_ID = viDDocumentId no-lock,
first DInvoice of DDocumentInvoiceXref no-lock:
find first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = viDDocumentId and
tDocumentByDivision.tiDivisionId = DInvoice.Division_ID no-error.
if not available tDocumentByDivision
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDivisionId = DInvoice.Division_ID
tDocumentByDivision.tiDocumentId = viDDocumentId
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = 0
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = 0.
end.
assign vdDDocumentInvoiceXrefPayTC = DDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
- DDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
vdDDocumentInvoiceXrefPayCC = <M-76 RoundSCAmount (input vdDDocumentInvoiceXrefPayTC * DInvoice.DInvoiceCCRate * DInvoice.DInvoiceCCScale (idUnroundedAmount)) in TSetStatutoryCurrency>
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = tDocumentByDivision.tdDocumentInvoiceXrefPayCC + vdDDocumentInvoiceXrefPayCC
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = tDocumentByDivision.tdDocumentInvoiceXrefPayTC + vdDDocumentInvoiceXrefPayTC.
end. /* for each DDocumentInvoiceXref where */
/* Go through all posting lines of the posting */
for each PostingLine of Posting exclusive-lock,
first GL of PostingLine no-lock,
first GLType of GL no-lock:
/* If the posting contains Bank GL account, any balance in the CC will be posted to ralized gain/loss */
if GLType.GLTypeCode = {&GLTYPECODE-BANK}
then assign ocPostCCBalanceTo = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT}.
assign biPostingLineCounter = biPostingLineCounter + 1.
assign vlIsPostingLineProcessed = false.
/* Check, if the posting is created for Supplier Invoice movement, if yes, take exchange rate of the invoice */
if not vlIsPostingLineProcessed
then do:
for first DInvoiceMovement of PostingLine no-lock,
first DInvoice of DInvoiceMovement no-lock:
<M-15 run PostingLineCCUpdate
(input DInvoice.DInvoiceCCRate (idCCRate),
input DInvoice.DInvoiceCCScale (idCCRateScale),
output vcTempErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave STATCURRBLOCK.
assign vlIsPostingLineProcessed = true.
end. /* for first DInvoiceMovement of PostingLine no-lock, */
end. /* if not vlIsPostingLineProcessed */
/* Check, if the posting is created for Payment In Process account */
if not vlIsPostingLineProcessed and
GLType.GLTypeCode = {&GLTYPECODE-DDOC}
then do:
for first DDocumentPostingLine of PostingLine no-lock:
/* PIP account has division */
if PostingLine.Division_ID <> 0 and PostingLine.Division_ID <> ?
then do:
find tDocumentByDivision where
tDocumentByDivision.tiDivisionId = PostingLine.Division_ID no-error.
if not available tDocumentByDivision
then find tDocumentByDivision where
tDocumentByDivision.tiDivisionId = 0 or
tDocumentByDivision.tiDivisionId = ?
no-error.
if not available tDocumentByDivision
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForDDocument - Cannot find record for tCDocumentByDivision for Division &1 for posting &1/&2/&3", PostingLine.Division_ID, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end. /* if not available tDocumentByDivision */
<M-87 run PostingLineCCUpdate
(input tDocumentByDivision.tdDocumentInvoiceXrefPayCC / tDocumentByDivision.tdDocumentInvoiceXrefPayTC (idCCRate),
input 1 (idCCRateScale),
output vcTempErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave STATCURRBLOCK.
assign vlIsPostingLineProcessed = true.
end. /* if PostingLine.Division_ID <> 0 or PostingLine.Division_ID <> ? */
/* PIP account has not division */
else do:
Find DDocument where
DDocument.DDocument_ID = viDDocumentId
no-lock no-error.
if not available DDocument
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForDDocument - Cannot find record for DDDocument for Document &1 for posting &1/&2/&3", viDDocumentId, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end. /* if not available DDocument */
<M-94 run PostingLineCCUpdate
(input DDocument.DDocumentCCRate (idCCRate),
input DDocument.DDocumentCCScale (idCCRateScale),
output vcTempErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave STATCURRBLOCK.
assign vlIsPostingLineProcessed = true.
end.
end. /* for first DDocumentPostingLine of PostingLine no-lock: */
end. /* if not vlIsPostingLineProcessed */
/* In all other cases just use SC exchange rate of the date of posting, even we know it is not perfect (like for discounts) */
if not vlIsPostingLineProcessed
then do:
<M-92 run PostingLineCCUpdate
(input ? (idCCRate),
input ? (idCCRateScale),
output vcTempErrorMessage (ocErrorMessage),
output viFcReturnSuper (oiReturnStatus)) in TSetStatutoryCurrency>
assign ocErrorMessage = ocErrorMessage + vcTempErrorMessage.
if viFcReturnSuper <> 0 then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0 then leave STATCURRBLOCK.
assign vlIsPostingLineProcessed = true.
end. /* if not vlIsPostingLineProcessed */
end. /* PostingLine */
assign olPostingIsProcessed = true.
end. /* STATCURRBLOCK */
assign oiReturnStatus = viLocalReturnStatus.