Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21987 kshitij.so 1
var grnhistory= grnhistory || {};
2
grnhistory.searchText = "";
3
grnhistory.searchType = "";
4
grnhistory.startTime = "0";
5
grnhistory.endTime = "0";
6
 
22283 ashik.ali 7
var saleHistory=saleHistory || {};
8
saleHistory.searchText="";
9
saleHistory.searchType="";
10
saleHistory.startTime="";
11
saleHistory.endTime="";
12
 
22551 ashik.ali 13
var walletHistory = walletHistory || {};
14
walletHistory.startTime="";
15
walletHistory.endTime="";
16
 
21627 kshitij.so 17
$(function() {
18
	$(".new_grn").live('click', function() {
19
		loadNewGrn("main-content");
20
	});
21987 kshitij.so 21
 
22
	$(".good_inventory").live('click', function() {
23
		loadGoodInventory("main-content","");
24
	});
25
 
26
	$(".catalog").live('click', function() {
27
		loadCatalog("main-content","");
28
	});
29
 
22523 ashik.ali 30
	$(".item_aging").live('click', function() {
31
		getInventoryItemAgingByInterval("main-content", "");
32
	});
33
 
34
	$("#item-aging-paginated .next").live('click', function() {
35
		var end = $( "#item-aging-paginated .end" ).text();
36
		getItemAgingNextPreviousItems(end, "");
37
		$("#item-aging-paginated .next").blur();
38
    });
39
 
40
	$("#item-aging-search-button").live('click', function() {
41
		searchContent = $("#item-aging-search-text").val();
42
		if (typeof (searchContent) == "undefined" || !searchContent){
43
			searchContent = "";
44
		}
45
		getInventoryItemAgingByInterval("main-content", searchContent);
46
    });
47
 
48
	$("#item-aging-search-text").live("keyup", function(e) {
49
		var keyCode = e.keyCode || e.which;
50
    	if(keyCode == 13){
51
        	$("#item-aging-search-button").click();
52
    	}
53
	});
54
 
55
	$("#item-aging-paginated .previous").live('click', function() {
56
		var start = $( "#item-aging-paginated .start" ).text();
57
		getItemAgingNextPreviousItems(start - 11, "");
58
		$("#item-aging-paginated .previous").blur();
59
    });
60
 
22488 ashik.ali 61
	$(".download_aging_report").live('click', function() {
62
		downloadAgingReport();
63
	});
64
 
22523 ashik.ali 65
	$(".download_item_ledger_report").live('click', function() {
66
		downloadItemLedgerReport();
67
	});
68
 
21987 kshitij.so 69
	$(".bad_inventory").live('click', function() {
70
		loadBadInventory("main-content","");
71
	});
21627 kshitij.so 72
 
21987 kshitij.so 73
	$(".grn_history").live('click', function() {
74
		loadGrnHistory("main-content","","","0","0");
75
	});
76
 
77
	$(".cart_icon_header").live('click', function() {
78
		loadCart("main-content");
79
	});
80
 
22551 ashik.ali 81
	$(".wallet_icon_header").live('click', function() {
82
		loadWallet("main-content", "", "");
83
	});
84
 
21987 kshitij.so 85
	$(".cart-checkout").live('click', function() {
86
		checkout("main-content");
87
	});
88
 
22245 ashik.ali 89
	$(".create-order").live('click', function() {
90
		checkout("main-content");
91
	});
92
 
93
	$(".sale-history").live('click', function() {
22292 ashik.ali 94
		console.log("Sale History Button Clicked...")
22245 ashik.ali 95
		saleHistory("main-content","","","0","0");
96
	});
97
 
22860 ashik.ali 98
	$(".schemes").live('click', function() {
99
		console.log("Active Schemes Button Clicked...")
100
		schemes("main-content");
101
	});
22354 ashik.ali 102
 
22860 ashik.ali 103
 
22354 ashik.ali 104
	$(".contact-us").live('click', function() {
105
		console.log("Contact Us Button Clicked...")
106
		contactUs("main-content");
107
	});
108
 
22860 ashik.ali 109
	$(".create-scheme").live('click', function() {
110
		loadScheme("main-content");
111
	});
112
 
21987 kshitij.so 113
	//cart_icon_header
114
 
21627 kshitij.so 115
	$("#purchase-reference-submit").live('submit', function(){
116
		var formData = new FormData($(this)[0]);
117
 
118
		jQuery.ajax({
22092 amit.gupta 119
			url: context+"/purchase",
21627 kshitij.so 120
			type: 'POST',
121
			data: formData,
122
			async: false,
123
			success: function (data) {
124
				$('#main-content').html(data);
125
			},
126
			error : function() {
127
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
128
			},
129
			cache: false,
130
			contentType: false,
131
			processData: false
132
		});
133
		return false;
134
	});
135
 
21640 kshitij.so 136
	$("td.startGrnSerialized").live('click', function() {
21627 kshitij.so 137
		var invoiceNumber = $(this).attr('invoiceNumber');
138
		var quantity = $(this).attr('quantity');
139
		var displayName = $(this).attr('displayName');
140
		var itemId = $(this).attr('itemId');
141
		console.log(quantity);
142
		$(".modal-body .grnInvoiceNumber>span").text(invoiceNumber);
143
		$(".modal-body .grnProductInfo>span").text(displayName);
21640 kshitij.so 144
		$("#scanModel .invoiceNumber").val(invoiceNumber);
145
		$("#scanModel .itemId").val(itemId);
21627 kshitij.so 146
		$( "#grnImeiInformation" ).empty();
147
		var qty = parseInt(quantity);
148
		var divCode = '<div class="row">CONTENT</div><p></p>';
149
		var innerDiv = '<div class="col-sm-3">'+
150
		'<div class="input-group">'+
151
		'<input type="text" class="form-control">'+
152
		'</div>'+
153
		'</div>';
154
		while(qty!=0){
155
			var divText  = "";
156
			if (qty < 4){
157
				var cp = qty;
158
				for (var i=0;i<cp;i++ ){
159
					divText = divText + innerDiv;
160
					qty = qty - 1;
161
				}
162
			}
163
			else{
164
				for(var i=0;i<4;i++){
165
					divText = divText + innerDiv;
166
					qty = qty - 1;
167
				}
168
			}
169
			divText = divCode.replace("CONTENT",divText); 
170
			$("#grnImeiInformation")
171
			.append(divText)
172
		}
173
	});
174
 
21640 kshitij.so 175
	$("td.startGrnNonSerialized").live('click', function() {
176
		var invoiceNumber = $(this).attr('invoiceNumber');
177
		var quantity = $(this).attr('quantity');
178
		var displayName = $(this).attr('displayName');
179
		var itemId = $(this).attr('itemId');
180
		console.log(quantity);
181
		$("#scanNonSerializedModel .modal-body .grnInvoiceNumber>span").text(invoiceNumber);
182
		$("#scanNonSerializedModel .modal-body .grnProductInfo>span").text(displayName);
183
		$("#scanNonSerializedModel .invoiceNumber").val(invoiceNumber);
184
		$("#scanNonSerializedModel .itemId").val(itemId);
185
		$( "#grnImeiInformation" ).empty();
186
		var qty = parseInt(quantity);
187
		var divCode = '<div class="row">CONTENT</div><p></p>';
188
		var innerDiv = '<div class="col-sm-3">'+
189
		'<div class="input-group">'+
190
		'<input type="text" class="form-control">'+
191
		'</div>'+
192
		'</div>';
193
		while(qty!=0){
194
			var divText  = "";
195
			if (qty < 4){
196
				var cp = qty;
197
				for (var i=0;i<cp;i++ ){
198
					divText = divText + innerDiv;
199
					qty = qty - 1;
200
				}
201
			}
202
			else{
203
				for(var i=0;i<4;i++){
204
					divText = divText + innerDiv;
205
					qty = qty - 1;
206
				}
207
			}
208
			divText = divCode.replace("CONTENT",divText); 
209
			$("#grnImeiInformation")
210
			.append(divText)
211
		}
212
	});
213
 
214
	$("#grnSubmitSerialized").live('click', function(){
21627 kshitij.so 215
		var imeis = [];
216
		var error = false;
217
		var errorText = "";
218
		$("#grnImeiInformation :input").each(function(){
219
			var input = $(this).val().trim();
220
			if (imeis.indexOf(input) !=-1 || !input){
221
				error = true;
222
				if (!input){
223
					$(this).addClass("border-highlight");
224
				}
225
			}
226
			imeis.push(input);
22415 ashik.ali 227
 
21627 kshitij.so 228
		});
229
		if (error){
230
			return false;
231
		}
21640 kshitij.so 232
		var invoiceNumber = $("#scanModel .invoiceNumber").val();
233
		var itemId = $("#scanModel .itemId").val();
21627 kshitij.so 234
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"serialNumbers":imeis});
235
		jQuery.ajax({
22092 amit.gupta 236
			url: context+"/scanSerialized",
21627 kshitij.so 237
			type: 'POST',
238
			data: postData,
239
			contentType:'application/json',
240
			async: false,
241
			success: function (data) {
21640 kshitij.so 242
				alert("Purchase booked successfully");
243
				$('#scanModel').modal('hide');
244
				$("#scanModel").on("hidden.bs.modal", function () {
245
					$("#purchase-reference-submit").submit();
246
				});
21627 kshitij.so 247
			},
248
			error : function() {
249
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
250
			},
251
			cache: false,
252
			processData: false
253
		});
254
		return false;
255
	});
21640 kshitij.so 256
 
257
	$("#grnNonSerializedSubmit").live('click', function(){
258
		var error = false;
259
		var errorText = "";
260
		if (error){
261
			return false;
262
		}
263
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
264
		var itemId = $("#scanNonSerializedModel .itemId").val();
265
		var quantity = $("#scanNonSerializedModel .quantity").val();
266
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
267
		jQuery.ajax({
22092 amit.gupta 268
			url: context+"/scanNonSerialized",
21640 kshitij.so 269
			type: 'POST',
270
			data: postData,
271
			contentType:'application/json',
272
			async: false,
273
			success: function (data) {
274
				alert("Purchase booked successfully");
275
				$('#scanNonSerializedModel').modal('hide');
276
				$("#scanNonSerializedModel").on("hidden.bs.modal", function () {
277
					$("#purchase-reference-submit").submit();
278
				});
279
			},
280
			error : function() {
281
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
282
			},
283
			cache: false,
284
			processData: false
285
		});
286
		return false;
287
	});
21627 kshitij.so 288
 
289
	$("#grnImeiInformation :input").live('change paste keyup mouseup', function() {
290
		if ($(this).val().trim() != "") {
291
			console.log('The text box really changed this time');
292
			$('#grnImeiInformation :input').removeClass("border-highlight");
293
			if(findDuplicateSerialNumbers( $(this).val().trim()) > 0){
294
				var inputs = $("#grnImeiInformation :input[value="+$(this).val().trim()+"]");
295
				if(inputs.length > 1){
296
					inputs.each(function(){$(this).addClass("border-highlight")});
297
				}
298
			}
299
		}
300
	});
21987 kshitij.so 301
 
22415 ashik.ali 302
 
303
	$("#grnImeiInformation :input").live('paste', function() {
304
		if ($(this).val().trim() != "") {
305
			console.log('paste event');
306
			$(this).next("input .form-control").focus();
307
		}
308
	});
309
 
21987 kshitij.so 310
	$("#good-inventory-paginated .next").live('click', function() {
311
		var start = $( "#good-inventory-paginated .start" ).text();
312
		var end = $( "#good-inventory-paginated .end" ).text();
313
		var searchText = $("#good-inventory-search-text").val();
314
		if (typeof (searchText) == "undefined" || !searchText){
315
			searchText = "";
316
		}
22523 ashik.ali 317
		getNextItems(start,end, searchText);
21987 kshitij.so 318
		$("#good-inventory-paginated .next").blur();
319
 
320
    });
321
 
322
	$("#good-inventory-paginated .previous").live('click', function() {
323
		var start = $( "#good-inventory-paginated .start" ).text();
324
		var end =  $( "#good-inventory-paginated .end" ).text();
325
		var searchText = $("#good-inventory-search-text").val();
326
		if (typeof (searchText) == "undefined" || !searchText){
327
			searchText = "";
328
		}
329
		var pre = end - 20;
22523 ashik.ali 330
		getPreviousItems(start, end, pre, searchText);
21987 kshitij.so 331
		$("#good-inventory-paginated .previous").blur();
332
    });
333
 
334
	$("#good-inventory-search-button").live('click', function() {
335
		var searchText = $("#good-inventory-search-text").val();
336
		if (typeof (searchText) == "undefined" || !searchText){
337
			searchText = "";
338
		}
339
		loadGoodInventorySearchInfo(searchText);
340
    });
341
 
342
	$("#good-inventory-search-text").live("keyup", function(e) {
343
		var keyCode = e.keyCode || e.which;
344
    	if(keyCode == 13){
345
        	$("#good-inventory-search-button").click();
346
    	}
347
	});
348
 
349
	$("#catalog-paginated .next").live('click', function() {
350
		var start = $( "#catalog-paginated .start" ).text();
351
		var end = $( "#catalog-paginated .end" ).text();
352
		var searchText = $("#catalog-search-text").val();
353
		if (typeof (searchText) == "undefined" || !searchText){
354
			searchText = "";
355
		}
356
		getNextCatalogItems(start,end,searchText);
357
		$("#catalog-paginated .next").blur();
358
    });
359
 
360
	$("#catalog-paginated .previous").live('click', function() {
361
		var start = $( "#catalog-paginated .start" ).text();
362
		var end =  $( "#catalog-paginated .end" ).text();
363
		var searchText = $("#catalog-search-text").val();
364
		if (typeof (searchText) == "undefined" || !searchText){
365
			searchText = "";
366
		}
367
		var pre = end - 20;
368
		getPreviousCatalogItems(start,end,pre,searchText);
369
		$("#catalog-paginated .previous").blur();
370
    });
371
 
372
	$("#catalog-search-button").live('click', function() {
373
		var searchText = $("#catalog-search-text").val();
374
		if (typeof (searchText) == "undefined" || !searchText){
375
			searchText = "";
376
		}
377
		loadCatalogSearchInfo(searchText);
378
    });
379
 
380
	$("#catalog-search-text").live("keyup", function(e) {
381
		var keyCode = e.keyCode || e.which;
382
    	if(keyCode == 13){
383
        	$("#catalog-search-button").click();
384
    	}
385
	});
386
 
387
	$("#grn-history-search-button").live('click', function() {
388
		grnhistory.searchText = $("#grn-history-search-text").val();
389
		grnhistory.searchType = "purchaseReference";
390
		grnhistory.startTime = "0";
391
		grnhistory.endTime = "0";
392
		if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText){
393
			grnhistory.searchText = "";
394
		}
395
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
396
    });
397
 
398
	$("#grn-history-search-text").live("keyup", function(e) {
399
		var keyCode = e.keyCode || e.which;
400
    	if(keyCode == 13){
401
        	$("#grn-history-search-button").click();
402
    	}
403
	});
404
 
22283 ashik.ali 405
 
406
	$("#sale-history-search-button").live('click', function() {
407
		saleHistory.searchText = $("#sale-history-search-text").val();
408
		saleHistory.searchType = "invoiceNumber";
409
		saleHistory.startTime = "0";
410
		saleHistory.endTime = "0";
411
		if (typeof (saleHistory.searchText) == "undefined" || !saleHistory.searchText){
412
			saleHistory.searchText = "";
413
		}
414
		saleHistorySearchInfo(saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
415
    });
416
 
417
	$("#sale-history-search-text").live("keyup", function(e) {
418
		var keyCode = e.keyCode || e.which;
419
    	if(keyCode == 13){
420
        	$("#sale-history-search-button").click();
421
    	}
422
	});
423
 
21987 kshitij.so 424
	$("#grn-history-paginated .next").live('click', function() {
425
		var start = $( "#grn-history-paginated .start" ).text();
426
		var end = $( "#grn-history-paginated .end" ).text();
427
		getGrnHistoryNextItems(start,end,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
428
		$("#grn-history-paginated .next").blur();
429
 
430
    });
431
 
432
	$("#grn-history-paginated .previous").live('click', function() {
433
		var start = $( "#grn-history-paginated .start" ).text();
434
		var end =  $( "#grn-history-paginated .end" ).text();
435
		var pre = end - 20;
436
		getGrnHistoryPreviousItems(start,end,pre,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
437
		$("#grn-history-paginated .previous").blur();
438
    });
439
 
440
	$("#grn-history-date-button").live('click', function() {
441
		var dateRange = $('#reportrange span').text();
442
		grnhistory.startTime = new Date(dateRange.split("-")[0]).getTime();
443
		grnhistory.endTime = new Date(dateRange.split("-")[1]).getTime();
444
		grnhistory.searchType = "dateFilter";
445
		grnhistory.searchText = "";
446
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
447
    });
448
 
22292 ashik.ali 449
 
450
	$("#sale-history-paginated .next").live('click', function() {
451
		var start = $( "#sale-history-paginated .start" ).text();
452
		var end = $( "#sale-history-paginated .end" ).text();
453
		getSaleHistoryNextItems(start, end, saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
454
		$("#sale-history-paginated .next").blur();
455
    });
456
 
457
	$("#sale-history-paginated .previous").live('click', function() {
458
		var start = $( "#sale-history-paginated .start" ).text();
459
		var end =  $( "#sale-history-paginated .end" ).text();
460
		var pre = end - 20;
461
		getSaleHistoryPreviousItems(start, end, pre, saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
462
		$("#sale-history-paginated .previous").blur();
463
    });
464
 
22860 ashik.ali 465
	$("#schemes-paginated .next").live('click', function() {
466
		var start = $( "#schemes-paginated .start" ).text();
467
		var end = $( "#schemes-paginated .end" ).text();
468
		getSchemesNextItems(start, end);
469
		$("#schemes-paginated .next").blur();
470
    });
471
 
472
	$("#schemes-paginated .previous").live('click', function() {
473
		var start = $( "#schemes-paginated .start" ).text();
474
		var end =  $( "#schemes-paginated .end" ).text();
475
		var pre = end - 20;
476
		getSchemesPreviousItems(start, end, pre);
477
		$("#schemes-paginated .previous").blur();
478
    });
479
 
22551 ashik.ali 480
	$("#wallet-history-paginated .next").live('click', function() {
481
		var start = $( "#wallet-history-paginated .start" ).text();
482
		var end = $( "#wallet-history-paginated .end" ).text();
483
		getWalletHistoryNextItems(start, end, walletHistory.startTime, walletHistory.endTime);
484
		$("#wallet-history-paginated .next").blur();
485
    });
486
 
487
	$("#wallet-history-paginated .previous").live('click', function() {
488
		var start = $( "#wallet-history-paginated .start" ).text();
489
		var end =  $( "#wallet-history-paginated .end" ).text();
490
		var pre = end - 20;
491
		getWalletHistoryPreviousItems(start, end, pre, walletHistory.startTime, walletHistory.endTime);
492
		$("#wallet-history-paginated .previous").blur();
493
    });
494
 
22292 ashik.ali 495
	$("#sale-history-date-button").live('click', function() {
496
		var dateRange = $('#reportrange span').text();
497
		saleHistory.startTime = new Date(dateRange.split("-")[0]).getTime();
498
		saleHistory.endTime = new Date(dateRange.split("-")[1]).getTime();
499
		saleHistory.searchType = "dateFilter";
500
		saleHistory.searchText = "";
501
		saleHistorySearchInfo(saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
502
    });
503
 
22551 ashik.ali 504
	$("#wallet-history-date-button").live('click', function() {
505
		var dateRange = $('#reportrange span').text();
506
		walletHistory.startTime = new Date(dateRange.split("-")[0]).getTime();
507
		walletHistory.endTime = new Date(dateRange.split("-")[1]).getTime();
508
		saleHistorySearchInfo(saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
509
    });
510
 
21987 kshitij.so 511
	//grn-details
512
 
513
	$(".grn-details").live('click',function(){
514
		var purchaseId = $(this).attr('data');
515
		console.log(purchaseId);
516
		loadGrnDetails(purchaseId,"grn-details-container");
517
	});
518
 
22245 ashik.ali 519
	$(".sale-details").live('click',function(){
520
		var orderId = $(this).attr('data');
22860 ashik.ali 521
		console.log("orderId = "+orderId);
22245 ashik.ali 522
		loadSaleDetails(orderId,"sale-details-container");
523
	});
524
 
22860 ashik.ali 525
	$(".scheme-details").live('click',function(){
526
		var schemeId = $(this).attr('data');
527
		console.log("schemeId = "+schemeId);
528
		loadSchemeDetails(schemeId, "scheme-details-container");
529
	});
530
 
21987 kshitij.so 531
	$(".pending-grn").live('click',function(){
532
		var purchaseReference = $(this).attr('data');
533
		console.log(purchaseReference);
534
		loadPendingGrnDetails(purchaseReference,"main-content");
535
	});
536
 
22860 ashik.ali 537
	$(".active-scheme").live('click',function(){
538
		var schemeId = $(this).attr('data');
539
		console.log("active-scheme id : "+schemeId);
540
		var start = $( "#schemes-paginated .start" ).text();
541
		//var end = $( "#schemes-paginated .end" ).text();
542
		var offset = start - 1;
543
		if(confirm("Are you sure you want to Active Scheme!") == true){
544
			activeScheme(schemeId, offset, "schemes-table");
545
		}
546
	});
547
 
548
	$(".expire-scheme").live('click',function(){
549
		var schemeId = $(this).attr('data');
550
		console.log("expire-scheme id : "+schemeId);
551
		var start = $( "#schemes-paginated .start" ).text();
552
		//var end = $( "#schemes-paginated .end" ).text();
553
		var offset = start - 1;
554
		if(confirm("Are you sure you want to Expire Scheme!") == true){
555
			expireScheme(schemeId, offset, "schemes-table");
556
		}
557
	});
558
 
21987 kshitij.so 559
	//add-to-bag
560
 
561
	$(".add-to-bag").live('click', function() {
562
		var itemId = $(this).attr('data');
563
		$("#bagModel .itemId").val(itemId);
564
		$("#bagModel .quantity").val(0);
565
		jQuery.ajax({
22092 amit.gupta 566
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 567
			type: 'GET',
568
			contentType:'application/json',
569
			async: false,
570
			success: function (data) {
571
				var obj = JSON.parse(data);
572
				console.log(obj);
573
				console.log(obj.displayName);
574
				$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
575
				$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
576
				$("#bagModel .availability").val(obj.availability);
577
			},
578
			error : function() {
579
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
580
			},
581
			cache: false,
582
			processData: false
583
		});
584
	});
585
 
586
	//addToBagButton
587
 
588
	$("#addToBagButton").live('click', function() {
589
		var itemId = $(this).attr('data');
590
		var itemId = $("#bagModel .itemId").val();
591
		var tempAvailability = $("#bagModel .availability").val();
592
		var quantity = $("#bagModel .quantity").val();
593
 
594
		if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1){
595
			alert("Please enter valid quantity");
596
			return;
597
		}
598
 
599
		jQuery.ajax({
22092 amit.gupta 600
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 601
			type: 'GET',
602
			contentType:'application/json',
603
			async: false,
604
			success: function (data) {
605
				var obj = JSON.parse(data);
606
				console.log(obj);
607
				if (obj.availability < parseInt(quantity) || obj.availability == 0){
608
					alert("You don't have enough inventory of this item");
609
					return;
610
				}
611
				var obj = {'itemId':obj.itemId,'displayName':obj.displayName,'quantity':parseInt(quantity),'iconUrl':obj.iconUrl};
612
				console.log(obj);
613
				addItemInLocalStorage(obj);
614
				alert("Item added to bag successfully");
615
				$('#bagModel').modal('hide');
616
			},
617
			error : function() {
618
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
619
			},
620
			cache: false,
621
			processData: false
622
		});
623
	});
624
 
625
	$(".cart-trash").live('click',function(){
626
		var itemId = $(this).attr('data');
627
		removeItemFromLocalStorage(itemId);
628
		$('div[itemId="' + itemId + '"]').remove();
629
		if ($('#cart-details').html().trim() == ""){
630
			$('#cart-details-empty').show();
631
			$('#cart-checkout').hide();
632
		}
633
	});
634
 
635
	$(".cart-qty").live('change paste keyup mouseup', function() {
636
		var itemId = $(this).attr('data');
637
		var maxQty = $(this).attr('max');
638
		var qty = $(this).val();
639
		if (!qty){
640
			qty = 0;
641
		}
642
		if(parseInt(qty) < 0){
643
			alert("Invalid quantity");
644
			$(this).val(0);
645
			qty = 0;
646
		}
647
		if (parseInt(qty) > parseInt(maxQty)){
648
			alert("You don't have availability of "+qty);
649
			$(this).val(maxQty);
650
			qty = maxQty;
651
		}
652
		changeQuantityInLocalStorage(itemId, qty);
653
	});
654
 
22661 amit.gupta 655
	$("form#cd input.discountAmount").live('change paste keyup mouseup', function() {
656
		var discountAmount = parseFloat($(this).val());
657
		if (isNaN(discountAmount)){
658
			discountAmount = 0;
659
		}
660
		if(discountAmount < 0){
661
			alert("Invalid insurance Value");
662
			$(this).val(0);
663
		}
22662 amit.gupta 664
		calculateTotalAmount();
22661 amit.gupta 665
	});
666
 
21987 kshitij.so 667
	$("form#cd input.unitPrice").live('change paste keyup mouseup', function() {
22245 ashik.ali 668
 
22661 amit.gupta 669
		var unitPrice = parseFloat($(this).val());
670
		if (isNaN(unitPrice)){
21987 kshitij.so 671
			unitPrice = 0;
672
		}
22661 amit.gupta 673
		if(unitPrice < 0){
21987 kshitij.so 674
			alert("Invalid unit price");
675
			$(this).val(0);
676
		}
22661 amit.gupta 677
		calculateTotalAmount();
21987 kshitij.so 678
	});
22245 ashik.ali 679
 
680
 
681
	$("form#cd input.insuranceAmount").live('change paste keyup mouseup', function() {
22661 amit.gupta 682
		calculateTotalAmount();
683
	});
684
 
685
});
686
 
687
function calculateTotalAmount() {
688
	var netPayableAmount = 0;
689
	$("#cd").find('tr:gt(0)').each(function(index, el){
690
		var rowTotal = 0;
691
		$tr = $(el);
692
 
693
		var insuranceAmount = $tr.find('.insuranceAmount').val();
22245 ashik.ali 694
		if (!insuranceAmount){
695
			insuranceAmount = 0;
696
		}else{
697
			insuranceAmount = parseFloat(insuranceAmount);
698
		}
699
 
22661 amit.gupta 700
		var qty = parseFloat($(el).find('.unitPrice').attr('quantity'));
701
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
22245 ashik.ali 702
 
22661 amit.gupta 703
		var discountAmount =  parseFloat($(el).find('.discountAmount').val());
704
		if(isNaN(discountAmount)){
705
			discountAmount = 0;
706
		}
707
 
708
		rowTotal = unitPrice*qty + insuranceAmount - discountAmount; 
709
		$tr.find('.totalPrice').val(rowTotal);
710
		netPayableAmount += rowTotal;
22245 ashik.ali 711
	});
22661 amit.gupta 712
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
713
}