Subversion Repositories SmartDukaan

Rev

Rev 23434 | Rev 25737 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23434 Rev 24440
Line 1... Line 1...
1
$(function(){
1
$(function(){
2
	
-
 
3
	$("form#cd input.discountAmount").live('change paste keyup mouseup', function() {
2
	$(document).on('click', 'button.mk_plan_select', function(){
4
		var discountAmount = parseFloat($(this).val());
3
		$(planCheckedOn).closest('td').find('.insuranceid').val($(this).data('key'));
5
		if (isNaN(discountAmount)){
-
 
6
			discountAmount = 0;
-
 
7
		}
-
 
8
		if(discountAmount < 0){
-
 
9
			alert("Invalid insurance Value");
4
		$(planCheckedOn).closest('td').find('.insuranceamount').val($(this).data('amount'));
10
			$(this).val(0);
5
		$('#mobilePlansModal').modal('hide');
11
		}
-
 
12
		calculateTotalAmount();
6
		calculateTotalAmount();
13
	});
7
	});
-
 
8
  
-
 
9
	$(".mk_restore").live('click', function() {
-
 
10
		var customerDetails = localStorage.getItem("customerDetails");
-
 
11
		if(customerDetails!=null) {
-
 
12
			customerObj = JSON.parse(customerDetails);
-
 
13
			$("form#cd input[name=firstName]").val(customerObj['firstName']);
-
 
14
			$("form#cd input[name=lastName]").val(customerObj['lastName']);
-
 
15
			$("form#cd input[name=phone]").val(customerObj['mobileNumber']); 
-
 
16
			$("form#cd input[name=email]").val(customerObj['emailId']);
-
 
17
			$("form#cd input[name=gstNumber]").val(customerObj['gstNumber']);
-
 
18
			var customerAddress = customerObj['address'];
-
 
19
			$("form#cd input[name=line1]").val(customerAddress['line1']);
-
 
20
			$("form#cd input[name=line2]").val(customerAddress['line2']);
-
 
21
			$("form#cd input[name=landmark]").val(customerAddress['landmark']);
-
 
22
			$("form#cd input[name=city]").val(customerAddress['city']);
-
 
23
			$('select[name=state] option:selected').val(customerAddress['state']);
-
 
24
			$("form#cd input[name=pinCode]").val(customerAddress['pinCode']);
-
 
25
			$("form#cd input[name=alternatePhone]").val(customerAddress['phoneNumber']);
-
 
26
			$("form#cd input[name=phone]").attr("addressId", customerObj['customerAddressId']);
-
 
27
			$("form#cd input[name=gender").val(customerObj['gender']);
-
 
28
			$("form#cd input[name=dateOfBirth").val(customerObj['dateOfBirth']);
-
 
29
		}
-
 
30
	});
14
	
31
 
15
	$("form#cd input.unitPrice").live('change paste keyup mouseup', function() {
32
	$("form#cd input.unitPrice").live('change', function() {
16
		
33
		
17
		var unitPrice = parseFloat($(this).val());
34
		var unitPrice = parseFloat($(this).val());
18
		if (isNaN(unitPrice)){
35
		if (isNaN(unitPrice)){
19
			unitPrice = 0;
36
			unitPrice = 0;
20
		}
37
		}
Line 25... Line 42...
25
		
42
		
26
		calculateTotalAmount();
43
		calculateTotalAmount();
27
	});
44
	});
28
	
45
	
29
	
46
	
30
	$("form#cd input.insuranceAmount").live('change paste keyup mouseup', function() {
47
	$("form#cd input.insuranceamount").live('change', function() {
31
		calculateTotalAmount();
48
		calculateTotalAmount();
32
	});
49
	});
33
	
50
	
34
	$(".create-order").live('click', function() {
51
	$(".create-order").live('click', function() {
35
		checkout("main-content");
52
		checkout("main-content");
36
	});
53
	});
-
 
54
	
-
 
55
	$(".mk_check_plans").live('click', function(){
-
 
56
		var mop = parseFloat($(this).data("mop"));
-
 
57
		var sellingPrice = $(this).val();
-
 
58
		if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
-
 
59
			price = paeseFloat(sellingPrice);
-
 
60
		} else {
-
 
61
			price = mop;
-
 
62
		}
-
 
63
		that = this;
-
 
64
		doGetAjaxRequestHandler(context+"/checkplans?price=" + price, function(response){
-
 
65
			var obj = JSON.parse(response);
-
 
66
			getInsurancePlansModal(obj);
-
 
67
			planCheckedOn = that;
-
 
68
			return;
-
 
69
		});
-
 
70
	});
37
 
71
 
38
});
72
});
39
 
73
 
40
 
74
 
-
 
75
function getInsurancePlansModal(insurancePlans) {
-
 
76
	var htmlArr = [];
-
 
77
	for(var key in insurancePlans) {
-
 
78
		templateArr = [];
-
 
79
		var plansList = insurancePlans[key];
-
 
80
		for(var index in plansList) {
-
 
81
			var plan = plansList[index];
-
 
82
			console.log(plan);
-
 
83
			var template = 
-
 
84
				`<div class="col-lg-3">
-
 
85
					<div class="thumbnail">
-
 
86
						<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.provider_id]}" alt="${plan.provider_name}">
-
 
87
			      		<div class="caption" style="padding:9px 0 0">
-
 
88
						    <div style="margin:0 0 -2px -2px"><button class="btn btn-sm btn-default mk_plan_select" data-key="${plan.plan_key}" data-amount="${plan.price}">${plan.price}</button></div>
-
 
89
						</div>
-
 
90
					</div>
-
 
91
				</div>`;
-
 
92
			templateArr.push(template);
-
 
93
			if(index%4==3 || +index+1==plansList.length) {
-
 
94
				templateArr = [`<div class="row col-lg-6">${templateArr.join('')}</div>`];
-
 
95
			}
-
 
96
		}
-
 
97
		htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
-
 
98
	}
-
 
99
	$('#mobilePlansModal').find('.modal-body').html(htmlArr.join(''));
-
 
100
	$('#mobilePlansModal').modal({show: true});
-
 
101
 
-
 
102
}
-
 
103
 
-
 
104
 
41
function calculateTotalAmount() {
105
function calculateTotalAmount() {
42
	var netPayableAmount = 0;
106
	var netPayableAmount = 0;
-
 
107
	var totaInsuranceAmount = 0;
43
	$("#cd").find('tr:gt(0)').each(function(index, el){
108
	$("#cd").find('tr:gt(0)').each(function(index, el){
44
		var rowTotal = 0;
109
		var rowTotal = 0;
45
		$tr = $(el);
110
		$tr = $(el);
46
 
-
 
47
		var insuranceAmount = $tr.find('.insuranceAmount').val();
111
		var insuranceAmount = $tr.find('input.insuranceamount').val();
48
		if (!insuranceAmount){
112
		if (isNaN(insuranceAmount)){
49
			insuranceAmount = 0;
113
			insuranceAmount = 0;
50
		}else{
114
		}else{
51
			insuranceAmount = parseFloat(insuranceAmount);
115
			insuranceAmount = parseFloat(insuranceAmount);
52
		}
116
		}
53
		console.log("insuranceAmount : "+insuranceAmount);
-
 
54
		
117
		
55
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
118
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
56
		if(isNaN(quantity)){
119
		if(isNaN(quantity)){
57
			quantity = 0;
120
			quantity = 0;
58
		}
121
		}
Line 61... Line 124...
61
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
124
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
62
		if(isNaN(unitPrice)){
125
		if(isNaN(unitPrice)){
63
			unitPrice = 0;
126
			unitPrice = 0;
64
		}
127
		}
65
		console.log("unitPrice : "+unitPrice);
128
		console.log("unitPrice : "+unitPrice);
66
		
-
 
67
		var discountAmount =  parseFloat($(el).find('.discountAmount').val());
-
 
68
		if(isNaN(discountAmount)){
-
 
69
			discountAmount = 0.0;
-
 
70
		}
-
 
71
 
129
 
72
		rowTotal = unitPrice * quantity + insuranceAmount - discountAmount; 
130
		rowTotal = unitPrice * quantity + insuranceAmount; 
73
		$tr.find('.totalPrice').val(rowTotal);
131
		$tr.find('.totalPrice').val(rowTotal);
74
		netPayableAmount += rowTotal;
132
		netPayableAmount += rowTotal;
-
 
133
		totaInsuranceAmount += insuranceAmount;
75
	});
134
	});
-
 
135
	if(totaInsuranceAmount > 0) {
-
 
136
		$(".mk_insurance_row").show();
-
 
137
	} else {
-
 
138
		$(".mk_insurance_row").hide();
-
 
139
	}
76
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
140
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
77
}
141
}