Modified customer merge functionality to leave everything from the destination customer in-tact, and simply add on contacts from the source customer, if requested. This simplifies things significantly, and also the paradigm shift of starting the operation from the destination customer allows us to merge multiple customers into one with ease (no need to dig around for each source customer before clicking merge)

git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@995 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2010-07-02 20:52:00 +00:00
parent 34844760e8
commit 11aacd5803
4 changed files with 72 additions and 177 deletions

View File

@@ -20,40 +20,12 @@ Configure::write('debug', '0');
// pre-submit callback
function verifyRequest() {
var pid;
var rows;
if (!$("#dst-customer-id").val()) {
alert("Must select destination customer");
return false;
}
pid = $('#<?php echo "primary-contacts-jqGrid"; ?>').getGridParam('selrow');
if (!pid) {
alert("Must select a primary contact");
if (!$("#src-customer-id").val()) {
alert("Must select source customer");
return false;
}
rows = $('#<?php echo "contacts-jqGrid"; ?>').getGridParam('selarrrow');
if (!rows.length) {
alert("Must select at least one contact");
return false;
}
var found = false;
for (var i=0; i < rows.length; ++i) {
if (pid == rows[i]) {
found = true;
break;
}
}
if (!found) {
alert("Primary contact is not a member of the selected contacts");
return false;
}
$('#<?php echo "primary-contact-id"; ?>').val(pid);
$('#<?php echo "contact-ids"; ?>').val(serialize(rows));
// return false to prevent the form from being submitted;
@@ -61,21 +33,11 @@ function verifyRequest() {
return true;
}
// Reset the form
function resetForm() {
$('#payment-entry-id').val(1);
$('#payments').html('');
//updateContacts();
}
function updateContacts() {
$('#contacts-jqGrid').clearGridData();
var filter = new Array();
//filter['ContactsCustomer.customer_id'] = <?php echo $src_id ?>;
//filter['ContactsCustomer.customer_id'] = $("#dst-customer-id").val();
filter['ContactsCustomer.customer_id'] = new Array(<?php echo $src_id ?>, $("#dst-customer-id").val());
filter['ContactsCustomer.customer_id'] = $("#src-customer-id").val();
var dynamic_post = new Array();
dynamic_post['filter'] = filter;
@@ -84,26 +46,16 @@ function updateContacts() {
$('#contacts-jqGrid')
.setGridParam({ page: 1 })
.trigger("reloadGrid");
$('#primary-contacts-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
$('#primary-contacts-jqGrid')
.setGridParam({ page: 1 })
.trigger("reloadGrid");
/* var gridstate = $('#contacts-jqGrid').getGridParam('gridstate'); */
/* var gridstate = $('#primary-contacts-jqGrid').getGridParam('gridstate'); */
/* if (gridstate == 'hidden') */
/* $('#contacts .HeaderButton').click(); */
}
function onRowSelect(grid_id, customer_id) {
//$('#output-debug').append("select: "+grid_id+"; "+customer_id+"<BR>\n");
// Set the item id that will be returned with the form
$("#dst-customer-id").val(customer_id);
$("#src-customer-id").val(customer_id);
// Get the item name from the grid
$("#dst-customer-name").html($(grid_id).getCell(customer_id, "Customer-name"));
$("#src-customer-name").html($(grid_id).getCell(customer_id, "Customer-name"));
updateContacts();
@@ -118,7 +70,7 @@ function onGridState(grid_id, state) {
$(".customer-selection-valid").hide();
}
else {
if ($("#dst-customer-id").val() > 0) {
if ($("#src-customer-id").val() > 0) {
$(".customer-selection-invalid").hide();
$(".customer-selection-valid").show();
} else {
@@ -128,10 +80,6 @@ function onGridState(grid_id, state) {
}
}
/* function onContactsGridLoadComplete() { */
/* var userdata = $('#contacts-jqGrid').getGridParam('userData'); */
/* } */
--></script>
<?php
@@ -145,8 +93,8 @@ echo $form->create(null, array('id' => 'customer-merge-form',
'action' => 'mergeFinal')))."\n";
echo '<input type="hidden" id="src-customer-id" name="src-id" value="'.$src_id.'" />'."\n";
echo '<input type="hidden" id="dst-customer-id" name="dst-id" value="0" />'."\n";
echo '<input type="hidden" id="src-customer-id" name="src-id" value="0" />'."\n";
echo '<input type="hidden" id="dst-customer-id" name="dst-id" value="'.$dst_id.'" />'."\n";
echo $this->element('customers', array
('config' => array
@@ -154,7 +102,6 @@ echo $this->element('customers', array
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
' return false;">Select Customer</A>'),
//'grid_setup' => array('hiddengrid' => isset($customer['id'])),
'grid_events' => array('onSelectRow' =>
array('ids' =>
'if (ids != null){onRowSelect("#"+$(this).attr("id"), ids);}'),
@@ -162,7 +109,7 @@ echo $this->element('customers', array
array('gridstate' =>
'onGridState("#"+$(this).attr("id"), gridstate)'),
),
//'action' => 'current',
'filter' => array('Customer.id !=' => $dst_id),
//'nolinks' => true,
'limit' => 10,
)));
@@ -170,7 +117,7 @@ echo $this->element('customers', array
echo ('<DIV CLASS="customer-merge grid-selection-text">' .
'<DIV CLASS="customer-selection-valid" style="display:none">' .
'Destination Customer: <SPAN id="dst-customer-name"></SPAN>' .
'Destination Customer: <SPAN id="src-customer-name"></SPAN>' .
'</DIV>' .
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
@@ -179,42 +126,15 @@ echo ('<DIV CLASS="customer-merge grid-selection-text">' .
'</DIV>' . "\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 '<input type="hidden" id="primary-contact-id" name="primary-contact-id" value="0" />'."\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,
'caption' => 'Source contacts to keep',
'filter' => array('ContactsCustomer.customer_id' => 0),
'include' => array('Relationship', 'License', 'Comment'),
),
));
@@ -226,7 +146,7 @@ echo '<input type="hidden" id="contact-ids" name="contact-ids" value="" />'."\n"
?>
<H3>WARNING!</H3>
<?php echo $src_name ?> 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.<BR>
The above selected customer is about to be deleted, and all related data (leases, transactions, etc) will be merged into customer #<?php echo $dst_id ?>: <?php echo $dst_name ?>. This process is NOT reversible, so please ensure the selections are correct before proceeding.<BR>
<?php
echo $form->end('Merge Customers') . "\n";
@@ -242,12 +162,10 @@ Configure::write('debug', '0');
<script type="text/javascript"><!--
$(document).ready(function(){
$("#dst-customer-id").val(0);
$("#dst-customer-name").html("INTERNAL ERROR");
$("#src-customer-id").val(0);
$("#src-customer-name").html("INTERNAL ERROR");
//onGridState(null, 'visible');
resetForm();
<?php if ($this->params['dev']): ?>
$('#output-debug').show();
<?php endif; ?>

View File

@@ -6,6 +6,7 @@ $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter'
$cols['Name'] = array('index' => 'Contact.display_name', 'formatter' => 'longname');
$cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'name');
$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'name');
$cols['License'] = array('index' => 'Contact.id_local', 'formatter' => 'name');
$cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname');
$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment');
@@ -16,4 +17,4 @@ $grid
->defaultFields(array('Last Name', 'First Name'))
->searchFields(array('Last Name', 'First Name', 'Company'))
->render($this, isset($config) ? $config : null,
array_diff(array_keys($cols), array('Relationship', 'Comment')));
array_diff(array_keys($cols), array('Relationship', 'License', 'Comment')));