Added the charges controller and views. Fixed a couple minor bugs found with receipts.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@62 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
129
controllers/charges_controller.php
Normal file
129
controllers/charges_controller.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
class ChargesController extends AppController {
|
||||
var $helpers = array('Html');
|
||||
|
||||
var $paginate = array('limit' => 100,
|
||||
'group' => 'Charge.id',
|
||||
'order' => array('Charge.charge_date' => 'ASC'));
|
||||
|
||||
var $sidemenu_links =
|
||||
array(array('name' => 'Charges', 'header' => true),
|
||||
array('name' => 'Cleared', 'url' => array('controller' => 'charges', 'action' => 'cleared')),
|
||||
array('name' => 'Unresolved', 'url' => array('controller' => 'charges', '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 charges
|
||||
*/
|
||||
|
||||
function index() {
|
||||
$this->all();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: cleared
|
||||
* - Lists cleared charges
|
||||
*/
|
||||
|
||||
function cleared() {
|
||||
$this->all();
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: unresolved
|
||||
* - Lists unresolved charges
|
||||
*/
|
||||
|
||||
function unresolved() {
|
||||
$this->all();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: all
|
||||
* - Lists all charges
|
||||
*/
|
||||
|
||||
function all() {
|
||||
$this->paginate = array_merge
|
||||
($this->paginate,
|
||||
array('link' =>
|
||||
array(// Models
|
||||
'ChargeType',
|
||||
'Receipt',
|
||||
'Lease' => array('fields' => array('number'))
|
||||
),
|
||||
));
|
||||
|
||||
$title = 'All Charges';
|
||||
$this->set('title', $title); $this->set('heading', $title);
|
||||
$this->set('charges', $this->paginate());
|
||||
$this->render('index');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: view
|
||||
* - Displays information about a specific charge
|
||||
*/
|
||||
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
$this->Charge->Behaviors->attach('Containable');
|
||||
$this->Charge->contain
|
||||
(array(// Models
|
||||
'ChargeType',
|
||||
'Receipt',
|
||||
'Lease' => array('fields' => array('number')),
|
||||
)
|
||||
);
|
||||
$charge = $this->Charge->read(null, $id);
|
||||
//pr($charge);
|
||||
|
||||
$payment_amount = 0;
|
||||
foreach($charge['Receipt'] AS $receipt)
|
||||
$payment_amount += $receipt['ChargesReceipt']['amount'];
|
||||
$balance_amount = $charge['Charge']['total'] - $payment_amount;
|
||||
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Operations', 'header' => true); */
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Move-Out', 'url' => array('controller' => 'charges', 'action' => 'move-out')); */
|
||||
|
||||
$title = 'Charge #' . $charge['Charge']['id'];
|
||||
$this->set(compact('charge', 'title',
|
||||
'payment_amount',
|
||||
'balance_amount'));
|
||||
}
|
||||
}
|
||||
3
views/charges/index.ctp
Normal file
3
views/charges/index.ctp
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="charges index">
|
||||
<?php echo $this->element('charges', array('heading' => '<h2>'.$heading.'</h2>')) ?>
|
||||
</div>
|
||||
84
views/charges/view.ctp
Normal file
84
views/charges/view.ctp
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<div class="charges 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);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Charge Info
|
||||
*/
|
||||
|
||||
$rows = array(array('ID', $charge['Charge']['id']),
|
||||
array('Date', datefmt($charge['Charge']['charge_date'])),
|
||||
array('Through', datefmt($charge['Charge']['charge_to_date'])),
|
||||
array('Due', datefmt($charge['Charge']['due_date'])),
|
||||
array('Type', $charge['ChargeType']['name']),
|
||||
array('Lease', '#'.$charge['Lease']['number']),
|
||||
array('Amount', currency($charge['Charge']['amount'])),
|
||||
array('Tax', currency($charge['Charge']['tax'])),
|
||||
array('Total', currency($charge['Charge']['total'])),
|
||||
array('Comment', $charge['Charge']['comment']));
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item charge detail',
|
||||
'caption' => 'Charge Info',
|
||||
'rows' => $rows,
|
||||
'column_class' => array('field', 'value')));
|
||||
|
||||
|
||||
?>
|
||||
<DIV CLASS="infobox charge">
|
||||
<DIV CLASS="summary grand payment">
|
||||
Amount Received: <?php echo currency($paymentAmount); ?>
|
||||
</DIV>
|
||||
<DIV CLASS="summary grand balance">
|
||||
Amount Owing: <?php echo currency($balanceAmount); ?>
|
||||
</DIV>
|
||||
</DIV>
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Receipts
|
||||
*/
|
||||
|
||||
$headers = array('ID', 'Timestamp', 'Comment', 'Applied');
|
||||
$rows = array();
|
||||
$running_total = 0;
|
||||
foreach($charge['Receipt'] AS $receipt) {
|
||||
$amount = $receipt['ChargesReceipt']['amount'];
|
||||
$running_total += $amount;
|
||||
$rows[] = array('#'.$receipt['id'],
|
||||
datefmt($receipt['stamp']),
|
||||
$receipt['comment'],
|
||||
currency($receipt['ChargesReceipt']['amount']),
|
||||
//currency($running_total)
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item receipt list',
|
||||
'caption' => 'Receipts towards Charge',
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $headers));
|
||||
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
68
views/elements/charges.ctp
Normal file
68
views/elements/charges.ctp
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Charges',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', 'Date', 'Due', 'Type', 'Lease', '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('Date', 'charge_date'),
|
||||
$paginator->sort('Due', 'due_date'),
|
||||
$paginator->sort('Type', 'charge_type'),
|
||||
$paginator->sort('Lease', 'number'),
|
||||
$paginator->sort('total'),
|
||||
$paginator->sort('comment'));
|
||||
} else {
|
||||
$headers = $headers_manual;
|
||||
}
|
||||
|
||||
|
||||
$rows = array();
|
||||
foreach ($charges as $charge) {
|
||||
$rows[] = array($html->link($charge['Charge']['id'],
|
||||
array('controller' => 'charges',
|
||||
'action' => 'view',
|
||||
$charge['Charge']['id'])),
|
||||
datefmt($charge['Charge']['charge_date']),
|
||||
datefmt($charge['Charge']['due_date']),
|
||||
$charge['ChargeType']['name'],
|
||||
'#'.$charge['Lease']['number'],
|
||||
currency($charge['Charge']['total']),
|
||||
$charge['Charge']['comment'],
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item charge 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");
|
||||
}
|
||||
@@ -5,6 +5,20 @@ if (isset($heading))
|
||||
else
|
||||
echo '<h2>'.__('Receipts',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', 'Timestamp', 'Comment');
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
@@ -23,7 +37,7 @@ foreach ($receipts as $receipt) {
|
||||
array('controller' => 'receipts',
|
||||
'action' => 'view',
|
||||
$receipt['Receipt']['id'])),
|
||||
$receipt['Receipt']['stamp'],
|
||||
datefmt($receipt['Receipt']['stamp']),
|
||||
$receipt['Receipt']['comment']);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ function datefmt($date) {
|
||||
* Receipt Info
|
||||
*/
|
||||
|
||||
$rows = array(array('Timestamp', $receipt['Receipt']['stamp']),
|
||||
$rows = array(array('ID', $receipt['Receipt']['id']),
|
||||
array('Timestamp', datefmt($receipt['Receipt']['stamp'])),
|
||||
array('Comment', $receipt['Receipt']['comment']));
|
||||
|
||||
echo $this->element('table',
|
||||
|
||||
Reference in New Issue
Block a user