Subversion Repositories SmartDukaan

Rev

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

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