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