Another snapshot
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@356 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -35,7 +35,11 @@ class EntriesController extends AppController {
|
||||
$link =
|
||||
array(// Models
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
array('fields' => array('id', 'name', 'type'),
|
||||
),
|
||||
|
||||
'Ledger' =>
|
||||
array('fields' => array('id', 'sequence'),
|
||||
),
|
||||
|
||||
'DoubleEntry' => array
|
||||
@@ -43,6 +47,20 @@ class EntriesController extends AppController {
|
||||
array('fields' => array('id', 'stamp'),
|
||||
),
|
||||
|
||||
'DebitLedger' =>
|
||||
array('fields' => array('id'),
|
||||
'Account' => array('alias' => 'DebitAccount',
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'CreditLedger' =>
|
||||
array('fields' => array('id'),
|
||||
'Account' => array('alias' => 'CreditAccount',
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
@@ -56,23 +74,24 @@ class EntriesController extends AppController {
|
||||
),
|
||||
);
|
||||
|
||||
if ($params['action'] === 'collected' ||
|
||||
isset($params['custom']['reconcile_id'])) {
|
||||
$link['Payment'] = array(//'linkalias' => 'MatchingPayment',
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1) {
|
||||
$link['Payment'] = array('DoubleEntry' =>
|
||||
array('alias' => 'PaymentDoubleEntry',
|
||||
'Receipt'),
|
||||
'Account' => array('alias' => 'PaymentAccount'),
|
||||
'Receipt');
|
||||
$link['Charge'] = array(//'linkalias' => 'MatchingCharge',
|
||||
);
|
||||
$link['Charge'] = array('DoubleEntry' =>
|
||||
array('alias' => 'ChargeDoubleEntry',
|
||||
'Invoice'),
|
||||
'Account' => array('alias' => 'ChargeAccount'),
|
||||
'Invoice');
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['ledger_id'])) {
|
||||
$link['Ledger'] =
|
||||
array('fields' => array('id', 'sequence'),
|
||||
'Account' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
);
|
||||
elseif (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])) {
|
||||
$link['Charge'] = array('DoubleEntry' =>
|
||||
array('alias' => 'ChargeDoubleEntry',
|
||||
'Invoice'),
|
||||
'Account' => array('alias' => 'ChargeAccount'),
|
||||
);
|
||||
}
|
||||
|
||||
return array('link' => $link);
|
||||
@@ -81,20 +100,40 @@ class EntriesController extends AppController {
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
$fields = parent::jqGridDataFields($params, $model);
|
||||
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1)
|
||||
$fields[] = ('SUM(COALESCE(AppliedPayment.amount,0)' .
|
||||
' + COALESCE(AppliedCharge.amount,0)) AS applied');
|
||||
if (!isset($fields))
|
||||
$fields = array('Entry.*');
|
||||
|
||||
if (isset($params['custom']['reconcile_id'])) {
|
||||
$fields[] = array("IF(Entry.type = 'CHARGE',",
|
||||
" COALESCE(AppliedCharge.amount,0),",
|
||||
" COALESCE(AppliedPayment.amount,0))",
|
||||
" AS 'applied'");
|
||||
$fields[] = array("Entry.amount - (",
|
||||
"IF(Entry.type = 'CHARGE',",
|
||||
" COALESCE(AppliedCharge.amount,0),",
|
||||
" COALESCE(AppliedPayment.amount,0))",
|
||||
") AS 'balance'");
|
||||
/* if (isset($params['custom']['reconcile_id'])) { */
|
||||
/* $fields[] = array("IF(Entry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* " AS 'applied'"); */
|
||||
/* $fields[] = array("Entry.amount - (", */
|
||||
/* "IF(Entry.type = 'CHARGE',", */
|
||||
/* " COALESCE(AppliedCharge.amount,0),", */
|
||||
/* " COALESCE(AppliedPayment.amount,0))", */
|
||||
/* ") AS 'balance'"); */
|
||||
/* } */
|
||||
|
||||
if (isset($params['custom']['customer_id']) || isset($params['custom']['lease_id'])) {
|
||||
$fields[] = "IF(Entry.type = 'CHARGE', DoubleEntry.amount, NULL) AS debit";
|
||||
$fields[] = "IF(Entry.type = 'PAYMENT', DoubleEntry.amount, NULL) AS credit";
|
||||
$fields[] = "IF(Entry.type = 'CHARGE', 1, -1) * DoubleEntry.amount AS balance";
|
||||
}
|
||||
else {
|
||||
if (count(array_intersect($params['fields'], array('applied'))) == 1)
|
||||
$fields[] = ('SUM(COALESCE(AppliedPayment.amount,0)' .
|
||||
' + COALESCE(AppliedCharge.amount,0)) AS applied');
|
||||
|
||||
if (count(array_intersect($params['fields'], array('debit', 'credit'))) >= 1) {
|
||||
$fields = array_merge($fields,
|
||||
$this->Entry->DoubleEntry->debitCreditFields());
|
||||
/* $fields = array_merge($fields, */
|
||||
/* $this->Entry->Account->debitCreditFields()); */
|
||||
/* $fields[] = "IF(Entry.crdr = 'CREDIT', DoubleEntry.amount, NULL) AS credit"; */
|
||||
/* $fields[] = "IF(Entry.crdr = 'DEBIT', DoubleEntry.amount, NULL) AS debit"; */
|
||||
/* $fields[] = "IF(Account.type IN Entry.crdr = 'DEBIT', DoubleEntry.amount, NULL) AS debit"; */
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['action'] === 'collected')
|
||||
@@ -145,13 +184,37 @@ class EntriesController extends AppController {
|
||||
}
|
||||
|
||||
if (isset($params['custom']['customer_id'])) {
|
||||
$customer_id = $params['custom']['customer_id'];
|
||||
$conditions[] =
|
||||
array('Customer.id' => $params['custom']['customer_id']);
|
||||
array('OR' =>
|
||||
array(array(array('Entry.type' => 'CHARGE'),
|
||||
array('DoubleEntry.customer_id' => $customer_id)),
|
||||
array(array('Entry.type' => 'PAYMENT'),
|
||||
array('ChargeDoubleEntry.customer_id' => $customer_id)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($params['custom']['lease_id'])) {
|
||||
$lease_id = $params['custom']['lease_id'];
|
||||
$conditions[] =
|
||||
array('Lease.id' => $params['custom']['lease_id']);
|
||||
array('OR' =>
|
||||
array(array(array('Entry.type' => 'CHARGE'),
|
||||
array('DoubleEntry.lease_id' => $lease_id)),
|
||||
array(array('Entry.type' => 'PAYMENT'),
|
||||
array('ChargeDoubleEntry.lease_id' => $lease_id)),
|
||||
),
|
||||
);
|
||||
/* array('OR' => */
|
||||
/* array('AND' => */
|
||||
/* array(array('Entry.type' => 'CHARGE'), */
|
||||
/* array('DoubleEntry.lease_id' => $lease_id)) */
|
||||
/* ), */
|
||||
/* array('AND' => */
|
||||
/* array(array('Entry.type' => 'PAYMENT'), */
|
||||
/* array('ChargeDoubleEntry.lease_id' => $lease_id)), */
|
||||
/* ), */
|
||||
/* ); */
|
||||
}
|
||||
|
||||
if (isset($params['custom']['transaction_id'])) {
|
||||
|
||||
Reference in New Issue
Block a user