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
 
22354 ashik.ali 98
 
99
	$(".contact-us").live('click', function() {
100
		console.log("Contact Us Button Clicked...")
101
		contactUs("main-content");
102
	});
103
 
21987 kshitij.so 104
	//cart_icon_header
105
 
21627 kshitij.so 106
	$("#purchase-reference-submit").live('submit', function(){
107
		var formData = new FormData($(this)[0]);
108
 
109
		jQuery.ajax({
22092 amit.gupta 110
			url: context+"/purchase",
21627 kshitij.so 111
			type: 'POST',
112
			data: formData,
113
			async: false,
114
			success: function (data) {
115
				$('#main-content').html(data);
116
			},
117
			error : function() {
118
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
119
			},
120
			cache: false,
121
			contentType: false,
122
			processData: false
123
		});
124
		return false;
125
	});
126
 
21640 kshitij.so 127
	$("td.startGrnSerialized").live('click', function() {
21627 kshitij.so 128
		var invoiceNumber = $(this).attr('invoiceNumber');
129
		var quantity = $(this).attr('quantity');
130
		var displayName = $(this).attr('displayName');
131
		var itemId = $(this).attr('itemId');
132
		console.log(quantity);
133
		$(".modal-body .grnInvoiceNumber>span").text(invoiceNumber);
134
		$(".modal-body .grnProductInfo>span").text(displayName);
21640 kshitij.so 135
		$("#scanModel .invoiceNumber").val(invoiceNumber);
136
		$("#scanModel .itemId").val(itemId);
21627 kshitij.so 137
		$( "#grnImeiInformation" ).empty();
138
		var qty = parseInt(quantity);
139
		var divCode = '<div class="row">CONTENT</div><p></p>';
140
		var innerDiv = '<div class="col-sm-3">'+
141
		'<div class="input-group">'+
142
		'<input type="text" class="form-control">'+
143
		'</div>'+
144
		'</div>';
145
		while(qty!=0){
146
			var divText  = "";
147
			if (qty < 4){
148
				var cp = qty;
149
				for (var i=0;i<cp;i++ ){
150
					divText = divText + innerDiv;
151
					qty = qty - 1;
152
				}
153
			}
154
			else{
155
				for(var i=0;i<4;i++){
156
					divText = divText + innerDiv;
157
					qty = qty - 1;
158
				}
159
			}
160
			divText = divCode.replace("CONTENT",divText); 
161
			$("#grnImeiInformation")
162
			.append(divText)
163
		}
164
	});
165
 
21640 kshitij.so 166
	$("td.startGrnNonSerialized").live('click', function() {
167
		var invoiceNumber = $(this).attr('invoiceNumber');
168
		var quantity = $(this).attr('quantity');
169
		var displayName = $(this).attr('displayName');
170
		var itemId = $(this).attr('itemId');
171
		console.log(quantity);
172
		$("#scanNonSerializedModel .modal-body .grnInvoiceNumber>span").text(invoiceNumber);
173
		$("#scanNonSerializedModel .modal-body .grnProductInfo>span").text(displayName);
174
		$("#scanNonSerializedModel .invoiceNumber").val(invoiceNumber);
175
		$("#scanNonSerializedModel .itemId").val(itemId);
176
		$( "#grnImeiInformation" ).empty();
177
		var qty = parseInt(quantity);
178
		var divCode = '<div class="row">CONTENT</div><p></p>';
179
		var innerDiv = '<div class="col-sm-3">'+
180
		'<div class="input-group">'+
181
		'<input type="text" class="form-control">'+
182
		'</div>'+
183
		'</div>';
184
		while(qty!=0){
185
			var divText  = "";
186
			if (qty < 4){
187
				var cp = qty;
188
				for (var i=0;i<cp;i++ ){
189
					divText = divText + innerDiv;
190
					qty = qty - 1;
191
				}
192
			}
193
			else{
194
				for(var i=0;i<4;i++){
195
					divText = divText + innerDiv;
196
					qty = qty - 1;
197
				}
198
			}
199
			divText = divCode.replace("CONTENT",divText); 
200
			$("#grnImeiInformation")
201
			.append(divText)
202
		}
203
	});
204
 
205
	$("#grnSubmitSerialized").live('click', function(){
21627 kshitij.so 206
		var imeis = [];
207
		var error = false;
208
		var errorText = "";
209
		$("#grnImeiInformation :input").each(function(){
210
			var input = $(this).val().trim();
211
			if (imeis.indexOf(input) !=-1 || !input){
212
				error = true;
213
				if (!input){
214
					$(this).addClass("border-highlight");
215
				}
216
			}
217
			imeis.push(input);
22415 ashik.ali 218
 
21627 kshitij.so 219
		});
220
		if (error){
221
			return false;
222
		}
21640 kshitij.so 223
		var invoiceNumber = $("#scanModel .invoiceNumber").val();
224
		var itemId = $("#scanModel .itemId").val();
21627 kshitij.so 225
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"serialNumbers":imeis});
226
		jQuery.ajax({
22092 amit.gupta 227
			url: context+"/scanSerialized",
21627 kshitij.so 228
			type: 'POST',
229
			data: postData,
230
			contentType:'application/json',
231
			async: false,
232
			success: function (data) {
21640 kshitij.so 233
				alert("Purchase booked successfully");
234
				$('#scanModel').modal('hide');
235
				$("#scanModel").on("hidden.bs.modal", function () {
236
					$("#purchase-reference-submit").submit();
237
				});
21627 kshitij.so 238
			},
239
			error : function() {
240
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
241
			},
242
			cache: false,
243
			processData: false
244
		});
245
		return false;
246
	});
21640 kshitij.so 247
 
248
	$("#grnNonSerializedSubmit").live('click', function(){
249
		var error = false;
250
		var errorText = "";
251
		if (error){
252
			return false;
253
		}
254
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
255
		var itemId = $("#scanNonSerializedModel .itemId").val();
256
		var quantity = $("#scanNonSerializedModel .quantity").val();
257
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
258
		jQuery.ajax({
22092 amit.gupta 259
			url: context+"/scanNonSerialized",
21640 kshitij.so 260
			type: 'POST',
261
			data: postData,
262
			contentType:'application/json',
263
			async: false,
264
			success: function (data) {
265
				alert("Purchase booked successfully");
266
				$('#scanNonSerializedModel').modal('hide');
267
				$("#scanNonSerializedModel").on("hidden.bs.modal", function () {
268
					$("#purchase-reference-submit").submit();
269
				});
270
			},
271
			error : function() {
272
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
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
 
22551 ashik.ali 456
	$("#wallet-history-paginated .next").live('click', function() {
457
		var start = $( "#wallet-history-paginated .start" ).text();
458
		var end = $( "#wallet-history-paginated .end" ).text();
459
		getWalletHistoryNextItems(start, end, walletHistory.startTime, walletHistory.endTime);
460
		$("#wallet-history-paginated .next").blur();
461
    });
462
 
463
	$("#wallet-history-paginated .previous").live('click', function() {
464
		var start = $( "#wallet-history-paginated .start" ).text();
465
		var end =  $( "#wallet-history-paginated .end" ).text();
466
		var pre = end - 20;
467
		getWalletHistoryPreviousItems(start, end, pre, walletHistory.startTime, walletHistory.endTime);
468
		$("#wallet-history-paginated .previous").blur();
469
    });
470
 
22292 ashik.ali 471
	$("#sale-history-date-button").live('click', function() {
472
		var dateRange = $('#reportrange span').text();
473
		saleHistory.startTime = new Date(dateRange.split("-")[0]).getTime();
474
		saleHistory.endTime = new Date(dateRange.split("-")[1]).getTime();
475
		saleHistory.searchType = "dateFilter";
476
		saleHistory.searchText = "";
477
		saleHistorySearchInfo(saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
478
    });
479
 
22551 ashik.ali 480
	$("#wallet-history-date-button").live('click', function() {
481
		var dateRange = $('#reportrange span').text();
482
		walletHistory.startTime = new Date(dateRange.split("-")[0]).getTime();
483
		walletHistory.endTime = new Date(dateRange.split("-")[1]).getTime();
484
		saleHistorySearchInfo(saleHistory.searchText, saleHistory.searchType, saleHistory.startTime, saleHistory.endTime);
485
    });
486
 
21987 kshitij.so 487
	//grn-details
488
 
489
	$(".grn-details").live('click',function(){
490
		var purchaseId = $(this).attr('data');
491
		console.log(purchaseId);
492
		loadGrnDetails(purchaseId,"grn-details-container");
493
	});
494
 
22245 ashik.ali 495
	$(".sale-details").live('click',function(){
496
		var orderId = $(this).attr('data');
497
		console.log(orderId);
498
		loadSaleDetails(orderId,"sale-details-container");
499
	});
500
 
21987 kshitij.so 501
	$(".pending-grn").live('click',function(){
502
		var purchaseReference = $(this).attr('data');
503
		console.log(purchaseReference);
504
		loadPendingGrnDetails(purchaseReference,"main-content");
505
	});
506
 
507
	//add-to-bag
508
 
509
	$(".add-to-bag").live('click', function() {
510
		var itemId = $(this).attr('data');
511
		$("#bagModel .itemId").val(itemId);
512
		$("#bagModel .quantity").val(0);
513
		jQuery.ajax({
22092 amit.gupta 514
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 515
			type: 'GET',
516
			contentType:'application/json',
517
			async: false,
518
			success: function (data) {
519
				var obj = JSON.parse(data);
520
				console.log(obj);
521
				console.log(obj.displayName);
522
				$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
523
				$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
524
				$("#bagModel .availability").val(obj.availability);
525
			},
526
			error : function() {
527
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
528
			},
529
			cache: false,
530
			processData: false
531
		});
532
	});
533
 
534
	//addToBagButton
535
 
536
	$("#addToBagButton").live('click', function() {
537
		var itemId = $(this).attr('data');
538
		var itemId = $("#bagModel .itemId").val();
539
		var tempAvailability = $("#bagModel .availability").val();
540
		var quantity = $("#bagModel .quantity").val();
541
 
542
		if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1){
543
			alert("Please enter valid quantity");
544
			return;
545
		}
546
 
547
		jQuery.ajax({
22092 amit.gupta 548
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 549
			type: 'GET',
550
			contentType:'application/json',
551
			async: false,
552
			success: function (data) {
553
				var obj = JSON.parse(data);
554
				console.log(obj);
555
				if (obj.availability < parseInt(quantity) || obj.availability == 0){
556
					alert("You don't have enough inventory of this item");
557
					return;
558
				}
559
				var obj = {'itemId':obj.itemId,'displayName':obj.displayName,'quantity':parseInt(quantity),'iconUrl':obj.iconUrl};
560
				console.log(obj);
561
				addItemInLocalStorage(obj);
562
				alert("Item added to bag successfully");
563
				$('#bagModel').modal('hide');
564
			},
565
			error : function() {
566
				alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
567
			},
568
			cache: false,
569
			processData: false
570
		});
571
	});
572
 
573
	$(".cart-trash").live('click',function(){
574
		var itemId = $(this).attr('data');
575
		removeItemFromLocalStorage(itemId);
576
		$('div[itemId="' + itemId + '"]').remove();
577
		if ($('#cart-details').html().trim() == ""){
578
			$('#cart-details-empty').show();
579
			$('#cart-checkout').hide();
580
		}
581
	});
582
 
583
	$(".cart-qty").live('change paste keyup mouseup', function() {
584
		var itemId = $(this).attr('data');
585
		var maxQty = $(this).attr('max');
586
		var qty = $(this).val();
587
		if (!qty){
588
			qty = 0;
589
		}
590
		if(parseInt(qty) < 0){
591
			alert("Invalid quantity");
592
			$(this).val(0);
593
			qty = 0;
594
		}
595
		if (parseInt(qty) > parseInt(maxQty)){
596
			alert("You don't have availability of "+qty);
597
			$(this).val(maxQty);
598
			qty = maxQty;
599
		}
600
		changeQuantityInLocalStorage(itemId, qty);
601
	});
602
 
22661 amit.gupta 603
	$("form#cd input.discountAmount").live('change paste keyup mouseup', function() {
604
		var discountAmount = parseFloat($(this).val());
605
		if (isNaN(discountAmount)){
606
			discountAmount = 0;
607
		}
608
		if(discountAmount < 0){
609
			alert("Invalid insurance Value");
610
			$(this).val(0);
611
		}
22662 amit.gupta 612
		calculateTotalAmount();
22661 amit.gupta 613
	});
614
 
21987 kshitij.so 615
	$("form#cd input.unitPrice").live('change paste keyup mouseup', function() {
22245 ashik.ali 616
 
22661 amit.gupta 617
		var unitPrice = parseFloat($(this).val());
618
		if (isNaN(unitPrice)){
21987 kshitij.so 619
			unitPrice = 0;
620
		}
22661 amit.gupta 621
		if(unitPrice < 0){
21987 kshitij.so 622
			alert("Invalid unit price");
623
			$(this).val(0);
624
		}
22661 amit.gupta 625
		calculateTotalAmount();
21987 kshitij.so 626
	});
22245 ashik.ali 627
 
628
 
629
	$("form#cd input.insuranceAmount").live('change paste keyup mouseup', function() {
22661 amit.gupta 630
		calculateTotalAmount();
631
	});
632
 
633
});
634
 
635
function calculateTotalAmount() {
636
	var netPayableAmount = 0;
637
	$("#cd").find('tr:gt(0)').each(function(index, el){
638
		var rowTotal = 0;
639
		$tr = $(el);
640
 
641
		var insuranceAmount = $tr.find('.insuranceAmount').val();
22245 ashik.ali 642
		if (!insuranceAmount){
643
			insuranceAmount = 0;
644
		}else{
645
			insuranceAmount = parseFloat(insuranceAmount);
646
		}
647
 
22661 amit.gupta 648
		var qty = parseFloat($(el).find('.unitPrice').attr('quantity'));
649
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
22245 ashik.ali 650
 
22661 amit.gupta 651
		var discountAmount =  parseFloat($(el).find('.discountAmount').val());
652
		if(isNaN(discountAmount)){
653
			discountAmount = 0;
654
		}
655
 
656
		rowTotal = unitPrice*qty + insuranceAmount - discountAmount; 
657
		$tr.find('.totalPrice').val(rowTotal);
658
		netPayableAmount += rowTotal;
22245 ashik.ali 659
	});
22661 amit.gupta 660
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
661
}