Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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