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