diff --git a/site/controllers/receipts_controller.php b/site/controllers/receipts_controller.php new file mode 100644 index 0000000..a78764f --- /dev/null +++ b/site/controllers/receipts_controller.php @@ -0,0 +1,133 @@ + 100, + 'group' => 'Receipt.id', + 'order' => array('Receipt.stamp' => 'ASC')); + + var $sidemenu_links = + array(array('name' => 'Receipts', 'header' => true), + array('name' => 'Cleared', 'url' => array('controller' => 'receipts', 'action' => 'cleared')), + array('name' => 'Unresolved', 'url' => array('controller' => 'receipts', 'action' => 'unresolved')), + ); + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * override: sideMenuLinks + * - Generates controller specific links for the side menu + */ + function sideMenuLinks() { + return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: index + * - Lists all receipts + */ + + function index() { + $this->all(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: cleared + * - Lists cleared receipts + */ + + function cleared() { + $this->all(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: unresolved + * - Lists unresolved receipts + */ + + function unresolved() { + $this->all(); + } + + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: all + * - Lists all receipts + */ + + function all() { + $this->paginate = array_merge + ($this->paginate, + array('link' => + array(// Models + 'Charge', + 'Payment' + ), + )); + + $title = 'All Receipts'; + $this->set('title', $title); $this->set('heading', $title); + $this->set('receipts', $this->paginate()); + $this->render('index'); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: view + * - Displays information about a specific receipt + */ + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'index')); + } + + $this->Receipt->Behaviors->attach('Containable'); + $this->Receipt->contain + (array(// Models + 'Charge' => array(// Models + 'Lease' => array('fields' => array('number')), + 'ChargesReceipt', + 'ChargeType'), + 'Payment' => array(// Models + 'PaymentType'), + ) + ); + $receipt = $this->Receipt->read(null, $id); + //pr($receipt); + + $charge_amount = 0; + $payment_amount = 0; + foreach($receipt['Charge'] AS $charge) + $charge_amount += $charge['ChargesReceipt']['amount']; + foreach($receipt['Payment'] AS $payment) + $payment_amount += $payment['amount']; + +/* $this->sidemenu_links[] = */ +/* array('name' => 'Operations', 'header' => true); */ +/* $this->sidemenu_links[] = */ +/* array('name' => 'Move-Out', 'url' => array('controller' => 'receipts', 'action' => 'move-out')); */ + + $title = 'Receipt #' . $receipt['Receipt']['id']; + $this->set(compact('receipt', 'title', + 'charge_amount', + 'payment_amount')); + } +} diff --git a/site/views/elements/receipts.ctp b/site/views/elements/receipts.ctp new file mode 100644 index 0000000..169d702 --- /dev/null +++ b/site/views/elements/receipts.ctp @@ -0,0 +1,44 @@ +'.__('Receipts',true).''; + +$headers_manual = array('Id', 'Timestamp', 'Comment'); +if (isset($paginator)) { + echo $paginator->counter(array( + 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); + + $headers = array($paginator->sort('id'), + $paginator->sort('Timestamp', 'stamp'), + $paginator->sort('comment')); +} else { + $headers = $headers_manual; +} + +$rows = array(); +foreach ($receipts as $receipt) { + $rows[] = array($html->link($receipt['Receipt']['id'], + array('controller' => 'receipts', + 'action' => 'view', + $receipt['Receipt']['id'])), + $receipt['Receipt']['stamp'], + $receipt['Receipt']['comment']); +} + +echo $this->element('table', + array('class' => 'item receipt list', + 'headers' => $headers, + 'rows' => $rows, + 'column_class' => $headers_manual)); + +if (isset($paginator)) { + echo('