Subversion Repositories SmartDukaan

Rev

Rev 26817 | Rev 28395 | 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');
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
 
27754 amit.gupta 26
	$(document).on('change', "form#cd input.unitPrice", function() {
23343 ashik.ali 27
 
28
		var unitPrice = parseFloat($(this).val());
29
		if (isNaN(unitPrice)){
30
			unitPrice = 0;
31
		}
32
		if(unitPrice < 0){
33
			alert("Invalid unit price");
34
			$(this).val(0);
35
		}
36
 
37
		calculateTotalAmount();
38
	});
39
 
40
 
27754 amit.gupta 41
	$(document).on('change', "form#cd input.insuranceamount", function() {
23343 ashik.ali 42
		calculateTotalAmount();
43
	});
44
 
27754 amit.gupta 45
	$(document).on('click', ".create-order", function() {
23347 ashik.ali 46
		checkout("main-content");
47
	});
24440 amit.gupta 48
 
27754 amit.gupta 49
	$(document).on('click', ".mk_check_plans", function(){
25778 amit.gupta 50
		$('div.itemdetails').find('input').val('');
24440 amit.gupta 51
		var mop = parseFloat($(this).data("mop"));
52
		var sellingPrice = $(this).val();
25737 amit.gupta 53
		var itemId = $(this).closest(".input-group").find("input.insuranceamount").attr("itemid");
24440 amit.gupta 54
		if(!isNaN(sellingPrice) && parseFloat(sellingPrice) >= mop){
55
			price = paeseFloat(sellingPrice);
56
		} else {
57
			price = mop;
58
		}
59
		that = this;
25737 amit.gupta 60
		doGetAjaxRequestHandler(context+"/checkplans?price=" + price + "&itemId=" + itemId, function(response){
24440 amit.gupta 61
			var obj = JSON.parse(response);
62
			getInsurancePlansModal(obj);
63
			planCheckedOn = that;
64
			return;
65
		});
66
	});
23343 ashik.ali 67
 
22245 ashik.ali 68
});
23343 ashik.ali 69
 
70
 
24440 amit.gupta 71
function getInsurancePlansModal(insurancePlans) {
72
	var htmlArr = [];
73
	for(var key in insurancePlans) {
74
		templateArr = [];
75
		var plansList = insurancePlans[key];
76
		for(var index in plansList) {
77
			var plan = plansList[index];
78
			console.log(plan);
79
			var template = 
80
				`<div class="col-lg-3">
81
					<div class="thumbnail">
25737 amit.gupta 82
						<img class="card-img-top" src="${logosmapping.mobile_insurance_providers[plan.providerId]}" alt="${plan.providerName}">
24440 amit.gupta 83
			      		<div class="caption" style="padding:9px 0 0">
25737 amit.gupta 84
						    <div style="margin:0 0 -2px -2px">
25813 amit.gupta 85
						    	<button class="btn btn-lg btn-default mk_plan_select" style="width:100%" 
25737 amit.gupta 86
						    		data-key="${plan.productId}"
25809 amit.gupta 87
						    		data-amount="${plan.premium}"
88
						    	>${plan.duration} Rs.<span class="currency">@${plan.premium}</span>
25737 amit.gupta 89
						    	</button>
90
						    </div>
24440 amit.gupta 91
						</div>
92
					</div>
93
				</div>`;
94
			templateArr.push(template);
95
			if(index%4==3 || +index+1==plansList.length) {
25813 amit.gupta 96
				templateArr = [`<div class="row col-lg-12">${templateArr.join('')}</div>`];
24440 amit.gupta 97
			}
98
		}
99
		htmlArr.push(`<div class="row"><h4>${key}</h4>${templateArr.join('')}</div>`);
100
	}
25778 amit.gupta 101
	$('#mobilePlansModal').find('.insurancedetails').html(htmlArr.join(''));
24440 amit.gupta 102
	$('#mobilePlansModal').modal({show: true});
103
 
104
}
105
 
106
 
23343 ashik.ali 107
function calculateTotalAmount() {
108
	var netPayableAmount = 0;
24440 amit.gupta 109
	var totaInsuranceAmount = 0;
23343 ashik.ali 110
	$("#cd").find('tr:gt(0)').each(function(index, el){
111
		var rowTotal = 0;
112
		$tr = $(el);
24440 amit.gupta 113
		var insuranceAmount = $tr.find('input.insuranceamount').val();
114
		if (isNaN(insuranceAmount)){
23343 ashik.ali 115
			insuranceAmount = 0;
116
		}else{
117
			insuranceAmount = parseFloat(insuranceAmount);
118
		}
119
 
23434 ashik.ali 120
		var quantity = parseFloat($(el).find('.unitPrice').attr('quantity'));
121
		if(isNaN(quantity)){
122
			quantity = 0;
123
		}
124
		console.log("quantity : "+quantity);
125
 
23343 ashik.ali 126
		var unitPrice = parseFloat($(el).find('.unitPrice').val());
23434 ashik.ali 127
		if(isNaN(unitPrice)){
128
			unitPrice = 0;
129
		}
130
		console.log("unitPrice : "+unitPrice);
23343 ashik.ali 131
 
24440 amit.gupta 132
		rowTotal = unitPrice * quantity + insuranceAmount; 
23343 ashik.ali 133
		$tr.find('.totalPrice').val(rowTotal);
134
		netPayableAmount += rowTotal;
24440 amit.gupta 135
		totaInsuranceAmount += insuranceAmount;
23343 ashik.ali 136
	});
24440 amit.gupta 137
	if(totaInsuranceAmount > 0) {
138
		$(".mk_insurance_row").show();
139
	} else {
140
		$(".mk_insurance_row").hide();
141
	}
23343 ashik.ali 142
	$('#cd').find('input.netPayableAmount').val(netPayableAmount);
143
}