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