Subversion Repositories SmartDukaan

Rev

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

Rev 30708 Rev 30725
Line 1... Line 1...
1
$(function(){
1
$(function () {
2
	$(document).on('click', 'button.mk_plan_select', function(){
2
	$(document).on('click', 'button.mk_plan_select', function () {
3
		$itemDetails = $('div.itemdetails');
3
		$itemDetails = $('div.itemdetails');
4
		if($itemDetails.find('.dgram').val()==='') {
4
		if ($itemDetails.find('.dgram').val() === '') {
5
			bootbox.alert('Mobile RAM is required');
5
			bootbox.alert('Mobile RAM is required');
6
			return;
6
			return;
7
		}
7
		}
8
		if($itemDetails.find('.dgmemory').val()==='') {
8
		if ($itemDetails.find('.dgmemory').val() === '') {
9
			bootbox.alert('Mobile Memory is required');
9
			bootbox.alert('Mobile Memory is required');
10
			return;
10
			return;
11
		}
11
		}
12
		if($itemDetails.find('#dgmfgdate').val()==='') {
12
		if ($itemDetails.find('#dgmfgdate').val() === '') {
13
			bootbox.alert('Mobile Mfg Date is required');
13
			bootbox.alert('Mobile Mfg Date is required');
14
			return;
14
			return;
15
		}
15
		}
16
		$orderItemRow = $(planCheckedOn).closest('td');
16
		$orderItemRow = $(planCheckedOn).closest('td');
17
		$orderItemRow.find('.insuranceid').val($(this).data('key'));
17
		$orderItemRow.find('.insuranceid').val($(this).data('key'));
Line 22... Line 22...
22
		$('#mobilePlansModal').modal('hide');
22
		$('#mobilePlansModal').modal('hide');
23
		calculateTotalAmount();
23
		calculateTotalAmount();
24
	});
24
	});
25
 
25
 
26
	//Price change handler
26
	//Price change handler
27
	$(document).on('change', "form#cd input.unitPrice,form#cd input.discount", function() {
27
	$(document).on('change', "form#cd input.unitPrice,form#cd input.discount", function () {
28
		
28
 
29
		var unitPrice = parseFloat($('form#cd input.unitPrice').val());
29
		var unitPrice = parseFloat($('form#cd input.unitPrice').val());
30
		if (isNaN(unitPrice)){
30
		if (isNaN(unitPrice)) {
31
			unitPrice = 0;
31
			unitPrice = 0;
32
		}
32
		}
33
		var discount = parseFloat($('form#cd input.discount').val());
33
		var discount = parseFloat($('form#cd input.discount').val());
34
		var maxDiscount = parseFloat($('form#cd input.discount').data('maxdiscount'));
34
		var maxDiscount = parseFloat($('form#cd input.discount').data('maxdiscount'));
35
		if (isNaN(discount)){
35
		if (isNaN(discount)) {
36
			discount = 0;
36
			discount = 0;
37
		}
37
		}
38
		if(isNaN(maxDiscount)) { 
38
		if (isNaN(maxDiscount)) {
39
			maxDiscount = 0;
39
			maxDiscount = 0;
40
		}
40
		}
41
		if(discount > maxDiscount) {
41
		if (discount > maxDiscount) {
42
			alert("Discount cant be greater than max Discount");
42
			alert("Discount cant be greater than max Discount");
43
			$('form#cd input.discount').val(maxDiscount);
43
			$('form#cd input.discount').val(maxDiscount);
44
			$(this).focus();
44
			$(this).focus();
45
			return;
45
			return;
46
		}
46
		}
47
		if(unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)){
47
		if (unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)) {
48
			alert("Invalid unit/discount price");
48
			alert("Invalid unit/discount price");
49
			$(this).focus();
49
			$(this).focus();
50
			return;
50
			return;
51
		}
51
		}
52
		
52
 
53
		calculateTotalAmount();
53
		calculateTotalAmount();
54
		//$('.mk_check_plans').click();
54
		//$('.mk_check_plans').click();
55
	});
55
	});
56
	
56
 
57
	
57
 
58
	$(document).on('change', "form#cd input.insuranceamount", function() {
58
	$(document).on('change', "form#cd input.insuranceamount", function () {
59
		calculateTotalAmount();
59
		calculateTotalAmount();
60
	});
60
	});
61
	
61
 
62
	$(document).on('click', ".create-order", function() {
62
	$(document).on('click', ".create-order", function () {
63
		checkout("main-content");
63
		checkout("main-content");
64
	});
64
	});
65
	
65
 
66
	$(document).on('click', ".mk_check_plans", function(){
66
	$(document).on('click', ".mk_check_plans", function () {
67
		$('div.itemdetails').find('input').val('');
67
		$('div.itemdetails').find('input').val('');
68
		var mop = parseFloat($(this).data("mop"));
68
		var mop = parseFloat($(this).data("mop"));
69
		var sellingPrice = $(this).val();
69
		var sellingPrice = $(this).val();
70
		var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
70
		var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
71
		if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
71
		if (!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop) {
72
			price = parseFloat(sellingPrice);
72
			price = parseFloat(sellingPrice);
73
		} else {
73
		} else {
74
			price = mop;
74
			price = mop;
75
		}
75
		}
76
		var discount = parseFloat($(this).closest("tr").find("input.discount").val());
76
		var discount = parseFloat($(this).closest("tr").find("input.discount").val());
77
		if(!isNaN(discount)) {
77
		if (!isNaN(discount)) {
78
			price = price - discount;
78
			price = price - discount;
79
		}
79
		}
80
		that = this;
80
		that = this;
81
		doGetAjaxRequestHandler(context+"/checkplans?price=" + price + "&itemId=" + itemId, function(response){
81
		doGetAjaxRequestHandler(context + "/checkplans?price=" + price + "&itemId=" + itemId, function (response) {
82
			var obj = JSON.parse(response);
82
			var obj = JSON.parse(response);
-
 
83
			if (obj != null) {
83
			getInsurancePlansModal(obj);
84
				getInsurancePlansModal(obj);
84
			planCheckedOn = that;
85
				planCheckedOn = that;
85
			return;
86
				return;
-
 
87
			}
86
		});
88
		});
87
	});
89
	});
88
 
90
 
89
});
91
});
90
 
92
 
91
 
93
 
92
function getInsurancePlansModal(insurancePlans) {
94
function getInsurancePlansModal(insurancePlans) {
93
	var htmlArr = [];
95
	var htmlArr = [];
94
	for(var key in insurancePlans) {
96
	for (var key in insurancePlans) {
95
		templateArr = [];
97
		templateArr = [];
96
		var plansList = insurancePlans[key];
98
		var plansList = insurancePlans[key];
97
		for(var index in plansList) {
99
		for (var index in plansList) {
98
			var plan = plansList[index];
100
			var plan = plansList[index];
99
			console.log(plan);
101
			console.log(plan);
100
			var template = 
102
			var template =
101
				`<div class="col-lg-3">
103
				`<div class="col-lg-3">
102
					<div class="thumbnail">
104
					<div class="thumbnail">
103
						<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
105
						<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
104
			      		<div class="caption" style="padding:9px 0 0">
106
			      		<div class="caption" style="padding:9px 0 0">
105
						    <div style="margin:0 0 -2px -2px">
107
						    <div style="margin:0 0 -2px -2px">
Line 114... Line 116...
114
							Your Landing(DP) - ${plan.dp}
116
							Your Landing(DP) - ${plan.dp}
115
						</div>
117
						</div>
116
					</div>
118
					</div>
117
				</div>`;
119
				</div>`;
118
			templateArr.push(template);
120
			templateArr.push(template);
119
			if(index%4==3 || +index+1==plansList.length) {
121
			if (index % 4 == 3 || +index + 1 == plansList.length) {
120
				templateArr = [`<div class="row col-lg-12">${templateArr.join('')}</div>`];
122
				templateArr = [`<div class="row col-lg-12">${templateArr.join('')}</div>`];
121
			}
123
			}
122
		}
124
		}
123
		htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
125
		htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
124
	}
126
	}
Line 129... Line 131...
129
 
131
 
130
 
132
 
131
function calculateTotalAmount() {
133
function calculateTotalAmount() {
132
	var netPayableAmount = 0;
134
	var netPayableAmount = 0;
133
	var totaInsuranceAmount = 0;
135
	var totaInsuranceAmount = 0;
134
	$("#cd").find('tr:gt(0)').each(function(index, el){
136
	$("#cd").find('tr:gt(0)').each(function (index, el) {
135
		var rowTotal = 0;
137
		var rowTotal = 0;
136
		$tr = $(el);
138
		$tr = $(el);
137
		var insuranceAmount = $tr.find('input.insuranceamount').val();
139
		var insuranceAmount = $tr.find('input.insuranceamount').val();
138
		if (isNaN(insuranceAmount)){
140
		if (isNaN(insuranceAmount)) {
139
			insuranceAmount = 0;
141
			insuranceAmount = 0;
140
		}else{
142
		} else {
141
			insuranceAmount = parseFloat(insuranceAmount);
143
			insuranceAmount = parseFloat(insuranceAmount);
142
		}
144
		}
143
		
145
 
144
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
146
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
145
		
147
 
146
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
148
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
147
		if(isNaN(unitPrice)){
149
		if (isNaN(unitPrice)) {
148
			unitPrice = 0;
150
			unitPrice = 0;
149
		}
151
		}
150
		
152
 
151
		var discount = $(el).find('.discount').val();
153
		var discount = $(el).find('.discount').val();
152
		if(isNaN(discount)){
154
		if (isNaN(discount)) {
153
			discount = 0;
155
			discount = 0;
154
		}
156
		}
155
 
157
 
156
		rowTotal = unitPrice - discount + insuranceAmount; 
158
		rowTotal = unitPrice - discount + insuranceAmount;
157
		$tr.find('.totalPrice').val(rowTotal);
159
		$tr.find('.totalPrice').val(rowTotal);
158
		netPayableAmount += rowTotal;
160
		netPayableAmount += rowTotal;
159
		totaInsuranceAmount += insuranceAmount;
161
		totaInsuranceAmount += insuranceAmount;
160
	});
162
	});
161
	if(totaInsuranceAmount > 0) {
163
	if (totaInsuranceAmount > 0) {
162
		$(".mk_insurance_row").show();
164
		$(".mk_insurance_row").show();
163
	} else {
165
	} else {
164
		$(".mk_insurance_row").hide();
166
		$(".mk_insurance_row").hide();
165
	}
167
	}
166
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
168
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);