| 23347 |
ashik.ali |
1 |
$(function(){
|
| 24440 |
amit.gupta |
2 |
$(document).on('click', 'button.mk_plan_select', function(){
|
| 25778 |
amit.gupta |
3 |
$itemDetails = $('div.itemdetails');
|
| 25780 |
amit.gupta |
4 |
if($itemDetails.find('.dgram').val()==='') {
|
| 25778 |
amit.gupta |
5 |
bootbox.alert('Mobile RAM is required');
|
|
|
6 |
return;
|
|
|
7 |
}
|
| 25780 |
amit.gupta |
8 |
if($itemDetails.find('.dgmemory').val()==='') {
|
| 25778 |
amit.gupta |
9 |
bootbox.alert('Mobile Memory is required');
|
|
|
10 |
return;
|
|
|
11 |
}
|
|
|
12 |
if($itemDetails.find('#dgmfgdate').val()==='') {
|
|
|
13 |
bootbox.alert('Mobile Mfg Date is required');
|
|
|
14 |
return;
|
|
|
15 |
}
|
|
|
16 |
$orderItemRow = $(planCheckedOn).closest('td');
|
|
|
17 |
$orderItemRow.find('.insuranceid').val($(this).data('key'));
|
|
|
18 |
$orderItemRow.find('.insuranceamount').val($(this).data('amount'));
|
|
|
19 |
$orderItemRow.find('.ram').val($itemDetails.find('.dgram').val());
|
|
|
20 |
$orderItemRow.find('.memory').val($itemDetails.find('.dgmemory').val());
|
| 25813 |
amit.gupta |
21 |
$orderItemRow.find('.mfgdate').val(mfgDate);
|
| 24440 |
amit.gupta |
22 |
$('#mobilePlansModal').modal('hide');
|
| 23343 |
ashik.ali |
23 |
calculateTotalAmount();
|
|
|
24 |
});
|
| 24440 |
amit.gupta |
25 |
|
| 26669 |
tejbeer |
26 |
$("#mk_restore").live('click', function() {
|
| 24440 |
amit.gupta |
27 |
var customerDetails = localStorage.getItem("customerDetails");
|
|
|
28 |
if(customerDetails!=null) {
|
|
|
29 |
customerObj = JSON.parse(customerDetails);
|
|
|
30 |
$("form#cd input[name=firstName]").val(customerObj['firstName']);
|
|
|
31 |
$("form#cd input[name=lastName]").val(customerObj['lastName']);
|
|
|
32 |
$("form#cd input[name=phone]").val(customerObj['mobileNumber']);
|
|
|
33 |
$("form#cd input[name=email]").val(customerObj['emailId']);
|
|
|
34 |
$("form#cd input[name=gstNumber]").val(customerObj['gstNumber']);
|
|
|
35 |
var customerAddress = customerObj['address'];
|
|
|
36 |
$("form#cd input[name=line1]").val(customerAddress['line1']);
|
|
|
37 |
$("form#cd input[name=line2]").val(customerAddress['line2']);
|
|
|
38 |
$("form#cd input[name=landmark]").val(customerAddress['landmark']);
|
|
|
39 |
$("form#cd input[name=city]").val(customerAddress['city']);
|
|
|
40 |
$('select[name=state] option:selected').val(customerAddress['state']);
|
|
|
41 |
$("form#cd input[name=pinCode]").val(customerAddress['pinCode']);
|
|
|
42 |
$("form#cd input[name=alternatePhone]").val(customerAddress['phoneNumber']);
|
|
|
43 |
$("form#cd input[name=phone]").attr("addressId", customerObj['customerAddressId']);
|
|
|
44 |
}
|
|
|
45 |
});
|
|
|
46 |
|
|
|
47 |
$("form#cd input.unitPrice").live('change', function() {
|
| 23343 |
ashik.ali |
48 |
|
|
|
49 |
var unitPrice = parseFloat($(this).val());
|
|
|
50 |
if (isNaN(unitPrice)){
|
|
|
51 |
unitPrice = 0;
|
|
|
52 |
}
|
|
|
53 |
if(unitPrice < 0){
|
|
|
54 |
alert("Invalid unit price");
|
|
|
55 |
$(this).val(0);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
calculateTotalAmount();
|
|
|
59 |
});
|
|
|
60 |
|
|
|
61 |
|
| 24440 |
amit.gupta |
62 |
$("form#cd input.insuranceamount").live('change', function() {
|
| 23343 |
ashik.ali |
63 |
calculateTotalAmount();
|
|
|
64 |
});
|
|
|
65 |
|
| 23347 |
ashik.ali |
66 |
$(".create-order").live('click', function() {
|
|
|
67 |
checkout("main-content");
|
|
|
68 |
});
|
| 24440 |
amit.gupta |
69 |
|
|
|
70 |
$(".mk_check_plans").live('click', function(){
|
| 25778 |
amit.gupta |
71 |
$('div.itemdetails').find('input').val('');
|
| 24440 |
amit.gupta |
72 |
var mop = parseFloat($(this).data("mop"));
|
|
|
73 |
var sellingPrice = $(this).val();
|
| 25737 |
amit.gupta |
74 |
var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
|
| 24440 |
amit.gupta |
75 |
if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
|
|
|
76 |
price = paeseFloat(sellingPrice);
|
|
|
77 |
} else {
|
|
|
78 |
price = mop;
|
|
|
79 |
}
|
|
|
80 |
that = this;
|
| 25737 |
amit.gupta |
81 |
doGetAjaxRequestHandler(context+"/checkplans?price=" + price + "&itemId=" + itemId, function(response){
|
| 24440 |
amit.gupta |
82 |
var obj = JSON.parse(response);
|
|
|
83 |
getInsurancePlansModal(obj);
|
|
|
84 |
planCheckedOn = that;
|
|
|
85 |
return;
|
|
|
86 |
});
|
|
|
87 |
});
|
| 23343 |
ashik.ali |
88 |
|
| 22245 |
ashik.ali |
89 |
});
|
| 23343 |
ashik.ali |
90 |
|
|
|
91 |
|
| 24440 |
amit.gupta |
92 |
function getInsurancePlansModal(insurancePlans) {
|
|
|
93 |
var htmlArr = [];
|
|
|
94 |
for(var key in insurancePlans) {
|
|
|
95 |
templateArr = [];
|
|
|
96 |
var plansList = insurancePlans[key];
|
|
|
97 |
for(var index in plansList) {
|
|
|
98 |
var plan = plansList[index];
|
|
|
99 |
console.log(plan);
|
|
|
100 |
var template =
|
|
|
101 |
`<div class="col-lg-3">
|
|
|
102 |
<div class="thumbnail">
|
| 25737 |
amit.gupta |
103 |
<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
|
| 24440 |
amit.gupta |
104 |
<div class="caption" style="padding:9px 0 0">
|
| 25737 |
amit.gupta |
105 |
<div style="margin:0 0 -2px -2px">
|
| 25813 |
amit.gupta |
106 |
<button class="btn btn-lg btn-default mk_plan_select" style="width:100%"
|
| 25737 |
amit.gupta |
107 |
data-key="${plan.productId}"
|
| 25809 |
amit.gupta |
108 |
data-amount="${plan.premium}"
|
|
|
109 |
>${plan.duration} Rs.<span class="currency">@${plan.premium}</span>
|
| 25737 |
amit.gupta |
110 |
</button>
|
|
|
111 |
</div>
|
| 24440 |
amit.gupta |
112 |
</div>
|
|
|
113 |
</div>
|
|
|
114 |
</div>`;
|
|
|
115 |
templateArr.push(template);
|
|
|
116 |
if(index%4==3 || +index+1==plansList.length) {
|
| 25813 |
amit.gupta |
117 |
templateArr = [`<div class="row col-lg-12">${templateArr.join('')}</div>`];
|
| 24440 |
amit.gupta |
118 |
}
|
|
|
119 |
}
|
|
|
120 |
htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
|
|
|
121 |
}
|
| 25778 |
amit.gupta |
122 |
$('#mobilePlansModal').find('.insurancedetails').html(htmlArr.join(''));
|
| 24440 |
amit.gupta |
123 |
$('#mobilePlansModal').modal({show: true});
|
|
|
124 |
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
|
| 23343 |
ashik.ali |
128 |
function calculateTotalAmount() {
|
|
|
129 |
var netPayableAmount = 0;
|
| 24440 |
amit.gupta |
130 |
var totaInsuranceAmount = 0;
|
| 23343 |
ashik.ali |
131 |
$("#cd").find('tr:gt(0)').each(function(index, el){
|
|
|
132 |
var rowTotal = 0;
|
|
|
133 |
$tr = $(el);
|
| 24440 |
amit.gupta |
134 |
var insuranceAmount = $tr.find('input.insuranceamount').val();
|
|
|
135 |
if (isNaN(insuranceAmount)){
|
| 23343 |
ashik.ali |
136 |
insuranceAmount = 0;
|
|
|
137 |
}else{
|
|
|
138 |
insuranceAmount = parseFloat(insuranceAmount);
|
|
|
139 |
}
|
|
|
140 |
|
| 23434 |
ashik.ali |
141 |
var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
|
|
|
142 |
if(isNaN(quantity)){
|
|
|
143 |
quantity = 0;
|
|
|
144 |
}
|
|
|
145 |
console.log("quantity : "+quantity);
|
|
|
146 |
|
| 23343 |
ashik.ali |
147 |
var unitPrice = parseFloat($(el).find('.unitPrice').val());
|
| 23434 |
ashik.ali |
148 |
if(isNaN(unitPrice)){
|
|
|
149 |
unitPrice = 0;
|
|
|
150 |
}
|
|
|
151 |
console.log("unitPrice : "+unitPrice);
|
| 23343 |
ashik.ali |
152 |
|
| 24440 |
amit.gupta |
153 |
rowTotal = unitPrice * quantity + insuranceAmount;
|
| 23343 |
ashik.ali |
154 |
$tr.find('.totalPrice').val(rowTotal);
|
|
|
155 |
netPayableAmount += rowTotal;
|
| 24440 |
amit.gupta |
156 |
totaInsuranceAmount += insuranceAmount;
|
| 23343 |
ashik.ali |
157 |
});
|
| 24440 |
amit.gupta |
158 |
if(totaInsuranceAmount > 0) {
|
|
|
159 |
$(".mk_insurance_row").show();
|
|
|
160 |
} else {
|
|
|
161 |
$(".mk_insurance_row").hide();
|
|
|
162 |
}
|
| 23343 |
ashik.ali |
163 |
$('#cd').find('input.netPayableAmount').val(netPayableAmount);
|
|
|
164 |
}
|