Many, many changes, and yet still much to do. Many things are working, but certainly nothing beyond simply data retrieval (no editing or adding of any data). Also, some work is still required to ensure the grids have the right columns; we can strip out certain columns for some views (such as removing customer from the leases grid of the customer view... completely redundant). And of course, there are still many bugs and lots to clean up.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@368 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-23 01:49:46 +00:00
parent 85edb1c658
commit 25bc1607cc
46 changed files with 616 additions and 1128 deletions

View File

@@ -107,7 +107,7 @@ class Account extends AppModel {
* on the overall balance of the account.
*/
function debitCreditFields($sum = false, $entry_name = 'Entry', $account_name = 'Account') {
function debitCreditFields($sum = false, $entry_name = 'LedgerEntry', $account_name = 'Account') {
return $this->LedgerEntry->debitCreditFields
($sum, $entry_name, $account_name);
}

View File

@@ -3,13 +3,6 @@ class Contact extends AppModel {
var $displayField = 'display_name';
var $validate = array(
'id' => array('numeric'),
'display_name' => array('notempty'),
'id_federal' => array('ssn'),
'id_exp' => array('date')
);
var $hasMany = array(
'ContactsMethod',
'ContactsCustomer',

View File

@@ -111,6 +111,7 @@ class Lease extends AppModel {
return false;
if (count($entries) != 1)
return null;
pr($entries);
return $entries[0]['StatementEntry']['through_date'];
}
@@ -425,7 +426,7 @@ class Lease extends AppModel {
$query['group'] = null;
$stats = $this->StatementEntry->find('first', $query);
pr(compact('query', 'stats'));
//pr(compact('query', 'stats'));
// The fields are all tucked into the [0] index,
// and the rest of the array is useless (empty).

View File

@@ -110,7 +110,7 @@ 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($sum = false, $entry_name = 'Entry', $account_name = 'Account') {
function debitCreditFields($sum = false, $entry_name = 'LedgerEntry', $account_name = 'Account') {
return $this->LedgerEntry->debitCreditFields
($sum, $entry_name, $account_name);
}
@@ -128,7 +128,7 @@ class Ledger extends AppModel {
$entries = $this->LedgerEntry->find
('all', array
('contain' => array('Ledger' => array('Account')),
('link' => array('Ledger' => array('Account')),
'fields' => array_merge(array("LedgerEntry.*"),
$this->LedgerEntry->debitCreditFields()),
'conditions' => array('LedgerEntry.ledger_id' => $ids),
@@ -151,14 +151,14 @@ class Ledger extends AppModel {
$this->queryInit($query);
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']['Ledger'])) */
/* $query['link']['Ledger'] = array(); */
/* if (!isset($query['link']['Ledger']['fields'])) */
/* $query['link']['Ledger']['fields'] = array(); */
if (!isset($query['link']['Account']))
$query['link']['Account'] = array();
if (!isset($query['link']['Account']['fields']))
$query['link']['Account']['fields'] = array();
/* if (!isset($query['link']['Transaction'])) */
/* $query['link']['Transaction'] = array(); */
/* if (!isset($query['link']['Transaction']['fields'])) */
@@ -175,7 +175,7 @@ class Ledger extends AppModel {
$query['group'][] = 'LedgerEntry.ledger_id';
$stats = $this->LedgerEntry->find('first', $query);
pr(compact('stats'));
//pr(compact('stats'));
/* unset($query['group']); */
@@ -187,6 +187,11 @@ class Ledger extends AppModel {
// and the rest of the array is useless (empty).
$stats = $stats[0];
// Make sure we have a member for debit/credit
foreach(array('debits', 'credits') AS $crdr)
if (!isset($stats[$crdr]))
$stats[$crdr] = null;
// Make sure we have a non-null balance
if (!isset($stats['balance']))
$stats['balance'] = 0;

View File

@@ -8,7 +8,7 @@ class LedgerEntry extends AppModel {
);
var $hasOne = array(
'Payment',
'Tender',
);
var $hasMany = array(
@@ -44,23 +44,23 @@ class LedgerEntry extends AppModel {
* on the overall balance of the account/ledger.
*/
function debitCreditFields($sum = false, $entry_name = 'Entry', $account_name = 'Account') {
function debitCreditFields($sum = false, $entry_name = 'LedgerEntry', $account_name = 'Account') {
$fields = array
(
($sum ? 'SUM(' : '') .
"IF({$entry_name}.type = 'DEBIT'," .
"IF({$entry_name}.crdr = 'DEBIT'," .
" {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS debit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.type = 'CREDIT'," .
"IF({$entry_name}.crdr = 'CREDIT'," .
" {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS credit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF(${account_name}.type IN ('ASSET', 'EXPENSE')," .
" IF({$entry_name}.type = 'DEBIT', 1, -1)," .
" IF({$entry_name}.type = 'CREDIT', 1, -1))" .
" IF({$entry_name}.crdr = 'DEBIT', 1, -1)," .
" IF({$entry_name}.crdr = 'CREDIT', 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance',
);

View File

@@ -274,7 +274,7 @@ OPTION 2
$resultset = array();
foreach ($result AS $i => $entry) {
pr(compact('entry'));
//pr(compact('entry'));
$entry['StatementEntry'] += $entry[0];
unset($entry[0]);
@@ -369,16 +369,12 @@ OPTION 2
//'type' => 'INNER',
);
$query['fields'] = array();
$query['fields'][] = "StatementEntry.amount AS total";
//$query['conditions'][] = array("{$Set}Entry.id !=" => null);
$query['fields'] = array('StatementEntry.amount');
$query['conditions'][] = array('StatementEntry.id' => $id);
$query['group'] = 'StatementEntry.id';
$result = $this->find('first', $query);
$result[0]['balance'] = $result[0]['total'] - $result[0]['reconciled'];
$result[0]['balance'] = $result['StatementEntry']['amount'] - $result[0]['reconciled'];
//pr(compact('query', 'result'));
return $result['StatementEntry'] + $result[0];

View File

@@ -1,5 +1,5 @@
<?php
class Payment extends AppModel {
class Tender extends AppModel {
var $belongsTo = array(
'LedgerEntry',
@@ -15,39 +15,39 @@ class Payment extends AppModel {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addPayment
* - Adds a new payment
* function: addTender
* - Adds a new tender
*/
function addPayment($data, $customer_id, $lease_id = null, $reconcile = null) {
function addTender($data, $customer_id, $lease_id = null, $reconcile = null) {
// Create some models for convenience
$A = new Account();
// Assume this will succeed
$ret = true;
// Establish the key payment parameters
$payment = array_intersect_key($data, array('stamp'=>1, 'type'=>1, 'name'=>1, 'amount'=>1,
// Establish the key tender parameters
$tender = array_intersect_key($data, array('stamp'=>1, 'type'=>1, 'name'=>1, 'amount'=>1,
'data1'=>1, 'data2'=>1, 'data3'=>1, 'data4'=>1));
$payment['customer_id'] = $customer_id;
$tender['customer_id'] = $customer_id;
// Create the payment entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a payment.
// Create the tender entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a tender.
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
($payment,
($tender,
array('debit_ledger_id' => $A->currentLedgerID($entry['account_id']),
'credit_ledger_id' => $A->currentLedgerID($A->paymentAccountID())
'credit_ledger_id' => $A->currentLedgerID($A->tenderAccountID())
) + $entry,
array('debit' => 'payment',
array('debit' => 'tender',
'credit' => $reconcile)
);
if ($ids['error'])
$ret = false;
$payment = array_intersect_key($ids,
array('payment_id'=>1,
'split_payment_id'=>1));
$tender = array_intersect_key($ids,
array('tender_id'=>1,
'split_tender_id'=>1));
return $ret;
}
@@ -84,7 +84,7 @@ class Payment extends AppModel {
*/
function nsf($id, $stamp = null) {
pr(array('Payment::nsf',
pr(array('Tender::nsf',
compact('id')));
$A = new Account();
@@ -96,7 +96,7 @@ class Payment extends AppModel {
array(/* e3 */
'LedgerEntry' =>
array('Transaction.id',
'Payment.id',
'Tender.id',
'Customer.id',
'Lease.id',
@@ -156,7 +156,7 @@ class Payment extends AppModel {
),
),
'conditions' => array(array('Payment.id' => $id)),
'conditions' => array(array('Tender.id' => $id)),
));
pr($source);