Subversion Repositories SmartDukaan

Rev

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