Subversion Repositories SmartDukaan

Rev

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

Rev 36651 Rev 36668
Line 786... Line 786...
786
	}
786
	}
787
 
787
 
788
	recalcDay();
788
	recalcDay();
789
	drawRoute();
789
	drawRoute();
790
	renderRoutePanel();
790
	renderRoutePanel();
-
 
791
	if (typeof renderPartnersPanel === 'function') renderPartnersPanel();
791
 
792
 
792
	if (action === 'last') {
793
	if (action === 'last') {
793
		// Last visit — end day, go home
794
		// Last visit — end day, go home
794
		day.endAction = 'HOME';
795
		day.endAction = 'HOME';
795
		day.stayLat = state.homeLat;
796
		day.stayLat = state.homeLat;
Line 1117... Line 1118...
1117
 
1118
 
1118
	recalcDay();
1119
	recalcDay();
1119
	drawRoute();
1120
	drawRoute();
1120
	renderRoutePanel();
1121
	renderRoutePanel();
1121
	updateBottomBar();
1122
	updateBottomBar();
-
 
1123
	if (typeof renderPartnersPanel === 'function') renderPartnersPanel();
1122
});
1124
});
1123
 
1125
 
1124
// ============ LAST VISIT (from sidebar) — marks beat as complete, return home ============
1126
// ============ LAST VISIT (from sidebar) — marks beat as complete, return home ============
1125
$(document).on('click', '.btn-last-visit', function (e) {
1127
$(document).on('click', '.btn-last-visit', function (e) {
1126
    e.stopPropagation();
1128
    e.stopPropagation();
Line 1270... Line 1272...
1270
$('.panel-tab').on('click', function () {
1272
$('.panel-tab').on('click', function () {
1271
	var tab = $(this).data('tab');
1273
	var tab = $(this).data('tab');
1272
	$('.panel-tab').removeClass('active');
1274
	$('.panel-tab').removeClass('active');
1273
	$(this).addClass('active');
1275
	$(this).addClass('active');
1274
	$('#panel-route').toggle(tab === 'route');
1276
	$('#panel-route').toggle(tab === 'route');
-
 
1277
	$('#panel-partners').toggle(tab === 'partners');
1275
	$('#panel-calendar').toggle(tab === 'calendar');
1278
	$('#panel-calendar').toggle(tab === 'calendar');
1276
	$('#cal-grid-container').toggle(tab === 'calendar');
1279
	$('#cal-grid-container').toggle(tab === 'calendar');
1277
	$('#bottom-bar').toggle(tab === 'route' && (state.mode === 'create' || state.mode === 'edit') && state.days && state.days.length > 0);
1280
	$('#bottom-bar').toggle((tab === 'route' || tab === 'partners') && (state.mode === 'create' || state.mode === 'edit') && state.days && state.days.length > 0);
1278
 
1281
 
-
 
1282
	if (tab === 'partners') renderPartnersPanel();
1279
	if (tab === 'calendar' && !state.calMonth) {
1283
	if (tab === 'calendar' && !state.calMonth) {
1280
		var now = new Date();
1284
		var now = new Date();
1281
		state.calMonth = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1)).slice(-2);
1285
		state.calMonth = now.getFullYear() + '-' + ('0' + (now.getMonth() + 1)).slice(-2);
1282
		loadCalendarData();
1286
		loadCalendarData();
1283
	}
1287
	}
1284
});
1288
});
1285
 
1289
 
-
 
1290
// ============ PARTNERS PANEL (search + tick to add) ============
-
 
1291
function renderPartnersPanel() {
-
 
1292
	var $list = $('#partners-list');
-
 
1293
	if (!$list.length) return;
-
 
1294
	if (!state.partners || state.partners.length === 0) {
-
 
1295
		$list.html('<p style="color:#64748b;font-size:12px;text-align:center;padding:20px 10px;">Load a user first.</p>');
-
 
1296
		$('#partners-count').text('0 / 0');
-
 
1297
		return;
-
 
1298
	}
-
 
1299
 
-
 
1300
	var q = ($('#partners-search').val() || '').trim().toLowerCase();
-
 
1301
 
-
 
1302
	// Build a lookup: fofoId -> dayNumber it's already in (current day's visits)
-
 
1303
	var inRoute = {};
-
 
1304
	(state.days || []).forEach(function (d) {
-
 
1305
		(d.visits || []).forEach(function (v) {
-
 
1306
			if (v.type === 'partner' || v.type == null) inRoute[v.id] = d.dayNumber;
-
 
1307
		});
-
 
1308
	});
-
 
1309
 
-
 
1310
	var filtered = state.partners.filter(function (p) {
-
 
1311
		if (!q) return true;
-
 
1312
		var hay = ((p.code || '') + ' ' + (p.outletName || '') + ' ' + (p.businessName || '') + ' ' + (p.city || '')).toLowerCase();
-
 
1313
		return hay.indexOf(q) !== -1;
-
 
1314
	});
-
 
1315
 
-
 
1316
	// Sort: in-route first (so user can see what's already added), then by code
-
 
1317
	filtered.sort(function (a, b) {
-
 
1318
		var aIn = inRoute[a.fofoId] ? 0 : 1;
-
 
1319
		var bIn = inRoute[b.fofoId] ? 0 : 1;
-
 
1320
		if (aIn !== bIn) return aIn - bIn;
-
 
1321
		return (a.code || '').localeCompare(b.code || '');
-
 
1322
	});
-
 
1323
 
-
 
1324
	var html = '';
-
 
1325
	filtered.forEach(function (p) {
-
 
1326
		var checked = inRoute[p.fofoId];
-
 
1327
		var name = (p.outletName || p.businessName || '');
-
 
1328
		var city = p.city || '';
-
 
1329
		html += '<label class="partner-row' + (checked ? ' in-route' : '') + '">'
-
 
1330
			+ '<input type="checkbox" class="partner-tick" data-fofoid="' + p.fofoId + '"' + (checked ? ' checked' : '') + '>'
-
 
1331
			+ '<div class="pr-info">'
-
 
1332
			+ '<div class="pr-code">' + (p.code || '') + (name ? ' <span class="pr-name">- ' + name + '</span>' : '') + '</div>'
-
 
1333
			+ (city ? '<div class="pr-name">' + city + '</div>' : '')
-
 
1334
			+ '</div>'
-
 
1335
			+ (checked ? '<span class="pr-day">D' + checked + '</span>' : '')
-
 
1336
			+ '</label>';
-
 
1337
	});
-
 
1338
	if (html === '') html = '<p style="color:#64748b;font-size:12px;text-align:center;padding:20px 10px;">No partners match.</p>';
-
 
1339
	$list.html(html);
-
 
1340
	$('#partners-count').text(filtered.length + ' / ' + state.partners.length);
-
 
1341
}
-
 
1342
 
-
 
1343
$(document).on('input', '#partners-search', function () {
-
 
1344
	renderPartnersPanel();
-
 
1345
});
-
 
1346
 
-
 
1347
$(document).on('change', '.partner-tick', function () {
-
 
1348
	var fofoId = parseInt($(this).data('fofoid'));
-
 
1349
	var checked = this.checked;
-
 
1350
 
-
 
1351
	if (checked) {
-
 
1352
		// Add to current day
-
 
1353
		if (!state.days || state.days.length === 0) {
-
 
1354
			alert('Set a home location first to start the route.');
-
 
1355
			this.checked = false;
-
 
1356
			return;
-
 
1357
		}
-
 
1358
		addVisit(fofoId, 'next');
-
 
1359
		renderPartnersPanel();
-
 
1360
		return;
-
 
1361
	}
-
 
1362
 
-
 
1363
	// Untick → remove from whichever day it's in
-
 
1364
	var foundDay = null;
-
 
1365
	(state.days || []).forEach(function (d) {
-
 
1366
		if (d.visits && d.visits.some(function (v) {
-
 
1367
			return v.id === fofoId;
-
 
1368
		})) foundDay = d;
-
 
1369
	});
-
 
1370
	if (!foundDay) {
-
 
1371
		renderPartnersPanel();
-
 
1372
		return;
-
 
1373
	}
-
 
1374
 
-
 
1375
	foundDay.visits = foundDay.visits.filter(function (v) {
-
 
1376
		return v.id !== fofoId;
-
 
1377
	});
-
 
1378
 
-
 
1379
	// Reset that marker to red
-
 
1380
	if (markers[fofoId]) {
-
 
1381
		var p = state.partners.find(function (x) {
-
 
1382
			return x.fofoId === fofoId;
-
 
1383
		});
-
 
1384
		markers[fofoId].setIcon({
-
 
1385
			path: google.maps.SymbolPath.CIRCLE, scale: 14,
-
 
1386
			fillColor: '#ef4444', fillOpacity: 0.9, strokeColor: '#fff', strokeWeight: 1
-
 
1387
		});
-
 
1388
		markers[fofoId].setLabel({text: (p ? p.code : '') || '', color: '#fff', fontSize: '10px', fontWeight: '600'});
-
 
1389
	}
-
 
1390
	// Re-number remaining markers on that day
-
 
1391
	foundDay.visits.forEach(function (v, i) {
-
 
1392
		if (markers[v.id]) {
-
 
1393
			markers[v.id].setLabel({text: '' + (i + 1), color: '#fff', fontSize: '11px', fontWeight: '700'});
-
 
1394
		}
-
 
1395
	});
-
 
1396
 
-
 
1397
	recalcDay();
-
 
1398
	drawRoute();
-
 
1399
	renderRoutePanel();
-
 
1400
	updateBottomBar();
-
 
1401
	renderPartnersPanel();
-
 
1402
});
-
 
1403
 
1286
// Click a beat chip on the calendar → view that specific day's route
1404
// Click a beat chip on the calendar → view that specific day's route
1287
// (partners + only the leads scheduled for that exact date)
1405
// (partners + only the leads scheduled for that exact date)
1288
$(document).on('click', '.cal-chip-view', function (e) {
1406
$(document).on('click', '.cal-chip-view', function (e) {
1289
	if ($(e.target).hasClass('cal-chip-remove')) return; // handled separately
1407
	if ($(e.target).hasClass('cal-chip-remove')) return; // handled separately
1290
	e.stopPropagation();
1408
	e.stopPropagation();