| 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();
|
| 25737 |
amit.gupta |
58 |
var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
|
| 24440 |
amit.gupta |
59 |
if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
|
|
|
60 |
price = paeseFloat(sellingPrice);
|
|
|
61 |
} else {
|
|
|
62 |
price = mop;
|
|
|
63 |
}
|
|
|
64 |
that = this;
|
| 25737 |
amit.gupta |
65 |
doGetAjaxRequestHandler(context+"/checkplans?price=" + price + "&itemId=" + itemId, function(response){
|
| 24440 |
amit.gupta |
66 |
var obj = JSON.parse(response);
|
|
|
67 |
getInsurancePlansModal(obj);
|
|
|
68 |
planCheckedOn = that;
|
|
|
69 |
return;
|
|
|
70 |
});
|
|
|
71 |
});
|
| 23343 |
ashik.ali |
72 |
|
| 22245 |
ashik.ali |
73 |
});
|
| 23343 |
ashik.ali |
74 |
|
|
|
75 |
|
| 24440 |
amit.gupta |
76 |
function getInsurancePlansModal(insurancePlans) {
|
|
|
77 |
var htmlArr = [];
|
|
|
78 |
for(var key in insurancePlans) {
|
|
|
79 |
templateArr = [];
|
|
|
80 |
var plansList = insurancePlans[key];
|
|
|
81 |
for(var index in plansList) {
|
|
|
82 |
var plan = plansList[index];
|
|
|
83 |
console.log(plan);
|
|
|
84 |
var template =
|
|
|
85 |
`<div class="col-lg-3">
|
|
|
86 |
<div class="thumbnail">
|
| 25737 |
amit.gupta |
87 |
<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
|
| 24440 |
amit.gupta |
88 |
<div class="caption" style="padding:9px 0 0">
|
| 25737 |
amit.gupta |
89 |
<div style="margin:0 0 -2px -2px">
|
|
|
90 |
<button class="btn btn-sm btn-default mk_plan_select" style="width:100%"
|
|
|
91 |
data-key="${plan.productId}"
|
|
|
92 |
data-amount="${plan.premium}">${plan.premium}
|
|
|
93 |
</button>
|
|
|
94 |
</div>
|
| 24440 |
amit.gupta |
95 |
</div>
|
|
|
96 |
</div>
|
|
|
97 |
</div>`;
|
|
|
98 |
templateArr.push(template);
|
|
|
99 |
if(index%4==3 || +index+1==plansList.length) {
|
|
|
100 |
templateArr = [`<div class="row col-lg-6">${templateArr.join('')}</div>`];
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
|
|
|
104 |
}
|
|
|
105 |
$('#mobilePlansModal').find('.modal-body').html(htmlArr.join(''));
|
|
|
106 |
$('#mobilePlansModal').modal({show: true});
|
|
|
107 |
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
|
| 23343 |
ashik.ali |
111 |
function calculateTotalAmount() {
|
|
|
112 |
var netPayableAmount = 0;
|
| 24440 |
amit.gupta |
113 |
var totaInsuranceAmount = 0;
|
| 23343 |
ashik.ali |
114 |
$("#cd").find('tr:gt(0)').each(function(index, el){
|
|
|
115 |
var rowTotal = 0;
|
|
|
116 |
$tr = $(el);
|
| 24440 |
amit.gupta |
117 |
var insuranceAmount = $tr.find('input.insuranceamount').val();
|
|
|
118 |
if (isNaN(insuranceAmount)){
|
| 23343 |
ashik.ali |
119 |
insuranceAmount = 0;
|
|
|
120 |
}else{
|
|
|
121 |
insuranceAmount = parseFloat(insuranceAmount);
|
|
|
122 |
}
|
|
|
123 |
|
| 23434 |
ashik.ali |
124 |
var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
|
|
|
125 |
if(isNaN(quantity)){
|
|
|
126 |
quantity = 0;
|
|
|
127 |
}
|
|
|
128 |
console.log("quantity : "+quantity);
|
|
|
129 |
|
| 23343 |
ashik.ali |
130 |
var unitPrice = parseFloat($(el).find('.unitPrice').val());
|
| 23434 |
ashik.ali |
131 |
if(isNaN(unitPrice)){
|
|
|
132 |
unitPrice = 0;
|
|
|
133 |
}
|
|
|
134 |
console.log("unitPrice : "+unitPrice);
|
| 23343 |
ashik.ali |
135 |
|
| 24440 |
amit.gupta |
136 |
rowTotal = unitPrice * quantity + insuranceAmount;
|
| 23343 |
ashik.ali |
137 |
$tr.find('.totalPrice').val(rowTotal);
|
|
|
138 |
netPayableAmount += rowTotal;
|
| 24440 |
amit.gupta |
139 |
totaInsuranceAmount += insuranceAmount;
|
| 23343 |
ashik.ali |
140 |
});
|
| 24440 |
amit.gupta |
141 |
if(totaInsuranceAmount > 0) {
|
|
|
142 |
$(".mk_insurance_row").show();
|
|
|
143 |
} else {
|
|
|
144 |
$(".mk_insurance_row").hide();
|
|
|
145 |
}
|
| 23343 |
ashik.ali |
146 |
$('#cd').find('input.netPayableAmount').val(netPayableAmount);
|
|
|
147 |
}
|