Added a receipt controller to verify receipt data

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@60 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-01 07:24:51 +00:00
parent 8ea0822ed1
commit cdd274adf7
4 changed files with 289 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
<?php
class ReceiptsController extends AppController {
var $helpers = array('Html');
var $paginate = array('limit' => 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'));
}
}

View File

@@ -0,0 +1,44 @@
<?php /* -*- mode:PHP -*- */
if (isset($heading))
echo $heading;
else
echo '<h2>'.__('Receipts',true).'</h2>';
$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('<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/receipts/index.ctp Normal file
View File

@@ -0,0 +1,3 @@
<div class="receipts index">
<?php echo $this->element('receipts', array('heading' => '<h2>'.$heading.'</h2>')) ?>
</div>

109
views/receipts/view.ctp Normal file
View File

@@ -0,0 +1,109 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="receipts 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);
}
/**********************************************************************
* Receipt Info
*/
$rows = array(array('Timestamp', $receipt['Receipt']['stamp']),
array('Comment', $receipt['Receipt']['comment']));
echo $this->element('table',
array('class' => 'item receipt detail',
'caption' => 'Receipt Info',
'rows' => $rows,
'column_class' => array('field', 'value')));
?>
<DIV CLASS="infobox receipt">
<DIV CLASS="summary grand payment">
Amount Received: <?php echo currency($paymentAmount); ?>
</DIV>
<DIV CLASS="summary grand charge">
Amount Applied: <?php echo currency($chargeAmount); ?>
</DIV>
</DIV>
<?php
/**********************************************************************
* Payments
*/
$headers = array('ID', 'Type', 'Comment', 'Amount', /*'Total'*/);
$rows = array();
$running_total = 0;
foreach($receipt['Payment'] AS $payment) {
$amount = $payment['amount'];
$running_total += $amount;
$rows[] = array('#'.$payment['id'],
$payment['PaymentType']['name'],
$payment['comment'],
currency($payment['amount']),
//currency($running_total)
);
}
echo $this->element('table',
array('class' => 'item payment list',
'caption' => 'Payments in Receipt',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
/**********************************************************************
* Charges
*/
$headers = array('Date', 'ID', /*'Due',*/ 'Type', 'Lease', 'Comment', 'Amount' /*, 'Tax', 'Subtotal'*/, 'Applied', /*'Total'*/);
$rows = array();
$running_total = 0;
foreach($receipt['Charge'] AS $charge) {
$amount = $charge['total'];
$running_total += $amount;
$rows[] = array(datefmt($charge['charge_date']) .' - '. datefmt($charge['charge_to_date']),
'#'.$charge['id'],
//datefmt($charge['due_date']),
$charge['ChargeType']['name'],
'#'.$charge['Lease']['number'],
$charge['comment'],
//currency($charge['amount']),
//currency($charge['tax']),
currency($charge['total']),
currency($charge['ChargesReceipt']['amount']),
//currency($running_total)
);
}
echo $this->element('table',
array('class' => 'item charge list',
'caption' => 'Charges Applied Towards',
'headers' => $headers,
'rows' => $rows,
'column_class' => $headers));
?>
</div>