project QadFinancials > class BVAT > method CalculateTax
Description
Calculate the tax amounts to post, based on an input amount with or without tax
Parameters
ilStartAndOpenPGTM | input | logical | |
icCurrencyCode | input | character | Tax Currency Code |
icTransactionType | input | character | Transaction Type |
icDocumentReference | input | character | Document Reference : invoice number, voucher number, ... |
icDocumentNumber | input | character | Document Number : eg po number, payment number, ... |
ilTaxIsIncluded | input | logical | is the Amount with taxes or without ? |
itTaxPointDate | input | date | tax point date |
itPostingDate | input | date | posting date |
icTaxEnvCode | input | character | Tax Environment |
icFromTaxZoneCode | input | character | From Tax Zone : Tax zone of the company or tax zone of default site of creditor/debtor |
icToTaxZoneCode | input | character | To Tax Zone : Tax Zone of creditor/debtor or Tax Zone of ship-to site of Invoice |
icTaxClassCode | input | character | Tax Class |
icTaxUsageCode | input | character | Tax Usage |
idAmountTC | input | decimal | Amount TC : invoice amount with or without taxes, you can indicate that by setting the input parameter ilTaxIsIncluded |
idExchangeRateScale | input | decimal | Scale factor of the exchange rate |
idExchangeRate | input | decimal | exchange rate |
icCompanyCode | input | character | Company code of the invoice |
icPaymentCondition | input | character | Payment condition : necessary to get the discount percentage |
ilIsTaxInCityFromCompany | input | logical | In city flag from the Headoffice address of the company |
ilIsTaxInCityFromShipTo | input | logical | In city flag from the headoffice address of the ship to |
ilIsTaxable | input | logical | Taxable flag |
idAdjustmentFactor | input | decimal | Adjustment Factor |
iiShipToAddressID | input | integer | |
iiShipFromAddressID | input | integer | |
icCustomerCode | input | character | |
icInvoiceType | input | character | |
tTaxDetail | input-output | temp-table | output records with all tax lines to post in it |
tTaxParametersExtVAT | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program7/bvat.p)
assign
viLocalReturnStatus = 0
oiReturnStatus = -98.
/* replace unknown values */
if icCurrencyCode = ? then assign icCurrencyCode = "":U.
if icTransactionType = ? then assign icTransactionType = "":U.
if icDocumentReference = ? then assign icDocumentReference = "":U.
if icDocumentNumber = ? then assign icDocumentNumber = "":U.
if icTaxEnvCode = ? then assign icTaxEnvCode = "":U.
if icFromTaxZoneCode = ? then assign icFromTaxZoneCode = "":U.
if icToTaxZoneCode = ? then assign icToTaxZoneCode = "":U.
if icTaxClassCode = ? then assign icTaxClassCode = "":U.
if icTaxUsageCode = ? then assign icTaxUsageCode = "":U.
if idAmountTC = ? then assign idAmountTC = 0.
if idExchangeRateScale = ? then assign idExchangeRateScale = 0.
if icCompanyCode = ? then assign icCompanyCode = "":U.
if icPaymentCondition = ? then assign icPaymentCondition = "":U.
if idAdjustmentFactor = ? then assign idAdjustmentFactor = 1.
/* Retrieve percentage of the discount associtated with the payment condition */
if icPaymentCondition <> "":U
then do:
<Q-1 run PaymentConditionByIdCode (all) (Read) (NoCache)
(input ?, (PaymentConditionId)
input icPaymentCondition, (PaymentConditionCode)
output dataset tqPaymentConditionByIdCode) in BPaymentCondition>
find first tqPaymentConditionByIdCode where
tqPaymentConditionByIdCode.tcPaymentConditionCode = icPaymentCondition
no-error.
if available tqPaymentConditionByIdCode
then do:
if tqPaymentConditionByIdCode.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL}
then assign vdPercentage = tqPaymentConditionByIdCode.tdPaymentConditionPercentage.
else do:
/* When the payment condition is staged payment, total percentage is calcualted as *
* weighted avarage of the stages */
<Q-39 run PaymentConditionStagedByPC (all) (Read) (NoCache)
(input tqPaymentConditionByIdCode.tiPaymentCondition_ID, (ParentPaymentConditionID)
output dataset tqPaymentConditionStagedByPC) in BPaymentCondition>
for each tqPaymentConditionStagedByPC where
tqPaymentConditionStagedByPC.tiParentPaymentCondition_ID = tqPaymentConditionByIdCode.tiPaymentCondition_ID:
assign vdPercentage = vdPercentage
+ tqPaymentConditionStagedByPC.tdPaymentConditionStagedPerc / 100 * tqPaymentConditionStagedByPC.tdPaymentConditionPercentage.
end. /* for each tqPaymentConditionStagedByPC where */
end. /* else if tqPaymentConditionByIdCode.tcPaymentConditionPaymentTyp = {&PAYMENTCONDITIONPAYMENTTYPE-NORMAL} */
end. /* if available tqPaymentConditionByIdCode */
end. /* if icPaymentCondition <> "":U */
/* get the ship-to address details */
if (iiShipToAddressID <> ? and iiShipToAddressID <> 0)
then do:
<Q-65 run AddressByIdByCode (all) (Read) (Cache)
(input ?, (AddressCity)
input ?, (AddressStreet1)
input ?, (AddressStreet2)
input ?, (AddressZip)
input ?, (AddressTypeCode)
input iiShipToAddressID, (AddressID)
input ?, (BusinessRelationID)
input ?, (BusinessRelationCode)
input ?, (AddressTypeID)
input ?, (AddressStreet3)
output dataset tqAddressByIdByCode) in BBusinessRelation>
find first tqAddressByIdByCode where
tqAddressByIdByCode.tiAddress_ID = iiShipToAddressID
no-error.
if available tqAddressByIdByCode
then do :
assign
vcShipToAddrStreet1 = tqAddressByIdByCode.tcAddressStreet1
vcShipToAddrStreet2 = tqAddressByIdByCode.tcAddressStreet2
vcShipToAddrStreet3 = tqAddressByIdByCode.tcAddressStreet3
vcShipToAddrCity = tqAddressByIdByCode.tcAddressCity
vcShipToAddrState = tqAddressByIdByCode.tcAddressState
vcShipToAddrZip = tqAddressByIdByCode.tcAddressZip
vcShipToAddrCountry = tqAddressByIdByCode.tcCountryCode
vcShipToAddrCountry = tqAddressByIdByCode.tcCountyCode.
end. /* if available tqAddressByIdByCode */
else do:
assign
vcShipToAddrStreet1 = ""
vcShipToAddrStreet2 = ""
vcShipToAddrStreet3 = ""
vcShipToAddrCity = ""
vcShipToAddrState = ""
vcShipToAddrZip = ""
vcShipToAddrCountry = ""
vcShipToAddrCountry = "".
end. /* else */
end. /* if (iiShipToAddressID <> ? and */
<Q-74 run CompanyPrim (all) (Read) (NoCache)
(input ?, (LookupCompanyId)
input icCompanyCode, (CompanyCode)
output dataset tqCompanyPrim) in BCompany>
find first tqCompanyPrim where
tqCompanyPrim.tcCompanyCode = icCompanyCode
no-error.
if available tqCompanyPrim
then assign viCompanyId1 = tqCompanyPrim.tiCompany_ID.
<Q-35 run CompanyBusinessRelation (all) (Read) (NoCache)
(input viCompanyId1, (CompanyId)
output dataset tqCompanyBusinessRelation) in BCompany>
find first tqCompanyBusinessRelation where
tqCompanyBusinessRelation.tiCompany_ID = viCompanyId1
no-error.
if available tqCompanyBusinessRelation
then assign vcShipToCode = tqCompanyBusinessRelation.tcBusinessRelationCode.
assign icCustomerCode = icCustomerCode + "|":U + vcShipToCode.
if ilStartAndOpenPGTM
then do:
<I-5 {bFcStartAndOpenInstance
&CLASS = "PGTM"}>
end.
/* Call CalculateTax... */
<M-4 run CalculateTaxByParam
(input icCurrencyCode (icCurrencyCode),
input icTransactionType (icTransactionType),
input icDocumentReference (icDocumentReference),
input icDocumentNumber (icDocumentNumber),
input ilIsTaxable (ilTaxable),
input ilTaxIsIncluded (ilTaxIsIncluded),
input itTaxPointDate (itTaxPointDate),
input itPostingDate (itPostingDate),
input icTaxEnvCode (icTaxEnvCode),
input icFromTaxZoneCode (icFromTaxZoneCode),
input icToTaxZoneCode (icToTaxZoneCode),
input icTaxClassCode (icTaxClassCode),
input icTaxUsageCode (icTaxUsageCode),
input idAmountTC (idAmountTC),
input idExchangeRateScale (idExchangeRateScale),
input idExchangeRate (idExchangeRate),
input icCompanyCode (icCompanyCode),
input idAdjustmentFactor (idAdjustmentFactor),
input vdPercentage (idPaymentConditionPercentage),
input ilIsTaxInCityFromCompany (ilIsTaxInCityFromCompany),
input ilIsTaxInCityFromShipTo (ilIsTaxInCityFromShipTo),
input iiShipToAddressID (iiShipToAddressID),
input iiShipFromAddressID (iiShipFromAddressID),
input vcShipToAddrStreet1 (icShipToAddrLine1),
input vcShipToAddrStreet2 (icShipToAddrLine2),
input vcShipToAddrStreet3 (icShipToAddrLine3),
input vcShipToAddrCity (icShipToAddrCity),
input vcShipToAddrState (icShipToAddrState),
input vcShipToAddrZip (icShipToAddrZip),
input vcShipToAddrCountry (icShipToAddrCountry),
input vcShipToAddrCounty (icShipToAddrCounty),
input icCustomerCode (icCustomerCode),
input false (ilIsAvataxCommit),
input icInvoiceType (icInvoiceType),
output tTaxParametersExtVAT (tTaxParametersExtended),
input-output tTaxDetail (tTaxDetailDataExt),
output viLocalReturnStatus (oiReturnStatus)) in PGTM>
if viLocalReturnStatus < 0 or (viLocalReturnStatus > 0 and oiReturnStatus = -98)
then assign oiReturnStatus = viLocalReturnStatus.
if ilStartAndOpenPGTM
then do:
<I-12 {bFcCloseAndStopInstance
&CLASS = "PGTM"}>
end.
if oiReturnStatus = -98 then assign oiReturnStatus = 0.