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