Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 974a3ae8bd | |||
| 0833c4a1c0 | |||
| d2383a76b7 | |||
| 6328f3632f |
@@ -1,9 +1,35 @@
|
|||||||
/*
|
/*
|
||||||
* FinanceBuddy styles.
|
* FinanceBuddy styles.
|
||||||
*
|
|
||||||
* The per-column total (.fb-column-total) styling is added in a later version.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Per-column net total in the column header (its own line, subtle pill). */
|
||||||
|
.fb-column-total {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 3px;
|
||||||
|
padding: 0 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.95em;
|
||||||
|
background: rgba(0, 0, 0, 0.05);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep the signed amount together ("-R$450,00"); a break before it (after "Total:") is fine. */
|
||||||
|
.fb-amount {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fb-total-debit {
|
||||||
|
color: #b94a48;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fb-total-credit {
|
||||||
|
color: #468847;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fb-total-zero {
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
/* Line-3 money badge on board cards. Its own background guarantees contrast on any card color. */
|
/* Line-3 money badge on board cards. Its own background guarantees contrast on any card color. */
|
||||||
.fb-line {
|
.fb-line {
|
||||||
margin: 2px 0 4px;
|
margin: 2px 0 4px;
|
||||||
@@ -17,6 +43,7 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fb-badge-debit {
|
.fb-badge-debit {
|
||||||
|
|||||||
@@ -62,6 +62,54 @@ class FinanceHelper extends Base
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Net money for a board column: credits positive, debits negative, summed over the cards in
|
||||||
|
* the column. One grouped query over the column's task ids (the task rows carry no metadata).
|
||||||
|
*
|
||||||
|
* @param array $column A board column as passed to template:board:column:header ('tasks').
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function columnNet(array $column)
|
||||||
|
{
|
||||||
|
if (empty($column['tasks'])) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$task_ids = array();
|
||||||
|
foreach ($column['tasks'] as $task) {
|
||||||
|
$task_ids[] = (int) $task['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $this->db->table('task_has_metadata')
|
||||||
|
->columns('task_id', 'name', 'value')
|
||||||
|
->in('task_id', $task_ids)
|
||||||
|
->in('name', array(self::AMOUNT_KEY, self::DIRECTION_KEY))
|
||||||
|
->findAll();
|
||||||
|
|
||||||
|
$amounts = array();
|
||||||
|
$directions = array();
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row['name'] === self::AMOUNT_KEY) {
|
||||||
|
$amounts[$row['task_id']] = (float) $row['value'];
|
||||||
|
} else {
|
||||||
|
$directions[$row['task_id']] = $row['value'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$net = 0.0;
|
||||||
|
foreach ($amounts as $task_id => $amount) {
|
||||||
|
if ($amount <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_credit = isset($directions[$task_id]) && $directions[$task_id] === 'credit';
|
||||||
|
$net += $is_credit ? $amount : -$amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $net;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Values to prefill the task-form fields: a re-post (after a validation error) wins, then the
|
* Values to prefill the task-form fields: a re-post (after a validation error) wins, then the
|
||||||
* stored metadata for an existing task, otherwise blanks for a new task.
|
* stored metadata for an existing task, otherwise blanks for a new task.
|
||||||
|
|||||||
10
Plugin.php
10
Plugin.php
@@ -33,6 +33,14 @@ class Plugin extends Base
|
|||||||
// "private" is the normal board, "public" is the read-only board shared by token.
|
// "private" is the normal board, "public" is the read-only board shared by token.
|
||||||
$this->template->hook->attach('template:board:private:task:after-title', 'financeBuddy:board/task_money');
|
$this->template->hook->attach('template:board:private:task:after-title', 'financeBuddy:board/task_money');
|
||||||
$this->template->hook->attach('template:board:public:task:after-title', 'financeBuddy:board/task_money');
|
$this->template->hook->attach('template:board:public:task:after-title', 'financeBuddy:board/task_money');
|
||||||
|
|
||||||
|
// Per-column net total (credits - debits) in the column header.
|
||||||
|
$this->template->hook->attach('template:board:column:header', 'financeBuddy:board/column_total');
|
||||||
|
|
||||||
|
// The same money badge at the top of the opened card (task view), under the title, so a
|
||||||
|
// card shows its money whether you are on the board or reading the card. Reuses the board
|
||||||
|
// badge template (both hooks pass $task).
|
||||||
|
$this->template->hook->attach('template:task:details:top', 'financeBuddy:board/task_money');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHelpers()
|
public function getHelpers()
|
||||||
@@ -59,7 +67,7 @@ class Plugin extends Base
|
|||||||
|
|
||||||
public function getPluginVersion()
|
public function getPluginVersion()
|
||||||
{
|
{
|
||||||
return '0.3.1';
|
return '1.0.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPluginHomepage()
|
public function getPluginHomepage()
|
||||||
|
|||||||
64
README.md
64
README.md
@@ -1,8 +1,8 @@
|
|||||||
# FinanceBuddy -- money on your Kanboard cards
|
# FinanceBuddy -- money on your Kanboard cards
|
||||||
|
|
||||||
Attach a money value to a board card, see it on the card, and total it per column -- so a
|
Attach a money value to each board card, see it on the card, and total it per column, so a
|
||||||
Kanboard project can double as a simple, visual finance board (bills, installments, income
|
Kanboard project can double as a simple, visual finance board -- bills, installments, income
|
||||||
vs expenses).
|
vs expenses.
|
||||||
|
|
||||||
FinanceBuddy is **opt-in per board**: installing it changes nothing until a project manager
|
FinanceBuddy is **opt-in per board**: installing it changes nothing until a project manager
|
||||||
enables it for a specific board under Settings -> Integrations. Boards that are not enabled
|
enables it for a specific board under Settings -> Integrations. Boards that are not enabled
|
||||||
@@ -10,30 +10,59 @@ look exactly as before.
|
|||||||
|
|
||||||
## The idea: a bill-lifecycle board
|
## The idea: a bill-lifecycle board
|
||||||
|
|
||||||
Kanboard imposes no structure, so FinanceBuddy is built to fit one rather than dictate it. The
|
Kanboard imposes no structure, so FinanceBuddy fits one rather than dictating it. A layout that
|
||||||
suggested organization:
|
works well:
|
||||||
|
|
||||||
- **Columns = a bill's status:** `Templates -> Due this month -> Paid`. Cards flow left to
|
- **Columns = a bill's status:** `Templates -> Due this month -> Paid`. Cards flow left to right
|
||||||
right as they are paid.
|
as they are paid.
|
||||||
- **Tags = category:** housing, utilities, comms, food...
|
- **Tags = category:** housing, utilities, comms, food...
|
||||||
- **Due date = the bill's due date;** color/priority = urgency.
|
- **Due date = the bill's due date;** color/priority = urgency.
|
||||||
- Each card carries a **money value** (debit or credit) and, optionally, an **installment**
|
- Each card carries a **money value** and, optionally, an **installment** count.
|
||||||
count (`p2/10` = 2nd of 10 payments; leave the total blank for an open-ended recurring bill).
|
|
||||||
|
|
||||||
Recurring monthly bills can live as template cards spawned each month by the companion RecoReco
|
Recurring monthly bills can live as template cards spawned each month by the companion RecoReco
|
||||||
plugin; FinanceBuddy only owns the money.
|
plugin; FinanceBuddy only owns the money.
|
||||||
|
|
||||||
|
## What it does
|
||||||
|
|
||||||
|
Once a board is enabled:
|
||||||
|
|
||||||
|
### Set the money on a card
|
||||||
|
|
||||||
|
The task edit/create form gains a **Finance** section in the middle column:
|
||||||
|
|
||||||
|
- **Amount** in 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.
|
||||||
|
|
||||||
|
### See it on the card
|
||||||
|
|
||||||
|
A badge appears just under the card title -- both on the board and at the top of the opened
|
||||||
|
card, so the money is visible whether you glance at the board or read the card (no need to open
|
||||||
|
the edit form):
|
||||||
|
|
||||||
|
- **red** with a `-` for a debit, **green** with a `+` for a credit (both the color and the sign
|
||||||
|
carry the meaning, and the badge's own background stays readable on any card color);
|
||||||
|
- followed by `pN/M` when a total is set (for example `p2/10`), hidden for open-ended bills.
|
||||||
|
|
||||||
|
### Total per column
|
||||||
|
|
||||||
|
Each column header shows a **`Total:`** of its cards -- credits positive, debits negative (the
|
||||||
|
net): red when negative (what you owe), green when positive, gray at zero. It is shown for every
|
||||||
|
column, including `Total: R$0,00`.
|
||||||
|
|
||||||
## Money format
|
## Money format
|
||||||
|
|
||||||
Amounts are shown in R$ with a comma decimal and no thousand separator (for example
|
Amounts show in R$ with a comma decimal and no thousand separator (for example `R$1234,56`).
|
||||||
`R$1234,56`). Input accepts either a dot or a comma as the decimal separator, so `1234.56` and
|
Input accepts either a dot or a comma as the decimal separator, so `1234.56` and `1234,56` are
|
||||||
`1234,56` are the same value.
|
the same value.
|
||||||
|
|
||||||
## Status
|
## How it stores data
|
||||||
|
|
||||||
Early development. This version registers the plugin and loads its stylesheet; the per-board
|
No database migration. The per-board enable flag is stored in project metadata; each card's
|
||||||
toggle, the in-form editing, the card badge, and the per-column totals arrive in the following
|
money is stored in task metadata. The finance fields live in the normal task form but are saved
|
||||||
versions.
|
separately (they are not task columns), so ordinary task saving is untouched. Uninstalling the
|
||||||
|
plugin leaves that metadata harmlessly in place and changes nothing else.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@@ -43,7 +72,8 @@ versions.
|
|||||||
|
|
||||||
Copy this folder into your Kanboard installation as `plugins/FinanceBuddy/`. The directory name
|
Copy this folder into your Kanboard installation as `plugins/FinanceBuddy/`. The directory name
|
||||||
must be exactly `FinanceBuddy` (Kanboard derives the plugin namespace from the folder name). No
|
must be exactly `FinanceBuddy` (Kanboard derives the plugin namespace from the folder name). No
|
||||||
build step and no database migration.
|
build step and no database migration. Then, on each board you want to track, go to
|
||||||
|
Settings -> Integrations and tick "Enable FinanceBuddy on this board".
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
24
Template/board/column_total.php
Normal file
24
Template/board/column_total.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
// Per-column net total in the column header (credits - debits). Shown in every column of an
|
||||||
|
// enabled board, including "total R$0,00" -- never hidden on zero. Server-side, re-renders on
|
||||||
|
// every board refresh.
|
||||||
|
if (empty($column['project_id']) || ! $this->FinanceHelper->isEnabled($column['project_id'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$net = $this->FinanceHelper->columnNet($column);
|
||||||
|
|
||||||
|
if ($net > 0) {
|
||||||
|
$class = 'fb-column-total fb-total-credit';
|
||||||
|
$sign = '+';
|
||||||
|
} elseif ($net < 0) {
|
||||||
|
$class = 'fb-column-total fb-total-debit';
|
||||||
|
$sign = '-';
|
||||||
|
} else {
|
||||||
|
$class = 'fb-column-total fb-total-zero';
|
||||||
|
$sign = '';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="<?= $class ?>">
|
||||||
|
<?= t('Total') ?>: <span class="fb-amount"><?= $sign ?>R$<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::money(abs($net)) ?></span>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user