4 Commits
v1.0 ... v1.0.4

7 changed files with 135 additions and 15 deletions

View File

@@ -2,13 +2,17 @@
* FinanceBuddy styles. * FinanceBuddy styles.
*/ */
/* Per-column net total in the column header (its own line, subtle pill). */ /* Per-column net total: its own full-width line under the column title (clears the right-floated
task count), so a wide amount never overflows the column. Keep the background pill (theme-safe
contrast). "Total:" is black; only the amount span is colored by sign. */
.fb-column-total { .fb-column-total {
display: inline-block; display: block;
clear: both;
margin-top: 3px; margin-top: 3px;
padding: 0 5px; padding: 0 5px;
font-weight: bold; font-weight: bold;
font-size: 0.95em; font-size: 0.95em;
color: #000;
background: rgba(0, 0, 0, 0.05); background: rgba(0, 0, 0, 0.05);
border-radius: 3px; border-radius: 3px;
} }

View File

@@ -48,6 +48,41 @@ class FinancePersistence extends Base
if ($this->pending !== null) { if ($this->pending !== null) {
$this->persist((int) $task_id, $this->pending['project_id'], $this->pending['fields']); $this->persist((int) $task_id, $this->pending['project_id'], $this->pending['fields']);
$this->pending = null; $this->pending = null;
return;
}
// Not a form submission. Native recurrence builds the next occurrence with a plain task
// create (which copies no metadata) after setting recurrence_parent to the source task, so
// carry the finance metadata across -- otherwise the recurring card loses its money.
$task = $this->taskFinderModel->getById((int) $task_id);
if (! empty($task['recurrence_parent'])) {
// A recurrence is the NEXT occurrence, so advance the installment (p2/30 -> p3/30).
$this->copyMetadata((int) $task['recurrence_parent'], (int) $task_id, true);
}
}
/**
* model:task:duplication:aftersave -- the manual "Duplicate" action. TaskDuplicationModel does
* not copy metadata, so carry the finance fields to the new task.
*/
public function onDuplication(array &$hook_values)
{
if (! empty($hook_values['source_task_id']) && ! empty($hook_values['destination_task_id'])) {
$this->copyMetadata((int) $hook_values['source_task_id'], (int) $hook_values['destination_task_id']);
}
}
/**
* recoreco:task:spawned -- RecoReco (calendar recurrence) just spawned a copy. Its ongoing card
* is the TEMPLATE that stays (unlike native recurrence, whose ongoing card is the new child), so
* advance the SOURCE template's installment. The clone already copied the current installment
* verbatim via onDuplication during RecoReco's duplicate() call.
*/
public function onRecoRecoSpawn(array &$payload)
{
if (! empty($payload['source_task_id'])) {
$this->advanceInstallment((int) $payload['source_task_id']);
} }
} }
@@ -114,6 +149,71 @@ class FinancePersistence extends Base
)); ));
} }
/**
* Copy the finance metadata from one task to another (recurrence next occurrence, or a manual
* duplicate). When $advance is true, bump the current installment by one -- clamped at the
* total so a finite plan stops at its last installment (e.g. p30/30 stays p30/30).
*/
private function copyMetadata($source_id, $dest_id, $advance = false)
{
if ($source_id <= 0 || $dest_id <= 0) {
return;
}
$amount = $this->taskMetadataModel->get($source_id, FinanceHelper::AMOUNT_KEY, '');
// Nothing to carry over if the source has no money set.
if ($amount === '' || (float) $amount <= 0) {
return;
}
$direction = $this->taskMetadataModel->get($source_id, FinanceHelper::DIRECTION_KEY, 'debit');
$current = $this->taskMetadataModel->get($source_id, FinanceHelper::INSTALLMENT_CURRENT_KEY, '');
$total = $this->taskMetadataModel->get($source_id, FinanceHelper::INSTALLMENT_TOTAL_KEY, '');
if ($advance && $current !== '' && ctype_digit((string) $current)) {
$next = (int) $current + 1;
if ($total !== '' && ctype_digit((string) $total) && $next > (int) $total) {
$next = (int) $total;
}
$current = (string) $next;
}
$this->taskMetadataModel->save($dest_id, array(
FinanceHelper::AMOUNT_KEY => $amount,
FinanceHelper::DIRECTION_KEY => $direction === 'credit' ? 'credit' : 'debit',
FinanceHelper::INSTALLMENT_CURRENT_KEY => $current,
FinanceHelper::INSTALLMENT_TOTAL_KEY => $total,
));
}
/**
* Advance a task's current installment by one, in place. A finite plan clamps at the total
* (p10/10 stays p10/10); an open-ended one (no total) increments unbounded (p2 -> p3). Cards
* with no numeric current installment are left alone.
*/
private function advanceInstallment($task_id)
{
$current = $this->taskMetadataModel->get($task_id, FinanceHelper::INSTALLMENT_CURRENT_KEY, '');
if ($current === '' || ! ctype_digit((string) $current)) {
return;
}
$total = $this->taskMetadataModel->get($task_id, FinanceHelper::INSTALLMENT_TOTAL_KEY, '');
$next = (int) $current + 1;
if ($total !== '' && ctype_digit((string) $total) && $next > (int) $total) {
$next = (int) $total;
}
$this->taskMetadataModel->save($task_id, array(
FinanceHelper::INSTALLMENT_CURRENT_KEY => (string) $next,
));
}
private function intOrBlank($raw) private function intOrBlank($raw)
{ {
$raw = trim((string) $raw); $raw = trim((string) $raw);

View File

@@ -29,6 +29,16 @@ class Plugin extends Base
$this->hook->on('model:task:creation:aftersave', array($persistence, 'onCreationAfterSave')); $this->hook->on('model:task:creation:aftersave', array($persistence, 'onCreationAfterSave'));
$this->hook->on('model:task:modification:prepare', array($persistence, 'onModificationPrepare')); $this->hook->on('model:task:modification:prepare', array($persistence, 'onModificationPrepare'));
// Carry the finance metadata onto copies (which Kanboard does not copy): native recurrence
// advances the installment for the next occurrence (creation:aftersave via recurrence_parent),
// and a manual Duplicate copies it verbatim.
$this->hook->on('model:task:duplication:aftersave', array($persistence, 'onDuplication'));
// RecoReco (calendar recurrence) spawns a copy and emits this signal. The clone already got
// the finance verbatim (via onDuplication above); here we advance the SOURCE template's
// installment, since RecoReco's ongoing card is the template that stays.
$this->hook->on('recoreco:task:spawned', array($persistence, 'onRecoRecoSpawn'));
// The line-3 money badge on each board card, rendered directly under the title. Two hooks: // The line-3 money badge on each board card, rendered directly under the title. Two hooks:
// "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');
@@ -67,7 +77,7 @@ class Plugin extends Base
public function getPluginVersion() public function getPluginVersion()
{ {
return '1.0.0'; return '1.0.4';
} }
public function getPluginHomepage() public function getPluginHomepage()

View File

@@ -1,7 +1,8 @@
<?php <?php
// Per-column net total in the column header (credits - debits). Shown in every column of an // 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 // enabled board, including "Total: R$0,00" -- never hidden on zero. Server-side, re-renders on
// every board refresh. // every board refresh. Rendered on its own full-width line under the title; "Total:" stays the
// default (black) and only the amount is colored by sign.
if (empty($column['project_id']) || ! $this->FinanceHelper->isEnabled($column['project_id'])) { if (empty($column['project_id']) || ! $this->FinanceHelper->isEnabled($column['project_id'])) {
return; return;
} }
@@ -9,16 +10,16 @@ if (empty($column['project_id']) || ! $this->FinanceHelper->isEnabled($column['p
$net = $this->FinanceHelper->columnNet($column); $net = $this->FinanceHelper->columnNet($column);
if ($net > 0) { if ($net > 0) {
$class = 'fb-column-total fb-total-credit'; $amount_class = 'fb-total-credit';
$sign = '+'; $sign = '+';
} elseif ($net < 0) { } elseif ($net < 0) {
$class = 'fb-column-total fb-total-debit'; $amount_class = 'fb-total-debit';
$sign = '-'; $sign = '-';
} else { } else {
$class = 'fb-column-total fb-total-zero'; $amount_class = 'fb-total-zero';
$sign = ''; $sign = '';
} }
?> ?>
<div class="<?= $class ?>"> <div class="fb-column-total">
<?= t('Total') ?>: <span class="fb-amount"><?= $sign ?>R$<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::money(abs($net)) ?></span> <?= t('Total') ?>: <span class="fb-amount <?= $amount_class ?>"><?= $sign ?>R$<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::money(abs($net)) ?></span>
</div> </div>

View File

@@ -15,13 +15,18 @@ if ($fb['amount'] === '' || (float) $fb['amount'] <= 0) {
$credit = $fb['direction'] === 'credit'; $credit = $fb['direction'] === 'credit';
$sign = $credit ? '+' : '-'; $sign = $credit ? '+' : '-';
$total = $fb['installment_total']; $total = $fb['installment_total'];
$current = $fb['installment_current'] !== '' ? $fb['installment_current'] : '1'; $current = $fb['installment_current'];
// Installments: "p2/10" when a total is set; "p2" (open-ended) when only the current is set;
// nothing when neither is set. Default the current to 1 if only a total was entered.
$show_installments = $current !== '' || $total !== '';
$current_display = $current !== '' ? $current : '1';
?> ?>
<div class="fb-line"> <div class="fb-line">
<span class="fb-badge <?= $credit ? 'fb-badge-credit' : 'fb-badge-debit' ?>"> <span class="fb-badge <?= $credit ? 'fb-badge-credit' : 'fb-badge-debit' ?>">
<?= $sign ?>R$<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::money($fb['amount']) ?> <?= $sign ?>R$<?= \Kanboard\Plugin\FinanceBuddy\Helper\FinanceHelper::money($fb['amount']) ?>
</span> </span>
<?php if ($total !== ''): ?> <?php if ($show_installments): ?>
<span class="fb-installments">p<?= $this->text->e($current) ?>/<?= $this->text->e($total) ?></span> <span class="fb-installments">p<?= $this->text->e($current_display) ?><?= $total !== '' ? '/'.$this->text->e($total) : '' ?></span>
<?php endif ?> <?php endif ?>
</div> </div>

View File

@@ -24,6 +24,6 @@
<span><?= t('of') ?></span> <span><?= t('of') ?></span>
<input type="number" min="1" name="financebuddy_installment_total" value="<?= $this->text->e($fb['installment_total']) ?>" class="fb-form-num"> <input type="number" min="1" name="financebuddy_installment_total" value="<?= $this->text->e($fb['installment_total']) ?>" class="fb-form-num">
</div> </div>
<p class="form-help"><?= t('Leave the total blank for an open-ended recurring bill.') ?></p> <p class="form-help"><?= t('Set a total for a finite plan (shows p2/10); leave it blank for an open-ended count (shows p2).') ?></p>
</div> </div>
<?php endif ?> <?php endif ?>

View File

@@ -1 +1 @@
FinanceBuddy v1.0 FinanceBuddy v1.0.4