Subversion Repositories SmartDukaan

Rev

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