Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
23343 ashik.ali 1
$(function() {
27754 amit.gupta 2
	$(document).on('click', ".create-scheme", function() {
23343 ashik.ali 3
		loadScheme("main-content");
4
	});
23752 govind 5
 
27755 amit.gupta 6
	$(document).on('click', "#schemes-paginated .next",
23752 govind 7
			function() {
26802 tejbeer 8
				var category = $('#partner-category').val();
23752 govind 9
				var searchText = $("#scheme-item-search-text").val();
26802 tejbeer 10
 
26763 tejbeer 11
				var category = $('#partner-category').val();
23752 govind 12
				if (typeof (searchText) == "undefined" || !searchText) {
13
					searchText = "";
14
				}
26802 tejbeer 15
				if (typeof (category) == "undefined" || !category) {
16
					category = "";
17
				}
23752 govind 18
 
26802 tejbeer 19
				if ((searchText) && (category)) {
20
 
23752 govind 21
					var params = {};
26802 tejbeer 22
					params['searchItem'] = currentItem.itemId;
23
					params['partnerType'] = category
24
					loadPaginatedNextItems('/getPaginatedSchemes', params,
25
							'schemes-paginated', 'schemes-table',
23752 govind 26
							'scheme-details-container');
26763 tejbeer 27
 
26802 tejbeer 28
				} else if ((searchText)) {
26763 tejbeer 29
					var params = {};
26802 tejbeer 30
					params['searchItem'] = currentItem.itemId;
31
					loadPaginatedNextItems('/getPaginatedSchemes', params,
32
							'schemes-paginated', 'schemes-table',
26763 tejbeer 33
							'scheme-details-container');
26802 tejbeer 34
 
23752 govind 35
				} else {
26912 tejbeer 36
					var params = {};
37
					params['partnerType'] = category
38
					loadPaginatedNextItems('/getPaginatedSchemes', params,
23752 govind 39
							'schemes-paginated', 'schemes-table',
40
							'scheme-details-container');
41
				}
42
				$(this).blur();
43
			});
44
 
27755 amit.gupta 45
	$(document).on('click', "#schemes-paginated .previous",
23752 govind 46
			function() {
47
				var searchText = $("#scheme-item-search-text").val();
26763 tejbeer 48
				var category = $('#partner-category').val();
23752 govind 49
				// var searchTxt=$("#scheme-search-text").val();
50
				console.log(searchText);
51
				if (typeof (searchText) == "undefined" || !searchText) {
52
					searchText = "";
53
				}
26802 tejbeer 54
				if (typeof (category) == "undefined" || !category) {
55
					category = "";
56
				}
23752 govind 57
 
26802 tejbeer 58
				console.log(searchText)
59
 
60
				if ((searchText) && (category)) {
61
 
23752 govind 62
					var params = {};
26802 tejbeer 63
					params['searchItem'] = currentItem.itemId;
64
					params['partnerType'] = category
65
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
66
							'schemes-paginated', 'schemes-table',
23752 govind 67
							'scheme-details-container');
26763 tejbeer 68
 
26802 tejbeer 69
				} else if ((searchText)) {
26763 tejbeer 70
					var params = {};
26802 tejbeer 71
					params['searchItem'] = currentItem.itemId;
72
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
73
							'schemes-paginated', 'schemes-table',
26763 tejbeer 74
							'scheme-details-container');
75
 
26802 tejbeer 76
				} else {
26912 tejbeer 77
					var params = {};
78
					params['partnerType'] = category
79
					loadPaginatedPreviousItems('/getPaginatedSchemes', params,
23752 govind 80
							'schemes-paginated', 'schemes-table',
81
							'scheme-details-container');
82
				}
83
				$(this).blur();
84
			});
85
 
27754 amit.gupta 86
	$(document).on('click', ".scheme-details", function() {
23343 ashik.ali 87
		var schemeId = $(this).attr('data');
23752 govind 88
		console.log("schemeId = " + schemeId);
23343 ashik.ali 89
		loadSchemeDetails(schemeId, "scheme-details-container");
90
	});
23752 govind 91
 
27754 amit.gupta 92
	$(document).on('click', ".active-scheme", function() {
23343 ashik.ali 93
		var schemeId = $(this).attr('data');
23752 govind 94
		console.log("active-scheme id : " + schemeId);
95
		var start = $("#schemes-paginated .start").text();
96
		// var end = $( "#schemes-paginated .end" ).text();
23343 ashik.ali 97
		var offset = start - 1;
23752 govind 98
		if (confirm("Are you sure you want to Active Scheme!") == true) {
23343 ashik.ali 99
			activeScheme(schemeId, offset, "schemes-table");
100
		}
101
	});
23752 govind 102
 
27754 amit.gupta 103
	$(document).on('click', ".expire-scheme", function() {
23343 ashik.ali 104
		var schemeId = $(this).attr('data');
25069 amit.gupta 105
		var expireDate = startDate;
23752 govind 106
		var start = $("#schemes-paginated .start").text();
107
		// var end = $( "#schemes-paginated .end" ).text();
23343 ashik.ali 108
		var offset = start - 1;
23752 govind 109
		if (confirm("Are you sure you want to Expire Scheme!") == true) {
25069 amit.gupta 110
			expireScheme(schemeId, expireDate, offset, "schemes-table");
23343 ashik.ali 111
		}
112
	});
27755 amit.gupta 113
	$(document).on('click', "#extendDatetime-button",
23914 govind 114
					function() {
115
						console.log("extendAll button click");
116
						var extendDatetime = $('input[name="extendDatetime"]')
117
								.val();
118
						console.log("extendDatetime : " + extendDatetime);
119
						if (extendDatetime) {
120
							if (confirm("Are you sure you want to Extend expireDateTime for All Scheme!") == true) {
121
								extendAllScheme(extendDatetime, "schemes-table")
122
							}
123
						} else {
124
							alert("feild can't be blank");
125
						}
126
					});
27755 amit.gupta 127
	$(document).on('click', "#extendScheme-button",
23914 govind 128
					function() {
129
						console.log("extend button click");
130
						var extendDatetime = $('input[name="extendScheme"]')
131
								.val();
132
						var schemeId = $('#schemeId').val()
133
						console.log("extendDatetime : " + extendDatetime);
134
						console.log(schemeId);
135
						if (extendDatetime) {
136
							if (confirm("Are you sure you want to Extend expireDateTime for Scheme!") == true) {
137
								extendSchemeById(schemeId)
138
							}
139
						} else {
140
							alert("feild can't be blank");
141
						}
142
					});
23752 govind 143
 
27754 amit.gupta 144
	$(document).on('click', ".schemes", function() {
23347 ashik.ali 145
		console.log("Active Schemes Button Clicked...")
27648 tejbeer 146
	  schemes("main-content");
23347 ashik.ali 147
	});
23752 govind 148
 
27754 amit.gupta 149
    $(document).on('click', ".margin-calculator", function() {
27648 tejbeer 150
		console.log("Active Schemes Button Clicked...")
151
	   marginCalculator("main-content");
152
	});
153
 
27754 amit.gupta 154
	$(document).on('click', ".schemes-download-page", function() {
23347 ashik.ali 155
		console.log("Schemes Download Clicked...")
156
		loadSchemesDownloadPage("main-content");
22860 ashik.ali 157
	});
23752 govind 158
 
27754 amit.gupta 159
	$(document).on('click', ".schemes-update", function() {
23556 amit.gupta 160
		loadSchemeUpdatePage("main-content");
161
	});
23557 amit.gupta 162
 
27754 amit.gupta 163
	$(document).on('click', ".add-item", function() {
23928 govind 164
 
165
		schemeIds = $("#schemeids").val();
166
		itemIds = $("#itemids").val();
167
		console.log(schemeIds);
168
		console.log(itemIds);
169
		if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
26763 tejbeer 170
			if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
171
				alert("fields shouldn't be blank");
172
				return;
173
			}
174
			updateSingleScheme(schemeIds, itemIds);
23928 govind 175
		}
176
	});
27754 amit.gupta 177
	$(document).on('click', ".add-schemes", function() {
23752 govind 178
 
23557 amit.gupta 179
		schemeIds = $("#schemeids").val();
180
		itemIds = $("#itemids").val();
23914 govind 181
		console.log(schemeIds);
182
		console.log(itemIds);
183
		if (confirm("Are you sure you want to Add Item to Scheme!") == true) {
26763 tejbeer 184
			if (itemIds.trim().length === 0 || schemeIds.trim().length === 0) {
185
				alert("fields shouldn't be blank");
186
				return;
187
			}
188
			updateSchemes(schemeIds, itemIds);
23557 amit.gupta 189
		}
190
	});
27754 amit.gupta 191
	$(document).on('click', ".delete-schemes", function() {
23819 govind 192
		if (confirm("Are you sure you want to delete Scheme!") == true) {
23914 govind 193
			schemeId = $(this).data('schemeid');
194
			itemId = $(this).data('itemid');
195
			console.log(schemeId);
196
			console.log(itemId);
197
			deleteScheme(schemeId, itemId);
23715 govind 198
		}
23752 govind 199
	});
200
 
27755 amit.gupta 201
	$(document).on('click', "#scheme-search-button",
26802 tejbeer 202
			function() {
203
				var searchText = $("#scheme-search-text").val();
204
				if (typeof (searchText) == "undefined" || !searchText) {
205
					searchText = "";
206
				}
207
				doGetAjaxRequestHandler(context + "/getSchemes/?searchTerm="
208
						+ searchText, function(response) {
209
					$('#' + "main-content").html(response);
210
				});
211
			});
212
 
27754 amit.gupta 213
	$(document).on("keyup", "#scheme-search-text", function(e) {
23752 govind 214
		var keyCode = e.keyCode || e.which;
215
		if (keyCode == 13) {
216
			$("#scheme-search-button").click();
217
		}
218
	});
27754 amit.gupta 219
	$(document).on('click', "#scheme-item-search-button", function() {
23752 govind 220
		var searchText = $("#scheme-item-search-text").val();
221
		if (typeof (searchText) == "undefined" || !searchText) {
222
			searchText = "";
26497 amit.gupta 223
			alert("please select item");
224
			return;
23752 govind 225
		}
27094 tejbeer 226
		if (typeof currentItem != "undefined") {
227
			console.log(currentItem);
228
			loadSchemeItemSearchInfo(currentItem);
229
		} else {
230
			console.log("reeffff")
231
			alert("Data No Found")
232
		}
233
 
23752 govind 234
	});
235
 
27755 amit.gupta 236
	$(document).on('click', ".categoryWiseSchemeHistory",
26763 tejbeer 237
			function() {
238
				var category = $('#partner-category').val();
239
				console.log(category);
240
 
26912 tejbeer 241
				doGetAjaxRequestHandler(context + "/getSchemes?partnerType="
26802 tejbeer 242
						+ category, function(response) {
243
					$('#' + "main-content").html(response);
244
					$('#partner-category').val(category);
245
					window.dispatchEvent(new Event('resize'));
246
				});
26763 tejbeer 247
 
248
			});
249
 
27754 amit.gupta 250
	$(document).on("keyup", "#scheme-item-search-text", function(e) {
23752 govind 251
		var keyCode = e.keyCode || e.which;
252
		if (keyCode == 13) {
253
			$("#scheme-item-search-button").click();
254
		}
255
	});
22860 ashik.ali 256
});
257
 
23752 govind 258
function configureTagListingItemsDescriptionDropDown() {
23347 ashik.ali 259
	$(document).ready(function() {
27798 amit.gupta 260
		$('.tagListingItemsDescription').multiselect({
23752 govind 261
			includeSelectAllOption : true,
262
			maxHeight : 200,
263
			buttonWidth : '180px',
264
			numberDisplayed : 1,
265
			nonSelectedText : 'Items',
266
			nSelectedText : ' - Items Selected',
267
			allSelectedText : 'All Items Selected',
268
			enableFiltering : true,
269
			enableCaseInsensitiveFiltering : true
270
 
271
		});
272
	});
23343 ashik.ali 273
}
274
 
23752 govind 275
function schemesDownload() {
23343 ashik.ali 276
	console.log("downloadItemLedgerReport Button clicked")
23914 govind 277
	var startDateTime = $('input[name="startDateTime"]').val();
278
	console.log("startDateTime : " + startDateTime);
279
	var endDateTime = $('input[name="endDateTime"]').val();
280
	console.log("endDateTime : " + endDateTime);
23752 govind 281
	doAjaxGetDownload(context + "/schemes/download?startDateTime="
23914 govind 282
			+ startDateTime + "&endDateTime=" + endDateTime,
23347 ashik.ali 283
			"SchemesReport.xlsx");
23343 ashik.ali 284
}
23914 govind 285
function selectedbrand() {
286
	var brands = $('#tag-listing-brands').val();
287
	console.log(brands);
288
	if (brands) {
289
		loadTagListingItemsDescriptionByBrand(
290
				"tag-listing-items-description-container", brands);
291
	}
292
}
23752 govind 293
function loadSchemeDetails(schemeId, domId) {
294
	doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
295
			function(response) {
296
				$('#' + domId).html(response);
297
				window.dispatchEvent(new Event('resize'));
298
			});
23343 ashik.ali 299
}
300
 
23752 govind 301
function activeScheme(schemeId, offset, domId) {
302
	doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
303
			+ "&offset=" + offset, function(response) {
23343 ashik.ali 304
		$('#' + domId).html(response);
305
		$('#scheme-details-container').html('');
306
	});
23752 govind 307
 
23343 ashik.ali 308
}
309
 
25069 amit.gupta 310
function expireScheme(schemeId, expireDate, offset, domId) {
23752 govind 311
	doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
26763 tejbeer 312
			+ "&offset=" + offset + "&expireTimestamp=" + expireDate, function(
313
			response) {
314
		alert("Scheme - " + schemeId + " marked for expiry successfully!");
23343 ashik.ali 315
		$('#' + domId).html(response);
316
		$('#scheme-details-container').html('');
317
	});
318
}
23914 govind 319
function extendAllScheme(domId) {
26763 tejbeer 320
	doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
321
			.stringify(startDate), function(response) {
23914 govind 322
		if (response == 'true') {
323
			alert("Scheme All Extended successfully");
324
			schemes("main-content");
325
		} else {
326
			alert("No scheme Activated Currently");
327
			schemes("main-content");
328
		}
329
	});
23343 ashik.ali 330
 
23914 govind 331
}
332
function extendSchemeById(schemeId) {
26763 tejbeer 333
	doPostAjaxRequestWithJsonHandler(context + "/extendSchemeById?schemeId="
334
			+ schemeId, JSON.stringify(startDate), function(response) {
23914 govind 335
		if (response == 'true') {
336
			alert("Scheme extended successfully");
337
			schemes("main-content");
338
		} else {
339
			alert("Scheme already Expired");
340
			schemes("main-content");
341
		}
342
	});
343
 
344
}
345
 
23752 govind 346
function loadScheme(domId) {
347
	doGetAjaxRequestHandler(context + "/createScheme", function(response) {
23343 ashik.ali 348
		$('#' + domId).html(response);
349
	});
23752 govind 350
 
23343 ashik.ali 351
}
352
 
23914 govind 353
function loadTagListingItemsDescriptionByBrand(domId, brands) {
354
	doPostAjaxRequestWithJsonHandler(context + '/getTagListingItemsByBrand',
355
			JSON.stringify(brands), function(response) {
356
				$('#' + domId).html(response);
357
				configureTagListingItemsDescriptionDropDown();
358
			});
23752 govind 359
 
23343 ashik.ali 360
}
361
 
23752 govind 362
function schemes(domId) {
363
	doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
23343 ashik.ali 364
		$('#' + domId).html(response);
365
	});
366
}
27648 tejbeer 367
function marginCalculator(domId) {
368
	doGetAjaxRequestHandler(context + "/getMarginCalculator", function(response) {
369
		$('#' + domId).html(response);
370
	});
371
}
23343 ashik.ali 372
 
23752 govind 373
function loadSchemesDownloadPage(domId) {
374
	doGetAjaxRequestHandler(context + "/schemes/downloadPage", function(
375
			response) {
23343 ashik.ali 376
		$('#' + domId).html(response);
377
	});
23556 amit.gupta 378
}
379
 
23752 govind 380
function loadSchemeUpdatePage(domId) {
381
	doGetAjaxRequestHandler(context + "/schemes/update-schemes-page", function(
382
			response) {
23556 amit.gupta 383
		$('#' + domId).html(response);
384
	});
23557 amit.gupta 385
}
386
 
23928 govind 387
function updateSingleScheme(shcemeIds, itemIds) {
388
	doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
23752 govind 389
			.stringify({
390
				"itemIds" : itemIds.split(",").map(Number),
391
				"schemeIds" : schemeIds.split(",").map(Number)
392
			}), function(response) {
26763 tejbeer 393
		if (response == 'true') {
23914 govind 394
			alert("Item Added to scheme successfully");
395
			// $('#newItemToSchemeModal').modal('hide');
396
			loadSchemeDetails(shcemeIds, "scheme-details-container");
397
		} else {
398
			alert("Item already present");
399
			loadSchemeDetails(shcemeIds, "scheme-details-container");
23557 amit.gupta 400
		}
401
	});
23715 govind 402
}
23928 govind 403
function updateSchemes(shcemeIds, itemIds) {
404
	doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
405
			.stringify({
406
				"itemIds" : itemIds.split(",").map(Number),
407
				"schemeIds" : schemeIds.split(",").map(Number)
408
			}), function(response) {
409
		if (response == 'true') {
410
			alert("Item Added to scheme successfully");
411
			// $('#newItemToSchemeModal').modal('hide');
412
			loadSchemeUpdatePage("main-content");
26763 tejbeer 413
		}
23928 govind 414
	});
415
}
23914 govind 416
function deleteScheme(shcemeId, itemId) {
417
	doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + shcemeId
418
			+ "&itemId=" + itemId, function(response) {
23752 govind 419
		if (response == 'true') {
23914 govind 420
			alert("ItemId Deleted successfully from Scheme");
421
			loadSchemeDetails(shcemeId, "scheme-details-container");
23715 govind 422
		}
423
	});
23752 govind 424
}
425
function loadSearchScheme(domId, search_text) {
426
	doGetAjaxRequestHandler(context + "/searchScheme/?searchTerm="
427
			+ search_text, function(response) {
428
		$('#' + domId).html(response);
429
	});
430
}
26497 amit.gupta 431
function loadSearchItemScheme(domId, selected_item) {
26802 tejbeer 432
	var category = $('#partner-category').val();
433
	var searchText = $("#scheme-item-search-text").val();
26763 tejbeer 434
 
26802 tejbeer 435
	var category = $('#partner-category').val();
26912 tejbeer 436
 
437
	console.log(category)
438
 
26802 tejbeer 439
	if (typeof (searchText) == "undefined" || !searchText) {
440
		searchText = "";
441
	}
442
	if (typeof (category) == "undefined" || !category) {
443
		category = "";
444
	}
445
	if ((searchText) && (category)) {
446
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
447
				+ selected_item.itemId + "&partnerType=" + category, function(
448
				response) {
449
			$('#' + domId).html(response);
450
			$('#partner-category').val(category);
451
			$('#scheme-item-search-text').val(selected_item.itemDescription);
452
 
453
		});
26912 tejbeer 454
	} else if ((searchText)) {
26802 tejbeer 455
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
456
				+ selected_item.itemId, function(response) {
457
			$('#' + domId).html(response);
458
			$('#scheme-item-search-text').val(selected_item.itemDescription);
459
 
460
		});
26912 tejbeer 461
 
462
	}
463
 
23752 govind 464
}
465
function loadSchemeSearchInfo(search_text) {
466
	loadSearchScheme("main-content", search_text);
467
}
26497 amit.gupta 468
function loadSchemeItemSearchInfo(selectedItem) {
469
	loadSearchItemScheme("main-content", selectedItem);
23914 govind 470
}