Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
22245 ashik.ali 1
$().ready(function() {
2
	$("form#cd input").each(function(){
3
		$(this).attr('autocomplete', 'off');
4
	});
5
});
6
$().ready(function() {
23419 ashik.ali 7
    // validate the comment form when it is submitted
8
    $('#cd').validate({
22245 ashik.ali 9
		rules:{
10
			name:{
11
				required:true
12
			},
13
			email:{
14
				required:true,
15
				email:true
16
			},
17
			line1:{
18
				required:true
19
			},
20
			state:{
21
				required:true
22
			},
23
			city:{
24
				required:true
25
			},
26
			pincode:{
27
				required:true,
28
				digits:true,
29
				minlength: 6,
30
                maxlength: 6,
31
			},
32
			phone:{
33
				required:true,
34
				minlength:10,
35
				maxlength:10,
36
				digits:true
37
			},
38
		},
39
		messages:{
40
			name:{
41
				required:"Please enter the name"
42
			},
43
			line1:{
44
				required:"Please enter the address"
45
			},
46
			state:{
47
				required: "Please select a state"
48
			},
49
			city:{
50
				required: "Please enter the city"
51
			},
52
			email:{
53
				require: "Please enter a valid email address"
54
			},
55
			pincode:{
56
				required: "Please enter the pincode",
57
				digits:"Please enter a valid pincode"
58
			},
59
			phone:{
60
				required: "Please enter the phone number",
61
				digits:"Please enter a valid number",
62
				minlength:"Number should be of 10 digits"
63
			}
64
		},
65
		submitHandler: function (form, event) {
66
			event.preventDefault();
67
			var payload = orderDetailsPayload();
68
			if(!validateOrderDetails()){
69
				alert("Please fix highlighted errors");
70
				return false;
71
			}
23783 ashik.ali 72
			doPostAjaxRequestWithJsonHandler(context+"/create-order", payload, function(response){
23353 ashik.ali 73
				emptyBag();
74
				$('#main-content').html(response);
75
			});
76
            return false; // required to block normal submit since you used ajax
22245 ashik.ali 77
         }
78
	});
79
 
23340 ashik.ali 80
	$("input.unitPrice").blur(function() {
22245 ashik.ali 81
		console.log("unitPrice blur called");
82
		var $element = $(this);
23820 amit.gupta 83
		var unitPrice = parseFloat($element.val());
84
		if(!isNaN(unitPrice)) {
85
			var mopPrice = parseFloat($(this).attr('mopPrice'));
86
			var dp = parseFloat($(this).attr('dp'));
87
			if(!accessoriesDeals && unitPrice < mopPrice){
88
				alert("Selling Price must be greater than equal to MOP")
89
				$element.addClass("border-highlight");
90
			}else if(unitPrice < dp){
91
				alert("Selling Price must be greater than equal to Purchase Price")
92
				$element.addClass("border-highlight");
93
			}else{
94
				$element.removeClass("border-highlight")
95
				if(unitPrice == mopPrice){
96
					$("input.discountAmount").removeAttr("readonly");
97
				}
23353 ashik.ali 98
				doAjaxRequestHandler(context+"/insurancePrices?price="+unitPrice, "GET", function(response){
99
					console.log("response : "+JSON.stringify(response));
100
					var insurancePriceMap = response.response;
101
					for(key in insurancePriceMap){
102
						var dealerPrice = insurancePriceMap[key].dealerPrice;
103
						var sellingPrice = insurancePriceMap[key].sellingPrice;
104
						$element.closest('tr').find('.insuranceAmount').attr("placeholder", dealerPrice + "-" + sellingPrice);
105
						break;
106
					}
107
				});
23820 amit.gupta 108
			}
22354 ashik.ali 109
		}
22245 ashik.ali 110
	}).focus(function(){
111
		console.log("unitPrice focus called");
112
		var $element = $(this);
113
		$element.closest('tr').find('.insuranceAmount').attr("placeholder", "");
114
	});
22354 ashik.ali 115
 
23569 govind 116
	$( "input.phone").change(function() {
22354 ashik.ali 117
		console.log("phone blur called");
118
		var mobileNumber = $(this).val();
23405 amit.gupta 119
		if(mobileNumber.length < 10) {
120
			return;
121
		}
22354 ashik.ali 122
		writeOldCustomerDetailsByMobileNumber(mobileNumber);
23419 ashik.ali 123
		var itemIds = [];
124
		$("form#cd input.serialNumber").each(function(){
125
			var itemId = parseInt($(this).attr("itemId"));
126
			itemIds.push(itemId);
127
		});
128
		console.log(itemIds);
23434 ashik.ali 129
		calculateTotalAmount();
23419 ashik.ali 130
		checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds);
22354 ashik.ali 131
	});
22245 ashik.ali 132
 
23343 ashik.ali 133
});
134
 
135
 
136
function validateOrderDetails(){
137
	var sNumbers = [];
138
	var error = false;
139
	$("form#cd input.serialNumber").each(function(){
140
		var input = $(this).val().trim();
141
		var itemType = $(this).attr("itemType");
142
		$(this).removeClass("border-highlight");
143
		if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
144
			error = true;
145
			$(this).addClass("border-highlight");
146
		}
147
		sNumbers.push(input);
148
	});
149
 
150
	$("form#cd input.unitPrice").each(function(){
151
		var input = $(this).val().trim();
152
		$(this).removeClass("border-highlight");
153
		if (!input || parseInt(input)<=0 || isNaN(input)){
154
			error=true;
155
			$(this).addClass("border-highlight");
156
		}
157
	});
158
 
159
	// checking input discountAmount is not greater than maxDiscountAmount
160
	$("form#cd input.discountAmount").each(function(){
161
		var input = $(this).val().trim();
162
		var mop = $(this).attr("mop");
163
 
164
		if(mop){
165
			var maxDiscountPriceRangeString = $(this).attr("placeholder");
166
			var maxDiscountPrice = 0;
167
			if(maxDiscountPriceRangeString != undefined && maxDiscountPriceRangeString != ''){
168
				maxDiscountPrice = maxDiscountPriceRangeString.substring(6);
169
			}
170
			$(this).removeClass("border-highlight");
171
			if (!input || parseFloat(input)<0 || isNaN(input)){
172
				alert("DiscountAmount value can not be lesser than 0 or invalid value");
173
				error=true;
174
				$(this).addClass("border-highlight");
175
			}
176
			if(parseFloat(input) > maxDiscountPrice){
177
				alert("DiscountAmount [" + parseFloat(input) + "] value can not be greater than the suggested maxDiscountPrice [" + maxDiscountPrice + "]");
178
				error=true;
179
				$(this).addClass("border-highlight");
180
			}
181
		}
182
	});
183
 
23370 ashik.ali 184
	var gstNumber = $("form#cd input[name=gstNumber]").val();
185
	$("form#cd input[name=gstNumber]").removeClass("border-highlight");
186
	if(gstNumber.length > 0 && gstNumber.length != 15){
187
		alert("Please provide valid gstNumber");
188
		error = true;
189
		$("form#cd input[name=gstNumber]").addClass("border-highlight");
190
	}
191
 
23440 ashik.ali 192
	/*if(localStorage.getItem('otpVerified') == null || localStorage.getItem('otpVerified') == "false"){
23434 ashik.ali 193
		alert("Please verify prebooking orders otp");
194
		error = true;
23440 ashik.ali 195
	}*/
23434 ashik.ali 196
 
23343 ashik.ali 197
	var amount = 0;
198
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
23434 ashik.ali 199
	var totalAdvanceAmount = parseFloat($("form#cd input.totalAdvanceAmount").val());
23343 ashik.ali 200
 
23434 ashik.ali 201
	netPayableAmount = netPayableAmount - totalAdvanceAmount;
23343 ashik.ali 202
 
203
	$("form#cd input.amount").each(function(){
204
		if ($(this).val() == ""){
205
			$(this).val(0);
206
		}
207
		var tmpAmount = parseFloat($(this).val());
208
		amount = amount + tmpAmount;
209
	});
210
 
211
	console.log(amount);
212
	console.log(netPayableAmount);
213
 
214
	if (amount != netPayableAmount){
215
		if(amount < netPayableAmount){
216
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
217
		}else{
218
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
219
		}
220
		$("form#cd input.netPayableAmount").each(function(){
221
			$(this).addClass("border-highlight");
222
		});
223
		error = true;
224
	}
225
 
226
	if (error){
227
		return false;
228
	}
229
	return true;
230
 
23347 ashik.ali 231
}
232
 
233
 
234
function getSerialNumbersFromOrder($el){
235
	var $serialNumberElement = $el.find('.serialNumber');
236
	if($serialNumberElement.val() == ''){
237
		return null;
238
	}
239
	var insuranceAmount = parseFloat($el.find('.insuranceAmount').val());
240
	if(insuranceAmount > 0){
241
		insurance = true;
242
		globalInsurace = true;
243
	}else{
244
		insurance = false;
245
	}
246
	return {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
247
}
248
 
249
function orderDetailsPayload(){
23419 ashik.ali 250
	var orderObj = {};
251
	var priceQtyArray = [];
252
	var customerObj = {};
253
	var paymentOptionIdAmount = [];
254
	var globalInsurance = false;
255
 
256
	$("form#cd input.serialNumber").each(function(){
257
		var itemId = parseInt($(this).attr("itemId"));
258
		if (orderObj.hasOwnProperty('fofoOrderItems')){
259
			var itemDetails = orderObj['fofoOrderItems'];
260
			if (itemDetails.hasOwnProperty(itemId)){
261
				var serialNumbers = itemDetails[itemId];
262
				serialNumbers.push($(this).val());
263
				itemDetails[itemId] = serialNumbers;
23347 ashik.ali 264
			}else{
265
				var serialNumbers = [];
266
				serialNumbers.push($(this).val());
23419 ashik.ali 267
				itemDetails[itemId] = serialNumbers;
23347 ashik.ali 268
			}
23419 ashik.ali 269
		}else{
270
			var serialNumbers = [];
271
			serialNumbers.push($(this).val());
272
			var tmp ={};
273
			tmp[itemId]  = serialNumbers;
274
			orderObj['fofoOrderItems'] = tmp;
275
		}
276
	});
277
	console.log( JSON.stringify(orderObj));
278
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
279
		//console.log(el);
280
		//console.log(index);
281
		var $el = $(el);
282
		var $unitPriceElement = $el.find('.unitPrice');
283
		var $discountAmountElement = $el.find('.discountAmount');
23347 ashik.ali 284
 
23419 ashik.ali 285
		var itemId = parseInt($unitPriceElement.attr("itemId"));
286
		var unitPrice = parseFloat($unitPriceElement.val());
287
		var qty = parseInt($unitPriceElement.attr("quantity"));
288
		var discountAmount = parseFloat($discountAmountElement.val());
289
		var mop = $discountAmountElement.attr("mop");
23434 ashik.ali 290
		var prebookingOrder = false;
291
		$('.prebooking-order-details').each(function(){
292
			if($(this).find('.useAdvanceAmount').is(':checked')){
293
		    		var prebookingOrderItemId = parseInt($(this).find('.prebooking-item-id').text());
294
		    		if(prebookingOrderItemId == itemId){
295
		    			prebookingOrder = true;
296
		    		}
297
			}
298
		});
299
 
300
		var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty, 'prebookingOrder':prebookingOrder};
23419 ashik.ali 301
		tmpObj.discountAmount = discountAmount;
302
		/*tmpObj['serialNumberDetails'] = [];
303
		var found = false;
304
		for(var i = 0; i < priceQtyArray.length; i++){			
305
			if (priceQtyArray[i]["itemId"] == itemId){
306
				found = true;
307
				break;
308
			}
309
		}
310
		if(!found){
311
			priceQtyArray.push(tmpObj);
312
		}else{
23347 ashik.ali 313
			for(var i = 0; i < priceQtyArray.length; i++){			
314
				if (priceQtyArray[i]["itemId"] == itemId){
23419 ashik.ali 315
					priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
23347 ashik.ali 316
					break;
317
				}
318
			}
23419 ashik.ali 319
		}
320
		var serialNumberDetails = getSerialNumbersFromOrder($el);
321
		if(serialNumberDetails != null){
23347 ashik.ali 322
			for(var i = 0; i < priceQtyArray.length; i++){			
323
				if (priceQtyArray[i]["itemId"] == itemId){
23419 ashik.ali 324
					priceQtyArray[i]["serialNumberDetails"].push(serialNumberDetails);
23347 ashik.ali 325
					break;
326
				}
327
			}
23419 ashik.ali 328
		}
329
		});*/
330
 
331
		if (orderObj['fofoOrderItems'][itemId] === undefined){
332
			tmpObj['serialNumberDetails'] =[];
333
		}else{
334
			//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
335
			tmpObj['serialNumberDetails'] = [];
336
		}
337
		var found = false;
338
		for(var i = 0; i < priceQtyArray.length; i++){			
339
			if (priceQtyArray[i]["itemId"] == itemId){
340
				priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
341
				found = true;
342
				break;
23347 ashik.ali 343
			}
23419 ashik.ali 344
		}
345
		if(!found){
346
			priceQtyArray.push(tmpObj);
347
		}
348
	});	
23347 ashik.ali 349
 
23419 ashik.ali 350
	$("#order-details").find("tr:not(:first-child)").each(function(index,el){
351
		//console.log(el);
352
		//console.log(index);
353
		var $serialNumberElement = $(el).find('.serialNumber');
354
		var itemId = parseInt($serialNumberElement.attr("itemId"));
355
		var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
356
		//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
357
 
358
		//}
359
		//console.log($serialNumberElement.val());
360
		//console.log(itemId);
361
		for(var i = 0; i < priceQtyArray.length; i++){
362
			console.log(priceQtyArray[i]["itemId"]);
363
			if (priceQtyArray[i]["itemId"] == itemId){
364
				if(insuranceAmount > 0){
365
					insurance = true;
366
					globalInsurance = true;
367
				}else{
368
					insurance = false;
23347 ashik.ali 369
				}
23419 ashik.ali 370
				var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
371
				priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
23353 ashik.ali 372
			}
23419 ashik.ali 373
        }
374
	});
375
 
376
	console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
377
	customerObj['firstName'] = $("form#cd input[name=firstName]").val();
378
	customerObj['lastName'] = $("form#cd input[name=lastName]").val();
379
	customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
380
	customerObj['emailId'] = $("form#cd input[name=email]").val();
381
	customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
382
	customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth]").val();
383
	var customerAddress = {};
384
	customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
385
	customerAddress['line1'] = $("form#cd input[name=line1]").val();
386
	customerAddress['line2'] = $("form#cd input[name=line2]").val();
387
	customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
388
	customerAddress['city'] = $("form#cd input[name=city]").val();
389
	customerAddress['state'] = $('select[name=state] option:selected').val();
390
	customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
391
	customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
392
	customerAddress['country'] = "India";
393
	customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
394
	customerObj['address'] = customerAddress; 
395
	console.log( JSON.stringify(customerObj));
396
 
397
 
398
	var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
399
	//console.log("paymentOptionSize = "+paymentOptionSize);
400
	for(var index = 0; index < paymentOptionSize; index++){
401
		var paymentOptionAmount = 0.0;
402
		if($('#paymentOptionIdAmount'+index).val() != ""){
403
			paymentOptionAmount = parseFloat($('#paymentOptionIdAmount'+index).val());
23367 ashik.ali 404
		}
23419 ashik.ali 405
		var paymentOptionId = $('#paymentOptionIdAmount'+index).attr("paymentOptionId");
406
		var paymentOptionIdAmountObject = {};
407
		paymentOptionIdAmountObject['paymentOptionId'] = paymentOptionId;
408
		paymentOptionIdAmountObject['amount'] = paymentOptionAmount;
409
		paymentOptionIdAmount.push(paymentOptionIdAmountObject);
410
	}
411
 
412
	console.log( JSON.stringify(paymentOptionIdAmount));
413
 
414
	var retObj = {};
415
	var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
416
	if(globalInsurance){
417
		retObj['customerDateOfBirth'] = (dateOfBirth);
418
	}
419
 
420
	retObj['fofoOrderItems'] = (priceQtyArray);
421
	retObj['customer'] = (customerObj);
422
	retObj['paymentOptions'] =  (paymentOptionIdAmount);
423
 
424
	console.log(retObj);
425
	return  JSON.stringify(retObj);
23347 ashik.ali 426
}
427
 
428
 
429
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
23353 ashik.ali 430
	doAjaxRequestHandler(context+"/customer/mobileNumber?mobileNumber="+mobileNumber, "GET", function(response){
431
		var customer = response.response;
432
	    $('#firstName').attr('value', customer.firstName);
433
	    $('#lastName').attr('value', customer.lastName);
434
	    $('#email').attr('value', customer.emailId);
435
	    //$('#phone').attr('value', customer.mobileNumber);
23443 amit.gupta 436
	    if(customer.address !== null) {
437
	    	$('#alternatePhone').attr('value', customer.address.phoneNumber);
438
	    	$('#line1').attr('value', customer.address.line1);
439
	    	$('#line2').attr('value', customer.address.line2);
440
	    	$('#landmark').attr('value', customer.address.landmark);
441
	    	$('#pinCode').attr('value', customer.address.pinCode);
442
	    	$('#city').attr('value', customer.address.city);
443
	    	$('#state').attr('value', customer.address.state).prop('selected',true);
444
	    	$('#phone').attr('addressId', customer.address.id);
445
	    }
23353 ashik.ali 446
	    //$('#state').val(customer.address.state).prop('selected', true);
447
	});
23419 ashik.ali 448
}
449
 
450
$(document).on('change', '.prebooking-order-details', function(){
451
 
452
	var itemIdQuantityMap = {};
453
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
454
		//console.log(el);
455
		//console.log(index);
456
		var $el = $(el);
457
		var $unitPriceElement = $el.find('.unitPrice');
458
 
459
		var itemId = parseInt($unitPriceElement.attr("itemId"));
460
		var qty = parseInt($unitPriceElement.attr("quantity"));
461
		if(itemIdQuantityMap[itemId] == null){
462
			itemIdQuantityMap[itemId] = qty;
463
		}else{
464
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
465
		}
466
 
467
	});
468
 
469
	console.log(itemIdQuantityMap);
470
 
471
	console.log("use advance amount clicked");
472
    if ($('.useAdvanceAmount').is(':checked')) {
473
    		//$(this).val('true');
23434 ashik.ali 474
    		if(localStorage.getItem('otpVerified') != null && localStorage.getItem("otpVerified") == true){
475
    			$('#customer-otp-details').html('');
476
    		}else{
477
	    		var customerOtpDetailsDiv='<div class="row">'
478
	    			+'<div class="col-lg-2 form-group">'
479
					+'<button class="btn btn-primary" id="generate-otp-button" onclick="generateOtp()" type="button">Generate Otp</button>'
480
				+'</div>'
481
	    			+'<div class="col-lg-2 form-group">'
482
	    				+'<input placeholder = "OTP" id="otpValue" name="otpValue"  type="text" class="form-control input-sm">'
483
				+'</div>'
484
				+'<div class="col-lg-2 form-group">'
485
					+'<button class="btn btn-primary" id="validate-otp-button" onclick="validateOtp()" type="button">Validate Otp</button>'
486
				+'</div>';
487
	    		+'</div>';
488
	    		$('#customer-otp-details').html(customerOtpDetailsDiv);
489
    		}
23419 ashik.ali 490
    }else{
491
    		//$(this).val('false');
492
    		$('#customer-otp-details').html('');
493
    }
494
    if($(this).find('.useAdvanceAmount').is(':checked')){
495
    		$(this).find('.useAdvanceAmount').val('true');
496
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
497
		console.log("- advanceAmount : "+advanceAmount);
498
		var quantity = $(this).find('.prebooking-available-quantity').text();
499
		console.log("available quantity : "+quantity);
500
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
501
		console.log("itemId : "+itemId);
502
		var prebookingAmount = 0.0;
503
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
504
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
505
		}else{
506
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
507
		}
508
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 509
 
510
 
511
		//calculateTotalAmount();
512
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
513
		//console.log("netPayableAmount : "+netPayableAmount);
514
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) - prebookingAmount);
515
		$('#cd').find('input.totalAdvanceAmount').val(prebookingAmount);
23419 ashik.ali 516
    }else if(!$(this).find('.useAdvanceAmount').is(':checked')){
517
    		$(this).find('.useAdvanceAmount').val('false');
518
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
519
		console.log("+ advanceAmount : "+advanceAmount);
520
		var quantity = $(this).find('.prebooking-available-quantity').text();
521
		console.log("available quantity : "+quantity);
522
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
523
		console.log("itemId : "+itemId);
524
		var prebookingAmount = 0.0;
525
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
526
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
527
			console.log("used quantity : "+itemIdQuantityMap[itemId]);
528
		}else{
529
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
530
			console.log("used quantity : "+quantity);
531
		}
532
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 533
		//calculateTotalAmount();
534
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
535
		//console.log("netPayableAmount : "+netPayableAmount);
536
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) + prebookingAmount);
537
		var totalAdvanceAmount = $('#cd').find('input.totalAdvanceAmount').val();
538
		$('#cd').find('input.totalAdvanceAmount').val(parseFloat(totalAdvanceAmount) - prebookingAmount);
23419 ashik.ali 539
    }
540
});
541
 
542
/*$(document).on('change', '.useAdvanceAmount', function() {
543
    if($(this).is(':checked')){
544
    		$(this).val('true');
545
    }else{
546
    		$(this).val('false');
547
    }
548
});*/
549
 
550
function generateOtp(){
551
	console.log("generate Otp button clicked")
552
	var itemIdQuantityMap = {};
553
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
554
		//console.log(el);
555
		//console.log(index);
556
		var $el = $(el);
557
		var $unitPriceElement = $el.find('.unitPrice');
558
 
559
		var itemId = parseInt($unitPriceElement.attr("itemId"));
560
		var qty = parseInt($unitPriceElement.attr("quantity"));
561
		if(itemIdQuantityMap[itemId] == null){
562
			itemIdQuantityMap[itemId] = qty;
563
		}else{
564
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
565
		}
566
 
567
	});
568
 
569
	//console.log(itemIdQuantityMap);
570
	var itemIdAdvanceAmountMap = {};
571
	$('.prebooking-order-details').each(function(){
572
		if($(this).find('.useAdvanceAmount').is(':checked')){
573
    			var advanceAmount = $(this).find('.prebooking-advance-amount').text();
574
    			//console.log("- advanceAmount : "+advanceAmount);
575
			var quantity = $(this).find('.prebooking-available-quantity').text();
576
			//console.log("available quantity : "+quantity);
577
			var itemId = parseInt($(this).find('.prebooking-item-id').text());
578
			//console.log("itemId : "+itemId);
579
			var prebookingAmount = 0.0;
580
			if(itemIdQuantityMap[itemId] < parseInt(quantity)){
581
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
582
			}else{
583
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
584
			}
585
			itemIdAdvanceAmountMap[itemId] = prebookingAmount;
586
	    }
587
	});
588
	console.log(itemIdAdvanceAmountMap);
589
	var mobileNumber = $("form#cd input[name=phone]").val();
590
	var emailId = $("form#cd input[name=email]").val();
591
	var url = context+'/generateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId;
592
	doAjaxRequestWithJsonHandler(url, "POST", JSON.stringify(itemIdAdvanceAmountMap), function(response){
593
		console.log("generate Otp response : "+JSON.stringify(response));
23434 ashik.ali 594
		alert("OTP has been generated successfully, Please verify OTP for further process");
23419 ashik.ali 595
		var otpId = parseInt(response.response);
596
		localStorage.setItem("otpId", otpId);
597
		localStorage.setItem("otpVerified", false);
598
	});
599
}
600
 
601
function validateOtp(){
602
	console.log("validateOtp button click");
603
	var mobileNumber = $("form#cd input[name=phone]").val();
604
	var emailId = $("form#cd input[name=email]").val();
605
	var otpId = parseInt(localStorage.getItem('otpId'));
606
	var otpValue = $('#otpValue').val();
607
	if(otpId == null || otpValue == ""){
608
		alert("Please enter otpValue");
609
	}else{
610
		var url = context+'/validateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId+'&otpId='+otpId+'&otpValue='+otpValue;
611
		doAjaxRequestHandler(url, "GET", function(response){
612
			alert(response.response);
613
			localStorage.removeItem("otpId");
23434 ashik.ali 614
			$('#customer-otp-details').html('');
615
			//$('#generate-otp-button').prop("disabled", true);
616
			//$('#otpValue').prop("disabled", true);
617
			//$('#validate-otp-button').prop("disabled", true);
23419 ashik.ali 618
			localStorage.setItem("otpVerified", true);
619
		});
620
	}
621
}
622
 
623
 
624
function checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds){
625
	//window.dispatchEvent(new Event('resize'));
626
 
627
	doAjaxRequestWithJsonHandler(context+"/getPrebookingOrdersByCustomerMobileNumber?customerMobileNumber="+mobileNumber, "POST", JSON.stringify(itemIds), function(response){
628
		$('#prebooking-order-details').html(response);
629
	});
23343 ashik.ali 630
}