Very, very messy and broken. It does work somewhat, but I can see just what a mess it's going to be to carry it out, so I'm abandoning.
git-svn-id: file:///svn-source/pmgr/branches/reconcile_entry_to_receipt_20090629@187 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -33,7 +33,7 @@ class LedgerEntriesController extends AppController {
|
||||
}
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
function jqGridDataCountTables(&$params, &$model) {
|
||||
$link =
|
||||
array(// Models
|
||||
'Transaction' =>
|
||||
@@ -95,8 +95,13 @@ class LedgerEntriesController extends AppController {
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['account_id'])) {
|
||||
$account_id = $params['custom']['account_id'];
|
||||
if (isset($params['custom']['account_id']) || isset($params['custom']['lease_id'])) {
|
||||
if (isset($params['custom']['account_id']))
|
||||
$account_id = $params['custom']['account_id'];
|
||||
else
|
||||
$account_id =
|
||||
$this->LedgerEntry->DebitLedger->Account->accountReceivableAccountID();
|
||||
|
||||
$link['Ledger'] =
|
||||
array('fields' => array('id', 'sequence'),
|
||||
'conditions' => ("Ledger.id = IF(DebitLedger.account_id = $account_id," .
|
||||
@@ -108,18 +113,57 @@ class LedgerEntriesController extends AppController {
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$account_id = $params['custom']['lease_id'];
|
||||
$link['Transaction']['ReconciledLedgerEntry'] =
|
||||
array('fields' => array('id', 'Reconciliation.amount', 'Reconciliation.type'),
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['reconcile_id'])) {
|
||||
$ftype = $params['custom']['account_ftype'];
|
||||
$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
||||
$ftype = ucfirst($ftype);
|
||||
$link[$ftype.'ReconciliationLedgerEntry'] =
|
||||
array('fields' => array('Reconciliation.amount'));
|
||||
$link['ReconcilingTransaction'] =
|
||||
array('fields' => array('Reconciliation.amount'),
|
||||
'conditions' => array('Reconciliation.type' => $ftype),
|
||||
);
|
||||
}
|
||||
|
||||
return array('link' => $link);
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
return $this->jqGridDataCountTables($params, $model);
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$account_id =
|
||||
$this->LedgerEntry->DebitLedger->Account->accountReceivableAccountID();
|
||||
|
||||
$fields = array('id', 'name', 'comment', 'amount');
|
||||
$fields[] = ("IF(DebitLedger.account_id = $account_id," .
|
||||
" SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
||||
" LedgerEntry.amount," .
|
||||
" ReconciledLedgerEntry.amount))," .
|
||||
" NULL) AS debit");
|
||||
$fields[] = ("IF(CreditLedger.account_id = $account_id," .
|
||||
" SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
||||
" LedgerEntry.amount," .
|
||||
" ReconciledLedgerEntry.amount))," .
|
||||
" NULL) AS credit");
|
||||
|
||||
$Account = new Account();
|
||||
$account_ftype = ucfirst($Account->fundamentalType($account_id));
|
||||
$fields[] = ("(IF({$account_ftype}Ledger.account_id = $account_id, 1, -1)" .
|
||||
" * SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
||||
" LedgerEntry.amount," .
|
||||
" ReconciledLedgerEntry.amount)))" .
|
||||
" AS balance");
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
$ledger_id = (isset($params['custom']['ledger_id'])
|
||||
? $params['custom']['ledger_id']
|
||||
: null);
|
||||
@@ -143,60 +187,39 @@ class LedgerEntriesController extends AppController {
|
||||
|
||||
$conditions = parent::jqGridDataConditions($params, $model);
|
||||
|
||||
if ($params['action'] === 'ledger') {
|
||||
if ($params['action'] === 'ledger' && isset($ledger_id)) {
|
||||
$conditions[] = $model->ledgerContextConditions($ledger_id, $account_type);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['reconcile_id'])) {
|
||||
$ftype = $params['custom']['account_ftype'];
|
||||
//$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
||||
$conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']);
|
||||
//$link['ReconcilingTransaction']['conditions'][] = array('Reconciliation.type' => $ftype);
|
||||
$conditions[] = array('Reconciliation.ledger_entry_id' => $params['custom']['reconcile_id']);
|
||||
|
||||
}
|
||||
|
||||
if (isset($params['custom']['account_id'])) {
|
||||
$conditions[] =
|
||||
array('OR' =>
|
||||
array('OR' =>
|
||||
array(array('CreditAccount.id' => $params['custom']['account_id']),
|
||||
array('DebitAccount.id' => $params['custom']['account_id'])));
|
||||
/* $conditions[] = */
|
||||
/* array('Account.id' => $params['custom']['account_id']); */
|
||||
|
||||
}
|
||||
|
||||
if (isset($params['custom']['customer_id'])) {
|
||||
$conditions[] =
|
||||
array('Customer.id' => $params['custom']['customer_id']);
|
||||
|
||||
/* $Account = new Account(); */
|
||||
/* if (isset($params['custom']['account_ftype']) || */
|
||||
/* isset($params['custom']['ledger_id'])) { */
|
||||
/* $conditions[] = */
|
||||
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
|
||||
/* 'Account.id' => $Account->receiptAccountID())); */
|
||||
/* } else { */
|
||||
/* $conditions[] = */
|
||||
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
|
||||
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
|
||||
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
|
||||
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
|
||||
/* )); */
|
||||
/* } */
|
||||
}
|
||||
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$conditions[] =
|
||||
array('Lease.id' => $params['custom']['lease_id']);
|
||||
|
||||
/* $Account = new Account(); */
|
||||
/* if (isset($params['custom']['account_ftype']) || */
|
||||
/* isset($params['custom']['ledger_id'])) { */
|
||||
/* $conditions[] = */
|
||||
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
|
||||
/* 'Account.id' => $Account->receiptAccountID())); */
|
||||
/* } else { */
|
||||
/* $conditions[] = */
|
||||
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
|
||||
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
|
||||
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
|
||||
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
|
||||
/* )); */
|
||||
/* } */
|
||||
array('OR' => array
|
||||
(array('Lease.id' => $params['custom']['lease_id']),
|
||||
array('ReconciledLedgerEntry.lease_id' => $params['custom']['lease_id']),
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($params['custom']['transaction_id'])) {
|
||||
@@ -304,7 +327,7 @@ class LedgerEntriesController extends AppController {
|
||||
|
||||
'conditions' => array('LedgerEntry.id' => $id),
|
||||
));
|
||||
pr($entry);
|
||||
//pr($entry);
|
||||
|
||||
// Because 'DebitLedger' and 'CreditLedger' both relate to 'Account',
|
||||
// CakePHP will not include them in the LedgerEntry->find (or so it
|
||||
@@ -334,8 +357,8 @@ class LedgerEntriesController extends AppController {
|
||||
$stats['credit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['credit_amount_reconciled'];
|
||||
//pr($stats);
|
||||
|
||||
$reconciled = $this->LedgerEntry->findReconciledLedgerEntries($id);
|
||||
//pr($reconciled);
|
||||
$reconciled = $this->LedgerEntry->findReconcilingTransactions($id);
|
||||
//pr(compact('reconciled'));
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
|
||||
|
||||
Reference in New Issue
Block a user