Making progress. Much still to do, but there are hints of functionality finally returning so I'm snapshotting.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@360 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class AccountsController extends AppController {
|
||||
|
||||
var $uses = array('Account', 'DoubleEntry');
|
||||
var $uses = array('Account', 'LedgerEntry');
|
||||
|
||||
var $sidemenu_links =
|
||||
array(array('name' => 'Accounts', 'header' => true),
|
||||
@@ -68,7 +68,7 @@ class AccountsController extends AppController {
|
||||
array(// Models
|
||||
'CurrentLedger' => array
|
||||
(// Models
|
||||
'DoubleEntry'
|
||||
'LedgerEntry'
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -76,7 +76,7 @@ class AccountsController extends AppController {
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return array_merge(array('Account.*'),
|
||||
$this->Account->Ledger->DoubleEntry->debitCreditFields(true, 'DoubleEntry', 'CurrentLedger'));
|
||||
$this->Account->Ledger->LedgerEntry->debitCreditFields(true, 'LedgerEntry', 'CurrentLedger'));
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
@@ -166,7 +166,7 @@ class AccountsController extends AppController {
|
||||
('Account' =>
|
||||
array('fields' => array('name')),
|
||||
|
||||
'DoubleEntry' =>
|
||||
'LedgerEntry' =>
|
||||
array('fields' => array('id', 'amount'),
|
||||
|
||||
'MonetarySource' =>
|
||||
@@ -181,7 +181,7 @@ class AccountsController extends AppController {
|
||||
),
|
||||
'fields' => false,
|
||||
'conditions' => array(array('Ledger.id' => $ledger_id),
|
||||
array('DoubleEntry.id IS NOT NULL'),
|
||||
array('LedgerEntry.id IS NOT NULL'),
|
||||
),
|
||||
));
|
||||
|
||||
@@ -247,7 +247,7 @@ class AccountsController extends AppController {
|
||||
// Get all ledger entries of the CURRENT ledger
|
||||
$entries = $this->Account->ledgerEntries($id);
|
||||
//pr(compact('entries'));
|
||||
$account['CurrentLedger']['DoubleEntry'] = $entries;
|
||||
$account['CurrentLedger']['LedgerEntry'] = $entries;
|
||||
|
||||
// Summarize each ledger
|
||||
foreach($account['Ledger'] AS &$ledger)
|
||||
|
||||
@@ -16,203 +16,6 @@ class DoubleEntriesController extends AppController {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* virtuals: jqGridData
|
||||
* - With the application controller handling the jqGridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function jqGridDataSetup(&$params) {
|
||||
parent::jqGridDataSetup($params);
|
||||
if (isset($params['custom']['collected_account_id']))
|
||||
$params['custom']['account_id'] = $params['custom']['collected_account_id'];
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link =
|
||||
array(// Models
|
||||
'Transaction' =>
|
||||
array('fields' => array('id', 'stamp'),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
|
||||
'Lease' =>
|
||||
array('fields' => array('id', 'number'),
|
||||
'Unit' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if ($params['action'] == 'collected' || $params['action'] == 'reconcile') {
|
||||
$link['Payment'] = array('Account' => array('alias' => 'PaymentAccount'),
|
||||
'Receipt');
|
||||
$link['Charge'] = array('Account' => array('alias' => 'ChargeAccount'),
|
||||
'Invoice');
|
||||
}
|
||||
|
||||
if (isset($params['custom']['ledger_id'])) {
|
||||
$link['Ledger'] =
|
||||
array('fields' => array('id', 'sequence'),
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return array('link' => $link);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
if ($params['action'] == 'collected') {
|
||||
$fields[] = ('SUM(COALESCE(AppliedPayment.amount,0)' .
|
||||
' + COALESCE(AppliedCharge.amount,0)) AS applied');
|
||||
$fields[] = 'MAX(Receipt.stamp) AS last_paid';
|
||||
}
|
||||
elseif ($params['action'] == 'reconcile') {
|
||||
$fields[] = array("IF(Entry.type = 'CHARGE',",
|
||||
" COALESCE(AppliedCharge.amount,0),",
|
||||
" COALESCE(AppliedPayment.amount,0))",
|
||||
" AS 'applied'");
|
||||
$fields[] = array("Entry.amount - (",
|
||||
"IF(Entry.type = 'CHARGE',",
|
||||
" COALESCE(AppliedCharge.amount,0),",
|
||||
" COALESCE(AppliedPayment.amount,0))",
|
||||
") AS 'balance'");
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
if ($params['action'] === 'collected') {
|
||||
if (!isset($params['custom']['account_id']))
|
||||
die("INTERNAL ERROR: ACCOUNT ID NOT SET");
|
||||
|
||||
extract($params['custom']);
|
||||
|
||||
if (!empty($collected_from_date))
|
||||
$conditions[]
|
||||
= array('Receipt.stamp >=' =>
|
||||
$this->DoubleEntry->Transaction->dateFormatBeforeSave($collected_from_date));
|
||||
|
||||
if (!empty($collected_through_date))
|
||||
$conditions[]
|
||||
= array('Receipt.stamp <=' =>
|
||||
$this->DoubleEntry->Transaction->dateFormatBeforeSave($collected_through_date . ' 23:59:59'));
|
||||
|
||||
if (isset($collected_payment_accounts))
|
||||
$conditions[] = array('PaymentAccount.id' => $collected_payment_accounts);
|
||||
else
|
||||
$conditions[] = array('NOT' => array(array('PaymentAccount.id' => null)));
|
||||
}
|
||||
|
||||
if ($params['action'] === 'ledger') {
|
||||
$ledger_id = $params['custom']['ledger_id'];
|
||||
$conditions[] = array('Ledger.id' => $ledger_id);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['reconcile_id'])) {
|
||||
$conditions[] = array('OR' =>
|
||||
array('AppliedCharge.id' => $reconcile_id),
|
||||
array('AppliedPayment.id' => $reconcile_id));
|
||||
}
|
||||
|
||||
if (isset($params['custom']['account_id'])) {
|
||||
$account_id = $params['custom']['account_id'];
|
||||
$conditions[] = array('Account.id' => $account_id);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['customer_id'])) {
|
||||
$conditions[] =
|
||||
array('Customer.id' => $params['custom']['customer_id']);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$conditions[] =
|
||||
array('Lease.id' => $params['custom']['lease_id']);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['transaction_id'])) {
|
||||
$conditions[] =
|
||||
array('Transaction.id' => $params['custom']['transaction_id']);
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Transaction'] = array('id');
|
||||
$links['Entry'] = array('id');
|
||||
$links['Account'] = array('controller' => 'accounts', 'name');
|
||||
$links['DebitAccount'] = array('controller' => 'accounts', 'name');
|
||||
$links['CreditAccount'] = array('controller' => 'accounts', 'name');
|
||||
$links['MonetarySource'] = array('name');
|
||||
$links['Customer'] = array('name');
|
||||
$links['Lease'] = array('number');
|
||||
$links['Unit'] = array('name');
|
||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
function jqGridDataGroup(&$params, &$model) {
|
||||
return parent::jqGridDataGroup($params, $model);
|
||||
}
|
||||
|
||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||
/* if ($index === 'balance') */
|
||||
/* return ($index .' '. $direction); */
|
||||
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||
|
||||
if ($index === 'Transaction.stamp') {
|
||||
$order[] = 'Entry.id ' . $direction;
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
function jqGridDataRecords(&$params, &$model, $query) {
|
||||
if ($params['action'] === 'collected') {
|
||||
$tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1));
|
||||
$tquery['group'] = array('AppliedPayment.id');
|
||||
$tquery['fields'] = array("IF(Entry.type = 'CHARGE',",
|
||||
" SUM(COALESCE(AppliedCharge.amount,0)),",
|
||||
" SUM(COALESCE(AppliedPayment.amount,0)))",
|
||||
" AS 'applied'",
|
||||
|
||||
"Charge.amount - (",
|
||||
"IF(Entry.type = 'CHARGE',",
|
||||
" SUM(COALESCE(AppliedCharge.amount,0)),",
|
||||
" SUM(COALESCE(AppliedPayment.amount,0)))",
|
||||
") AS 'balance'",
|
||||
);
|
||||
|
||||
$total = $model->find('first', $tquery);
|
||||
$params['userdata']['total'] = $total[0]['applied'];
|
||||
$params['userdata']['balance'] = $total[0]['balance'];
|
||||
}
|
||||
|
||||
return parent::jqGridDataRecords($params, $model, $query);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: reverse the ledger entry
|
||||
*/
|
||||
|
||||
function reverse($id) {
|
||||
$this->DoubleEntry->reverse($id);
|
||||
$this->redirect(array('action'=>'view', $id));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -229,107 +32,13 @@ class DoubleEntriesController extends AppController {
|
||||
// Get the Entry and related fields
|
||||
$entry = $this->DoubleEntry->find
|
||||
('first',
|
||||
array('contain' => array
|
||||
('Transaction' => array('fields' => array('id', 'stamp')),
|
||||
'Customer' => array('fields' => array('id', 'name')),
|
||||
'Lease' => array('fields' => array('id')),
|
||||
'DebitLedger' => array('fields' => array('id', 'sequence'),
|
||||
'Account' => array('id', 'name', 'type', 'trackable')),
|
||||
'CreditLedger' => array('fields' => array('id', 'sequence'),
|
||||
'Account' => array('id', 'name', 'type', 'trackable')),
|
||||
'DebitEntry'/* => array('fields' => array('id'))*/,
|
||||
'CreditEntry'/* => array('fields' => array('id'))*/,
|
||||
'Entry' => array('fields' => array('id')),
|
||||
),
|
||||
|
||||
//'fields' => array('DoubleEntry.*'),
|
||||
|
||||
array('contain' => array('DebitEntry', 'CreditEntry'),
|
||||
'conditions' => array('DoubleEntry.id' => $id),
|
||||
));
|
||||
pr($entry);
|
||||
|
||||
$stats = $this->DoubleEntry->stats($id);
|
||||
|
||||
foreach (array('debit', 'credit') AS $crdr) {
|
||||
$CrDr = ucfirst($crdr);
|
||||
$entry[$CrDr.'Ledger']['Account']['ftype'] =
|
||||
$this->DoubleEntry->Ledger->Account->fundamentalType
|
||||
($entry[$CrDr.'Ledger']['Account']['type']);
|
||||
|
||||
$stats[$crdr]['amount_reconciled'] = null;
|
||||
$stats[$crdr]['amount_remaining'] = null;
|
||||
}
|
||||
|
||||
/* // Get the reconciliation balances for this ledger entry */
|
||||
/* $stats['debit']['amount_reconciled'] = $stats['debit_amount_reconciled']; */
|
||||
/* $stats['credit']['amount_reconciled'] = $stats['credit_amount_reconciled']; */
|
||||
/* if ($entry['DebitLedger']['Account']['trackable']) */
|
||||
/* $stats['debit']['amount_remaining'] = $entry['Entry']['amount'] - $stats['debit']['amount_reconciled']; */
|
||||
/* if ($entry['CreditLedger']['Account']['trackable']) */
|
||||
/* $stats['credit']['amount_remaining'] = $entry['Entry']['amount'] - $stats['credit']['amount_reconciled']; */
|
||||
/* //pr($stats); */
|
||||
|
||||
/* $reconciled = $this->DoubleEntry->findReconciledDoubleEntries($id); */
|
||||
/* //pr($reconciled); */
|
||||
|
||||
|
||||
// REVISIT <AP>: 20090711
|
||||
// It's not clear whether we should be able to reverse charges that have
|
||||
// already been paid/cleared/reconciled. Certainly, that will be the
|
||||
// case when someone has pre-paid and then moves out early. However, this
|
||||
// will work well for items accidentally charged but not yet paid for.
|
||||
if ((!$entry['DebitLedger']['Account']['trackable'] ||
|
||||
$stats['debit']['amount_reconciled'] == 0) &&
|
||||
(!$entry['CreditLedger']['Account']['trackable'] ||
|
||||
$stats['credit']['amount_reconciled'] == 0)
|
||||
|
||||
&& 0
|
||||
|
||||
)
|
||||
{
|
||||
// Set up dynamic menu items
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Undo',
|
||||
'url' => array('action' => 'reverse',
|
||||
$id));
|
||||
}
|
||||
|
||||
if ($this->DoubleEntry->Ledger->Account->type
|
||||
($entry['CreditLedger']['Account']['id']) == 'INCOME')
|
||||
{
|
||||
// Set up dynamic menu items
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Reverse',
|
||||
'url' => array('action' => 'reverse',
|
||||
$id));
|
||||
}
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Double Ledger Entry #{$entry['DoubleEntry']['id']}";
|
||||
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
||||
}
|
||||
|
||||
function tst($id = null) {
|
||||
$entry = $this->DoubleEntry->find
|
||||
('first',
|
||||
array('contain' => array('Account',
|
||||
|
||||
'DoubleEntry',
|
||||
|
||||
'Payment' => array('fields' => array('Payment.*'/*, 'AppliedPayment.*'*/),
|
||||
'DoubleEntry'/* => array('alias' => 'PaymentDoubleEntry')*/),
|
||||
'Charge' => array('fields' => array('Charge.*'/*, 'AppliedCharge.*'*/),
|
||||
'DoubleEntry'/* => array('alias' => 'ChargeDoubleEntry')*/),
|
||||
),
|
||||
'conditions' => array('Entry.id' => $id),
|
||||
));
|
||||
pr($entry);
|
||||
$this->set(compact('entry', 'title'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,31 +57,15 @@ class LeasesController extends AppController {
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link = $this->jqGridDataCountTables($params, $model);
|
||||
$link['link']['DoubleEntry'] = array('fields' => array());
|
||||
$link['link']['DoubleEntry']['Ledger'] = array('fields' => array());
|
||||
$link['link']['DoubleEntry']['Ledger']['Account'] = array('fields' => array());
|
||||
// INNER JOIN would be great, as it would ensure we're only looking
|
||||
// at the ledger entries that we truly want. However, this also
|
||||
// removes from the query any leases that do not yet have a ledger
|
||||
// entry in A/R. A solution would be to INNER JOIN these tables,
|
||||
// and LEFT JOIN it to the rest. Grouping of JOINs, however, is
|
||||
// implemented with the 'joins' tag, and is not available through
|
||||
// the Linkable behavior interface.
|
||||
//$link['link']['DoubleEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['DoubleEntry']['Ledger']['Account']['conditions']
|
||||
= array('Account.id' =>
|
||||
$this->Lease->DoubleEntry->Ledger->Account->accountReceivableAccountID());
|
||||
$link['link']['StatementEntry'] = array('fields' => array());
|
||||
return $link;
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
$db = &$model->getDataSource();
|
||||
$fields = $db->fields($model, $model->alias);
|
||||
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||
" IF(DoubleEntry.debit_ledger_id = Account.id," .
|
||||
" 1, -1))" .
|
||||
" * IF(DoubleEntry.amount IS NULL, 0, DoubleEntry.amount))" .
|
||||
" AS 'balance'");
|
||||
$fields = array_merge($fields,
|
||||
$this->Lease->StatementEntry->chargePaymentFields(true));
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -95,6 +79,9 @@ class LeasesController extends AppController {
|
||||
$conditions[] = 'Lease.close_date IS NOT NULL';
|
||||
}
|
||||
|
||||
if (isset($params['custom']['customer_id']))
|
||||
$conditions[] = array('Lease.customer_id' => $params['custom']['customer_id']);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
@@ -252,10 +239,10 @@ class LeasesController extends AppController {
|
||||
$receipt_transaction = array_intersect_key($this->data,
|
||||
array('Transaction'=>1,
|
||||
'transaction_id'=>1));
|
||||
foreach ($data['DoubleEntry'] AS $entry) {
|
||||
foreach ($data['StatementEntry'] AS $entry) {
|
||||
// Create the receipt entry, and reconcile the credit side
|
||||
// of the double-entry (which should be A/R) as a payment.
|
||||
$ids = $this->DoubleEntry->Ledger->Account->postDoubleEntry
|
||||
$ids = $this->StatementEntry->Ledger->Account->postLedgerEntry
|
||||
($receipt_transaction,
|
||||
array_intersect_key($entry, array('MonetarySource'=>1))
|
||||
+ array_intersect_key($entry, array('account_id'=>1)),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class EntriesController extends AppController {
|
||||
class LedgerEntriesController extends AppController {
|
||||
|
||||
var $sidemenu_links = array();
|
||||
|
||||
@@ -58,7 +58,7 @@ class LedgersController extends AppController {
|
||||
('link' =>
|
||||
array(// Models
|
||||
'Account',
|
||||
'DoubleEntry',
|
||||
'LedgerEntry',
|
||||
'Close',
|
||||
),
|
||||
);
|
||||
@@ -67,7 +67,7 @@ class LedgersController extends AppController {
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return array_merge(array('Ledger.*',
|
||||
'CONCAT(Account.id, "-", Ledger.sequence) AS id_sequence'),
|
||||
$this->Ledger->DoubleEntry->debitCreditFields(true));
|
||||
$this->Ledger->LedgerEntry->debitCreditFields(true));
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
|
||||
292
site/controllers/statement_entries_controller.php
Normal file
292
site/controllers/statement_entries_controller.php
Normal file
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
class StatementEntriesController extends AppController {
|
||||
|
||||
var $sidemenu_links = array();
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* override: sideMenuLinks
|
||||
* - Generates controller specific links for the side menu
|
||||
*/
|
||||
function sideMenuLinks() {
|
||||
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* virtuals: jqGridData
|
||||
* - With the application controller handling the jqGridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function jqGridDataSetup(&$params) {
|
||||
parent::jqGridDataSetup($params);
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link =
|
||||
array(// Models
|
||||
'Transaction' =>
|
||||
array('fields' => array('id', 'stamp'),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
|
||||
'Lease' =>
|
||||
array('fields' => array('id', 'number'),
|
||||
'Unit' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name', 'type'),
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($params['custom']['statement_entry_id'])) {
|
||||
$link['PaymentEntry'] = array();
|
||||
$link['ChargeEntry'] = array();
|
||||
}
|
||||
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
|
||||
/* $link['PaymentEntry'] = array(); */
|
||||
/* $link['ChargeEntry'] = array(); */
|
||||
/* } */
|
||||
/* elseif (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])) { */
|
||||
/* $link['PaymentEntry'] = array(); */
|
||||
/* } */
|
||||
|
||||
return array('link' => $link);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
$fields = parent::jqGridDataFields($params, $model);
|
||||
|
||||
if (!isset($fields))
|
||||
$fields = array('StatementEntry.*');
|
||||
|
||||
/* if (isset($params['custom']['reconcile_id'])) { */
|
||||
/* $fields[] = array("IF(StatementEntry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* " AS 'applied'"); */
|
||||
/* $fields[] = array("StatementEntry.amount - (", */
|
||||
/* "IF(StatementEntry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* ") AS 'balance'"); */
|
||||
/* } */
|
||||
|
||||
if (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])
|
||||
|| isset($params['custom']['statement_entry_id'])) {
|
||||
$fields = array_merge($fields,
|
||||
$this->StatementEntry->chargePaymentFields());
|
||||
}
|
||||
|
||||
if ($params['action'] === 'collected')
|
||||
$fields[] = 'MAX(Receipt.stamp) AS last_paid';
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
$conditions = parent::jqGridDataConditions($params, $model);
|
||||
extract($params['custom']);
|
||||
|
||||
if (isset($transaction_id))
|
||||
$conditions[] = array('Transaction.id' => $transaction_id);
|
||||
|
||||
if (isset($account_id))
|
||||
$conditions[] = array('Account.id' => $account_id);
|
||||
|
||||
if (isset($customer_id))
|
||||
$conditions[] = array('Customer.id' => $customer_id);
|
||||
|
||||
if (isset($lease_id))
|
||||
$conditions[] = array('Lease.id' => $lease_id);
|
||||
|
||||
if (!empty($from_date))
|
||||
$conditions[]
|
||||
= array('Transaction.stamp >=' =>
|
||||
$this->StatementEntry->Transaction->dateFormatBeforeSave($from_date));
|
||||
|
||||
if (!empty($through_date))
|
||||
$conditions[]
|
||||
= array('Transaction.stamp <=' =>
|
||||
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
|
||||
|
||||
if (isset($payment_accounts))
|
||||
$conditions[] = array('PaymentEntry.account_id' => $payment_accounts);
|
||||
|
||||
if (isset($charge_accounts))
|
||||
$conditions[] = array('ChargeEntry.account_id' => $charge_accounts);
|
||||
|
||||
if (isset($statement_entry_id)) {
|
||||
$conditions[] = array('OR' =>
|
||||
array(array('ChargeEntry.id' => $statement_entry_id),
|
||||
array('PaymentEntry.id' => $statement_entry_id)));
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||
$links['StatementEntry'] = array('id');
|
||||
$links['Transaction'] = array('id');
|
||||
$links['Account'] = array('name');
|
||||
$links['Customer'] = array('name');
|
||||
$links['Lease'] = array('number');
|
||||
$links['Unit'] = array('name');
|
||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
function jqGridDataGroup(&$params, &$model) {
|
||||
return parent::jqGridDataGroup($params, $model);
|
||||
}
|
||||
|
||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||
|
||||
if ($index === 'Transaction.stamp')
|
||||
$order[] = 'StatementEntry.id ' . $direction;
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
function jqGridDataRecords(&$params, &$model, $query) {
|
||||
if ($params['action'] === 'collected') {
|
||||
$tquery = array_diff_key($query, array(/*'fields'=>1,*/'group'=>1,'limit'=>1,'order'=>1));
|
||||
$tquery['group'] = array('AppliedPayment.id');
|
||||
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE',",
|
||||
" SUM(COALESCE(PaymentEntry.amount,0)),",
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))",
|
||||
" AS 'applied'",
|
||||
|
||||
"StatementEntry.amount - (",
|
||||
"IF(StatementEntry.type = 'CHARGE',",
|
||||
" SUM(COALESCE(PaymentEntry.amount,0)),",
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))",
|
||||
") AS 'balance'",
|
||||
);
|
||||
|
||||
$total = $model->find('first', $tquery);
|
||||
$params['userdata']['total'] = $total[0]['applied'];
|
||||
$params['userdata']['balance'] = $total[0]['balance'];
|
||||
}
|
||||
|
||||
return parent::jqGridDataRecords($params, $model, $query);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: reverse the ledger entry
|
||||
*/
|
||||
|
||||
function reverse($id) {
|
||||
$this->StatementEntry->reverse($id);
|
||||
$this->redirect(array('action'=>'view', $id));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: view
|
||||
* - Displays information about a specific entry
|
||||
*/
|
||||
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// Get the StatementEntry and related fields
|
||||
$entry = $this->StatementEntry->find
|
||||
('first',
|
||||
array('contain' => array
|
||||
('Transaction' => array('fields' => array('id', 'stamp')),
|
||||
'Account' => array('id', 'name', 'type', 'trackable'),
|
||||
'Customer' => array('fields' => array('id', 'name')),
|
||||
'Lease' => array('fields' => array('id')),
|
||||
),
|
||||
|
||||
'conditions' => array('StatementEntry.id' => $id),
|
||||
));
|
||||
|
||||
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
||||
|
||||
|
||||
/* // REVISIT <AP>: 20090711 */
|
||||
/* // It's not clear whether we should be able to reverse charges that have */
|
||||
/* // already been paid/cleared/reconciled. Certainly, that will be the */
|
||||
/* // case when someone has pre-paid and then moves out early. However, this */
|
||||
/* // will work well for items accidentally charged but not yet paid for. */
|
||||
/* if ((!$entry['DebitLedger']['Account']['trackable'] || */
|
||||
/* $stats['debit']['amount_reconciled'] == 0) && */
|
||||
/* (!$entry['CreditLedger']['Account']['trackable'] || */
|
||||
/* $stats['credit']['amount_reconciled'] == 0) */
|
||||
|
||||
/* && 0 */
|
||||
|
||||
/* ) */
|
||||
/* { */
|
||||
/* // Set up dynamic menu items */
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Operations', 'header' => true); */
|
||||
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Undo', */
|
||||
/* 'url' => array('action' => 'reverse', */
|
||||
/* $id)); */
|
||||
/* } */
|
||||
|
||||
/* if ($this->StatementEntry->Ledger->Account->type */
|
||||
/* ($entry['CreditLedger']['Account']['id']) == 'INCOME') */
|
||||
/* { */
|
||||
/* // Set up dynamic menu items */
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Operations', 'header' => true); */
|
||||
|
||||
/* $this->sidemenu_links[] = */
|
||||
/* array('name' => 'Reverse', */
|
||||
/* 'url' => array('action' => 'reverse', */
|
||||
/* $id)); */
|
||||
/* } */
|
||||
|
||||
$stats = $this->StatementEntry->stats($id);
|
||||
pr($stats);
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Statement Entry #{$entry['StatementEntry']['id']}";
|
||||
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
||||
}
|
||||
|
||||
function tst($id = null) {
|
||||
$entry = $this->StatementEntry->find
|
||||
('first',
|
||||
array('contain' => array('Account',
|
||||
|
||||
'DoubleStatementEntry',
|
||||
|
||||
'Payment' => array('fields' => array('Payment.*'/*, 'AppliedPayment.*'*/),
|
||||
'DoubleStatementEntry'/* => array('alias' => 'PaymentDoubleStatementEntry')*/),
|
||||
'Charge' => array('fields' => array('Charge.*'/*, 'AppliedCharge.*'*/),
|
||||
'DoubleStatementEntry'/* => array('alias' => 'ChargeDoubleStatementEntry')*/),
|
||||
),
|
||||
'conditions' => array('StatementEntry.id' => $id),
|
||||
));
|
||||
pr($entry);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,31 +64,19 @@ class TransactionsController extends AppController {
|
||||
('first',
|
||||
array('contain' =>
|
||||
array(// Models
|
||||
'LedgerEntry' => array('fields' => array('LedgerEntry.id',
|
||||
'LedgerEntry.amount',
|
||||
'LedgerEntry.comment'),
|
||||
//Models
|
||||
|
||||
'DebitLedger' => array
|
||||
('fields' => array('DebitLedger.id', 'DebitLedger.sequence'),
|
||||
'Account' => array
|
||||
('fields' => array('Account.id', 'Account.name')),
|
||||
),
|
||||
|
||||
'CreditLedger' => array
|
||||
('fields' => array('CreditLedger.id', 'CreditLedger.sequence'),
|
||||
'Account' => array
|
||||
('fields' => array('Account.id', 'Account.name')),
|
||||
),
|
||||
),
|
||||
'LedgerEntry' =>
|
||||
array('fields' => array('LedgerEntry.id',
|
||||
'LedgerEntry.amount',
|
||||
'LedgerEntry.comment'),
|
||||
),
|
||||
),
|
||||
'conditions' => array('Transaction.id' => $id),
|
||||
));
|
||||
|
||||
// Figure out the transaction total
|
||||
$total = 0;
|
||||
foreach($transaction['LedgerEntry'] AS $entry)
|
||||
$total += $entry['amount'];
|
||||
/* // Figure out the transaction total */
|
||||
/* $total = 0; */
|
||||
/* foreach($transaction['LedgerEntry'] AS $entry) */
|
||||
/* $total += $entry['amount']; */
|
||||
|
||||
// OK, prepare to render.
|
||||
$title = 'Transaction #' . $transaction['Transaction']['id'];
|
||||
@@ -145,6 +133,7 @@ class TransactionsController extends AppController {
|
||||
}
|
||||
|
||||
pr($this->data);
|
||||
|
||||
if (!$this->Transaction->addReceipt($this->data,
|
||||
$this->data['Customer']['id'],
|
||||
(isset($this->data['Lease']['id'])
|
||||
|
||||
Reference in New Issue
Block a user