git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@994 97e9348a-65ac-dc4b-aefc-98561f571b83
259 lines
8.0 KiB
PHP
259 lines
8.0 KiB
PHP
<?php /* -*- mode:PHP -*- */ ?>
|
|
|
|
<div class="customer merge">
|
|
<?php
|
|
; // Editor alignment
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Javascript
|
|
*/
|
|
|
|
// Warnings _really_ screw up javascript
|
|
$saved_debug_state = Configure::read('debug');
|
|
Configure::write('debug', '0');
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
|
|
// 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");
|
|
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;
|
|
// anything other than false will allow submission.
|
|
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());
|
|
|
|
var dynamic_post = new Array();
|
|
dynamic_post['filter'] = filter;
|
|
|
|
$('#contacts-jqGrid').setPostDataItem('dynamic_post_replace', serialize(dynamic_post));
|
|
$('#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);
|
|
|
|
// Get the item name from the grid
|
|
$("#dst-customer-name").html($(grid_id).getCell(customer_id, "Customer-name"));
|
|
|
|
updateContacts();
|
|
|
|
$("#customers-list .HeaderButton").click();
|
|
}
|
|
|
|
function onGridState(grid_id, state) {
|
|
//$('#output-debug').append("state: "+grid_id+"; "+state+"<BR>\n");
|
|
|
|
if (state == 'visible') {
|
|
$(".customer-selection-invalid").hide();
|
|
$(".customer-selection-valid").hide();
|
|
}
|
|
else {
|
|
if ($("#dst-customer-id").val() > 0) {
|
|
$(".customer-selection-invalid").hide();
|
|
$(".customer-selection-valid").show();
|
|
} else {
|
|
$(".customer-selection-invalid").show();
|
|
$(".customer-selection-valid").hide();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* function onContactsGridLoadComplete() { */
|
|
/* var userdata = $('#contacts-jqGrid').getGridParam('userData'); */
|
|
/* } */
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // align
|
|
// Re-Enable warnings
|
|
Configure::write('debug', $saved_debug_state);
|
|
|
|
echo $form->create(null, array('id' => 'customer-merge-form',
|
|
'onsubmit' => 'return verifyRequest();',
|
|
'url' => array('controller' => 'customers',
|
|
'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 $this->element('customers', array
|
|
('config' => array
|
|
('grid_div_id' => 'customers-list',
|
|
'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);}'),
|
|
'onHeaderClick' =>
|
|
array('gridstate' =>
|
|
'onGridState("#"+$(this).attr("id"), gridstate)'),
|
|
),
|
|
//'action' => 'current',
|
|
//'nolinks' => true,
|
|
'limit' => 10,
|
|
)));
|
|
|
|
echo ('<DIV CLASS="customer-merge grid-selection-text">' .
|
|
|
|
'<DIV CLASS="customer-selection-valid" style="display:none">' .
|
|
'Destination Customer: <SPAN id="dst-customer-name"></SPAN>' .
|
|
'</DIV>' .
|
|
|
|
'<DIV CLASS="customer-selection-invalid" style="display:none">' .
|
|
'Please select customer to merge into' .
|
|
'</DIV>' .
|
|
|
|
'</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,
|
|
),
|
|
));
|
|
|
|
// Add a hidden item to hold the jqGrid selection,
|
|
// which we'll populate prior to form submission.
|
|
echo "\n";
|
|
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>
|
|
|
|
<?php
|
|
echo $form->end('Merge Customers') . "\n";
|
|
?>
|
|
|
|
<div id="output-debug" style="display:none"></div>
|
|
|
|
<?php
|
|
// Warnings _really_ screw up javascript
|
|
Configure::write('debug', '0');
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
$(document).ready(function(){
|
|
|
|
$("#dst-customer-id").val(0);
|
|
$("#dst-customer-name").html("INTERNAL ERROR");
|
|
//onGridState(null, 'visible');
|
|
|
|
resetForm();
|
|
|
|
<?php if ($this->params['dev']): ?>
|
|
$('#output-debug').show();
|
|
<?php endif; ?>
|
|
|
|
});
|
|
--></script>
|
|
|
|
</div>
|