Subversion Repositories SmartDukaan

Rev

Rev 23440 | Rev 23569 | 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);
23443 amit.gupta 440
	    if(customer.address !== null) {
441
	    	$('#alternatePhone').attr('value', customer.address.phoneNumber);
442
	    	$('#line1').attr('value', customer.address.line1);
443
	    	$('#line2').attr('value', customer.address.line2);
444
	    	$('#landmark').attr('value', customer.address.landmark);
445
	    	$('#pinCode').attr('value', customer.address.pinCode);
446
	    	$('#city').attr('value', customer.address.city);
447
	    	$('#state').attr('value', customer.address.state).prop('selected',true);
448
	    	$('#phone').attr('addressId', customer.address.id);
449
	    }
23353 ashik.ali 450
	    //$('#state').val(customer.address.state).prop('selected', true);
451
	});
23419 ashik.ali 452
}
453
 
454
$(document).on('change', '.prebooking-order-details', function(){
455
 
456
	var itemIdQuantityMap = {};
457
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
458
		//console.log(el);
459
		//console.log(index);
460
		var $el = $(el);
461
		var $unitPriceElement = $el.find('.unitPrice');
462
 
463
		var itemId = parseInt($unitPriceElement.attr("itemId"));
464
		var qty = parseInt($unitPriceElement.attr("quantity"));
465
		if(itemIdQuantityMap[itemId] == null){
466
			itemIdQuantityMap[itemId] = qty;
467
		}else{
468
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
469
		}
470
 
471
	});
472
 
473
	console.log(itemIdQuantityMap);
474
 
475
	console.log("use advance amount clicked");
476
    if ($('.useAdvanceAmount').is(':checked')) {
477
    		//$(this).val('true');
23434 ashik.ali 478
    		if(localStorage.getItem('otpVerified') != null && localStorage.getItem("otpVerified") == true){
479
    			$('#customer-otp-details').html('');
480
    		}else{
481
	    		var customerOtpDetailsDiv='<div class="row">'
482
	    			+'<div class="col-lg-2 form-group">'
483
					+'<button class="btn btn-primary" id="generate-otp-button" onclick="generateOtp()" type="button">Generate Otp</button>'
484
				+'</div>'
485
	    			+'<div class="col-lg-2 form-group">'
486
	    				+'<input placeholder = "OTP" id="otpValue" name="otpValue"  type="text" class="form-control input-sm">'
487
				+'</div>'
488
				+'<div class="col-lg-2 form-group">'
489
					+'<button class="btn btn-primary" id="validate-otp-button" onclick="validateOtp()" type="button">Validate Otp</button>'
490
				+'</div>';
491
	    		+'</div>';
492
	    		$('#customer-otp-details').html(customerOtpDetailsDiv);
493
    		}
23419 ashik.ali 494
    }else{
495
    		//$(this).val('false');
496
    		$('#customer-otp-details').html('');
497
    }
498
    if($(this).find('.useAdvanceAmount').is(':checked')){
499
    		$(this).find('.useAdvanceAmount').val('true');
500
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
501
		console.log("- advanceAmount : "+advanceAmount);
502
		var quantity = $(this).find('.prebooking-available-quantity').text();
503
		console.log("available quantity : "+quantity);
504
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
505
		console.log("itemId : "+itemId);
506
		var prebookingAmount = 0.0;
507
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
508
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
509
		}else{
510
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
511
		}
512
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 513
 
514
 
515
		//calculateTotalAmount();
516
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
517
		//console.log("netPayableAmount : "+netPayableAmount);
518
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) - prebookingAmount);
519
		$('#cd').find('input.totalAdvanceAmount').val(prebookingAmount);
23419 ashik.ali 520
    }else if(!$(this).find('.useAdvanceAmount').is(':checked')){
521
    		$(this).find('.useAdvanceAmount').val('false');
522
    		var advanceAmount = $(this).find('.prebooking-advance-amount').text();
523
		console.log("+ advanceAmount : "+advanceAmount);
524
		var quantity = $(this).find('.prebooking-available-quantity').text();
525
		console.log("available quantity : "+quantity);
526
		var itemId = parseInt($(this).find('.prebooking-item-id').text());
527
		console.log("itemId : "+itemId);
528
		var prebookingAmount = 0.0;
529
		if(itemIdQuantityMap[itemId] < parseInt(quantity)){
530
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
531
			console.log("used quantity : "+itemIdQuantityMap[itemId]);
532
		}else{
533
			prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
534
			console.log("used quantity : "+quantity);
535
		}
536
		console.log("prebookingAmount : "+prebookingAmount);
23434 ashik.ali 537
		//calculateTotalAmount();
538
		//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
539
		//console.log("netPayableAmount : "+netPayableAmount);
540
		//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) + prebookingAmount);
541
		var totalAdvanceAmount = $('#cd').find('input.totalAdvanceAmount').val();
542
		$('#cd').find('input.totalAdvanceAmount').val(parseFloat(totalAdvanceAmount) - prebookingAmount);
23419 ashik.ali 543
    }
544
});
545
 
546
/*$(document).on('change', '.useAdvanceAmount', function() {
547
    if($(this).is(':checked')){
548
    		$(this).val('true');
549
    }else{
550
    		$(this).val('false');
551
    }
552
});*/
553
 
554
function generateOtp(){
555
	console.log("generate Otp button clicked")
556
	var itemIdQuantityMap = {};
557
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
558
		//console.log(el);
559
		//console.log(index);
560
		var $el = $(el);
561
		var $unitPriceElement = $el.find('.unitPrice');
562
 
563
		var itemId = parseInt($unitPriceElement.attr("itemId"));
564
		var qty = parseInt($unitPriceElement.attr("quantity"));
565
		if(itemIdQuantityMap[itemId] == null){
566
			itemIdQuantityMap[itemId] = qty;
567
		}else{
568
			itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
569
		}
570
 
571
	});
572
 
573
	//console.log(itemIdQuantityMap);
574
	var itemIdAdvanceAmountMap = {};
575
	$('.prebooking-order-details').each(function(){
576
		if($(this).find('.useAdvanceAmount').is(':checked')){
577
    			var advanceAmount = $(this).find('.prebooking-advance-amount').text();
578
    			//console.log("- advanceAmount : "+advanceAmount);
579
			var quantity = $(this).find('.prebooking-available-quantity').text();
580
			//console.log("available quantity : "+quantity);
581
			var itemId = parseInt($(this).find('.prebooking-item-id').text());
582
			//console.log("itemId : "+itemId);
583
			var prebookingAmount = 0.0;
584
			if(itemIdQuantityMap[itemId] < parseInt(quantity)){
585
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
586
			}else{
587
				prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
588
			}
589
			itemIdAdvanceAmountMap[itemId] = prebookingAmount;
590
	    }
591
	});
592
	console.log(itemIdAdvanceAmountMap);
593
	var mobileNumber = $("form#cd input[name=phone]").val();
594
	var emailId = $("form#cd input[name=email]").val();
595
	var url = context+'/generateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId;
596
	doAjaxRequestWithJsonHandler(url, "POST", JSON.stringify(itemIdAdvanceAmountMap), function(response){
597
		console.log("generate Otp response : "+JSON.stringify(response));
23434 ashik.ali 598
		alert("OTP has been generated successfully, Please verify OTP for further process");
23419 ashik.ali 599
		var otpId = parseInt(response.response);
600
		localStorage.setItem("otpId", otpId);
601
		localStorage.setItem("otpVerified", false);
602
	});
603
}
604
 
605
function validateOtp(){
606
	console.log("validateOtp button click");
607
	var mobileNumber = $("form#cd input[name=phone]").val();
608
	var emailId = $("form#cd input[name=email]").val();
609
	var otpId = parseInt(localStorage.getItem('otpId'));
610
	var otpValue = $('#otpValue').val();
611
	if(otpId == null || otpValue == ""){
612
		alert("Please enter otpValue");
613
	}else{
614
		var url = context+'/validateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId+'&otpId='+otpId+'&otpValue='+otpValue;
615
		doAjaxRequestHandler(url, "GET", function(response){
616
			alert(response.response);
617
			localStorage.removeItem("otpId");
23434 ashik.ali 618
			$('#customer-otp-details').html('');
619
			//$('#generate-otp-button').prop("disabled", true);
620
			//$('#otpValue').prop("disabled", true);
621
			//$('#validate-otp-button').prop("disabled", true);
23419 ashik.ali 622
			localStorage.setItem("otpVerified", true);
623
		});
624
	}
625
}
626
 
627
 
628
function checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds){
629
	//window.dispatchEvent(new Event('resize'));
630
 
631
	doAjaxRequestWithJsonHandler(context+"/getPrebookingOrdersByCustomerMobileNumber?customerMobileNumber="+mobileNumber, "POST", JSON.stringify(itemIds), function(response){
632
		$('#prebooking-order-details').html(response);
633
	});
23343 ashik.ali 634
}