Compare commits
2 Commits
main
...
statement_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae09d160bb | ||
|
|
4ee9c99e30 |
@@ -1000,9 +1000,9 @@ CREATE TABLE `pmgr_transactions` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- TABLE pmgr_ledger_entries
|
-- TABLE pmgr_ledger_entries
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_ledger_entries`;
|
DROP TABLE IF EXISTS `pmgr_ledger_entries`;
|
||||||
CREATE TABLE `pmgr_ledger_entries` (
|
CREATE TABLE `pmgr_ledger_entries` (
|
||||||
@@ -1028,9 +1028,9 @@ CREATE TABLE `pmgr_ledger_entries` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- TABLE pmgr_double_entries
|
-- TABLE pmgr_double_entries
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_double_entries`;
|
DROP TABLE IF EXISTS `pmgr_double_entries`;
|
||||||
CREATE TABLE `pmgr_double_entries` (
|
CREATE TABLE `pmgr_double_entries` (
|
||||||
@@ -1053,9 +1053,9 @@ CREATE TABLE `pmgr_double_entries` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- ----------------------------------------------------------------------
|
-- ----------------------------------------------------------------------
|
||||||
-- -- TABLE pmgr_statement_entries
|
-- TABLE pmgr_statement_entries
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `pmgr_statement_entries`;
|
DROP TABLE IF EXISTS `pmgr_statement_entries`;
|
||||||
CREATE TABLE `pmgr_statement_entries` (
|
CREATE TABLE `pmgr_statement_entries` (
|
||||||
@@ -1090,12 +1090,9 @@ CREATE TABLE `pmgr_statement_entries` (
|
|||||||
|
|
||||||
`amount` FLOAT(12,2) NOT NULL,
|
`amount` FLOAT(12,2) NOT NULL,
|
||||||
|
|
||||||
-- The account of the entry
|
-- Account ID is used only for those statement entries that have
|
||||||
-- REVISIT <AP>: 20090720
|
-- a guaranteed single ledger entry, and thus single account.
|
||||||
-- We don't want to confuse statement entries with ledger entries,
|
-- Right now, this is only used for charges.
|
||||||
-- 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` INT(10) UNSIGNED DEFAULT NULL,
|
`account_id` INT(10) UNSIGNED DEFAULT NULL,
|
||||||
|
|
||||||
-- Allow the payment to reconcile against the charge
|
-- Allow the payment to reconcile against the charge
|
||||||
@@ -1107,6 +1104,27 @@ CREATE TABLE `pmgr_statement_entries` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) 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
|
-- TABLE pmgr_tender_types
|
||||||
|
|||||||
@@ -1098,6 +1098,17 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'}
|
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'}
|
||||||
= $newdb{'tables'}{'statement_entries'}{'autoid'};
|
= $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'};
|
next unless $row->{'TaxAmount'};
|
||||||
|
|
||||||
# # Add the tax charge entry
|
# # Add the tax charge entry
|
||||||
@@ -1315,6 +1326,7 @@ foreach $row (@{query($sdbh, $query)})
|
|||||||
'amount' => $reconcile_amount,
|
'amount' => $reconcile_amount,
|
||||||
|
|
||||||
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'},
|
'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
|
$row->{'ChargeID'} = undef
|
||||||
@@ -1343,7 +1355,6 @@ foreach $row (@{query($sdbh, $query)})
|
|||||||
'through_date' => $through_date,
|
'through_date' => $through_date,
|
||||||
'customer_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'},
|
'customer_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'},
|
||||||
'lease_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'lease_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'},
|
'amount' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'},
|
||||||
'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'},
|
'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'},
|
||||||
'comment' => $comment,
|
'comment' => $comment,
|
||||||
@@ -1351,6 +1362,17 @@ foreach $row (@{query($sdbh, $query)})
|
|||||||
|
|
||||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'}
|
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'}
|
||||||
= $newdb{'tables'}{'statement_entries'}{'autoid'};
|
= $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.
|
* to jqGrid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function gridDataTables(&$params, &$model) {
|
function gridDataCountTables(&$params, &$model) {
|
||||||
$link =
|
$link =
|
||||||
array(// Models
|
array(// Models
|
||||||
'Transaction' =>
|
'Transaction' =>
|
||||||
@@ -42,10 +42,6 @@ class StatementEntriesController extends AppController {
|
|||||||
array('fields' => array('id', 'name'),
|
array('fields' => array('id', 'name'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
'Account' =>
|
|
||||||
array('fields' => array('id', 'name', 'type'),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($params['post']['custom']['statement_entry_id'])) {
|
if (isset($params['post']['custom']['statement_entry_id'])) {
|
||||||
@@ -53,25 +49,32 @@ class StatementEntriesController extends AppController {
|
|||||||
$link['ChargeEntry'] = array();
|
$link['ChargeEntry'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if ($params['action'] === 'collected') { */
|
if (isset($params['post']['custom']['account_id'])) {
|
||||||
/* $link['PaymentEntry'] = array('Receipt' => array('class' => 'Transaction')); */
|
$link['LedgerEntry'] = array('fields' => array('id'));
|
||||||
/* $link['ChargeEntry'] = array('Invoice' => array('class' => 'Transaction')); */
|
$link['LedgerEntry']['Account'] = array('fields' => array('id', 'name', 'type'));
|
||||||
/* } */
|
}
|
||||||
|
|
||||||
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
|
/* if (count(array_intersect($params['fields'], array('applied'))) == 1) { */
|
||||||
/* $link['PaymentEntry'] = array(); */
|
/* $link['PaymentEntry'] = array(); */
|
||||||
/* $link['ChargeEntry'] = array(); */
|
/* $link['ChargeEntry'] = array(); */
|
||||||
/* } */
|
|
||||||
/* elseif (isset($params['post']['custom']['customer_id']) || isset($params['post']['custom']['lease_id'])) { */
|
|
||||||
/* $link['PaymentEntry'] = array(); */
|
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
return array('link' => $link);
|
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) {
|
function gridDataFields(&$params, &$model) {
|
||||||
|
//foreach(
|
||||||
$fields = parent::gridDataFields($params, $model);
|
$fields = parent::gridDataFields($params, $model);
|
||||||
|
|
||||||
|
$fields[] = "COUNT(LedgerEntry.id) AS ledger_entry_count";
|
||||||
|
|
||||||
if (in_array('applied', $params['post']['fields'])) {
|
if (in_array('applied', $params['post']['fields'])) {
|
||||||
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
|
$fields[] = ("IF(StatementEntry.type = 'CHARGE'," .
|
||||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
||||||
@@ -105,7 +108,7 @@ class StatementEntriesController extends AppController {
|
|||||||
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
|
$this->StatementEntry->Transaction->dateFormatBeforeSave($through_date . ' 23:59:59'));
|
||||||
|
|
||||||
if (isset($account_id))
|
if (isset($account_id))
|
||||||
$conditions[] = array('StatementEntry.account_id' => $account_id);
|
$conditions[] = array('LedgerEntry.account_id' => $account_id);
|
||||||
|
|
||||||
if (isset($statement_entry_id)) {
|
if (isset($statement_entry_id)) {
|
||||||
$conditions[] = array('OR' =>
|
$conditions[] = array('OR' =>
|
||||||
@@ -116,6 +119,14 @@ class StatementEntriesController extends AppController {
|
|||||||
return $conditions;
|
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) {
|
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||||
$links['StatementEntry'] = array('id');
|
$links['StatementEntry'] = array('id');
|
||||||
$links['Transaction'] = array('id');
|
$links['Transaction'] = array('id');
|
||||||
@@ -144,7 +155,7 @@ class StatementEntriesController extends AppController {
|
|||||||
if (in_array('applied', $params['post']['fields'])) {
|
if (in_array('applied', $params['post']['fields'])) {
|
||||||
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
|
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
|
||||||
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
|
$tquery['fields'] = array("IF(StatementEntry.type = 'CHARGE'," .
|
||||||
" SUM(COALESCE(PaymentEntry.amount,0))," .
|
" SUM(COALESCE(StatementFraction.amount,0))," .
|
||||||
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
" SUM(COALESCE(ChargeEntry.amount,0)))" .
|
||||||
" AS 'applied'",
|
" AS 'applied'",
|
||||||
|
|
||||||
@@ -197,18 +208,22 @@ class StatementEntriesController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the StatementEntry and related fields
|
// Get the StatementEntry and related fields
|
||||||
|
$this->StatementEntry->prClassLevel(30, 'Model');
|
||||||
$entry = $this->StatementEntry->find
|
$entry = $this->StatementEntry->find
|
||||||
('first',
|
('first',
|
||||||
array('contain' => array
|
array('contain' => array
|
||||||
('Transaction' => array('fields' => array('id', 'stamp')),
|
('Transaction' => array('fields' => array('id', 'stamp')),
|
||||||
'Account' => array('id', 'name', 'type'),
|
|
||||||
'Customer' => array('fields' => array('id', 'name')),
|
'Customer' => array('fields' => array('id', 'name')),
|
||||||
'Lease' => array('fields' => array('id')),
|
'Lease' => array('fields' => array('id')),
|
||||||
|
'LedgerEntry' => array('fields' => array('id'),
|
||||||
|
'Account' => array('id', 'name', 'type')),
|
||||||
),
|
),
|
||||||
|
|
||||||
'conditions' => array('StatementEntry.id' => $id),
|
'conditions' => array('StatementEntry.id' => $id),
|
||||||
));
|
));
|
||||||
|
pr($entry);
|
||||||
|
//die();
|
||||||
|
|
||||||
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
$reconciled = $this->StatementEntry->reconciledEntries($id);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Customer extends AppModel {
|
|||||||
|
|
||||||
$query['conditions'][] = array('Customer.id' => $id);
|
$query['conditions'][] = array('Customer.id' => $id);
|
||||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||||
$this->StatementEntry->Account->securityDepositAccountID());
|
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||||
|
|
||||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, false, true);
|
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, false, true);
|
||||||
return $this->prReturn($set);
|
return $this->prReturn($set);
|
||||||
@@ -113,7 +113,7 @@ class Customer extends AppModel {
|
|||||||
|
|
||||||
$query['conditions'][] = array('Lease.id' => $id);
|
$query['conditions'][] = array('Lease.id' => $id);
|
||||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||||
$this->StatementEntry->Account->securityDepositAccountID());
|
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||||
|
|
||||||
$stats = $this->StatementEntry->stats(null, $query);
|
$stats = $this->StatementEntry->stats(null, $query);
|
||||||
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Lease extends AppModel {
|
|||||||
|
|
||||||
$query['conditions'][] = array('Lease.id' => $id);
|
$query['conditions'][] = array('Lease.id' => $id);
|
||||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||||
$this->StatementEntry->Account->securityDepositAccountID());
|
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||||
|
|
||||||
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, false, true);
|
$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('Lease.id' => $id);
|
||||||
$query['conditions'][] = array('StatementEntry.account_id' =>
|
$query['conditions'][] = array('StatementEntry.account_id' =>
|
||||||
$this->StatementEntry->Account->securityDepositAccountID());
|
$this->StatementEntry->LedgerEntry->Account->securityDepositAccountID());
|
||||||
|
|
||||||
$stats = $this->StatementEntry->stats(null, $query);
|
$stats = $this->StatementEntry->stats(null, $query);
|
||||||
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
$balance = $stats['Charge']['reconciled'] - $stats['Payment']['reconciled'];
|
||||||
@@ -115,7 +115,7 @@ class Lease extends AppModel {
|
|||||||
|
|
||||||
$release['Entry'][] =
|
$release['Entry'][] =
|
||||||
array('amount' => $charge['StatementEntry']['reconciled'],
|
array('amount' => $charge['StatementEntry']['reconciled'],
|
||||||
'account_id' => $this->StatementEntry->Account->securityDepositAccountID(),
|
'account_id' => $this->StatementEntry->LedgerEntry->Account->securityDepositAccountID(),
|
||||||
'comment' => "Released Security Deposit",
|
'comment' => "Released Security Deposit",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ class Lease extends AppModel {
|
|||||||
|
|
||||||
function rentLastCharges($id) {
|
function rentLastCharges($id) {
|
||||||
$this->prEnter(compact('id'));
|
$this->prEnter(compact('id'));
|
||||||
$rent_account_id = $this->StatementEntry->Account->rentAccountID();
|
$rent_account_id = $this->StatementEntry->LedgerEntry->Account->rentAccountID();
|
||||||
$entries = $this->find
|
$entries = $this->find
|
||||||
('all',
|
('all',
|
||||||
array('link' =>
|
array('link' =>
|
||||||
@@ -221,7 +221,7 @@ class Lease extends AppModel {
|
|||||||
|
|
||||||
function rentPaidThrough($id) {
|
function rentPaidThrough($id) {
|
||||||
$this->prEnter(compact('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,
|
// First, see if we can find any unpaid entries. Of course,
|
||||||
// the first unpaid entry gives us a very direct indication
|
// the first unpaid entry gives us a very direct indication
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ class LedgerEntry extends AppModel {
|
|||||||
'foreignKey' => 'debit_entry_id',
|
'foreignKey' => 'debit_entry_id',
|
||||||
'associationForeignKey' => 'credit_entry_id',
|
'associationForeignKey' => 'credit_entry_id',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
//
|
||||||
|
'StatementEntry' => array(
|
||||||
|
'joinTable' => 'statement_fractions',
|
||||||
|
'fields' => 'StatementFraction.amount',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ class StatementEntry extends AppModel {
|
|||||||
'Transaction',
|
'Transaction',
|
||||||
'Customer',
|
'Customer',
|
||||||
'Lease',
|
'Lease',
|
||||||
'Account',
|
|
||||||
|
|
||||||
// The charge to which this payment applies (if it is one)
|
// The charge to which this payment applies (if it is one)
|
||||||
'ChargeEntry' => array(
|
'ChargeEntry' => array(
|
||||||
@@ -20,6 +19,14 @@ class StatementEntry extends AppModel {
|
|||||||
'foreignKey' => 'charge_entry_id',
|
'foreignKey' => 'charge_entry_id',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'StatementFraction',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasAndBelongsToMany = array(
|
||||||
|
'LedgerEntry' => array(
|
||||||
|
'joinTable' => 'statement_fractions',
|
||||||
|
//'fields' => 'StatementFraction.amount',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
//var $default_log_level = 30;
|
//var $default_log_level = 30;
|
||||||
@@ -66,12 +73,11 @@ class StatementEntry extends AppModel {
|
|||||||
* (not in a pre-existing statement entry)
|
* (not in a pre-existing statement entry)
|
||||||
*/
|
*/
|
||||||
function verifyStatementEntry($entry) {
|
function verifyStatementEntry($entry) {
|
||||||
$this->prFunctionLevel(10);
|
$this->prFunctionLevel(30);
|
||||||
$this->prEnter(compact('entry'));
|
$this->prEnter(compact('entry'));
|
||||||
|
|
||||||
if (empty($entry['type']) ||
|
if (empty($entry['type']) ||
|
||||||
//empty($entry['effective_date']) ||
|
//empty($entry['effective_date']) ||
|
||||||
empty($entry['account_id']) ||
|
|
||||||
empty($entry['amount'])
|
empty($entry['amount'])
|
||||||
) {
|
) {
|
||||||
return $this->prReturn(false);
|
return $this->prReturn(false);
|
||||||
@@ -101,6 +107,12 @@ class StatementEntry extends AppModel {
|
|||||||
if (!$this->save($entry))
|
if (!$this->save($entry))
|
||||||
return array('error' => true, 'save_data' => $entry) + $ret;
|
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;
|
$ret['statement_entry_id'] = $this->id;
|
||||||
return $this->prReturn($ret + array('error' => false));
|
return $this->prReturn($ret + array('error' => false));
|
||||||
}
|
}
|
||||||
@@ -335,7 +347,7 @@ OPTION 2
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function assignCredits($query = null, $receipt_id = null) {
|
function assignCredits($query = null, $receipt_id = null) {
|
||||||
//$this->prFunctionLevel(25);
|
$this->prFunctionLevel(25);
|
||||||
$this->prEnter( compact('query', 'receipt_id'));
|
$this->prEnter( compact('query', 'receipt_id'));
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
|
|
||||||
@@ -352,16 +364,17 @@ OPTION 2
|
|||||||
// Next, establish credit from the newly added receipt
|
// Next, establish credit from the newly added receipt
|
||||||
$receipt_credit = null;
|
$receipt_credit = null;
|
||||||
if (!empty($receipt_id)) {
|
if (!empty($receipt_id)) {
|
||||||
$lquery = $query;
|
$lquery = array
|
||||||
$lquery['link'] += array('LedgerEntry' =>
|
('contain' => array
|
||||||
array('conditions' =>
|
('LedgerEntry' =>
|
||||||
//array(LedgerEntry.'crdr'=>'DEBIT'),
|
array('conditions' =>
|
||||||
array('LedgerEntry.account_id !=' => $this->Account->accountReceivableAccountID()),
|
//array(LedgerEntry.'crdr'=>'DEBIT'),
|
||||||
));
|
array('LedgerEntry.account_id !=' =>
|
||||||
$lquery['fields'] = array('Transaction.id', 'Transaction.stamp', 'Transaction.amount',
|
$this->LedgerEntry->Account->accountReceivableAccountID()),
|
||||||
'LedgerEntry.account_id');
|
),
|
||||||
// Very specific case here... no extra conditions
|
),
|
||||||
unset($lquery['conditions']);
|
);
|
||||||
|
|
||||||
$this->Transaction->id = $receipt_id;
|
$this->Transaction->id = $receipt_id;
|
||||||
$receipt_credit = $this->Transaction->find('first', $lquery);
|
$receipt_credit = $this->Transaction->find('first', $lquery);
|
||||||
if (!$receipt_credit)
|
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
|
// REVISIT <AP>: 20090802
|
||||||
// Completely un-implemented. Just copied from addReceipt
|
// Completely un-implemented. Just copied from addReceipt
|
||||||
// and search-replace receipt with waiver.
|
// and search-replace receipt with waiver.
|
||||||
return ('error' => true);
|
return array('error' => true);
|
||||||
|
|
||||||
// Establish the transaction as a waiver
|
// Establish the transaction as a waiver
|
||||||
$waiver =& $data['Transaction'];
|
$waiver =& $data['Transaction'];
|
||||||
@@ -427,7 +427,7 @@ class Transaction extends AppModel {
|
|||||||
// Create the statement entry
|
// Create the statement entry
|
||||||
$se =
|
$se =
|
||||||
array_intersect_key($entry,
|
array_intersect_key($entry,
|
||||||
array_flip(array('type', 'account_id', 'amount',
|
array_flip(array('type', 'amount',
|
||||||
'effective_date', 'through_date', 'due_date',
|
'effective_date', 'through_date', 'due_date',
|
||||||
'customer_id', 'lease_id',
|
'customer_id', 'lease_id',
|
||||||
'charge_entry_id'))) +
|
'charge_entry_id'))) +
|
||||||
@@ -502,7 +502,11 @@ class Transaction extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($se)) {
|
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['transaction_id'] = $ret['transaction_id'];
|
||||||
|
$se['Fraction'] = array(array('ledger_entry_id' => $le_id,
|
||||||
|
'amount' => $se['amount']));
|
||||||
$result = $this->StatementEntry->addStatementEntry($se);
|
$result = $this->StatementEntry->addStatementEntry($se);
|
||||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||||
if ($result['error']) {
|
if ($result['error']) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ echo '<div class="statement-entry view">' . "\n";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$transaction = $entry['Transaction'];
|
$transaction = $entry['Transaction'];
|
||||||
$account = $entry['Account'];
|
$account = $entry['LedgerEntry'][0]['Account'];
|
||||||
$customer = $entry['Customer'];
|
$customer = $entry['Customer'];
|
||||||
$lease = $entry['Lease'];
|
$lease = $entry['Lease'];
|
||||||
$entry = $entry['StatementEntry'];
|
$entry = $entry['StatementEntry'];
|
||||||
|
|||||||
Reference in New Issue
Block a user