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)
define buffer bDocumentByDivision for tDocumentByDivision.
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-BANKINGENTRY} and
Journal.JournalTypeCode <> {&JOURNALTYPE-CASHENTRY}
then leave STATCURRBLOCK.
/* Assign type of GL account to be used for posting of any SC balances */
assign ocPostCCBalanceTo = {&GLSYSTEMTYPE-EXCHANGEREALPROFIT}.
/* =========================================================================================================================== */
/* Calculate allocated amount of the Supplier and Customer payment by Division, this calculated CC rate is used on PIP account */
/* =========================================================================================================================== */
empty temp-table tDocumentByDivision.
/* Create list of all Payments paied by this Banking/Cash Entry */
for each PostingLine of Posting where
PostingLine.Division_ID <> ? and
PostingLine.Division_ID <> 0 no-lock:
find first CDocumentPostingLine of PostingLine no-lock no-error.
if available CDocumentPostingLine
then do:
if not can-find(first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = CDocumentPostingLine.CDocument_ID and
tDocumentByDivision.tiDivisionId = -1)
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDocumentId = CDocumentPostingLine.CDocument_ID
tDocumentByDivision.tiDivisionId = -1.
end.
next.
end.
find first DDocumentPostingLine of PostingLine no-lock no-error.
if available DDocumentPostingLine
then do:
if not can-find(first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = DDocumentPostingLine.DDocument_ID and
tDocumentByDivision.tiDivisionId = -1)
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDocumentId = DDocumentPostingLine.DDocument_ID
tDocumentByDivision.tiDivisionId = -1.
end.
next.
end.
end.
/* Go throuth all allocated documents and calculate allocated amount per division */
for each bDocumentByDivision where
bDocumentByDivision.tiDivisionId = -1:
for each CDocumentInvoiceXref where
CDocumentInvoiceXref.CDocument_ID = bDocumentByDivision.tiDocumentId no-lock,
first CInvoice of CDocumentInvoiceXref no-lock:
find first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = bDocumentByDivision.tiDocumentId and
tDocumentByDivision.tiDivisionId = CInvoice.Division_ID no-error.
if not available tDocumentByDivision
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDivisionId = CInvoice.Division_ID
tDocumentByDivision.tiDocumentId = bDocumentByDivision.tiDocumentId
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = 0
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = 0.
end.
assign vdDocumentInvoiceXrefPayTC = CDocumentInvoiceXref.CDocumentInvoiceXrefAlloTC
- CDocumentInvoiceXref.CDocumentInvoiceXrefDiscTC
- CDocumentInvoiceXref.CDocumentInvoiceXrefWhtAmtT
vdDocumentInvoiceXrefPayCC = <M-33 RoundSCAmount (input vdDocumentInvoiceXrefPayTC * CInvoice.CInvoiceCCRate * CInvoice.CInvoiceCCScale (idUnroundedAmount)) in TSetStatutoryCurrency>
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = tDocumentByDivision.tdDocumentInvoiceXrefPayCC + vdDocumentInvoiceXrefPayCC
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = tDocumentByDivision.tdDocumentInvoiceXrefPayTC + vdDocumentInvoiceXrefPayTC.
end. /* for each CDocumentInvoiceXref where */
for each DDocumentInvoiceXref where
DDocumentInvoiceXref.DDocument_ID = bDocumentByDivision.tiDocumentId no-lock,
first DInvoice of DDocumentInvoiceXref no-lock:
find first tDocumentByDivision where
tDocumentByDivision.tiDocumentId = bDocumentByDivision.tiDocumentId and
tDocumentByDivision.tiDivisionId = DInvoice.Division_ID no-error.
if not available tDocumentByDivision
then do:
create tDocumentByDivision.
assign tDocumentByDivision.tiDivisionId = DInvoice.Division_ID
tDocumentByDivision.tiDocumentId = bDocumentByDivision.tiDocumentId
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = 0
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = 0.
end.
assign vdDocumentInvoiceXrefPayTC = DDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC
- DDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC
vdDocumentInvoiceXrefPayCC = <M-80 RoundSCAmount (input vdDocumentInvoiceXrefPayTC * DInvoice.DInvoiceCCRate * DInvoice.DInvoiceCCScale (idUnroundedAmount)) in TSetStatutoryCurrency>
tDocumentByDivision.tdDocumentInvoiceXrefPayCC = tDocumentByDivision.tdDocumentInvoiceXrefPayCC + vdDocumentInvoiceXrefPayCC
tDocumentByDivision.tdDocumentInvoiceXrefPayTC = tDocumentByDivision.tdDocumentInvoiceXrefPayTC + vdDocumentInvoiceXrefPayTC.
end. /* for each DDocumentInvoiceXref where */
end. /* for each bDocumentByDivision where */
/* Go through all posting lines of the posting */
for each PostingLine of Posting exclusive-lock:
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-25 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 DInvoiceMovement of PostingLine no-lock, */
end. /* if not vlIsPostingLineProcessed */
/* Check, if the posting is created for Customer 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-91 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
then do:
for first CDocumentPostingLine of PostingLine no-lock,
first CDocument of CDocumentPostingLine 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 do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForBankCashEntry - Cannot find record for tDocumentByDivision for Division &1 for posting &1/&2/&3", PostingLine.Division_ID, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end.
<M-49 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:
<M-4 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 DDocumentPostingLine of PostingLine no-lock: */
end. /* if not vlIsPostingLineProcessed */
/* Check, if the posting is created for Payment In Process account */
if not vlIsPostingLineProcessed
then do:
for first DDocumentPostingLine of PostingLine no-lock,
first DDocument of DDocumentPostingLine no-lock:
/* PIP account has division */
if PostingLine.Division_ID <> 0 and PostingLine.Division_ID <> ?
then do:
find tDocumentByDivision where
tDocumentByDivision.tiDocumentId = DDocumentPostingLine.DDocument_ID and
tDocumentByDivision.tiDivisionId = PostingLine.Division_ID no-error.
if not available tDocumentByDivision
then do:
assign ocErrorMessage = subst("TSetStatutoryCurrency.PostingForBankCashEntry - Cannot find record for tDocumentByDivision for Division &1 for posting &1/&2/&3", PostingLine.Division_ID, Posting.PostingYear, Journal.JournalCode, Posting.PostingVoucher).
oiReturnStatus = -1.
return.
end.
<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:
<M-28 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-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.