Captured some thoughts, some experiments on how to tie statement entry to ledger entry. It's not at all clear we want to go down this (or any other) path at the moment. This checkin will probably go nowhere, as I'm going to see if we can make do with the current implementation.
git-svn-id: file:///svn-source/pmgr/branches/statement_ledger_entry_tie_20090802@468 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -1000,9 +1000,9 @@ CREATE TABLE `pmgr_transactions` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- TABLE pmgr_ledger_entries
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_ledger_entries
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_ledger_entries`;
|
||||
CREATE TABLE `pmgr_ledger_entries` (
|
||||
@@ -1028,9 +1028,9 @@ CREATE TABLE `pmgr_ledger_entries` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- TABLE pmgr_double_entries
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_double_entries
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_double_entries`;
|
||||
CREATE TABLE `pmgr_double_entries` (
|
||||
@@ -1053,9 +1053,9 @@ CREATE TABLE `pmgr_double_entries` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- ----------------------------------------------------------------------
|
||||
-- -- TABLE pmgr_statement_entries
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_statement_entries
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_statement_entries`;
|
||||
CREATE TABLE `pmgr_statement_entries` (
|
||||
@@ -1090,12 +1090,9 @@ CREATE TABLE `pmgr_statement_entries` (
|
||||
|
||||
`amount` FLOAT(12,2) NOT NULL,
|
||||
|
||||
-- The account of the entry
|
||||
-- REVISIT <AP>: 20090720
|
||||
-- We don't want to confuse statement entries with ledger entries,
|
||||
-- yet we're including account here. It doesn't feel right, but at
|
||||
-- the same time, it will allow us to show _what_ was charged for
|
||||
-- in the statement. Keeping it for now...
|
||||
-- Account ID is used only for those statement entries that have
|
||||
-- a guaranteed single ledger entry, and thus single account.
|
||||
-- Right now, this is only used for charges.
|
||||
`account_id` INT(10) UNSIGNED DEFAULT NULL,
|
||||
|
||||
-- Allow the payment to reconcile against the charge
|
||||
@@ -1107,6 +1104,27 @@ CREATE TABLE `pmgr_statement_entries` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_statement_entries_ledger_entries
|
||||
-- TABLE pmgr_statement_fractions
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_statement_fractions`;
|
||||
CREATE TABLE `pmgr_statement_fractions` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
||||
-- The two entries that make up a "double entry"
|
||||
`statement_entry_id` INT(10) UNSIGNED NOT NULL,
|
||||
`ledger_entry_id` INT(10) UNSIGNED NOT NULL,
|
||||
|
||||
`amount` FLOAT(12,2) NOT NULL,
|
||||
|
||||
`comment` VARCHAR(255) DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_tender_types
|
||||
|
||||
@@ -1098,6 +1098,17 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'}
|
||||
= $newdb{'tables'}{'statement_entries'}{'autoid'};
|
||||
|
||||
# Add the Charge Statement Entry Fraction
|
||||
addRow('statement_fractions', {
|
||||
'statement_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'},
|
||||
'ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_entry_id'},
|
||||
'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'},
|
||||
#'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_fraction_id'}
|
||||
= $newdb{'tables'}{'statement_fractions'}{'autoid'};
|
||||
|
||||
next unless $row->{'TaxAmount'};
|
||||
|
||||
# # Add the tax charge entry
|
||||
@@ -1315,6 +1326,7 @@ foreach $row (@{query($sdbh, $query)})
|
||||
'amount' => $reconcile_amount,
|
||||
|
||||
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'},
|
||||
'debit_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'},
|
||||
};
|
||||
|
||||
$row->{'ChargeID'} = undef
|
||||
@@ -1343,7 +1355,6 @@ foreach $row (@{query($sdbh, $query)})
|
||||
'through_date' => $through_date,
|
||||
'customer_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'},
|
||||
'lease_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'lease_id'},
|
||||
'account_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'account_id'},
|
||||
'amount' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'},
|
||||
'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'},
|
||||
'comment' => $comment,
|
||||
@@ -1351,6 +1362,17 @@ foreach $row (@{query($sdbh, $query)})
|
||||
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'}
|
||||
= $newdb{'tables'}{'statement_entries'}{'autoid'};
|
||||
|
||||
# Add the Charge Statement Entry Fraction
|
||||
addRow('statement_fractions', {
|
||||
'statement_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'},
|
||||
'ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_entry_id'},
|
||||
'amount' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'},
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_fraction_id'}
|
||||
= $newdb{'tables'}{'statement_fractions'}{'autoid'};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class StatementEntriesController extends AppController {
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
function gridDataCountTables(&$params, &$model) {
|
||||
$link =
|
||||
array(// Models
|
||||
'Transaction' =>
|
||||
@@ -42,10 +42,6 @@ class StatementEntriesController extends AppController {
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name', 'type'),
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($params['post']['custom']['statement_entry_id'])) {
|
||||
@@ -53,25 +49,32 @@ class StatementEntriesController extends AppController {
|
||||
$link['ChargeEntry'] = array();
|
||||
}
|
||||
|
||||
/* if ($params['action'] === 'collected') { */
|
||||
/* $link['PaymentEntry'] = array('Receipt' => array('class' => 'Transaction')); */
|
||||
/* $link['ChargeEntry'] = array('Invoice' => array('class' => 'Transaction')); */
|
||||
/* } */
|
||||
if (isset($params['post']['custom']['account_id'])) {
|
||||
$link['LedgerEntry'] = array('fields' => array('id'));
|
||||
$link['LedgerEntry']['Account'] = array('fields' => array('id', 'name', 'type'));
|
||||
}
|
||||
|
||||
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
|
||||
/* $link['PaymentEntry'] = array(); */
|
||||
/* $link['ChargeEntry'] = array(); */
|
||||
/* } */
|
||||
/* elseif (isset($params['post']['custom']['customer_id']) || isset($params['post']['custom']['lease_id'])) { */
|
||||
/* $link['PaymentEntry'] = array(); */
|
||||
/* } */
|
||||
|
||||
return array('link' => $link);
|
||||
}
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
$tables = $this->gridDataCountTables($params, $model);
|
||||
$tables['link']['LedgerEntry'] = array('fields' => array('id'));
|
||||
$tables['link']['LedgerEntry']['Account'] = array('fields' => array('id', 'name', 'type'));
|
||||
return $tables;
|
||||
}
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
//foreach(
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
|
||||
$fields[] = "COUNT(LedgerEntry.id) AS ledger_entry_count";
|
||||
|
||||
if (in_array('applied', $params['post']['fields'])) {
|
||||
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||
@@ -105,7 +108,7 @@ class StatementEntriesController extends AppController {
|
||||
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
|
||||
|
||||
if (isset($account_id))
|
||||
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
||||
$conditions[] = array('LedgerEntry.account_id' => $account_id);
|
||||
|
||||
if (isset($statement_entry_id)) {
|
||||
$conditions[] = array('OR' =>
|
||||
@@ -116,6 +119,14 @@ class StatementEntriesController extends AppController {
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function gridDataPostProcessCalculatedFields(&$params, &$model, &$records) {
|
||||
parent::gridDataPostProcessCalculatedFields($params, $model, $records);
|
||||
foreach ($records AS &$record) {
|
||||
if ($record['StatementEntry']['ledger_entry_count'] > 1)
|
||||
$record['Account']['name'] = 'Multiple';
|
||||
}
|
||||
}
|
||||
|
||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||
$links['StatementEntry'] = array('id');
|
||||
$links['Transaction'] = array('id');
|
||||
@@ -144,7 +155,7 @@ class StatementEntriesController extends AppController {
|
||||
if (in_array('applied', $params['post']['fields'])) {
|
||||
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
|
||||
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
|
||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||
" SUM(COALESCE(StatementFraction.amount,0))," .
|
||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||
" AS 'applied'",
|
||||
|
||||
@@ -197,17 +208,21 @@ class StatementEntriesController extends AppController {
|
||||
}
|
||||
|
||||
// Get the StatementEntry and related fields
|
||||
$this->StatementEntry->prClassLevel(30, 'Model');
|
||||
$entry = $this->StatementEntry->find
|
||||
('first',
|
||||
array('contain' => array
|
||||
('Transaction' => array('fields' => array('id', 'stamp')),
|
||||
'Account' => array('id', 'name', 'type'),
|
||||
'Customer' => array('fields' => array('id', 'name')),
|
||||
'Lease' => array('fields' => array('id')),
|
||||
'LedgerEntry' => array('fields' => array('id'),
|
||||
'Account' => array('id', 'name', 'type')),
|
||||
),
|
||||
|
||||
'conditions' => array('StatementEntry.id' => $id),
|
||||
));
|
||||
pr($entry);
|
||||
//die();
|
||||
|
||||
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class Customer extends AppModel {
|
||||
|
||||
$query['conditions'][] = array('Customer.id' => $id);
|
||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||
$this->StatementEntry->Account->securityDepositAccountID());
|
||||
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||
|
||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, false, true);
|
||||
return $this->prReturn($set);
|
||||
@@ -113,7 +113,7 @@ class Customer extends AppModel {
|
||||
|
||||
$query['conditions'][] = array('Lease.id' => $id);
|
||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||
$this->StatementEntry->Account->securityDepositAccountID());
|
||||
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||
|
||||
$stats = $this->StatementEntry->stats(null, $query);
|
||||
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
||||
|
||||
@@ -30,7 +30,7 @@ class Lease extends AppModel {
|
||||
|
||||
$query['conditions'][] = array('Lease.id' => $id);
|
||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||
$this->StatementEntry->Account->securityDepositAccountID());
|
||||
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||
|
||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, false, true);
|
||||
|
||||
@@ -60,7 +60,7 @@ class Lease extends AppModel {
|
||||
|
||||
$query['conditions'][] = array('Lease.id' => $id);
|
||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||
$this->StatementEntry->Account->securityDepositAccountID());
|
||||
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||
|
||||
$stats = $this->StatementEntry->stats(null, $query);
|
||||
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
||||
@@ -115,7 +115,7 @@ class Lease extends AppModel {
|
||||
|
||||
$release['Entry'][] =
|
||||
array('amount' => $charge['StatementEntry']['reconciled'],
|
||||
'account_id' => $this->StatementEntry->Account->securityDepositAccountID(),
|
||||
'account_id' => $this->StatementEntry->LedgerEntry->Account->securityDepositAccountID(),
|
||||
'comment' => "Released Security Deposit",
|
||||
);
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class Lease extends AppModel {
|
||||
|
||||
function rentLastCharges($id) {
|
||||
$this->prEnter(compact('id'));
|
||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||
$rent_account_id = $this->StatementEntry->LedgerEntry->Account->rentAccountID();
|
||||
$entries = $this->find
|
||||
('all',
|
||||
array('link' =>
|
||||
@@ -221,7 +221,7 @@ class Lease extends AppModel {
|
||||
|
||||
function rentPaidThrough($id) {
|
||||
$this->prEnter(compact('id'));
|
||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
||||
$rent_account_id = $this->StatementEntry->LedgerEntry->Account->rentAccountID();
|
||||
|
||||
// First, see if we can find any unpaid entries. Of course,
|
||||
// the first unpaid entry gives us a very direct indication
|
||||
|
||||
@@ -33,6 +33,12 @@ class LedgerEntry extends AppModel {
|
||||
'foreignKey' => 'debit_entry_id',
|
||||
'associationForeignKey' => 'credit_entry_id',
|
||||
),
|
||||
|
||||
//
|
||||
'StatementEntry' => array(
|
||||
'joinTable' => 'statement_fractions',
|
||||
'fields' => 'StatementFraction.amount',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ class StatementEntry extends AppModel {
|
||||
'Transaction',
|
||||
'Customer',
|
||||
'Lease',
|
||||
'Account',
|
||||
|
||||
// The charge to which this payment applies (if it is one)
|
||||
'ChargeEntry' => array(
|
||||
@@ -20,6 +19,14 @@ class StatementEntry extends AppModel {
|
||||
'foreignKey' => 'charge_entry_id',
|
||||
),
|
||||
|
||||
'StatementFraction',
|
||||
);
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'LedgerEntry' => array(
|
||||
'joinTable' => 'statement_fractions',
|
||||
//'fields' => 'StatementFraction.amount',
|
||||
),
|
||||
);
|
||||
|
||||
//var $default_log_level = 30;
|
||||
@@ -66,12 +73,11 @@ class StatementEntry extends AppModel {
|
||||
* (not in a pre-existing statement entry)
|
||||
*/
|
||||
function verifyStatementEntry($entry) {
|
||||
$this->prFunctionLevel(10);
|
||||
$this->prFunctionLevel(30);
|
||||
$this->prEnter(compact('entry'));
|
||||
|
||||
if (empty($entry['type']) ||
|
||||
//empty($entry['effective_date']) ||
|
||||
empty($entry['account_id']) ||
|
||||
empty($entry['amount'])
|
||||
) {
|
||||
return $this->prReturn(false);
|
||||
@@ -101,6 +107,12 @@ class StatementEntry extends AppModel {
|
||||
if (!$this->save($entry))
|
||||
return array('error' => true, 'save_data' => $entry) + $ret;
|
||||
|
||||
foreach ($entry['Fraction'] AS $fraction) {
|
||||
$fraction['statement_entry_id'] = $this->id;
|
||||
$this->StatementFraction->id = null;
|
||||
$this->StatementFraction->save($fraction);
|
||||
}
|
||||
|
||||
$ret['statement_entry_id'] = $this->id;
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
@@ -335,7 +347,7 @@ OPTION 2
|
||||
*
|
||||
*/
|
||||
function assignCredits($query = null, $receipt_id = null) {
|
||||
//$this->prFunctionLevel(25);
|
||||
$this->prFunctionLevel(25);
|
||||
$this->prEnter( compact('query', 'receipt_id'));
|
||||
$this->queryInit($query);
|
||||
|
||||
@@ -352,16 +364,17 @@ OPTION 2
|
||||
// Next, establish credit from the newly added receipt
|
||||
$receipt_credit = null;
|
||||
if (!empty($receipt_id)) {
|
||||
$lquery = $query;
|
||||
$lquery['link'] += array('LedgerEntry' =>
|
||||
array('conditions' =>
|
||||
//array(LedgerEntry.'crdr'=>'DEBIT'),
|
||||
array('LedgerEntry.account_id !=' => $this->Account->accountReceivableAccountID()),
|
||||
));
|
||||
$lquery['fields'] = array('Transaction.id', 'Transaction.stamp', 'Transaction.amount',
|
||||
'LedgerEntry.account_id');
|
||||
// Very specific case here... no extra conditions
|
||||
unset($lquery['conditions']);
|
||||
$lquery = array
|
||||
('contain' => array
|
||||
('LedgerEntry' =>
|
||||
array('conditions' =>
|
||||
//array(LedgerEntry.'crdr'=>'DEBIT'),
|
||||
array('LedgerEntry.account_id !=' =>
|
||||
$this->LedgerEntry->Account->accountReceivableAccountID()),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->Transaction->id = $receipt_id;
|
||||
$receipt_credit = $this->Transaction->find('first', $lquery);
|
||||
if (!$receipt_credit)
|
||||
|
||||
9
site/models/statement_fraction.php
Normal file
9
site/models/statement_fraction.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class StatementFraction extends AppModel {
|
||||
|
||||
var $belongsTo = array(
|
||||
'StatementEntry',
|
||||
'LedgerEntry',
|
||||
);
|
||||
|
||||
}
|
||||
@@ -118,7 +118,7 @@ class Transaction extends AppModel {
|
||||
// REVISIT <AP>: 20090802
|
||||
// Completely un-implemented. Just copied from addReceipt
|
||||
// and search-replace receipt with waiver.
|
||||
return ('error' => true);
|
||||
return array('error' => true);
|
||||
|
||||
// Establish the transaction as a waiver
|
||||
$waiver =& $data['Transaction'];
|
||||
@@ -427,7 +427,7 @@ class Transaction extends AppModel {
|
||||
// Create the statement entry
|
||||
$se =
|
||||
array_intersect_key($entry,
|
||||
array_flip(array('type', 'account_id', 'amount',
|
||||
array_flip(array('type', 'amount',
|
||||
'effective_date', 'through_date', 'due_date',
|
||||
'customer_id', 'lease_id',
|
||||
'charge_entry_id'))) +
|
||||
@@ -502,7 +502,11 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
if (!empty($se)) {
|
||||
//pr($ret['entries'][$e_index]['DoubleEntry']); die;
|
||||
$le_id = $ret['entries'][0]['DoubleEntry']['Entry1']['ledger_entry_id'];
|
||||
$se['transaction_id'] = $ret['transaction_id'];
|
||||
$se['Fraction'] = array(array('ledger_entry_id' => $le_id,
|
||||
'amount' => $se['amount']));
|
||||
$result = $this->StatementEntry->addStatementEntry($se);
|
||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
|
||||
@@ -10,7 +10,7 @@ echo '<div class="statement-entry view">' . "\n";
|
||||
*/
|
||||
|
||||
$transaction = $entry['Transaction'];
|
||||
$account = $entry['Account'];
|
||||
$account = $entry['LedgerEntry'][0]['Account'];
|
||||
$customer = $entry['Customer'];
|
||||
$lease = $entry['Lease'];
|
||||
$entry = $entry['StatementEntry'];
|
||||
|
||||
Reference in New Issue
Block a user