diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php
index fb60635..bab2c95 100644
--- a/site/controllers/customers_controller.php
+++ b/site/controllers/customers_controller.php
@@ -2,6 +2,8 @@
class CustomersController extends AppController {
+ var $components = array('RequestHandler');
+
// DEBUG FUNCTION ONLY!
// Call without id to update ALL customers
function force_update($id = null) {
@@ -311,6 +313,11 @@ class CustomersController extends AppController {
array('action' => 'edit', $id), null,
'ACTION');
+ if ($this->admin())
+ $this->addSideMenuLink('Merge',
+ array('action' => 'merge', $id), null,
+ 'ACTION');
+
// Prepare to render.
$title = 'Customer: ' . $customer['Customer']['name'];
$this->set(compact('customer', 'title',
@@ -445,6 +452,42 @@ class CustomersController extends AppController {
$this->edit();
}
+ /**************************************************************************
+ **************************************************************************
+ **************************************************************************
+ * action: merge
+ * - Merges two customers
+ */
+
+ function merge($id = null) {
+ if ($id) {
+ $this->Customer->recursive = -1;
+ $customer = $this->Customer->read(null, $id);
+ $customer = $customer['Customer'];
+ if (empty($customer))
+ $this->INTERNAL_ERROR("Customer $id does not exist");
+ $this->set('src_customer', $customer);
+ $this->set('src_name', $customer['name']);
+ $this->set('src_id', $id);
+ }
+ else {
+ $this->INTERNAL_ERROR("Merge called with invalid customer");
+ }
+ }
+
+ function mergeFinal() {
+ if (!$this->RequestHandler->isPost()) {
+ echo('
+
+
+
+
+create(null, array('id' => 'customer-merge-form',
+ 'onsubmit' => 'return verifyRequest();',
+ 'url' => array('controller' => 'customers',
+ 'action' => 'mergeFinal')))."\n";
+
+
+echo '
'."\n";
+echo '
'."\n";
+
+echo $this->element('customers', array
+ ('config' => array
+ ('grid_div_id' => 'customers-list',
+ 'grid_div_class' => 'text-below',
+ 'caption' => ('
Select Customer '),
+ //'grid_setup' => array('hiddengrid' => isset($customer['id'])),
+ 'grid_events' => array('onSelectRow' =>
+ array('ids' =>
+ 'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'),
+ 'onHeaderClick' =>
+ array('gridstate' =>
+ 'onGridState("#"+$(this).attr("id"), gridstate)'),
+ ),
+ //'action' => 'current',
+ //'nolinks' => true,
+ 'limit' => 10,
+ )));
+
+echo ('
' .
+
+ '
' .
+ 'Destination Customer: ' .
+ '
' .
+
+ '
' .
+ 'Please select customer to merge into' .
+ '
' .
+
+ '
' . "\n");
+
+echo $this->element('contacts', array
+ (// Grid configuration
+ 'config' => array
+ (
+ 'grid_div_id' => 'primary-contacts',
+ /* 'grid_events' => array('onSelectRow' => */
+ /* array('ids' => */
+ /* 'if (ids != null){$("#primary-contacts-list .HeaderButton").click();}')), */
+ 'grid_setup' => array('select' => true),
+ 'caption' => 'Primary Contact',
+ 'filter' => array('ContactsCustomer.customer_id' => $src_id),
+ //'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
+ //'include' => array('Applied', 'Balance'),
+ //'remap' => array('Received' => 'Paid'),
+ //'limit' => 20,
+ ),
+ ));
+
+// Add a hidden item to hold the jqGrid selection,
+// which we'll populate prior to form submission.
+echo "\n";
+echo '
'."\n";
+
+echo $this->element('contacts', array
+ (// Grid configuration
+ 'config' => array
+ (
+ 'grid_div_id' => 'contacts',
+ //'grid_events' => array('loadComplete' => 'onContactsGridLoadComplete()'),
+ 'grid_setup' => array('multiselect' => true),
+ 'caption' => 'Combined Contacts',
+ 'filter' => array('ContactsCustomer.customer_id' => $src_id),
+ //'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
+ //'include' => array('Applied', 'Balance'),
+ //'remap' => array('Received' => 'Paid'),
+ //'limit' => 20,
+ ),
+ ));
+
+// Add a hidden item to hold the jqGrid selection,
+// which we'll populate prior to form submission.
+echo "\n";
+echo '
'."\n";
+
+?>
+
+
WARNING!
+ is about to be deleted, and all data (leases, transactions, etc) from that customer will be merged into the destination customer selected above. This process is NOT reversible, so please ensure the selections are correct before proceeding.
+
+end('Merge Customers') . "\n";
+?>
+
+
+
+
+
+
+
+