| 23347 |
ashik.ali |
1 |
$(function(){
|
| 24440 |
amit.gupta |
2 |
$(document).on('click', 'button.mk_plan_select', function(){
|
|
|
3 |
$(planCheckedOn).closest('td').find('.insuranceid').val($(this).data('key'));
|
|
|
4 |
$(planCheckedOn).closest('td').find('.insuranceamount').val($(this).data('amount'));
|
|
|
5 |
$('#mobilePlansModal').modal('hide');
|
| 23343 |
ashik.ali |
6 |
calculateTotalAmount();
|
|
|
7 |
});
|
| 24440 |
amit.gupta |
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 |
});
|
|
|
31 |
|
|
|
32 |
$("form#cd input.unitPrice").live('change', function() {
|
| 23343 |
ashik.ali |
33 |
|
|
|
34 |
var unitPrice = parseFloat($(this).val());
|
|
|
35 |
if (isNaN(unitPrice)){
|
|
|
36 |
unitPrice = 0;
|
|
|
37 |
}
|
|
|
38 |
if(unitPrice < 0){
|
|
|
39 |
alert("Invalid unit price");
|
|
|
40 |
$(this).val(0);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
calculateTotalAmount();
|
|
|
44 |
});
|
|
|
45 |
|
|
|
46 |
|
| 24440 |
amit.gupta |
47 |
$("form#cd input.insuranceamount").live('change', function() {
|
| 23343 |
ashik.ali |
48 |
calculateTotalAmount();
|
|
|
49 |
});
|
|
|
50 |
|
| 23347 |
ashik.ali |
51 |
$(".create-order").live('click', function() {
|
|
|
52 |
checkout("main-content");
|
|
|
53 |
});
|
| 24440 |
amit.gupta |
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 |
});
|
| 23343 |
ashik.ali |
71 |
|
| 22245 |
ashik.ali |
72 |
});
|
| 23343 |
ashik.ali |
73 |
|
|
|
74 |
|
| 24440 |
amit.gupta |
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 |
|
| 23343 |
ashik.ali |
105 |
function calculateTotalAmount() {
|
|
|
106 |
var netPayableAmount = 0;
|
| 24440 |
amit.gupta |
107 |
var totaInsuranceAmount = 0;
|
| 23343 |
ashik.ali |
108 |
$("#cd").find('tr:gt(0)').each(function(index, el){
|
|
|
109 |
var rowTotal = 0;
|
|
|
110 |
$tr = $(el);
|
| 24440 |
amit.gupta |
111 |
var insuranceAmount = $tr.find('input.insuranceamount').val();
|
|
|
112 |
if (isNaN(insuranceAmount)){
|
| 23343 |
ashik.ali |
113 |
insuranceAmount = 0;
|
|
|
114 |
}else{
|
|
|
115 |
insuranceAmount = parseFloat(insuranceAmount);
|
|
|
116 |
}
|
|
|
117 |
|
| 23434 |
ashik.ali |
118 |
var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
|
|
|
119 |
if(isNaN(quantity)){
|
|
|
120 |
quantity = 0;
|
|
|
121 |
}
|
|
|
122 |
console.log("quantity : "+quantity);
|
|
|
123 |
|
| 23343 |
ashik.ali |
124 |
var unitPrice = parseFloat($(el).find('.unitPrice').val());
|
| 23434 |
ashik.ali |
125 |
if(isNaN(unitPrice)){
|
|
|
126 |
unitPrice = 0;
|
|
|
127 |
}
|
|
|
128 |
console.log("unitPrice : "+unitPrice);
|
| 23343 |
ashik.ali |
129 |
|
| 24440 |
amit.gupta |
130 |
rowTotal = unitPrice * quantity + insuranceAmount;
|
| 23343 |
ashik.ali |
131 |
$tr.find('.totalPrice').val(rowTotal);
|
|
|
132 |
netPayableAmount += rowTotal;
|
| 24440 |
amit.gupta |
133 |
totaInsuranceAmount += insuranceAmount;
|
| 23343 |
ashik.ali |
134 |
});
|
| 24440 |
amit.gupta |
135 |
if(totaInsuranceAmount > 0) {
|
|
|
136 |
$(".mk_insurance_row").show();
|
|
|
137 |
} else {
|
|
|
138 |
$(".mk_insurance_row").hide();
|
|
|
139 |
}
|
| 23343 |
ashik.ali |
140 |
$('#cd').find('input.netPayableAmount').val(netPayableAmount);
|
|
|
141 |
}
|