Subversion Repositories SmartDukaan

Rev

Rev 22292 | Rev 22488 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21627 kshitij.so 1
var googleProfile;
2
 
22139 amit.gupta 3
 
4
$(document).ajaxComplete(
5
	function(){
6
 
7
	}
8
);
21627 kshitij.so 9
var startApp = function() {
10
  gapi.load('auth2', function(){
11
    // Retrieve the singleton for the GoogleAuth library and set up the client.
12
    auth2 = gapi.auth2.init({
22071 ashik.ali 13
      client_id: googleApiKey,
21627 kshitij.so 14
      cookiepolicy: 'single_host_origin',
15
      // Request scopes in addition to 'profile' and 'email'
16
      //scope: 'additional_scope'
17
    });
18
    attachSignin(document.getElementById('customBtn'));
19
  });
20
};
21
 
22
function attachSignin(element) {
23
    console.log(element.id);
24
    auth2.attachClickHandler(element, {},
25
        function(googleUser) {
26
    		googleProfile = googleUser.getBasicProfile();
27
        	console.log(googleProfile.getImageUrl());
28
        	submitUser(googleUser);
29
        }, function(error) {
30
          console.log(JSON.stringify(error, undefined, 2));
31
        });
32
  }
33
 
34
function submitUser(googleUser){
35
	jQuery.ajax({
36
        type : "POST",
22090 amit.gupta 37
        url : context+"/login",
22139 amit.gupta 38
        dataType: 'json',
21627 kshitij.so 39
        data: {"token":googleUser.getAuthResponse().id_token},
40
        success: function(data, textStatus, request){
41
        	console.log(data);
42
        	addProfileInLocalDb();
22139 amit.gupta 43
        	window.location.href= data.redirectUrl;
21627 kshitij.so 44
   		}
45
    });  
46
}
47
 
48
function addProfileInLocalDb(){
49
	var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
50
	localStorage.setItem("profile",JSON.stringify(profile));
51
}
52
 
53
 
54
function loadNewGrn(domId){
55
	jQuery.ajax({
56
        type : "GET",
22091 amit.gupta 57
        url : context+"/purchase",
21627 kshitij.so 58
        success : function(response) {
59
            $('#' + domId).html(response);
60
        }
61
    });  
62
}
63
 
21987 kshitij.so 64
function loadGoodInventory(domId, search_text){
65
	jQuery.ajax({
66
        type : "GET",
22091 amit.gupta 67
        url : context+"/getCurrentInventorySnapshot/?searchTerm="+search_text,
21987 kshitij.so 68
        success : function(response) {
69
            $('#' + domId).html(response);
70
        }
71
    });  
72
}
73
 
74
function loadCatalog(domId, search_text){
75
	jQuery.ajax({
76
        type : "GET",
22091 amit.gupta 77
        url : context+"/getCatalog/?searchTerm="+search_text,
21987 kshitij.so 78
        success : function(response) {
79
            $('#' + domId).html(response);
80
        }
81
    });  
82
}
83
 
84
function loadBadInventory(domId, search_text){
85
	jQuery.ajax({
86
        type : "GET",
22090 amit.gupta 87
        url : context+"/getBadInventorySnapshot/?searchTerm="+search_text,
21987 kshitij.so 88
        success : function(response) {
89
            $('#' + domId).html(response);
90
        }
91
    });  
92
}
93
 
94
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
95
	jQuery.ajax({
96
        type : "GET",
22090 amit.gupta 97
        url : context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 98
        +"&startTime="+startTime
99
        +"&endTime="+endTime,
100
        success : function(response) {
101
            $('#' + domId).html(response);
102
        }
103
    });  
104
}
105
 
22245 ashik.ali 106
 
107
 
22283 ashik.ali 108
 
109
 
21987 kshitij.so 110
function getNextItems(start, end, searchText){
111
	console.log(start);
112
	console.log(end);
113
	console.log(+end + +10);
114
	console.log(+start + +10);
115
	jQuery.ajax({
116
	        type : "GET",
22090 amit.gupta 117
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText,
21987 kshitij.so 118
			beforeSend: function(){
119
	        //$('#ajax-spinner').show();
120
	        },
121
	        complete: function(){
122
	        //$('#ajax-spinner').hide();
123
	        },
124
	        success : function(response) {
125
	        	$( "#good-inventory-paginated .end" ).text(+end + +10);
126
	        	$( "#good-inventory-paginated .start" ).text(+start + +10);
127
				var last = $( "#good-inventory-paginated .end" ).text();
128
				var temp = $( "#good-inventory-paginated .size" ).text();
129
				if (parseInt(last) >= parseInt(temp)){
130
					$("#good-inventory-paginated .next").prop('disabled', true);
131
					//$( "#good-inventory-paginated .end" ).text(temp);
132
				}
133
	            $('#good-inventory-table').html(response);
134
	            $("#good-inventory-paginated .previous").prop('disabled', false);
135
	        },
136
			error : function() {
137
				alert("Unable to fetch items");
138
			 },
139
	    });  
140
	}
141
function getPreviousItems(start,end,pre,searchText){
142
	jQuery.ajax({
143
	        type : "GET",
22090 amit.gupta 144
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText,
21987 kshitij.so 145
			beforeSend: function(){
146
	        //$('#ajax-spinner').show();
147
	        },
148
	        complete: function(){
149
	        //$('#ajax-spinner').hide();
150
	        },
151
	        success : function(response) {
152
	        	$( "#good-inventory-paginated .end" ).text(+end - +10);
153
	        	$( "#good-inventory-paginated .start" ).text(+start - +10);
154
	        	$('#good-inventory-table').html(response);
155
	        	$("#good-inventory-paginated .next").prop('disabled', false);
156
				if (parseInt(pre)==0)
157
				{
158
					$("#good-inventory-paginated .previous").prop('disabled', true);
159
				}
160
 
161
	        },
162
			error : function() {
163
				alert("Unable to fetch items");
164
			 },
165
	    });
166
}
167
 
168
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
169
	console.log(start);
170
	console.log(end);
171
	console.log(+end + +10);
172
	console.log(+start + +10);
173
	jQuery.ajax({
174
	        type : "GET",
22090 amit.gupta 175
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 176
	        +"&startTime="+startTime
177
	        +"&endTime="+endTime+"&offset="+end,
178
			beforeSend: function(){
179
	        //$('#ajax-spinner').show();
180
	        },
181
	        complete: function(){
182
	        //$('#ajax-spinner').hide();
183
	        },
184
	        success : function(response) {
185
	        	$( "#grn-history-paginated .end" ).text(+end + +10);
186
	        	$( "#grn-history-paginated .start" ).text(+start + +10);
187
				var last = $( "#grn-history-paginated .end" ).text();
188
				var temp = $( "#grn-history-paginated .size" ).text();
189
				if (parseInt(last) >= parseInt(temp)){
190
					$("#grn-history-paginated .next").prop('disabled', true);
191
					//$( "#good-inventory-paginated .end" ).text(temp);
192
				}
193
	            $('#grn-history-table').html(response);
194
	            $("#grn-history-paginated .previous").prop('disabled', false);
195
	        },
196
			error : function() {
197
				alert("Unable to fetch items");
198
			 },
199
	    });  
200
	}
201
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
202
	jQuery.ajax({
203
	        type : "GET",
22090 amit.gupta 204
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 205
	        +"&startTime="+startTime
206
	        +"&endTime="+endTime+"&offset="+pre,
207
			beforeSend: function(){
208
	        //$('#ajax-spinner').show();
209
	        },
210
	        complete: function(){
211
	        //$('#ajax-spinner').hide();
212
	        },
213
	        success : function(response) {
214
	        	$( "#grn-history-paginated .end" ).text(+end - +10);
215
	        	$( "#grn-history-paginated .start" ).text(+start - +10);
216
	        	$('#grn-history-table').html(response);
217
	        	$("#grn-history-paginated .next").prop('disabled', false);
218
				if (parseInt(pre)==0)
219
				{
220
					$("#grn-history-paginated .previous").prop('disabled', true);
221
				}
222
 
223
	        },
224
			error : function() {
225
				alert("Unable to fetch items");
226
			 },
227
	    });
228
}
229
 
22292 ashik.ali 230
function getSaleHistoryNextItems(start, end, invoiceNumber, searchType, startTime, endTime){
231
	console.log(start);
232
	console.log(end);
233
	console.log(+end + +10);
234
	console.log(+start + +10);
235
	jQuery.ajax({
236
	        type : "GET",
237
	        url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
238
	        +"&startTime="+startTime
239
	        +"&endTime="+endTime+"&offset="+end,
240
			beforeSend: function(){
241
	        //$('#ajax-spinner').show();
242
	        },
243
	        complete: function(){
244
	        //$('#ajax-spinner').hide();
245
	        },
246
	        success : function(response) {
247
	        	$( "#sale-history-paginated .end" ).text(+end + +10);
248
	        	$( "#sale-history-paginated .start" ).text(+start + +10);
249
				var last = $( "#sale-history-paginated .end" ).text();
250
				var temp = $( "#sale-history-paginated .size" ).text();
251
				if (parseInt(last) >= parseInt(temp)){
252
					$("#sale-history-paginated .next").prop('disabled', true);
253
					//$( "#good-inventory-paginated .end" ).text(temp);
254
				}
255
	            $('#sale-history-table').html(response);
256
	            $("#sale-history-paginated .previous").prop('disabled', false);
257
	        },
258
			error : function() {
259
				alert("Unable to fetch items");
260
			 },
261
	    });  
262
	}
263
function getSaleHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
264
	jQuery.ajax({
265
	        type : "GET",
266
	        url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
267
	        +"&startTime="+startTime
268
	        +"&endTime="+endTime+"&offset="+pre,
269
			beforeSend: function(){
270
	        //$('#ajax-spinner').show();
271
	        },
272
	        complete: function(){
273
	        //$('#ajax-spinner').hide();
274
	        },
275
	        success : function(response) {
276
	        	$( "#sale-history-paginated .end" ).text(+end - +10);
277
	        	$( "#sale-history-paginated .start" ).text(+start - +10);
278
	        	$('#sale-history-table').html(response);
279
	        	$("#sale-history-paginated .next").prop('disabled', false);
280
				if (parseInt(pre)==0)
281
				{
282
					$("#sale-history-paginated .previous").prop('disabled', true);
283
				}
284
	        },
285
			error : function() {
286
				alert("Unable to fetch items");
287
			 },
288
	    });
289
}
290
 
21987 kshitij.so 291
function loadGoodInventorySearchInfo(search_text){
292
	loadGoodInventory("main-content",search_text);
293
}
294
 
295
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
296
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
297
}
298
 
21627 kshitij.so 299
function findDuplicateSerialNumbers(value){
300
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
301
    return result;
302
}
21987 kshitij.so 303
 
304
function loadGrnDetails(purchaseId,domId){
305
	jQuery.ajax({
306
        type : "GET",
22090 amit.gupta 307
        url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
21987 kshitij.so 308
        success : function(response) {
309
            $('#' + domId).html(response);
310
            window.dispatchEvent(new Event('resize'));
311
        }
312
    });
313
}
314
 
22245 ashik.ali 315
function loadSaleDetails(orderId, domId){
316
	jQuery.ajax({
317
        type : "GET",
318
        url : context+"/saleDetails?orderId="+orderId,
319
        success : function(response) {
320
            $('#' + domId).html(response);
321
            window.dispatchEvent(new Event('resize'));
322
        }
323
    });
324
}
325
 
21987 kshitij.so 326
function loadPendingGrnDetails(purchaseId,domId){
327
	jQuery.ajax({
22090 amit.gupta 328
		url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
21987 kshitij.so 329
		type: 'POST',
330
		async: false,
331
		success: function (data) {
332
			$('#'+domId).html(data);
333
		},
334
		error : function() {
335
			alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
336
		},
337
		cache: false,
338
		contentType: false,
339
		processData: false
340
	});
341
}
342
 
343
function getNextCatalogItems(start, end, searchText){
344
	console.log(start);
345
	console.log(end);
346
	console.log(+end + +10);
347
	console.log(+start + +10);
348
	jQuery.ajax({
349
	        type : "GET",
22090 amit.gupta 350
	        url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
21987 kshitij.so 351
			beforeSend: function(){
352
	        //$('#ajax-spinner').show();
353
	        },
354
	        complete: function(){
355
	        //$('#ajax-spinner').hide();
356
	        },
357
	        success : function(response) {
358
	        	$( "#catalog-paginated .end" ).text(+end + +10);
359
	        	$( "#catalog-paginated .start" ).text(+start + +10);
360
				var last = $( "#catalog-paginated .end" ).text();
361
				var temp = $( "#catalog-paginated .size" ).text();
362
				if (parseInt(last) >= parseInt(temp)){
363
					$("#catalog-paginated .next").prop('disabled', true);
364
				}
365
	            $('#catalog-table').html(response);
366
	            $("#catalog-paginated .previous").prop('disabled', false);
367
	        },
368
			error : function() {
369
				alert("Unable to fetch items");
370
			 },
371
	    });  
372
	}
373
function getPreviousCatalogItems(start,end,pre,searchText){
374
	jQuery.ajax({
375
	        type : "GET",
22090 amit.gupta 376
	        url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
21987 kshitij.so 377
			beforeSend: function(){
378
	        //$('#ajax-spinner').show();
379
	        },
380
	        complete: function(){
381
	        //$('#ajax-spinner').hide();
382
	        },
383
	        success : function(response) {
384
	        	$( "#catalog-paginated .end" ).text(+end - +10);
385
	        	$( "#catalog-paginated .start" ).text(+start - +10);
386
	        	$('#catalog-table').html(response);
387
	        	$("#catalog-paginated .next").prop('disabled', false);
388
				if (parseInt(pre)==0)
389
				{
390
					$("#catalog-paginated .previous").prop('disabled', true);
391
				}
392
 
393
	        },
394
			error : function() {
395
				alert("Unable to fetch items");
396
			 },
397
	    });
398
}
399
 
400
function loadCatalogSearchInfo(search_text){
401
	loadCatalog("main-content",search_text);
402
}
403
 
404
function addItemInLocalStorage(bagObj){
405
	if (localStorage.getItem("bag")!=null){
406
		var bag = JSON.parse(localStorage.getItem("bag"));
407
		bag[bagObj.itemId] = bagObj
408
		localStorage.setItem("bag",JSON.stringify(bag));
409
		bag = localStorage.getItem("bag")
410
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
411
	}
412
	else{
413
		var tempObj = {};
414
		tempObj[bagObj.itemId] = bagObj
415
		localStorage.setItem("bag",JSON.stringify(tempObj));
416
		var bag = localStorage.getItem("bag")
417
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
418
	}
419
}
420
 
421
 
422
function changeQuantityInLocalStorage(itemId, newQuantity){
423
	var bag = JSON.parse(localStorage.getItem("bag"));
424
	bag[itemId].quantity = newQuantity;
425
	localStorage.setItem("bag",JSON.stringify(bag));
426
}
427
 
428
function removeItemFromLocalStorage(itemId){
429
	if (localStorage.getItem("bag")!=null){
430
		var bag = JSON.parse(localStorage.getItem("bag"));
431
		delete bag[itemId];
432
		localStorage.setItem("bag",JSON.stringify(bag));
433
		$("#cart_bar").find('span').text(Object.keys(bag).length);
434
	}
435
}
436
 
437
function emptyBag(){
22095 kshitij.so 438
	localStorage.setItem("bag",JSON.stringify({}));
21987 kshitij.so 439
	$("#cart_bar").find('span').text(0);
440
}
441
 
442
function loadCart(domId){
443
	jQuery.ajax({
444
        type : "POST",
445
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 446
        url : context+"/cart",
21987 kshitij.so 447
        success : function(response) {
448
            $('#' + domId).html(response);
449
        }
450
    });  
451
}
452
 
453
function checkout(domId){
454
	jQuery.ajax({
22095 kshitij.so 455
        type : "GET",
21987 kshitij.so 456
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 457
        url : context+"/validate-cart",
21987 kshitij.so 458
        success : function(response) {
459
        	var obj = JSON.parse(response);
460
        	redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
22095 kshitij.so 461
        	$('#main-content').html(response);
21987 kshitij.so 462
        }
22245 ashik.ali 463
    });
21987 kshitij.so 464
}
465
 
466
function redirectCart(url, cartData, method, domId){
467
	jQuery.ajax({
468
        type : method,
469
        data: {"cartData":cartData},
470
        url : context+url,
471
        success : function(response) {
472
            $('#' + domId).html(response);
473
            window.dispatchEvent(new Event('resize'));
474
        }
475
    });  
476
}
477
 
22245 ashik.ali 478
function saleHistory(domId, invoiceNumber, searchType, startTime, endTime){
479
	jQuery.ajax({
480
        type : "GET",
481
        url : context+"/saleHistory?invoiceNumber="+invoiceNumber+"&searchType="+searchType
482
        +"&startTime="+startTime
483
        +"&endTime="+endTime,
484
        success : function(response) {
485
            $('#' + domId).html(response);
486
        }
487
    });  
488
}
489
 
22354 ashik.ali 490
 
491
function contactUs(domId){
492
	jQuery.ajax({
493
        type : "GET",
494
        url : context+"/contactUs",
495
        success : function(response) {
496
            $('#' + domId).html(response);
497
        }
498
    });  
499
}
500
 
501
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
502
	jQuery.ajax({
503
        type : "GET",
504
        url : context+"/customer/mobileNumber?mobileNumber="+mobileNumber,
505
        success : function(response) {
506
        	console.log("response"+response);
507
        	var customer = response.response;
508
            $('#firstName').attr('value', customer.firstName);
509
            $('#lastName').attr('value', customer.lastName);
510
            $('#email').attr('value', customer.emailId);
511
            $('#phone').attr('value', customer.mobileNumber);
512
            $('#alternatePhone').attr('value', customer.address.phoneNumber);
513
            $('#line1').attr('value', customer.address.line1);
514
            $('#line2').attr('value', customer.address.line2);
515
            $('#landmark').attr('value', customer.address.landmark);
516
            $('#pinCode').attr('value', customer.address.pinCode);
517
            $('#city').attr('value', customer.address.city);
518
            $('#state').attr('value', customer.address.state);
519
        }
520
    });  
521
}
522
 
22283 ashik.ali 523
function saleHistorySearchInfo(search_text, searchType, startTime, endTime){
524
	saleHistory("main-content", search_text, searchType, startTime, endTime);
525
}
22245 ashik.ali 526
 
22283 ashik.ali 527
 
21987 kshitij.so 528
function validateOrderDetails(){
529
	var sNumbers = [];
530
	var error = false;
531
	$("form#cd input.serialNumber").each(function(){
532
		var input = $(this).val().trim();
22245 ashik.ali 533
		var itemType = $(this).attr("itemType");
21987 kshitij.so 534
		$(this).removeClass("border-highlight");
22245 ashik.ali 535
		if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
21987 kshitij.so 536
			error = true;
537
			$(this).addClass("border-highlight");
538
		}
539
		sNumbers.push(input);
540
	});
541
 
542
	$("form#cd input.unitPrice").each(function(){
543
		var input = $(this).val().trim();
544
		$(this).removeClass("border-highlight");
545
		if (!input || parseInt(input)<=0 || isNaN(input)){
546
			error=true;
547
			$(this).addClass("border-highlight");
548
		}
549
	});
550
 
551
	var amount = 0;
552
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
553
 
554
 
555
	$("form#cd input.amount").each(function(){
22354 ashik.ali 556
		if ($(this).val() == ""){
21987 kshitij.so 557
			$(this).val(0);
558
		}
559
		var tmpAmount = parseFloat($(this).val());
560
		amount = amount + tmpAmount;
561
	});
562
 
563
	console.log(amount);
564
	console.log(netPayableAmount);
565
 
22354 ashik.ali 566
	if (amount != netPayableAmount){
567
		if(amount < netPayableAmount){
568
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
569
		}else{
570
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
571
		}
572
		$("form#cd input.netPayableAmount").each(function(){
573
			$(this).addClass("border-highlight");
574
		});
21987 kshitij.so 575
		error = true;
576
	}
577
 
578
	if (error){
579
		return false;
580
	}
581
	return true;
582
 
583
}
584
 
585
function orderDetailsPayload(){
586
		var orderObj = {};
587
		var priceQtyArray = [];
588
		var customerObj = {};
589
		var paymentOption = [];
590
 
591
		$("form#cd input.serialNumber").each(function(){
592
			var itemId = parseInt($(this).attr("itemId"));
593
			if (orderObj.hasOwnProperty('fofoLineItems')){
594
				var itemDetails = orderObj['fofoLineItems'];
595
				if (itemDetails.hasOwnProperty(itemId)){
596
					var serialNumbers = itemDetails[itemId];
597
					serialNumbers.push($(this).val());
598
					itemDetails[itemId] = serialNumbers;
22245 ashik.ali 599
				}else{
21987 kshitij.so 600
					var serialNumbers = [];
601
					serialNumbers.push($(this).val());
602
					itemDetails[itemId] = serialNumbers;
603
				}
22245 ashik.ali 604
			}else{
21987 kshitij.so 605
				var serialNumbers = [];
606
				serialNumbers.push($(this).val());
607
				var tmp ={};
608
				tmp[itemId]  = serialNumbers;
609
				orderObj['fofoLineItems'] = tmp;
610
			}
611
		});
612
		console.log( JSON.stringify(orderObj));
613
		$("form#cd input.unitPrice").each(function(){
614
			var itemId = parseInt($(this).attr("itemId"));
615
			var unitPrice = parseFloat($(this).val());
616
			var qty = parseInt($(this).attr("quantity"));
617
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
22245 ashik.ali 618
			if (orderObj['fofoLineItems'][itemId] === undefined){
619
				tmpObj['serialNumberDetails'] =[];
21987 kshitij.so 620
			}
621
			else{
22245 ashik.ali 622
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
623
				tmpObj['serialNumberDetails'] = [];
21987 kshitij.so 624
			}
22245 ashik.ali 625
			var found = false;
626
			for(var i = 0; i < priceQtyArray.length; i++){			
627
				if (priceQtyArray[i]["itemId"] == itemId){
628
					found = true;
629
					break;
630
				}
631
			}
632
			if(!found){
633
				priceQtyArray.push(tmpObj);
634
			}
21987 kshitij.so 635
		});
636
 
22245 ashik.ali 637
 
22254 ashik.ali 638
		var insurance = false;
639
 
22245 ashik.ali 640
		$("#order-details").find("tr:not(:first-child)").each(function(index,el){
641
			//console.log(el);
642
			//console.log(index);
643
			var $serialNumberElement = $(el).find('.serialNumber');
644
			var itemId = parseInt($serialNumberElement.attr("itemId"));
645
			var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
646
			//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
647
 
648
			//}
649
			//console.log($serialNumberElement.val());
650
			//console.log(itemId);
651
			for(var i = 0; i < priceQtyArray.length; i++){
652
				console.log(priceQtyArray[i]["itemId"]);			
653
				if (priceQtyArray[i]["itemId"] == itemId){
654
					if(insuranceAmount > 0){
655
						insurance = true;
656
					}
657
					var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
658
					priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
659
				}
660
            }
661
 
662
		});
663
 
664
		console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
21987 kshitij.so 665
		//customer-details
666
		/*$("#customer-details input").each(function(){
667
			console.log($(this).attr('name'));
668
			customerObj[$(this).attr('name')] = $(this).val();
669
		});*/
670
		//$("input[name=nameGoesHere]").val();
22245 ashik.ali 671
		customerObj['firstName'] = $("form#cd input[name=firstName]").val();
672
		customerObj['lastName'] = $("form#cd input[name=lastName]").val();
21987 kshitij.so 673
		customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
674
		customerObj['emailId'] = $("form#cd input[name=email]").val();
22245 ashik.ali 675
		customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth").val();
21987 kshitij.so 676
		var customerAddress = {};
22245 ashik.ali 677
		customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
21987 kshitij.so 678
		customerAddress['line1'] = $("form#cd input[name=line1]").val();
679
		customerAddress['line2'] = $("form#cd input[name=line2]").val();
680
		customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
681
		customerAddress['city'] = $("form#cd input[name=city]").val();
682
		customerAddress['state'] = $('select[name=state] option:selected').val();
22245 ashik.ali 683
		customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
21987 kshitij.so 684
		customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
685
		customerAddress['country'] = "India";
686
		customerObj['address'] = customerAddress; 
687
		console.log( JSON.stringify(customerObj));
688
		$("#payment-details input").each(function(){
689
		console.log($(this).attr('name'));
690
		if ($(this).attr('name') =="" ){
691
			return;
692
		}
693
		var paymentObj = {};
694
		paymentObj['type'] = $(this).attr('name');
695
		if ($(this).val() == ""){
696
			paymentObj['amount'] = 0.0;
697
		}
698
		else{
699
			paymentObj['amount'] = parseFloat($(this).val());
700
		}
701
		paymentOption.push(paymentObj);
702
		});
703
		console.log( JSON.stringify(paymentOption));
704
 
705
		var retObj = {};
22254 ashik.ali 706
		var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
707
		if(insurance){
708
			retObj['customerDateOfBirth'] = (dateOfBirth)
709
		}
21987 kshitij.so 710
		retObj['fofoLineItems'] = (priceQtyArray);
711
		retObj['customer'] = (customerObj);
712
		retObj['paymentOptions'] =  (paymentOption);
22254 ashik.ali 713
 
21987 kshitij.so 714
		console.log(retObj);
715
		return  JSON.stringify(retObj);
716
}