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