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