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