Rev 36740 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<section class="wrapper"><div class="row"><div class="col-lg-12"><h3 class="page-header"><i class="icon_calendar"></i> Deferred Partners</h3><ol class="breadcrumb"><li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li><li><i class="icon_group"></i> Partner Acquisition</li><li><i class="icon_calendar"></i> Deferred Partners</li></ol></div></div><div class="row" style="margin-bottom:10px;"><div class="col-lg-12" style="display:flex; gap:10px; align-items:center; flex-wrap:wrap;"><label style="margin:0;">Date:</label><input type="date" id="defDate" class="form-control input-sm" style="width:160px;"><button class="btn btn-primary btn-sm" id="defLoad">Load</button><span id="defSummary" style="color:#777; font-size:12px; margin-left:10px;"></span></div></div><div class="row"><div class="col-lg-12"><div class="table-responsive"><table class="table table-bordered table-striped table-hover" id="defTable"><thead><tr><th>User</th><th>Date</th><th>Type</th><th>Partner / Agenda</th><th>Reason</th><th>Status</th><th>Next Scheduled</th><th>Action</th></tr></thead><tbody id="defRows"><tr><td colspan="8" style="text-align:center; color:#999;">Pick a date and click Load.</td></tr></tbody></table></div></div></div></section><!-- Reschedule modal --><!-- Reschedule via the beat-plan calendar window (pick an upcoming beat to drop the item into) --><div class="modal fade" id="defCalModal" tabindex="-1"><div class="modal-dialog" style="width:95%; max-width:1300px; margin-top:20px;"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"onclick="$('#defCalFrame').attr('src','');">×</button><h4 class="modal-title" id="defCalTitle">Reschedule into a Beat</h4></div><div class="modal-body" style="padding:0;"><iframe id="defCalFrame" style="width:100%; height:80vh; border:none;"></iframe></div></div></div></div><script>(function () {var d = new Date();function fmt(x) {return x.getFullYear() + '-' + ('0' + (x.getMonth() + 1)).slice(-2) + '-' + ('0' + x.getDate()).slice(-2);}$('#defDate').val(fmt(d));loadDeferred();})();$(document).on('click', '#defLoad', function () {loadDeferred();});function loadDeferred() {var d = $('#defDate').val();if (!d) {alert('Pick a date');return;}$('#defRows').html('<tr><td colspan="8" style="text-align:center;">Loading...</td></tr>');$('#defSummary').text('');$.get(context + '/beatPlan/deferred', {startDate: d, endDate: d}).done(function (r) {var data = r.response || r;renderDeferredRows(data.rows || []);$('#defSummary').text((data.rows || []).length + ' deferred on ' + data.startDate);}).fail(function (xhr) {$('#defRows').html('<tr><td colspan="8" style="color:#d9534f; text-align:center;">Error: ' + (xhr.responseText || xhr.statusText) + '</td></tr>');});}function renderDeferredRows(rows) {if (!rows || rows.length === 0) {$('#defRows').html('<tr><td colspan="8" style="text-align:center; color:#999;">No deferred items on this date.</td></tr>');return;}var html = '';rows.forEach(function (r) {// "Auto-covered" = the same partner is on an upcoming beat run. Just a// hint — the row stays actionable (the next run may be far off, so the// head can still reschedule it sooner). Leads never auto-cover.var autoCovered = !!r.nextScheduledDate;var statusCell = autoCovered? '<span class="label label-success" title="Also scheduled on ' + r.nextScheduledDate + '">Auto-covered</span>': '<span class="label label-warning">Deferred</span>';var typeCell = (r.type === 'Lead')? '<span class="label label-warning">Lead</span>': '<span class="label label-info">Visit</span>';var next = autoCovered? '<span style="color:#2e7d32; font-weight:600;">' + r.nextScheduledDate + '</span>': '<span style="color:#999;">—</span>';var safeName = (r.name || '').replace(/"/g, '"');var action = '<button class="btn btn-xs btn-success def-reschedule"'+ ' data-id="' + r.id + '"'+ ' data-userid="' + r.authUserId + '"'+ ' data-username="' + (r.userName || '').replace(/"/g, '"') + '"'+ ' data-type="' + (r.type === 'Lead' ? 'lead' : 'visit') + '"'+ ' data-deferdate="' + (r.deferredDate || '') + '"'+ ' data-name="' + safeName + '">Reschedule</button> '+ '<button class="btn btn-xs btn-default def-cancel" data-id="' + r.id + '">Cancel</button>';html += '<tr>'+ '<td>' + (r.userName || '') + '</td>'+ '<td><span class="label label-primary">' + (r.deferredDate || '') + '</span></td>'+ '<td>' + typeCell + '</td>'+ '<td>' + (r.name || '') + '</td>'+ '<td>' + (r.reason || '') + '</td>'+ '<td>' + statusCell + '</td>'+ '<td>' + next + '</td>'+ '<td>' + action + '</td>'+ '</tr>';});$('#defRows').html(html);}// Cancel$(document).on('click', '.def-cancel', function () {var id = $(this).data('id');if (!confirm('Cancel this deferred visit? It will be dropped (no re-visit).')) return;$.ajax({url: context + '/beatPlan/deferred/action',type: 'POST', contentType: 'application/json',data: JSON.stringify({deferredId: id, action: 'cancel'}),success: function () {loadDeferred();},error: function (xhr) {alert(serverMsg(xhr, 'Cancel failed'));}});});// Reschedule → open the beat-plan calendar window scoped to that sales person,// in "deferred-assign" mode. The head clicks an upcoming beat there to drop the// deferred lead/partner into it. On close, reload (the assigned item drops off).$(document).on('click', '.def-reschedule', function () {var id = $(this).data('id');var userId = $(this).data('userid');var userName = $(this).data('username') || '';var type = $(this).data('type') || 'visit';var name = $(this).data('name') || '';var deferDate = $(this).data('deferdate') || '';var url = context + '/beatPlanWindow'+ '?autoUserId=' + userId+ '&autoUserName=' + encodeURIComponent(userName)+ '&assignDeferredId=' + id+ '&deferType=' + encodeURIComponent(type)+ '&deferDate=' + encodeURIComponent(deferDate)+ '&deferName=' + encodeURIComponent(name);$('#defCalTitle').text('Reschedule "' + name + '" into a beat — ' + userName);$('#defCalFrame').attr('src', url);$('#defCalModal').modal('show');});// Reload the list when the calendar window closes (item may have been assigned)$('#defCalModal').on('hidden.bs.modal', function () {$('#defCalFrame').attr('src', '');loadDeferred();});function serverMsg(xhr, fallback) {try {var err = JSON.parse(xhr.responseText);if (err && err.response) {if (typeof err.response === 'string') return err.response;if (err.response.message) return err.response.message;}} catch (e) {}return fallback;}</script>