Subversion Repositories SmartDukaan

Rev

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