diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php
index d0a1238..d3e8ef7 100644
--- a/site/controllers/customers_controller.php
+++ b/site/controllers/customers_controller.php
@@ -180,15 +180,59 @@ class CustomersController extends AppController {
/* $customer = $this->data; */
/* } */
if (isset($id)) {
- $customer = $this->Customer->details($id);
- unset($customer['deposits']['Entries']);
+ $this->Customer->recursive = -1;
+ $customer = $this->Customer->read(null, $id);
+ $customer = $customer['Customer'];
+ $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
+ $charges = $unreconciled['debit'];
}
else {
$customer = null;
+ $charges = array('balance' => 0, 'entry' => array());
}
$title = 'Payment Entry';
- $this->set(compact('customer', 'title'));
+ $this->set(compact('customer', 'charges', 'title'));
+ }
+
+
+ /**************************************************************************
+ **************************************************************************
+ **************************************************************************
+ * action: unreconciledEntries
+ * - returns the list of unreconciled entries
+ */
+
+ function unreconciled($id) {
+
+ //$this->layout = 'ajax';
+ $this->layout = null;
+ $this->autoLayout = false;
+ $this->autoRender = false;
+ Configure::write('debug', '0');
+ header("Content-type: text/xml;charset=utf-8");
+
+ App::import('Helper', 'Xml');
+ $xml = new XmlHelper();
+
+ // Find the unreconciled entries, then manipulate the structure
+ // slightly to accomodate the format necessary for XML Helper.
+ $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
+ $unreconciled = array('entries' =>
+ array_intersect_key($unreconciled['debit'],
+ array('entry'=>1, 'balance'=>1)));
+
+ // XML Helper will dump an empty tag if the array is empty
+ if (!count($unreconciled['entries']['entry']))
+ unset($unreconciled['entries']['entry']);
+
+ pr($unreconciled);
+ //$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount);
+
+ $opts = array();
+ //$opts['format'] = 'tags';
+ echo $xml->header();
+ echo $xml->serialize($unreconciled, $opts);
}
}
diff --git a/site/models/account.php b/site/models/account.php
index 8945109..e007bc8 100644
--- a/site/models/account.php
+++ b/site/models/account.php
@@ -236,7 +236,7 @@ class Account extends AppModel {
? array($fundamental_type)
: array('debit', 'credit')) AS $fund) {
$ucfund = ucfirst($fund);
- $unreconciled[$fund]['entries'] = $this->find
+ $unreconciled[$fund]['entry'] = $this->find
('all', array
('link' => array
('Ledger' => array
@@ -261,7 +261,7 @@ class Account extends AppModel {
'fields' => array(),
));
$balance = 0;
- foreach ($unreconciled[$fund]['entries'] AS &$entry) {
+ foreach ($unreconciled[$fund]['entry'] AS &$entry) {
$entry = array_merge(array_diff_key($entry["LedgerEntry"], array(0=>true)),
$entry[0]);
$balance += $entry['balance'];
@@ -289,7 +289,7 @@ class Account extends AppModel {
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
$ofund = $this->fundamentalOpposite($fundamental_type);
- $unreconciled = array($ofund => array('entries'=>array(), 'balance'=>0));
+ $unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
$applied = 0;
// if there is no money in the entry, it can reconcile nothing
@@ -297,7 +297,7 @@ class Account extends AppModel {
if ($amount > 0) {
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund);
- foreach ($unreconciled[$ofund]['entries'] AS $i => &$entry) {
+ foreach ($unreconciled[$ofund]['entry'] AS $i => &$entry) {
// Determine if amount is sufficient to cover the entry
if ($amount > $entry['balance'])
$apply = $entry['balance'];
diff --git a/site/models/customer.php b/site/models/customer.php
index e6475d5..4064fe0 100644
--- a/site/models/customer.php
+++ b/site/models/customer.php
@@ -122,7 +122,7 @@ class Customer extends AppModel {
$left = &$unreconciled[$type];
$right = &$unrec[$type];
- $left['entries'] = array_merge($left['entries'], $right['entries']);
+ $left['entry'] = array_merge($left['entry'], $right['entry']);
$left['balance'] += $right['balance'];
}
}
@@ -159,7 +159,7 @@ class Customer extends AppModel {
$left = &$reconciled[$type];
$right = &$rec[$type];
- $left['entries'] = array_merge($left['entries'], $right['entries']);
+ $left['entry'] = array_merge($left['entry'], $right['entry']);
$left['balance'] += $right['balance'];
$left['applied'] += $right['applied'];
$left['unapplied'] = $right['unapplied'];
diff --git a/site/views/customers/payment.ctp b/site/views/customers/payment.ctp
index 9023240..2ec59e5 100644
--- a/site/views/customers/payment.ctp
+++ b/site/views/customers/payment.ctp
@@ -54,36 +54,14 @@
$grid_setup = array();
-if (isset($customer['Customer']['id']))
+if (isset($customer['id']))
$grid_setup['hiddengrid'] = true;
$grid_setup['onSelectRow'] = array
('--special' =>
- 'function(ids) { if (ids != null)' .
- ' {' .
- // Set the customer id that will be returned with the form
- ' $("#customer-id").val(ids);' .
- // Get the customer name from the grid
- ' $("#payment_customer").html($("#"+$(this).attr("id"))' .
- ' .getCell(ids, "Customer-name"));' .
- // Replace that with just the text portion of the hyperlink
- ' $("#payment_customer").html("Receipt for "+ $("#payment_customer a").html());' .
- ' } }'
+ 'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
);
-/* $grid_setup['loadComplete'] = array */
-/* ('--special' => */
-/* 'function() { ' . */
-/* //' $("#"+$(this).attr("id")).setSelection($("#customer-id").val());' . */
-/* ' $(\'#customers-list-jqGrid\').setSelection($(\'#customer-id\').val());' . */
-/* ' $("#"+$(this).attr("id")).setCaption("Hello");' . */
-/* ' alert("Loaded");' . */
-/* ' }' */
-/* ); */
-
-
-//pr($customer);
-//echo ('Get grid code
');
// Customer
// Outstanding balance
@@ -95,7 +73,7 @@ $grid_setup['onSelectRow'] = array
?>
-
' . "\n";
echo $this->element('customers',
- array('caption' => 'Select Customer',
+ array('grid_div_id' => 'customers-list',
+ 'caption' => ('Select Customer'),
'limit' => 7,
'grid_setup' => $grid_setup,
));
-echo ('