diff --git a/controllers/ledger_entries_controller.php b/controllers/ledger_entries_controller.php index 25cd6f6..6675547 100644 --- a/controllers/ledger_entries_controller.php +++ b/controllers/ledger_entries_controller.php @@ -266,6 +266,18 @@ class LedgerEntriesController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: reverse the ledger entry + */ + + function reverse($id) { + $id = $this->LedgerEntry->reverse($id); + $this->redirect(array('action'=>'view', $id)); + } + + /************************************************************************** ************************************************************************** ************************************************************************** @@ -342,6 +354,27 @@ class LedgerEntriesController extends AppController { $reconciled = $this->LedgerEntry->findReconciledLedgerEntries($id); //pr($reconciled); + + // REVISIT : 20090711 + // It's not clear whether we should be able to reverse charges that have + // already been paid/cleared/reconciled. Certainly, that will be the + // case when someone has pre-paid and then moves out early. However, this + // will work well for items accidentally charged but not yet paid for. + if ((!$entry['DebitLedger']['Account']['trackable'] || + $stats['debit']['amount_reconciled'] == 0) && + (!$entry['CreditLedger']['Account']['trackable'] || + $stats['credit']['amount_reconciled'] == 0)) + { + // Set up dynamic menu items + $this->sidemenu_links[] = + array('name' => 'Operations', 'header' => true); + + $this->sidemenu_links[] = + array('name' => 'Reverse', + 'url' => array('action' => 'reverse', + $id)); + } + // Prepare to render. $title = "Double Ledger Entry #{$entry['LedgerEntry']['id']}"; $this->set(compact('entry', 'title', 'reconciled', 'stats'));