From 9607fc9dd5f6c6731428118ffec59d710d348bfa Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Wed, 10 Jan 2024 18:13:04 +0100 Subject: [PATCH] Restult table - mod --- .../Controllers/ProductsCompareController.php | 9 +- lang/id.json | 3 +- resources/js/Pages/IkeaRoot.vue | 105 +++++++++--------- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/ProductsCompareController.php b/app/Http/Controllers/ProductsCompareController.php index 1221c88..b937591 100644 --- a/app/Http/Controllers/ProductsCompareController.php +++ b/app/Http/Controllers/ProductsCompareController.php @@ -45,15 +45,8 @@ class ProductsCompareController extends Controller if (count($countries)) $products->whereIn("country",$countries); $products = $products->get(); - $currencyRates = CurrencyRates::rates2EUR("Y"); - if ($currency == "EUR") { - $coef = 1; - } else { - $coef = floatval(CurrencyRates::where('currency',$currency)->first()->rate); - } - $products = $products->map(function ($product) use ($currencyRates, $coef, $cHash) { - $product["salesPrice"] = round(floatval(($product["salesPrice"]) / $currencyRates[$product["country"]]) * $coef, 2); + $products = $products->map(function ($product) use ( $cHash) { $product["countryName"] = $cHash[$product["country"]]; return $product; }); diff --git a/lang/id.json b/lang/id.json index e448764..adfaee3 100644 --- a/lang/id.json +++ b/lang/id.json @@ -119,5 +119,6 @@ "referenceerror: assignment to undeclared variable country": "ReferenceError: assignment to undeclared variable country", "typeerror: can't access property \"map\", ccountry.value is undefined": "TypeError: can't access property \"map\", ccountry.value is undefined", "referenceerror: priceunit is not defined": "ReferenceError: priceUnit is not defined", - "referenceerror: mainimagealt is not defined": "ReferenceError: mainImageAlt is not defined" + "referenceerror: mainimagealt is not defined": "ReferenceError: mainImageAlt is not defined", + "referenceerror: countrycurrency is not defined": "ReferenceError: countryCurrency is not defined" } \ No newline at end of file diff --git a/resources/js/Pages/IkeaRoot.vue b/resources/js/Pages/IkeaRoot.vue index 854dec7..52ecde8 100644 --- a/resources/js/Pages/IkeaRoot.vue +++ b/resources/js/Pages/IkeaRoot.vue @@ -37,28 +37,34 @@ const sdropdown = ref([ const products = ref([]); const countryHash = ref([]); +const countryCurrency = ref({}); const showItemFilter = ref(false); let tproducts = computed(() => { + console.log('PR=',products); + console.log('CC=',countryCurrency.value); return products.value.map((prod) => { - prod.salesPrice = parseFloat(prod.salesPrice); - // prod.country = countryHash.value[prod.country]; + prod.currency = countryCurrency.value[prod.countryName]; + prod.calcPrice = prod.salesPrice/currencyHash.value[prod.currency]; + prod.calcPrice = (prod.salesPrice * currencyCoef.value).toFixed(2); + prod.rate = currencyHash.value[prod.currency]; + return prod; }) }) let uniqProducts = computed(() => { - var output = []; - var keys = []; - options_items.value.forEach((element) => { - var key = element.item; - if (keys.indexOf(key) === -1) { - keys.push(key); - output.push(element.item); - } - }); - console.log('OUT',output); - return output; + var output = []; + var keys = []; + options_items.value.forEach((element) => { + var key = element.item; + if (keys.indexOf(key) === -1) { + keys.push(key); + output.push(element.item); + } + }); + console.log('OUT', output); + return output; }); const type = 'GeoChart'; @@ -86,7 +92,10 @@ const hrates = ref([ const hproducts = ref([ { text: "Country", value: "countryName", sortable: true }, { text: "Name", value: "name", sortable: true }, - { text: "Price", value: "salesPrice", sortable: true } + { text: "Local Price", value: "salesPrice", sortable: true }, + { text: "Cur", value: "currency", sortable: false}, + { text: "Rate", value: "rate" }, + { text: "Price", value: "calcPrice", sortable: true } ]); const hresults = ref([ { text: "Code", value: "code", sortable: true }, @@ -154,6 +163,9 @@ const fetch_rates = async () => { const response = await axios.get(route('rates.index')) rates.value = response.data; currency.value = rates.value.map((currency) => currency.currency); + countryCurrency.value = Object.fromEntries( + rates.value.map((currency) => [currency.country_name, currency.currency ]) + ); currencyHash.value = Object.fromEntries( rates.value.map((currency) => [currency.currency, currency.rate]), ); @@ -267,18 +279,9 @@ const showRow = async (item) => { const onSelectCurrency = () => { console.log('CURR', form.currency); console.log('COEF', currencyCoef.value); - console.log('PROD', products.value); - if (products.value.length > 0) { - if (currencyCoef.value != 1.0) - products.value.map((product) => { product.salesPrice = product.salesPrice / currencyCoef.value }); - if (form.currency != 'EUR') currencyCoef.value = currencyHash.value[form.currency]; - else currencyCoef.value = 1.0; - - products.value = products.value.map((product) => { product.salesPrice = (product.salesPrice * currencyCoef.value).toFixed(2); return product }); - - console.log('PROD-NEW', products.value); - } + if (form.currency != 'EUR') currencyCoef.value = currencyHash.value[form.currency]; + else currencyCoef.value = 1.0; } const submit = () => { @@ -299,28 +302,28 @@ const submit = () => {
-
- +
+ +
+
+ Currency recalculation +
+
+ +
+
+ Results +
+
+ + + +
-
- Currency recalculation -
-
- -
-
- Results -
-
- - - -
-
@@ -357,7 +360,8 @@ const submit = () => {
- + @@ -381,9 +385,9 @@ const submit = () => {
- - + +
@@ -416,6 +420,7 @@ const submit = () => { width: 250px; background-color: #fff; -} +} +