Subversion Repositories SmartDukaan

Rev

Rev 22860 | Rev 22982 | 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
 
22956 ashik.ali 22
function badRequestAlert(response){
23
	console.log(response.responseText);
24
	var errorObject = JSON.parse(response.responseText);
25
	errorObject = errorObject.response;
26
	alert('Bad Request\n'+
27
			'rejectedType : '+errorObject.rejectedType+'\n'+
28
			'rejectedValue : '+errorObject.rejectedValue+'\n'+
29
			'message : '+errorObject.message);
30
}
31
 
32
function internalServerErrorAlert(response){
33
	console.log(response.responseText);
34
	var errorObject = JSON.parse(response.responseText);
35
	errorObject = errorObject.response;
36
	alert('Internal Server Error\n'+
37
		'rejectedType : '+errorObject.rejectedType+'\n'+
38
		'rejectedValue : '+errorObject.rejectedValue+'\n'+
39
		'message : '+errorObject.message);
40
}
41
 
42
$( document ).ajaxError(function(event, jqxhr, settings, thrownError) {
43
	//$( ".log" ).text( "Triggered ajaxError handler." );
44
	if(jqxhr.status == 400){
45
		$('#error-prompt-model').modal();
46
		badRequestAlert(jqxhr);	
47
	}else{
48
		internalServerErrorAlert(jqxhr);
49
	}
50
});
51
 
21627 kshitij.so 52
function attachSignin(element) {
53
    console.log(element.id);
54
    auth2.attachClickHandler(element, {},
55
        function(googleUser) {
56
    		googleProfile = googleUser.getBasicProfile();
57
        	console.log(googleProfile.getImageUrl());
58
        	submitUser(googleUser);
59
        }, function(error) {
60
          console.log(JSON.stringify(error, undefined, 2));
61
        });
62
  }
63
 
64
function submitUser(googleUser){
65
	jQuery.ajax({
66
        type : "POST",
22090 amit.gupta 67
        url : context+"/login",
22139 amit.gupta 68
        dataType: 'json',
21627 kshitij.so 69
        data: {"token":googleUser.getAuthResponse().id_token},
70
        success: function(data, textStatus, request){
71
        	console.log(data);
72
        	addProfileInLocalDb();
22139 amit.gupta 73
        	window.location.href= data.redirectUrl;
21627 kshitij.so 74
   		}
75
    });  
76
}
77
 
78
function addProfileInLocalDb(){
79
	var profile = {'image_url':googleProfile.getImageUrl(),'name':googleProfile.getName()};
80
	localStorage.setItem("profile",JSON.stringify(profile));
81
}
82
 
83
 
84
function loadNewGrn(domId){
85
	jQuery.ajax({
86
        type : "GET",
22091 amit.gupta 87
        url : context+"/purchase",
21627 kshitij.so 88
        success : function(response) {
89
            $('#' + domId).html(response);
90
        }
91
    });  
92
}
93
 
21987 kshitij.so 94
function loadGoodInventory(domId, search_text){
95
	jQuery.ajax({
96
        type : "GET",
22091 amit.gupta 97
        url : context+"/getCurrentInventorySnapshot/?searchTerm="+search_text,
21987 kshitij.so 98
        success : function(response) {
99
            $('#' + domId).html(response);
100
        }
101
    });  
102
}
103
 
104
function loadCatalog(domId, search_text){
105
	jQuery.ajax({
106
        type : "GET",
22091 amit.gupta 107
        url : context+"/getCatalog/?searchTerm="+search_text,
21987 kshitij.so 108
        success : function(response) {
109
            $('#' + domId).html(response);
110
        }
111
    });  
112
}
113
 
22523 ashik.ali 114
function getInventoryItemAgingByInterval(domId, searchContent){
115
	jQuery.ajax({
116
        type : "POST",
117
        url : context+"/getInventoryItemAgingByInterval?searchContent="+searchContent,
118
        cache: false,
119
        contentType: "application/json",
120
        processData: false,
121
        async: false,
122
        data : JSON.stringify([5,15,30,45]),
123
        success : function(response) {
124
            $('#' + domId).html(response);
22956 ashik.ali 125
        }
22523 ashik.ali 126
    });  
127
}
128
 
22488 ashik.ali 129
function downloadAgingReport(){
22523 ashik.ali 130
	data = JSON.stringify([5,15,30,45]),
22488 ashik.ali 131
	xhttp = new XMLHttpRequest();
132
	xhttp.onreadystatechange = function() {
133
	    var a;
134
	    if (xhttp.readyState === 4 && xhttp.status === 200) {
135
	        // Trick for making downloadable link
136
	        a = document.createElement('a');
137
	        a.href = window.URL.createObjectURL(xhttp.response);
138
	        // Give filename you wish to download
139
	        a.download = "InventoryItemAging.xlsx";
140
	        a.style.display = 'none';
141
	        document.body.appendChild(a);
142
	        a.click();
143
	    }
22956 ashik.ali 144
	    if(xhttp.readyState == 4 && xhttp.status === 400){
145
	    	badRequestAlert(xhttp.responseText);
146
	    }
147
	    if(xhttp.readyState == 4 && xhttp.status === 500){
148
	    	internalServerErrorAlert(xhttp.responseText);
149
	    }
22488 ashik.ali 150
	};
151
	// Post data to URL which handles post request
152
	xhttp.open("POST", context+"/getInventoryItemAgingByInterval");
153
	xhttp.setRequestHeader("Content-Type", "application/json");
154
	// You should set responseType as blob for binary responses
155
	xhttp.responseType = 'blob';
156
	xhttp.send(data);
157
}
158
 
22523 ashik.ali 159
function downloadItemLedgerReport(){
160
	//data = JSON.stringify([5,10,15,20,25,30,35,40]),
161
	xhttp = new XMLHttpRequest();
162
	xhttp.onreadystatechange = function() {
163
	    var a;
164
	    if (xhttp.readyState === 4 && xhttp.status === 200) {
165
	        // Trick for making downloadable link
166
	        a = document.createElement('a');
167
	        a.href = window.URL.createObjectURL(xhttp.response);
168
	        // Give filename you wish to download
169
	        a.download = "ItemCompleteLedegerReport.xlsx";
170
	        a.style.display = 'none';
171
	        document.body.appendChild(a);
172
	        a.click();
173
	    }
22956 ashik.ali 174
	    if(xhttp.readyState == 4 && xhttp.status === 400){
175
	    	badRequestAlert(xhttp.responseText);
176
	    }
177
	    if(xhttp.readyState == 4 && xhttp.status === 500){
178
	    	internalServerErrorAlert(xhttp.responseText);
179
	    }
22523 ashik.ali 180
	};
181
	// Post data to URL which handles post request
182
	xhttp.open("GET", context+"/itemLedger/complete/download");
183
	//xhttp.setRequestHeader("Content-Type", "application/json");
184
	// You should set responseType as blob for binary responses
185
	xhttp.responseType = 'blob';
186
	xhttp.send(null);
187
}
188
 
189
function getItemAgingNextPreviousItems(offset, searchContent){
190
 
191
	jQuery.ajax({
192
		type : "POST",
193
        url : context+"/getInventoryItemAgingByInterval?offset="+offset+"&searchContent="+searchContent,
194
        cache: false,
195
        contentType: "application/json",
196
        processData: false,
197
        async: false,
198
        data : JSON.stringify([5,15,30,45]),
199
		beforeSend: function(){
200
			//$('#ajax-spinner').show();
201
        },
202
        complete: function(){
203
        	//$('#ajax-spinner').hide();
204
        },
205
        success : function(response) {
206
        	$('#main-content').html(response);
22956 ashik.ali 207
        }
22523 ashik.ali 208
    });
209
}
210
 
211
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
212
	jQuery.ajax({
213
	        type : "GET",
214
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
215
	        +"&startTime="+startTime
216
	        +"&endTime="+endTime+"&offset="+pre,
217
			beforeSend: function(){
218
	        //$('#ajax-spinner').show();
219
	        },
220
	        complete: function(){
221
	        //$('#ajax-spinner').hide();
222
	        },
223
	        success : function(response) {
224
	        	$( "#grn-history-paginated .end" ).text(+end - +10);
225
	        	$( "#grn-history-paginated .start" ).text(+start - +10);
226
	        	$('#grn-history-table').html(response);
227
	        	$("#grn-history-paginated .next").prop('disabled', false);
228
				if (parseInt(pre)==0)
229
				{
230
					$("#grn-history-paginated .previous").prop('disabled', true);
231
				}
232
 
22956 ashik.ali 233
	        }
22523 ashik.ali 234
	    });
235
}
236
 
21987 kshitij.so 237
function loadBadInventory(domId, search_text){
238
	jQuery.ajax({
239
        type : "GET",
22090 amit.gupta 240
        url : context+"/getBadInventorySnapshot/?searchTerm="+search_text,
21987 kshitij.so 241
        success : function(response) {
242
            $('#' + domId).html(response);
243
        }
244
    });  
245
}
246
 
247
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
248
	jQuery.ajax({
249
        type : "GET",
22090 amit.gupta 250
        url : context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 251
        +"&startTime="+startTime
252
        +"&endTime="+endTime,
253
        success : function(response) {
254
            $('#' + domId).html(response);
255
        }
256
    });  
257
}
258
 
22245 ashik.ali 259
 
21987 kshitij.so 260
function getNextItems(start, end, searchText){
261
	console.log(start);
262
	console.log(end);
263
	console.log(+end + +10);
264
	console.log(+start + +10);
265
	jQuery.ajax({
266
	        type : "GET",
22090 amit.gupta 267
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText,
21987 kshitij.so 268
			beforeSend: function(){
269
	        //$('#ajax-spinner').show();
270
	        },
271
	        complete: function(){
272
	        //$('#ajax-spinner').hide();
273
	        },
274
	        success : function(response) {
275
	        	$( "#good-inventory-paginated .end" ).text(+end + +10);
276
	        	$( "#good-inventory-paginated .start" ).text(+start + +10);
277
				var last = $( "#good-inventory-paginated .end" ).text();
278
				var temp = $( "#good-inventory-paginated .size" ).text();
279
				if (parseInt(last) >= parseInt(temp)){
280
					$("#good-inventory-paginated .next").prop('disabled', true);
281
					//$( "#good-inventory-paginated .end" ).text(temp);
282
				}
283
	            $('#good-inventory-table').html(response);
284
	            $("#good-inventory-paginated .previous").prop('disabled', false);
22956 ashik.ali 285
	        }
21987 kshitij.so 286
	    });  
287
	}
288
function getPreviousItems(start,end,pre,searchText){
289
	jQuery.ajax({
290
	        type : "GET",
22090 amit.gupta 291
	        url : context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText,
21987 kshitij.so 292
			beforeSend: function(){
293
	        //$('#ajax-spinner').show();
294
	        },
295
	        complete: function(){
296
	        //$('#ajax-spinner').hide();
297
	        },
298
	        success : function(response) {
299
	        	$( "#good-inventory-paginated .end" ).text(+end - +10);
300
	        	$( "#good-inventory-paginated .start" ).text(+start - +10);
301
	        	$('#good-inventory-table').html(response);
302
	        	$("#good-inventory-paginated .next").prop('disabled', false);
303
				if (parseInt(pre)==0)
304
				{
305
					$("#good-inventory-paginated .previous").prop('disabled', true);
306
				}
307
 
22956 ashik.ali 308
	        }
21987 kshitij.so 309
	    });
310
}
311
 
312
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
313
	console.log(start);
314
	console.log(end);
315
	console.log(+end + +10);
316
	console.log(+start + +10);
317
	jQuery.ajax({
318
	        type : "GET",
22090 amit.gupta 319
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 320
	        +"&startTime="+startTime
321
	        +"&endTime="+endTime+"&offset="+end,
322
			beforeSend: function(){
323
	        //$('#ajax-spinner').show();
324
	        },
325
	        complete: function(){
326
	        //$('#ajax-spinner').hide();
327
	        },
328
	        success : function(response) {
329
	        	$( "#grn-history-paginated .end" ).text(+end + +10);
330
	        	$( "#grn-history-paginated .start" ).text(+start + +10);
331
				var last = $( "#grn-history-paginated .end" ).text();
332
				var temp = $( "#grn-history-paginated .size" ).text();
333
				if (parseInt(last) >= parseInt(temp)){
334
					$("#grn-history-paginated .next").prop('disabled', true);
335
					//$( "#good-inventory-paginated .end" ).text(temp);
336
				}
337
	            $('#grn-history-table').html(response);
338
	            $("#grn-history-paginated .previous").prop('disabled', false);
22956 ashik.ali 339
	        }
21987 kshitij.so 340
	    });  
341
	}
342
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
343
	jQuery.ajax({
344
	        type : "GET",
22090 amit.gupta 345
	        url : context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
21987 kshitij.so 346
	        +"&startTime="+startTime
347
	        +"&endTime="+endTime+"&offset="+pre,
348
			beforeSend: function(){
349
	        //$('#ajax-spinner').show();
350
	        },
351
	        complete: function(){
352
	        //$('#ajax-spinner').hide();
353
	        },
354
	        success : function(response) {
355
	        	$( "#grn-history-paginated .end" ).text(+end - +10);
356
	        	$( "#grn-history-paginated .start" ).text(+start - +10);
357
	        	$('#grn-history-table').html(response);
358
	        	$("#grn-history-paginated .next").prop('disabled', false);
359
				if (parseInt(pre)==0)
360
				{
361
					$("#grn-history-paginated .previous").prop('disabled', true);
362
				}
363
 
22956 ashik.ali 364
	        }
21987 kshitij.so 365
	    });
366
}
367
 
22292 ashik.ali 368
function getSaleHistoryNextItems(start, end, invoiceNumber, searchType, startTime, endTime){
369
	console.log(start);
370
	console.log(end);
371
	console.log(+end + +10);
372
	console.log(+start + +10);
373
	jQuery.ajax({
374
	        type : "GET",
375
	        url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
376
	        +"&startTime="+startTime
377
	        +"&endTime="+endTime+"&offset="+end,
378
			beforeSend: function(){
379
	        //$('#ajax-spinner').show();
380
	        },
381
	        complete: function(){
382
	        //$('#ajax-spinner').hide();
383
	        },
384
	        success : function(response) {
385
	        	$( "#sale-history-paginated .end" ).text(+end + +10);
386
	        	$( "#sale-history-paginated .start" ).text(+start + +10);
387
				var last = $( "#sale-history-paginated .end" ).text();
388
				var temp = $( "#sale-history-paginated .size" ).text();
389
				if (parseInt(last) >= parseInt(temp)){
390
					$("#sale-history-paginated .next").prop('disabled', true);
391
					//$( "#good-inventory-paginated .end" ).text(temp);
392
				}
393
	            $('#sale-history-table').html(response);
394
	            $("#sale-history-paginated .previous").prop('disabled', false);
22956 ashik.ali 395
	        }
22292 ashik.ali 396
	    });  
397
	}
398
function getSaleHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
399
	jQuery.ajax({
400
	        type : "GET",
401
	        url : context+"/getPaginatedSaleHistory/?invoiceNumber="+invoiceNumber+"&searchType="+searchType
402
	        +"&startTime="+startTime
403
	        +"&endTime="+endTime+"&offset="+pre,
404
			beforeSend: function(){
405
	        //$('#ajax-spinner').show();
406
	        },
407
	        complete: function(){
408
	        //$('#ajax-spinner').hide();
409
	        },
410
	        success : function(response) {
411
	        	$( "#sale-history-paginated .end" ).text(+end - +10);
412
	        	$( "#sale-history-paginated .start" ).text(+start - +10);
413
	        	$('#sale-history-table').html(response);
414
	        	$("#sale-history-paginated .next").prop('disabled', false);
415
				if (parseInt(pre)==0)
416
				{
417
					$("#sale-history-paginated .previous").prop('disabled', true);
418
				}
22956 ashik.ali 419
	        }
22292 ashik.ali 420
	    });
421
}
422
 
22551 ashik.ali 423
 
22860 ashik.ali 424
function getSchemesNextItems(start, end){
425
	console.log(start);
426
	console.log(end);
427
	console.log(+end + +10);
428
	console.log(+start + +10);
429
	jQuery.ajax({
430
	        type : "GET",
431
	        url : context+"/getPaginatedSchemes?offset="+end,
432
			beforeSend: function(){
433
	        //$('#ajax-spinner').show();
434
	        },
435
	        complete: function(){
436
	        //$('#ajax-spinner').hide();
437
	        },
438
	        success : function(response) {
439
	        	$( "#schemes-paginated .end" ).text(+end + +10);
440
	        	$( "#schemes-paginated .start" ).text(+start + +10);
441
				var last = $( "#schemes-paginated .end" ).text();
442
				var temp = $( "#schemes-paginated .size" ).text();
443
				if (parseInt(last) >= parseInt(temp)){
444
					$("#schemes-paginated .next").prop('disabled', true);
445
					//$( "#good-inventory-paginated .end" ).text(temp);
446
				}
447
	            $('#schemes-table').html(response);
448
	            $('#scheme-details-container').html('');
449
	            $("#schemes-paginated .previous").prop('disabled', false);
22956 ashik.ali 450
	        }
22860 ashik.ali 451
	    });  
452
	}
22551 ashik.ali 453
 
22860 ashik.ali 454
 
455
function getSchemesPreviousItems(start, end, pre){
456
	jQuery.ajax({
457
	        type : "GET",
458
	        url : context+"/getPaginatedSchemes/?offset="+pre,
459
			beforeSend: function(){
460
	        //$('#ajax-spinner').show();
461
	        },
462
	        complete: function(){
463
	        //$('#ajax-spinner').hide();
464
	        },
465
	        success : function(response) {
466
	        	$( "#schemes-paginated .end" ).text(+end - +10);
467
	        	$( "#schemes-paginated .start" ).text(+start - +10);
468
	        	$('#schemes-table').html(response);
469
	        	$('#scheme-details-container').html('');
470
	        	$("#schemes-paginated .next").prop('disabled', false);
471
				if (parseInt(pre)==0)
472
				{
473
					$("#schemes-paginated .previous").prop('disabled', true);
474
				}
22956 ashik.ali 475
	        }
22860 ashik.ali 476
	    });
477
}
478
 
479
 
480
 
22551 ashik.ali 481
function getWalletHistoryNextItems(start, end, startTime, endTime){
482
	console.log(start);
483
	console.log(end);
484
	console.log(+end + +10);
485
	console.log(+start + +10);
486
	jQuery.ajax({
487
	        type : "GET",
488
	        url : context+"/getPaginatedWalletHistory?startTime="+startTime
489
	        +"&endTime="+endTime+"&offset="+end,
490
			beforeSend: function(){
491
	        //$('#ajax-spinner').show();
492
	        },
493
	        complete: function(){
494
	        //$('#ajax-spinner').hide();
495
	        },
496
	        success : function(response) {
497
	        	$( "#wallet-history-paginated .end" ).text(+end + +10);
498
	        	$( "#wallet-history-paginated .start" ).text(+start + +10);
499
				var last = $( "#wallet-history-paginated .end" ).text();
500
				var temp = $( "#wallet-history-paginated .size" ).text();
501
				if (parseInt(last) >= parseInt(temp)){
502
					$("#wallet-history-paginated .next").prop('disabled', true);
503
					//$( "#good-inventory-paginated .end" ).text(temp);
504
				}
505
	            $('#wallet-history-table').html(response);
506
	            $("#wallet-history-paginated .previous").prop('disabled', false);
22956 ashik.ali 507
	        }
22551 ashik.ali 508
	    });  
509
	}
22860 ashik.ali 510
function getWalletHistoryPreviousItems(start, end, pre, startTime, endTime){
22551 ashik.ali 511
	jQuery.ajax({
512
	        type : "GET",
513
	        url : context+"/getPaginatedWalletHistory?startTime="+startTime
514
	        +"&endTime="+endTime+"&offset="+pre,
515
			beforeSend: function(){
516
	        //$('#ajax-spinner').show();
517
	        },
518
	        complete: function(){
519
	        //$('#ajax-spinner').hide();
520
	        },
521
	        success : function(response) {
522
	        	$( "#wallet-history-paginated .end" ).text(+end - +10);
523
	        	$( "#wallet-history-paginated .start" ).text(+start - +10);
524
	        	$('#wallet-history-table').html(response);
525
	        	$("#wallet-history-paginated .next").prop('disabled', false);
526
				if (parseInt(pre)==0)
527
				{
528
					$("#wallet-history-paginated .previous").prop('disabled', true);
529
				}
22956 ashik.ali 530
	        }
22551 ashik.ali 531
	    });
532
}
533
 
21987 kshitij.so 534
function loadGoodInventorySearchInfo(search_text){
535
	loadGoodInventory("main-content",search_text);
536
}
537
 
538
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
539
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
540
}
541
 
21627 kshitij.so 542
function findDuplicateSerialNumbers(value){
543
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
544
    return result;
545
}
21987 kshitij.so 546
 
547
function loadGrnDetails(purchaseId,domId){
548
	jQuery.ajax({
549
        type : "GET",
22090 amit.gupta 550
        url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
21987 kshitij.so 551
        success : function(response) {
552
            $('#' + domId).html(response);
553
            window.dispatchEvent(new Event('resize'));
554
        }
555
    });
556
}
557
 
22245 ashik.ali 558
function loadSaleDetails(orderId, domId){
559
	jQuery.ajax({
560
        type : "GET",
561
        url : context+"/saleDetails?orderId="+orderId,
562
        success : function(response) {
563
            $('#' + domId).html(response);
22860 ashik.ali 564
            //window.dispatchEvent(new Event('resize'));
565
        }
566
    });
567
}
568
 
569
function loadSchemeDetails(schemeId, domId){
570
	jQuery.ajax({
571
        type : "GET",
572
        url : context+"/getSchemeById?schemeId="+schemeId,
573
        success : function(response) {
574
            $('#' + domId).html(response);
22245 ashik.ali 575
            window.dispatchEvent(new Event('resize'));
576
        }
577
    });
578
}
579
 
22860 ashik.ali 580
function activeScheme(schemeId, offset, domId){
581
	jQuery.ajax({
582
        type : "PUT",
583
        url : context+"/activeSchemeById?schemeId="+schemeId
584
        +"&offset="+offset,
585
        success : function(response) {
586
            $('#' + domId).html(response);
587
            $('#scheme-details-container').html('');
588
        }
589
    });
590
}
591
 
592
function expireScheme(schemeId, offset, domId){
593
	jQuery.ajax({
594
        type : "PUT",
595
        url : context+"/expireSchemeById?schemeId="+schemeId
596
        +"&offset="+offset,
597
        success : function(response) {
598
            $('#' + domId).html(response);
599
            $('#scheme-details-container').html('');
600
        }
601
    });
602
}
603
 
21987 kshitij.so 604
function loadPendingGrnDetails(purchaseId,domId){
605
	jQuery.ajax({
22090 amit.gupta 606
		url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
21987 kshitij.so 607
		type: 'POST',
608
		async: false,
609
		success: function (data) {
610
			$('#'+domId).html(data);
611
		},
612
		cache: false,
613
		contentType: false,
614
		processData: false
615
	});
616
}
617
 
618
function getNextCatalogItems(start, end, searchText){
619
	console.log(start);
620
	console.log(end);
621
	console.log(+end + +10);
622
	console.log(+start + +10);
623
	jQuery.ajax({
624
	        type : "GET",
22090 amit.gupta 625
	        url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
21987 kshitij.so 626
			beforeSend: function(){
627
	        //$('#ajax-spinner').show();
628
	        },
629
	        complete: function(){
630
	        //$('#ajax-spinner').hide();
631
	        },
632
	        success : function(response) {
633
	        	$( "#catalog-paginated .end" ).text(+end + +10);
634
	        	$( "#catalog-paginated .start" ).text(+start + +10);
635
				var last = $( "#catalog-paginated .end" ).text();
636
				var temp = $( "#catalog-paginated .size" ).text();
637
				if (parseInt(last) >= parseInt(temp)){
638
					$("#catalog-paginated .next").prop('disabled', true);
639
				}
640
	            $('#catalog-table').html(response);
641
	            $("#catalog-paginated .previous").prop('disabled', false);
22956 ashik.ali 642
	        }
21987 kshitij.so 643
	    });  
644
	}
645
function getPreviousCatalogItems(start,end,pre,searchText){
646
	jQuery.ajax({
647
	        type : "GET",
22090 amit.gupta 648
	        url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
21987 kshitij.so 649
			beforeSend: function(){
650
	        //$('#ajax-spinner').show();
651
	        },
652
	        complete: function(){
653
	        //$('#ajax-spinner').hide();
654
	        },
655
	        success : function(response) {
656
	        	$( "#catalog-paginated .end" ).text(+end - +10);
657
	        	$( "#catalog-paginated .start" ).text(+start - +10);
658
	        	$('#catalog-table').html(response);
659
	        	$("#catalog-paginated .next").prop('disabled', false);
660
				if (parseInt(pre)==0)
661
				{
662
					$("#catalog-paginated .previous").prop('disabled', true);
663
				}
664
 
22956 ashik.ali 665
	        }
21987 kshitij.so 666
	    });
667
}
668
 
669
function loadCatalogSearchInfo(search_text){
670
	loadCatalog("main-content",search_text);
671
}
672
 
673
function addItemInLocalStorage(bagObj){
674
	if (localStorage.getItem("bag")!=null){
675
		var bag = JSON.parse(localStorage.getItem("bag"));
676
		bag[bagObj.itemId] = bagObj
677
		localStorage.setItem("bag",JSON.stringify(bag));
678
		bag = localStorage.getItem("bag")
679
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
680
	}
681
	else{
682
		var tempObj = {};
683
		tempObj[bagObj.itemId] = bagObj
684
		localStorage.setItem("bag",JSON.stringify(tempObj));
685
		var bag = localStorage.getItem("bag")
686
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
687
	}
688
}
689
 
690
 
691
function changeQuantityInLocalStorage(itemId, newQuantity){
692
	var bag = JSON.parse(localStorage.getItem("bag"));
693
	bag[itemId].quantity = newQuantity;
694
	localStorage.setItem("bag",JSON.stringify(bag));
695
}
696
 
697
function removeItemFromLocalStorage(itemId){
698
	if (localStorage.getItem("bag")!=null){
699
		var bag = JSON.parse(localStorage.getItem("bag"));
700
		delete bag[itemId];
701
		localStorage.setItem("bag",JSON.stringify(bag));
702
		$("#cart_bar").find('span').text(Object.keys(bag).length);
703
	}
704
}
705
 
706
function emptyBag(){
22095 kshitij.so 707
	localStorage.setItem("bag",JSON.stringify({}));
21987 kshitij.so 708
	$("#cart_bar").find('span').text(0);
709
}
710
 
711
function loadCart(domId){
712
	jQuery.ajax({
713
        type : "POST",
714
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 715
        url : context+"/cart",
21987 kshitij.so 716
        success : function(response) {
717
            $('#' + domId).html(response);
718
        }
719
    });  
720
}
721
 
22551 ashik.ali 722
function loadWallet(domId, startTime, endTime){
723
	jQuery.ajax({
724
        type : "GET",
725
        //data: {"cartData":localStorage.getItem("bag")},
726
        url : context+"/walletDetails?startTime="+startTime
727
        +"&endTime="+endTime,
728
        success : function(response) {
729
            $('#' + domId).html(response);
730
        }
731
    });  
732
}
733
 
21987 kshitij.so 734
function checkout(domId){
735
	jQuery.ajax({
22095 kshitij.so 736
        type : "GET",
21987 kshitij.so 737
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 738
        url : context+"/validate-cart",
21987 kshitij.so 739
        success : function(response) {
740
        	var obj = JSON.parse(response);
741
        	redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
22095 kshitij.so 742
        	$('#main-content').html(response);
21987 kshitij.so 743
        }
22245 ashik.ali 744
    });
21987 kshitij.so 745
}
746
 
22860 ashik.ali 747
function loadScheme(domId){
748
	jQuery.ajax({
749
        type : "GET",
750
        url : context+"/createScheme",
751
        success : function(response) {
752
        	$('#main-content').html(response);
753
        }
754
    });
755
}
756
 
21987 kshitij.so 757
function redirectCart(url, cartData, method, domId){
758
	jQuery.ajax({
759
        type : method,
760
        data: {"cartData":cartData},
761
        url : context+url,
762
        success : function(response) {
763
            $('#' + domId).html(response);
764
            window.dispatchEvent(new Event('resize'));
765
        }
766
    });  
767
}
768
 
22245 ashik.ali 769
function saleHistory(domId, invoiceNumber, searchType, startTime, endTime){
770
	jQuery.ajax({
771
        type : "GET",
772
        url : context+"/saleHistory?invoiceNumber="+invoiceNumber+"&searchType="+searchType
773
        +"&startTime="+startTime
774
        +"&endTime="+endTime,
775
        success : function(response) {
776
            $('#' + domId).html(response);
777
        }
778
    });  
779
}
780
 
22860 ashik.ali 781
function schemes(domId){
782
	jQuery.ajax({
783
        type : "GET",
784
        url : context+"/getSchemes",
785
        success : function(response) {
786
            $('#' + domId).html(response);
787
        }
788
    });  
789
}
22354 ashik.ali 790
 
22860 ashik.ali 791
 
22354 ashik.ali 792
function contactUs(domId){
793
	jQuery.ajax({
794
        type : "GET",
795
        url : context+"/contactUs",
796
        success : function(response) {
797
            $('#' + domId).html(response);
798
        }
799
    });  
800
}
801
 
802
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
803
	jQuery.ajax({
804
        type : "GET",
805
        url : context+"/customer/mobileNumber?mobileNumber="+mobileNumber,
806
        success : function(response) {
22860 ashik.ali 807
        	console.log("response"+JSON.stringify(response));
22354 ashik.ali 808
        	var customer = response.response;
809
            $('#firstName').attr('value', customer.firstName);
810
            $('#lastName').attr('value', customer.lastName);
811
            $('#email').attr('value', customer.emailId);
22860 ashik.ali 812
            //$('#phone').attr('value', customer.mobileNumber);
22354 ashik.ali 813
            $('#alternatePhone').attr('value', customer.address.phoneNumber);
814
            $('#line1').attr('value', customer.address.line1);
815
            $('#line2').attr('value', customer.address.line2);
816
            $('#landmark').attr('value', customer.address.landmark);
817
            $('#pinCode').attr('value', customer.address.pinCode);
818
            $('#city').attr('value', customer.address.city);
22860 ashik.ali 819
            $('#state').attr('value', customer.address.state).prop('selected',true);
820
            //$('#state').val(customer.address.state).prop('selected', true);
821
            $('#phone').attr('addressId', customer.address.id);
822
            console.log("customerAddressId : ", customer.address.id);
22354 ashik.ali 823
        }
824
    });  
825
}
826
 
22283 ashik.ali 827
function saleHistorySearchInfo(search_text, searchType, startTime, endTime){
828
	saleHistory("main-content", search_text, searchType, startTime, endTime);
829
}
22245 ashik.ali 830
 
22551 ashik.ali 831
function walletHistoryDateSearchSearchInfo(startTime, endTime){
832
 
833
}
22283 ashik.ali 834
 
22551 ashik.ali 835
 
21987 kshitij.so 836
function validateOrderDetails(){
837
	var sNumbers = [];
838
	var error = false;
839
	$("form#cd input.serialNumber").each(function(){
840
		var input = $(this).val().trim();
22245 ashik.ali 841
		var itemType = $(this).attr("itemType");
21987 kshitij.so 842
		$(this).removeClass("border-highlight");
22245 ashik.ali 843
		if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
21987 kshitij.so 844
			error = true;
845
			$(this).addClass("border-highlight");
846
		}
847
		sNumbers.push(input);
848
	});
849
 
850
	$("form#cd input.unitPrice").each(function(){
851
		var input = $(this).val().trim();
852
		$(this).removeClass("border-highlight");
853
		if (!input || parseInt(input)<=0 || isNaN(input)){
854
			error=true;
855
			$(this).addClass("border-highlight");
856
		}
857
	});
858
 
22581 ashik.ali 859
	// checking input discountAmount is not greater than maxDiscountAmount
860
	$("form#cd input.discountAmount").each(function(){
861
		var input = $(this).val().trim();
862
		var mop = $(this).attr("mop");
22860 ashik.ali 863
 
22581 ashik.ali 864
		if(mop){
22860 ashik.ali 865
			var maxDiscountPriceRangeString = $(this).attr("placeholder");
866
			var maxDiscountPrice = 0;
867
			if(maxDiscountPriceRangeString != undefined && maxDiscountPriceRangeString != ''){
868
				maxDiscountPrice = maxDiscountPriceRangeString.substring(6);
869
			}
22581 ashik.ali 870
			$(this).removeClass("border-highlight");
871
			if (!input || parseFloat(input)<0 || isNaN(input)){
872
				alert("DiscountAmount value can not be lesser than 0 or invalid value");
873
				error=true;
874
				$(this).addClass("border-highlight");
875
			}
876
			if(parseFloat(input) > maxDiscountPrice){
22655 ashik.ali 877
				alert("DiscountAmount [" + parseFloat(input) + "] value can not be greater than the suggested maxDiscountPrice [" + maxDiscountPrice + "]");
22581 ashik.ali 878
				error=true;
879
				$(this).addClass("border-highlight");
880
			}
881
		}
882
	});
883
 
21987 kshitij.so 884
	var amount = 0;
885
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
886
 
887
 
888
	$("form#cd input.amount").each(function(){
22354 ashik.ali 889
		if ($(this).val() == ""){
21987 kshitij.so 890
			$(this).val(0);
891
		}
892
		var tmpAmount = parseFloat($(this).val());
893
		amount = amount + tmpAmount;
894
	});
895
 
896
	console.log(amount);
897
	console.log(netPayableAmount);
898
 
22354 ashik.ali 899
	if (amount != netPayableAmount){
900
		if(amount < netPayableAmount){
901
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
902
		}else{
903
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
904
		}
905
		$("form#cd input.netPayableAmount").each(function(){
906
			$(this).addClass("border-highlight");
907
		});
21987 kshitij.so 908
		error = true;
909
	}
910
 
911
	if (error){
912
		return false;
913
	}
914
	return true;
915
 
916
}
917
 
22860 ashik.ali 918
function validateSchemeDetails(){
919
	console.log("validating Scheme Details...");
920
	var error = false;
921
	var name = $("form#create-scheme-form input[name=schemeName]").val();
922
	console.log("schemeName = " + name);
923
	$("#schemeName").removeClass("border-highlight");
924
	if(name = ""){
925
		alert("Name is required");
926
		$("#schemeName").addClass("border-highlight");
927
		error = true;
928
		return error;
929
	}
930
	var schemeType = $("#schemeType option:selected").val();
931
	console.log("schemeType = " + schemeType);
932
	$("#schemeType").removeClass("border-highlight");
933
	if(schemeType = ""){
934
		alert("Please choose Scheme Type");
935
		$("#schemeType").addClass("border-highlight");
936
		error = true;
937
		return error;
938
	}
939
	var amountType = $("#amountType option:selected").val();
940
	console.log("amountType = " + amountType);
941
	$("#amountType").removeClass("border-highlight");
942
	if(amountType = ""){
943
		alert("Please choose Amount Type");
944
		$("#amountType").addClass("border-highlight");
945
		error = true;
946
		return error;
947
	}
948
	var amount = $("form#create-scheme-form input[name=schemeAmount]").val();
949
	console.log("amount = " + amount);
950
	$("#schemeAmount").removeClass("border-highlight");
951
	if (amount == ""){
952
		$("form#create-scheme-form input[name=schemeAmount]").val(0);
953
	}else if(amount <= 0){
954
		alert("Amount should be greater than 0");
955
		$("#schemeAmount").addClass("border-highlight");
956
		error = true;
957
		return error;
958
	}
959
	var startDateString = $("form#create-scheme-form input[name=startDate]").val();
960
	console.log("startDateString = " + startDateString);
961
	$("#startDate").removeClass("border-highlight");
962
 
963
	var endDateString = $("form#create-scheme-form input[name=endDate]").val();
964
	console.log("endDateString = " + endDateString);
965
	$("#endDate").removeClass("border-highlight");
966
 
967
	if(Date.parse(endDateString) < Date.parse(startDateString)){
968
		alert("End date [" + endDateString + "] can not be greater than equal to Start date [" + startDateString + "]");
969
		$("#startDate").addClass("border-highlight");
970
		$("#endDate").addClass("border-highlight");
971
		error = true;
972
		return error;
973
	}
974
 
975
	var itemIdsString = $("#itemIds").val();
976
	var itemIdsPattern = "^[0-9]{1,10}(?:,[0-9]{1,10})*$";
977
	if(itemIdsString.match(itemIdsPattern) == null){
978
		alert("Invalid itemIds["+itemIdsString+"] pattern");
979
		$("#itemIds").addClass("border-highlight");
980
		error = true;
981
		return error;
982
	}
983
 
984
	var retailerIdsString = $("#retailerIds").val();
985
	if(retailerIdsString != undefined){
986
		var retailerIdsPattern = "^[0-9]{1,10}(?:,[0-9]{1,10})*$";
987
		if(retailerIdsString.match(retailerIdsPattern) == null){
988
			alert("Invalid retailerIds["+retailerIdsString+"] pattern");
989
			$("#retailerIds").addClass("border-highlight");
990
			error = true;
991
			return error;
992
		}
993
	}
994
 
995
	console.log("validation scheme error = " + error);
996
	return error;
997
}
998
 
999
function schemeDetailsJson(){
1000
	console.log("schemeDetailsJson")
1001
	var schemeObject = {};
1002
	schemeObject['name'] = $("form#create-scheme-form input[name=schemeName]").val();
1003
	schemeObject['description'] = $("form#create-scheme-form input[name=description]").val();
1004
	schemeObject['type'] = $("#schemeType option:selected").val();
1005
	schemeObject['amountType'] = $("#amountType option:selected").val();
1006
	schemeObject['amount'] = $('#schemeAmount').val();
1007
	schemeObject['startDateString'] = $("form#create-scheme-form input[name=startDate]").val();
1008
	schemeObject['endDateString'] = $("form#create-scheme-form input[name=endDate]").val();
1009
	schemeObject['itemIds'] = [];
1010
	var itemIds = $("#itemIds").val().split(",");
1011
	for(var itemId of itemIds){
1012
		schemeObject['itemIds'].push(parseInt(itemId));
1013
	}
1014
	schemeObject['active'] = $("form#create-scheme-form input[name=schemeActive]").val();
1015
	schemeObject['retailerAll'] = $("form#create-scheme-form input[name=retailerAll]").val();
1016
	if($("#retailerAll").val() == 'true'){
1017
		schemeObject['retailerIds'] = [];
1018
	}else{
1019
		schemeObject['retailerIds'] = []
1020
		var retailerIds = $("#retailerIds").val().split(",");
1021
		for(var retailerId of retailerIds){
1022
			schemeObject['retailerIds'].push(parseInt(retailerId));
1023
		}
1024
	}
1025
	return JSON.stringify(schemeObject);
1026
}
1027
 
22681 amit.gupta 1028
function getSerialNumbersFromOrder($el){
1029
	var $serialNumberElement = $el.find('.serialNumber');
22860 ashik.ali 1030
	if($serialNumberElement.val() == ''){
1031
		return null;
1032
	}
22681 amit.gupta 1033
	var insuranceAmount = parseFloat($el.find('.insuranceAmount').val());
1034
	if(insuranceAmount > 0){
1035
		insurance = true;
1036
		globalInsurace = true;
1037
	}else{
1038
		insurance = false;
1039
	}
1040
	return {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
1041
}
1042
 
21987 kshitij.so 1043
function orderDetailsPayload(){
1044
		var orderObj = {};
1045
		var priceQtyArray = [];
1046
		var customerObj = {};
1047
		var paymentOption = [];
22860 ashik.ali 1048
		var globalInsurance = false;
21987 kshitij.so 1049
 
1050
		$("form#cd input.serialNumber").each(function(){
1051
			var itemId = parseInt($(this).attr("itemId"));
22860 ashik.ali 1052
			if (orderObj.hasOwnProperty('fofoOrderItems')){
1053
				var itemDetails = orderObj['fofoOrderItems'];
21987 kshitij.so 1054
				if (itemDetails.hasOwnProperty(itemId)){
1055
					var serialNumbers = itemDetails[itemId];
1056
					serialNumbers.push($(this).val());
1057
					itemDetails[itemId] = serialNumbers;
22245 ashik.ali 1058
				}else{
21987 kshitij.so 1059
					var serialNumbers = [];
1060
					serialNumbers.push($(this).val());
1061
					itemDetails[itemId] = serialNumbers;
1062
				}
22245 ashik.ali 1063
			}else{
21987 kshitij.so 1064
				var serialNumbers = [];
1065
				serialNumbers.push($(this).val());
1066
				var tmp ={};
1067
				tmp[itemId]  = serialNumbers;
22860 ashik.ali 1068
				orderObj['fofoOrderItems'] = tmp;
21987 kshitij.so 1069
			}
1070
		});
1071
		console.log( JSON.stringify(orderObj));
22581 ashik.ali 1072
		$("#order-details").find("tr:not(:first-child)").each(function(index, el){
1073
			//console.log(el);
1074
			//console.log(index);
22681 amit.gupta 1075
			var $el = $(el);
1076
			var $unitPriceElement = $el.find('.unitPrice');
1077
			var $discountAmountElement = $el.find('.discountAmount');
22581 ashik.ali 1078
 
1079
			var itemId = parseInt($unitPriceElement.attr("itemId"));
1080
			var unitPrice = parseFloat($unitPriceElement.val());
1081
			var qty = parseInt($unitPriceElement.attr("quantity"));
1082
			var discountAmount = parseFloat($discountAmountElement.val());
1083
			var mop = $discountAmountElement.attr("mop");
1084
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
1085
			tmpObj.discountAmount = discountAmount;
22860 ashik.ali 1086
			/*tmpObj['serialNumberDetails'] = [];
1087
			var found = false;
1088
			for(var i = 0; i < priceQtyArray.length; i++){			
1089
				if (priceQtyArray[i]["itemId"] == itemId){
1090
					found = true;
1091
					break;
1092
				}
1093
			}
1094
			if(!found){
1095
				priceQtyArray.push(tmpObj);
1096
			}else{
1097
				for(var i = 0; i < priceQtyArray.length; i++){			
1098
					if (priceQtyArray[i]["itemId"] == itemId){
1099
						priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
1100
						break;
1101
					}
1102
				}
1103
			}
1104
			var serialNumberDetails = getSerialNumbersFromOrder($el);
1105
			if(serialNumberDetails != null){
1106
				for(var i = 0; i < priceQtyArray.length; i++){			
1107
					if (priceQtyArray[i]["itemId"] == itemId){
1108
						priceQtyArray[i]["serialNumberDetails"].push(serialNumberDetails);
1109
						break;
1110
					}
1111
				}
1112
			}
1113
		});*/
22581 ashik.ali 1114
 
22860 ashik.ali 1115
			if (orderObj['fofoOrderItems'][itemId] === undefined){
1116
				tmpObj['serialNumberDetails'] =[];
1117
			}
1118
			else{
1119
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
1120
				tmpObj['serialNumberDetails'] = [];
1121
			}
1122
			var found = false;
1123
			for(var i = 0; i < priceQtyArray.length; i++){			
1124
				if (priceQtyArray[i]["itemId"] == itemId){
1125
					priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
1126
					found = true;
1127
					break;
1128
				}
1129
			}
1130
			if(!found){
1131
				priceQtyArray.push(tmpObj);
1132
			}
21987 kshitij.so 1133
		});
1134
 
22860 ashik.ali 1135
 
1136
		$("#order-details").find("tr:not(:first-child)").each(function(index,el){
1137
			//console.log(el);
1138
			//console.log(index);
1139
			var $serialNumberElement = $(el).find('.serialNumber');
1140
			var itemId = parseInt($serialNumberElement.attr("itemId"));
1141
			var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
1142
			//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
1143
 
1144
			//}
1145
			//console.log($serialNumberElement.val());
1146
			//console.log(itemId);
1147
			for(var i = 0; i < priceQtyArray.length; i++){
1148
				console.log(priceQtyArray[i]["itemId"]);
1149
				if (priceQtyArray[i]["itemId"] == itemId){
1150
					if(insuranceAmount > 0){
1151
						insurance = true;
1152
						globalInsurance = true;
1153
					}else{
1154
						insurance = false;
1155
					}
1156
					var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
1157
					priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
1158
				}
1159
            }
1160
		});
1161
 
22245 ashik.ali 1162
		console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
1163
		customerObj['firstName'] = $("form#cd input[name=firstName]").val();
1164
		customerObj['lastName'] = $("form#cd input[name=lastName]").val();
21987 kshitij.so 1165
		customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
1166
		customerObj['emailId'] = $("form#cd input[name=email]").val();
22594 ashik.ali 1167
		customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth]").val();
21987 kshitij.so 1168
		var customerAddress = {};
22245 ashik.ali 1169
		customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
21987 kshitij.so 1170
		customerAddress['line1'] = $("form#cd input[name=line1]").val();
1171
		customerAddress['line2'] = $("form#cd input[name=line2]").val();
1172
		customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
1173
		customerAddress['city'] = $("form#cd input[name=city]").val();
1174
		customerAddress['state'] = $('select[name=state] option:selected').val();
22245 ashik.ali 1175
		customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
21987 kshitij.so 1176
		customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
1177
		customerAddress['country'] = "India";
22860 ashik.ali 1178
		customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
21987 kshitij.so 1179
		customerObj['address'] = customerAddress; 
1180
		console.log( JSON.stringify(customerObj));
1181
		$("#payment-details input").each(function(){
1182
		console.log($(this).attr('name'));
1183
		if ($(this).attr('name') =="" ){
1184
			return;
1185
		}
1186
		var paymentObj = {};
1187
		paymentObj['type'] = $(this).attr('name');
1188
		if ($(this).val() == ""){
1189
			paymentObj['amount'] = 0.0;
1190
		}
1191
		else{
1192
			paymentObj['amount'] = parseFloat($(this).val());
1193
		}
1194
		paymentOption.push(paymentObj);
1195
		});
1196
		console.log( JSON.stringify(paymentOption));
1197
 
1198
		var retObj = {};
22254 ashik.ali 1199
		var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
22860 ashik.ali 1200
		if(globalInsurance){
22681 amit.gupta 1201
			retObj['customerDateOfBirth'] = (dateOfBirth);
22254 ashik.ali 1202
		}
22860 ashik.ali 1203
		retObj['fofoOrderItems'] = (priceQtyArray);
21987 kshitij.so 1204
		retObj['customer'] = (customerObj);
1205
		retObj['paymentOptions'] =  (paymentOption);
22254 ashik.ali 1206
 
21987 kshitij.so 1207
		console.log(retObj);
1208
		return  JSON.stringify(retObj);
1209
}