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:
@@ -8,27 +8,8 @@ class Ledger extends AppModel {
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'Entry',
|
||||
|
||||
'DoubleEntry' => array(
|
||||
'foreignKey' => false,
|
||||
|
||||
// conditions will be used when JOINing tables
|
||||
// (such as find with LinkableBehavior)
|
||||
'conditions' => array('OR' =>
|
||||
array('DoubleEntry.debit_ledger_id = %{MODEL_ALIAS}.id',
|
||||
'DoubleEntry.credit_ledger_id = %{MODEL_ALIAS}.id')),
|
||||
|
||||
// finderQuery will be used when tables are put
|
||||
// together across several querys, not with JOIN.
|
||||
// (such as find with ContainableBehavior)
|
||||
'finderQuery' => 'SELECT `DoubleEntry`.*
|
||||
FROM pmgr_double_entries AS `DoubleEntry`
|
||||
WHERE DoubleEntry.debit_ledger_id = ({$__cakeID__$})
|
||||
OR DoubleEntry.credit_ledger_id = ({$__cakeID__$})',
|
||||
|
||||
'counterQuery' => ''
|
||||
),
|
||||
'Transaction',
|
||||
'LedgerEntry',
|
||||
);
|
||||
|
||||
|
||||
@@ -111,7 +92,7 @@ class Ledger extends AppModel {
|
||||
'comment' => "Ledger Balance Forward",
|
||||
);
|
||||
|
||||
$carry_entry = new DoubleEntry();
|
||||
$carry_entry = new LedgerEntry();
|
||||
$carry_entry->create();
|
||||
if (!$carry_entry->save($carry_entry_data, false)) {
|
||||
return null;
|
||||
@@ -129,10 +110,9 @@ class Ledger extends AppModel {
|
||||
* entries are a debit, or a credit, and also the effect each have
|
||||
* on the overall balance of the ledger.
|
||||
*/
|
||||
function debitCreditFields($id, $sum = false,
|
||||
$entry_name = 'Entry', $double_name = 'DoubleEntry') {
|
||||
return $this->Account->debitCreditFields
|
||||
($this->accountID($id), $sum, $entry_name, $double_name);
|
||||
function debitCreditFields($sum = false, $entry_name = 'Entry', $account_name = 'Account') {
|
||||
return $this->LedgerEntry->debitCreditFields
|
||||
($sum, $entry_name, $account_name);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@@ -142,23 +122,16 @@ class Ledger extends AppModel {
|
||||
* - Returns an array of ledger entries that belong to a given
|
||||
* ledger. There is extra work done to establish debit/credit
|
||||
*/
|
||||
function ledgerEntries($ids, $cond = null, $link = null) {
|
||||
function ledgerEntries($ids, $query = null) {
|
||||
if (empty($ids))
|
||||
return null;
|
||||
|
||||
/* $id = (is_array($ids) ? $ids[0] : $ids); */
|
||||
/* $ftype = strtoupper($this->Account->fundamentalType($this->accountID($id))); */
|
||||
|
||||
$entries = $this->Entry->find
|
||||
$entries = $this->LedgerEntry->find
|
||||
('all', array
|
||||
('contain' => array('DoubleEntry' => array('fields' => array('amount'))),
|
||||
'fields' => array_merge(array("Entry.*"),
|
||||
$this->debitCreditFields(is_array($ids) ? $ids[0] : $ids)),
|
||||
/* "IF(Entry.crdr = 'CREDIT', DoubleEntry.amount, NULL) AS credit", */
|
||||
/* "IF(Entry.crdr = 'DEBIT', DoubleEntry.amount, NULL) AS debit", */
|
||||
/* "IF(Entry.crdr = '$ftype', 1, -1) * DoubleEntry.amount AS balance", */
|
||||
|
||||
'conditions' => array('Entry.ledger_id' => $ids),
|
||||
('contain' => array('Ledger' => array('Account')),
|
||||
'fields' => array_merge(array("LedgerEntry.*"),
|
||||
$this->LedgerEntry->debitCreditFields()),
|
||||
'conditions' => array('LedgerEntry.ledger_id' => $ids),
|
||||
));
|
||||
|
||||
//pr(compact('entries'));
|
||||
@@ -178,37 +151,37 @@ class Ledger extends AppModel {
|
||||
|
||||
$this->queryInit($query);
|
||||
|
||||
if (!isset($query['link']['Account']))
|
||||
$query['link']['Account'] = array();
|
||||
if (!isset($query['link']['Account']['fields']))
|
||||
$query['link']['Account']['fields'] = array();
|
||||
if (!isset($query['link']['Entry']))
|
||||
$query['link']['Entry'] = array();
|
||||
if (!isset($query['link']['Entry']['DoubleEntry']))
|
||||
$query['link']['Entry']['DoubleEntry'] = array();
|
||||
if (!isset($query['link']['Entry']['DoubleEntry']['fields']))
|
||||
$query['link']['Entry']['DoubleEntry']['fields'] = array();
|
||||
if (!isset($query['link']['Entry']['DoubleEntry']['Transaction']))
|
||||
$query['link']['Entry']['DoubleEntry']['Transaction'] = array();
|
||||
if (!isset($query['link']['Entry']['DoubleEntry']['Transaction']['fields']))
|
||||
$query['link']['Entry']['DoubleEntry']['Transaction']['fields'] = array();
|
||||
$query['link']['Entry']['DoubleEntry']['Transaction']['fields'][] = 'stamp';
|
||||
if (!isset($query['link']['Ledger']))
|
||||
$query['link']['Ledger'] = array();
|
||||
if (!isset($query['link']['Ledger']['fields']))
|
||||
$query['link']['Ledger']['fields'] = array();
|
||||
if (!isset($query['link']['Ledger']['Account']))
|
||||
$query['link']['Ledger']['Account'] = array();
|
||||
if (!isset($query['link']['Ledger']['Account']['fields']))
|
||||
$query['link']['Ledger']['Account']['fields'] = array();
|
||||
/* if (!isset($query['link']['Transaction'])) */
|
||||
/* $query['link']['Transaction'] = array(); */
|
||||
/* if (!isset($query['link']['Transaction']['fields'])) */
|
||||
/* $query['link']['Transaction']['fields'] = array(); */
|
||||
/* $query['link']['Transaction']['fields'][] = 'stamp'; */
|
||||
|
||||
if (!isset($query['fields']))
|
||||
$query['fields'] = array();
|
||||
|
||||
$query['fields'] = array_merge($query['fields'],
|
||||
$this->debitCreditFields($id, true));
|
||||
$this->debitCreditFields(true));
|
||||
|
||||
$query['conditions'][] = array('Ledger.id' => $id);
|
||||
$query['group'][] = 'Ledger.id';
|
||||
$query['conditions'][] = array('LedgerEntry.ledger_id' => $id);
|
||||
$query['group'][] = 'LedgerEntry.ledger_id';
|
||||
|
||||
$stats = $this->find('first', $query);
|
||||
$stats = $this->LedgerEntry->find('first', $query);
|
||||
pr(compact('stats'));
|
||||
|
||||
unset($query['group']);
|
||||
$query['fields'] = $this->debitCreditFields($id, false);
|
||||
$stats = $this->find('all', $query);
|
||||
pr(compact('query', 'stats'));
|
||||
|
||||
/* unset($query['group']); */
|
||||
/* $query['fields'] = $this->debitCreditFields($id, false); */
|
||||
/* $stats = $this->find('all', $query); */
|
||||
/* pr(compact('query', 'stats')); */
|
||||
|
||||
// The fields are all tucked into the [0] index,
|
||||
// and the rest of the array is useless (empty).
|
||||
|
||||
Reference in New Issue
Block a user