More changes. I just can't seem to come up with a solution that works that I like. The problem now, without invoice/receipt, is that one check cannot cleanly pay for two units.

git-svn-id: file:///svn-source/pmgr/branches/single_AR_20090622/site@182 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-24 00:33:39 +00:00
parent 009ea6b44d
commit 73eacdbcf2
10 changed files with 193 additions and 71 deletions

View File

@@ -344,29 +344,39 @@ class AppController extends Controller {
}
function jqGridDataOutputRecords(&$params, &$model, &$records) {
$model_alias = $model->alias;
$id = 'jqGrid_id';
$id_field = 'jqGrid_id';
foreach ($records AS $record) {
echo " <row id='{$record[$id]}'>\n";
foreach ($params['fields'] AS $field) {
$this->jqGridDataOutputRecord($params, $model, $record,
$record[$id_field], $params['fields']);
}
}
function jqGridDataOutputRecord(&$params, &$model, &$record, $id, $fields) {
echo " <row id='$id'>\n";
foreach ($fields AS $field) {
$this->jqGridDataOutputRecordField($params, $model, $record, $field);
}
echo " </row>\n";
}
function jqGridDataOutputRecordField(&$params, &$model, &$record, $field) {
if (preg_match("/\./", $field)) {
list($tbl, $col) = explode(".", $field);
$data = $record[$tbl][$col];
}
else {
$data = $record[$model_alias][$field];
$data = $record[$model->alias][$field];
}
$this->jqGridDataOutputRecordCell($params, $model, $record, $field, $data);
}
function jqGridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) {
// be sure to put text data in CDATA
if (preg_match("/^\d*$/", $data))
echo " <cell>$data</cell>\n";
else
echo " <cell><![CDATA[$data]]></cell>\n";
}
echo " </row>\n";
}
}
function jqGridDataFinalize(&$params) {
if ($params['debug']) {

View File

@@ -25,6 +25,14 @@ class LedgerEntriesController extends AppController {
* to jqGrid.
*/
function jqGridDataSetup(&$params) {
parent::jqGridDataSetup($params);
if (isset($params['custom']['ar_account'])) {
$params['custom']['account_id'] =
$this->LedgerEntry->DebitLedger->Account->accountReceivableAccountID();
}
}
function jqGridDataTables(&$params, &$model) {
$link =
array(// Models
@@ -87,6 +95,19 @@ class LedgerEntriesController extends AppController {
);
}
if (isset($params['custom']['account_id'])) {
$account_id = $params['custom']['account_id'];
$link['Ledger'] =
array('fields' => array('id', 'sequence'),
'conditions' => ("Ledger.id = IF(DebitLedger.account_id = $account_id," .
" LedgerEntry.credit_ledger_id," .
" LedgerEntry.debit_ledger_id)"),
'Account' => array(
'fields' => array('id', 'name'),
),
);
}
if (isset($params['custom']['reconcile_id'])) {
$ftype = $params['custom']['account_ftype'];
$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
@@ -102,11 +123,14 @@ class LedgerEntriesController extends AppController {
$ledger_id = (isset($params['custom']['ledger_id'])
? $params['custom']['ledger_id']
: null);
$account_id = (isset($params['custom']['account_id'])
? $params['custom']['account_id']
: null);
$account_type = (isset($params['custom']['account_type'])
? $params['custom']['account_type']
: null);
return $model->ledgerContextFields2($ledger_id, $account_type);
return $model->ledgerContextFields2($ledger_id, $account_id, $account_type);
}
function jqGridDataConditions(&$params, &$model) {
@@ -128,6 +152,13 @@ class LedgerEntriesController extends AppController {
$conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']);
}
if (isset($params['custom']['account_id'])) {
$conditions[] =
array('OR' =>
array(array('CreditAccount.id' => $params['custom']['account_id']),
array('DebitAccount.id' => $params['custom']['account_id'])));
}
if (isset($params['custom']['customer_id'])) {
$conditions[] =
array('Customer.id' => $params['custom']['customer_id']);
@@ -208,6 +239,32 @@ class LedgerEntriesController extends AppController {
return $order;
}
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
parent::jqGridRecordsPostProcess($params, $model, $records);
$subtotal = 0;
foreach ($records AS &$record) {
$amount = (isset($record['LedgerEntry']['balance'])
? $record['LedgerEntry']['balance']
: $record['LedgerEntry']['amount']);
$record['LedgerEntry']['subtotal'] = ($subtotal += $amount);
continue;
// Experiment to minimize columns by putting the monetary source
// as the Account, when available
if ($record['MonetarySource']['name'])
$record['Account']['name'] = $record['MonetarySource']['name'];
}
}
function jqGridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) {
/* if ($field === 'CreditAccount.name') { */
/* $data .= '-OK'; */
/* } */
parent::jqGridDataOutputRecordCell($params, $model, $record, $field, $data);
}
/**************************************************************************
**************************************************************************
@@ -247,6 +304,7 @@ class LedgerEntriesController extends AppController {
'conditions' => array('LedgerEntry.id' => $id),
));
pr($entry);
// Because 'DebitLedger' and 'CreditLedger' both relate to 'Account',
// CakePHP will not include them in the LedgerEntry->find (or so it

View File

@@ -86,7 +86,7 @@ class LedgerEntry extends AppModel {
return $fields;
}
function ledgerContextFields2($ledger_id = null, $account_type = null) {
function ledgerContextFields2($ledger_id = null, $account_id = null, $account_type = null) {
$fields = array('id', 'name', 'comment', 'amount');
if (isset($ledger_id)) {
@@ -95,20 +95,29 @@ class LedgerEntry extends AppModel {
$fields[] = ("IF(LedgerEntry.credit_ledger_id = $ledger_id," .
" SUM(LedgerEntry.amount), NULL) AS credit");
if (isset($account_type)) {
if (in_array($account_type, array('ASSET', 'EXPENSE')))
$ledger_type = 'debit';
else
$ledger_type = 'credit';
$fields[] = ("(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id," .
if (isset($account_id) || isset($account_type)) {
$Account = new Account();
$account_ftype = $Account->fundamentalType($account_id ? $account_id : $account_type);
$fields[] = ("(IF(LedgerEntry.{$account_ftype}_ledger_id = $ledger_id," .
" 1, -1) * SUM(LedgerEntry.amount)) AS balance");
}
}
elseif (isset($account_id)) {
$fields[] = ("IF(DebitLedger.account_id = $account_id," .
" SUM(LedgerEntry.amount), NULL) AS debit");
$fields[] = ("IF(CreditLedger.account_id = $account_id," .
" SUM(LedgerEntry.amount), NULL) AS credit");
$Account = new Account();
$account_ftype = ucfirst($Account->fundamentalType($account_id));
$fields[] = ("(IF({$account_ftype}Ledger.account_id = $account_id," .
" 1, -1) * SUM(LedgerEntry.amount)) AS balance");
}
return $fields;
}
function ledgerContextConditions($ledger_id, $account_type) {
if (isset($ledger_id)) {
return array

View File

@@ -69,6 +69,7 @@ echo $this->element('leases',
echo $this->element('ledger_entries',
array('caption' => 'Account',
'customer_id' => $customer['Customer']['id'],
'ar_account' => true,
));

View File

@@ -189,10 +189,14 @@ $jqGrid_setup = array_merge
jQuery(document).ready(function(){
currencyFormatter = function(el, cellval, opts) {
if (!cellval)
return;
$(el).html(fmtCurrency(cellval));
}
idFormatter = function(el, cellval, opts) {
if (!cellval)
return;
$(el).html('#'+cellval);
}

View File

@@ -1,5 +1,30 @@
<?php /* -*- mode:PHP -*- */
if (isset($account_ftype) || isset($ledger_id) || isset($account_id) || isset($ar_account)) {
$single_account = true;
} else {
$single_account = false;
}
if (isset($ledger_id) || isset($account_id) || isset($ar_account)) {
$single_amount = false;
} else {
$single_amount = true;
}
if (isset($reconcile_id)) {
$applied_amount = true;
} else {
$applied_amount = false;
}
if (isset($account_ftype)) {
$subtotal_amount = false;
} else {
$subtotal_amount = true;
}
// Define the table columns
$cols = array();
if (0) {
@@ -8,36 +33,44 @@ if (isset($notxgroup))
else
$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id');
} else {
$notxgroup = true;
$notxgroup = false;
$cols['Transaction'] = array('index' => 'Transaction.id', 'formatter' => 'id');
$cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id');
}
$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date');
if (isset($account_ftype) || isset($ledger_id)) {
$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'longname');
if ($single_account) {
$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'name');
}
else {
$cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'longname');
$cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'longname');
$cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name');
$cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'name');
}
$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'name');
$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname');
$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id');
$cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'name');
$cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name');
$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150);
if (isset($ledger_id)) {
if ($single_amount) {
$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency');
}
else {
$cols['Debit'] = array('index' => 'debit', 'formatter' => 'currency');
$cols['Credit'] = array('index' => 'credit', 'formatter' => 'currency');
}
else {
$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency');
}
if (isset($reconcile_id)) {
if ($applied_amount) {
$cols['Applied'] = array('index' => "Reconciliation.amount", 'formatter' => 'currency');
}
$custom_post_data = compact('ledger_id', 'account_type', 'account_ftype',
if ($subtotal_amount) {
$cols['Sub-Total'] = array('index' => 'subtotal', 'formatter' => 'currency', 'sortable' => false);
}
$custom_post_data = compact('ledger_id', 'account_id', 'ar_account',
'account_type', 'account_ftype',
'customer_id', 'lease_id', 'transaction_id', 'notxgroup');
$jqGrid_options = array('jqGridColumns' => $cols,

View File

@@ -19,7 +19,7 @@ if (isset($lease['Lease']))
$rows = array(array('ID', $lease['id']),
array('Number', $lease['number']),
array('Lease Type', $lease_type['name']),
array('Unit', $html->link($unit['id'],
array('Unit', $html->link($unit['name'],
array('controller' => 'units',
'action' => 'view',
$unit['id']))),
@@ -81,6 +81,7 @@ echo '<div CLASS="detail supporting">' . "\n";
echo $this->element('ledger_entries',
array('caption' => 'Account',
'lease_id' => $lease['id'],
'ar_account' => true,
));

View File

@@ -23,14 +23,18 @@ $rows = array(array('ID', $entry['id']),
'action' => 'view',
$transaction['id']))),
array('Timestamp', FormatHelper::datetime($transaction['stamp'])),
array('Customer', $html->link($customer['name'],
array('Customer', (isset($customer['name'])
? $html->link($customer['name'],
array('controller' => 'customers',
'action' => 'view',
$customer['id']))),
array('Lease', $html->link('#'.$lease['id'],
$customer['id']))
: null)),
array('Lease', (isset($lease['id'])
? $html->link('#'.$lease['id'],
array('controller' => 'leases',
'action' => 'view',
$lease['id']))),
$lease['id']))
: null)),
array('Monetary Source', (isset($source['name'])
? $html->link($source['name'],
array('controller' => 'monetary_sources',
@@ -107,26 +111,25 @@ echo '<div CLASS="detail supporting">' . "\n";
* Reconciliation Ledger Entries
*/
echo $this->element('ledger_entries',
array('caption' => "Debit Applications",
if ($debit_ledger['Account']['trackable']) {
echo $this->element('ledger_entries',
array('caption' => "Payments Received",
'grid_div_id' => 'debit_reconciliation_ledger_entries',
//'ledger_id' => $debit_ledger['id'],
//'account_type' => $debit_ledger['Account']['type'],
'account_ftype' => 'debit',
'reconcile_id' => $entry['id'],
'ledger_entries' => $reconciled['debit']['entry'],
//'ledger_entries' => $reconciled['debit']['entry'],
));
}
echo $this->element('ledger_entries',
array('caption' => "Credit Applications",
if ($credit_ledger['Account']['trackable']) {
echo $this->element('ledger_entries',
array('caption' => "Charges Paid",
'grid_div_id' => 'credit_reconciliation_ledger_entries',
//'ledger_id' => $credit_ledger['id'],
//'account_type' => $credit_ledger['Account']['type'],
//'account_ftype' => 'debit', // Looking for debits to match this credit
'account_ftype' => 'credit',
'reconcile_id' => $entry['id'],
'ledger_entries' => $reconciled['credit']['entry'],
//'ledger_entries' => $reconciled['credit']['entry'],
));
}
/* End "detail supporting" div */

View File

@@ -64,6 +64,7 @@ echo $this->element('ledger_entries',
array('caption' => ('Current Lease Account (' .
$unit['CurrentLease']['Customer']['name']
. ')'),
'ar_account' => true,
'lease_id' => $unit['CurrentLease']['id'],
));

View File

@@ -65,8 +65,10 @@ tr.evnrow { background: #f4f4f4; }
*/
table.detail { width : 60%;
float: left; }
table.detail td.field { width: 10em; }
float : left; }
table.detail td.field { width : 10em; }
table.item.detail td.value { white-space : normal; }
div.detail.supporting { clear : both;
padding-top: 1.5em; }