Moved the contact info into the contacts controller.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@20 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-05-28 07:12:32 +00:00
parent ffe04ed6fd
commit 4923712238
6 changed files with 87 additions and 340 deletions

View File

@@ -0,0 +1,21 @@
<?php
class ContactsController extends AppController {
var $helpers = array('Html');
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>''));
}
$this->Contact->recursive = 4;
$this->Contact->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease')));
$this->Contact->Lease->Charge->unbindModel(array('belongsTo' => array('Lease')));
$this->Contact->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge')));
$this->Contact->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt')));
$this->set('tenant', $this->Contact->read(null, $id));
}
}
?>

View File

@@ -1,36 +0,0 @@
<?php
class TransactionsController extends AppController {
var $helpers = array('Html');
var $uses = array('Contact', 'Charge', 'Payment', 'Receipt');
function ledger($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>''));
}
$this->Charge->recursive = 0;
//$ledgers = array($this->Charge->read(null, $id));
$this->set('ledgers', $this->Charge->find('all'));
//$this->set(compact('ledgers', 'tables'));
}
function contact($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>''));
}
$this->Contact->recursive = 4;
$this->Contact->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease')));
$this->Contact->Lease->Charge->unbindModel(array('belongsTo' => array('Lease')));
$this->Contact->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge')));
$this->Contact->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt')));
//$ledgers = array($this->Charge->read(null, $id));
//$this->set('ledgers', $this->Contact->Lease->Charge->find('all'));
//$this->set(compact('ledgers', 'tables'));
$this->set('tenant', $this->Contact->read(null, $id));
}
}
?>

View File

@@ -0,0 +1,66 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="contacts view">
<h2><?php __('Contact'); ?></h2>
<?php
function currency($number) {
if ($number < 0) {
return "($ " . number_format(-1*$number, 2) . ")";
} else {
return "$ " . number_format($number, 2);
}
}
$rows = array();
foreach($tenant['Contact'] AS $col => $val) {
$rows[] = array(array($col, 'width=1%'), $val);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Tenant Info</CAPTION>' . "\n");
echo $html->tableCells($rows, null, array('class' => "altrow"));
echo('</table>' . "\n");
$grand_total = 0;
foreach($tenant['Lease'] AS $lease) {
$headers = array('Date', /*'Through',*/ /*'Charge/Receipt'*/'ID', 'Type', 'Comment', 'Amount', 'Total');
$rows = array();
$running_total = 0;
foreach($lease['Charge'] AS $charge) {
$amount = $charge['total'];
$running_total += $amount;
$rows[] = array(date_format(date_create($charge['charge_date']), 'm-d-Y') . ' - ' .
date_format(date_create($charge['charge_to_date']), 'm-d-Y'),
'#'.$charge['id'],
$charge['ChargeType']['name'],
$charge['comment'],
currency($amount),
currency($running_total));
foreach ($charge['Receipt'] AS $receipt) {
$amount = -1 * $receipt['ChargesReceipt']['amount'];
$running_total += $amount;
$rows[] = array(' -- ' .date_format(date_create($receipt['stamp']), 'm-d-Y'),
//null,
'#'.$receipt['id'],
'Receipt',
$receipt['comment'],
currency($amount),
currency($running_total));
}
}
$grand_total += $running_total;
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease #'.$lease['number'].' (Unit '.$lease['Unit']['name'].')</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"));
echo('</table>' . "\n");
}
?>
<DIV ALIGN=RIGHT><H3>Grand Total: <?php echo currency($grand_total); ?></H3></DIV>
</div>

View File

@@ -1,193 +0,0 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="contacts view">
<h2><?php __('Contact'); ?></h2>
<?php
function currency($number) {
if ($number < 0)
return "($ " . number_format(-1*$number, 2) . ")";
else
return "$ " . number_format($number, 2);
}
function phone($phone) {
$phone = preg_replace("/\D/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/(\d{3})(\d{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/(\d{3})(\d{3})(\d{4})/", "$1-$2-$3", $phone);
else
return $phone;
}
function datefmt($date) {
$date_fmt = 'm/d/Y';
return ($date
? date_format(date_create($date), $date_fmt)
: null);
}
/**********************************************************************
* Tenant Info
*/
$rows = array();
foreach($tenant['Contact'] AS $col => $val) {
$rows[] = array(array($col, 'width=1%'), $val);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Tenant Info</CAPTION>' . "\n");
echo $html->tableCells(array(array('Name', $tenant['Contact']['display_name']),
array('Company', $tenant['Contact']['company_name']),
array('SSN', $tenant['Contact']['id_federal']),
array('ID', $tenant['Contact']['id_num']
. ($tenant['Contact']['id_state']
? " - ".$tenant['Contact']['id_state']
: ""))),
null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
/**********************************************************************
* Phones
*/
$headers = array('Location', 'Preference', 'Type', 'Phone', 'Extension', 'Comment');
$rows = array();
foreach($tenant['ContactPhone'] AS $phone) {
$rows[] = array($phone['ContactsMethod']['type'],
$phone['ContactsMethod']['preference'],
$phone['type'],
phone($phone['phone']),
$phone['ext'],
$phone['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Phone</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
/**********************************************************************
* Emails
*/
$headers = array('Location', 'Preference', 'Email', 'Comment');
$rows = array();
foreach($tenant['ContactEmail'] AS $email) {
$rows[] = array($email['ContactsMethod']['type'],
$email['ContactsMethod']['preference'],
$email['email'],
$email['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Email</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
/**********************************************************************
* Addresses
*/
$headers = array('Location', 'Preference', 'Address', 'City', 'State', 'Zip', 'Country', 'Comment');
$rows = array();
foreach($tenant['ContactAddress'] AS $address) {
$rows[] = array($address['ContactsMethod']['type'],
$address['ContactsMethod']['preference'],
$address['address'],
$address['city'],
$address['state'],
$address['postcode'],
$address['country'],
$address['comment']);
}
if (count($rows)) {
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Address</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
/**********************************************************************
* Lease History
*/
$headers = array('Lease', 'Unit', 'Signed', 'Move-In', 'Move-Out', 'Rent', 'Deposit', 'Comment');
$rows = array();
foreach($tenant['Lease'] AS $lease) {
$rows[] = array('#'.$lease['id'],
$lease['Unit']['name'],
datefmt($lease['lease_date']),
datefmt($lease['movein_date']),
datefmt($lease['moveout_date']),
$lease['amount'],
$lease['deposit'],
$lease['comment']);
}
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease History</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
/**********************************************************************
* Ledger History
*/
$security_deposit = 0;
$grand_total = 0;
foreach($tenant['Lease'] AS $lease) {
$headers = array('Date', /*'Through',*/ /*'Charge/Receipt'*/'ID', 'Type', 'Comment', 'Amount', 'Total');
$rows = array();
$running_total = 0;
foreach($lease['Charge'] AS $charge) {
$amount = $charge['total'];
$running_total += $amount;
$rows[] = array(datefmt($charge['charge_date']) .' - '. datefmt($charge['charge_to_date']),
'#'.$charge['id'],
$charge['ChargeType']['name'],
$charge['comment'],
currency($amount),
currency($running_total));
foreach ($charge['Receipt'] AS $receipt) {
$amount = -1 * $receipt['ChargesReceipt']['amount'];
$running_total += $amount;
// REVISIT <AP> 20090527:
// Using hardcoded value for security deposit... can't be good!
if ($charge['charge_type_id'] == 1)
$security_deposit += $receipt['ChargesReceipt']['amount'];
$rows[] = array(' -- ' . datefmt($receipt['stamp']),
'#'.$receipt['id'],
'Payment/Receipt',
$receipt['comment'],
currency($amount),
currency($running_total));
}
}
$grand_total += $running_total;
echo('<table cellpadding="0" cellspacing="0">' . "\n");
echo(' <CAPTION>Lease #'.$lease['number'].' ('.$lease['Unit']['name'].')</CAPTION>' . "\n");
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"), false, false);
echo('</table>' . "\n");
}
?>
<DIV ALIGN=RIGHT><H3>Total Security Deposit: <?php echo currency($security_deposit); ?></H3></DIV>
<DIV ALIGN=RIGHT><H3>Outstanding Balance: <?php echo currency($grand_total); ?></H3></DIV>
</div>

View File

@@ -1,53 +0,0 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="ledgers view">
<h2><?php __('Ledgers'); ?></h2>
<?php
foreach($ledgers AS $ledger) {
foreach ($ledger AS $tablename => $table) {
if (array_key_exists(0, $table)) {
// Horizontal table (multiple items)
$headers = array_keys($table[0]);
//$rows = array_map('array_values', $table);
$rows = array();
//echo("<PRE>table:\n"); print_r($table); echo("</PRE>\n");
foreach ($table as $row) {
//echo("<PRE>row:\n"); print_r($row); echo("</PRE>\n");
$rows[] = array_values($row);
}
}
else {
// Vertical table (one item)
$headers = array('Field', 'Value');
$rows = array();
foreach ($table as $col => $val) {
$rows[] = array($col, $val);
}
}
foreach($rows AS &$row) {
foreach ($row AS &$cell) {
if (is_array($cell))
$cell = "&lt;ARRAY&gt;";
}
}
//echo("<PRE>headers:\n"); print_r($headers); echo("</PRE>\n");
//echo("<PRE>rows:\n"); print_r($rows); echo("</PRE>\n");
?>
<table cellpadding="0" cellspacing="0">
<CAPTION><?php echo $tablename ?></CAPTION>
<?php
echo $html->tableHeaders($headers);
echo $html->tableCells($rows, null, array('class' => "altrow"));
?>
</table>
<?php
}
}
?>
</div>

View File

@@ -1,58 +0,0 @@
<div class="ledgers view">
<h2><?php __('Ledgers'); ?></h2>
<table cellpadding="0" cellspacing="0">
<?php
if (isset($paginator)) {
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
$cells = array($paginator->sort('id'),
$paginator->sort('charge_type_id'),
$paginator->sort('lease_id'),
$paginator->sort('charge_date'),
$paginator->sort('charge_to_date'),
$paginator->sort('due_date'),
$paginator->sort('amount'),
$paginator->sort('tax'),
$paginator->sort('total'),
$paginator->sort('comment'));
} else {
$cells = array('Id', 'Type', 'Lease', 'Date', 'Through', 'Due', 'Amount', 'Tax', 'Total', 'Comment');
}
echo $html->tableHeaders($cells);
$cells = array();
foreach ($ledgers as $ledger) {
$cells[] = array($html->link($ledger['Charge']['id'],
array('controller' => 'transactions',
'action' => 'view',
$ledger['Charge']['id'])),
$ledger['Charge']['charge_type_id'],
$ledger['Charge']['lease_id'],
$ledger['Charge']['charge_date'],
$ledger['Charge']['charge_to_date'],
$ledger['Charge']['due_date'],
$ledger['Charge']['amount'],
$ledger['Charge']['tax'],
$ledger['Charge']['total'],
$ledger['Charge']['comment']);
}
echo $html->tableCells($cells, null, array('class' => "altrow"));
?>
</table>
<?php
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");
}
?>
</DIV>