Subversion Repositories SmartDukaan

Rev

Rev 36866 | 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
 
36866 ranu 16
		var ActiveDays = $(row).find("td:eq(5) input[type='text']").val();
28711 amit.gupta 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");
35962 amit 126
		var storeCode = $(this).data("storecode");
27797 tejbeer 127
		console.log(fofoId);
128
		if (confirm("Are you sure you want to deactivate store!") == true) {
35962 amit 129
			deactivateStore("main-content", fofoId, storeCode);
27797 tejbeer 130
		}
27171 tejbeer 131
 
27797 tejbeer 132
	});
28711 amit.gupta 133
	$(document).on('click', ".activate-store-forever", function() {
134
		var fofoId = $(this).data("fofoid");
135
		console.log(fofoId);
136
		if (confirm("Are you sure you want to activate this store!") == true) {
137
			activateStoreForever("main-content", fofoId);
138
		}
139
 
140
	});
31860 tejbeer 141
 
27797 tejbeer 142
	$(document).on('click', ".login_as", function() {
143
		var fofoId = $('#partnerId').val();
144
		loginAsPartner(fofoId);
24159 tejbeer 145
 
27797 tejbeer 146
	});
24159 tejbeer 147
 
31860 tejbeer 148
 
31892 tejbeer 149
	$('#partnerSecondary').on('click', '.brandFocusedStock', function() {
34087 ranu 150
 
31892 tejbeer 151
		var fofoId = $(this).data('fofoid');
152
		var brand = $(this).data('brand');
153
 
31895 tejbeer 154
		doGetAjaxRequestHandler(
155
			"https://partners.smartdukaan.com" + "/getPartnerShortageStock?brand=" + brand + "&fofoId="
31892 tejbeer 156
			+ fofoId, function(response) {
157
 
158
				$('#itemWiseBrandStock .modal-content').html(response);
159
 
160
			});
161
	});
162
 
163
 
164
 
34087 ranu 165
 
166
 
167
 
168
 
31932 tejbeer 169
	$(document).on('click', ".agingDataAfterNintyDays", function() {
170
		var fofoId = $(this).data('fofoid');
171
		console.log(fofoId)
172
 
173
		doPostAjaxRequestWithJsonHandler(
174
			"https://partners.smartdukaan.com" + "/getInventoryItemAgingByFofoId?fofoId="
175
			+ fofoId, JSON.stringify([90]),
176
			function(response) {
177
				$('#agingItemWiseBrandStock .modal-content').html(response);
178
			});
179
	});
180
 
181
 
182
 
27797 tejbeer 183
	$(document).on('click', ".extend-billing", function() {
184
		var fofoId = $(this).data("fofoid");
185
		console.log(fofoId);
186
		if (confirm("Are you sure you want to extend Billing?")) {
187
			extendBilling($(this).parent(), fofoId);
188
		}
24159 tejbeer 189
 
27797 tejbeer 190
	});
24159 tejbeer 191
 
31860 tejbeer 192
	/*
193
	 * $(document).on('change', '#retailerAddressState', function() { var stateName =
194
	 * $(this).find('option:selected').text();
195
	 *
196
	 * loadDistrictNames(stateName); });
197
	 */
24159 tejbeer 198
 
199
 
27797 tejbeer 200
	$(document).on('click', "#location", function() {
201
		if ($(this).is(":checked")) {
27516 amit.gupta 202
 
27797 tejbeer 203
			$("#divLocation").show();
27516 amit.gupta 204
 
27797 tejbeer 205
		} else {
206
			$("#divLocation").hide();
207
		}
208
	});
27516 amit.gupta 209
 
210
 
27797 tejbeer 211
	$(document).on('click', ".changePartnerCategory", function() {
35459 amit 212
		$clickedElement = $(this);
27797 tejbeer 213
		var fofoId = $clickedElement.data("id");
35459 amit 214
		$tdElement = $(this).closest('td');
27797 tejbeer 215
		doGetAjaxRequestHandler(context + "/getPartnerCategory?fofoId=" + fofoId, function(response) {
27516 amit.gupta 216
 
27797 tejbeer 217
			$tdElement.html(response);
218
			$tdElement.find('.partnerCategory').multiselect({
219
				includeSelectAllOption: true,
220
				multiple: true,
221
				maxHeight: 200,
222
				buttonWidth: '180px',
223
				numberDisplayed: 1,
224
				nonSelectedText: 'Category',
225
				nSelectedText: ' - Category Selected',
226
				allSelectedText: 'All Category Selected',
227
				enableFiltering: true,
228
				enableCaseInsensitiveFiltering: true
229
			});
230
		});
231
	});
27516 amit.gupta 232
 
233
 
27797 tejbeer 234
	$(document).on('click', ".update-category",
235
		function() {
236
			var fofoId = $(this).data('fofoid');
237
			var partnerType = $('#partnerCategory').val();
35674 amit 238
			var durationMonths = $('#upgradeDuration').val();
27516 amit.gupta 239
 
35674 amit 240
			if (confirm("Are you sure you want to upgrade for " + durationMonths + " month(s)?") == true) {
27797 tejbeer 241
				doPostAjaxRequestHandler(context
242
					+ "/updatePartnerCategory?fofoId="
35674 amit 243
					+ fofoId + "&partnerType=" + partnerType + "&durationMonths=" + durationMonths, function(
27797 tejbeer 244
						response) {
245
					if (response == "true") {
246
						alert("Update successfully");
247
						storeInfo("main-content");
248
					}
249
				});
250
			}
27516 amit.gupta 251
 
27797 tejbeer 252
		});
253
 
254
 
31860 tejbeer 255
 
256
 
27797 tejbeer 257
	$(document).on('click', ".addlocationbutton",
258
		function() {
259
			var userId = $('#retailerId').text();
260
			var name = $('#personName').val();
261
			var line1 = $('#line1').val();
262
			var line2 = $('#line2').val();
263
			var city = $('#city').val();
264
			var state = $('#state').val();
265
			var pin = $('#pinCode').val();
266
 
267
			if (name === "" && line1 === "" && city === "" && pin === "") {
268
				alert("Field can't be empty");
269
				return;
270
			}
271
			if (name === "") {
272
				alert("name is required");
273
				return;
274
			}
275
			if (line1 === "") {
276
				alert("line1 is required");
277
				return;
278
			}
279
			if (city === "") {
280
				alert("city is required");
281
				return;
282
			}
283
			if (pin === "") {
284
				alert("pin is required");
285
				return;
286
			}
287
 
288
			var locationData = {};
289
			locationData['userId'] = $('#retailerId').text();
290
			locationData['name'] = $('#personName').val();
291
			locationData['line1'] = $('#line1').val();
292
			locationData['line2'] = $('#line2').val();
293
			locationData['city'] = $('#city').val();
294
			locationData['state'] = $('#state').val();
295
			locationData['pin'] = $('#pinCode').val();
296
 
297
			if (confirm("Are you sure you want to add location!") == true) {
298
				doPostAjaxRequestWithJsonHandler(context + "/addLocation",
299
					JSON.stringify(locationData), function(response) {
300
						if (response == 'true') {
301
							alert("successfully Add");
302
							$("#addLocationModal").modal('hide');
303
 
304
						}
305
					});
306
 
307
				return false;
308
			}
309
		});
310
 
32044 tejbeer 311
 
312
 
313
	//Performance
314
	$(document).on('click', ".partner-performance-access", function() {
315
		doGetAjaxRequestHandler(context + "/getPartnersForPerformance", function(response) {
316
			$('#' + "main-content").html(response);
317
		});
318
	});
319
 
320
	$(document).on('click', ".partnerPerformance", function() {
321
		var fofoId = $('#fofo-users').val();
322
		var url = context + "/partnerPerformance?fofoId=" + fofoId;
323
		//$('.partner-performance-container').html(`<iframe class="wrapper" src="${url}" style="width:100%;height:100vh"> </iframe>`); 
324
		doGetAjaxRequestHandler(context + "/partnerPerformance?fofoId=" + fofoId, function(response) {
325
			$('.partner-performance-container').html(response);
326
		});
327
	});
328
 
329
	$(document).on('click', ".retailer-filter", function() {
330
		doGetAjaxRequestHandler(context + "/getFilters", function(response) {
331
			$('#' + "main-content").html(response);
332
		});
333
	});
334
 
335
 
336
	$(document).on('click', ".filters", function() {
337
 
338
		var credit = $('#credit').is(':checked');
339
		var billing = $('#billing').is(':checked');
340
		var investment = $('#investment').is(':checked');
341
		var secondary = $('#secondary').is(':checked');
342
		var tertiary = $('#tertiary').is(':checked');
343
		var mtds = $('#mtds').is(':checked');
344
		var mtdt = $('#mtdt').is(':checked');
345
 
346
		var investmentPct = $('#investmentvalue').val();
347
		var secondaryDays = $('#secondaryvalue').val();
348
		var tertiaryDays = $('#tertiaryvalue').val();
349
		var mtdsPct = $('#mtdsvalue').val();
350
		var mtdtPct = $('#mtdtvalue').val();
351
 
352
		console.log(investmentPct)
353
 
354
 
355
 
356
		var retailerFilters = {};
357
		retailerFilters['credit'] = credit;
358
		retailerFilters['billing'] = billing
359
		if (investment) {
360
			retailerFilters['investmentPct'] = investmentPct
361
		}
362
		if (secondary) {
363
			retailerFilters['secondaryDays'] = secondaryDays
364
		}
365
		if (tertiary) {
366
			retailerFilters['tertiaryDays'] = tertiaryDays
367
		}
368
 
369
		if (mtds) {
370
			retailerFilters['mtdsPct'] = mtdsPct
371
		}
372
 
373
		if (mtdt) {
374
			retailerFilters['mtdtPct'] = mtdtPct
375
		}
376
 
32089 tejbeer 377
		console.log(JSON.stringify(retailerFilters));
378
 
32044 tejbeer 379
		doAjaxRequestWithJsonHandler(context + "/getFilteredRetailers", 'POST', JSON.stringify(retailerFilters), function(response) {
380
			$('.filtered-partner-performance-container').html(response);
381
 
382
		});
383
	});
384
 
385
 
386
 
387
	$(document).on('click', ".default-email-val", function() {
388
 
389
		var credit = $('#credit').is(':checked');
390
		var billing = $('#billing').is(':checked');
391
		var investment = $('#investment').is(':checked');
392
		var secondary = $('#secondary').is(':checked');
393
		var tertiary = $('#tertiary').is(':checked');
394
		var mtds = $('#mtds').is(':checked');
395
		var mtdt = $('#mtdt').is(':checked');
396
 
397
		var investmentPct = $('#investmentvalue').val();
398
		var secondaryDays = $('#secondaryvalue').val();
399
		var tertiaryDays = $('#tertiaryvalue').val();
400
		var mtdsPct = $('#mtdsvalue').val();
401
		var mtdtPct = $('#mtdtvalue').val();
402
 
403
		console.log(investmentPct)
404
 
405
 
406
 
407
		var retailerFilters = {};
408
		retailerFilters['credit'] = credit;
409
		retailerFilters['billing'] = billing
410
		retailerFilters['investmentPct'] = investmentPct
411
		retailerFilters['secondaryDays'] = secondaryDays
412
		retailerFilters['tertiaryDays'] = tertiaryDays
413
		retailerFilters['mtdsPct'] = mtdsPct
414
		retailerFilters['mtdtPct'] = mtdtPct
415
 
416
 
417
 
418
 
419
		doAjaxRequestWithJsonHandler(context + "/defaultFilterSetForEmail", 'POST', JSON.stringify(retailerFilters), function(response) {
420
			if (response == "true") {
421
				alert("Successfully Done")
422
			}
423
		});
424
	});
425
 
426
 
23347 ashik.ali 427
});
428
 
23837 ashik.ali 429
function getDistance(lat1, lon1, lat2, lon2) {
27797 tejbeer 430
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
431
	var cos = Math.cos;
432
	lat1 *= deg2rad;
433
	lon1 *= deg2rad;
434
	lat2 *= deg2rad;
435
	lon2 *= deg2rad;
436
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
437
	var dLat = lat2 - lat1;
438
	var dLon = lon2 - lon1;
439
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 440
 
27797 tejbeer 441
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
24125 govind 442
}
23837 ashik.ali 443
 
24125 govind 444
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
27797 tejbeer 445
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
446
		+ emailIdOrMobileNumber, function(response) {
447
			$('#' + domId).html(response);
448
			if ($("#location").is(":checked")) {
27171 tejbeer 449
 
27797 tejbeer 450
				$("#divLocation").show();
451
			}
452
		});
23347 ashik.ali 453
}
454
 
24125 govind 455
function updateRetailerDocument() {
27797 tejbeer 456
	// $("#updateRetailerShopDocument0").click( function() {
457
	console.log("Update Retailer Document Clicked");
458
	// console.log(ownerId);
459
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
460
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
461
	var file = $('#retailerDocument')[0].files[0];
462
	console.log("file : " + file.name);
463
	uploadRetailerDocument("retailer-details-container", file,
464
		emailIdOrMobileNumber);
23347 ashik.ali 465
}
466
 
24125 govind 467
function updateRetailerShopDocument(ownerId) {
27797 tejbeer 468
	// $("#updateRetailerShopDocument0").click( function() {
469
	console.log("Update Retailer Shop Document Clicked");
470
	console.log(ownerId);
471
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
472
	console.log("size : " + shopSize);
473
	for (var index = 0; index < shopSize; index++) {
474
		if ("updateRetailerShopDocument" + index == ownerId) {
475
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
476
				.val();
477
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
478
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
479
			console.log("shopId : " + shopId);
480
			var file = $('#retailerShopDocument' + index)[0].files[0];
481
			console.log("file : " + file.name);
482
			uploadRetailerShopDocument("retailer-details-container", file,
483
				emailIdOrMobileNumber, shopId);
484
		}
485
	}
23347 ashik.ali 486
}
487
 
24125 govind 488
function loadDistrictNames(stateName) {
27797 tejbeer 489
	if (undefined != $("#districtName")) {
490
		doGetAjaxRequestHandler(
491
			context + "/district/all/stateName?stateName=" + stateName,
492
			function(response) {
493
				console.log(response);
494
				var districtMasters = response.response;
495
				// districtMasters = districtMasters.response;
496
				var districtNameElements = '<option value="" disabled selected>District Name</option>';
497
				for (index = 0; index < districtMasters.length; index++) {
498
					districtNameElements = districtNameElements
499
						+ '<option value="'
500
						+ districtMasters[index].name + '">'
501
						+ districtMasters[index].name + '</option>';
502
				}
503
				$('#districtName').html(districtNameElements);
504
			});
505
	}
23347 ashik.ali 506
}
507
 
33124 ranu 508
function loadASTDetail(stateName) {
509
	doGetAjaxRequestHandler(
510
		context + "/astDetail?stateName=" + stateName,
33128 amit.gupta 511
		function (asts) {
33124 ranu 512
			$('#retailerAstId').find('option').not(':first').remove();
33128 amit.gupta 513
			for (let ast of asts) {
514
				var opt = $("<option>").val(ast.id).text(ast.area + "(" + ast.areaDescription + ")" + " - " + ast.territory + "(" + ast.territoryDescription + ")");
33124 ranu 515
				$('#retailerAstId').append(opt);
516
			}
517
		}
518
	);
519
}
520
 
24125 govind 521
function retailerInfo(domId) {
27797 tejbeer 522
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
523
		$('#' + domId).html(response);
24159 tejbeer 524
 
27797 tejbeer 525
	});
24159 tejbeer 526
 
24125 govind 527
}
27231 tejbeer 528
 
27516 amit.gupta 529
function partnerInfo(domId) {
27797 tejbeer 530
	doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function(response) {
531
		$('#' + domId).html(response);
27516 amit.gupta 532
 
27797 tejbeer 533
	});
27231 tejbeer 534
}
28071 tejbeer 535
function blockBrandMapping(domId) {
536
	doGetAjaxRequestHandler(context + "/getBlockBrandMapping", function(response) {
537
		$('#' + domId).html(response);
27516 amit.gupta 538
 
28071 tejbeer 539
	});
540
}
28272 tejbeer 541
function brandsLimit(domId) {
542
	doGetAjaxRequestHandler(context + "/getBrandslimit", function(response) {
543
		$('#' + domId).html(response);
28071 tejbeer 544
 
28272 tejbeer 545
	});
546
}
24125 govind 547
function storeInfo(domId) {
27797 tejbeer 548
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
549
		$('#' + domId).html(response);
550
	});
24125 govind 551
}
27516 amit.gupta 552
 
29268 manish 553
function store(domId) {
554
	doGetAjaxRequestHandler(context + "/getstore", function(response) {
555
		$('#' + domId).html(response);
556
	});
557
}
24680 govind 558
function inactiveStoreInfo(domId) {
27797 tejbeer 559
	doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(
560
		response) {
561
		$('#' + domId).html(response);
562
	});
24680 govind 563
}
27516 amit.gupta 564
 
28381 tejbeer 565
function allPartnerPincode(domId) {
566
	doGetAjaxRequestHandler(context + "/getAllPartnerPincode", function(
567
		response) {
568
		$('#' + domId).html(response);
569
	});
570
}
571
 
35962 amit 572
function deactivateStore(domId, fofoId, storeCode) {
27797 tejbeer 573
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
574
		function(response) {
575
			if (response == "true") {
35962 amit 576
				alert("Store marked inactive successfully!");
35982 amit 577
				storeInfo(domId);
578
				askClosureConfirmation(domId, fofoId, storeCode);
27797 tejbeer 579
			}
580
		});
24125 govind 581
}
35982 amit 582
 
583
function askClosureConfirmation(domId, fofoId, storeCode) {
37765 amit 584
	if (!confirm("Do you also want to PERMANENTLY close store " + storeCode + "? This cannot be undone.")) {
35982 amit 585
		return;
586
	}
37765 amit 587
	openStoreClosureModal(fofoId, storeCode, function() {
588
		storeInfo(domId);
589
	});
590
}
591
 
592
var STORE_CLOSURE_REASONS = [
593
	["OUTSIDE_SOURCING", "Outside / GT sourcing"],
594
	["CREDIT_DEFAULT", "SD Credit default"],
595
	["FINANCIAL_STRESS", "Financial stress"],
596
	["NON_PERFORMANCE", "Non-performance / low sales"],
597
	["SERVICE_ISSUES", "Service issues"],
598
	["PERSONAL_RELOCATION", "Partner personal / relocation"],
599
	["AGREEMENT_BREACH", "Agreement breach"],
600
	["OTHER", "Other"]
601
];
602
 
603
// Permanent closure needs a reason, a remark and the approval mail; the server re-checks all of them
604
// and mails the closure report with the approval attached.
605
function openStoreClosureModal(fofoId, storeCode, onClosed) {
606
	$('#store-closure-modal').remove();
607
	var reasonOptions = '<option value="">-- Select reason --</option>';
608
	STORE_CLOSURE_REASONS.forEach(function(reason) {
609
		reasonOptions += '<option value="' + reason[0] + '">' + reason[1] + '</option>';
610
	});
611
	var modal = $(
612
		'<div class="modal fade" id="store-closure-modal" tabindex="-1" role="dialog">' +
613
		'<div class="modal-dialog" role="document"><div class="modal-content">' +
614
		'<div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button>' +
615
		'<h4 class="modal-title">Permanently close store</h4></div>' +
616
		'<div class="modal-body">' +
617
		'<p class="text-danger">This cannot be undone. A closure report with the approval mail goes to the partner\'s Sales L2, Tarun, Kamini, Finance and you.</p>' +
618
		'<div class="form-group"><label>Reason *</label><select class="form-control closure-reason">' + reasonOptions + '</select></div>' +
619
		'<div class="form-group"><label>Remark *</label><textarea class="form-control closure-remark" rows="3" maxlength="1000"></textarea></div>' +
620
		'<div class="form-group"><label>Approval mail * <small class="text-muted">(PDF or screenshot, max 5 MB)</small></label>' +
621
		'<input type="file" class="form-control closure-approval" accept=".pdf,.png,.jpg,.jpeg"></div>' +
622
		'<div class="form-group"><label>Type the store code <b class="closure-store-code"></b> to confirm *</label>' +
623
		'<input type="text" class="form-control closure-code"></div>' +
624
		'</div>' +
625
		'<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>' +
626
		'<button type="button" class="btn btn-danger closure-submit">Close Store</button></div>' +
627
		'</div></div></div>');
628
	modal.find('.closure-store-code').text(storeCode);
629
	$('body').append(modal);
630
	modal.modal('show');
631
 
632
	modal.find('.closure-submit').on('click', function() {
633
		var reason = modal.find('.closure-reason').val();
634
		var remark = $.trim(modal.find('.closure-remark').val());
635
		var file = modal.find('.closure-approval')[0].files[0];
636
		var code = $.trim(modal.find('.closure-code').val());
637
		if (!reason) {
638
			alert("Please select the reason for closure.");
639
			return;
640
		}
641
		if (remark === "") {
642
			alert("Please enter a remark explaining the closure.");
643
			return;
644
		}
645
		if (!file) {
646
			alert("Please attach the approval mail.");
647
			return;
648
		}
649
		var rejection = uploadFileRejectionReason(file);
650
		if (rejection) {
651
			alert(rejection);
652
			return;
653
		}
654
		if (code !== storeCode) {
655
			alert("Store code does not match. Closure cancelled.");
656
			return;
657
		}
658
		var submitButton = $(this).prop('disabled', true);
659
		doAjaxUploadRequestHandler(context + '/document-upload', 'POST', file, function(uploadResponse) {
660
			var params = {
661
				fofoId: fofoId,
662
				storeCode: code,
663
				reason: reason,
664
				remark: remark,
665
				approvalDocumentId: uploadResponse.response.document_id
666
			};
667
			doPostAjaxRequestWithParamsHandler(context + '/closeStore', params, function(closeResponse) {
668
				modal.modal('hide');
669
				if (closeResponse == "true") {
670
					alert("Store permanently closed. Closure report mailed.");
671
				}
672
				if (typeof onClosed === 'function') {
673
					onClosed();
674
				}
675
			});
676
			submitButton.prop('disabled', false);
677
		}, function(xhr, msg) {
678
			submitButton.prop('disabled', false);
679
			alert("Approval mail upload failed: " + msg);
35982 amit 680
		});
37765 amit 681
	});
35982 amit 682
}
37765 amit 683
 
28711 amit.gupta 684
function activateStoreForever(domId, fofoId) {
685
	doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,
686
		function(response) {
687
			if (response == "true") {
688
				alert("successfully activated!");
689
				inactiveStoreInfo(domId);
690
			}
27516 amit.gupta 691
 
28711 amit.gupta 692
		});
693
}
694
 
24976 amit.gupta 695
function loginAsPartner(fofoId) {
27797 tejbeer 696
	doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
697
		function(response) {
35726 vikas 698
			window.location.reload();
27797 tejbeer 699
		});
24976 amit.gupta 700
}
27231 tejbeer 701
 
702
function loginAsPartnerReadonly(fofoId) {
27797 tejbeer 703
	doGetAjaxRequestHandler(context + "/login-as-partner-readonly?fofoId=" + fofoId,
704
		function(response) {
705
			window.create({
706
				"url": "/dashboard",
707
				"incognito": true
708
			});
709
		});
27231 tejbeer 710
}
27516 amit.gupta 711
 
24349 amit.gupta 712
function extendBilling(container, fofoId) {
27797 tejbeer 713
	doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
714
		function(response) {
715
			if (isFinite(response)) {
716
				alert("successfully deactivated!");
717
				container.html("Billing extended upto "
718
					+ moment().add(1, 'day').format("DD-MM-YY")
719
					+ " Grace count(" + response + ")");
720
			}
721
		});
24349 amit.gupta 722
}
24159 tejbeer 723
 
724
function updateLocationButton(id) {
725
 
27797 tejbeer 726
	var userId = id;
727
	var name = $('#personName').val();
728
	var line1 = $('#line1').val();
729
	var line2 = $('#line2').val();
730
	var city = $('#city').val();
731
	var state = $('#state').val();
732
	var pin = $('#pinCode').val();
733
	console.log(id);
734
	if (name === "" && line1 === "" && city === "" && pin === "") {
735
		alert("Field can't be empty");
736
		return;
737
	}
738
	if (name === "") {
739
		alert("name is required");
740
		return;
741
	}
742
	if (line1 === "") {
743
		alert("line1 is required");
744
		return;
745
	}
746
	if (city === "") {
747
		alert("city is required");
748
		return;
749
	}
750
	if (pin === "") {
751
		alert("pin is required");
752
		return;
753
	}
24159 tejbeer 754
 
27797 tejbeer 755
	var changeLocationData = {};
24159 tejbeer 756
 
27797 tejbeer 757
	changeLocationData['userId'] = id;
758
	changeLocationData['name'] = $('#personName').val();
759
	changeLocationData['line1'] = $('#line1').val();
760
	changeLocationData['line2'] = $('#line2').val();
761
	changeLocationData['city'] = $('#city').val();
762
	changeLocationData['state'] = $('#state').val();
763
	changeLocationData['pin'] = $('#pinCode').val();
24159 tejbeer 764
 
27797 tejbeer 765
	console.log(changeLocationData);
24159 tejbeer 766
 
27797 tejbeer 767
	if (confirm("Are you sure you want to add location!") == true) {
768
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
769
			.stringify(changeLocationData), function(response) {
770
				if (response == 'true') {
771
					alert("successfully Update");
24159 tejbeer 772
 
27797 tejbeer 773
					$("#addLocationModal").modal('hide');
24159 tejbeer 774
 
27797 tejbeer 775
				}
776
			});
24159 tejbeer 777
 
27797 tejbeer 778
		return false;
779
	}
24159 tejbeer 780
 
33814 ranu 781
}
782
 
783
$(document).on('click', ".retailer_contacts", function () {
784
	doGetAjaxRequestHandler(context + "/alternateRetailerContacts",
785
		function (response) {
786
			$('#' + 'main-content').html(response);
787
		});
788
});
789
 
790
$(document).on('click', '.get-retailer-contacts', function () {
791
 
792
	if (typeof partnerId != "undefined") {
793
		doGetAjaxRequestHandler(context + "/retailer-contact-list?fofoId=" + partnerId,
794
			function (response) {
795
				$('.retailer-contacts-container').html(response);
796
			});
797
	}
798
 
799
});
800
 
801
$(document).on('click', '.retailer-contact-submit', function () {
802
	var contactName = $('#retailer-contact-name').val();
803
	var contactNumber = $('#retailer-contact-number').val();
35648 ranu 804
	var brandName = $('#retailer-contact-brand').val();
805
	var contactType = $('#retailer-contact-type').val();
33814 ranu 806
 
807
	if (typeof partnerId != "undefined") {
35648 ranu 808
		doGetAjaxRequestHandler(context + "/add-retailer-contact-list?contactName=" + encodeURIComponent(contactName) + "&contactNumber=" + encodeURIComponent(contactNumber) + "&brandName=" + encodeURIComponent(brandName) + "&contactType=" + encodeURIComponent(contactType) + "&fofoId=" + partnerId,
33814 ranu 809
			function (response) {
810
				$('#update-retailer-contact-modal').modal('toggle');
811
				$('.retailer-contacts-container').html(response);
812
			});
813
	}
814
 
815
});
816
 
817
$(document).on('click', '.update-contact-status', function () {
818
	var contactId = $(this).data('contactid');
819
	var active = $(this).data('status');
820
 
821
	if (typeof partnerId != "undefined") {
822
		doGetAjaxRequestHandler(context + "/update-contact-status?contactId=" + contactId + "&fofoId=" + partnerId + "&active=" + active,
823
			function (response) {
824
				$('.retailer-contacts-container').html(response);
825
			});
826
	}
827
 
34425 ranu 828
});
829
 
830
// analysis dasboard js for retailer
831
 
832
$(document).on('click', '.dashboard-view', function () {
833
	var fofoId = $(this).data('fofoid');
834
 
835
	window.open(context + "/analysisDashboard?fofoId=" + fofoId, '_blank');
836
});
34813 aman 837
 
838
$('#partnerTasks').modal({
34971 aman 839
	backdrop: 'static',
840
	keyboard: false
34813 aman 841
});
842
 
843
const emailId = getCookie('emailId');
844
console.log("Email ID:", emailId);
845
 
34818 aman 846
function showModal() {
34971 aman 847
	if (emailId && emailId.endsWith('@smartdukaan.com')) {
848
		console.log('SmartDukaan user - modal not shown');
849
		return;
850
	}
34818 aman 851
	$('#partnerTasks').removeAttr('aria-hidden');
34813 aman 852
 
853
	if (!emailId || !emailId.endsWith('@smartdukaan.com')) {
854
		$('#chartData').html('<div class="loader text-center " style=" height: 30px;\n' +
855
			'    display: flex;\n' +
856
			'    justify-content: center;\n' +
857
			'    align-items: center;\n' +
858
			'    font-size: 1.5rem;\n' +
859
			'    font-weight: 200;\n' +
860
			'    color: #555;" >Loading...</div>');
861
 
35001 aman 862
		doGetAjaxRequestHandler(context + "/dashboardModal", function (response, status) {
863
			if (status === 500) {
34968 ranu 864
				return;
865
			}
34813 aman 866
			$('#chartData').html(response);
34818 aman 867
			$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 868
		});
869
	} else {
870
		$('#chartData').html('<p>No data to load</p>');
34818 aman 871
		$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 872
	}
34818 aman 873
}
874
 
875
$(document).ready(function () {
34987 aman 876
	const isAdmin = emailId && emailId.endsWith('@smartdukaan.com');
877
	console.log("user is admin?" + isAdmin)
878
	console.log("user email id?" + emailId)
879
	if (isAdmin) {
880
		console.log('Admin user - modal logic completely skipped');
34971 aman 881
		return;
882
	}
34987 aman 883
 
34818 aman 884
	const today = new Date().toDateString();
885
	const currentHour = new Date().getHours();
886
	const stored = JSON.parse(localStorage.getItem('modalData') || '{}');
887
 
888
	if (stored.date !== today) {
889
		localStorage.setItem('modalData', JSON.stringify({date: today, count: 1}));
890
		console.log('First login of day - showing modal');
891
		showModal();
892
	} else if (stored.count === 1 && currentHour >= 17) {
893
		localStorage.setItem('modalData', JSON.stringify({date: today, count: 2}));
894
		console.log('5 PM show - showing modal');
895
		showModal();
896
	} else {
897
		console.log('Modal conditions not met - not showing');
898
		$('#partnerTasks').modal('hide');
34825 aman 899
		$('.modal-backdrop').remove();
34818 aman 900
	}
34813 aman 901
});
34818 aman 902
 
34813 aman 903
$(document).on('click', '.partner-tasks-btn', function () {
34971 aman 904
	if (emailId && emailId.endsWith('@smartdukaan.com')) {
905
		console.log('SmartDukaan user - button click blocked');
906
		return;
907
	}
34813 aman 908
	doGetAjaxRequestHandler(context + "/dashboardModal", function (response) {
909
		$('#chartData').html(response);
34818 aman 910
		$('#partnerTasks').css('zoom', '125%').modal('show');
34813 aman 911
		$('#partnerTasks').modal('show');
912
	});
913
});
914
 
915
$('#partnerTasks').on('hidden.bs.modal', function () {
916
	$(this).data('modal', null);
917
	$('.modal-backdrop').remove();
918
	const bootstrapCss = document.getElementById('modal-bootstrap-css');
919
	if (bootstrapCss) {
920
		bootstrapCss.remove();
921
	}
34818 aman 922
});