Subversion Repositories SmartDukaan

Rev

Rev 29268 | Rev 31892 | 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() {
4
		searchContent = $("#retailer-details-search-text").val();
5
		if (typeof (searchContent) == "undefined" || !searchContent) {
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);
106
						for (let city of response.response.cities) {
107
							var opt = $("<option>").val(city).text(city);
108
							$('#retailerAddressCity').append(opt);
24349 amit.gupta 109
 
27797 tejbeer 110
						}
24159 tejbeer 111
 
27797 tejbeer 112
					});
113
			}
114
		});
24159 tejbeer 115
 
27797 tejbeer 116
	$(document).on("keyup", "#retailer-details-search-text", function(e) {
117
		var keyCode = e.keyCode || e.which;
118
		if (keyCode == 13) {
119
			$("#retailer-details-search-button").click();
120
		}
121
	});
24159 tejbeer 122
 
27797 tejbeer 123
	$(document).on('click', ".deactivate-store", function() {
124
		var fofoId = $(this).data("fofoid");
125
		console.log(fofoId);
126
		if (confirm("Are you sure you want to deactivate store!") == true) {
127
			deactivateStore("main-content", fofoId);
128
		}
27171 tejbeer 129
 
27797 tejbeer 130
	});
28711 amit.gupta 131
	$(document).on('click', ".activate-store-forever", function() {
132
		var fofoId = $(this).data("fofoid");
133
		console.log(fofoId);
134
		if (confirm("Are you sure you want to activate this store!") == true) {
135
			activateStoreForever("main-content", fofoId);
136
		}
137
 
138
	});
31860 tejbeer 139
 
27797 tejbeer 140
	$(document).on('click', ".login_as", function() {
141
		var fofoId = $('#partnerId').val();
142
		loginAsPartner(fofoId);
24159 tejbeer 143
 
27797 tejbeer 144
	});
31860 tejbeer 145
	$(document).on('click', ".partner-performance-access", function() {
24159 tejbeer 146
 
31860 tejbeer 147
 
148
		doGetAjaxRequestHandler(context + "/getPartnersForPerformance", function(response) {
149
			$('#' + "main-content").html(response);
150
		});
151
	});
152
 
153
	$(document).on('click', ".partnerPerformance", function() {
154
		var fofoId = $('#fofo-users').val();
155
 
156
		var url = context + "/partnerPerformance?fofoId=" + fofoId;
157
 
158
 
159
		$('.partner-performance-container').html(`<iframe class="wrapper" src="${url}" style="width:100%;height:100vh"> </iframe>`);
160
 
161
	});
27797 tejbeer 162
	$(document).on('click', ".extend-billing", function() {
163
		var fofoId = $(this).data("fofoid");
164
		console.log(fofoId);
165
		if (confirm("Are you sure you want to extend Billing?")) {
166
			extendBilling($(this).parent(), fofoId);
167
		}
24159 tejbeer 168
 
27797 tejbeer 169
	});
24159 tejbeer 170
 
31860 tejbeer 171
	/*
172
	 * $(document).on('change', '#retailerAddressState', function() { var stateName =
173
	 * $(this).find('option:selected').text();
174
	 *
175
	 * loadDistrictNames(stateName); });
176
	 */
24159 tejbeer 177
 
178
 
27797 tejbeer 179
	$(document).on('click', "#location", function() {
180
		if ($(this).is(":checked")) {
27516 amit.gupta 181
 
27797 tejbeer 182
			$("#divLocation").show();
27516 amit.gupta 183
 
27797 tejbeer 184
		} else {
185
			$("#divLocation").hide();
186
		}
187
	});
27516 amit.gupta 188
 
189
 
27797 tejbeer 190
	$(document).on('click', ".changePartnerCategory", function() {
191
		$clickedElement = $(this);
192
		var fofoId = $clickedElement.data("id");
193
		$tdElement = $(this).closest('td');
194
		doGetAjaxRequestHandler(context + "/getPartnerCategory?fofoId=" + fofoId, function(response) {
27516 amit.gupta 195
 
27797 tejbeer 196
			$tdElement.html(response);
197
			$tdElement.find('.partnerCategory').multiselect({
198
				includeSelectAllOption: true,
199
				multiple: true,
200
				maxHeight: 200,
201
				buttonWidth: '180px',
202
				numberDisplayed: 1,
203
				nonSelectedText: 'Category',
204
				nSelectedText: ' - Category Selected',
205
				allSelectedText: 'All Category Selected',
206
				enableFiltering: true,
207
				enableCaseInsensitiveFiltering: true
208
			});
209
		});
210
	});
27516 amit.gupta 211
 
212
 
27797 tejbeer 213
	$(document).on('click', ".update-category",
214
		function() {
215
			var fofoId = $(this).data('fofoid');
216
			var partnerType = $('#partnerCategory').val();
27516 amit.gupta 217
 
27797 tejbeer 218
			if (confirm("Are you sure you want to update the partners!") == true) {
219
				doPostAjaxRequestHandler(context
220
					+ "/updatePartnerCategory?fofoId="
221
					+ fofoId + "&partnerType=" + partnerType, function(
222
						response) {
223
					if (response == "true") {
224
						alert("Update successfully");
225
						storeInfo("main-content");
226
					}
227
				});
228
			}
27516 amit.gupta 229
 
27797 tejbeer 230
		});
231
 
232
 
31860 tejbeer 233
 
234
 
27797 tejbeer 235
	$(document).on('click', ".addlocationbutton",
236
		function() {
237
			var userId = $('#retailerId').text();
238
			var name = $('#personName').val();
239
			var line1 = $('#line1').val();
240
			var line2 = $('#line2').val();
241
			var city = $('#city').val();
242
			var state = $('#state').val();
243
			var pin = $('#pinCode').val();
244
 
245
			if (name === "" && line1 === "" && city === "" && pin === "") {
246
				alert("Field can't be empty");
247
				return;
248
			}
249
			if (name === "") {
250
				alert("name is required");
251
				return;
252
			}
253
			if (line1 === "") {
254
				alert("line1 is required");
255
				return;
256
			}
257
			if (city === "") {
258
				alert("city is required");
259
				return;
260
			}
261
			if (pin === "") {
262
				alert("pin is required");
263
				return;
264
			}
265
 
266
			var locationData = {};
267
			locationData['userId'] = $('#retailerId').text();
268
			locationData['name'] = $('#personName').val();
269
			locationData['line1'] = $('#line1').val();
270
			locationData['line2'] = $('#line2').val();
271
			locationData['city'] = $('#city').val();
272
			locationData['state'] = $('#state').val();
273
			locationData['pin'] = $('#pinCode').val();
274
 
275
			if (confirm("Are you sure you want to add location!") == true) {
276
				doPostAjaxRequestWithJsonHandler(context + "/addLocation",
277
					JSON.stringify(locationData), function(response) {
278
						if (response == 'true') {
279
							alert("successfully Add");
280
							$("#addLocationModal").modal('hide');
281
 
282
						}
283
					});
284
 
285
				return false;
286
			}
287
		});
288
 
23347 ashik.ali 289
});
290
 
23837 ashik.ali 291
function getDistance(lat1, lon1, lat2, lon2) {
27797 tejbeer 292
	var deg2rad = 0.017453292519943295; // === Math.PI / 180
293
	var cos = Math.cos;
294
	lat1 *= deg2rad;
295
	lon1 *= deg2rad;
296
	lat2 *= deg2rad;
297
	lon2 *= deg2rad;
298
	var diam = 12742; // Diameter of the earth in km (2 * 6371)
299
	var dLat = lat2 - lat1;
300
	var dLon = lon2 - lon1;
301
	var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;
23837 ashik.ali 302
 
27797 tejbeer 303
	return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);
24125 govind 304
}
23837 ashik.ali 305
 
24125 govind 306
function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {
27797 tejbeer 307
	doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="
308
		+ emailIdOrMobileNumber, function(response) {
309
			$('#' + domId).html(response);
310
			if ($("#location").is(":checked")) {
27171 tejbeer 311
 
27797 tejbeer 312
				$("#divLocation").show();
313
			}
314
		});
23347 ashik.ali 315
}
316
 
24125 govind 317
function updateRetailerDocument() {
27797 tejbeer 318
	// $("#updateRetailerShopDocument0").click( function() {
319
	console.log("Update Retailer Document Clicked");
320
	// console.log(ownerId);
321
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
322
	console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
323
	var file = $('#retailerDocument')[0].files[0];
324
	console.log("file : " + file.name);
325
	uploadRetailerDocument("retailer-details-container", file,
326
		emailIdOrMobileNumber);
23347 ashik.ali 327
}
328
 
24125 govind 329
function updateRetailerShopDocument(ownerId) {
27797 tejbeer 330
	// $("#updateRetailerShopDocument0").click( function() {
331
	console.log("Update Retailer Shop Document Clicked");
332
	console.log(ownerId);
333
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
334
	console.log("size : " + shopSize);
335
	for (var index = 0; index < shopSize; index++) {
336
		if ("updateRetailerShopDocument" + index == ownerId) {
337
			var emailIdOrMobileNumber = $('#retailer-details-search-text')
338
				.val();
339
			console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);
340
			var shopId = $('#retailerShopDocument' + index).attr("shopId");
341
			console.log("shopId : " + shopId);
342
			var file = $('#retailerShopDocument' + index)[0].files[0];
343
			console.log("file : " + file.name);
344
			uploadRetailerShopDocument("retailer-details-container", file,
345
				emailIdOrMobileNumber, shopId);
346
		}
347
	}
23347 ashik.ali 348
}
349
 
24125 govind 350
function loadDistrictNames(stateName) {
27797 tejbeer 351
	if (undefined != $("#districtName")) {
352
		doGetAjaxRequestHandler(
353
			context + "/district/all/stateName?stateName=" + stateName,
354
			function(response) {
355
				console.log(response);
356
				var districtMasters = response.response;
357
				// districtMasters = districtMasters.response;
358
				var districtNameElements = '<option value="" disabled selected>District Name</option>';
359
				for (index = 0; index < districtMasters.length; index++) {
360
					districtNameElements = districtNameElements
361
						+ '<option value="'
362
						+ districtMasters[index].name + '">'
363
						+ districtMasters[index].name + '</option>';
364
				}
365
				$('#districtName').html(districtNameElements);
366
			});
367
	}
23347 ashik.ali 368
}
369
 
24125 govind 370
function retailerInfo(domId) {
27797 tejbeer 371
	doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {
372
		$('#' + domId).html(response);
24159 tejbeer 373
 
27797 tejbeer 374
	});
24159 tejbeer 375
 
24125 govind 376
}
27231 tejbeer 377
 
27516 amit.gupta 378
function partnerInfo(domId) {
27797 tejbeer 379
	doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function(response) {
380
		$('#' + domId).html(response);
27516 amit.gupta 381
 
27797 tejbeer 382
	});
27231 tejbeer 383
}
28071 tejbeer 384
function blockBrandMapping(domId) {
385
	doGetAjaxRequestHandler(context + "/getBlockBrandMapping", function(response) {
386
		$('#' + domId).html(response);
27516 amit.gupta 387
 
28071 tejbeer 388
	});
389
}
28272 tejbeer 390
function brandsLimit(domId) {
391
	doGetAjaxRequestHandler(context + "/getBrandslimit", function(response) {
392
		$('#' + domId).html(response);
28071 tejbeer 393
 
28272 tejbeer 394
	});
395
}
24125 govind 396
function storeInfo(domId) {
27797 tejbeer 397
	doGetAjaxRequestHandler(context + "/getAllStores", function(response) {
398
		$('#' + domId).html(response);
399
	});
24125 govind 400
}
27516 amit.gupta 401
 
29268 manish 402
function store(domId) {
403
	doGetAjaxRequestHandler(context + "/getstore", function(response) {
404
		$('#' + domId).html(response);
405
	});
406
}
24680 govind 407
function inactiveStoreInfo(domId) {
27797 tejbeer 408
	doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(
409
		response) {
410
		$('#' + domId).html(response);
411
	});
24680 govind 412
}
27516 amit.gupta 413
 
28381 tejbeer 414
function allPartnerPincode(domId) {
415
	doGetAjaxRequestHandler(context + "/getAllPartnerPincode", function(
416
		response) {
417
		$('#' + domId).html(response);
418
	});
419
}
420
 
24125 govind 421
function deactivateStore(domId, fofoId) {
27797 tejbeer 422
	doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
423
		function(response) {
424
			if (response == "true") {
425
				alert("successfully deactivated!");
426
				storeInfo(domId);
427
			}
24159 tejbeer 428
 
27797 tejbeer 429
		});
24125 govind 430
}
28711 amit.gupta 431
function activateStoreForever(domId, fofoId) {
432
	doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,
433
		function(response) {
434
			if (response == "true") {
435
				alert("successfully activated!");
436
				inactiveStoreInfo(domId);
437
			}
27516 amit.gupta 438
 
28711 amit.gupta 439
		});
440
}
441
 
24976 amit.gupta 442
function loginAsPartner(fofoId) {
27797 tejbeer 443
	doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
444
		function(response) {
445
			window.create({
446
				"url": "/dashboard",
447
				"incognito": true
448
			});
31860 tejbeer 449
 
27797 tejbeer 450
		});
24976 amit.gupta 451
}
27231 tejbeer 452
 
453
function loginAsPartnerReadonly(fofoId) {
27797 tejbeer 454
	doGetAjaxRequestHandler(context + "/login-as-partner-readonly?fofoId=" + fofoId,
455
		function(response) {
456
			window.create({
457
				"url": "/dashboard",
458
				"incognito": true
459
			});
460
		});
27231 tejbeer 461
}
27516 amit.gupta 462
 
24349 amit.gupta 463
function extendBilling(container, fofoId) {
27797 tejbeer 464
	doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,
465
		function(response) {
466
			if (isFinite(response)) {
467
				alert("successfully deactivated!");
468
				container.html("Billing extended upto "
469
					+ moment().add(1, 'day').format("DD-MM-YY")
470
					+ " Grace count(" + response + ")");
471
			}
472
		});
24349 amit.gupta 473
}
24159 tejbeer 474
 
475
function updateLocationButton(id) {
476
 
27797 tejbeer 477
	var userId = id;
478
	var name = $('#personName').val();
479
	var line1 = $('#line1').val();
480
	var line2 = $('#line2').val();
481
	var city = $('#city').val();
482
	var state = $('#state').val();
483
	var pin = $('#pinCode').val();
484
	console.log(id);
485
	if (name === "" && line1 === "" && city === "" && pin === "") {
486
		alert("Field can't be empty");
487
		return;
488
	}
489
	if (name === "") {
490
		alert("name is required");
491
		return;
492
	}
493
	if (line1 === "") {
494
		alert("line1 is required");
495
		return;
496
	}
497
	if (city === "") {
498
		alert("city is required");
499
		return;
500
	}
501
	if (pin === "") {
502
		alert("pin is required");
503
		return;
504
	}
24159 tejbeer 505
 
27797 tejbeer 506
	var changeLocationData = {};
24159 tejbeer 507
 
27797 tejbeer 508
	changeLocationData['userId'] = id;
509
	changeLocationData['name'] = $('#personName').val();
510
	changeLocationData['line1'] = $('#line1').val();
511
	changeLocationData['line2'] = $('#line2').val();
512
	changeLocationData['city'] = $('#city').val();
513
	changeLocationData['state'] = $('#state').val();
514
	changeLocationData['pin'] = $('#pinCode').val();
24159 tejbeer 515
 
27797 tejbeer 516
	console.log(changeLocationData);
24159 tejbeer 517
 
27797 tejbeer 518
	if (confirm("Are you sure you want to add location!") == true) {
519
		doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON
520
			.stringify(changeLocationData), function(response) {
521
				if (response == 'true') {
522
					alert("successfully Update");
24159 tejbeer 523
 
27797 tejbeer 524
					$("#addLocationModal").modal('hide');
24159 tejbeer 525
 
27797 tejbeer 526
				}
527
			});
24159 tejbeer 528
 
27797 tejbeer 529
		return false;
530
	}
24159 tejbeer 531
 
532
}