|
FOROS PROFESIONALES WINDEV, WEBDEV y WINDEV Mobile |
| | | | | |
Inicio → WINDEV 25 → OBTER O VALOR DO EURO DO DIA + VET E CALCULAR OS PREÇOS DE UM JSON EM EUROS PARA REAIS COM OS DEVIDOS IMPOSTOS E TAXAS |
OBTER O VALOR DO EURO DO DIA + VET E CALCULAR OS PREÇOS DE UM JSON EM EUROS PARA REAIS COM OS DEVIDOS IMPOSTOS E TAXAS |
Iniciado por Boller, 08,feb. 2025 22:45 - No hay respuesta |
| |
| | | |
|
| |
Miembro registrado 4.521 mensajes |
|
Publicado el 08,febrero 2025 - 22:45 |

// API URL CALCULA EURO DO DIA VET EM LISTA JSON DE PRODUTOS PCSOFT
sAPI_URL_EURO is string = "https://economia.awesomeapi.com.br/json/last/USD-BRL,EUR-BRL,BTC-BRL"
// Fetch exchange rate data IF HTTPRequest(sAPI_URL_EURO) = False THEN Error("Error fetching exchange rate data.") RETURN -1 // Return an error value END
// Get API response sResponse1 is string = HTTPGetResult()
// Parse JSON response jsExchangeData is Variant = JSONToVariant(sResponse1)
// Validate response structure IF Length(jsExchangeData) = 0 Error("Invalid exchange rate response.") RETURN -1 END
// Get the Euro exchange rate nEuroRate is numeric = Val(jsExchangeData.EURBRL.bid) + 0.3 // Adding 30 CENTAVOS VET
// Display result (optional) Info("Euro exchange rate (BRL): " + NumToString(nEuroRate, "2.2f"))
// API URL sAPI_URL is string = "https://distri.pcsoft.fr/api/v0.2/products…"
sResponse2 is string
// Fetch API data RES is boolean = HTTPRequest(sAPI_URL) IF ErrorOccurred THEN Error("Error fetching data from PCSOFT API.") RETURN -1 ELSE sResponse2 = HTTPGetResult() END
// Parse JSON response arrProducts is Variant = JSONToVariant(sResponse2)
// Validate response structure IF arrProducts..Count = 0 Error("Invalid response format from API.") RETURN -1 ELSE // Currency exchange rate (Example: 1 EUR = 5.98 BRL) nEuroRate // IOF tax for international purchases (Example: 0,0683) nIOFTax is numeric = 0.0683 // Constants nFreight is numeric = 100 // EUR freight for Full Edition nSedex is numeric = 200 // BRL for shipping // Array to store converted product prices arrConvertedProducts is Variant // Process each product FOR EACH jsProduct OF arrProducts // Extract relevant values nPriceEuro is numeric = jsProduct.Price_Standard // Initialize calculation variables nGrossValueBRL is numeric = 0 nIOFValue is numeric = 0 nTotal is numeric = 0 nTotalWithInvoice is numeric = 0 nFinalFreight is numeric = 0 nFinalSedex is numeric = 0 nAlfandega is numeric = 0 nPriceEuroWithFreight is numeric = 0 // Check if product is an UPGRADE version IF Position(Upper(jsProduct.Description), "UPGRADE") > 0 THEN // Upgrade pricing calculation nGrossValueBRL = nPriceEuro * nEuroRate nIOFValue = nGrossValueBRL * nIOFTax nTotal = nGrossValueBRL + nIOFValue nTotalWithInvoice = nTotal * 1.05 ELSE // Full Edition pricing calculation nFinalFreight = nFreight nPriceEuroWithFreight = nPriceEuro + nFinalFreight nGrossValueBRL = nPriceEuroWithFreight * nEuroRate nIOFValue = nGrossValueBRL * nIOFTax nFinalSedex = nSedex nAlfandega = 1000 nTotal = nGrossValueBRL + nIOFValue + nFinalSedex + nAlfandega nTotalWithInvoice = nTotal * 1.05 END // Create a new JSON object for the converted product jsConvertedProduct is Variant jsConvertedProduct.IDPRICE = jsProduct.IDPRICE jsConvertedProduct.Category = jsProduct.Category jsConvertedProduct.FromVersion = jsProduct.FromVersion jsConvertedProduct.ToVersion = jsProduct.ToVersion jsConvertedProduct.Description = jsProduct.Description jsConvertedProduct.Ref_Example = jsProduct.Ref_Example jsConvertedProduct.Price_S = jsProduct.Price_S jsConvertedProduct.Price_P = jsProduct.Price_P jsConvertedProduct.Price_Standard = jsProduct.Price_Standard jsConvertedProduct.Price_Currency = "EUR" jsConvertedProduct.value_euro_dia = nEuroRate jsConvertedProduct.valor_frete = nFinalFreight jsConvertedProduct.iof = nIOFValue jsConvertedProduct.valor_bruto = nGrossValueBRL jsConvertedProduct.sedex = nFinalSedex jsConvertedProduct.nAlfandega = nAlfandega jsConvertedProduct.value_nfe = nTotalWithInvoice - nTotal jsConvertedProduct.value_total = nTotalWithInvoice // Add the converted product to the list ArrayAdd(arrConvertedProducts, jsConvertedProduct) END // Convert the list of converted products to JSON sJsonConvertedProducts is string = VariantToJSON(arrConvertedProducts) sJsonConvertedProducts = Replace( sJsonConvertedProducts, ",", ","+CRLF) sJsonConvertedProducts = Replace( sJsonConvertedProducts, "{", "{"+CRLF) sJsonConvertedProducts = Replace( sJsonConvertedProducts, "}", "}"+CRLF) EDT_Price = sJsonConvertedProducts // Display or save the resulting JSON Info(sJsonConvertedProducts) END
-- Adriano José Boller ______________________________________________ Consultor e Representante Oficial da PcSoft no Brasil +55 (41) 99949 1800 adrianoboller@gmail.com skype: adrianoboller http://wxinformatica.com.br/Mensaje modificado, 08,febrero 2025 - 22:49 |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|