Added the payments controller and views.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@63 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
120
controllers/payments_controller.php
Normal file
120
controllers/payments_controller.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class PaymentsController extends AppController {
|
||||
var $helpers = array('Html');
|
||||
|
||||
var $paginate = array('limit' => 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'));
|
||||
}
|
||||
}
|
||||
64
views/elements/payments.ctp
Normal file
64
views/elements/payments.ctp
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Payments',true).'</h2>';
|
||||
|
||||
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('<div class="paging">' . "\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('</div>' . "\n");
|
||||
}
|
||||
3
views/payments/index.ctp
Normal file
3
views/payments/index.ctp
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="payments index">
|
||||
<?php echo $this->element('payments', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||
</div>
|
||||
40
views/payments/view.ctp
Normal file
40
views/payments/view.ctp
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<div class="payments view">
|
||||
|
||||
<?php
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Payment Info
|
||||
*/
|
||||
|
||||
$rows = array(array('ID', $payment['Payment']['id']),
|
||||
array('Type', $payment['PaymentType']['name']),
|
||||
array('Receipt', '#'.$payment['Receipt']['id']),
|
||||
array('Amount', currency($payment['Payment']['amount'])),
|
||||
array('Comment', $payment['Payment']['comment']));
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item payment detail',
|
||||
'caption' => 'Payment Info',
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value')));
|
||||
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user