MNB árfolyam az árazásban

This commit is contained in:
Sperg Tamás 2026-02-26 17:19:49 +01:00
parent 7ce5a96fe6
commit 8327aa99cf

View File

@ -6,6 +6,38 @@ if (!(UserHasPerm('manage_pricing'))) {
StopAndDie(); StopAndDie();
} }
function getMNBExchange($curr = 'USD') {
$url = 'http://www.mnb.hu/arfolyamok.asmx';
$soap = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.mnb.hu/webservices/">
<soap:Body>
<web:GetCurrentExchangeRates/>
</soap:Body>
</soap:Envelope>';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $soap,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "http://www.mnb.hu/webservices/MNBArfolyamServiceSoap/GetCurrentExchangeRates"'
]
]);
$response = curl_exec($ch);
curl_close($ch);
$decoded = htmlspecialchars_decode(htmlspecialchars_decode($response, ENT_QUOTES), ENT_QUOTES);
if (preg_match('/curr="' . preg_quote($curr, '/') . '"\s*>\s*(\d+,\d+)/', $decoded, $m)) {
$value = (float)str_replace(',', '.', $m[1]);
return $value;
}
return null;
}
if (isset($_POST["func"])) { if (isset($_POST["func"])) {
if (htmlspecialchars($_POST["func"]) == "LoadCustomerType") { if (htmlspecialchars($_POST["func"]) == "LoadCustomerType") {
@ -42,7 +74,7 @@ if (isset($_POST["func"])) {
$ct_id = $data["ct_id"]; $ct_id = $data["ct_id"];
$sql = mysqli_query($conn,"UPDATE customer_types SET type_name='$type_name',currency='$currency',category_name='Alapértelmezett',price=0,is_active=1 WHERE ct_id = '$ct_id'"); $sql = mysqli_query($conn,"UPDATE customer_types SET type_name='$type_name',currency='$currency',category_name='Alapértelmezett',price=0,is_active=1 WHERE ct_id = '$ct_id'");
} else { } else {
$sql = mysqli_query($conn,"INSERT INTO customer_types(type_name, currency, category_name, price, is_active) VALUES ('$type_name','$currency','Alapértelmezett',0,1)"); $sql = mysqli_query($conn,"INSERT INTO customer_types(type_name, currency, category_name, price, is_active) VALUES ('$type_name','$currency','Alapértelmezett',1,1)");
} }
echo json_encode(array( 'result' => 'ok' )); echo json_encode(array( 'result' => 'ok' ));
} }
@ -50,6 +82,7 @@ if (isset($_POST["func"])) {
$type_name = htmlspecialchars($_POST["type_name"]); $type_name = htmlspecialchars($_POST["type_name"]);
$return_array = []; $return_array = [];
$currency = '';
$query = "SELECT * FROM customer_types WHERE type_name = '$type_name' and is_active = 1 ORDER BY category_name ASC"; $query = "SELECT * FROM customer_types WHERE type_name = '$type_name' and is_active = 1 ORDER BY category_name ASC";
if ($result = $conn->query($query)) { if ($result = $conn->query($query)) {
@ -61,11 +94,14 @@ if (isset($_POST["func"])) {
"price" => $c_type['price'], "price" => $c_type['price'],
"is_active" => $c_type['is_active'] "is_active" => $c_type['is_active']
]; ];
$currency = $c_type['currency'];
} }
} }
echo json_encode(array( echo json_encode(array(
'data' => $return_array, 'data' => $return_array,
'exchange' => (getMNBExchange($currency) ?: 'N/A'),
'result' => 'ok' 'result' => 'ok'
)); ));
} else if (htmlspecialchars($_POST["func"]) == "EditCategoryName") { } else if (htmlspecialchars($_POST["func"]) == "EditCategoryName") {
@ -232,16 +268,18 @@ if (isset($_POST["func"])) {
<main class="main-content" id="main-content"> <main class="main-content" id="main-content">
<h1>Árazás</h1> <h1>Árazás</h1>
<div id="errorDIV" style="z-index: 100; top: 50px; position: fixed; width: calc(100% - 260px);"></div> <p style="position: absolute; float: right; top: 50px; right: 15px; opacity: 0.8;">1 <span id="c_currency"></span> = <span id="c_exchange"></span> HUF</p>
<div id="errorDIV" style="z-index: 100; top: 50px; position: fixed; width: calc(100% - 587px);"></div>
<br clear"all"> <br clear="all">
<div style="width: 100%; margin-top: 10px; display: inline; float: left; max-width: 800px;"> <div style="width: 100%; margin-top: 10px; display: inline; float: left; max-width: 800px;">
<div class="tables" style="width: 100%"> <div class="tables" style="width: 100%">
<table id="table"> <table id="table">
<thead> <thead>
<tr style="top: 0px; position: sticky; z-index: 1;"> <tr style="top: 0px; position: sticky; z-index: 1;">
<th>Árkategória</th> <th>Árkategória</th>
<th style="width: 200px;">Ár</th> <th style="width: 200px;">Ár <small style="opacity: 0.8;"><small id="c_exchange_table"></small></small></th>
<th style="width: 200px;">Ár <small style="opacity: 0.8;"><small>HUF</small></small></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -327,6 +365,7 @@ if (isset($_POST["func"])) {
} }
} }
var exchange = 1;
function SelectCustomerType(type_name) { function SelectCustomerType(type_name) {
Loading(true); Loading(true);
document.querySelectorAll('.customer-type-item').forEach(item => { document.querySelectorAll('.customer-type-item').forEach(item => {
@ -346,17 +385,31 @@ if (isset($_POST["func"])) {
var Currency = ''; var Currency = '';
if (response.data[0].currency == "HUF") {
document.getElementById('c_exchange').innerHTML = '1';
exchange = 1;
} else {
document.getElementById('c_exchange').innerHTML = response.exchange;
exchange = response.exchange;
}
document.getElementById('c_currency').innerHTML = response.data[0].currency;
document.getElementById('c_exchange_table').innerHTML = response.data[0].currency;
response.data.forEach((item, i) => { response.data.forEach((item, i) => {
var newRow = table.insertRow(); var newRow = table.insertRow();
var cat_name = newRow.insertCell(0); var cat_name = newRow.insertCell(0);
var cat_price = newRow.insertCell(1); var cat_price = newRow.insertCell(1);
var cat_create = newRow.insertCell(2); var cat_exchange = newRow.insertCell(2);
var cat_create = newRow.insertCell(3);
Currency = item.currency; Currency = item.currency;
cat_name.innerHTML = item.category_name; cat_name.innerHTML = item.category_name;
cat_price.innerHTML = `<input class="price" type="number" min="0" value="${item.price ? item.price : ''}" autocomplete="off" step="0.01" onchange="EditCategoryName('${type_name}', '${item.category_name}', this.value)"> <span style="color: var(--panelcolor); margin-left: 10px;">${item.currency}</span>`; cat_price.innerHTML = `<input class="price" type="number" min="0" value="${item.price ? item.price : ''}" autocomplete="off" step="0.01" onchange="EditCategoryName('${type_name}', '${item.category_name}', this.value)"> <span style="color: var(--panelcolor); margin-left: 10px;">${item.currency}</span>`;
let rounded = Math.round((item.price ? item.price : 1) * exchange * 100) / 100;
cat_exchange.innerHTML = `${rounded.toFixed(rounded % 1 === 0 ? 0 : 2)} <span style="color: var(--panelcolor); opacity: 0.8; font-size: 14px;">HUF</span>`;
cat_create.innerHTML = `<button onclick="DisableCategory(${item.ct_id}, '${item.category_name}', '${type_name}')" style="width:36px; background: red; color: #f5f5f5; opacity: 0.6;">-</button>`; cat_create.innerHTML = `<button onclick="DisableCategory(${item.ct_id}, '${item.category_name}', '${type_name}')" style="width:36px; background: red; color: #f5f5f5; opacity: 0.6;">-</button>`;
cat_create.style.width = "36px"; cat_create.style.width = "36px";
}); });
@ -368,7 +421,8 @@ if (isset($_POST["func"])) {
var newRow = table.insertRow(); var newRow = table.insertRow();
var cat_name = newRow.insertCell(0); var cat_name = newRow.insertCell(0);
var cat_price = newRow.insertCell(1); var cat_price = newRow.insertCell(1);
var cat_create = newRow.insertCell(2); var cat_exchange = newRow.insertCell(2);
var cat_create = newRow.insertCell(3);
cat_name.innerHTML = `<input type="text" id="new_category_name" autocomplete="off" placeholder="Megnevezés...">`; cat_name.innerHTML = `<input type="text" id="new_category_name" autocomplete="off" placeholder="Megnevezés...">`;
cat_price.innerHTML = `<input class="price" type="number" min="0" value="" autocomplete="off" step="0.01"> <span style="color: var(--panelcolor); margin-left: 10px;">${Currency}</span>`; cat_price.innerHTML = `<input class="price" type="number" min="0" value="" autocomplete="off" step="0.01"> <span style="color: var(--panelcolor); margin-left: 10px;">${Currency}</span>`;
@ -376,7 +430,6 @@ if (isset($_POST["func"])) {
cat_create.innerHTML = `<button onclick="EditCategoryName('${type_name}')" style="width:36px; background: var(--panelcolor); color: var(--bgcolor);">+</button>`; cat_create.innerHTML = `<button onclick="EditCategoryName('${type_name}')" style="width:36px; background: var(--panelcolor); color: var(--bgcolor);">+</button>`;
cat_create.style.width = "36px"; cat_create.style.width = "36px";
} else { } else {
GenerateAlerts("error", response.result); GenerateAlerts("error", response.result);
} }