Subversion Repositories SmartDukaan

Rev

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

Rev 36811 Rev 36847
Line 2776... Line 2776...
2776
            + locLine
2776
            + locLine
2777
			+ nearLine
2777
			+ nearLine
2778
			+ reqMeta
2778
			+ reqMeta
2779
			+ '<div style="margin-top:6px;display:flex;gap:6px;flex-wrap:wrap;">'
2779
			+ '<div style="margin-top:6px;display:flex;gap:6px;flex-wrap:wrap;">'
2780
			+ '<button class="vr-schedule" data-rid="' + r.id + '" data-lead="' + r.leadId + '" data-leadname="' + safeName + '" data-assignee="' + r.assigneeAuthId + '" style="font-size:11px;padding:3px 8px;border:none;border-radius:4px;background:#22c55e;color:#fff;cursor:pointer;">Schedule on a beat</button>'
2780
			+ '<button class="vr-schedule" data-rid="' + r.id + '" data-lead="' + r.leadId + '" data-leadname="' + safeName + '" data-assignee="' + r.assigneeAuthId + '" style="font-size:11px;padding:3px 8px;border:none;border-radius:4px;background:#22c55e;color:#fff;cursor:pointer;">Schedule on a beat</button>'
-
 
2781
			+ '<button class="vr-new-beat" data-rid="' + r.id + '" data-leadname="' + safeName + '" data-preferred="' + (r.requestedDate || '') + '" style="font-size:11px;padding:3px 8px;border:none;border-radius:4px;background:#3b82f6;color:#fff;cursor:pointer;" title="Use this when the assignee has no beats yet">+ New beat</button>'
2781
			+ '<button class="vr-reassign" data-rid="' + r.id + '" style="font-size:11px;padding:3px 8px;border:1px solid #475569;border-radius:4px;background:none;color:#cbd5e1;cursor:pointer;">Reassign</button>'
2782
			+ '<button class="vr-reassign" data-rid="' + r.id + '" style="font-size:11px;padding:3px 8px;border:1px solid #475569;border-radius:4px;background:none;color:#cbd5e1;cursor:pointer;">Reassign</button>'
2782
			+ '<button class="vr-reject" data-rid="' + r.id + '" style="font-size:11px;padding:3px 8px;border:none;border-radius:4px;background:#ef4444;color:#fff;cursor:pointer;">Reject</button>'
2783
			+ '<button class="vr-reject" data-rid="' + r.id + '" style="font-size:11px;padding:3px 8px;border:none;border-radius:4px;background:#ef4444;color:#fff;cursor:pointer;">Reject</button>'
2783
			+ '</div>'
2784
			+ '</div>'
2784
			+ '</div>';
2785
			+ '</div>';
2785
	});
2786
	});
Line 2805... Line 2806...
2805
		+ (state.assignVisitRequest.leadName || ('Lead #' + state.assignVisitRequest.leadId))
2806
		+ (state.assignVisitRequest.leadName || ('Lead #' + state.assignVisitRequest.leadId))
2806
		+ '" onto it.');
2807
		+ '" onto it.');
2807
	$('.panel-tab[data-tab="calendar"]').click();
2808
	$('.panel-tab[data-tab="calendar"]').click();
2808
});
2809
});
2809
 
2810
 
-
 
2811
// "+ New beat" — create a single-day beat with just this lead as the Day-1 stop.
-
 
2812
// For the case the screen card was added to handle: assignee has zero beats,
-
 
2813
// so "Schedule on a beat" has nothing to land on.
-
 
2814
$(document).on('click', '.vr-new-beat', function () {
-
 
2815
	var $b = $(this);
-
 
2816
	var rid = $b.data('rid');
-
 
2817
	var leadName = String($b.data('leadname') || 'this lead');
-
 
2818
	var preferred = String($b.data('preferred') || '');
-
 
2819
	// Prompt for date — preferred wins as default, otherwise tomorrow.
-
 
2820
	var tmrw = new Date();
-
 
2821
	tmrw.setDate(tmrw.getDate() + 1);
-
 
2822
	var def = preferred || tmrw.toISOString().slice(0, 10);
-
 
2823
	var date = prompt('Create a new 1-day beat for "' + leadName + '". Date (YYYY-MM-DD):', def);
-
 
2824
	if (!date) return;
-
 
2825
	date = date.trim();
-
 
2826
	if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
-
 
2827
		alert('Date must be YYYY-MM-DD');
-
 
2828
		return;
-
 
2829
	}
-
 
2830
	if (!confirm('Create new beat for "' + leadName + '" on ' + date + '?')) return;
-
 
2831
	$.ajax({
-
 
2832
		url: context + '/visitRequest/' + rid + '/create-beat-and-schedule',
-
 
2833
		type: 'POST', contentType: 'application/json',
-
 
2834
		data: JSON.stringify({scheduleDate: date}),
-
 
2835
		success: function (resp) {
-
 
2836
			var r = resp && resp.response ? resp.response : resp;
-
 
2837
			alert('Beat "' + (r.beatName || 'New beat') + '" created on ' + (r.scheduleDate || date) + '.');
-
 
2838
			loadVisitRequests();
-
 
2839
			// Refresh the beat list so the new beat shows up in the left rail.
-
 
2840
			$('#bp-load').click();
-
 
2841
		},
-
 
2842
		error: function (xhr) {
-
 
2843
			var msg = 'Could not create the beat';
-
 
2844
			try {
-
 
2845
				var e = JSON.parse(xhr.responseText);
-
 
2846
				if (e && e.response) msg = (typeof e.response === 'string') ? e.response : (e.response.message || msg);
-
 
2847
			} catch (_) {
-
 
2848
			}
-
 
2849
			alert(msg);
-
 
2850
		}
-
 
2851
	});
-
 
2852
});
-
 
2853
 
2810
$(document).on('click', '.vr-reassign', function () {
2854
$(document).on('click', '.vr-reassign', function () {
2811
	var rid = $(this).data('rid');
2855
	var rid = $(this).data('rid');
2812
	var newId = prompt('New assignee auth user id (must be in your downline):');
2856
	var newId = prompt('New assignee auth user id (must be in your downline):');
2813
	if (!newId) return;
2857
	if (!newId) return;
2814
	var newIdInt = parseInt(newId);
2858
	var newIdInt = parseInt(newId);