Subversion Repositories SmartDukaan

Rev

Rev 23434 | Rev 23443 | 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);
23434 ashik.ali 126
		calculateTotalAmount();
23419 ashik.ali 127
		checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds);
22354 ashik.ali 128
	});
22245 ashik.ali 129
 
23343 ashik.ali 130
});
131
 
132
 
133
function validateOrderDetails(){
134
	var sNumbers = [];
135
	var error = false;
136
	$("form#cd input.serialNumber").each(function(){
137
		var input = $(this).val().trim();
138
		var itemType = $(this).attr("itemType");
139
		$(this).removeClass("border-highlight");
140
		if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
141
			error = true;
142
			$(this).addClass("border-highlight");
143
		}
144
		sNumbers.push(input);
145
	});
146
 
147
	$("form#cd input.unitPrice").each(function(){
148
		var input = $(this).val().trim();
149
		$(this).removeClass("border-highlight");
150
		if (!input || parseInt(input)<=0 || isNaN(input)){
151
			error=true;
152
			$(this).addClass("border-highlight");
153
		}
154
		var unitPrice = parseFloat(input);
155
		var mopPrice = parseFloat($(this).attr('mopPrice'));
156
		if(unitPrice < mopPrice){
157
			error = true;
158
			alert("sellingPrice must be greater than equal to mop")
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;
306
		/*tmpObj['serialNumberDetails'] = [];
307
		var found = false;
308
		for(var i = 0; i < priceQtyArray.length; i++){			
309
			if (priceQtyArray[i]["itemId"] == itemId){
310
				found = true;
311
				break;
312
			}
313
		}
314
		if(!found){
315
			priceQtyArray.push(tmpObj);
316
		}else{
23347 ashik.ali 317
			for(var i = 0; i < priceQtyArray.length; i++){			
318
				if (priceQtyArray[i]["itemId"] == itemId){
23419 ashik.ali 319
					priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
23347 ashik.ali 320
					break;
321
				}
322
			}
23419 ashik.ali 323
		}
324
		var serialNumberDetails = getSerialNumbersFromOrder($el);
325
		if(serialNumberDetails != null){
23347 ashik.ali 326
			for(var i = 0; i < priceQtyArray.length; i++){			
327
				if (priceQtyArray[i]["itemId"] == itemId){
23419 ashik.ali 328
					priceQtyArray[i]["serialNumberDetails"].push(serialNumberDetails);
23347 ashik.ali 329
					break;
330
				}
331
			}
23419 ashik.ali 332
		}
333
		});*/
334
 
335
		if (orderObj['fofoOrderItems'][itemId] === undefined){
336
			tmpObj['serialNumberDetails'] =[];
337
		}else{
338
			//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
339
			tmpObj['serialNumberDetails'] = [];
340
		}
341
		var found = false;
342
		for(var i = 0; i < priceQtyArray.length; i++){			
343
			if (priceQtyArray[i]["itemId"] == itemId){
344
				priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
345
				found = true;
346
				break;
23347 ashik.ali 347
			}
23419 ashik.ali 348
		}
349
		if(!found){
350
			priceQtyArray.push(tmpObj);
351
		}
352
	});	
23347 ashik.ali 353
 
23419 ashik.ali 354
	$("#order-details").find("tr:not(:first-child)").each(function(index,el){
355
		//console.log(el);
356
		//console.log(index);
357
		var $serialNumberElement = $(el).find('.serialNumber');
358
		var itemId = parseInt($serialNumberElement.attr("itemId"));
359
		var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
360
		//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
361
 
362
		//}
363
		//console.log($serialNumberElement.val());
364
		//console.log(itemId);
365
		for(var i = 0; i < priceQtyArray.length; i++){
366
			console.log(priceQtyArray[i]["itemId"]);
367
			if (priceQtyArray[i]["itemId"] == itemId){
368
				if(insuranceAmount > 0){
369
					insurance = true;
370
					globalInsurance = true;
371
				}else{
372
					insurance = false;
23347 ashik.ali 373
				}
23419 ashik.ali 374
				var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
375
				priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
23353 ashik.ali 376
			}
23419 ashik.ali 377
        }
378
	});
379
 
380
	console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
381
	customerObj['firstName'] = $("form#cd input[name=firstName]").val();
382
	customerObj['lastName'] = $("form#cd input[name=lastName]").val();
383
	customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
384
	customerObj['emailId'] = $("form#cd input[name=email]").val();
385
	customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
386
	customerObj['dateOfBirth'] = $("form#cd input[name=dateOfBirth]").val();
387
	var customerAddress = {};
388
	customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
389
	customerAddress['line1'] = $("form#cd input[name=line1]").val();
390
	customerAddress['line2'] = $("form#cd input[name=line2]").val();
391
	customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
392
	customerAddress['city'] = $("form#cd input[name=city]").val();
393
	customerAddress['state'] = $('select[name=state] option:selected').val();
394
	customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
395
	customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
396
	customerAddress['country'] = "India";
397
	customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
398
	customerObj['address'] = customerAddress; 
399
	console.log( JSON.stringify(customerObj));
400
 
401
 
402
	var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
403
	//console.log("paymentOptionSize = "+paymentOptionSize);
404
	for(var index = 0; index < paymentOptionSize; index++){
405
		var paymentOptionAmount = 0.0;
406
		if($('#paymentOptionIdAmount'+index).val() != ""){
407
			paymentOptionAmount = parseFloat($('#paymentOptionIdAmount'+index).val());
23367 ashik.ali 408
		}
23419 ashik.ali 409
		var paymentOptionId = $('#paymentOptionIdAmount'+index).attr("paymentOptionId");
410
		var paymentOptionIdAmountObject = {};
411
		paymentOptionIdAmountObject['paymentOptionId'] = paymentOptionId;
412
		paymentOptionIdAmountObject['amount'] = paymentOptionAmount;
413
		paymentOptionIdAmount.push(paymentOptionIdAmountObject);
414
	}
415
 
416
	console.log( JSON.stringify(paymentOptionIdAmount));
417
 
418
	var retObj = {};
419
	var dateOfBirth = $("form#cd input[name=dateOfBirth]").val();
420
	if(globalInsurance){
421
		retObj['customerDateOfBirth'] = (dateOfBirth);
422
	}
423
 
424
	retObj['fofoOrderItems'] = (priceQtyArray);
425
	retObj['customer'] = (customerObj);
426
	retObj['paymentOptions'] =  (paymentOptionIdAmount);
427
 
428
	console.log(retObj);
429
	return  JSON.stringify(retObj);
23347 ashik.ali 430
}
431
 
432
 
433
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
23353 ashik.ali 434
	doAjaxRequestHandler(context+"/customer/mobileNumber?mobileNumber="+mobileNumber, "GET", function(response){
435
		var customer = response.response;
436
	    $('#firstName').attr('value', customer.firstName);
437
	    $('#lastName').attr('value', customer.lastName);
438
	    $('#email').attr('value', customer.emailId);
439
	    //$('#phone').attr('value', customer.mobileNumber);
440
	    $('#alternatePhone').attr('value', customer.address.phoneNumber);
441
	    $('#line1').attr('value', customer.address.line1);
442
	    $('#line2').attr('value', customer.address.line2);
443
	    $('#landmark').attr('value', customer.address.landmark);
444
	    $('#pinCode').attr('value', customer.address.pinCode);
445
	    $('#city').attr('value', customer.address.city);
446
	    $('#state').attr('value', customer.address.state).prop('selected',true);
447
	    //$('#state').val(customer.address.state).prop('selected', true);
448
	    $('#phone').attr('addressId', customer.address.id);
449
	});
23419 ashik.ali 450
}
451
 
452
$(document).on('change', '.prebooking-order-details', function(){
453
 
454
	var itemIdQuantityMap = {};
455
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
456
		//console.log(el);
457
		//console.log(index);
458
		var $el = $(el);
459
		var $unitPriceElement = $el.find('.unitPrice');
460
 
461
		var itemId = parseInt($unitPriceElement.attr("itemId"));
462
		var qty = parseInt($unitPriceElement.attr("quantity"));
463
		if(itemIdQuantityMap[itemId] == null){
464
			itemIdQuantityMap[itemId] = qty;
465
		}else{
466
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
467
		}
468
 
469
	});
470
 
471
	console.log(itemIdQuantityMap);
472
 
473
	console.log("use advance amount clicked");
474
    if ($('.useAdvanceAmount').is(':checked')) {
475
    		//$(this).val('true');
23434 ashik.ali 476
    		if(localStorage.getItem('otpVerified') != null && localStorage.getItem("otpVerified") == true){
477
    			$('#customer-otp-details').html('');
478
    		}else{
479
	    		var customerOtpDetailsDiv='<div class="row">'
480
	    			+'<div class="col-lg-2 form-group">'
481
					+'<button class="btn btn-primary" id="generate-otp-button" onclick="generateOtp()" type="button">Generate Otp</button>'
482
				+'</div>'
483
	    			+'<div class="col-lg-2 form-group">'
484
	    				+'<input placeholder = "OTP" id="otpValue" name="otpValue"  type="text" class="form-control input-sm">'
485
				+'</div>'
486
				+'<div class="col-lg-2 form-group">'
487
					+'<button class="btn btn-primary" id="validate-otp-button" onclick="validateOtp()" type="button">Validate Otp</button>'
488
				+'</div>';
489
	    		+'</div>';
490
	    		$('#customer-otp-details').html(customerOtpDetailsDiv);
491
    		}
23419 ashik.ali 492
    }else{
493
    		//$(this).val('false');
494
    		$('#customer-otp-details').html('');
495
    }
496
    if($(this).find('.useAdvanceAmount').is(':checked')){
497
    		$(this).find('.useAdvanceAmount').val('true');
498
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
499
		console.log("- advanceAmount : "+advanceAmount);
500
		var quantity = $(this).find('.prebooking-available-quantity').text();
501
		console.log("available quantity : "+quantity);
502
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
503
		console.log("itemId : "+itemId);
504
		var prebookingAmount = 0.0;
505
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
506
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
507
		}else{
508
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
509
		}
510
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 511
 
512
 
513
		//calculateTotalAmount();
514
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
515
		//console.log("netPayableAmount : "+netPayableAmount);
516
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) - prebookingAmount);
517
		$('#cd').find('input.totalAdvanceAmount').val(prebookingAmount);
23419 ashik.ali 518
    }else if(!$(this).find('.useAdvanceAmount').is(':checked')){
519
    		$(this).find('.useAdvanceAmount').val('false');
520
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
521
		console.log("+ advanceAmount : "+advanceAmount);
522
		var quantity = $(this).find('.prebooking-available-quantity').text();
523
		console.log("available quantity : "+quantity);
524
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
525
		console.log("itemId : "+itemId);
526
		var prebookingAmount = 0.0;
527
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
528
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
529
			console.log("used quantity : "+itemIdQuantityMap[itemId]);
530
		}else{
531
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
532
			console.log("used quantity : "+quantity);
533
		}
534
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 535
		//calculateTotalAmount();
536
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
537
		//console.log("netPayableAmount : "+netPayableAmount);
538
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) + prebookingAmount);
539
		var totalAdvanceAmount = $('#cd').find('input.totalAdvanceAmount').val();
540
		$('#cd').find('input.totalAdvanceAmount').val(parseFloat(totalAdvanceAmount) - prebookingAmount);
23419 ashik.ali 541
    }
542
});
543
 
544
/*$(document).on('change', '.useAdvanceAmount', function() {
545
    if($(this).is(':checked')){
546
    		$(this).val('true');
547
    }else{
548
    		$(this).val('false');
549
    }
550
});*/
551
 
552
function generateOtp(){
553
	console.log("generate Otp button clicked")
554
	var itemIdQuantityMap = {};
555
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
556
		//console.log(el);
557
		//console.log(index);
558
		var $el = $(el);
559
		var $unitPriceElement = $el.find('.unitPrice');
560
 
561
		var itemId = parseInt($unitPriceElement.attr("itemId"));
562
		var qty = parseInt($unitPriceElement.attr("quantity"));
563
		if(itemIdQuantityMap[itemId] == null){
564
			itemIdQuantityMap[itemId] = qty;
565
		}else{
566
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
567
		}
568
 
569
	});
570
 
571
	//console.log(itemIdQuantityMap);
572
	var itemIdAdvanceAmountMap = {};
573
	$('.prebooking-order-details').each(function(){
574
		if($(this).find('.useAdvanceAmount').is(':checked')){
575
    			var advanceAmount = $(this).find('.prebooking-advance-amount').text();
576
    			//console.log("- advanceAmount : "+advanceAmount);
577
			var quantity = $(this).find('.prebooking-available-quantity').text();
578
			//console.log("available quantity : "+quantity);
579
			var itemId = parseInt($(this).find('.prebooking-item-id').text());
580
			//console.log("itemId : "+itemId);
581
			var prebookingAmount = 0.0;
582
			if(itemIdQuantityMap[itemId] < parseInt(quantity)){
583
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
584
			}else{
585
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
586
			}
587
			itemIdAdvanceAmountMap[itemId] = prebookingAmount;
588
	    }
589
	});
590
	console.log(itemIdAdvanceAmountMap);
591
	var mobileNumber = $("form#cd input[name=phone]").val();
592
	var emailId = $("form#cd input[name=email]").val();
593
	var url = context+'/generateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId;
594
	doAjaxRequestWithJsonHandler(url, "POST", JSON.stringify(itemIdAdvanceAmountMap), function(response){
595
		console.log("generate Otp response : "+JSON.stringify(response));
23434 ashik.ali 596
		alert("OTP has been generated successfully, Please verify OTP for further process");
23419 ashik.ali 597
		var otpId = parseInt(response.response);
598
		localStorage.setItem("otpId", otpId);
599
		localStorage.setItem("otpVerified", false);
600
	});
601
}
602
 
603
function validateOtp(){
604
	console.log("validateOtp button click");
605
	var mobileNumber = $("form#cd input[name=phone]").val();
606
	var emailId = $("form#cd input[name=email]").val();
607
	var otpId = parseInt(localStorage.getItem('otpId'));
608
	var otpValue = $('#otpValue').val();
609
	if(otpId == null || otpValue == ""){
610
		alert("Please enter otpValue");
611
	}else{
612
		var url = context+'/validateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId+'&otpId='+otpId+'&otpValue='+otpValue;
613
		doAjaxRequestHandler(url, "GET", function(response){
614
			alert(response.response);
615
			localStorage.removeItem("otpId");
23434 ashik.ali 616
			$('#customer-otp-details').html('');
617
			//$('#generate-otp-button').prop("disabled", true);
618
			//$('#otpValue').prop("disabled", true);
619
			//$('#validate-otp-button').prop("disabled", true);
23419 ashik.ali 620
			localStorage.setItem("otpVerified", true);
621
		});
622
	}
623
}
624
 
625
 
626
function checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds){
627
	//window.dispatchEvent(new Event('resize'));
628
 
629
	doAjaxRequestWithJsonHandler(context+"/getPrebookingOrdersByCustomerMobileNumber?customerMobileNumber="+mobileNumber, "POST", JSON.stringify(itemIds), function(response){
630
		$('#prebooking-order-details').html(response);
631
	});
23343 ashik.ali 632
}