Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.
fix: don't show budget alert when budget is 0
Miguel Ribeirof6b8fb9162c5
diff --git a/calendar.php b/calendar.phpindex b424a3c..6a6656d 100644--- a/calendar.php+++ b/calendar.php@@ -24,7 +24,7 @@ $stmt = $db->prepare($query);$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);$result = $stmt->execute();$row = $result->fetchArray(SQLITE3_ASSOC);-$budget = $row['budget'];+$budget = $row['budget'] ?? 0;$currentMonth = date('m');$currentYear = date('Y');@@ -345,7 +345,7 @@ $yearsToLoad = $calendarYear - $currentYear + 1;</div><?php- if ($totalCostThisMonth > $budget) {+ if ($budget > 0 && $totalCostThisMonth > $budget) {$overBudgetAmount = $totalCostThisMonth - $budget;$overBudgetAmount = CurrencyFormatter::format($overBudgetAmount, $code);?>diff --git a/endpoints/user/budget.php b/endpoints/user/budget.phpindex 06bee21..a129882 100644--- a/endpoints/user/budget.php+++ b/endpoints/user/budget.php@@ -14,37 +14,26 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {$postData = file_get_contents("php://input");$data = json_decode($postData, true);- if (- !isset($data["budget"]) || $data["budget"] == ""- ) {+ $budget = $data["budget"];++ $sql = "UPDATE user SET budget = :budget WHERE id = :userId";+ $stmt = $db->prepare($sql);+ $stmt->bindValue(':budget', $budget, SQLITE3_TEXT);+ $stmt->bindValue(':userId', $userId, SQLITE3_TEXT);+ $result = $stmt->execute();++ if ($result) {$response = [- "success" => false,- "message" => translate('fill_mandatory_fields', $i18n)+ "success" => true,+ "message" => translate('user_details_saved', $i18n)];echo json_encode($response);} else {- $budget = $data["budget"];-- $sql = "UPDATE user SET budget = :budget WHERE id = :userId";- $stmt = $db->prepare($sql);- $stmt->bindValue(':budget', $budget, SQLITE3_TEXT);- $stmt->bindValue(':userId', $userId, SQLITE3_TEXT);- $result = $stmt->execute();-- if ($result) {- $response = [- "success" => true,- "message" => translate('user_details_saved', $i18n)- ];- echo json_encode($response);- } else {- $response = [- "success" => false,- "message" => translate('error_updating_user_data', $i18n)- ];- echo json_encode($response);- }-+ $response = [+ "success" => false,+ "message" => translate('error_updating_user_data', $i18n)+ ];+ echo json_encode($response);}}diff --git a/includes/version.php b/includes/version.phpindex f02e300..0e4fe53 100644--- a/includes/version.php+++ b/includes/version.php@@ -1,3 +1,3 @@<?php-$version = "v3.0.0";+$version = "v3.0.1";?>\ No newline at end of file