From d77fc01195534dc59145de33a055aed8c17172ac Mon Sep 17 00:00:00 2001 From: Ruben Carlo Benante Date: Mon, 13 Jul 2026 09:45:22 -0300 Subject: [PATCH] =?UTF-8?q?FinanceBuddy=20v1.3.0=20=E2=80=94=20per-board?= =?UTF-8?q?=20currency=20shipped.=20All=20clean=20(php=20-l,=20ASCII,=20RE?= =?UTF-8?q?ADME=20+=20TODO=20synced)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Helper/FinanceHelper.php | 29 +++++++++++++++++++++++++++++ Plugin.php | 2 +- README.md | 12 ++++++++---- Template/board/column_total.php | 2 +- Template/board/task_money.php | 2 +- Template/project/integration.php | 6 ++++++ Template/task/form_fields.php | 2 +- VERSION | 2 +- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Helper/FinanceHelper.php b/Helper/FinanceHelper.php index 2b3b146..07de678 100644 --- a/Helper/FinanceHelper.php +++ b/Helper/FinanceHelper.php @@ -19,6 +19,12 @@ class FinanceHelper extends Base const INSTALLMENT_CURRENT_KEY = 'financebuddy_installment_current'; const INSTALLMENT_TOTAL_KEY = 'financebuddy_installment_total'; + // Per-board currency symbol shown before every amount (default "R$"). Up to 4 chars; the stored + // value is trimmed, capped, and defaulted on read, so an empty or oversized value is harmless. + const CURRENCY_KEY = 'financebuddy_currency'; + const CURRENCY_DEFAULT = 'R$'; + const CURRENCY_MAX_LENGTH = 4; + // Per-column opt-out of the header total. Stored per column in PROJECT metadata as // financebuddy_hide_total_ = 'on' (hidden) or 'off' (shown, the default). Literal // on/off, never 1/0, so the flag is never dropped by the metadata save (PHP empty("0") === true). @@ -33,6 +39,9 @@ class FinanceHelper extends Base // Memoized per project_id: the board hooks below call isEnabled() once per card. private static $enabledCache = array(); + // Memoized per project_id: currency() is likewise resolved once per card/column render. + private static $currencyCache = array(); + /** * Is FinanceBuddy enabled for this board? * @@ -50,6 +59,26 @@ class FinanceHelper extends Base return self::$enabledCache[$project_id]; } + /** + * Per-board currency symbol shown before amounts: the stored value trimmed and capped to + * CURRENCY_MAX_LENGTH, or CURRENCY_DEFAULT ("R$") when empty. Memoized per project. + * + * @param integer $project_id + * @return string + */ + public function currency($project_id) + { + $project_id = (int) $project_id; + + if (! isset(self::$currencyCache[$project_id])) { + $symbol = trim((string) $this->projectMetadataModel->get($project_id, self::CURRENCY_KEY, '')); + $symbol = mb_substr($symbol, 0, self::CURRENCY_MAX_LENGTH); + self::$currencyCache[$project_id] = $symbol === '' ? self::CURRENCY_DEFAULT : $symbol; + } + + return self::$currencyCache[$project_id]; + } + /** * Stored finance values for a task, with defaults. One query (getAll) since the board renders * this per card. diff --git a/Plugin.php b/Plugin.php index 0a204b5..6340dde 100644 --- a/Plugin.php +++ b/Plugin.php @@ -85,7 +85,7 @@ class Plugin extends Base public function getPluginVersion() { - return '1.2.2'; + return '1.3.0'; } public function getPluginHomepage() diff --git a/README.md b/README.md index 21f956e..2675ceb 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Once a board is enabled: The task edit/create form gains a **Finance** section in the middle column: -- **Amount** in R$. +- **Amount** in the board's currency (default R$). - **Debit** or **Credit** (money out vs money in). - **Installment** current / total (for example `2` of `10`). Leave the total blank for an open-ended recurring bill. @@ -66,9 +66,13 @@ counting. ## Money format -Amounts show in R$ with a comma decimal and no thousand separator (for example `R$1234,56`). -Input accepts either a dot or a comma as the decimal separator, so `1234.56` and `1234,56` are -the same value. +Amounts show with a comma decimal and no thousand separator (for example `R$1234,56`). Input +accepts either a dot or a comma as the decimal separator, so `1234.56` and `1234,56` are the same +value. + +The currency symbol shown before every amount is **per board**: set it under +Settings -> Integrations next to the enable checkbox (up to 4 characters, e.g. `US$`, `EUR`, `GBP`). +Leave it empty for the default `R$`. ## How it stores data diff --git a/Template/board/column_total.php b/Template/board/column_total.php index fcf8402..8b69b82 100644 --- a/Template/board/column_total.php +++ b/Template/board/column_total.php @@ -26,5 +26,5 @@ if ($net > 0) { } ?>
- : R$ + : text->e($this->FinanceHelper->currency($column['project_id'])) ?>
diff --git a/Template/board/task_money.php b/Template/board/task_money.php index ef7e309..8112666 100644 --- a/Template/board/task_money.php +++ b/Template/board/task_money.php @@ -24,7 +24,7 @@ $current_display = $current !== '' ? $current : '1'; ?>
- R$ + text->e($this->FinanceHelper->currency($task['project_id'])) ?> ptext->e($current_display) ?>text->e($total) : '' ?> diff --git a/Template/project/integration.php b/Template/project/integration.php index 0b426a1..889bc95 100644 --- a/Template/project/integration.php +++ b/Template/project/integration.php @@ -13,6 +13,12 @@

+ + form->label(t('Currency symbol'), 'financebuddy_currency') ?> + form->text('financebuddy_currency', $values, array(), array('maxlength="4"', 'placeholder="R$"')) ?> +

+ +

diff --git a/Template/task/form_fields.php b/Template/task/form_fields.php index a335160..3547c28 100644 --- a/Template/task/form_fields.php +++ b/Template/task/form_fields.php @@ -5,7 +5,7 @@
- + diff --git a/VERSION b/VERSION index ec61652..0683163 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -FinanceBuddy v1.2.2 +FinanceBuddy v1.3.0