Subversion Repositories SmartDukaan

Rev

Rev 25737 | Rev 25780 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23347 ashik.ali 1
$(function(){
24440 amit.gupta 2
	$(document).on('click', 'button.mk_plan_select', function(){
25778 amit.gupta 3
		$itemDetails = $('div.itemdetails');
4
		if($itemDetails.find('.ram').val()==='') {
5
			bootbox.alert('Mobile RAM is required');
6
			return;
7
		}
8
		if($itemDetails.find('.memory').val()==='') {
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());
21
		$orderItemRow.find('.mfgdate').val(startDate);
24440 amit.gupta 22
		$('#mobilePlansModal').modal('hide');
23343 ashik.ali 23
		calculateTotalAmount();
24
	});
24440 amit.gupta 25
 
26
	$(".mk_restore").live('click', function() {
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
			$("form#cd input[name=gender").val(customerObj['gender']);
45
			$("form#cd input[name=dateOfBirth").val(customerObj['dateOfBirth']);
46
		}
47
	});
48
 
49
	$("form#cd input.unitPrice").live('change', function() {
23343 ashik.ali 50
 
51
		var unitPrice = parseFloat($(this).val());
52
		if (isNaN(unitPrice)){
53
			unitPrice = 0;
54
		}
55
		if(unitPrice < 0){
56
			alert("Invalid unit price");
57
			$(this).val(0);
58
		}
59
 
60
		calculateTotalAmount();
61
	});
62
 
63
 
24440 amit.gupta 64
	$("form#cd input.insuranceamount").live('change', function() {
23343 ashik.ali 65
		calculateTotalAmount();
66
	});
67
 
23347 ashik.ali 68
	$(".create-order").live('click', function() {
69
		checkout("main-content");
70
	});
24440 amit.gupta 71
 
72
	$(".mk_check_plans").live('click', function(){
25778 amit.gupta 73
		$('div.itemdetails').find('input').val('');
24440 amit.gupta 74
		var mop = parseFloat($(this).data("mop"));
75
		var sellingPrice = $(this).val();
25737 amit.gupta 76
		var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
24440 amit.gupta 77
		if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
78
			price = paeseFloat(sellingPrice);
79
		} else {
80
			price = mop;
81
		}
82
		that = this;
25737 amit.gupta 83
		doGetAjaxRequestHandler(context+"/checkplans?price=" + price + "&itemId=" + itemId, function(response){
24440 amit.gupta 84
			var obj = JSON.parse(response);
85
			getInsurancePlansModal(obj);
86
			planCheckedOn = that;
87
			return;
88
		});
89
	});
23343 ashik.ali 90
 
22245 ashik.ali 91
});
23343 ashik.ali 92
 
93
 
24440 amit.gupta 94
function getInsurancePlansModal(insurancePlans) {
95
	var htmlArr = [];
96
	for(var key in insurancePlans) {
97
		templateArr = [];
98
		var plansList = insurancePlans[key];
99
		for(var index in plansList) {
100
			var plan = plansList[index];
101
			console.log(plan);
102
			var template = 
103
				`<div class="col-lg-3">
104
					<div class="thumbnail">
25737 amit.gupta 105
						<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
24440 amit.gupta 106
			      		<div class="caption" style="padding:9px 0 0">
25737 amit.gupta 107
						    <div style="margin:0 0 -2px -2px">
108
						    	<button class="btn btn-sm btn-default mk_plan_select" style="width:100%" 
109
						    		data-key="${plan.productId}"
110
						    		data-amount="${plan.premium}">${plan.premium}
111
						    	</button>
112
						    </div>
24440 amit.gupta 113
						</div>
114
					</div>
115
				</div>`;
116
			templateArr.push(template);
117
			if(index%4==3 || +index+1==plansList.length) {
118
				templateArr = [`<div class="row col-lg-6">${templateArr.join('')}</div>`];
119
			}
120
		}
121
		htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
122
	}
25778 amit.gupta 123
	$('#mobilePlansModal').find('.insurancedetails').html(htmlArr.join(''));
24440 amit.gupta 124
	$('#mobilePlansModal').modal({show: true});
125
 
126
}
127
 
128
 
23343 ashik.ali 129
function calculateTotalAmount() {
130
	var netPayableAmount = 0;
24440 amit.gupta 131
	var totaInsuranceAmount = 0;
23343 ashik.ali 132
	$("#cd").find('tr:gt(0)').each(function(index, el){
133
		var rowTotal = 0;
134
		$tr = $(el);
24440 amit.gupta 135
		var insuranceAmount = $tr.find('input.insuranceamount').val();
136
		if (isNaN(insuranceAmount)){
23343 ashik.ali 137
			insuranceAmount = 0;
138
		}else{
139
			insuranceAmount = parseFloat(insuranceAmount);
140
		}
141
 
23434 ashik.ali 142
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
143
		if(isNaN(quantity)){
144
			quantity = 0;
145
		}
146
		console.log("quantity : "+quantity);
147
 
23343 ashik.ali 148
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
23434 ashik.ali 149
		if(isNaN(unitPrice)){
150
			unitPrice = 0;
151
		}
152
		console.log("unitPrice : "+unitPrice);
23343 ashik.ali 153
 
24440 amit.gupta 154
		rowTotal = unitPrice * quantity + insuranceAmount; 
23343 ashik.ali 155
		$tr.find('.totalPrice').val(rowTotal);
156
		netPayableAmount += rowTotal;
24440 amit.gupta 157
		totaInsuranceAmount += insuranceAmount;
23343 ashik.ali 158
	});
24440 amit.gupta 159
	if(totaInsuranceAmount > 0) {
160
		$(".mk_insurance_row").show();
161
	} else {
162
		$(".mk_insurance_row").hide();
163
	}
23343 ashik.ali 164
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
165
}