Currency recalc, design

This commit is contained in:
2024-01-07 09:18:07 +01:00
parent 23f69817c0
commit 691e9b8841
2 changed files with 56 additions and 34 deletions

View File

@@ -52,8 +52,9 @@ class ProductsCompareController extends Controller
$coef = floatval(CurrencyRates::where('currency',$currency)->first()->rate); $coef = floatval(CurrencyRates::where('currency',$currency)->first()->rate);
} }
$products = $products->map(function ($product) use ($currencyRates, $coef) { $products = $products->map(function ($product) use ($currencyRates, $coef, $cHash) {
$product["salesPrice"] = round(floatval(($product["salesPrice"]) / $currencyRates[$product["country"]]) * $coef, 2); $product["salesPrice"] = round(floatval(($product["salesPrice"]) / $currencyRates[$product["country"]]) * $coef, 2);
$product["countryName"] = $cHash[$product["country"]];
return $product; return $product;
}); });
Log::info("{products}", ["products" => $products]); Log::info("{products}", ["products" => $products]);

View File

@@ -28,9 +28,9 @@ const props = defineProps({
}) })
const sdropdown = ref([ const sdropdown = ref([
{ text: "Description", value: "typeName"}, { text: "Description", value: "typeName" },
{ text: "Item name", value: "name"}, { text: "Item name", value: "name" },
{ text: "Code of product", value: "code"} { text: "Code of product", value: "code" }
]); ]);
@@ -40,7 +40,7 @@ const countryHash = ref([]);
let tproducts = computed(() => { let tproducts = computed(() => {
return products.value.map((prod) => { return products.value.map((prod) => {
prod.salesPrice = parseFloat(prod.salesPrice); prod.salesPrice = parseFloat(prod.salesPrice);
prod.country = countryHash.value[prod.country]; // prod.country = countryHash.value[prod.country];
return prod; return prod;
}) })
}) })
@@ -58,9 +58,9 @@ const ccodes = ref([]);
const ccountry = ref([]); const ccountry = ref([]);
const ccountry_filter = ref([['Country'],]); const ccountry_filter = ref([['Country'],]);
const ccountry_list = ref(['TEST']); const ccountry_list = ref(['TEST']);
const selected = ref(null); const currencyHash = ref({});
const article = ref('');
const currency = ref([]); const currency = ref([]);
const currencyCoef = ref(1.0);
const hrates = ref([ const hrates = ref([
{ text: "Currency", value: "currency", sortable: true }, { text: "Currency", value: "currency", sortable: true },
{ text: "Country", value: "country_name", sortable: true }, { text: "Country", value: "country_name", sortable: true },
@@ -68,15 +68,15 @@ const hrates = ref([
]); ]);
// { "country": "AT", "code": "50161321", "url": "https://www.ikea.com/at/de/p/hol-aufbewahrungstisch-akazie-50161321/", "name": "HOL", "typeName": "Aufbewahrungstisch", "mainImageUrl": "https://www.ikea.com/at/de/images/products/hol-aufbewahrungstisch-akazie__0104310_pe251255_s5.jpg", "itemNoGlobal": "50161321", "salesPrice": "80.99", "tag": "FAMILY_PRICE", "last_mod": "2023-12-03 16:44:24" }, // { "country": "AT", "code": "50161321", "url": "https://www.ikea.com/at/de/p/hol-aufbewahrungstisch-akazie-50161321/", "name": "HOL", "typeName": "Aufbewahrungstisch", "mainImageUrl": "https://www.ikea.com/at/de/images/products/hol-aufbewahrungstisch-akazie__0104310_pe251255_s5.jpg", "itemNoGlobal": "50161321", "salesPrice": "80.99", "tag": "FAMILY_PRICE", "last_mod": "2023-12-03 16:44:24" },
const hproducts = ref([ const hproducts = ref([
{ text: "Country", value: "country", sortable: true }, { text: "Country", value: "countryName", sortable: true },
{ text: "Name", value: "name", sortable: true }, { text: "Name", value: "name", sortable: true },
{ text: "Price", value: "salesPrice", sortable: true } { text: "Price", value: "salesPrice", sortable: true }
]); ]);
const hresults = ref([ const hresults = ref([
{ text: "Code", value: "code", sortable: true}, { text: "Code", value: "code", sortable: true },
{ text: "Name of product", value: "item", sortable: true}, { text: "Name of product", value: "item", sortable: true },
{ text: "Description", value: "desc", sortable: true}, { text: "Description", value: "desc", sortable: true },
{ text: "Image", value: "img", sortable: false} { text: "Image", value: "img", sortable: false }
]) ])
const rates = ref([]); const rates = ref([]);
const options_items = ref([]); const options_items = ref([]);
@@ -135,8 +135,12 @@ const fetch_rates = async () => {
const response = await axios.get(route('rates.index')) const response = await axios.get(route('rates.index'))
rates.value = response.data; rates.value = response.data;
currency.value = rates.value.map((currency) => currency.currency); currency.value = rates.value.map((currency) => currency.currency);
currencyHash.value = Object.fromEntries(
rates.value.map((currency) => [currency.currency, currency.rate]),
);
currency.value.unshift('EUR'); currency.value.unshift('EUR');
console.log("RATE=", rates.value); console.log("RATE=", rates.value);
console.log('HASH=', currencyHash.value);
} catch (e) { } catch (e) {
const response = await Swal.fire({ const response = await Swal.fire({
title: __('are you want to try again') + '?', title: __('are you want to try again') + '?',
@@ -176,7 +180,7 @@ const async_search = async () => {
let country = null; let country = null;
if (form.country.code !== undefined) country = form.country.code; if (form.country.code !== undefined) country = form.country.code;
console.log('SEARCH',route('products.search',[form.field.value, form.text, country])); console.log('SEARCH', route('products.search', [form.field.value, form.text, country]));
const response = await axios.get(route('products.search', [form.field.value, form.text, country])); const response = await axios.get(route('products.search', [form.field.value, form.text, country]));
options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl, "code": i.code, "url": i.url } }); options_items.value = response.data.map((i) => { return { "item": i.name, "desc": i.typeName, "img": i.mainImageUrl, "code": i.code, "url": i.url } });
@@ -224,7 +228,7 @@ const showRow = async (item) => {
console.log('FORM=', form); console.log('FORM=', form);
try { try {
const response = await axios.post(route('products.compare'),{ codes: item.code, countries: form.countries, currency: form.currency }) const response = await axios.post(route('products.compare'), { codes: item.code, countries: form.countries, currency: form.currency })
products.value = response.data.products; products.value = response.data.products;
countryHash.value = response.data.countryHash; countryHash.value = response.data.countryHash;
@@ -241,7 +245,22 @@ const showRow = async (item) => {
response.isConfirmed && fetch() response.isConfirmed && fetch()
} }
}; };
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);
}
}
const submit = () => { const submit = () => {
console.log('ITEM=', form); console.log('ITEM=', form);
@@ -286,7 +305,8 @@ const submit = () => {
<span class="font-extrabold font-mono">Search in:</span> <span class="font-extrabold font-mono">Search in:</span>
</div> </div>
<div> <div>
<multiselect v-model="form.field" :multiple="false" :searchable="false" :allow-empty="false" :options="sdropdown" track-by="value" label="text"></multiselect> <multiselect v-model="form.field" :multiple="false" :searchable="false" :allow-empty="false"
:options="sdropdown" track-by="value" label="text"></multiselect>
</div> </div>
<div> <div>
@@ -296,19 +316,12 @@ const submit = () => {
<input class="rounded-md " v-model="form.text" @input="async_search" /> <input class="rounded-md " v-model="form.text" @input="async_search" />
</div> </div>
<div>
<span class="font-extrabold font-mono">Currency recalculation</span>
</div>
<div>
<multiselect v-model="form.currency" :multiple="false" :allow-empty="false" placeholder="Currency"
:searchable="true" :options="currency" />
</div>
</form> </form>
<div class="mt-5"> <div class="mt-5">
<EasyTable :rows-per-page=20 :headers="hresults" :items="options_items" @click-row="showRow" alternating> <EasyTable :rows-per-page=20 :headers="hresults" :items="options_items" @click-row="showRow" alternating>
<template #item-img="{ code, img }"> <template #item-img="{ code, img }">
<img class="h-12" :src="img" alt=""/> <img class="h-12" :src="img" alt="" />
</template> </template>
</EasyTable> </EasyTable>
</div> </div>
@@ -321,6 +334,14 @@ const submit = () => {
</div> </div>
</div> </div>
<div> <div>
<div>
<span class="font-extrabold font-mono">Currency recalculation</span>
</div>
<div>
<multiselect v-model="form.currency" :multiple="false" :allow-empty="false" placeholder="Currency"
:searchable="true" :options="currency" @select="onSelectCurrency" />
</div>
<div class="flex flex-col start-0"> <div class="flex flex-col start-0">
<span class="font-extrabold font-mono">Vysledky vyhladavania</span> <span class="font-extrabold font-mono">Vysledky vyhladavania</span>
</div> </div>