Subversion Repositories SmartDukaan

Rev

Rev 36761 | Rev 36789 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36761 Rev 36787
Line 1046... Line 1046...
1046
                        '</span>');
1046
                        '</span>');
1047
                    badge.data('value', beat.planDate + '|' + beat.beatName + '|' + beat.planGroupId);
1047
                    badge.data('value', beat.planDate + '|' + beat.beatName + '|' + beat.planGroupId);
1048
                    badgesDiv.append(badge);
1048
                    badgesDiv.append(badge);
1049
                }
1049
                }
1050
            } else {
1050
            } else {
-
 
1051
                // No beat-days available for this assignee. Surface a CTA so the
-
 
1052
                // user can fire a visit request to the assignee's hierarchy instead
-
 
1053
                // of being stuck. The pre-existing 'beats > 0' branch above is
-
 
1054
                // untouched — this only fires for the empty-beats case.
-
 
1055
                var nearestId = (stores.length > 0 && stores[0].storeId) ? stores[0].storeId : '';
-
 
1056
                badgesDiv.append(
-
 
1057
                    '<div style="background:#fff8e1; border:1px solid #f0e0a0; border-radius:6px; padding:8px 10px; margin-top:4px;">'
-
 
1058
                    + '<div style="font-size:12px; color:#7c5a00; margin-bottom:6px;">'
-
 
1059
                    + 'No upcoming beat is available for this assignee.'
-
 
1060
                    + '</div>'
-
 
1061
                    + '<div style="display:flex; gap:8px; align-items:center;">'
1051
                badgesDiv.append('<span style="color:#999; font-size:12px;">No upcoming beats available for this person</span>');
1062
                    + '<label style="font-size:11px; color:#666; margin:0;">Preferred date (optional):</label>'
-
 
1063
                    + '<input type="date" id="vrPreferredDate" class="input-sm" style="font-size:12px; padding:3px 6px;">'
-
 
1064
                    + '<button type="button" id="vrSendBtn" class="btn btn-warning btn-sm" '
-
 
1065
                    + 'data-nearest="' + nearestId + '" style="font-size:12px;">Send Visit Request</button>'
-
 
1066
                    + '</div>'
-
 
1067
                    + '<div style="font-size:11px; color:#888; margin-top:6px;">'
-
 
1068
                    + 'The request goes to the assignee\'s reporting head (and up). Once they approve and pick a beat-day, the lead lands on that beat.'
-
 
1069
                    + '</div>'
-
 
1070
                    + '</div>');
1052
            }
1071
            }
1053
        },
1072
        },
1054
        error: function () {
1073
        error: function () {
1055
            badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
1074
            badgesDiv.html('<span style="color:#d9534f; font-size:12px;">Error loading beats</span>');
1056
        }
1075
        }
1057
    });
1076
    });
1058
}
1077
}
1059
 
1078
 
-
 
1079
// Send Visit Request when no beats are available for the chosen assignee.
-
 
1080
// Posts to /visitRequest/create. Existing beat-pick + Submit flow is unchanged.
-
 
1081
$(document).on('click', '#vrSendBtn', function () {
-
 
1082
    var $btn = $(this);
-
 
1083
    var assigneeAuthId = parseInt($('#assignTo').val());
-
 
1084
    var commType = $('#communicationType').val() || null;
-
 
1085
    var nearestStoreId = parseInt($btn.data('nearest'));
-
 
1086
    var preferred = $('#vrPreferredDate').val() || null;
-
 
1087
    if (!leadId || !assigneeAuthId) {
-
 
1088
        alert('Pick an assignee first.');
-
 
1089
        return;
-
 
1090
    }
-
 
1091
    $btn.prop('disabled', true).text('Sending...');
-
 
1092
    var payload = {
-
 
1093
        leadId: leadId,
-
 
1094
        assigneeAuthId: assigneeAuthId,
-
 
1095
        communicationType: commType,
-
 
1096
        reason: 'No upcoming beats for assignee'
-
 
1097
    };
-
 
1098
    if (!isNaN(nearestStoreId) && nearestStoreId > 0) payload.nearestStoreId = nearestStoreId;
-
 
1099
    if (preferred) payload.requestedDate = preferred;
-
 
1100
 
-
 
1101
    doPostAjaxRequestWithJsonHandler(context + '/visitRequest/create', JSON.stringify(payload),
-
 
1102
        function (response) {
-
 
1103
            $btn.prop('disabled', false).text('Send Visit Request');
-
 
1104
            var data = (response && response.response) || response || {};
-
 
1105
            if (data && data.id) {
-
 
1106
                alert('Visit request sent. The assignee\'s manager has been notified.');
-
 
1107
                $('#editLeadData').modal('hide');
-
 
1108
                $('.modal-backdrop').remove();
-
 
1109
            } else {
-
 
1110
                var msg = (data && data.message) || (data && data.error) || 'Could not send request.';
-
 
1111
                alert(msg);
-
 
1112
            }
-
 
1113
        });
-
 
1114
});
-
 
1115
 
1060
// Click on beat badge to select it. A picked beat becomes the schedule
1116
// Click on beat badge to select it. A picked beat becomes the schedule
1061
// source — the manual date input is hidden (not needed when scheduling by beat).
1117
// source — the manual date input is hidden (not needed when scheduling by beat).
1062
$(document).on('click', '.beat-badge', function () {
1118
$(document).on('click', '.beat-badge', function () {
1063
    $('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
1119
    $('.beat-badge').css({'background': '#337ab7', 'border-color': '#337ab7'});
1064
    $(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});
1120
    $(this).css({'background': '#1a5276', 'border-color': '#f39c12', 'border-width': '2px'});