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:
abijah
2009-06-06 20:18:56 +00:00
parent ce24abc812
commit 677458e942
52 changed files with 2367 additions and 1469 deletions

View File

@@ -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");
}
?>