Subversion Repositories SmartDukaan

Rev

Rev 21627 | Rev 22071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21627 Rev 21987
Line 53... Line 53...
53
            $('#' + domId).html(response);
53
            $('#' + domId).html(response);
54
        }
54
        }
55
    });  
55
    });  
56
}
56
}
57
 
57
 
-
 
58
function loadGoodInventory(domId, search_text){
-
 
59
	jQuery.ajax({
-
 
60
        type : "GET",
-
 
61
        url : context+"/getCurrentInventorySnapshot/?searchTerm="+search_text,
-
 
62
        success : function(response) {
-
 
63
            $('#' + domId).html(response);
-
 
64
        }
-
 
65
    });  
-
 
66
}
-
 
67
 
-
 
68
function loadCatalog(domId, search_text){
-
 
69
	jQuery.ajax({
-
 
70
        type : "GET",
-
 
71
        url : context+"/getCatalog/?searchTerm="+search_text,
-
 
72
        success : function(response) {
-
 
73
            $('#' + domId).html(response);
-
 
74
        }
-
 
75
    });  
-
 
76
}
-
 
77
 
-
 
78
function loadBadInventory(domId, search_text){
-
 
79
	jQuery.ajax({
-
 
80
        type : "GET",
-
 
81
        url : context+"/getBadInventorySnapshot/?searchTerm="+search_text,
-
 
82
        success : function(response) {
-
 
83
            $('#' + domId).html(response);
-
 
84
        }
-
 
85
    });  
-
 
86
}
-
 
87
 
-
 
88
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
-
 
89
	jQuery.ajax({
-
 
90
        type : "GET",
-
 
91
        url : context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
-
 
92
        +"&startTime="+startTime
-
 
93
        +"&endTime="+endTime,
-
 
94
        success : function(response) {
-
 
95
            $('#' + domId).html(response);
-
 
96
        }
-
 
97
    });  
-
 
98
}
-
 
99
 
-
 
100
function getNextItems(start, end, searchText){
-
 
101
	console.log(start);
-
 
102
	console.log(end);
-
 
103
	console.log(+end + +10);
-
 
104
	console.log(+start + +10);
-
 
105
	jQuery.ajax({
-
 
106
	        type : "GET",
-
 
107
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText,
-
 
108
			beforeSend: function(){
-
 
109
	        //$('#ajax-spinner').show();
-
 
110
	        },
-
 
111
	        complete: function(){
-
 
112
	        //$('#ajax-spinner').hide();
-
 
113
	        },
-
 
114
	        success : function(response) {
-
 
115
	        	$( "#good-inventory-paginated .end" ).text(+end + +10);
-
 
116
	        	$( "#good-inventory-paginated .start" ).text(+start + +10);
-
 
117
				var last = $( "#good-inventory-paginated .end" ).text();
-
 
118
				var temp = $( "#good-inventory-paginated .size" ).text();
-
 
119
				if (parseInt(last) >= parseInt(temp)){
-
 
120
					$("#good-inventory-paginated .next").prop('disabled', true);
-
 
121
					//$( "#good-inventory-paginated .end" ).text(temp);
-
 
122
				}
-
 
123
	            $('#good-inventory-table').html(response);
-
 
124
	            $("#good-inventory-paginated .previous").prop('disabled', false);
-
 
125
	        },
-
 
126
			error : function() {
-
 
127
				alert("Unable to fetch items");
-
 
128
			 },
-
 
129
	    });  
-
 
130
	}
-
 
131
function getPreviousItems(start,end,pre,searchText){
-
 
132
	jQuery.ajax({
-
 
133
	        type : "GET",
-
 
134
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText,
-
 
135
			beforeSend: function(){
-
 
136
	        //$('#ajax-spinner').show();
-
 
137
	        },
-
 
138
	        complete: function(){
-
 
139
	        //$('#ajax-spinner').hide();
-
 
140
	        },
-
 
141
	        success : function(response) {
-
 
142
	        	$( "#good-inventory-paginated .end" ).text(+end - +10);
-
 
143
	        	$( "#good-inventory-paginated .start" ).text(+start - +10);
-
 
144
	        	$('#good-inventory-table').html(response);
-
 
145
	        	$("#good-inventory-paginated .next").prop('disabled', false);
-
 
146
				if (parseInt(pre)==0)
-
 
147
				{
-
 
148
					$("#good-inventory-paginated .previous").prop('disabled', true);
-
 
149
				}
-
 
150
				
-
 
151
	        },
-
 
152
			error : function() {
-
 
153
				alert("Unable to fetch items");
-
 
154
			 },
-
 
155
	    });
-
 
156
}
-
 
157
 
-
 
158
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
-
 
159
	console.log(start);
-
 
160
	console.log(end);
-
 
161
	console.log(+end + +10);
-
 
162
	console.log(+start + +10);
-
 
163
	jQuery.ajax({
-
 
164
	        type : "GET",
-
 
165
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
-
 
166
	        +"&startTime="+startTime
-
 
167
	        +"&endTime="+endTime+"&offset="+end,
-
 
168
			beforeSend: function(){
-
 
169
	        //$('#ajax-spinner').show();
-
 
170
	        },
-
 
171
	        complete: function(){
-
 
172
	        //$('#ajax-spinner').hide();
-
 
173
	        },
-
 
174
	        success : function(response) {
-
 
175
	        	$( "#grn-history-paginated .end" ).text(+end + +10);
-
 
176
	        	$( "#grn-history-paginated .start" ).text(+start + +10);
-
 
177
				var last = $( "#grn-history-paginated .end" ).text();
-
 
178
				var temp = $( "#grn-history-paginated .size" ).text();
-
 
179
				if (parseInt(last) >= parseInt(temp)){
-
 
180
					$("#grn-history-paginated .next").prop('disabled', true);
-
 
181
					//$( "#good-inventory-paginated .end" ).text(temp);
-
 
182
				}
-
 
183
	            $('#grn-history-table').html(response);
-
 
184
	            $("#grn-history-paginated .previous").prop('disabled', false);
-
 
185
	        },
-
 
186
			error : function() {
-
 
187
				alert("Unable to fetch items");
-
 
188
			 },
-
 
189
	    });  
-
 
190
	}
-
 
191
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
-
 
192
	jQuery.ajax({
-
 
193
	        type : "GET",
-
 
194
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
-
 
195
	        +"&startTime="+startTime
-
 
196
	        +"&endTime="+endTime+"&offset="+pre,
-
 
197
			beforeSend: function(){
-
 
198
	        //$('#ajax-spinner').show();
-
 
199
	        },
-
 
200
	        complete: function(){
-
 
201
	        //$('#ajax-spinner').hide();
-
 
202
	        },
-
 
203
	        success : function(response) {
-
 
204
	        	$( "#grn-history-paginated .end" ).text(+end - +10);
-
 
205
	        	$( "#grn-history-paginated .start" ).text(+start - +10);
-
 
206
	        	$('#grn-history-table').html(response);
-
 
207
	        	$("#grn-history-paginated .next").prop('disabled', false);
-
 
208
				if (parseInt(pre)==0)
-
 
209
				{
-
 
210
					$("#grn-history-paginated .previous").prop('disabled', true);
-
 
211
				}
-
 
212
				
-
 
213
	        },
-
 
214
			error : function() {
-
 
215
				alert("Unable to fetch items");
-
 
216
			 },
-
 
217
	    });
-
 
218
}
-
 
219
 
-
 
220
function loadGoodInventorySearchInfo(search_text){
-
 
221
	loadGoodInventory("main-content",search_text);
-
 
222
}
-
 
223
 
-
 
224
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
-
 
225
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
-
 
226
}
-
 
227
 
58
function findDuplicateSerialNumbers(value){
228
function findDuplicateSerialNumbers(value){
59
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
229
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
60
    return result;
230
    return result;
61
}
231
}
-
 
232
 
-
 
233
function loadGrnDetails(purchaseId,domId){
-
 
234
	jQuery.ajax({
-
 
235
        type : "GET",
-
 
236
        url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
-
 
237
        success : function(response) {
-
 
238
            $('#' + domId).html(response);
-
 
239
            window.dispatchEvent(new Event('resize'));
-
 
240
        }
-
 
241
    });
-
 
242
}
-
 
243
 
-
 
244
function loadPendingGrnDetails(purchaseId,domId){
-
 
245
	jQuery.ajax({
-
 
246
		url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
-
 
247
		type: 'POST',
-
 
248
		async: false,
-
 
249
		success: function (data) {
-
 
250
			$('#'+domId).html(data);
-
 
251
		},
-
 
252
		error : function() {
-
 
253
			alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
-
 
254
		},
-
 
255
		cache: false,
-
 
256
		contentType: false,
-
 
257
		processData: false
-
 
258
	});
-
 
259
}
-
 
260
 
-
 
261
function getNextCatalogItems(start, end, searchText){
-
 
262
	console.log(start);
-
 
263
	console.log(end);
-
 
264
	console.log(+end + +10);
-
 
265
	console.log(+start + +10);
-
 
266
	jQuery.ajax({
-
 
267
	        type : "GET",
-
 
268
	        url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
-
 
269
			beforeSend: function(){
-
 
270
	        //$('#ajax-spinner').show();
-
 
271
	        },
-
 
272
	        complete: function(){
-
 
273
	        //$('#ajax-spinner').hide();
-
 
274
	        },
-
 
275
	        success : function(response) {
-
 
276
	        	$( "#catalog-paginated .end" ).text(+end + +10);
-
 
277
	        	$( "#catalog-paginated .start" ).text(+start + +10);
-
 
278
				var last = $( "#catalog-paginated .end" ).text();
-
 
279
				var temp = $( "#catalog-paginated .size" ).text();
-
 
280
				if (parseInt(last) >= parseInt(temp)){
-
 
281
					$("#catalog-paginated .next").prop('disabled', true);
-
 
282
				}
-
 
283
	            $('#catalog-table').html(response);
-
 
284
	            $("#catalog-paginated .previous").prop('disabled', false);
-
 
285
	        },
-
 
286
			error : function() {
-
 
287
				alert("Unable to fetch items");
-
 
288
			 },
-
 
289
	    });  
-
 
290
	}
-
 
291
function getPreviousCatalogItems(start,end,pre,searchText){
-
 
292
	jQuery.ajax({
-
 
293
	        type : "GET",
-
 
294
	        url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
-
 
295
			beforeSend: function(){
-
 
296
	        //$('#ajax-spinner').show();
-
 
297
	        },
-
 
298
	        complete: function(){
-
 
299
	        //$('#ajax-spinner').hide();
-
 
300
	        },
-
 
301
	        success : function(response) {
-
 
302
	        	$( "#catalog-paginated .end" ).text(+end - +10);
-
 
303
	        	$( "#catalog-paginated .start" ).text(+start - +10);
-
 
304
	        	$('#catalog-table').html(response);
-
 
305
	        	$("#catalog-paginated .next").prop('disabled', false);
-
 
306
				if (parseInt(pre)==0)
-
 
307
				{
-
 
308
					$("#catalog-paginated .previous").prop('disabled', true);
-
 
309
				}
-
 
310
				
-
 
311
	        },
-
 
312
			error : function() {
-
 
313
				alert("Unable to fetch items");
-
 
314
			 },
-
 
315
	    });
-
 
316
}
-
 
317
 
-
 
318
function loadCatalogSearchInfo(search_text){
-
 
319
	loadCatalog("main-content",search_text);
-
 
320
}
-
 
321
 
-
 
322
function addItemInLocalStorage(bagObj){
-
 
323
	if (localStorage.getItem("bag")!=null){
-
 
324
		var bag = JSON.parse(localStorage.getItem("bag"));
-
 
325
		bag[bagObj.itemId] = bagObj
-
 
326
		localStorage.setItem("bag",JSON.stringify(bag));
-
 
327
		bag = localStorage.getItem("bag")
-
 
328
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
-
 
329
	}
-
 
330
	else{
-
 
331
		var tempObj = {};
-
 
332
		tempObj[bagObj.itemId] = bagObj
-
 
333
		localStorage.setItem("bag",JSON.stringify(tempObj));
-
 
334
		var bag = localStorage.getItem("bag")
-
 
335
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
-
 
336
	}
-
 
337
}
-
 
338
 
-
 
339
 
-
 
340
function changeQuantityInLocalStorage(itemId, newQuantity){
-
 
341
	var bag = JSON.parse(localStorage.getItem("bag"));
-
 
342
	bag[itemId].quantity = newQuantity;
-
 
343
	localStorage.setItem("bag",JSON.stringify(bag));
-
 
344
}
-
 
345
 
-
 
346
function removeItemFromLocalStorage(itemId){
-
 
347
	if (localStorage.getItem("bag")!=null){
-
 
348
		var bag = JSON.parse(localStorage.getItem("bag"));
-
 
349
		delete bag[itemId];
-
 
350
		localStorage.setItem("bag",JSON.stringify(bag));
-
 
351
		$("#cart_bar").find('span').text(Object.keys(bag).length);
-
 
352
	}
-
 
353
}
-
 
354
 
-
 
355
function emptyBag(){
-
 
356
	localStorage.removeItem("bag");
-
 
357
	$("#cart_bar").find('span').text(0);
-
 
358
}
-
 
359
 
-
 
360
function loadCart(domId){
-
 
361
	jQuery.ajax({
-
 
362
        type : "POST",
-
 
363
        data: {"cartData":localStorage.getItem("bag")},
-
 
364
        url : context+"/cart",
-
 
365
        success : function(response) {
-
 
366
            $('#' + domId).html(response);
-
 
367
        }
-
 
368
    });  
-
 
369
}
-
 
370
 
-
 
371
function checkout(domId){
-
 
372
	jQuery.ajax({
-
 
373
        type : "POST",
-
 
374
        data: {"cartData":localStorage.getItem("bag")},
-
 
375
        url : context+"/validate-cart",
-
 
376
        success : function(response) {
-
 
377
        	var obj = JSON.parse(response);
-
 
378
        	redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
-
 
379
        }
-
 
380
    });  
-
 
381
}
-
 
382
 
-
 
383
function redirectCart(url, cartData, method, domId){
-
 
384
	jQuery.ajax({
-
 
385
        type : method,
-
 
386
        data: {"cartData":cartData},
-
 
387
        url : context+url,
-
 
388
        success : function(response) {
-
 
389
            $('#' + domId).html(response);
-
 
390
            window.dispatchEvent(new Event('resize'));
-
 
391
        }
-
 
392
    });  
-
 
393
}
-
 
394
 
-
 
395
function validateOrderDetails(){
-
 
396
	var sNumbers = [];
-
 
397
	var error = false;
-
 
398
	$("form#cd input.serialNumber").each(function(){
-
 
399
		var input = $(this).val().trim();
-
 
400
		$(this).removeClass("border-highlight");
-
 
401
		if (sNumbers.indexOf(input) !=-1 || !input){
-
 
402
			error = true;
-
 
403
			$(this).addClass("border-highlight");
-
 
404
		}
-
 
405
		sNumbers.push(input);
-
 
406
	});
-
 
407
	
-
 
408
	$("form#cd input.unitPrice").each(function(){
-
 
409
		var input = $(this).val().trim();
-
 
410
		$(this).removeClass("border-highlight");
-
 
411
		if (!input || parseInt(input)<=0 || isNaN(input)){
-
 
412
			error=true;
-
 
413
			$(this).addClass("border-highlight");
-
 
414
		}
-
 
415
	});
-
 
416
	
-
 
417
	var amount = 0;
-
 
418
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
-
 
419
	
-
 
420
	
-
 
421
	$("form#cd input.amount").each(function(){
-
 
422
		if ($(this).val() ==""){
-
 
423
			$(this).val(0);
-
 
424
		}
-
 
425
		var tmpAmount = parseFloat($(this).val());
-
 
426
		amount = amount + tmpAmount;
-
 
427
	});
-
 
428
	
-
 
429
	console.log(amount);
-
 
430
	console.log(netPayableAmount);
-
 
431
	
-
 
432
	if (amount!=netPayableAmount){
-
 
433
		alert("Mismatch in amount");
-
 
434
		error = true;
-
 
435
	}
-
 
436
	
-
 
437
	if (error){
-
 
438
		return false;
-
 
439
	}
-
 
440
	return true;
-
 
441
	
-
 
442
}
-
 
443
 
-
 
444
function orderDetailsPayload(){
-
 
445
		var orderObj = {};
-
 
446
		var priceQtyArray = [];
-
 
447
		var customerObj = {};
-
 
448
		var paymentOption = [];
-
 
449
		
-
 
450
		$("form#cd input.serialNumber").each(function(){
-
 
451
			var itemId = parseInt($(this).attr("itemId"));
-
 
452
			if (orderObj.hasOwnProperty('fofoLineItems')){
-
 
453
				var itemDetails = orderObj['fofoLineItems'];
-
 
454
				if (itemDetails.hasOwnProperty(itemId)){
-
 
455
					var serialNumbers = itemDetails[itemId];
-
 
456
					serialNumbers.push($(this).val());
-
 
457
					itemDetails[itemId] = serialNumbers;
-
 
458
				}
-
 
459
				else{
-
 
460
					var serialNumbers = [];
-
 
461
					serialNumbers.push($(this).val());
-
 
462
					itemDetails[itemId] = serialNumbers;
-
 
463
				}
-
 
464
			}
-
 
465
			else{
-
 
466
				var serialNumbers = [];
-
 
467
				serialNumbers.push($(this).val());
-
 
468
				var tmp ={};
-
 
469
				tmp[itemId]  = serialNumbers;
-
 
470
				orderObj['fofoLineItems'] = tmp;
-
 
471
			}
-
 
472
		});
-
 
473
		console.log( JSON.stringify(orderObj));
-
 
474
		$("form#cd input.unitPrice").each(function(){
-
 
475
			var itemId = parseInt($(this).attr("itemId"));
-
 
476
			var unitPrice = parseFloat($(this).val());
-
 
477
			var qty = parseInt($(this).attr("quantity"));
-
 
478
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
-
 
479
			if (orderObj['fofoLineItems'][itemId] ===undefined){
-
 
480
				tmpObj['serialNumbers'] =[]
-
 
481
			}
-
 
482
			else{
-
 
483
				tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
-
 
484
			}
-
 
485
			priceQtyArray.push(tmpObj);
-
 
486
		});
-
 
487
		console.log( JSON.stringify(priceQtyArray));
-
 
488
		
-
 
489
		//customer-details
-
 
490
		/*$("#customer-details input").each(function(){
-
 
491
			console.log($(this).attr('name'));
-
 
492
			customerObj[$(this).attr('name')] = $(this).val();
-
 
493
		});*/
-
 
494
		//$("input[name=nameGoesHere]").val();
-
 
495
		customerObj['name'] = $("form#cd input[name=name]").val(); 
-
 
496
		customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
-
 
497
		customerObj['emailId'] = $("form#cd input[name=email]").val();
-
 
498
		var customerAddress = {};
-
 
499
		customerAddress['name'] = $("form#cd input[name=name]").val();
-
 
500
		customerAddress['line1'] = $("form#cd input[name=line1]").val();
-
 
501
		customerAddress['line2'] = $("form#cd input[name=line2]").val();
-
 
502
		customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
-
 
503
		customerAddress['city'] = $("form#cd input[name=city]").val();
-
 
504
		customerAddress['state'] = $('select[name=state] option:selected').val();
-
 
505
		customerAddress['pinCode'] = $("form#cd input[name=pincode]").val();
-
 
506
		customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
-
 
507
		customerAddress['country'] = "India";
-
 
508
		customerObj['address'] = customerAddress; 
-
 
509
		console.log( JSON.stringify(customerObj));
-
 
510
		$("#payment-details input").each(function(){
-
 
511
		console.log($(this).attr('name'));
-
 
512
		if ($(this).attr('name') =="" ){
-
 
513
			return;
-
 
514
		}
-
 
515
		var paymentObj = {};
-
 
516
		paymentObj['type'] = $(this).attr('name');
-
 
517
		if ($(this).val() == ""){
-
 
518
			paymentObj['amount'] = 0.0;
-
 
519
		}
-
 
520
		else{
-
 
521
			paymentObj['amount'] = parseFloat($(this).val());
-
 
522
		}
-
 
523
		paymentOption.push(paymentObj);
-
 
524
		});
-
 
525
		console.log( JSON.stringify(paymentOption));
-
 
526
		
-
 
527
		var retObj = {};
-
 
528
		retObj['fofoLineItems'] = (priceQtyArray);
-
 
529
		retObj['customer'] = (customerObj);
-
 
530
		retObj['paymentOptions'] =  (paymentOption);
-
 
531
		console.log(retObj);
-
 
532
		return  JSON.stringify(retObj);
-
 
533
}