Another snapshot
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@356 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -76,7 +76,7 @@ class AccountsController extends AppController {
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return array_merge(array('Account.*'),
|
||||
$this->Account->Ledger->DoubleEntry->debitCreditFields('DoubleEntry', 'CurrentLedger'));
|
||||
$this->Account->Ledger->DoubleEntry->debitCreditFields(true, 'DoubleEntry', 'CurrentLedger'));
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
@@ -245,8 +245,9 @@ class AccountsController extends AppController {
|
||||
);
|
||||
|
||||
// Get all ledger entries of the CURRENT ledger
|
||||
$entries = $this->Account->findLedgerEntries($id);
|
||||
$account['CurrentLedger']['DoubleEntry'] = $entries['Entries'];
|
||||
$entries = $this->Account->ledgerEntries($id);
|
||||
//pr(compact('entries'));
|
||||
$account['CurrentLedger']['DoubleEntry'] = $entries;
|
||||
|
||||
// Summarize each ledger
|
||||
foreach($account['Ledger'] AS &$ledger)
|
||||
@@ -270,7 +271,7 @@ class AccountsController extends AppController {
|
||||
}
|
||||
|
||||
function tst($id) {
|
||||
$entries = $this->Account->unreconciledEntries($id);
|
||||
//$entries = $this->Account->($id);
|
||||
pr($entries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,9 @@ class CustomersController extends AppController {
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link = $this->jqGridDataCountTables($params, $model);
|
||||
$link['link']['LedgerEntry'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
|
||||
$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 units that do not yet have a ledger
|
||||
@@ -73,10 +73,10 @@ class CustomersController extends AppController {
|
||||
// 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']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||
//$link['link']['DoubleEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['DoubleEntry']['Ledger']['Account']['conditions']
|
||||
= array('Account.id' =>
|
||||
$this->Customer->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||
$this->Customer->DoubleEntry->Ledger->Account->accountReceivableAccountID());
|
||||
return $link;
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ class CustomersController extends AppController {
|
||||
$fields = $db->fields($model, $model->alias);
|
||||
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
|
||||
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||
" IF(DoubleEntry.debit_ledger_id = Account.id," .
|
||||
" 1, -1))" .
|
||||
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||
" * IF(DoubleEntry.amount IS NULL, 0, DoubleEntry.amount))" .
|
||||
" AS 'balance'");
|
||||
return $fields;
|
||||
}
|
||||
@@ -247,10 +247,18 @@ class CustomersController extends AppController {
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
$customer = $this->Customer->details($id);
|
||||
/* //$result = $this->Customer->securityDeposits($id); */
|
||||
/* $result = $this->Customer->excessPayments($id); */
|
||||
/* //$result = $this->Customer->unreconciledCharges($id); */
|
||||
/* echo('<HR>'); */
|
||||
/* pr($result); */
|
||||
/* $this->autoRender = false; */
|
||||
/* return; */
|
||||
|
||||
$customer = $this->Customer->details($id);
|
||||
//pr($customer);
|
||||
$outstanding_balance = $customer['stats']['balance'];
|
||||
$outstanding_deposit = $customer['deposits']['summary']['balance'];
|
||||
$outstanding_deposit = $customer['deposits']['summary']['Payment']['reconciled'];
|
||||
|
||||
// Figure out if this customer has any non-closed leases
|
||||
$show_moveout = false;
|
||||
@@ -429,17 +437,17 @@ class CustomersController extends AppController {
|
||||
*/
|
||||
|
||||
function refund() {
|
||||
$entries = $this->Customer->LedgerEntry->find
|
||||
$entries = $this->Customer->DoubleEntry->find
|
||||
('all', array
|
||||
('contain' => false,
|
||||
'conditions' => array('LedgerEntry.id' =>
|
||||
'conditions' => array('DoubleEntry.id' =>
|
||||
//array(199,200,201)
|
||||
61
|
||||
),
|
||||
));
|
||||
pr(compact('entries'));
|
||||
|
||||
$this->Customer->LedgerEntry->reverse($entries);
|
||||
$this->Customer->DoubleEntry->reverse($entries);
|
||||
}
|
||||
|
||||
|
||||
@@ -473,8 +481,8 @@ class CustomersController extends AppController {
|
||||
if (!count($unreconciled['entries']['entry']))
|
||||
unset($unreconciled['entries']['entry']);
|
||||
|
||||
pr($unreconciled);
|
||||
//$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount);
|
||||
//pr($unreconciled);
|
||||
//$reconciled = $cust->reconcileNewDoubleEntry($cust_id, 'credit', $amount);
|
||||
|
||||
$opts = array();
|
||||
//$opts['format'] = 'tags';
|
||||
|
||||
@@ -35,7 +35,11 @@ class EntriesController extends AppController {
|
||||
$link =
|
||||
array(// Models
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
array('fields' => array('id', 'name', 'type'),
|
||||
),
|
||||
|
||||
'Ledger' =>
|
||||
array('fields' => array('id', 'sequence'),
|
||||
),
|
||||
|
||||
'DoubleEntry' => array
|
||||
@@ -43,6 +47,20 @@ class EntriesController extends AppController {
|
||||
array('fields' => array('id', 'stamp'),
|
||||
),
|
||||
|
||||
'DebitLedger' =>
|
||||
array('fields' => array('id'),
|
||||
'Account' => array('alias' => 'DebitAccount',
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'CreditLedger' =>
|
||||
array('fields' => array('id'),
|
||||
'Account' => array('alias' => 'CreditAccount',
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
@@ -56,23 +74,24 @@ class EntriesController extends AppController {
|
||||
),
|
||||
);
|
||||
|
||||
if ($params['action'] === 'collected' ||
|
||||
isset($params['custom']['reconcile_id'])) {
|
||||
$link['Payment'] = array(//'linkalias' => 'MatchingPayment',
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1) {
|
||||
$link['Payment'] = array('DoubleEntry' =>
|
||||
array('alias' => 'PaymentDoubleEntry',
|
||||
'Receipt'),
|
||||
'Account' => array('alias' => 'PaymentAccount'),
|
||||
'Receipt');
|
||||
$link['Charge'] = array(//'linkalias' => 'MatchingCharge',
|
||||
);
|
||||
$link['Charge'] = array('DoubleEntry' =>
|
||||
array('alias' => 'ChargeDoubleEntry',
|
||||
'Invoice'),
|
||||
'Account' => array('alias' => 'ChargeAccount'),
|
||||
'Invoice');
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['ledger_id'])) {
|
||||
$link['Ledger'] =
|
||||
array('fields' => array('id', 'sequence'),
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
);
|
||||
elseif (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])) {
|
||||
$link['Charge'] = array('DoubleEntry' =>
|
||||
array('alias' => 'ChargeDoubleEntry',
|
||||
'Invoice'),
|
||||
'Account' => array('alias' => 'ChargeAccount'),
|
||||
);
|
||||
}
|
||||
|
||||
return array('link' => $link);
|
||||
@@ -81,20 +100,40 @@ class EntriesController extends AppController {
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
$fields = parent::jqGridDataFields($params, $model);
|
||||
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1)
|
||||
$fields[] = ('SUM(COALESCE(AppliedPayment.amount,0)' .
|
||||
' + COALESCE(AppliedCharge.amount,0)) AS applied');
|
||||
if (!isset($fields))
|
||||
$fields = array('Entry.*');
|
||||
|
||||
if (isset($params['custom']['reconcile_id'])) {
|
||||
$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'");
|
||||
/* if (isset($params['custom']['reconcile_id'])) { */
|
||||
/* $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'"); */
|
||||
/* } */
|
||||
|
||||
if (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])) {
|
||||
$fields[] = "IF(Entry.type = 'CHARGE', DoubleEntry.amount, NULL) AS debit";
|
||||
$fields[] = "IF(Entry.type = 'PAYMENT', DoubleEntry.amount, NULL) AS credit";
|
||||
$fields[] = "IF(Entry.type = 'CHARGE', 1, -1) * DoubleEntry.amount AS balance";
|
||||
}
|
||||
else {
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1)
|
||||
$fields[] = ('SUM(COALESCE(AppliedPayment.amount,0)' .
|
||||
' + COALESCE(AppliedCharge.amount,0)) AS applied');
|
||||
|
||||
if (count(array_intersect($params['fields'], array('debit', 'credit'))) >= 1) {
|
||||
$fields = array_merge($fields,
|
||||
$this->Entry->DoubleEntry->debitCreditFields());
|
||||
/* $fields = array_merge($fields, */
|
||||
/* $this->Entry->Account->debitCreditFields()); */
|
||||
/* $fields[] = "IF(Entry.crdr = 'CREDIT', DoubleEntry.amount, NULL) AS credit"; */
|
||||
/* $fields[] = "IF(Entry.crdr = 'DEBIT', DoubleEntry.amount, NULL) AS debit"; */
|
||||
/* $fields[] = "IF(Account.type IN Entry.crdr = 'DEBIT', DoubleEntry.amount, NULL) AS debit"; */
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['action'] === 'collected')
|
||||
@@ -145,13 +184,37 @@ class EntriesController extends AppController {
|
||||
}
|
||||
|
||||
if (isset($params['custom']['customer_id'])) {
|
||||
$customer_id = $params['custom']['customer_id'];
|
||||
$conditions[] =
|
||||
array('Customer.id' => $params['custom']['customer_id']);
|
||||
array('OR' =>
|
||||
array(array(array('Entry.type' => 'CHARGE'),
|
||||
array('DoubleEntry.customer_id' => $customer_id)),
|
||||
array(array('Entry.type' => 'PAYMENT'),
|
||||
array('ChargeDoubleEntry.customer_id' => $customer_id)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$lease_id = $params['custom']['lease_id'];
|
||||
$conditions[] =
|
||||
array('Lease.id' => $params['custom']['lease_id']);
|
||||
array('OR' =>
|
||||
array(array(array('Entry.type' => 'CHARGE'),
|
||||
array('DoubleEntry.lease_id' => $lease_id)),
|
||||
array(array('Entry.type' => 'PAYMENT'),
|
||||
array('ChargeDoubleEntry.lease_id' => $lease_id)),
|
||||
),
|
||||
);
|
||||
/* array('OR' => */
|
||||
/* array('AND' => */
|
||||
/* array(array('Entry.type' => 'CHARGE'), */
|
||||
/* array('DoubleEntry.lease_id' => $lease_id)) */
|
||||
/* ), */
|
||||
/* array('AND' => */
|
||||
/* array(array('Entry.type' => 'PAYMENT'), */
|
||||
/* array('ChargeDoubleEntry.lease_id' => $lease_id)), */
|
||||
/* ), */
|
||||
/* ); */
|
||||
}
|
||||
|
||||
if (isset($params['custom']['transaction_id'])) {
|
||||
|
||||
@@ -57,9 +57,9 @@ class LeasesController extends AppController {
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link = $this->jqGridDataCountTables($params, $model);
|
||||
$link['link']['LedgerEntry'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
|
||||
$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
|
||||
@@ -67,10 +67,10 @@ class LeasesController extends AppController {
|
||||
// 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']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||
//$link['link']['DoubleEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['DoubleEntry']['Ledger']['Account']['conditions']
|
||||
= array('Account.id' =>
|
||||
$this->Lease->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||
$this->Lease->DoubleEntry->Ledger->Account->accountReceivableAccountID());
|
||||
return $link;
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ class LeasesController extends AppController {
|
||||
$db = &$model->getDataSource();
|
||||
$fields = $db->fields($model, $model->alias);
|
||||
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||
" IF(DoubleEntry.debit_ledger_id = Account.id," .
|
||||
" 1, -1))" .
|
||||
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||
" * IF(DoubleEntry.amount IS NULL, 0, DoubleEntry.amount))" .
|
||||
" AS 'balance'");
|
||||
return $fields;
|
||||
}
|
||||
@@ -252,10 +252,10 @@ class LeasesController extends AppController {
|
||||
$receipt_transaction = array_intersect_key($this->data,
|
||||
array('Transaction'=>1,
|
||||
'transaction_id'=>1));
|
||||
foreach ($data['LedgerEntry'] AS $entry) {
|
||||
foreach ($data['DoubleEntry'] 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->LedgerEntry->Ledger->Account->postLedgerEntry
|
||||
$ids = $this->DoubleEntry->Ledger->Account->postDoubleEntry
|
||||
($receipt_transaction,
|
||||
array_intersect_key($entry, array('MonetarySource'=>1))
|
||||
+ array_intersect_key($entry, array('account_id'=>1)),
|
||||
@@ -269,6 +269,14 @@ class LeasesController extends AppController {
|
||||
if ($ids['error'])
|
||||
$ret = false;
|
||||
|
||||
$db = &$model->getDataSource();
|
||||
$fields = $db->fields($model, $model->alias);
|
||||
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||
" 1, -1))" .
|
||||
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||
" AS 'balance'");
|
||||
return $fields;
|
||||
$receipt_transaction = array_intersect_key($ids,
|
||||
array('transaction_id'=>1,
|
||||
'split_transaction_id'=>1));
|
||||
@@ -315,7 +323,7 @@ class LeasesController extends AppController {
|
||||
array('stats' => $this->Lease->stats($id)));
|
||||
|
||||
// Determine the lease security deposit
|
||||
$deposit = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||
$deposit = $this->Lease->securityDeposits($lease['Lease']['id']);
|
||||
$this->set(compact('deposit'));
|
||||
$this->set('customer', $lease['Customer']);
|
||||
$this->set('unit', $lease['Unit']);
|
||||
@@ -371,7 +379,7 @@ class LeasesController extends AppController {
|
||||
array('stats' => $this->Lease->stats($id)));
|
||||
|
||||
// Determine the lease security deposit
|
||||
$deposit = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||
$deposit = $this->Lease->securityDeposits($lease['Lease']['id']);
|
||||
if ($deposit['summary']['balance'] > 0)
|
||||
die("Still have un-utilized security deposit");
|
||||
|
||||
@@ -406,7 +414,7 @@ class LeasesController extends AppController {
|
||||
/* $outstanding_balance = $stats['balance']; */
|
||||
|
||||
/* // Determine the lease security deposit */
|
||||
/* $deposits = $this->Lease->findSecurityDeposits($id); */
|
||||
/* $deposits = $this->Lease->securityDeposits($id); */
|
||||
/* $outstanding_deposit = $deposits['summary']['balance']; */
|
||||
|
||||
|
||||
@@ -515,8 +523,8 @@ class LeasesController extends AppController {
|
||||
$outstanding_balance = $lease['Lease']['stats']['balance'];
|
||||
|
||||
// Determine the lease security deposit
|
||||
$deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||
$outstanding_deposit = $deposits['summary']['balance'];
|
||||
$deposits = $this->Lease->securityDeposits($lease['Lease']['id']);
|
||||
$outstanding_deposit = $deposits['summary']['Payment']['reconciled'];
|
||||
|
||||
// Set up dynamic menu items
|
||||
if (!isset($lease['Lease']['close_date'])) {
|
||||
|
||||
@@ -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());
|
||||
$this->Ledger->DoubleEntry->debitCreditFields(true));
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
|
||||
Reference in New Issue
Block a user