Subversion Repositories SmartDukaan

Rev

Rev 27798 | Rev 27801 | 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() {
27798 amit.gupta 259
		$('.tagListingItemsDescription').multiselect({
23752 govind 260
			includeSelectAllOption : true,
261
			maxHeight : 200,
262
			buttonWidth : '180px',
263
			numberDisplayed : 1,
264
			nonSelectedText : 'Items',
265
			nSelectedText : ' - Items Selected',
266
			allSelectedText : 'All Items Selected',
267
			enableFiltering : true,
268
			enableCaseInsensitiveFiltering : true
269
	});
23343 ashik.ali 270
}
271
 
23752 govind 272
function schemesDownload() {
23343 ashik.ali 273
	console.log("downloadItemLedgerReport Button clicked")
23914 govind 274
	var startDateTime = $('input[name="startDateTime"]').val();
275
	console.log("startDateTime : " + startDateTime);
276
	var endDateTime = $('input[name="endDateTime"]').val();
277
	console.log("endDateTime : " + endDateTime);
23752 govind 278
	doAjaxGetDownload(context + "/schemes/download?startDateTime="
23914 govind 279
			+ startDateTime + "&endDateTime=" + endDateTime,
23347 ashik.ali 280
			"SchemesReport.xlsx");
23343 ashik.ali 281
}
23914 govind 282
function selectedbrand() {
283
	var brands = $('#tag-listing-brands').val();
284
	console.log(brands);
285
	if (brands) {
286
		loadTagListingItemsDescriptionByBrand(
287
				"tag-listing-items-description-container", brands);
288
	}
289
}
23752 govind 290
function loadSchemeDetails(schemeId, domId) {
291
	doGetAjaxRequestHandler(context + "/getSchemeById?schemeId=" + schemeId,
292
			function(response) {
293
				$('#' + domId).html(response);
294
				window.dispatchEvent(new Event('resize'));
295
			});
23343 ashik.ali 296
}
297
 
23752 govind 298
function activeScheme(schemeId, offset, domId) {
299
	doPutAjaxRequestHandler(context + "/activeSchemeById?schemeId=" + schemeId
300
			+ "&offset=" + offset, function(response) {
23343 ashik.ali 301
		$('#' + domId).html(response);
302
		$('#scheme-details-container').html('');
303
	});
23752 govind 304
 
23343 ashik.ali 305
}
306
 
25069 amit.gupta 307
function expireScheme(schemeId, expireDate, offset, domId) {
23752 govind 308
	doPutAjaxRequestHandler(context + "/expireSchemeById?schemeId=" + schemeId
26763 tejbeer 309
			+ "&offset=" + offset + "&expireTimestamp=" + expireDate, function(
310
			response) {
311
		alert("Scheme - " + schemeId + " marked for expiry successfully!");
23343 ashik.ali 312
		$('#' + domId).html(response);
313
		$('#scheme-details-container').html('');
314
	});
315
}
23914 govind 316
function extendAllScheme(domId) {
26763 tejbeer 317
	doPostAjaxRequestWithJsonHandler(context + "/extendAllSchemes", JSON
318
			.stringify(startDate), function(response) {
23914 govind 319
		if (response == 'true') {
320
			alert("Scheme All Extended successfully");
321
			schemes("main-content");
322
		} else {
323
			alert("No scheme Activated Currently");
324
			schemes("main-content");
325
		}
326
	});
23343 ashik.ali 327
 
23914 govind 328
}
329
function extendSchemeById(schemeId) {
26763 tejbeer 330
	doPostAjaxRequestWithJsonHandler(context + "/extendSchemeById?schemeId="
331
			+ schemeId, JSON.stringify(startDate), function(response) {
23914 govind 332
		if (response == 'true') {
333
			alert("Scheme extended successfully");
334
			schemes("main-content");
335
		} else {
336
			alert("Scheme already Expired");
337
			schemes("main-content");
338
		}
339
	});
340
 
341
}
342
 
23752 govind 343
function loadScheme(domId) {
344
	doGetAjaxRequestHandler(context + "/createScheme", function(response) {
23343 ashik.ali 345
		$('#' + domId).html(response);
346
	});
23752 govind 347
 
23343 ashik.ali 348
}
349
 
23914 govind 350
function loadTagListingItemsDescriptionByBrand(domId, brands) {
351
	doPostAjaxRequestWithJsonHandler(context + '/getTagListingItemsByBrand',
352
			JSON.stringify(brands), function(response) {
353
				$('#' + domId).html(response);
354
				configureTagListingItemsDescriptionDropDown();
355
			});
23752 govind 356
 
23343 ashik.ali 357
}
358
 
23752 govind 359
function schemes(domId) {
360
	doGetAjaxRequestHandler(context + "/getSchemes", function(response) {
23343 ashik.ali 361
		$('#' + domId).html(response);
362
	});
363
}
27648 tejbeer 364
function marginCalculator(domId) {
365
	doGetAjaxRequestHandler(context + "/getMarginCalculator", function(response) {
366
		$('#' + domId).html(response);
367
	});
368
}
23343 ashik.ali 369
 
23752 govind 370
function loadSchemesDownloadPage(domId) {
371
	doGetAjaxRequestHandler(context + "/schemes/downloadPage", function(
372
			response) {
23343 ashik.ali 373
		$('#' + domId).html(response);
374
	});
23556 amit.gupta 375
}
376
 
23752 govind 377
function loadSchemeUpdatePage(domId) {
378
	doGetAjaxRequestHandler(context + "/schemes/update-schemes-page", function(
379
			response) {
23556 amit.gupta 380
		$('#' + domId).html(response);
381
	});
23557 amit.gupta 382
}
383
 
23928 govind 384
function updateSingleScheme(shcemeIds, itemIds) {
385
	doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
23752 govind 386
			.stringify({
387
				"itemIds" : itemIds.split(",").map(Number),
388
				"schemeIds" : schemeIds.split(",").map(Number)
389
			}), function(response) {
26763 tejbeer 390
		if (response == 'true') {
23914 govind 391
			alert("Item Added to scheme successfully");
392
			// $('#newItemToSchemeModal').modal('hide');
393
			loadSchemeDetails(shcemeIds, "scheme-details-container");
394
		} else {
395
			alert("Item already present");
396
			loadSchemeDetails(shcemeIds, "scheme-details-container");
23557 amit.gupta 397
		}
398
	});
23715 govind 399
}
23928 govind 400
function updateSchemes(shcemeIds, itemIds) {
401
	doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
402
			.stringify({
403
				"itemIds" : itemIds.split(",").map(Number),
404
				"schemeIds" : schemeIds.split(",").map(Number)
405
			}), function(response) {
406
		if (response == 'true') {
407
			alert("Item Added to scheme successfully");
408
			// $('#newItemToSchemeModal').modal('hide');
409
			loadSchemeUpdatePage("main-content");
26763 tejbeer 410
		}
23928 govind 411
	});
412
}
23914 govind 413
function deleteScheme(shcemeId, itemId) {
414
	doDeleteAjaxRequestHandler(context + "/schemes/delete?schemeId=" + shcemeId
415
			+ "&itemId=" + itemId, function(response) {
23752 govind 416
		if (response == 'true') {
23914 govind 417
			alert("ItemId Deleted successfully from Scheme");
418
			loadSchemeDetails(shcemeId, "scheme-details-container");
23715 govind 419
		}
420
	});
23752 govind 421
}
422
function loadSearchScheme(domId, search_text) {
423
	doGetAjaxRequestHandler(context + "/searchScheme/?searchTerm="
424
			+ search_text, function(response) {
425
		$('#' + domId).html(response);
426
	});
427
}
26497 amit.gupta 428
function loadSearchItemScheme(domId, selected_item) {
26802 tejbeer 429
	var category = $('#partner-category').val();
430
	var searchText = $("#scheme-item-search-text").val();
26763 tejbeer 431
 
26802 tejbeer 432
	var category = $('#partner-category').val();
26912 tejbeer 433
 
434
	console.log(category)
435
 
26802 tejbeer 436
	if (typeof (searchText) == "undefined" || !searchText) {
437
		searchText = "";
438
	}
439
	if (typeof (category) == "undefined" || !category) {
440
		category = "";
441
	}
442
	if ((searchText) && (category)) {
443
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
444
				+ selected_item.itemId + "&partnerType=" + category, function(
445
				response) {
446
			$('#' + domId).html(response);
447
			$('#partner-category').val(category);
448
			$('#scheme-item-search-text').val(selected_item.itemDescription);
449
 
450
		});
26912 tejbeer 451
	} else if ((searchText)) {
26802 tejbeer 452
		doGetAjaxRequestHandler(context + "/getSchemes/?searchItem="
453
				+ selected_item.itemId, function(response) {
454
			$('#' + domId).html(response);
455
			$('#scheme-item-search-text').val(selected_item.itemDescription);
456
 
457
		});
26912 tejbeer 458
 
459
	}
460
 
23752 govind 461
}
462
function loadSchemeSearchInfo(search_text) {
463
	loadSearchScheme("main-content", search_text);
464
}
26497 amit.gupta 465
function loadSchemeItemSearchInfo(selectedItem) {
466
	loadSearchItemScheme("main-content", selectedItem);
23914 govind 467
}