Skip to content

Commit

Permalink
Remove duplicate category.
Browse files Browse the repository at this point in the history
Fix changing main currency.
Fix currency conversion.
Pre-Select main currency when adding a new subscription.
  • Loading branch information
ellite committed Nov 10, 2023
1 parent eee998c commit 7e4ca23
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion db/commands.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ INSERT INTO categories (id, name) VALUES
(11, 'Insurance'),
(12, 'Gaming'),
(13, 'News & Magazines'),
(14, 'Productivity'),
(14, 'Software'),
(15, 'Technology'),
(16, 'Charity & Donations:');

Expand Down
2 changes: 1 addition & 1 deletion endpoints/cronjobs/createdatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
(11, 'Insurance'),
(12, 'Gaming'),
(13, 'News & Magazines'),
(14, 'Productivity'),
(14, 'Software'),
(15, 'Technology'),
(16, 'Cloud Services'),
(17, 'Charity & Donations')");
Expand Down
3 changes: 2 additions & 1 deletion endpoints/user/save_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function update_exchange_rate($db) {
$mainCurrencyCode = $row['code'];
$mainCurrencyId = $row['main_currency'];

$api_url = "http:https://data.fixer.io/api/latest?access_key=". $apiKey . "&base=" . $mainCurrencyCode . "&symbols=" . $codes;
$api_url = "http:https://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
$response = file_get_contents($api_url);
$apiData = json_decode($response, true);

Expand Down Expand Up @@ -131,6 +131,7 @@ function update_exchange_rate($db) {
$_SESSION['avatar'] = $avatar;

if ($main_currency != $mainCurrencyId) {
$_SESSION['main_currency'] = $main_currency;
update_exchange_rate($db);
}

Expand Down
2 changes: 1 addition & 1 deletion includes/list_subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getPriceConverted($price, $currency, $database) {
return $price;
} else {
$fromRate = $exchangeRate['rate'];
return number_format($price * $fromRate, 2);
return number_format($price / $fromRate, 2);
}
}

Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@
<select id="currency" name="currency_id" placeholder="Currency">
<?php
foreach ($currencies as $currency) {
$selected = ($currency['id'] == $main_currency) ? 'selected' : '';
?>
<option value="<?= $currency['id'] ?>"><?= $currency['name'] ?></option>
<option value="<?= $currency['id'] ?>" <?= $selected ?>><?= $currency['name'] ?></option>
<?php
}
?>
Expand Down

0 comments on commit 7e4ca23

Please sign in to comment.