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