Subversion Repositories SmartDukaan

Rev

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