Subversion Repositories SmartDukaan

Rev

Rev 35648 | Rev 35726 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27797 tejbeer 1
$(function() {
24125 govind 2
 
27797 tejbeer 3
	$(document).on('click', "#retailer-details-search-button", function() {
35459 amit 4
		searchContent = $("#retailer-details-search-text").val();
5
		if (typeof (searchContent) == "undefined" || !searchContent) {
27797 tejbeer 6
			searchContent = "";
7
		}
8
		getRetailerDetailsByEmailIdOrMobileNumber(
9
			"retailer-details-container", searchContent);
10
	});
31860 tejbeer 11
 
28711 amit.gupta 12
	$(document).on('click', ".activate-store-temporary", function() {
13
		var row = $(this).closest("tr");
14
		var fofoId = $(this).data("fofoid");
31860 tejbeer 15
 
28711 amit.gupta 16
		var ActiveDays = $(row).find("td:eq(4) input[type='text']").val();
17
		console.log("ActiveDays" + ActiveDays);
18
		console.log("fofoId" + fofoId);
19
		var days = parseInt(ActiveDays);
28713 amit.gupta 20
		if (confirm("Are you sure you want to activate this store!") == true) {
31860 tejbeer 21
			doPostAjaxRequestHandler(context + "/activateStoreTemporary?fofoId=" + fofoId + "&days=" + days,
28711 amit.gupta 22
				function(response) {
23
					if (response == "true") {
24
						alert("successfully activated!");
25
						inactiveStoreInfo("main-content");
26
					}
24159 tejbeer 27
 
28711 amit.gupta 28
				});
31860 tejbeer 29
 
28713 amit.gupta 30
		}
28711 amit.gupta 31
 
31860 tejbeer 32
 
28711 amit.gupta 33
	});
31860 tejbeer 34
 
29268 manish 35
	$(document).on('click', ".partner-info", function() {
31860 tejbeer 36
		var userIds = {};
37
		userIds['userIds'] = $('#fofo-users').val();
38
		console.log(userIds)
39
		doPostAjaxRequestWithJsonHandler(context + "/getPartnerinfo", JSON.stringify(userIds), function(response) {
40
 
29268 manish 41
			$('.storePartnerInfo').html(response);
42
		});
31860 tejbeer 43
 
29268 manish 44
	});
27797 tejbeer 45
	$(document).on('click', ".active-store", function() {
29268 manish 46
		store("main-content");
47
	});
48
	$(document).on('click', ".allStoreInfo", function() {
27797 tejbeer 49
		storeInfo("main-content");
50
	});
31860 tejbeer 51
 
52
 
27797 tejbeer 53
	$(document).on('click', ".inactive-store", function() {
54
		inactiveStoreInfo("main-content");
55
	});
56
	$(document).on('click', ".retailer-info", function() {
57
		retailerInfo("main-content");
58
	});
24125 govind 59
 
27231 tejbeer 60
 
27797 tejbeer 61
	$(document).on('click', ".partner-readonly-info", function() {
62
		partnerInfo("main-content")
27171 tejbeer 63
 
64
 
27797 tejbeer 65
	});
28071 tejbeer 66
	$(document).on('click', ".block-brand-mapping", function() {
67
		blockBrandMapping("main-content")
27171 tejbeer 68
 
24125 govind 69
 
28071 tejbeer 70
	});
31860 tejbeer 71
 
28272 tejbeer 72
	$(document).on('click', ".brands-limit", function() {
73
		brandsLimit("main-content")
28071 tejbeer 74
 
75
 
28272 tejbeer 76
	});
31860 tejbeer 77
 
78
	$(document).on('click', ".add-partner-pincode", function() {
28381 tejbeer 79
		allPartnerPincode("main-content")
28272 tejbeer 80
 
81
 
28381 tejbeer 82
	});
28272 tejbeer 83
 
28381 tejbeer 84
 
27797 tejbeer 85
	$(document).on('click', ".partnerInfoReadOnly",
86
		function() {
24125 govind 87
 
27797 tejbeer 88
			var fofoId = $('#fofo-users').val();
89
			loginAsPartnerReadonly(fofoId);
90
		});
91
	$(document).on('change', "#retailerAddressPinCode",
92
		function() {
27171 tejbeer 93
 
27797 tejbeer 94
			var pincode = $('#retailerAddressPinCode').val();
24125 govind 95
 
27797 tejbeer 96
			if (undefined != pincode) {
97
				doGetAjaxRequestHandler(context + "/postOffice?pinCode="
98
					+ pincode,
99
					function(response) {
100
						console.log(response.response.state);
101
						$('#retailerAddressCity').find('option').not(':first').remove();
102
						$('#retailerAddressState').val("");
103
						$('#retailerAddressState').val(
104
							response.response.state);
105
						loadDistrictNames(response.response.state);
33124 ranu 106
						loadASTDetail(response.response.state);
27797 tejbeer 107
						for (let city of response.response.cities) {
108
							var opt = $("<option>").val(city).text(city);
109
							$('#retailerAddressCity').append(opt);
24349 amit.gupta 110
 
27797 tejbeer 111
						}
24159 tejbeer 112
 
27797 tejbeer 113
					});
114
			}
115
		});
24159 tejbeer 116
 
27797 tejbeer 117
	$(document).on("keyup", "#retailer-details-search-text", function(e) {
118
		var keyCode = e.keyCode || e.which;
119
		if (keyCode == 13) {
120
			$("#retailer-details-search-button").click();
121
		}
122
	});
24159 tejbeer 123
 
27797 tejbeer 124
	$(document).on('click', ".deactivate-store", function() {
125
		var fofoId = $(this).data("fofoid");
126
		console.log(fofoId);
127
		if (confirm("Are you sure you want to deactivate store!") == true) {
128
			deactivateStore("main-content", fofoId);
129
		}
27171 tejbeer 130
 
27797 tejbeer 131
	});
28711 amit.gupta 132
	$(document).on('click', ".activate-store-forever", function() {
133
		var fofoId = $(this).data("fofoid");
134
		console.log(fofoId);
135
		if (confirm("Are you sure you want to activate this store!") == true) {
136
			activateStoreForever("main-content", fofoId);
137
		}
138
 
139
	});
31860 tejbeer 140
 
27797 tejbeer 141
	$(document).on('click', ".login_as", function() {
142
		var fofoId = $('#partnerId').val();
143
		loginAsPartner(fofoId);
24159 tejbeer 144
 
27797 tejbeer 145
	});
24159 tejbeer 146
 
31860 tejbeer 147
 
31892 tejbeer 148
	$('#partnerSecondary').on('click', '.brandFocusedStock', function() {
34087 ranu 149
 
31892 tejbeer 150
		var fofoId = $(this).data('fofoid');
151
		var brand = $(this).data('brand');
152
 
31895 tejbeer 153
		doGetAjaxRequestHandler(
154
			"https://partners.smartdukaan.com" + "/getPartnerShortageStock?brand=" + brand + "&fofoId="
31892 tejbeer 155
			+ fofoId, function(response) {
156
 
157
				$('#itemWiseBrandStock .modal-content').html(response);
158
 
159
			});
160
	});
161
 
162
 
163
 
34087 ranu 164
 
165
 
166
 
167
 
31932 tejbeer 168
	$(document).on('click', ".agingDataAfterNintyDays", function() {
169
		var fofoId = $(this).data('fofoid');
170
		console.log(fofoId)
171
 
172
		doPostAjaxRequestWithJsonHandler(
173
			"https://partners.smartdukaan.com" + "/getInventoryItemAgingByFofoId?fofoId="
174
			+ fofoId, JSON.stringify([90]),
175
			function(response) {
176
				$('#agingItemWiseBrandStock .modal-content').html(response);
177
			});
178
	});
179
 
180
 
181
 
27797 tejbeer 182
	$(document).on('click', ".extend-billing", function() {
183
		var fofoId = $(this).data("fofoid");
184
		console.log(fofoId);
185
		if (confirm("Are you sure you want to extend Billing?")) {
186
			extendBilling($(this).parent(), fofoId);
187
		}
24159 tejbeer 188
 
27797 tejbeer 189
	});
24159 tejbeer 190
 
31860 tejbeer 191
	/*
192
	 * $(document).on('change', '#retailerAddressState', function() { var stateName =
193
	 * $(this).find('option:selected').text();
194
	 *
195
	 * loadDistrictNames(stateName); });
196
	 */
24159 tejbeer 197
 
198
 
27797 tejbeer 199
	$(document).on('click', "#location", function() {
200
		if ($(this).is(":checked")) {
27516 amit.gupta 201
 
27797 tejbeer 202
			$("#divLocation").show();
27516 amit.gupta 203
 
27797 tejbeer 204
		} else {
205
			$("#divLocation").hide();
206
		}
207
	});
27516 amit.gupta 208
 
209
 
27797 tejbeer 210
	$(document).on('click', ".changePartnerCategory", function() {
35459 amit 211
		$clickedElement = $(this);
27797 tejbeer 212
		var fofoId = $clickedElement.data("id");
35459 amit 213
		$tdElement = $(this).closest('td');
27797 tejbeer 214
		doGetAjaxRequestHandler(context + "/getPartnerCategory?fofoId=" + fofoId, function(response) {
27516 amit.gupta 215
 
27797 tejbeer 216
			$tdElement.html(response);
217
			$tdElement.find('.partnerCategory').multiselect({
218
				includeSelectAllOption: true,
219
				multiple: true,
220
				maxHeight: 200,
221
				buttonWidth: '180px',
222
				numberDisplayed: 1,
223
				nonSelectedText: 'Category',
224
				nSelectedText: ' - Category Selected',
225
				allSelectedText: 'All Category Selected',
226
				enableFiltering: true,
227
				enableCaseInsensitiveFiltering: true
228
			});
229
		});
230
	});
27516 amit.gupta 231
 
232
 
27797 tejbeer 233
	$(document).on('click', ".update-category",
234
		function() {
235
			var fofoId = $(this).data('fofoid');
236
			var partnerType = $('#partnerCategory').val();
35674 amit 237
			var durationMonths = $('#upgradeDuration').val();
27516 amit.gupta 238
 
35674 amit 239
			if (confirm("Are you sure you want to upgrade for " + durationMonths + " month(s)?") == true) {
27797 tejbeer 240
				doPostAjaxRequestHandler(context
241
					+ "/updatePartnerCategory?fofoId="
35674 amit 242
					+ fofoId + "&partnerType=" + partnerType + "&durationMonths=" + durationMonths, function(
27797 tejbeer 243
						response) {
244
					if (response == "true") {
245
						alert("Update successfully");
246
						storeInfo("main-content");
247
					}
248
				});
249
			}
27516 amit.gupta 250
 
27797 tejbeer 251
		});
252
 
253
 
31860 tejbeer 254
 
255
 
27797 tejbeer 256
	$(document).on('click', ".addlocationbutton",
257
		function() {
258
			var userId = $('#retailerId').text();
259
			var name = $('#personName').val();
260
			var line1 = $('#line1').val();
261
			var line2 = $('#line2').val();
262
			var city = $('#city').val();
263
			var state = $('#state').val();
264
			var pin = $('#pinCode').val();
265
 
266
			if (name === "" && line1 === "" && city === "" && pin === "") {
267
				alert("Field can't be empty");
268
				return;
269
			}
270
			if (name === "") {
271
				alert("name is required");
272
				return;
273
			}
274
			if (line1 === "") {
275
				alert("line1 is required");
276
				return;
277
			}
278
			if (city === "") {
279
				alert("city is required");
280
				return;
281
			}
282
			if (pin === "") {
283
				alert("pin is required");
284
				return;
285
			}
286
 
287
			var locationData = {};
288
			locationData['userId'] = $('#retailerId').text();
289
			locationData['name'] = $('#personName').val();
290
			locationData['line1'] = $('#line1').val();
291
			locationData['line2'] = $('#line2').val();
292
			locationData['city'] = $('#city').val();
293
			locationData['state'] = $('#state').val();
294
			locationData['pin'] = $('#pinCode').val();
295
 
296
			if (confirm("Are you sure you want to add location!") == true) {
297
				doPostAjaxRequestWithJsonHandler(context + "/addLocation",
298
					JSON.stringify(locationData), function(response) {
299
						if (response == 'true') {
300
							alert("successfully Add");
301
							$("#addLocationModal").modal('hide');
302
 
303
						}
304
					});
305
 
306
				return false;
307
			}
308
		});
309
 
32044 tejbeer 310
 
311
 
312
	//Performance
313
	$(document).on('click', ".partner-performance-access", function() {
314
		doGetAjaxRequestHandler(context + "/getPartnersForPerformance", function(response) {
315
			$('#' + "main-content").html(response);
316
		});
317
	});
318
 
319
	$(document).on('click', ".partnerPerformance", function() {
320
		var fofoId = $('#fofo-users').val();
321
		var url = context + "/partnerPerformance?fofoId=" + fofoId;
322
		//$('.partner-performance-container').html(`<iframe class="wrapper" src="${url}" style="width:100%;height:100vh"> </iframe>`); 
323
		doGetAjaxRequestHandler(context + "/partnerPerformance?fofoId=" + fofoId, function(response) {
324
			$('.partner-performance-container').html(response);
325
		});
326
	});
327
 
328
	$(document).on('click', ".retailer-filter", function() {
329
		doGetAjaxRequestHandler(context + "/getFilters", function(response) {
330
			$('#' + "main-content").html(response);
331
		});
332
	});
333
 
334
 
335
	$(document).on('click', ".filters", function() {
336
 
337
		var credit = $('#credit').is(':checked');
338
		var billing = $('#billing').is(':checked');
339
		var investment = $('#investment').is(':checked');
340
		var secondary = $('#secondary').is(':checked');
341
		var tertiary = $('#tertiary').is(':checked');
342
		var mtds = $('#mtds').is(':checked');
343
		var mtdt = $('#mtdt').is(':checked');
344
 
345
		var investmentPct = $('#investmentvalue').val();
346
		var secondaryDays = $('#secondaryvalue').val();
347
		var tertiaryDays = $('#tertiaryvalue').val();
348
		var mtdsPct = $('#mtdsvalue').val();
349
		var mtdtPct = $('#mtdtvalue').val();
350
 
351
		console.log(investmentPct)
352
 
353
 
354
 
355
		var retailerFilters = {};
356
		retailerFilters['credit'] = credit;
357
		retailerFilters['billing'] = billing
358
		if (investment) {
359
			retailerFilters['investmentPct'] = investmentPct
360
		}
361
		if (secondary) {
362
			retailerFilters['secondaryDays'] = secondaryDays
363
		}
364
		if (tertiary) {
365
			retailerFilters['tertiaryDays'] = tertiaryDays
366
		}
367
 
368
		if (mtds) {
369
			retailerFilters['mtdsPct'] = mtdsPct
370
		}
371
 
372
		if (mtdt) {
373
			retailerFilters['mtdtPct'] = mtdtPct
374
		}
375
 
32089 tejbeer 376
		console.log(JSON.stringify(retailerFilters));
377
 
32044 tejbeer 378
		doAjaxRequestWithJsonHandler(context + "/getFilteredRetailers", 'POST', JSON.stringify(retailerFilters), function(response) {
379
			$('.filtered-partner-performance-container').html(response);
380
 
381
		});
382
	});
383
 
384
 
385
 
386
	$(document).on('click', ".default-email-val", function() {
387
 
388
		var credit = $('#credit').is(':checked');
389
		var billing = $('#billing').is(':checked');
390
		var investment = $('#investment').is(':checked');
391
		var secondary = $('#secondary').is(':checked');
392
		var tertiary = $('#tertiary').is(':checked');
393
		var mtds = $('#mtds').is(':checked');
394
		var mtdt = $('#mtdt').is(':checked');
395
 
396
		var investmentPct = $('#investmentvalue').val();
397
		var secondaryDays = $('#secondaryvalue').val();
398
		var tertiaryDays = $('#tertiaryvalue').val();
399
		var mtdsPct = $('#mtdsvalue').val();
400
		var mtdtPct = $('#mtdtvalue').val();
401
 
402
		console.log(investmentPct)
403
 
404
 
405
 
406
		var retailerFilters = {};
407
		retailerFilters['credit'] = credit;
408
		retailerFilters['billing'] = billing
409
		retailerFilters['investmentPct'] = investmentPct
410
		retailerFilters['secondaryDays'] = secondaryDays
411
		retailerFilters['tertiaryDays'] = tertiaryDays
412
		retailerFilters['mtdsPct'] = mtdsPct
413
		retailerFilters['mtdtPct'] = mtdtPct
414
 
415
 
416
 
417
 
418
		doAjaxRequestWithJsonHandler(context + "/defaultFilterSetForEmail", 'POST', JSON.stringify(retailerFilters), function(response) {
419
			if (response == "true") {
420
				alert("Successfully Done")
421
			}
422
		});
423
	});
424
 
425
 
23347 ashik.ali 426
});
427
 
23837 ashik.ali 428
function getDistance(lat1, lon1, lat2, lon2) {
27797 tejbeer 429
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
430
	var cos = Math.cos;
431
	lat1 *= deg2rad;
432
	lon1 *= deg2rad;
433
	lat2 *= deg2rad;
434
	lon2 *= deg2rad;
435
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
436
	var dLat = lat2 - lat1;
437
	var dLon = lon2 - lon1;
438
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 439
 
27797 tejbeer 440
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
24125 govind 441
}
23837 ashik.ali 442
 
24125 govind 443
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
27797 tejbeer 444
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
445
		+ emailIdOrMobileNumber, function(response) {
446
			$('#' + domId).html(response);
447
			if ($("#location").is(":checked")) {
27171 tejbeer 448
 
27797 tejbeer 449
				$("#divLocation").show();
450
			}
451
		});
23347 ashik.ali 452
}
453
 
24125 govind 454
function updateRetailerDocument() {
27797 tejbeer 455
	// $("#updateRetailerShopDocument0").click( function() {
456
	console.log("Update Retailer Document Clicked");
457
	// console.log(ownerId);
458
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
459
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
460
	var file = $('#retailerDocument')[0].files[0];
461
	console.log("file : " + file.name);
462
	uploadRetailerDocument("retailer-details-container", file,
463
		emailIdOrMobileNumber);
23347 ashik.ali 464
}
465
 
24125 govind 466
function updateRetailerShopDocument(ownerId) {
27797 tejbeer 467
	// $("#updateRetailerShopDocument0").click( function() {
468
	console.log("Update Retailer Shop Document Clicked");
469
	console.log(ownerId);
470
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
471
	console.log("size : " + shopSize);
472
	for (var index = 0; index < shopSize; index++) {
473
		if ("updateRetailerShopDocument" + index == ownerId) {
474
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
475
				.val();
476
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
477
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
478
			console.log("shopId : " + shopId);
479
			var file = $('#retailerShopDocument' + index)[0].files[0];
480
			console.log("file : " + file.name);
481
			uploadRetailerShopDocument("retailer-details-container", file,
482
				emailIdOrMobileNumber, shopId);
483
		}
484
	}
23347 ashik.ali 485
}
486
 
24125 govind 487
function loadDistrictNames(stateName) {
27797 tejbeer 488
	if (undefined != $("#districtName")) {
489
		doGetAjaxRequestHandler(
490
			context + "/district/all/stateName?stateName=" + stateName,
491
			function(response) {
492
				console.log(response);
493
				var districtMasters = response.response;
494
				// districtMasters = districtMasters.response;
495
				var districtNameElements = '<option value="" disabled selected>District Name</option>';
496
				for (index = 0; index < districtMasters.length; index++) {
497
					districtNameElements = districtNameElements
498
						+ '<option value="'
499
						+ districtMasters[index].name + '">'
500
						+ districtMasters[index].name + '</option>';
501
				}
502
				$('#districtName').html(districtNameElements);
503
			});
504
	}
23347 ashik.ali 505
}
506
 
33124 ranu 507
function loadASTDetail(stateName) {
508
	doGetAjaxRequestHandler(
509
		context + "/astDetail?stateName=" + stateName,
33128 amit.gupta 510
		function (asts) {
33124 ranu 511
			$('#retailerAstId').find('option').not(':first').remove();
33128 amit.gupta 512
			for (let ast of asts) {
513
				var opt = $("<option>").val(ast.id).text(ast.area + "(" + ast.areaDescription + ")" + " - " + ast.territory + "(" + ast.territoryDescription + ")");
33124 ranu 514
				$('#retailerAstId').append(opt);
515
			}
516
		}
517
	);
518
}
519
 
24125 govind 520
function retailerInfo(domId) {
27797 tejbeer 521
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
522
		$('#' + domId).html(response);
24159 tejbeer 523
 
27797 tejbeer 524
	});
24159 tejbeer 525
 
24125 govind 526
}
27231 tejbeer 527
 
27516 amit.gupta 528
function partnerInfo(domId) {
27797 tejbeer 529
	doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function(response) {
530
		$('#' + domId).html(response);
27516 amit.gupta 531
 
27797 tejbeer 532
	});
27231 tejbeer 533
}
28071 tejbeer 534
function blockBrandMapping(domId) {
535
	doGetAjaxRequestHandler(context + "/getBlockBrandMapping", function(response) {
536
		$('#' + domId).html(response);
27516 amit.gupta 537
 
28071 tejbeer 538
	});
539
}
28272 tejbeer 540
function brandsLimit(domId) {
541
	doGetAjaxRequestHandler(context + "/getBrandslimit", function(response) {
542
		$('#' + domId).html(response);
28071 tejbeer 543
 
28272 tejbeer 544
	});
545
}
24125 govind 546
function storeInfo(domId) {
27797 tejbeer 547
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
548
		$('#' + domId).html(response);
549
	});
24125 govind 550
}
27516 amit.gupta 551
 
29268 manish 552
function store(domId) {
553
	doGetAjaxRequestHandler(context + "/getstore", function(response) {
554
		$('#' + domId).html(response);
555
	});
556
}
24680 govind 557
function inactiveStoreInfo(domId) {
27797 tejbeer 558
	doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(
559
		response) {
560
		$('#' + domId).html(response);
561
	});
24680 govind 562
}
27516 amit.gupta 563
 
28381 tejbeer 564
function allPartnerPincode(domId) {
565
	doGetAjaxRequestHandler(context + "/getAllPartnerPincode", function(
566
		response) {
567
		$('#' + domId).html(response);
568
	});
569
}
570
 
24125 govind 571
function deactivateStore(domId, fofoId) {
27797 tejbeer 572
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
573
		function(response) {
574
			if (response == "true") {
575
				alert("successfully deactivated!");
576
				storeInfo(domId);
577
			}
24159 tejbeer 578
 
27797 tejbeer 579
		});
24125 govind 580
}
28711 amit.gupta 581
function activateStoreForever(domId, fofoId) {
582
	doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,
583
		function(response) {
584
			if (response == "true") {
585
				alert("successfully activated!");
586
				inactiveStoreInfo(domId);
587
			}
27516 amit.gupta 588
 
28711 amit.gupta 589
		});
590
}
591
 
24976 amit.gupta 592
function loginAsPartner(fofoId) {
27797 tejbeer 593
	doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
594
		function(response) {
595
			window.create({
596
				"url": "/dashboard",
597
				"incognito": true
598
			});
31860 tejbeer 599
 
27797 tejbeer 600
		});
24976 amit.gupta 601
}
27231 tejbeer 602
 
603
function loginAsPartnerReadonly(fofoId) {
27797 tejbeer 604
	doGetAjaxRequestHandler(context + "/login-as-partner-readonly?fofoId=" + fofoId,
605
		function(response) {
606
			window.create({
607
				"url": "/dashboard",
608
				"incognito": true
609
			});
610
		});
27231 tejbeer 611
}
27516 amit.gupta 612
 
24349 amit.gupta 613
function extendBilling(container, fofoId) {
27797 tejbeer 614
	doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
615
		function(response) {
616
			if (isFinite(response)) {
617
				alert("successfully deactivated!");
618
				container.html("Billing extended upto "
619
					+ moment().add(1, 'day').format("DD-MM-YY")
620
					+ " Grace count(" + response + ")");
621
			}
622
		});
24349 amit.gupta 623
}
24159 tejbeer 624
 
625
function updateLocationButton(id) {
626
 
27797 tejbeer 627
	var userId = id;
628
	var name = $('#personName').val();
629
	var line1 = $('#line1').val();
630
	var line2 = $('#line2').val();
631
	var city = $('#city').val();
632
	var state = $('#state').val();
633
	var pin = $('#pinCode').val();
634
	console.log(id);
635
	if (name === "" && line1 === "" && city === "" && pin === "") {
636
		alert("Field can't be empty");
637
		return;
638
	}
639
	if (name === "") {
640
		alert("name is required");
641
		return;
642
	}
643
	if (line1 === "") {
644
		alert("line1 is required");
645
		return;
646
	}
647
	if (city === "") {
648
		alert("city is required");
649
		return;
650
	}
651
	if (pin === "") {
652
		alert("pin is required");
653
		return;
654
	}
24159 tejbeer 655
 
27797 tejbeer 656
	var changeLocationData = {};
24159 tejbeer 657
 
27797 tejbeer 658
	changeLocationData['userId'] = id;
659
	changeLocationData['name'] = $('#personName').val();
660
	changeLocationData['line1'] = $('#line1').val();
661
	changeLocationData['line2'] = $('#line2').val();
662
	changeLocationData['city'] = $('#city').val();
663
	changeLocationData['state'] = $('#state').val();
664
	changeLocationData['pin'] = $('#pinCode').val();
24159 tejbeer 665
 
27797 tejbeer 666
	console.log(changeLocationData);
24159 tejbeer 667
 
27797 tejbeer 668
	if (confirm("Are you sure you want to add location!") == true) {
669
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
670
			.stringify(changeLocationData), function(response) {
671
				if (response == 'true') {
672
					alert("successfully Update");
24159 tejbeer 673
 
27797 tejbeer 674
					$("#addLocationModal").modal('hide');
24159 tejbeer 675
 
27797 tejbeer 676
				}
677
			});
24159 tejbeer 678
 
27797 tejbeer 679
		return false;
680
	}
24159 tejbeer 681
 
33814 ranu 682
}
683
 
684
$(document).on('click', ".retailer_contacts", function () {
685
	doGetAjaxRequestHandler(context + "/alternateRetailerContacts",
686
		function (response) {
687
			$('#' + 'main-content').html(response);
688
		});
689
});
690
 
691
$(document).on('click', '.get-retailer-contacts', function () {
692
 
693
	if (typeof partnerId != "undefined") {
694
		doGetAjaxRequestHandler(context + "/retailer-contact-list?fofoId=" + partnerId,
695
			function (response) {
696
				$('.retailer-contacts-container').html(response);
697
			});
698
	}
699
 
700
});
701
 
702
$(document).on('click', '.retailer-contact-submit', function () {
703
	var contactName = $('#retailer-contact-name').val();
704
	var contactNumber = $('#retailer-contact-number').val();
35648 ranu 705
	var brandName = $('#retailer-contact-brand').val();
706
	var contactType = $('#retailer-contact-type').val();
33814 ranu 707
 
708
	if (typeof partnerId != "undefined") {
35648 ranu 709
		doGetAjaxRequestHandler(context + "/add-retailer-contact-list?contactName=" + encodeURIComponent(contactName) + "&contactNumber=" + encodeURIComponent(contactNumber) + "&brandName=" + encodeURIComponent(brandName) + "&contactType=" + encodeURIComponent(contactType) + "&fofoId=" + partnerId,
33814 ranu 710
			function (response) {
711
				$('#update-retailer-contact-modal').modal('toggle');
712
				$('.retailer-contacts-container').html(response);
713
			});
714
	}
715
 
716
});
717
 
718
$(document).on('click', '.update-contact-status', function () {
719
	var contactId = $(this).data('contactid');
720
	var active = $(this).data('status');
721
 
722
	if (typeof partnerId != "undefined") {
723
		doGetAjaxRequestHandler(context + "/update-contact-status?contactId=" + contactId + "&fofoId=" + partnerId + "&active=" + active,
724
			function (response) {
725
				$('.retailer-contacts-container').html(response);
726
			});
727
	}
728
 
34425 ranu 729
});
730
 
731
// analysis dasboard js for retailer
732
 
733
$(document).on('click', '.dashboard-view', function () {
734
	var fofoId = $(this).data('fofoid');
735
 
736
	window.open(context + "/analysisDashboard?fofoId=" + fofoId, '_blank');
737
});
34813 aman 738
 
739
$('#partnerTasks').modal({
34971 aman 740
	backdrop: 'static',
741
	keyboard: false
34813 aman 742
});
743
 
744
const emailId = getCookie('emailId');
745
console.log("Email ID:", emailId);
746
 
34818 aman 747
function showModal() {
34971 aman 748
	if (emailId && emailId.endsWith('@smartdukaan.com')) {
749
		console.log('SmartDukaan user - modal not shown');
750
		return;
751
	}
34818 aman 752
	$('#partnerTasks').removeAttr('aria-hidden');
34813 aman 753
 
754
	if (!emailId || !emailId.endsWith('@smartdukaan.com')) {
755
		$('#chartData').html('<div class="loader text-center " style=" height: 30px;\n' +
756
			'    display: flex;\n' +
757
			'    justify-content: center;\n' +
758
			'    align-items: center;\n' +
759
			'    font-size: 1.5rem;\n' +
760
			'    font-weight: 200;\n' +
761
			'    color: #555;" >Loading...</div>');
762
 
35001 aman 763
		doGetAjaxRequestHandler(context + "/dashboardModal", function (response, status) {
764
			if (status === 500) {
34968 ranu 765
				return;
766
			}
34813 aman 767
			$('#chartData').html(response);
34818 aman 768
			$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 769
		});
770
	} else {
771
		$('#chartData').html('<p>No data to load</p>');
34818 aman 772
		$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 773
	}
34818 aman 774
}
775
 
776
$(document).ready(function () {
34987 aman 777
	const isAdmin = emailId && emailId.endsWith('@smartdukaan.com');
778
	console.log("user is admin?" + isAdmin)
779
	console.log("user email id?" + emailId)
780
	if (isAdmin) {
781
		console.log('Admin user - modal logic completely skipped');
34971 aman 782
		return;
783
	}
34987 aman 784
 
34818 aman 785
	const today = new Date().toDateString();
786
	const currentHour = new Date().getHours();
787
	const stored = JSON.parse(localStorage.getItem('modalData') || '{}');
788
 
789
	if (stored.date !== today) {
790
		localStorage.setItem('modalData', JSON.stringify({date: today, count: 1}));
791
		console.log('First login of day - showing modal');
792
		showModal();
793
	} else if (stored.count === 1 && currentHour >= 17) {
794
		localStorage.setItem('modalData', JSON.stringify({date: today, count: 2}));
795
		console.log('5 PM show - showing modal');
796
		showModal();
797
	} else {
798
		console.log('Modal conditions not met - not showing');
799
		$('#partnerTasks').modal('hide');
34825 aman 800
		$('.modal-backdrop').remove();
34818 aman 801
	}
34813 aman 802
});
34818 aman 803
 
34813 aman 804
$(document).on('click', '.partner-tasks-btn', function () {
34971 aman 805
	if (emailId && emailId.endsWith('@smartdukaan.com')) {
806
		console.log('SmartDukaan user - button click blocked');
807
		return;
808
	}
34813 aman 809
	doGetAjaxRequestHandler(context + "/dashboardModal", function (response) {
810
		$('#chartData').html(response);
34818 aman 811
		$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 812
		$('#partnerTasks').modal('show');
813
	});
814
});
815
 
816
$('#partnerTasks').on('hidden.bs.modal', function () {
817
	$(this).data('modal', null);
818
	$('.modal-backdrop').remove();
819
	const bootstrapCss = document.getElementById('modal-bootstrap-css');
820
	if (bootstrapCss) {
821
		bootstrapCss.remove();
822
	}
34818 aman 823
});