Subversion Repositories SmartDukaan

Rev

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

Rev 36728 Rev 36740
Line 1763... Line 1763...
1763
	if ($(e.target).hasClass('cal-chip-remove')) return; // handled separately
1763
	if ($(e.target).hasClass('cal-chip-remove')) return; // handled separately
1764
	e.stopPropagation();
1764
	e.stopPropagation();
1765
	var pg = $(this).data('plangroup');
1765
	var pg = $(this).data('plangroup');
1766
	var date = $(this).data('date');
1766
	var date = $(this).data('date');
1767
	if (!pg || !date) return;
1767
	if (!pg || !date) return;
-
 
1768
 
-
 
1769
	// Deferred-assign mode: clicking a beat chip drops the deferred item into
-
 
1770
	// that beat on that date (instead of opening the route).
-
 
1771
	if (state.assignDeferred) {
-
 
1772
		assignDeferredToBeat(String(pg), String(date));
-
 
1773
		return;
-
 
1774
	}
-
 
1775
 
1768
	// Switch to Route tab and load that day's run
1776
	// Switch to Route tab and load that day's run
1769
	$('.panel-tab[data-tab="route"]').click();
1777
	$('.panel-tab[data-tab="route"]').click();
1770
	viewBeat(String(pg), String(date));
1778
	viewBeat(String(pg), String(date));
1771
});
1779
});
1772
 
1780
 
-
 
1781
// Drop the deferred item (set on entry via URL params) into the chosen beat+date.
-
 
1782
function assignDeferredToBeat(beatId, date) {
-
 
1783
	var ad = state.assignDeferred;
-
 
1784
	if (!ad) return;
-
 
1785
	// Must be a FUTURE beat — strictly after the deferred day (and not in the past).
-
 
1786
	if (date <= ad.minDate) {
-
 
1787
		alert('Pick a later beat. A deferred ' + (ad.type === 'lead' ? 'lead' : 'partner')
-
 
1788
			+ ' can only move to a date after ' + ad.minDate + ' — not ' + date + '.');
-
 
1789
		return;
-
 
1790
	}
-
 
1791
	if (!confirm('Add deferred ' + (ad.type === 'lead' ? 'lead' : 'partner') + ' "' + ad.name + '" into this beat on ' + date + '?')) return;
-
 
1792
	$.ajax({
-
 
1793
		url: context + '/beatPlan/deferred/assignToBeat',
-
 
1794
		type: 'POST', contentType: 'application/json',
-
 
1795
		data: JSON.stringify({deferredId: ad.id, beatId: parseInt(beatId), date: date}),
-
 
1796
		success: function (r) {
-
 
1797
			var d = r.response || r;
-
 
1798
			$('#deferred-assign-banner').html('<span style="color:#bbf7d0;">' + (d.message || 'Added.') + '</span> You can close this window.');
-
 
1799
			loadCalendarData(); // refresh so the new stop shows on the calendar
-
 
1800
		},
-
 
1801
		error: function (xhr) {
-
 
1802
			var msg = 'Failed';
-
 
1803
			try {
-
 
1804
				var err = JSON.parse(xhr.responseText);
-
 
1805
				if (err && err.response) msg = (typeof err.response === 'string') ? err.response : (err.response.message || msg);
-
 
1806
			} catch (_) {
-
 
1807
			}
-
 
1808
			alert(msg);
-
 
1809
		}
-
 
1810
	});
-
 
1811
}
-
 
1812
 
1773
// ============ CALENDAR ============
1813
// ============ CALENDAR ============
1774
$('#cal-prev').on('click', function () {
1814
$('#cal-prev').on('click', function () {
1775
	navMonth(-1);
1815
	navMonth(-1);
1776
});
1816
});
1777
$('#cal-next').on('click', function () {
1817
$('#cal-next').on('click', function () {
Line 2454... Line 2494...
2454
 
2494
 
2455
	var autoName = getParam('autoUserName');
2495
	var autoName = getParam('autoUserName');
2456
	var editBeatId = getParam('editBeatId');
2496
	var editBeatId = getParam('editBeatId');
2457
	var editDate = getParam('editDate');
2497
	var editDate = getParam('editDate');
2458
 
2498
 
-
 
2499
	// Deferred-assign mode (opened from the Deferred Partners panel): the head
-
 
2500
	// picks an upcoming beat on the calendar to drop this deferred item into.
-
 
2501
	var assignDeferredId = getParam('assignDeferredId');
-
 
2502
	if (assignDeferredId) {
-
 
2503
		var d2 = new Date();
-
 
2504
		var todayStr = d2.getFullYear() + '-' + ('0' + (d2.getMonth() + 1)).slice(-2) + '-' + ('0' + d2.getDate()).slice(-2);
-
 
2505
		var deferDate = getParam('deferDate') || '';
-
 
2506
		// A deferral can only move FORWARD — never to the day it was deferred or
-
 
2507
		// earlier. The floor is the later of (deferred date, today).
-
 
2508
		var floor = (deferDate && deferDate > todayStr) ? deferDate : todayStr;
-
 
2509
		state.assignDeferred = {
-
 
2510
			id: parseInt(assignDeferredId),
-
 
2511
			type: getParam('deferType') || 'visit',
-
 
2512
			name: getParam('deferName') || 'item',
-
 
2513
			deferDate: deferDate,
-
 
2514
			minDate: floor // target date must be strictly AFTER this
-
 
2515
		};
-
 
2516
	}
-
 
2517
 
2459
	state.authUserId = parseInt(autoUid);
2518
	state.authUserId = parseInt(autoUid);
2460
	state.categoryId = parseInt($('#bp-category').val()) || 4;
2519
	state.categoryId = parseInt($('#bp-category').val()) || 4;
2461
	state.mode = 'list';
2520
	state.mode = 'list';
2462
	$('#bp-user-label').text(autoName || ('User #' + autoUid));
2521
	$('#bp-user-label').text(autoName || ('User #' + autoUid));
2463
 
2522
 
Line 2478... Line 2537...
2478
			} else {
2537
			} else {
2479
				showBeatList();
2538
				showBeatList();
2480
				setTimeout(function () {
2539
				setTimeout(function () {
2481
					$('.panel-tab[data-tab="calendar"]').click();
2540
					$('.panel-tab[data-tab="calendar"]').click();
2482
				}, 100);
2541
				}, 100);
-
 
2542
				if (state.assignDeferred) {
-
 
2543
					// Banner instructing the head to click an upcoming beat.
-
 
2544
					var ad = state.assignDeferred;
-
 
2545
					$('#deferred-assign-banner').remove();
-
 
2546
					$('body').prepend(
-
 
2547
						'<div id="deferred-assign-banner" style="position:sticky;top:0;z-index:2000;'
-
 
2548
						+ 'background:#0d9488;color:#fff;padding:8px 16px;font-size:13px;">'
-
 
2549
						+ 'Adding deferred ' + (ad.type === 'lead' ? 'lead' : 'partner') + ': '
-
 
2550
						+ '<strong>' + ad.name + '</strong> — click an upcoming beat on the calendar to drop it in.'
-
 
2551
						+ '</div>');
-
 
2552
				}
2483
			}
2553
			}
2484
		},
2554
		},
2485
		error: function (xhr) {
2555
		error: function (xhr) {
2486
			console.error('[BEAT-AUTO] getBaseLocation failed:', xhr.status, xhr.responseText);
2556
			console.error('[BEAT-AUTO] getBaseLocation failed:', xhr.status, xhr.responseText);
2487
		}
2557
		}