Added the front end code to perform a customer merge. Seems to work, although I don't fully trust it yet. Now that implementation is done, I realize I don't care for the interface. Really, the destination customer should keep its primary contact and all other contacts. The user should only be given the choice of adding zero to all contacts from the source customer. A change in primary contact could always be handled after the merge.

git-svn-id: file:///svn-source/pmgr/branches/v0.3_work/site@994 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2010-07-02 19:36:39 +00:00
parent 2e3f168036
commit d83b72b2a3
3 changed files with 304 additions and 1 deletions

View File

@@ -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('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
return;
}
$post = $this->params['form'];
$this->Customer->merge($post['dst-id'], $post['src-id'],
unserialize($post['contact-ids']),
$post['primary-contact-id']);
$this->redirect(array('action'=>'view', $post['dst-id']));
}
/**************************************************************************
**************************************************************************
**************************************************************************