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
 
23331 ashik.ali 441
	$('#retailerAddressState').live('change', function() { 
442
	    var stateName = $(this).find('option:selected').text();
443
	    loadDistrictNames(stateName);
444
	});
23203 ashik.ali 445
 
23331 ashik.ali 446
 
22283 ashik.ali 447
	$("#sale-history-search-button").live('click', function() {
23203 ashik.ali 448
		console.log("sale-history-search-button clicked")
449
		var searchType = $("#searchType option:selected").val();
450
		console.log("searchType = " + searchType);
451
		$("#searchType").removeClass("border-highlight");
452
		if(searchType == ""){
453
			alert("Please choose Search Type");
454
			$("#searchType").addClass("border-highlight");
455
		}else{
456
			var startDateTime = $('input[name="startDateTime"]').val();
457
			console.log("startDateTime : "+startDateTime);
458
			var endDateTime = $('input[name="endDateTime"]').val();
459
			console.log("endDateTime : "+endDateTime);
460
 
461
			saleHistory.searchText = $("#sale-history-search-text").val();
462
			saleHistory.searchType = searchType;
463
			saleHistory.startTime = startDateTime;
464
			saleHistory.endTime = endDateTime;
465
			if (typeof (saleHistory.searchText) == "undefined" || !saleHistory.searchText){
466
				saleHistory.searchText = "";
467
			}
468
			saleHistorySearchInfo(saleHistory.searchType, saleHistory.searchText, saleHistory.startTime, saleHistory.endTime);
469
			$("#sale-history-search-text").val(saleHistory.searchText);
470
			$("#searchType").val(searchType);
471
			$('input[name="startDateTime"]').val(saleHistory.startTime);
472
			$('input[name="endDateTime"]').val(saleHistory.endTime);
22283 ashik.ali 473
		}
474
    });
475
 
23203 ashik.ali 476
	/*$("#sale-history-search-text").live("keyup", function(e) {
22283 ashik.ali 477
		var keyCode = e.keyCode || e.which;
478
    	if(keyCode == 13){
479
        	$("#sale-history-search-button").click();
480
    	}
23203 ashik.ali 481
	});*/
22283 ashik.ali 482
 
21987 kshitij.so 483
	$("#grn-history-paginated .next").live('click', function() {
484
		var start = $( "#grn-history-paginated .start" ).text();
485
		var end = $( "#grn-history-paginated .end" ).text();
486
		getGrnHistoryNextItems(start,end,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
487
		$("#grn-history-paginated .next").blur();
488
 
489
    });
490
 
491
	$("#grn-history-paginated .previous").live('click', function() {
492
		var start = $( "#grn-history-paginated .start" ).text();
493
		var end =  $( "#grn-history-paginated .end" ).text();
494
		var pre = end - 20;
495
		getGrnHistoryPreviousItems(start,end,pre,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
496
		$("#grn-history-paginated .previous").blur();
497
    });
498
 
499
	$("#grn-history-date-button").live('click', function() {
500
		var dateRange = $('#reportrange span').text();
501
		grnhistory.startTime = new Date(dateRange.split("-")[0]).getTime();
502
		grnhistory.endTime = new Date(dateRange.split("-")[1]).getTime();
503
		grnhistory.searchType = "dateFilter";
504
		grnhistory.searchText = "";
505
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
506
    });
507
 
22292 ashik.ali 508
 
509
	$("#sale-history-paginated .next").live('click', function() {
510
		var start = $( "#sale-history-paginated .start" ).text();
511
		var end = $( "#sale-history-paginated .end" ).text();
23203 ashik.ali 512
		getSaleHistoryNextItems(start, end, saleHistory.searchType, saleHistory.searchText, saleHistory.startTime, saleHistory.endTime);
22292 ashik.ali 513
		$("#sale-history-paginated .next").blur();
514
    });
515
 
516
	$("#sale-history-paginated .previous").live('click', function() {
517
		var start = $( "#sale-history-paginated .start" ).text();
518
		var end =  $( "#sale-history-paginated .end" ).text();
519
		var pre = end - 20;
23203 ashik.ali 520
		getSaleHistoryPreviousItems(start, end, pre, saleHistory.searchType, saleHistory.searchText, saleHistory.startTime, saleHistory.endTime);
22292 ashik.ali 521
		$("#sale-history-paginated .previous").blur();
522
    });
523
 
22860 ashik.ali 524
	$("#schemes-paginated .next").live('click', function() {
525
		var start = $( "#schemes-paginated .start" ).text();
526
		var end = $( "#schemes-paginated .end" ).text();
527
		getSchemesNextItems(start, end);
528
		$("#schemes-paginated .next").blur();
529
    });
530
 
531
	$("#schemes-paginated .previous").live('click', function() {
532
		var start = $( "#schemes-paginated .start" ).text();
533
		var end =  $( "#schemes-paginated .end" ).text();
534
		var pre = end - 20;
535
		getSchemesPreviousItems(start, end, pre);
536
		$("#schemes-paginated .previous").blur();
537
    });
538
 
22551 ashik.ali 539
	$("#wallet-history-paginated .next").live('click', function() {
540
		var start = $( "#wallet-history-paginated .start" ).text();
541
		var end = $( "#wallet-history-paginated .end" ).text();
542
		getWalletHistoryNextItems(start, end, walletHistory.startTime, walletHistory.endTime);
543
		$("#wallet-history-paginated .next").blur();
544
    });
545
 
546
	$("#wallet-history-paginated .previous").live('click', function() {
547
		var start = $( "#wallet-history-paginated .start" ).text();
548
		var end =  $( "#wallet-history-paginated .end" ).text();
549
		var pre = end - 20;
550
		getWalletHistoryPreviousItems(start, end, pre, walletHistory.startTime, walletHistory.endTime);
551
		$("#wallet-history-paginated .previous").blur();
552
    });
553
 
23203 ashik.ali 554
	/*$("#sale-history-date-button").live('click', function() {
22292 ashik.ali 555
		var dateRange = $('#reportrange span').text();
556
		saleHistory.startTime = new Date(dateRange.split("-")[0]).getTime();
557
		saleHistory.endTime = new Date(dateRange.split("-")[1]).getTime();
23203 ashik.ali 558
		saleHistory.searchType = "";
22292 ashik.ali 559
		saleHistory.searchText = "";
23203 ashik.ali 560
		saleHistorySearchInfo(saleHistory.searchType, saleHistory.searchText, saleHistory.startTime, saleHistory.endTime);
561
    });*/
22292 ashik.ali 562
 
22551 ashik.ali 563
 
21987 kshitij.so 564
	//grn-details
565
 
566
	$(".grn-details").live('click',function(){
567
		var purchaseId = $(this).attr('data');
568
		console.log(purchaseId);
569
		loadGrnDetails(purchaseId,"grn-details-container");
570
	});
571
 
23076 ashik.ali 572
	$(".pending-grn-details").live('click',function(){
573
		console.log("pending-grn-details clicked");
574
		var orderId = $(this).attr('data');
575
		console.log("orderId : "+orderId);
576
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
577
	});
578
 
22245 ashik.ali 579
	$(".sale-details").live('click',function(){
580
		var orderId = $(this).attr('data');
22860 ashik.ali 581
		console.log("orderId = "+orderId);
22245 ashik.ali 582
		loadSaleDetails(orderId,"sale-details-container");
583
	});
584
 
22860 ashik.ali 585
	$(".scheme-details").live('click',function(){
586
		var schemeId = $(this).attr('data');
587
		console.log("schemeId = "+schemeId);
588
		loadSchemeDetails(schemeId, "scheme-details-container");
589
	});
590
 
21987 kshitij.so 591
	$(".pending-grn").live('click',function(){
592
		var purchaseReference = $(this).attr('data');
593
		console.log(purchaseReference);
594
		loadPendingGrnDetails(purchaseReference,"main-content");
595
	});
596
 
22860 ashik.ali 597
	$(".active-scheme").live('click',function(){
598
		var schemeId = $(this).attr('data');
599
		console.log("active-scheme id : "+schemeId);
600
		var start = $( "#schemes-paginated .start" ).text();
601
		//var end = $( "#schemes-paginated .end" ).text();
602
		var offset = start - 1;
603
		if(confirm("Are you sure you want to Active Scheme!") == true){
604
			activeScheme(schemeId, offset, "schemes-table");
605
		}
606
	});
607
 
608
	$(".expire-scheme").live('click',function(){
609
		var schemeId = $(this).attr('data');
610
		console.log("expire-scheme id : "+schemeId);
611
		var start = $( "#schemes-paginated .start" ).text();
612
		//var end = $( "#schemes-paginated .end" ).text();
613
		var offset = start - 1;
614
		if(confirm("Are you sure you want to Expire Scheme!") == true){
615
			expireScheme(schemeId, offset, "schemes-table");
616
		}
617
	});
618
 
21987 kshitij.so 619
	//add-to-bag
620
 
621
	$(".add-to-bag").live('click', function() {
622
		var itemId = $(this).attr('data');
623
		$("#bagModel .itemId").val(itemId);
624
		$("#bagModel .quantity").val(0);
625
		jQuery.ajax({
22092 amit.gupta 626
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 627
			type: 'GET',
628
			contentType:'application/json',
629
			async: false,
630
			success: function (data) {
631
				var obj = JSON.parse(data);
632
				console.log(obj);
633
				console.log(obj.displayName);
634
				$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
635
				$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
636
				$("#bagModel .availability").val(obj.availability);
637
			},
638
			cache: false,
639
			processData: false
640
		});
641
	});
642
 
643
	//addToBagButton
644
 
645
	$("#addToBagButton").live('click', function() {
646
		var itemId = $(this).attr('data');
647
		var itemId = $("#bagModel .itemId").val();
648
		var tempAvailability = $("#bagModel .availability").val();
649
		var quantity = $("#bagModel .quantity").val();
650
 
651
		if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1){
652
			alert("Please enter valid quantity");
653
			return;
654
		}
655
 
656
		jQuery.ajax({
22092 amit.gupta 657
			url: context+"/checkItemAvailability/?itemId="+itemId,
21987 kshitij.so 658
			type: 'GET',
659
			contentType:'application/json',
660
			async: false,
661
			success: function (data) {
662
				var obj = JSON.parse(data);
663
				console.log(obj);
664
				if (obj.availability < parseInt(quantity) || obj.availability == 0){
665
					alert("You don't have enough inventory of this item");
666
					return;
667
				}
668
				var obj = {'itemId':obj.itemId,'displayName':obj.displayName,'quantity':parseInt(quantity),'iconUrl':obj.iconUrl};
669
				console.log(obj);
670
				addItemInLocalStorage(obj);
671
				alert("Item added to bag successfully");
672
				$('#bagModel').modal('hide');
673
			},
674
			cache: false,
675
			processData: false
676
		});
677
	});
678
 
679
	$(".cart-trash").live('click',function(){
680
		var itemId = $(this).attr('data');
681
		removeItemFromLocalStorage(itemId);
682
		$('div[itemId="' + itemId + '"]').remove();
683
		if ($('#cart-details').html().trim() == ""){
684
			$('#cart-details-empty').show();
685
			$('#cart-checkout').hide();
686
		}
687
	});
688
 
689
	$(".cart-qty").live('change paste keyup mouseup', function() {
690
		var itemId = $(this).attr('data');
691
		var maxQty = $(this).attr('max');
692
		var qty = $(this).val();
693
		if (!qty){
694
			qty = 0;
695
		}
696
		if(parseInt(qty) < 0){
697
			alert("Invalid quantity");
698
			$(this).val(0);
699
			qty = 0;
700
		}
701
		if (parseInt(qty) > parseInt(maxQty)){
702
			alert("You don't have availability of "+qty);
703
			$(this).val(maxQty);
704
			qty = maxQty;
705
		}
706
		changeQuantityInLocalStorage(itemId, qty);
707
	});
708
 
22661 amit.gupta 709
	$("form#cd input.discountAmount").live('change paste keyup mouseup', function() {
710
		var discountAmount = parseFloat($(this).val());
711
		if (isNaN(discountAmount)){
712
			discountAmount = 0;
713
		}
714
		if(discountAmount < 0){
715
			alert("Invalid insurance Value");
716
			$(this).val(0);
717
		}
22662 amit.gupta 718
		calculateTotalAmount();
22661 amit.gupta 719
	});
720
 
21987 kshitij.so 721
	$("form#cd input.unitPrice").live('change paste keyup mouseup', function() {
22245 ashik.ali 722
 
22661 amit.gupta 723
		var unitPrice = parseFloat($(this).val());
724
		if (isNaN(unitPrice)){
21987 kshitij.so 725
			unitPrice = 0;
726
		}
22661 amit.gupta 727
		if(unitPrice < 0){
21987 kshitij.so 728
			alert("Invalid unit price");
729
			$(this).val(0);
730
		}
23340 ashik.ali 731
 
22661 amit.gupta 732
		calculateTotalAmount();
21987 kshitij.so 733
	});
22245 ashik.ali 734
 
735
 
736
	$("form#cd input.insuranceAmount").live('change paste keyup mouseup', function() {
22661 amit.gupta 737
		calculateTotalAmount();
738
	});
739
 
740
});
741
 
742
function calculateTotalAmount() {
743
	var netPayableAmount = 0;
744
	$("#cd").find('tr:gt(0)').each(function(index, el){
745
		var rowTotal = 0;
746
		$tr = $(el);
747
 
748
		var insuranceAmount = $tr.find('.insuranceAmount').val();
22245 ashik.ali 749
		if (!insuranceAmount){
750
			insuranceAmount = 0;
751
		}else{
752
			insuranceAmount = parseFloat(insuranceAmount);
753
		}
754
 
22661 amit.gupta 755
		var qty = parseFloat($(el).find('.unitPrice').attr('quantity'));
756
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
22245 ashik.ali 757
 
22661 amit.gupta 758
		var discountAmount =  parseFloat($(el).find('.discountAmount').val());
759
		if(isNaN(discountAmount)){
760
			discountAmount = 0;
761
		}
762
 
763
		rowTotal = unitPrice*qty + insuranceAmount - discountAmount; 
764
		$tr.find('.totalPrice').val(rowTotal);
765
		netPayableAmount += rowTotal;
22245 ashik.ali 766
	});
22661 amit.gupta 767
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
22982 ashik.ali 768
}
769
 
770
function updateRetailerDocument(){
771
	//$("#updateRetailerShopDocument0").click( function() {
772
	console.log("Update Retailer Document Clicked");
773
	//console.log(ownerId);
774
	var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
775
	console.log("emailIdOrMobileNumber: "+ emailIdOrMobileNumber);
776
	var file = $('#retailerDocument')[0].files[0];
777
	console.log("file : "+file.name);
778
	uploadRetailerDocument("retailer-details-container", file, emailIdOrMobileNumber);
779
}
780
 
781
function updateRetailerShopDocument(ownerId){
782
	//$("#updateRetailerShopDocument0").click( function() {
783
	console.log("Update Retailer Shop Document Clicked");
784
	console.log(ownerId);
785
	var shopSize = parseInt($("#shopDetailsSize").attr('size'));
786
	console.log("size : "+shopSize);
787
	for(var index = 0; index < shopSize; index++){
788
		if("updateRetailerShopDocument"+index == ownerId){
789
			var emailIdOrMobileNumber = $('#retailer-details-search-text').val();
790
			console.log("emailIdOrMobileNumber: "+ emailIdOrMobileNumber);
791
			var shopId = $('#retailerShopDocument'+index).attr("shopId");
792
			console.log("shopId : "+shopId);
793
			var file = $('#retailerShopDocument'+index)[0].files[0];
794
			console.log("file : "+file.name);
795
			uploadRetailerShopDocument("retailer-details-container", file, emailIdOrMobileNumber, shopId);
796
		}
797
	}
23026 ashik.ali 798
}
799
 
800
function updateDetails(){
801
 
22661 amit.gupta 802
}