diff --git a/site/controllers/payments_controller.php b/site/controllers/payments_controller.php new file mode 100644 index 0000000..f567bea --- /dev/null +++ b/site/controllers/payments_controller.php @@ -0,0 +1,120 @@ + 100, + 'group' => 'Payment.id', + 'order' => array('Payment.id' => 'ASC')); + + var $sidemenu_links = + array(array('name' => 'Payments', 'header' => true), + array('name' => 'Cleared', 'url' => array('controller' => 'payments', 'action' => 'cleared')), + array('name' => 'Unresolved', 'url' => array('controller' => 'payments', '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 payments + */ + + function index() { + $this->all(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: cleared + * - Lists cleared payments + */ + + function cleared() { + $this->all(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: unresolved + * - Lists unresolved payments + */ + + function unresolved() { + $this->all(); + } + + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: all + * - Lists all payments + */ + + function all() { + $this->paginate = array_merge + ($this->paginate, + array('link' => + array(// Models + 'PaymentType', + 'Receipt', + ), + )); + + $title = 'All Payments'; + $this->set('title', $title); $this->set('heading', $title); + $this->set('payments', $this->paginate()); + $this->render('index'); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: view + * - Displays information about a specific payment + */ + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'index')); + } + + $this->Payment->Behaviors->attach('Containable'); + $this->Payment->contain + (array(// Models + 'PaymentType', + 'Receipt', + ) + ); + $payment = $this->Payment->read(null, $id); + //pr($payment); + +/* $this->sidemenu_links[] = */ +/* array('name' => 'Operations', 'header' => true); */ +/* $this->sidemenu_links[] = */ +/* array('name' => 'Move-Out', 'url' => array('controller' => 'payments', 'action' => 'move-out')); */ + + $title = 'Payment #' . $payment['Payment']['id']; + $this->set(compact('payment', 'title')); + } +} diff --git a/site/views/elements/payments.ctp b/site/views/elements/payments.ctp new file mode 100644 index 0000000..78e7d22 --- /dev/null +++ b/site/views/elements/payments.ctp @@ -0,0 +1,64 @@ +'.__('Payments',true).''; + +function currency($number) { + if ($number < 0) + return "($ " . number_format(-1*$number, 2) . ")"; + else + return "$ " . number_format($number, 2); +} + +function datefmt($date) { + $date_fmt = 'm/d/Y'; + return ($date + ? date_format(date_create($date), $date_fmt) + : null); +} + +$headers_manual = array('ID', 'Type', 'Receipt', 'Amount', '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('Type', 'payment_type'), + $paginator->sort('Receipt', 'receipt_id'), + $paginator->sort('amount'), + $paginator->sort('comment')); +} else { + $headers = $headers_manual; +} + + +$rows = array(); +foreach ($payments as $payment) { + $rows[] = array($html->link($payment['Payment']['id'], + array('controller' => 'payments', + 'action' => 'view', + $payment['Payment']['id'])), + $payment['PaymentType']['name'], + '#'.$payment['Receipt']['id'], + currency($payment['Payment']['amount']), + $payment['Payment']['comment'], + ); +} + +echo $this->element('table', + array('class' => 'item payment list', + 'headers' => $headers, + 'rows' => $rows, + 'column_class' => $headers_manual)); + +if (isset($paginator)) { + echo('
' . "\n"); + echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled')); + echo(' | '); + echo $paginator->numbers(); + echo(' | '); + echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled')); + echo('
' . "\n"); +} diff --git a/site/views/payments/index.ctp b/site/views/payments/index.ctp new file mode 100644 index 0000000..4258e83 --- /dev/null +++ b/site/views/payments/index.ctp @@ -0,0 +1,3 @@ +
+element('payments', array('heading' => '

'.$heading.'

')) ?> +
diff --git a/site/views/payments/view.ctp b/site/views/payments/view.ctp new file mode 100644 index 0000000..08db77b --- /dev/null +++ b/site/views/payments/view.ctp @@ -0,0 +1,40 @@ + + +
+ +element('table', + array('class' => 'item payment detail', + 'caption' => 'Payment Info', + 'rows' => $rows, + 'column_class' => array('field', 'value'))); + + +?> + +