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