| Line 539... |
Line 539... |
| 539 |
leadActivityData['id'] = leadId;
|
539 |
leadActivityData['id'] = leadId;
|
| 540 |
leadActivityData['remark'] = remark;
|
540 |
leadActivityData['remark'] = remark;
|
| 541 |
leadActivityData['assignTo'] = assignTo
|
541 |
leadActivityData['assignTo'] = assignTo
|
| 542 |
leadActivityData['status'] = editStatus
|
542 |
leadActivityData['status'] = editStatus
|
| 543 |
leadActivityData['reason'] = reason
|
543 |
leadActivityData['reason'] = reason
|
| 544 |
leadActivityData['colorCheck'] = conversionprobability
|
544 |
leadActivityData['colorCheck'] = (conversionprobability === "true" || conversionprobability === true)
|
| 545 |
if (city && city.trim() !== "") {
|
545 |
if (city && city.trim() !== "") {
|
| 546 |
leadActivityData.city = city;
|
546 |
leadActivityData.city = city;
|
| 547 |
}
|
547 |
}
|
| 548 |
|
548 |
|
| 549 |
if (state && state.trim() !== "") {
|
549 |
if (state && state.trim() !== "") {
|
| Line 555... |
Line 555... |
| 555 |
}
|
555 |
}
|
| 556 |
|
556 |
|
| 557 |
|
557 |
|
| 558 |
if (editStatus == "followUp") {
|
558 |
if (editStatus == "followUp") {
|
| 559 |
leadActivityData['communicationType'] = communicationType
|
559 |
leadActivityData['communicationType'] = communicationType
|
| - |
|
560 |
var beatVal = $('#beatDate').val();
|
| - |
|
561 |
if (beatVal) {
|
| 560 |
leadActivityData['scheldule'] = getDatesFromPicker('input[name="editScheduleTime"]').startDate
|
562 |
// Scheduling by beat — derive schedule from the beat's planDate
|
| 561 |
|
- |
|
| 562 |
if (communicationType == 'VISIT') {
|
563 |
// (default to noon) and forward the selection for both VISIT
|
| - |
|
564 |
// and TELEPHONIC so the lead lands on that beat's route.
|
| 563 |
var beatVal = $('#beatDate').val();
|
565 |
var beatDate = beatVal.split('|')[0];
|
| 564 |
if (beatVal) {
|
566 |
leadActivityData['scheldule'] = beatDate + 'T12:00:00';
|
| 565 |
leadActivityData['beatSelection'] = beatVal;
|
567 |
leadActivityData['beatSelection'] = beatVal;
|
| 566 |
}
|
568 |
} else {
|
| - |
|
569 |
leadActivityData['scheldule'] = getDatesFromPicker('input[name="editScheduleTime"]').startDate
|
| 567 |
}
|
570 |
}
|
| 568 |
}
|
571 |
}
|
| 569 |
|
572 |
|
| 570 |
console.log(leadActivityData);
|
573 |
console.log(leadActivityData);
|
| 571 |
if (confirm("Are you sure you want to add lead!") == true) {
|
574 |
if (confirm("Are you sure you want to add lead!") == true) {
|
| Line 847... |
Line 850... |
| 847 |
$('#assignTo option').show();
|
850 |
$('#assignTo option').show();
|
| 848 |
}
|
851 |
}
|
| 849 |
|
852 |
|
| 850 |
}
|
853 |
}
|
| 851 |
|
854 |
|
| - |
|
855 |
// Clicking or changing status with a pre-existing Assign To selection clears it,
|
| - |
|
856 |
// so the user must reconfirm the assignee for the new status (avoids stale assignment).
|
| - |
|
857 |
$(document).on('mousedown change', '#editStatus', function () {
|
| - |
|
858 |
if ($('#assignTo').val()) {
|
| - |
|
859 |
$('#assignTo').val('');
|
| - |
|
860 |
$('#assignTo option').show();
|
| - |
|
861 |
$('#beatDate').val('');
|
| - |
|
862 |
$('#beatBadges').empty();
|
| - |
|
863 |
$("#beatDateSelection").hide();
|
| - |
|
864 |
$("#editScheduleTime").show();
|
| - |
|
865 |
}
|
| - |
|
866 |
});
|
| - |
|
867 |
|
| 852 |
function loadLeadSearchInfo(search_text) {
|
868 |
function loadLeadSearchInfo(search_text) {
|
| 853 |
loadSearchLead("main-content", search_text);
|
869 |
loadSearchLead("main-content", search_text);
|
| 854 |
}
|
870 |
}
|
| 855 |
|
871 |
|
| 856 |
function loadTeamCommitment(domId) {
|
872 |
function loadTeamCommitment(domId) {
|
| Line 930... |
Line 946... |
| 930 |
// Communication type change: filter assignTo based on type
|
946 |
// Communication type change: filter assignTo based on type
|
| 931 |
$(document).on('change', '#communicationType', function () {
|
947 |
$(document).on('change', '#communicationType', function () {
|
| 932 |
var val = $(this).val();
|
948 |
var val = $(this).val();
|
| 933 |
var assignDropdown = $('#assignTo');
|
949 |
var assignDropdown = $('#assignTo');
|
| 934 |
|
950 |
|
| 935 |
// Reset beat
|
951 |
// Reset beat + restore manual date input
|
| 936 |
$('#beatDate').val('');
|
952 |
$('#beatDate').val('');
|
| 937 |
$('#beatBadges').empty();
|
953 |
$('#beatBadges').empty();
|
| 938 |
$("#beatDateSelection").hide();
|
954 |
$("#beatDateSelection").hide();
|
| - |
|
955 |
$("#editScheduleTime").show();
|
| 939 |
|
956 |
|
| 940 |
if (val == 'VISIT') {
|
957 |
if (val == 'VISIT') {
|
| 941 |
// Filter assignTo to sales users only (no BGC)
|
958 |
// Filter assignTo to sales users only (no BGC)
|
| 942 |
if (typeof salesUserIds !== 'undefined') {
|
959 |
if (typeof salesUserIds !== 'undefined') {
|
| 943 |
assignDropdown.find('option').each(function () {
|
960 |
assignDropdown.find('option').each(function () {
|
| Line 947... |
Line 964... |
| 947 |
} else {
|
964 |
} else {
|
| 948 |
$(this).show();
|
965 |
$(this).show();
|
| 949 |
}
|
966 |
}
|
| 950 |
});
|
967 |
});
|
| 951 |
}
|
968 |
}
|
| 952 |
// If assignTo already selected, fetch beats immediately
|
- |
|
| 953 |
if (assignDropdown.val()) {
|
- |
|
| 954 |
fetchBeatDates();
|
- |
|
| 955 |
}
|
- |
|
| 956 |
} else {
|
969 |
} else {
|
| 957 |
// TELEPHONIC — show all users
|
970 |
// TELEPHONIC — show all users
|
| 958 |
assignDropdown.find('option').show();
|
971 |
assignDropdown.find('option').show();
|
| 959 |
}
|
972 |
}
|
| - |
|
973 |
// Both VISIT and TELEPHONIC offer beat-day slots when an assignee is set
|
| - |
|
974 |
// (TELEPHONIC just uses the beat date as the call slot; backend won't
|
| - |
|
975 |
// attach a LeadRoute for it). Non-sales assignees simply get an empty list.
|
| - |
|
976 |
if (val && assignDropdown.val()) {
|
| - |
|
977 |
fetchBeatDates();
|
| - |
|
978 |
}
|
| 960 |
});
|
979 |
});
|
| 961 |
|
980 |
|
| 962 |
// Fetch beats when communicationType or assignTo changes
|
981 |
// Fetch beats when assignTo changes (works for both VISIT and TELEPHONIC)
|
| 963 |
$(document).on('change', '#communicationType, #assignTo', function () {
|
982 |
$(document).on('change', '#assignTo', function () {
|
| 964 |
var commType = $('#communicationType').val();
|
983 |
var commType = $('#communicationType').val();
|
| 965 |
var salesAuthId = $('#assignTo').val();
|
984 |
var salesAuthId = $('#assignTo').val();
|
| 966 |
if (commType === 'VISIT' && salesAuthId && leadId) {
|
985 |
if (commType && salesAuthId && leadId) {
|
| 967 |
fetchBeatDates();
|
986 |
fetchBeatDates();
|
| 968 |
} else if (commType !== 'VISIT') {
|
987 |
} else if (!commType) {
|
| 969 |
$("#beatDateSelection").hide();
|
988 |
$("#beatDateSelection").hide();
|
| 970 |
}
|
989 |
}
|
| 971 |
});
|
990 |
});
|
| 972 |
|
991 |
|
| 973 |
function fetchBeatDates() {
|
992 |
function fetchBeatDates() {
|
| 974 |
var salesAuthId = $('#assignTo').val();
|
993 |
var salesAuthId = $('#assignTo').val();
|
| 975 |
var scheduleDate = $('input[name="editScheduleTime"]').val();
|
- |
|
| 976 |
if (!salesAuthId || !leadId) return;
|
994 |
if (!salesAuthId || !leadId) return;
|
| 977 |
|
995 |
|
| 978 |
var badgesDiv = $('#beatBadges');
|
996 |
var badgesDiv = $('#beatBadges');
|
| 979 |
badgesDiv.html('<span style="color:#999; font-size:12px;">Loading beats...</span>');
|
997 |
badgesDiv.html('<span style="color:#999; font-size:12px;">Loading beats...</span>');
|
| 980 |
$("#beatDateSelection").show();
|
998 |
$("#beatDateSelection").show();
|
| 981 |
$('#beatDate').val('');
|
999 |
$('#beatDate').val('');
|
| 982 |
|
1000 |
|
| 983 |
var url = context + "/lead-geo/beat-dates?leadId=" + leadId + "&salesAuthId=" + salesAuthId;
|
1001 |
var url = context + "/lead-geo/beat-dates?leadId=" + leadId + "&salesAuthId=" + salesAuthId;
|
| 984 |
if (scheduleDate) {
|
- |
|
| 985 |
url += "&scheduleDate=" + encodeURIComponent(scheduleDate);
|
- |
|
| 986 |
}
|
- |
|
| 987 |
|
1002 |
|
| 988 |
$.ajax({
|
1003 |
$.ajax({
|
| 989 |
url: url,
|
1004 |
url: url,
|
| 990 |
method: 'GET',
|
1005 |
method: 'GET',
|
| 991 |
success: function (response) {
|
1006 |
success: function (response) {
|
| 992 |
var data = response.response || response;
|
1007 |
var data = response.response || response;
|
| 993 |
badgesDiv.empty();
|
1008 |
badgesDiv.empty();
|
| 994 |
|
1009 |
|
| 995 |
// Show the nearest store to the lead's geo location
|
1010 |
// Stores within radius of the lead — show count + top 3 inline.
|
| - |
|
1011 |
var radius = (data && data.radiusKm) ? data.radiusKm : 30;
|
| 996 |
if (data && data.nearestStore) {
|
1012 |
var stores = (data && data.nearestStores) || [];
|
| - |
|
1013 |
if (stores.length > 0) {
|
| - |
|
1014 |
var preview = stores.slice(0, 3).map(function (s) {
|
| - |
|
1015 |
return '<strong>' + s.code + ' - ' + s.name + '</strong> (' + s.distanceKm + ' km)';
|
| 997 |
var ns = data.nearestStore;
|
1016 |
}).join(', ');
|
| - |
|
1017 |
var more = stores.length > 3 ? ' +' + (stores.length - 3) + ' more' : '';
|
| 998 |
badgesDiv.append('<div style="font-size:12px; color:#333; margin-bottom:6px;">' +
|
1018 |
badgesDiv.append('<div style="font-size:12px; color:#333; margin-bottom:6px;">' +
|
| 999 |
'Lead is nearest to: <strong>' + ns.code + ' - ' + ns.name + '</strong> ' +
|
1019 |
stores.length + ' partner store(s) within ' + radius + ' km of this lead: ' +
|
| 1000 |
'<span style="color:#e67e22;">(' + ns.distanceKm + ' km)</span></div>');
|
1020 |
preview + more + '</div>');
|
| 1001 |
}
|
1021 |
}
|
| 1002 |
|
1022 |
|
| 1003 |
// Show beat slots — these are dates the sales person visits the nearest store
|
1023 |
// All upcoming beat-dates for the assignee that touch any nearby store.
|
| 1004 |
if (data && data.beats && data.beats.length > 0) {
|
1024 |
if (data && data.beats && data.beats.length > 0) {
|
| 1005 |
badgesDiv.append('<div style="font-weight:bold; font-size:11px; color:#666; margin-bottom:4px;">Available Slots (near this lead):</div>');
|
1025 |
badgesDiv.append('<div style="font-weight:bold; font-size:11px; color:#666; margin-bottom:4px;">Available Slots (near this lead):</div>');
|
| 1006 |
var beats = data.beats.slice(0, 5);
|
1026 |
var beats = data.beats;
|
| 1007 |
for (var i = 0; i < beats.length; i++) {
|
1027 |
for (var i = 0; i < beats.length; i++) {
|
| 1008 |
var beat = beats[i];
|
1028 |
var beat = beats[i];
|
| 1009 |
var nearTxt = beat.nearStore ? ' · near ' + beat.nearStore : '';
|
1029 |
var nearTxt = beat.nearStore ? ' · near ' + beat.nearStore : '';
|
| 1010 |
var badge = $('<span class="beat-badge" style="' +
|
1030 |
var badge = $('<span class="beat-badge" style="' +
|
| 1011 |
'display:inline-block; background:#337ab7; color:#fff; padding:6px 12px; ' +
|
1031 |
'display:inline-block; background:#337ab7; color:#fff; padding:6px 12px; ' +
|
| Line 1024... |
Line 1044... |
| 1024 |
badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
|
1044 |
badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
|
| 1025 |
}
|
1045 |
}
|
| 1026 |
});
|
1046 |
});
|
| 1027 |
}
|
1047 |
}
|
| 1028 |
|
1048 |
|
| 1029 |
// Click on beat badge to select it
|
1049 |
// Click on beat badge to select it. A picked beat becomes the schedule
|
| - |
|
1050 |
// source — the manual date input is hidden (not needed when scheduling by beat).
|
| 1030 |
$(document).on('click', '.beat-badge', function () {
|
1051 |
$(document).on('click', '.beat-badge', function () {
|
| 1031 |
// Deselect others
|
- |
|
| 1032 |
$('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
|
1052 |
$('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
|
| 1033 |
// Select this one
|
- |
|
| 1034 |
$(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});
|
1053 |
$(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});
|
| 1035 |
$('#beatDate').val($(this).data('value'));
|
1054 |
$('#beatDate').val($(this).data('value'));
|
| - |
|
1055 |
$("#editScheduleTime").hide();
|
| 1036 |
});
|
1056 |
});
|
| 1037 |
|
1057 |
|
| 1038 |
// Generate Geo Link for lead
|
1058 |
// Generate Geo Link for lead
|
| 1039 |
$(document).on('click', '.generateGeoLink', function (e) {
|
1059 |
$(document).on('click', '.generateGeoLink', function (e) {
|
| 1040 |
e.stopPropagation();
|
1060 |
e.stopPropagation();
|