I'm still in the middle of moving onto a ledger based system. However, I'm am now changing how transactions and entries relate back to the customer. I'll be using a ledger for each lease (for rent, late charges, security deposits, etc), and a ledger for each customer (for POS, non-specific deposits such as reservations or covering mulitple units, bad debt writeoff, and possibly customer credits, when not obviously lease specific). This coming change might not be in the right direction, so I want to capture the work as is right now. This change set is not fully functional. Many operations do work, but there are obviously transaction problems with units and customers.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@71 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
85
views/elements/accounts.ctp
Normal file
85
views/elements/accounts.ctp
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Accounts',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 = array('Name', 'Type', 'Ext. Name', 'Ext. Account', 'Entries', 'Debits', 'Credits', 'Balance', 'Comment');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($column_class, array('Debits', 'Credits', 'Balance')) AS $k => $v) {
|
||||
$column_class[$k] = 'currency';
|
||||
}
|
||||
|
||||
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('name'),
|
||||
$paginator->sort('type'),
|
||||
$paginator->sort('Ext. Name', 'external_name'),
|
||||
$paginator->sort('Ext. Account', 'external_account'),
|
||||
$paginator->sort('entries'),
|
||||
$paginator->sort('debits'),
|
||||
$paginator->sort('credits'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('comment'));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($accounts as $account) {
|
||||
$extra = null;
|
||||
if (isset($account[0])) {
|
||||
$extra = $account[0];
|
||||
unset($account[0]);
|
||||
}
|
||||
if (isset($account['Account']))
|
||||
$account = $account['Account'];
|
||||
|
||||
if (isset($extra))
|
||||
$account = array_merge($account, $extra);
|
||||
|
||||
$rows[] = array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
$account['id'])),
|
||||
$account['type'],
|
||||
$account['external_name'],
|
||||
$account['external_account'],
|
||||
$account['entries'],
|
||||
currency($account['debits']),
|
||||
currency($account['credits']),
|
||||
currency($account['balance']),
|
||||
$account['comment'],
|
||||
);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item account list',
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?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");
|
||||
}
|
||||
@@ -2,44 +2,57 @@
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Contacts',true).'</h2>';
|
||||
|
||||
$headers_manual = array('Id', 'Last Name', 'First Name', 'Company', 'Comment');
|
||||
$headers_manual = array_merge(array('Id', 'Last Name', 'First Name', 'Company'),
|
||||
isset($contacts[0]['ContactsCustomer']) ? array('Type', 'Active') : array(),
|
||||
array('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('last_name'),
|
||||
$paginator->sort('first_name'),
|
||||
$paginator->sort('company_name'),
|
||||
//$paginator->sort('unit_id'),
|
||||
$paginator->sort('comment'));
|
||||
$headers = array_merge(array($paginator->sort('id'),
|
||||
$paginator->sort('last_name'),
|
||||
$paginator->sort('first_name'),
|
||||
$paginator->sort('company_name')),
|
||||
(isset($contacts[0]['ContactsCustomer'])
|
||||
? array($paginator->sort('type'),
|
||||
$paginator->sort('active'))
|
||||
: array()),
|
||||
array($paginator->sort('comment')));
|
||||
} else {
|
||||
$headers = $headers_manual;
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($contacts as $contact) {
|
||||
$rows[] = array($html->link($contact['Contact']['id'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['Contact']['id'])),
|
||||
$html->link($contact['Contact']['last_name'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['Contact']['id'])),
|
||||
$html->link($contact['Contact']['first_name'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['Contact']['id'])),
|
||||
$contact['Contact']['company_name'],
|
||||
$contact['Contact']['comment']);
|
||||
if (isset($contact['Contact']))
|
||||
$contact = $contact['Contact'];
|
||||
|
||||
$rows[] = array_merge(array($html->link($contact['id'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['id'])),
|
||||
$html->link($contact['last_name'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['id'])),
|
||||
$html->link($contact['first_name'],
|
||||
array('controller' => 'contacts',
|
||||
'action' => 'view',
|
||||
$contact['id'])),
|
||||
$contact['company_name']),
|
||||
(isset($contact['ContactsCustomer'])
|
||||
? array($contact['ContactsCustomer']['type'],
|
||||
$contact['ContactsCustomer']['active'],
|
||||
$contact['ContactsCustomer']['comment'])
|
||||
: array($contact['comment'])));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item contact list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $headers_manual));
|
||||
|
||||
@@ -3,46 +3,39 @@
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
else
|
||||
echo '<h2>'.__('Receipts',true).'</h2>';
|
||||
echo '<h2>'.__('Customers',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');
|
||||
$headers_manual = array('Id', 'Name', '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('name'),
|
||||
$paginator->sort('comment'));
|
||||
} else {
|
||||
$headers = $headers_manual;
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($receipts as $receipt) {
|
||||
$rows[] = array($html->link($receipt['Receipt']['id'],
|
||||
array('controller' => 'receipts',
|
||||
foreach ($customers as $customer) {
|
||||
if (isset($customer['Customer']))
|
||||
$customer = $customer['Customer'];
|
||||
|
||||
$rows[] = array($html->link($customer['id'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$receipt['Receipt']['id'])),
|
||||
datefmt($receipt['Receipt']['stamp']),
|
||||
$receipt['Receipt']['comment']);
|
||||
$customer['id'])),
|
||||
$html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
$customer['comment']);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item receipt list',
|
||||
array('class' => 'item customer list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $headers_manual));
|
||||
@@ -1,314 +1,80 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
/* if (isset($heading)) */
|
||||
/* echo $heading; */
|
||||
/* else */
|
||||
/* echo '<h2>'.__('Payments',true).'</h2>'; */
|
||||
|
||||
?>
|
||||
|
||||
<div class="ledger collection">
|
||||
<!-- <span class="title">$caption</span> -->
|
||||
|
||||
<?php
|
||||
; // Alignment purposes only
|
||||
|
||||
// Charges Only
|
||||
// Payments Only
|
||||
// Mixture of both (by date)
|
||||
// Match both (payments match charges)
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Charges Only
|
||||
*/
|
||||
if (isset($ledger['charges'])) {
|
||||
$headers = array('Charge', 'Date', 'Through', 'Type', 'Comment', 'Amount', 'Balance', 'Total');
|
||||
|
||||
$rows = array();
|
||||
$row_class = array();
|
||||
$running_total = 0;
|
||||
foreach($lease['Charge'] AS $charge) {
|
||||
$amount = $charge['total'];
|
||||
|
||||
$balance = $amount;
|
||||
foreach ($charge['Receipt'] AS $receipt)
|
||||
$balance -= $receipt['ChargesReceipt']['amount'];
|
||||
|
||||
$running_total += $balance;
|
||||
|
||||
$rows[] = array($html->link('#'.$charge['id'],
|
||||
array('controller' => 'charges',
|
||||
'action' => 'view',
|
||||
$charge['id'])),
|
||||
datefmt($charge['charge_date']),
|
||||
datefmt($charge['charge_to_date']),
|
||||
$charge['ChargeType']['name'],
|
||||
$charge['comment'],
|
||||
currency($amount),
|
||||
currency($balance),
|
||||
//currency($amount - $paid));
|
||||
currency($running_total));
|
||||
|
||||
$row_class[] = 'charge';
|
||||
}
|
||||
|
||||
echo ('<div class="ledger history charges">' . "\n");
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => $caption,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'row_class' => $row_class,
|
||||
'column_class' => $headers));
|
||||
echo ('</div>' . "\n");
|
||||
$headers = array('Transaction', 'Entry', 'Date', 'Customer', 'Comment', 'Debit', 'Credit', 'Total');
|
||||
$column_class = $headers;
|
||||
foreach (array_intersect($column_class, array('Transaction', 'Entry')) AS $k => $v) {
|
||||
$column_class[$k] = array($column_class[$k], 'id');
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Receipts Only
|
||||
*/
|
||||
|
||||
if (isset($ledger['receipts'])) {
|
||||
$headers = array('Receipt', 'Date', 'Comment', 'Amount', 'Balance', 'Total');
|
||||
|
||||
$receipts = array();
|
||||
foreach ($lease['Charge'] AS $charge) {
|
||||
foreach($charge['Receipt'] AS $receipt) {
|
||||
if (!isset($receipts[$receipt['id']])) {
|
||||
$receipts[$receipt['id']] = $receipt;
|
||||
$receipts[$receipt['id']]['amount'] = 0;
|
||||
$receipts[$receipt['id']]['charge'] = 0;
|
||||
foreach($receipt['Payment'] AS $payment)
|
||||
$receipts[$receipt['id']]['amount'] += $payment['amount'];
|
||||
unset($receipts[$receipt['id']]['ChargesReceipt']);
|
||||
unset($receipts[$receipt['id']]['Payment']);
|
||||
}
|
||||
$receipts[$receipt['id']]['charge'] += $receipt['ChargesReceipt']['amount'];
|
||||
}
|
||||
}
|
||||
|
||||
usort($receipts,
|
||||
create_function('$a, $b',
|
||||
'$adate = TimeHelper::toUnix(isset($a["charge_date"]) ? $a["charge_date"] : $a["stamp"]); ' .
|
||||
'$bdate = TimeHelper::toUnix(isset($b["charge_date"]) ? $b["charge_date"] : $b["stamp"]); ' .
|
||||
'return strcmp($adate, $bdate);')
|
||||
);
|
||||
|
||||
$rows = array();
|
||||
$row_class = array();
|
||||
$running_total = 0;
|
||||
|
||||
foreach ($receipts AS $receipt) {
|
||||
$amount = $receipt['amount'];
|
||||
$balance = $amount - $receipt['charge'];
|
||||
$running_total += $balance;
|
||||
|
||||
$rows[] = array($html->link('#'.$receipt['id'],
|
||||
array('controller' => 'receipts',
|
||||
'action' => 'view',
|
||||
$receipt['id'])),
|
||||
datefmt($receipt['stamp']),
|
||||
$receipt['comment'],
|
||||
currency($amount),
|
||||
currency($balance),
|
||||
currency($running_total));
|
||||
|
||||
$row_class[] = 'receipt';
|
||||
}
|
||||
|
||||
echo ('<div class="ledger history receipts">' . "\n");
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => $caption,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'row_class' => $row_class,
|
||||
'column_class' => $headers));
|
||||
echo ('</div>' . "\n");
|
||||
foreach (array_intersect($column_class, array('Debits', 'Credits', 'Total')) AS $k => $v) {
|
||||
$column_class[$k] = array($column_class[$k], 'currency');
|
||||
}
|
||||
/* if (isset($paginator)) { */
|
||||
/* echo $paginator->counter(array( */
|
||||
/* 'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true))); */
|
||||
|
||||
/* $headers = array('Receipt', 'Date', 'Comment', 'Amount', 'Balance', 'Total'); */
|
||||
|
||||
/* $rows = array(); */
|
||||
/* $row_class = array(); */
|
||||
/* $running_total = 0; */
|
||||
/* $odd = 0; */
|
||||
/* foreach($lease['Receipt'] AS $charge) { */
|
||||
/* $amount = $charge['total']; */
|
||||
|
||||
/* $balance = $amount; */
|
||||
/* foreach ($charge['Receipt'] AS $receipt) */
|
||||
/* $balance -= $receipt['ChargesReceipt']['amount']; */
|
||||
|
||||
/* $running_total += $balance; */
|
||||
|
||||
|
||||
/* $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']; */
|
||||
|
||||
/* foreach ($charge['Receipt'] AS $receipt) { */
|
||||
/* $amount = -1 * $receipt['ChargesReceipt']['amount']; */
|
||||
/* $running_total += $amount; */
|
||||
/* $rows[] = array($html->link('#'.$receipt['id'], */
|
||||
/* array('controller' => 'receipts', */
|
||||
/* 'action' => 'view', */
|
||||
/* $receipt['id'])), */
|
||||
/* datefmt($receipt['stamp']), */
|
||||
/* $receipt['comment'], */
|
||||
/* currency($amount), */
|
||||
/* currency($running_total)); */
|
||||
/* $row_class[] = array('receipt', ($odd % 2) ? 'oddrow' : 'evnrow'); */
|
||||
/* } */
|
||||
|
||||
/* $rows[] = array($html->link('#'.$charge['id'], */
|
||||
/* array('controller' => 'charges', */
|
||||
/* 'action' => 'view', */
|
||||
/* $charge['id'])), */
|
||||
/* datefmt($charge['charge_date']), */
|
||||
/* datefmt($charge['charge_to_date']), */
|
||||
/* $charge['ChargeType']['name'], */
|
||||
/* $charge['comment'], */
|
||||
/* currency($amount), */
|
||||
/* currency($balance), */
|
||||
/* //currency($amount - $paid)); */
|
||||
/* currency($running_total)); */
|
||||
|
||||
/* $row_class[] = array('charge', (++$odd % 2) ? 'oddrow' : 'evnrow'); */
|
||||
/* $headers = array($paginator->sort('Transaction', 'transaction_id'), */
|
||||
/* $paginator->sort('entry_id'), */
|
||||
/* $paginator->sort('Date', 'stamp'), */
|
||||
/* $paginator->sort('customer_id'), */
|
||||
/* $paginator->sort('comment'), */
|
||||
/* $paginator->sort('debit'), */
|
||||
/* $paginator->sort('credit'), */
|
||||
/* $paginator->sort('total')); */
|
||||
/* } */
|
||||
|
||||
/* echo ('<div class="ledger history charges">' . "\n"); */
|
||||
/* echo $this->element('table', */
|
||||
/* array('class' => 'item ledger list', */
|
||||
/* 'caption' => $caption */
|
||||
/* 'suppress_alternate_rows' => true, */
|
||||
/* 'headers' => $headers, */
|
||||
/* 'rows' => $rows, */
|
||||
/* 'row_class' => $row_class, */
|
||||
/* 'column_class' => $headers)); */
|
||||
/* echo ('</div>' . "\n"); */
|
||||
$rows = array();
|
||||
$running_total = 0;
|
||||
foreach($entries AS $entry) {
|
||||
$transaction = $entry['Transaction'];
|
||||
$customer = $entry['Customer'];
|
||||
|
||||
$credit = $debit = null;
|
||||
$running_total += $entry['balance'];
|
||||
|
||||
/**********************************************************************
|
||||
* Mixture
|
||||
*/
|
||||
if (isset($entry['debit']))
|
||||
$debit = $entry['debit'];
|
||||
if (isset($entry['credit']))
|
||||
$credit = $entry['credit'];
|
||||
|
||||
if (isset($ledger['mix'])) {
|
||||
$headers = array(/*'Charge/Receipt'*/'ID', 'Date', /*'Through',*/ 'Type', 'Comment', 'Amount', 'Total');
|
||||
// Now that we've extracted top level 'entry' data
|
||||
// move our variable to the meat of 'LedgerEntry' for clarity
|
||||
$entry = $entry['LedgerEntry'];
|
||||
|
||||
/* $mix = array_merge($lease['Charge'], $receipts); */
|
||||
/* usort($mix, */
|
||||
/* create_function('$a, $b', */
|
||||
/* '$adate = TimeHelper::toUnix(isset($a["charge_date"]) ? $a["charge_date"] : $a["stamp"]); ' . */
|
||||
/* '$bdate = TimeHelper::toUnix(isset($b["charge_date"]) ? $b["charge_date"] : $b["stamp"]); ' . */
|
||||
/* 'return strcmp($adate, $bdate);') */
|
||||
/* ); */
|
||||
|
||||
$rows = array();
|
||||
$row_class = array();
|
||||
$running_total = 0;
|
||||
|
||||
foreach ($transactions AS $transaction) {
|
||||
$transaction_date = datefmt($transaction['stamp']);
|
||||
if (isset($transaction['through_date']))
|
||||
$transaction_date .= ' - '. datefmt($transaction['through_date']);
|
||||
|
||||
$comment = $transaction['comment'];
|
||||
|
||||
foreach ($transaction['Entry'] AS $entry) {
|
||||
if ($entry['DebitAccount']['name'] === 'A/R') {
|
||||
$name = $entry['CreditAccount']['name'];
|
||||
$amount = $entry['amount'];
|
||||
$class = 'charge';
|
||||
}
|
||||
elseif ($entry['CreditAccount']['name'] === 'A/R') {
|
||||
$name = 'Payment';
|
||||
$amount = -1 * $entry['amount'];
|
||||
$class = 'payment';
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
$running_total += $amount;
|
||||
$rows[] = array($html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id'])),
|
||||
$transaction_date,
|
||||
$name,
|
||||
$comment,
|
||||
currency($amount),
|
||||
currency($running_total));
|
||||
$row_class[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
echo ('<div class="ledger history mix">' . "\n");
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => $caption,
|
||||
//'suppress_alternate_rows' => true,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'row_class' => $row_class,
|
||||
'column_class' => $headers));
|
||||
echo ('</div>' . "\n");
|
||||
$rows[] = array($html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id'])),
|
||||
$html->link('#'.$entry['id'],
|
||||
array('controller' => 'ledger_entries',
|
||||
'action' => 'view',
|
||||
$entry['id'])),
|
||||
datefmt($transaction['stamp']),
|
||||
$html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
comment(array($transaction['comment'], $entry['comment'])),
|
||||
currency($debit),
|
||||
currency($credit),
|
||||
currency($running_total)
|
||||
);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Match
|
||||
*/
|
||||
echo $this->element('table',
|
||||
array('class' => 'item account ledger list',
|
||||
'caption' => $caption,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
if (isset($ledger['match'])) {
|
||||
$headers = array(/*'Charge/Receipt'*/'ID', 'Date', /*'Through',*/ 'Type', 'Comment', 'Amount', 'Total');
|
||||
/* 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"); */
|
||||
/* } */
|
||||
|
||||
$rows = array();
|
||||
$row_class = array();
|
||||
$running_total = 0;
|
||||
$odd = 0;
|
||||
foreach($lease['Charge'] AS $charge) {
|
||||
$amount = $charge['total'];
|
||||
$running_total += $amount;
|
||||
$rows[] = array($html->link('#'.$charge['id'],
|
||||
array('controller' => 'charges',
|
||||
'action' => 'view',
|
||||
$charge['id'])),
|
||||
datefmt($charge['charge_date']) .' - '. datefmt($charge['charge_to_date']),
|
||||
$charge['ChargeType']['name'],
|
||||
$charge['comment'],
|
||||
currency($amount),
|
||||
currency($running_total));
|
||||
$row_class[] = array('charge', (++$odd % 2) ? 'oddrow' : 'evnrow');
|
||||
|
||||
foreach ($charge['Receipt'] AS $receipt) {
|
||||
$amount = -1 * $receipt['ChargesReceipt']['amount'];
|
||||
$running_total += $amount;
|
||||
$rows[] = array($html->link('#'.$receipt['id'],
|
||||
array('controller' => 'receipts',
|
||||
'action' => 'view',
|
||||
$receipt['id'])),
|
||||
' -- ' . datefmt($receipt['stamp']),
|
||||
'Payment Applied',
|
||||
$receipt['comment'],
|
||||
currency($amount),
|
||||
currency($running_total));
|
||||
$row_class[] = array('receipt', ($odd % 2) ? 'oddrow' : 'evnrow');
|
||||
}
|
||||
}
|
||||
|
||||
echo ('<div class="ledger history match">' . "\n");
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => $caption,
|
||||
'suppress_alternate_rows' => true,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'row_class' => $row_class,
|
||||
'column_class' => $headers));
|
||||
echo ('</div>' . "\n");
|
||||
}
|
||||
?>
|
||||
|
||||
77
views/elements/ledgers.ctp
Normal file
77
views/elements/ledgers.ctp
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Ledgers',true).'</h2>';
|
||||
|
||||
$headers = array_merge(array('Name'),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array('Account')
|
||||
: array()),
|
||||
array('Entries', 'Debits', 'Credits', 'Balance', 'Closed', 'Comment'));
|
||||
$column_class = array();
|
||||
foreach (array_intersect($column_class, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'comment';
|
||||
}
|
||||
|
||||
if (isset($paginator)) {
|
||||
echo $paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records (%start% - %end%) of %count% total', true)));
|
||||
|
||||
$headers = array_merge(array($paginator->sort('name')),
|
||||
(isset($ledgers[0]['Account'])
|
||||
? array($paginator->sort('Account', 'Account.name'))
|
||||
: array()),
|
||||
array($paginator->sort('entries'),
|
||||
$paginator->sort('debits'),
|
||||
$paginator->sort('credits'),
|
||||
$paginator->sort('balance'),
|
||||
$paginator->sort('closed'),
|
||||
$paginator->sort('comment')));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($ledgers as $ledger) {
|
||||
if (isset($ledger[0]))
|
||||
$ledger = array_merge($ledger[0], array_diff_key($ledger, array(0=>1)));
|
||||
if (isset($ledger['Ledger']))
|
||||
$ledger = array_merge($ledger['Ledger'], array_diff_key($ledger, array('Ledger'=>1)));
|
||||
|
||||
if (isset($ledger['Account']))
|
||||
$account = $ledger['Account'];
|
||||
|
||||
$rows[] = array_merge(array($html->link($ledger['name'],
|
||||
array('controller' => 'ledgers',
|
||||
'action' => 'view',
|
||||
$ledger['id']))),
|
||||
(isset($ledger['Account'])
|
||||
? array($html->link($account['name'],
|
||||
array('controller' => 'accounts',
|
||||
'action' => 'view',
|
||||
$account['id'])))
|
||||
: array()),
|
||||
array($ledger['entries'],
|
||||
currency($ledger['debits']),
|
||||
currency($ledger['credits']),
|
||||
currency($ledger['balance']),
|
||||
$ledger['closed'] ? 'Closed' : 'Open',
|
||||
$ledger['comment']));
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item ledger list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
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");
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?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'],
|
||||
$html->link('#'.$payment['Receipt']['id'],
|
||||
array('controller' => 'receipts',
|
||||
'action' => 'view',
|
||||
$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");
|
||||
}
|
||||
@@ -32,7 +32,7 @@ if (isset($rows) && is_array($rows) && count($rows)) {
|
||||
if (!is_array($rca))
|
||||
$rca = array($rca);
|
||||
foreach ($rca AS &$rc)
|
||||
$rc = preg_replace("/ /", "-", strtolower($rc));
|
||||
$rc = preg_replace("/ /", "-", preg_replace('/\./', '', strtolower($rc)));
|
||||
}
|
||||
|
||||
// Same prework for column_class
|
||||
@@ -40,7 +40,7 @@ if (isset($rows) && is_array($rows) && count($rows)) {
|
||||
if (!is_array($cca))
|
||||
$cca = array($cca);
|
||||
foreach ($cca AS &$cc)
|
||||
$cc = preg_replace("/ /", "-", strtolower($cc));
|
||||
$cc = preg_replace("/ /", "-", preg_replace('/\./', '', strtolower($cc)));
|
||||
}
|
||||
|
||||
// Associate each cell with the appropriate class(es).
|
||||
|
||||
65
views/elements/transactions.ctp
Normal file
65
views/elements/transactions.ctp
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php /* -*- mode:PHP -*- */
|
||||
|
||||
if (isset($heading))
|
||||
echo $heading;
|
||||
elseif (!isset($caption))
|
||||
echo '<h2>'.__('Transactions',true).'</h2>';
|
||||
|
||||
$headers = array('Id', 'Timestamp', 'Comment');
|
||||
$column_class = array();
|
||||
foreach (array_intersect($headers, array('Comment')) AS $k => $v) {
|
||||
$column_class[$k] = 'comment';
|
||||
}
|
||||
foreach (array_intersect($headers, array('Id')) AS $k => $v) {
|
||||
$column_class[$k] = 'id';
|
||||
}
|
||||
|
||||
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('customer_id'),
|
||||
$paginator->sort('Timestamp', 'stamp'),
|
||||
$paginator->sort('Through', 'through_date'),
|
||||
$paginator->sort('Due', 'due_date'),
|
||||
$paginator->sort('comment'));
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($transactions as $transaction) {
|
||||
$customer = $transaction['Customer'];
|
||||
|
||||
if (isset($transaction['Transaction']))
|
||||
$transaction = $transaction['Transaction'];
|
||||
|
||||
$rows[] = array($html->link('#'.$transaction['id'],
|
||||
array('controller' => 'transactions',
|
||||
'action' => 'view',
|
||||
$transaction['id'])),
|
||||
$html->link($customer['name'],
|
||||
array('controller' => 'customers',
|
||||
'action' => 'view',
|
||||
$customer['id'])),
|
||||
datefmt($transaction['stamp']),
|
||||
datefmt($transaction['through_date']),
|
||||
datefmt($transaction['due_date']),
|
||||
$transaction['comment']);
|
||||
}
|
||||
|
||||
echo $this->element('table',
|
||||
array('class' => 'item transaction list',
|
||||
'caption' => isset($caption) ? $caption : null,
|
||||
'headers' => $headers,
|
||||
'rows' => $rows,
|
||||
'column_class' => $column_class));
|
||||
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user