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-CREDITORPAYMENT}
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 Supplier payment by Division, this calculated CC rate is used on PIP account */
assign viCDocumentId = ?
vlIsCrossCompany = false.
for each PostingLine of Posting no-lock:
if PostingLine.CrossCompanyPostingLine_ID <> 0 and
PostingLine.CrossCompanyPostingLine_ID <> ?
then assign vlIsCrossCompany = true.
for first CDocumentPostingLine of PostingLine no-lock:
assign viCDocumentId = CDocumentPostingLine.CDocument_ID.
end. /* for first CDocumentPostingLine of PostingLine no-lock */
end. /* for each PostingLine of Posting no-lock */
/* ======================================================================= *
* 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
(viCDocumentId = ? or viCDocumentId = 0)
then do:
<M-23 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 vlIsCrossCompany = true and */
if viCDocumentId = ? or viCDocumentId = 0
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForCDocument - Cannot find CDocument of Posting &1/&2/&3", Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end. /* if viCDocumentId = ? or viCDocumentId = 0 */
empty temp-table tDocumentByDivision.
/* If there are no links from CDocument to the invoices then we cannot process this posting like a CDoc-posting */
if not can-find (first CDocumentInvoiceXref where
CDocumentInvoiceXref.CDocument_ID = viCDocumentId)
then leave STATCURRBLOCK.
for each CDocumentInvoiceXref where
CDocumentInvoiceXref.CDocument_ID = viCDocumentId no-lock,
first CInvoice of CDocumentInvoiceXref no-lock:
find first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = viCDocumentId and
tDocumentByDivision.tiDivisionId = CInvoice.Division_ID no-error.
if not available tDocumentByDivision
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDocumentId = viCDocumentId
tDocumentByDivision.tiDivisionId = CInvoice.Division_ID
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = 0
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = 0.
end. /* if not available tDocumentByDivision */
assign vdCDocumentInvoiceXrefPayTC = CDocumentInvoiceXref.CDocumentInvoiceXrefAlloTC
- CDocumentInvoiceXref.CDocumentInvoiceXrefDiscTC
- CDocumentInvoiceXref.CDocumentInvoiceXrefWhtAmtT
vdCDocumentInvoiceXrefPayCC = <M-80 RoundSCAmount (input vdCDocumentInvoiceXrefPayTC * CInvoice.CInvoiceCCRate * CInvoice.CInvoiceCCScale (idUnroundedAmount)) in TSetStatutoryCurrency>
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = tDocumentByDivision.tdDocumentInvoiceXrefPayCC + vdCDocumentInvoiceXrefPayCC
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = tDocumentByDivision.tdDocumentInvoiceXrefPayTC + vdCDocumentInvoiceXrefPayTC.
end. /* for each CDocumentInvoiceXref 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 CInvoiceMovement of PostingLine no-lock,
first CInvoice of CInvoiceMovement no-lock:
<M-91 run PostingLineCCUpdate
(input CInvoice.CInvoiceCCRate (idCCRate),
input CInvoice.CInvoiceCCScale (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 CInvoiceMovement 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-CDOC}
then do:
for first CDocumentPostingLine of PostingLine no-lock:
/* PIP account has division */
if PostingLine.Division_ID <> 0 and PostingLine.Division_ID <> ?
then do:
find tDocumentByDivision where
tDocumentByDivision.tiDocumentId = CDocumentPostingLine.CDocument_ID and
tDocumentByDivision.tiDivisionId = PostingLine.Division_ID no-error.
if not available tDocumentByDivision
then find tDocumentByDivision where
tDocumentByDivision.tiDocumentId = CDocumentPostingLine.CDocument_ID and
(tDocumentByDivision.tiDivisionId = 0 or
tDocumentByDivision.tiDivisionId = ?)
no-error.
if not available tDocumentByDivision
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForCDocument - Cannot find record for tCDocumentByDivision for Division &1 for posting &2/&3/&4", PostingLine.Division_ID, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end. /* if not available tDocumentByDivision */
<M-93 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 CDocument where
CDocument.CDocument_ID = viCDocumentId
no-lock no-error.
if not available CDocument
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForCDocument - Cannot find record for CDocument for Document &1 for posting &1/&2/&3", viCDocumentId, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end. /* if not available CDocument */
<M-28 run PostingLineCCUpdate
(input CDocument.CDocumentCCRate (idCCRate),
input CDocument.CDocumentCCScale (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 CDocumentPostingLine 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-38 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.