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/site@360 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-21 10:23:52 +00:00
parent 5a16e497ad
commit f52fba96c1
25 changed files with 1159 additions and 980 deletions

View File

@@ -16,6 +16,7 @@ class Account extends AppModel {
var $hasMany = array(
'Ledger',
'LedgerEntry',
);
@@ -105,30 +106,10 @@ class Account extends AppModel {
* entries are a debit, or a credit, and also the effect each have
* on the overall balance of the account.
*/
function debitCreditFields($id, $sum = false,
$entry_name = 'Entry', $double_name = 'DoubleEntry') {
$ftype = strtoupper($this->fundamentalType($id));
$fields = array
(
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = 'DEBIT', {$double_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS debit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = 'CREDIT', {$double_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS credit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = '$ftype', 1, -1) * {$double_name}.amount" .
// IF({$double_name}.amount, {$double_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance',
);
if ($sum)
$fields[] = "COUNT({$entry_name}.id) AS entries";
return $fields;
function debitCreditFields($sum = false, $entry_name = 'Entry', $account_name = 'Account') {
return $this->LedgerEntry->debitCreditFields
($sum, $entry_name, $account_name);
}
@@ -410,7 +391,7 @@ class Account extends AppModel {
$unreconciled = $this->unreconciledEntries($id, 'CHARGE', $cond, $link);
foreach ($unreconciled AS $i => &$item) {
$entry =& $item['DoubleEntry'];
$entry =& $item['LedgerEntry'];
// Determine if amount is sufficient to cover the entry
if ($amount > $entry['balance'])
$apply = $entry['balance'];
@@ -509,7 +490,7 @@ class Account extends AppModel {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: postDoubleEntry
* function: postLedgerEntry
* -
* transaction_data
* - transaction_id (optional... if set all else is ignored)
@@ -524,7 +505,7 @@ class Account extends AppModel {
* - name
*/
function postDoubleEntry($transaction_data,
function postLedgerEntry($transaction_data,
$monetary_data,
$entry_data,
$reconcile = null) {
@@ -577,7 +558,7 @@ class Account extends AppModel {
// No distinguishing features of Cash, just
// use the shared monetary source
$monetary_data['monetary_source_id'] =
$this->Ledger->DoubleEntry->MonetarySource->nameToID('Cash');
$this->Ledger->LedgerEntry->MonetarySource->nameToID('Cash');
}
}
@@ -645,7 +626,7 @@ class Account extends AppModel {
//pr(array('pre-save', compact('entry_data')));
// Create it!
$new_entry = new DoubleEntry();
$new_entry = new LedgerEntry();
$new_entry->create();
if (!$new_entry->saveAll($entry_data, array('validate'=>false))) {
return array('error' => true);
@@ -700,7 +681,7 @@ class Account extends AppModel {
// Payment must debit the Receipt ledger, and credit the A/R ledger
// debit: Receipt credit: A/R
$ids = $this->postDoubleEntry
$ids = $this->postLedgerEntry
($split_transaction,
null,
array('debit_ledger_id' => $this->currentLedgerID($this->receiptAccountID()),
@@ -709,9 +690,9 @@ class Account extends AppModel {
'lease_id' => $rec['lease_id'],
'customer_id' => $rec['customer_id'],
),
array('debit' => array(array('DoubleEntry' => array('id' => $new_entry->id,
array('debit' => array(array('LedgerEntry' => array('id' => $new_entry->id,
'amount' => $rec['applied']))),
'credit' => array(array('DoubleEntry' => array('id' => $rec['id'],
'credit' => array(array('LedgerEntry' => array('id' => $rec['id'],
'amount' => $rec['applied']))))
);
// Keep using the same split transaction for all reconciled entries
@@ -728,19 +709,19 @@ class Account extends AppModel {
if (is_array($reconcile_set)) {
//pr("reconcile_set is array");
foreach ($reconcile_set AS $reconcile_entry) {
if (!isset($reconcile_entry['DoubleEntry']['id']))
if (!isset($reconcile_entry['LedgerEntry']['id']))
continue;
$amount = $reconcile_entry['DoubleEntry']['amount'];
$amount = $reconcile_entry['LedgerEntry']['amount'];
if (!$amount)
continue;
if ($dc_type == 'debit') {
$debit_ledger_entry_id = $new_entry->id;
$credit_ledger_entry_id = $reconcile_entry['DoubleEntry']['id'];
$credit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
}
else {
$debit_ledger_entry_id = $reconcile_entry['DoubleEntry']['id'];
$debit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
$credit_ledger_entry_id = $new_entry->id;
}
@@ -760,9 +741,9 @@ class Account extends AppModel {
$ret = array
('error' => $err,
'id' => $new_entry->data['DoubleEntry']['id'],
'transaction_id' => $new_entry->data['DoubleEntry']['transaction_id'],
'monetary_source_id' => $new_entry->data['DoubleEntry']['monetary_source_id']);
'id' => $new_entry->data['LedgerEntry']['id'],
'transaction_id' => $new_entry->data['LedgerEntry']['transaction_id'],
'monetary_source_id' => $new_entry->data['LedgerEntry']['monetary_source_id']);
if (isset($split_transaction['transaction_id']))
$ret['split_transaction_id'] = $split_transaction['transaction_id'];
@@ -794,7 +775,7 @@ class Account extends AppModel {
if ($ledger['total'] == 0)
continue;
$ids = $this->postDoubleEntry
$ids = $this->postLedgerEntry
($transaction,
null,
array('debit_account_id' => $deposit_account_id,
@@ -806,7 +787,7 @@ class Account extends AppModel {
//pr(compact('ids'));
if ($ids['error'])
die("closeAndDeposit : postDoubleEntry returned error!");
die("closeAndDeposit : postLedgerEntry returned error!");
$transaction = array_intersect_key($ids, array('transaction_id'=>1));