Subversion Repositories SmartDukaan

Rev

Rev 22593 | Rev 22655 | 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
 
22551 ashik.ali 411
 
412
 
413
function getWalletHistoryNextItems(start, end, startTime, endTime){
414
	console.log(start);
415
	console.log(end);
416
	console.log(+end + +10);
417
	console.log(+start + +10);
418
	jQuery.ajax({
419
	        type : "GET",
420
	        url : context+"/getPaginatedWalletHistory?startTime="+startTime
421
	        +"&endTime="+endTime+"&offset="+end,
422
			beforeSend: function(){
423
	        //$('#ajax-spinner').show();
424
	        },
425
	        complete: function(){
426
	        //$('#ajax-spinner').hide();
427
	        },
428
	        success : function(response) {
429
	        	$( "#wallet-history-paginated .end" ).text(+end + +10);
430
	        	$( "#wallet-history-paginated .start" ).text(+start + +10);
431
				var last = $( "#wallet-history-paginated .end" ).text();
432
				var temp = $( "#wallet-history-paginated .size" ).text();
433
				if (parseInt(last) >= parseInt(temp)){
434
					$("#wallet-history-paginated .next").prop('disabled', true);
435
					//$( "#good-inventory-paginated .end" ).text(temp);
436
				}
437
	            $('#wallet-history-table').html(response);
438
	            $("#wallet-history-paginated .previous").prop('disabled', false);
439
	        },
440
			error : function() {
441
				alert("Unable to fetch items");
442
			 },
443
	    });  
444
	}
445
function getWalletHistoryPreviousItems(start, end, pre, invoiceNumber, searchType,startTime,endTime){
446
	jQuery.ajax({
447
	        type : "GET",
448
	        url : context+"/getPaginatedWalletHistory?startTime="+startTime
449
	        +"&endTime="+endTime+"&offset="+pre,
450
			beforeSend: function(){
451
	        //$('#ajax-spinner').show();
452
	        },
453
	        complete: function(){
454
	        //$('#ajax-spinner').hide();
455
	        },
456
	        success : function(response) {
457
	        	$( "#wallet-history-paginated .end" ).text(+end - +10);
458
	        	$( "#wallet-history-paginated .start" ).text(+start - +10);
459
	        	$('#wallet-history-table').html(response);
460
	        	$("#wallet-history-paginated .next").prop('disabled', false);
461
				if (parseInt(pre)==0)
462
				{
463
					$("#wallet-history-paginated .previous").prop('disabled', true);
464
				}
465
	        },
466
			error : function() {
467
				alert("Unable to fetch items");
468
			 },
469
	    });
470
}
471
 
21987 kshitij.so 472
function loadGoodInventorySearchInfo(search_text){
473
	loadGoodInventory("main-content",search_text);
474
}
475
 
476
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
477
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
478
}
479
 
21627 kshitij.so 480
function findDuplicateSerialNumbers(value){
481
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
482
    return result;
483
}
21987 kshitij.so 484
 
485
function loadGrnDetails(purchaseId,domId){
486
	jQuery.ajax({
487
        type : "GET",
22090 amit.gupta 488
        url : context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId,
21987 kshitij.so 489
        success : function(response) {
490
            $('#' + domId).html(response);
491
            window.dispatchEvent(new Event('resize'));
492
        }
493
    });
494
}
495
 
22245 ashik.ali 496
function loadSaleDetails(orderId, domId){
497
	jQuery.ajax({
498
        type : "GET",
499
        url : context+"/saleDetails?orderId="+orderId,
500
        success : function(response) {
501
            $('#' + domId).html(response);
502
            window.dispatchEvent(new Event('resize'));
503
        }
504
    });
505
}
506
 
21987 kshitij.so 507
function loadPendingGrnDetails(purchaseId,domId){
508
	jQuery.ajax({
22090 amit.gupta 509
		url: context+"/purchase/?airwayBillOrInvoiceNumber="+purchaseId,
21987 kshitij.so 510
		type: 'POST',
511
		async: false,
512
		success: function (data) {
513
			$('#'+domId).html(data);
514
		},
515
		error : function() {
516
			alert("OOPS!!!Failed to do changes.Try Again.",'ERROR');
517
		},
518
		cache: false,
519
		contentType: false,
520
		processData: false
521
	});
522
}
523
 
524
function getNextCatalogItems(start, end, searchText){
525
	console.log(start);
526
	console.log(end);
527
	console.log(+end + +10);
528
	console.log(+start + +10);
529
	jQuery.ajax({
530
	        type : "GET",
22090 amit.gupta 531
	        url : context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText,
21987 kshitij.so 532
			beforeSend: function(){
533
	        //$('#ajax-spinner').show();
534
	        },
535
	        complete: function(){
536
	        //$('#ajax-spinner').hide();
537
	        },
538
	        success : function(response) {
539
	        	$( "#catalog-paginated .end" ).text(+end + +10);
540
	        	$( "#catalog-paginated .start" ).text(+start + +10);
541
				var last = $( "#catalog-paginated .end" ).text();
542
				var temp = $( "#catalog-paginated .size" ).text();
543
				if (parseInt(last) >= parseInt(temp)){
544
					$("#catalog-paginated .next").prop('disabled', true);
545
				}
546
	            $('#catalog-table').html(response);
547
	            $("#catalog-paginated .previous").prop('disabled', false);
548
	        },
549
			error : function() {
550
				alert("Unable to fetch items");
551
			 },
552
	    });  
553
	}
554
function getPreviousCatalogItems(start,end,pre,searchText){
555
	jQuery.ajax({
556
	        type : "GET",
22090 amit.gupta 557
	        url : context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText,
21987 kshitij.so 558
			beforeSend: function(){
559
	        //$('#ajax-spinner').show();
560
	        },
561
	        complete: function(){
562
	        //$('#ajax-spinner').hide();
563
	        },
564
	        success : function(response) {
565
	        	$( "#catalog-paginated .end" ).text(+end - +10);
566
	        	$( "#catalog-paginated .start" ).text(+start - +10);
567
	        	$('#catalog-table').html(response);
568
	        	$("#catalog-paginated .next").prop('disabled', false);
569
				if (parseInt(pre)==0)
570
				{
571
					$("#catalog-paginated .previous").prop('disabled', true);
572
				}
573
 
574
	        },
575
			error : function() {
576
				alert("Unable to fetch items");
577
			 },
578
	    });
579
}
580
 
581
function loadCatalogSearchInfo(search_text){
582
	loadCatalog("main-content",search_text);
583
}
584
 
585
function addItemInLocalStorage(bagObj){
586
	if (localStorage.getItem("bag")!=null){
587
		var bag = JSON.parse(localStorage.getItem("bag"));
588
		bag[bagObj.itemId] = bagObj
589
		localStorage.setItem("bag",JSON.stringify(bag));
590
		bag = localStorage.getItem("bag")
591
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
592
	}
593
	else{
594
		var tempObj = {};
595
		tempObj[bagObj.itemId] = bagObj
596
		localStorage.setItem("bag",JSON.stringify(tempObj));
597
		var bag = localStorage.getItem("bag")
598
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
599
	}
600
}
601
 
602
 
603
function changeQuantityInLocalStorage(itemId, newQuantity){
604
	var bag = JSON.parse(localStorage.getItem("bag"));
605
	bag[itemId].quantity = newQuantity;
606
	localStorage.setItem("bag",JSON.stringify(bag));
607
}
608
 
609
function removeItemFromLocalStorage(itemId){
610
	if (localStorage.getItem("bag")!=null){
611
		var bag = JSON.parse(localStorage.getItem("bag"));
612
		delete bag[itemId];
613
		localStorage.setItem("bag",JSON.stringify(bag));
614
		$("#cart_bar").find('span').text(Object.keys(bag).length);
615
	}
616
}
617
 
618
function emptyBag(){
22095 kshitij.so 619
	localStorage.setItem("bag",JSON.stringify({}));
21987 kshitij.so 620
	$("#cart_bar").find('span').text(0);
621
}
622
 
623
function loadCart(domId){
624
	jQuery.ajax({
625
        type : "POST",
626
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 627
        url : context+"/cart",
21987 kshitij.so 628
        success : function(response) {
629
            $('#' + domId).html(response);
630
        }
631
    });  
632
}
633
 
22551 ashik.ali 634
function loadWallet(domId, startTime, endTime){
635
	jQuery.ajax({
636
        type : "GET",
637
        //data: {"cartData":localStorage.getItem("bag")},
638
        url : context+"/walletDetails?startTime="+startTime
639
        +"&endTime="+endTime,
640
        success : function(response) {
641
            $('#' + domId).html(response);
642
        }
643
    });  
644
}
645
 
21987 kshitij.so 646
function checkout(domId){
647
	jQuery.ajax({
22095 kshitij.so 648
        type : "GET",
21987 kshitij.so 649
        data: {"cartData":localStorage.getItem("bag")},
22090 amit.gupta 650
        url : context+"/validate-cart",
21987 kshitij.so 651
        success : function(response) {
652
        	var obj = JSON.parse(response);
653
        	redirectCart(obj.redirectUrl, obj.params, obj.method, "main-content");
22095 kshitij.so 654
        	$('#main-content').html(response);
21987 kshitij.so 655
        }
22245 ashik.ali 656
    });
21987 kshitij.so 657
}
658
 
659
function redirectCart(url, cartData, method, domId){
660
	jQuery.ajax({
661
        type : method,
662
        data: {"cartData":cartData},
663
        url : context+url,
664
        success : function(response) {
665
            $('#' + domId).html(response);
666
            window.dispatchEvent(new Event('resize'));
667
        }
668
    });  
669
}
670
 
22245 ashik.ali 671
function saleHistory(domId, invoiceNumber, searchType, startTime, endTime){
672
	jQuery.ajax({
673
        type : "GET",
674
        url : context+"/saleHistory?invoiceNumber="+invoiceNumber+"&searchType="+searchType
675
        +"&startTime="+startTime
676
        +"&endTime="+endTime,
677
        success : function(response) {
678
            $('#' + domId).html(response);
679
        }
680
    });  
681
}
682
 
22354 ashik.ali 683
 
684
function contactUs(domId){
685
	jQuery.ajax({
686
        type : "GET",
687
        url : context+"/contactUs",
688
        success : function(response) {
689
            $('#' + domId).html(response);
690
        }
691
    });  
692
}
693
 
694
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
695
	jQuery.ajax({
696
        type : "GET",
697
        url : context+"/customer/mobileNumber?mobileNumber="+mobileNumber,
698
        success : function(response) {
699
        	console.log("response"+response);
700
        	var customer = response.response;
701
            $('#firstName').attr('value', customer.firstName);
702
            $('#lastName').attr('value', customer.lastName);
703
            $('#email').attr('value', customer.emailId);
704
            $('#phone').attr('value', customer.mobileNumber);
705
            $('#alternatePhone').attr('value', customer.address.phoneNumber);
706
            $('#line1').attr('value', customer.address.line1);
707
            $('#line2').attr('value', customer.address.line2);
708
            $('#landmark').attr('value', customer.address.landmark);
709
            $('#pinCode').attr('value', customer.address.pinCode);
710
            $('#city').attr('value', customer.address.city);
711
            $('#state').attr('value', customer.address.state);
712
        }
713
    });  
714
}
715
 
22283 ashik.ali 716
function saleHistorySearchInfo(search_text, searchType, startTime, endTime){
717
	saleHistory("main-content", search_text, searchType, startTime, endTime);
718
}
22245 ashik.ali 719
 
22551 ashik.ali 720
function walletHistoryDateSearchSearchInfo(startTime, endTime){
721
 
722
}
22283 ashik.ali 723
 
22551 ashik.ali 724
 
21987 kshitij.so 725
function validateOrderDetails(){
726
	var sNumbers = [];
727
	var error = false;
728
	$("form#cd input.serialNumber").each(function(){
729
		var input = $(this).val().trim();
22245 ashik.ali 730
		var itemType = $(this).attr("itemType");
21987 kshitij.so 731
		$(this).removeClass("border-highlight");
22245 ashik.ali 732
		if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
21987 kshitij.so 733
			error = true;
734
			$(this).addClass("border-highlight");
735
		}
736
		sNumbers.push(input);
737
	});
738
 
739
	$("form#cd input.unitPrice").each(function(){
740
		var input = $(this).val().trim();
741
		$(this).removeClass("border-highlight");
742
		if (!input || parseInt(input)<=0 || isNaN(input)){
743
			error=true;
744
			$(this).addClass("border-highlight");
745
		}
746
	});
747
 
22581 ashik.ali 748
	// checking input discountAmount is not greater than maxDiscountAmount
749
	$("form#cd input.discountAmount").each(function(){
750
		var input = $(this).val().trim();
751
		var mop = $(this).attr("mop");
752
		var maxDiscountPrice = parseFloat($(this).attr("placeholder").substring(5));
753
		if(mop){
754
			$(this).removeClass("border-highlight");
755
			if (!input || parseFloat(input)<0 || isNaN(input)){
756
				alert("DiscountAmount value can not be lesser than 0 or invalid value");
757
				error=true;
758
				$(this).addClass("border-highlight");
759
			}
760
			if(parseFloat(input) > maxDiscountPrice){
761
				alert("DiscountAmount value can not be greater than the suggested maxDiscountPrice");
762
				error=true;
763
				$(this).addClass("border-highlight");
764
			}
765
		}
766
	});
767
 
21987 kshitij.so 768
	var amount = 0;
769
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
770
 
771
 
772
	$("form#cd input.amount").each(function(){
22354 ashik.ali 773
		if ($(this).val() == ""){
21987 kshitij.so 774
			$(this).val(0);
775
		}
776
		var tmpAmount = parseFloat($(this).val());
777
		amount = amount + tmpAmount;
778
	});
779
 
780
	console.log(amount);
781
	console.log(netPayableAmount);
782
 
22354 ashik.ali 783
	if (amount != netPayableAmount){
784
		if(amount < netPayableAmount){
785
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
786
		}else{
787
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
788
		}
789
		$("form#cd input.netPayableAmount").each(function(){
790
			$(this).addClass("border-highlight");
791
		});
21987 kshitij.so 792
		error = true;
793
	}
794
 
795
	if (error){
796
		return false;
797
	}
798
	return true;
799
 
800
}
801
 
802
function orderDetailsPayload(){
803
		var orderObj = {};
804
		var priceQtyArray = [];
805
		var customerObj = {};
806
		var paymentOption = [];
807
 
808
		$("form#cd input.serialNumber").each(function(){
809
			var itemId = parseInt($(this).attr("itemId"));
810
			if (orderObj.hasOwnProperty('fofoLineItems')){
811
				var itemDetails = orderObj['fofoLineItems'];
812
				if (itemDetails.hasOwnProperty(itemId)){
813
					var serialNumbers = itemDetails[itemId];
814
					serialNumbers.push($(this).val());
815
					itemDetails[itemId] = serialNumbers;
22245 ashik.ali 816
				}else{
21987 kshitij.so 817
					var serialNumbers = [];
818
					serialNumbers.push($(this).val());
819
					itemDetails[itemId] = serialNumbers;
820
				}
22245 ashik.ali 821
			}else{
21987 kshitij.so 822
				var serialNumbers = [];
823
				serialNumbers.push($(this).val());
824
				var tmp ={};
825
				tmp[itemId]  = serialNumbers;
826
				orderObj['fofoLineItems'] = tmp;
827
			}
828
		});
829
		console.log( JSON.stringify(orderObj));
22581 ashik.ali 830
		/*$("form#cd input.unitPrice").each(function(){
21987 kshitij.so 831
			var itemId = parseInt($(this).attr("itemId"));
832
			var unitPrice = parseFloat($(this).val());
833
			var qty = parseInt($(this).attr("quantity"));
22581 ashik.ali 834
			var discountAmount = parseFloat($(this).val());
21987 kshitij.so 835
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
22245 ashik.ali 836
			if (orderObj['fofoLineItems'][itemId] === undefined){
837
				tmpObj['serialNumberDetails'] =[];
21987 kshitij.so 838
			}
839
			else{
22245 ashik.ali 840
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
841
				tmpObj['serialNumberDetails'] = [];
21987 kshitij.so 842
			}
22245 ashik.ali 843
			var found = false;
844
			for(var i = 0; i < priceQtyArray.length; i++){			
845
				if (priceQtyArray[i]["itemId"] == itemId){
846
					found = true;
847
					break;
848
				}
849
			}
850
			if(!found){
851
				priceQtyArray.push(tmpObj);
852
			}
22581 ashik.ali 853
		});*/
854
 
855
		$("#order-details").find("tr:not(:first-child)").each(function(index, el){
856
			//console.log(el);
857
			//console.log(index);
858
			var $unitPriceElement = $(el).find('.unitPrice');
859
			var $discountAmountElement = $(el).find('.discountAmount');
860
 
861
			var itemId = parseInt($unitPriceElement.attr("itemId"));
862
			var unitPrice = parseFloat($unitPriceElement.val());
863
			var qty = parseInt($unitPriceElement.attr("quantity"));
864
			var discountAmount = parseFloat($discountAmountElement.val());
865
			var mop = $discountAmountElement.attr("mop");
866
			var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
867
			tmpObj.discountAmount = discountAmount;
868
 
869
			if (orderObj['fofoLineItems'][itemId] === undefined){
870
				tmpObj['serialNumberDetails'] =[];
871
			}
872
			else{
873
				//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
874
				tmpObj['serialNumberDetails'] = [];
875
			}
876
			var found = false;
877
			for(var i = 0; i < priceQtyArray.length; i++){			
878
				if (priceQtyArray[i]["itemId"] == itemId){
879
					found = true;
880
					break;
881
				}
882
			}
883
			if(!found){
884
				priceQtyArray.push(tmpObj);
885
			}
21987 kshitij.so 886
		});
887
 
22245 ashik.ali 888
 
889
		$("#order-details").find("tr:not(:first-child)").each(function(index,el){
890
			//console.log(el);
891
			//console.log(index);
892
			var $serialNumberElement = $(el).find('.serialNumber');
893
			var itemId = parseInt($serialNumberElement.attr("itemId"));
894
			var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
895
			//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
896
 
897
			//}
898
			//console.log($serialNumberElement.val());
899
			//console.log(itemId);
900
			for(var i = 0; i < priceQtyArray.length; i++){
901
				console.log(priceQtyArray[i]["itemId"]);			
902
				if (priceQtyArray[i]["itemId"] == itemId){
903
					if(insuranceAmount > 0){
904
						insurance = true;
22593 ashik.ali 905
					}else{
906
						insurance = false;
22245 ashik.ali 907
					}
908
					var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
909
					priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
910
				}
911
            }
912
 
913
		});
914
 
915
		console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
21987 kshitij.so 916
		//customer-details
917
		/*$("#customer-details input").each(function(){
918
			console.log($(this).attr('name'));
919
			customerObj[$(this).attr('name')] = $(this).val();
920
		});*/
921
		//$("input[name=nameGoesHere]").val();
22245 ashik.ali 922
		customerObj['firstName'] = $("form#cd input[name=firstName]").val();
923
		customerObj['lastName'] = $("form#cd input[name=lastName]").val();
21987 kshitij.so 924
		customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
925
		customerObj['emailId'] = $("form#cd input[name=email]").val();
22594 ashik.ali 926
		customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth]").val();
21987 kshitij.so 927
		var customerAddress = {};
22245 ashik.ali 928
		customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
21987 kshitij.so 929
		customerAddress['line1'] = $("form#cd input[name=line1]").val();
930
		customerAddress['line2'] = $("form#cd input[name=line2]").val();
931
		customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
932
		customerAddress['city'] = $("form#cd input[name=city]").val();
933
		customerAddress['state'] = $('select[name=state] option:selected').val();
22245 ashik.ali 934
		customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
21987 kshitij.so 935
		customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
936
		customerAddress['country'] = "India";
937
		customerObj['address'] = customerAddress; 
938
		console.log( JSON.stringify(customerObj));
939
		$("#payment-details input").each(function(){
940
		console.log($(this).attr('name'));
941
		if ($(this).attr('name') =="" ){
942
			return;
943
		}
944
		var paymentObj = {};
945
		paymentObj['type'] = $(this).attr('name');
946
		if ($(this).val() == ""){
947
			paymentObj['amount'] = 0.0;
948
		}
949
		else{
950
			paymentObj['amount'] = parseFloat($(this).val());
951
		}
952
		paymentOption.push(paymentObj);
953
		});
954
		console.log( JSON.stringify(paymentOption));
955
 
956
		var retObj = {};
22254 ashik.ali 957
		var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
958
		if(insurance){
959
			retObj['customerDateOfBirth'] = (dateOfBirth)
960
		}
21987 kshitij.so 961
		retObj['fofoLineItems'] = (priceQtyArray);
962
		retObj['customer'] = (customerObj);
963
		retObj['paymentOptions'] =  (paymentOption);
22254 ashik.ali 964
 
21987 kshitij.so 965
		console.log(retObj);
966
		return  JSON.stringify(retObj);
967
}