Subversion Repositories SmartDukaan

Rev

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

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