prepare($query); $stmt->bindParam(':currency', $currency, SQLITE3_INTEGER); $stmt->bindParam(':userId', $userId, SQLITE3_INTEGER); $result = $stmt->execute(); $exchangeRate = $result->fetchArray(SQLITE3_ASSOC); if ($exchangeRate === false) { return $price; } else { $fromRate = $exchangeRate['rate']; return $price / $fromRate; } } // Get budget from user table $query = "SELECT budget FROM user WHERE id = :userId"; $stmt = $db->prepare($query); $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER); $result = $stmt->execute(); $row = $result->fetchArray(SQLITE3_ASSOC); $budget = $row['budget'] ?? 0; $currentMonth = date('m'); $currentYear = date('Y'); $sameAsCurrent = false; if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['month']) && isset($_GET['year'])) { // Don't allow viewing past months $selectedMonth = str_pad($_GET['month'], 2, '0', STR_PAD_LEFT); $selectedYear = $_GET['year']; $selectedTimestamp = strtotime($selectedYear . '-' . $selectedMonth . '-01'); $currentTimestamp = strtotime($currentYear . '-' . $currentMonth . '-01'); if ($selectedTimestamp < $currentTimestamp) { $calendarMonth = $currentMonth; $calendarYear = $currentYear; } else { $calendarMonth = $selectedMonth; $calendarYear = $selectedYear; } if ($calendarMonth == $currentMonth && $calendarYear == $currentYear) { $sameAsCurrent = true; } } else { $calendarMonth = $currentMonth; $calendarYear = $currentYear; $sameAsCurrent = true; } $currenciesInUse = []; $numberOfSubscriptionsToPayThisMonth = 0; $totalCostThisMonth = 0; $amountDueThisMonth = 0; $query = "SELECT * FROM subscriptions WHERE user_id = :user_id AND inactive = 0"; $stmt = $db->prepare($query); $stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER); $result = $stmt->execute(); $subscriptions = []; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $subscriptions[] = $row; $currenciesInUse[] = $row['currency_id']; } $currenciesInUse = array_unique($currenciesInUse); $usesMultipleCurrencies = count($currenciesInUse) > 1; $showCantConverErrorMessage = false; if ($usesMultipleCurrencies) { $query = "SELECT api_key FROM fixer WHERE user_id = :userId"; $stmt = $db->prepare($query); $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER); $result = $stmt->execute(); if ($result->fetchArray(SQLITE3_ASSOC) === false) { $showCantConverErrorMessage = true; } } // Get code of main currency to display on statistics $query = "SELECT c.code FROM currencies c INNER JOIN user u ON c.id = u.main_currency WHERE u.id = :userId"; $stmt = $db->prepare($query); $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER); $result = $stmt->execute(); $row = $result->fetchArray(SQLITE3_ASSOC); $code = $row['code']; $yearsToLoad = $calendarYear - $currentYear + 1; ?>

 
$startOfMonth) { $startDate = strtotime("-" . $incrementString, $startDate); } for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) { if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) { if (date('d', $date) == $day) { $totalCostThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId); $numberOfSubscriptionsToPayThisMonth++; if ($date > $today) { $amountDueThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId); } ?>
$startOfMonth) { $startDate = strtotime("-" . $incrementString, $startDate); } for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) { if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) { if (date('d', $date) == $day) { $totalCostThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId); $numberOfSubscriptionsToPayThisMonth++; if ($date > $today) { $amountDueThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId); } ?>
 
0 && $totalCostThisMonth > $budget) { $overBudgetAmount = $totalCostThisMonth - $budget; $overBudgetAmount = CurrencyFormatter::format($overBudgetAmount, $code); ?>
()