A working version of the collected report for accounts. There is still some error checking to do, since we don't want this report for just any account. Also, we may wish to do away with the form to prevent accidental submittal. Finally, it would be nice to do away with the button, and automatically update on date changes.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@324 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-13 02:24:31 +00:00
parent 03af4e731f
commit 8a3c6ae21b
6 changed files with 195 additions and 105 deletions

View File

@@ -146,77 +146,26 @@ class AccountsController extends AppController {
* - Displays the items actually collected for the period
* e.g. How much was collected in rent from 4/1/09 - 5/1/09
*/
function collected($id) {
//if ($this->data) {
//pr($this->data);
//}
function collected($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
/* $tillable_account = $this->Account->relatedAccounts('tillable'); */
/* $depositable_account = $this->Account->relatedAccounts('depositable'); */
$payment_accounts = $this->Account->paymentAccounts();
$default_accounts = array_diff_key($payment_accounts,
array($this->Account->concessionAccountID() => 1));
$this->set(compact('payment_accounts', 'default_accounts'));
$ledger_entries =
$this->Account->Ledger->LedgerEntry->find
('all',
array('link' => array
('Ledger' =>
array('fields' => array('sequence'),
$this->Account->recursive = -1;
$account = $this->Account->read(null, $id);
$account = $account['Account'];
'Account' =>
array('fields' => array('id', 'name')),
),
'MonetarySource' =>
array('fields' => array('name')),
'Customer' =>
array('fields' => array('name')),
'Transaction' =>
array('fields' => array('stamp')),
// Income / Receipt flow
// debit: Receipt credit: A/R <-- this entry
// debit: A/R credit: Income <-- CRLE, below
//
// We're searching for the Receipt<->A/R entries,
// which are credits on the A/R account. Find the
// reconciling A/R entries (except for unassigned
// pre-payments, all A/R credits should have one).
'CreditReconciliationLedgerEntry' =>
array('alias' => 'RLedgerEntry',
'fields' => true,
'Transaction' =>
array('alias' => 'RTransaction',
'fields' => array('stamp')),
// Debit should be A/R; Credit is Account of interest
'CreditLedger' =>
array('alias' => 'RLedger',
'fields' => true,
'Account' =>
array('alias' => 'RAccount',
'fields' => true,
),
),
),
),
'fields' => array('LedgerEntry.*', 'Reconciliation.amount'),
'conditions' => array(array('RAccount.id' => $id),
//array('Account.tillable' => 1),
),
));
pr(compact('ledger_entries'));
$title = 'Collected Whatever';
$this->set(compact('title', 'ledger_entries'));
//$this->render('/empty');
$title = ($account['name'] . ': Collected Report');
$this->set(compact('account', 'title'));
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -337,8 +286,7 @@ class AccountsController extends AppController {
$this->sidemenu_links[] =
array('name' => 'New Ledger', 'url' => array('action' => 'newledger', $id));
$this->sidemenu_links[] =
array('name' => 'Collected', 'url' => array('controller' => 'ledger_entries',
'action' => 'collected', $id));
array('name' => 'Collected', 'url' => array('action' => 'collected', $id));
// Prepare to render
$title = 'Account: ' . $account['Account']['name'];

View File

@@ -16,22 +16,6 @@ class LedgerEntriesController extends AppController {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index / etc
* - Generate a listing of ledger_entries
*/
function collected($account_id) {
$A = new Account();
$this->set('collected_account_id', $account_id);
$this->jqGridView('Collected ' .
$this->LedgerEntry->Ledger->Account->name($account_id) .
' Entries');
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -214,22 +198,27 @@ class LedgerEntriesController extends AppController {
$conditions = parent::jqGridDataConditions($params, $model);
if ($params['action'] === 'collected') {
$conditions[] = array('Account.id' => $params['custom']['collected_account_id']);
//$conditions[] = array('DebitAccount.tillable' => 1);
//$conditions[] = array('ReceiptLedgerEntry.amount != LedgerEntry.amount');
//$conditions[] = array('Reconciliation.amount < ReceiptLedgerEntry.amount');
$conditions[] = array('MoneyAccount.payable' => 1);
$conditions[] = array('NOT' => array('MoneyAccount.name' => 'Concession'));
//$conditions[] = array('DA.name' => 'Check');
//$conditions[] = array('DA.name' => 'Cash');
//$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-03-26');
//$conditions[] = array('ReceiptTransaction.stamp <' => '2009-04-11');
//$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-04-11');
//$conditions[] = array('ReceiptTransaction.stamp <' => '2009-05-09');
//$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-05-09');
//$conditions[] = array('ReceiptTransaction.stamp <' => '2009-06-11');
$conditions[] = array('ReceiptTransaction.stamp >=' => '2009-06-11');
$conditions[] = array('ReceiptTransaction.stamp <' => '2009-07-11');
extract($params['custom']);
if (isset($collected_account_id))
$conditions[] = array('Account.id' => $params['custom']['collected_account_id']);
else
die("INTERNAL ERROR: COLLECTED ACCOUNT ID NOT SET");
if (isset($collected_from_date))
$conditions[]
= array('ReceiptTransaction.stamp >=' =>
$this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_from_date));
if (isset($collected_through_date))
$conditions[]
= array('ReceiptTransaction.stamp <=' =>
$this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_through_date . ' 23:59:59'));
if (isset($collected_payment_accounts))
$conditions[] = array('MoneyAccount.id' => $collected_payment_accounts);
else
$conditions[] = array('MoneyAccount.payable' => 1);
}
if ($params['action'] === 'ledger') {

View File

@@ -119,6 +119,7 @@ class Account extends AppModel {
function cashAccountID() { return $this->nameToID('Cash'); }
function checkAccountID() { return $this->nameToID('Check'); }
function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
function concessionAccountID() { return $this->nameToID('Concession'); }
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }
function invoiceAccountID() { return $this->nameToID('Invoice'); }
function receiptAccountID() { return $this->nameToID('Receipt'); }

View File

@@ -0,0 +1,145 @@
<?php /* -*- mode:PHP -*- */
echo '<div class="account collected">' . "\n";
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Javascript
*/
?>
<script type="text/javascript"><!--
// Reset the form
function resetForm() {
/* $('#payment-entry-id').val(1); */
/* $('#payments').html(''); */
/* $("#receipt-customer-id").html("INTERNAL ERROR"); */
/* $("#receipt-customer-name").html("INTERNAL ERROR"); */
/* $("#receipt-balance").html("INTERNAL ERROR"); */
/* $("#receipt-charges-caption").html("Outstanding Charges"); */
/* datepickerBOM(null, 'TxFromDate'); */
/* datepickerNow('TxThroughDate', false); */
/* updateEntriesGrid(); */
}
function updateEntriesGrid() {
var cust = new Array();
var account_ids = new Array();
$("INPUT[type='checkbox']:checked").each(function(i) {
account_ids.push($(this).val());
});
cust['collected_account_id'] = <?php echo $account['id']; ?>;
cust['collected_from_date'] = $('#TxFromDate').val();
cust['collected_through_date'] = $('#TxThroughDate').val();
cust['collected_payment_accounts'] = account_ids;
$('#collected-entries-jqGrid').clearGridData();
$('#collected-entries-jqGrid').setPostDataItem('custom', serialize(cust));
$('#collected-entries-jqGrid')
.setGridParam({ page: 1 })
.trigger("reloadGrid");
}
--></script>
<?php
; // align
//echo '<DIV ID="dialog">' . "\n";
echo $form->create(null, array('id' => 'receipt-form',
//'onsubmit' => 'updateEntriesGrid(); return false',
'url' => array('controller' => 'transactions',
'action' => 'postReceipt')));
echo $form->input("id",
array('id' => 'account-id',
'type' => 'hidden',
'value' => 0));
echo $this->element('form_table',
array('class' => "item account collected entry",
//'with_name_after' => ':',
'field_prefix' => 'Tx.',
'fields' => array
("account_id" => array('name' => 'Account',
'opts' =>
array('type' => 'select',
'multiple' => 'checkbox',
'options' => $paymentAccounts,
'selected' => array_keys($defaultAccounts),
),
),
"from_date" => array('opts' =>
array('type' => 'text'),
'between' => '<A HREF="#" ONCLICK="datepickerBOM(null,\'TxFromDate\'); return false;">BOM</A>',
),
"through_date" => array('opts' =>
array('type' => 'text'),
'between' => '<A HREF="#" ONCLICK="datepickerEOM(\'TxFromDate\',\'TxThroughDate\'); return false;">EOM</A>',
),
),
));
echo $form->button('Update',
array('onclick' => 'updateEntriesGrid(); return false',
));
echo $form->end();
echo $this->element('ledger_entries', array
(// Element configuration
'collected_account_id' => $account['id'],
'collected_payment_accounts' => array_keys($defaultAccounts),
// Grid configuration
'config' => array
(
'grid_div_id' => 'collected-entries',
'grid_div_class' => 'text-below',
//'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'caption' => 'Collected Charges',
),
));
echo('<DIV CLASS="grid-selection-text">' .
'<TABLE ID="supporting-table">' .
'<TR><TD CLASS="field">Balance:</TD><TD CLASS="value"><SPAN id="collected-balance"></SPAN></TD></TR>' .
'</TABLE>' .
'</DIV>' .
"\n");
?>
<script type="text/javascript"><!--
$(document).ready(function(){
$("#TxFromDate")
.attr('autocomplete', 'off')
.datepicker({ constrainInput: true,
numberOfMonths: [1, 1],
showCurrentAtPos: 0,
dateFormat: 'mm/dd/yy' });
$("#TxThroughDate")
.attr('autocomplete', 'off')
.datepicker({ constrainInput: true,
numberOfMonths: [1, 1],
showCurrentAtPos: 0,
dateFormat: 'mm/dd/yy' });
resetForm();
});
--></script>
</div>
<a href="#" onClick="$('#debug').html(''); return false;">Clear Debug Output</a>

View File

@@ -64,8 +64,10 @@ foreach ($fields AS $field => $config) {
elseif (isset($field_prefix) && !isset($config['no_prefix']))
$field = $field_prefix . '.' . $field;
$config['opts']['label'] = false;
$config['opts']['div'] = false;
if (!isset($config['opts']['label']))
$config['opts']['label'] = false;
if (!isset($config['opts']['div']))
$config['opts']['div'] = false;
$cells = array();
if ($include_before) {

View File

@@ -88,6 +88,12 @@ if (isset($account_ftype))
$grid->invalidFields('Sub-Total');
// Now that columns are defined, establish basic grid parameters
$grid
->columns($cols)
->sortField('Date')
->defaultFields(array('Entry', 'Date', 'Amount', 'Credit', 'Debit'));
if (!isset($config['rows']) && !isset($collected_account_id)) {
$config['action'] = 'ledger';
@@ -99,7 +105,9 @@ if (isset($reconcile_id)) {
}
if (isset($collected_account_id)) {
$config['action'] = 'collected';
$grid->customData(compact('collected_account_id'))->limit(500);
$grid->sortField('Paid');
}
// Set up search fields if requested by caller
@@ -113,9 +121,6 @@ $grid->customData(compact('ledger_id', 'account_id', 'ar_account',
// Render the grid
$grid
->columns($cols)
->sortField('Date')
->defaultFields(array('Entry', 'Date', 'Amount', 'Credit', 'Debit'))
->render($this, isset($config) ? $config : null,
array('Transaction', 'Entry', 'Date', 'Effective', 'Paid',
'Account', 'Debit Account', 'Credit Account',