Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7068 anupam.sin 1
$(function() {
7125 amit.gupta 2
	oldValue = "";
3
	$('.rechargetype').click(function (){
4
		$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
5
		$('#discountText').remove();
7068 anupam.sin 6
		var rechargeType = $('input.rechargetype:checked').val();
7
		//1 is for Normal
8
		//2 for New Connection(FRC)
9
		if(rechargeType == 1) {
10
			$('#frc-div').slideUp(100);
11
		}
12
		if(rechargeType == 2) {
7096 anupam.sin 13
			if($('input.devicetype:checked').val() == 2) {
14
				$('input.rechargetype:unchecked').attr('checked', 'checked');
15
				alert('New DTH Connections are not supported');
16
				return false;
17
			} else {
18
				$('#frc-div').slideDown(100);
19
			}
7068 anupam.sin 20
		}
21
	});
22
 
23
	$('.devicetype').change(function (){
24
		var devicetype = $('input.devicetype:checked').val();
25
		//1 is for Mobile
26
		//2 for DTH
27
		if(devicetype == 1) {
28
			var deviceNumberInput = $('.inputbox[name=number]')
29
			deviceNumberInput.removeClass('padding15');
30
			deviceNumberInput.addClass('num-prefix padding48');
7073 anupam.sin 31
			$('#dthSelector').hide();
32
			$('#mobileSelector').show();
7068 anupam.sin 33
		}
34
		if(devicetype == 2) {
7096 anupam.sin 35
			if($('input.rechargetype:checked').val() == 2) {
36
				$('input.devicetype:unchecked').attr('checked', 'checked');
37
				alert('New DTH Connections are not supported');
38
				return false;
39
			}
7068 anupam.sin 40
			var deviceNumberInput = $('.inputbox[name=number]')
41
			deviceNumberInput.removeClass('num-prefix padding48');
42
			deviceNumberInput.addClass('padding15');
7073 anupam.sin 43
			$('#mobileSelector').hide();
44
			$('#dthSelector').show();
7068 anupam.sin 45
		}
46
	});
7073 anupam.sin 47
 
7080 anupam.sin 48
	$('#recharge-button').click(function() {
7096 anupam.sin 49
		$('#confirmForm').attr('action', '/rch/confirm!createRecharge');
7080 anupam.sin 50
		$('#confirmForm').submit();
51
	});
52
 
7151 amit.gupta 53
	/*$('#edit-button').click(function() {
7096 anupam.sin 54
		$('#confirmForm').attr('action', '/rch/home!editRecharge');
7080 anupam.sin 55
		$('#confirmForm').submit();
7151 amit.gupta 56
	});*/
7080 anupam.sin 57
 
7073 anupam.sin 58
	$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur').bind('keyup blur', function(){
59
		var numvalue = $(this).val().substring(0,4);
60
		var count = $(this).val().length;
61
		if(count==10 && oldValue != numvalue){
62
			getRechargeProvider(numvalue, 1);
63
			//$(this).unbind('keyup');
64
		}
65
	});
7125 amit.gupta 66
	$('#mobileSelector').change(function(){
67
		var selectedOperator = $('#mobileSelector').val();
68
		if($('input.rechargetype:checked').val() == "2") {
69
			if(selectedOperator != 0) {
70
				return $.ajax({
71
					type: "POST",
72
					dataType:"json",
73
					url: "/rch/home!getFRC?operatorId=" + selectedOperator,
74
					success:function(msg) {
75
						if(msg.length != 0) {
7140 amit.gupta 76
							$('div.mk_amount_row .input-div').html('<select id="newConDis" style="height:30px;font-size:18px;"><option>Custom</option></select>' +
7125 amit.gupta 77
				    				'<input type="text" name="amount" class="inputbox rupee padding48" style="width:120px">');
78
							$.each(msg,function(index,obj){
79
								$("#newConDis").append('<option disc="' + obj.maxDiscount + '" >' + obj.denomination +'</option>');
80
							});
7176 anupam.sin 81
							$('div.mk_discount_row').append('<div id="discountText" style="text-align: left;font-size: 15px;width: 340px;color: blue;" class="text"></div>');
82
							$("#newConDis").change(function(){
83
								if(this.selectedIndex == 0){
84
									$('div.mk_discount_row :last').html('');
85
									$('#rechargeDetailsForm [name="amount"]').show().val('');	
86
								}else {
87
									var discount = $(this).find(":selected").attr("disc");
88
									$('#rechargeDetailsForm [name="amount"]').val($(this).val()).hide();	
89
									$('div.mk_discount_row :last').html('Discount more than rupees ' + discount + ' is not allowed');
90
								}
91
							});
7125 amit.gupta 92
						} else {
93
							$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
94
							$('#discountText').remove();
95
						}
96
					}
97
				});
98
			}
99
		}
100
	});
7073 anupam.sin 101
 
7151 amit.gupta 102
 
7176 anupam.sin 103
 
7151 amit.gupta 104
	$("#dateselector").change(function() {
105
		if($(this).val()=="3"){
106
			$("#daterange").show();
107
		}else {
108
			$("#daterange").hide();
109
		}
110
	});
111
 
7073 anupam.sin 112
	function getRechargeProvider(deviceNumber, deviceType){
113
		return $.ajax({
114
			type: "POST",
7096 anupam.sin 115
			url: "/rch/home!getServiceProvider?deviceNumber=" + deviceNumber + "&deviceType=" + deviceType,
7073 anupam.sin 116
			success:function(msg){
117
				if(msg != ""){
118
					var deviceNumberInfo = msg.split(":");
7125 amit.gupta 119
					if($.trim(deviceNumberInfo[0]) == -1) {
120
						alert ("Service not reachable or invalid number");
121
					}
122
					if($('input.rechargetype:checked').val() == "2"){
123
						if(storeCircleCode != $.trim(deviceNumberInfo[1])){
124
							$('input[name="number"]').val("");
125
							alert('This number does not belong to your circle');
126
							return false;
127
						}
128
					}
7073 anupam.sin 129
					$('#rechargeDetailsForm select[name="mobileOperator"]').val($.trim(deviceNumberInfo[0]));
7096 anupam.sin 130
					$('#circlecode').val($.trim(deviceNumberInfo[1]));
7073 anupam.sin 131
					$('#mobileSelector').trigger('change');
7125 amit.gupta 132
					oldValue = deviceNumber;
7073 anupam.sin 133
				}
7125 amit.gupta 134
			},
135
			complete : function(){
136
				$('#rechargeDetailsForm input[name="number"]').bind('keyup blur', function(){
137
					var numvalue = $(this).val().substring(0,4);
138
					var count = $(this).val().length;
139
					if(count==10 && oldValue != numvalue){
140
						getRechargeProvider(numvalue, 1);
141
					}
142
				});
143
			},
144
			beforeSend : function(){
145
				$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur');
7073 anupam.sin 146
			}
147
		});
148
	}
7176 anupam.sin 149
 
150
	$(document).ready(function(){
151
		var rechargeType = $('input.rechargetype:checked').val();
152
		if(rechargeType == 2) {
153
			$('#frc-div').show();
154
			$('#mobileSelector').trigger('change');
155
			//$('#rechargeDetailsForm input[name="number"]').keyup();
156
		}
157
	});
158
 
7096 anupam.sin 159
});
160
 
161
function validateAllFields() {
162
	var rechargeType = $('input.rechargetype:checked').val();
163
	//1 is for Normal
164
	//2 for New Connection(FRC)
165
	var devicetype = $('input.devicetype:checked').val();
166
	//1 is for Mobile
167
	//2 for DTH
168
	if($('input[name=number]').val() === ""){
169
		alert('Please enter device number');
170
		return false;
171
	}
172
	if($('input[name=name]').val() === ""){
173
		alert('Please enter customer name');
174
		return false;
175
	}
7151 amit.gupta 176
	if($('input[name=number]').val() != $('input[name=repeat]').val()){
177
		alert('Please confirm the device number.');
178
		return false;
179
	}
7096 anupam.sin 180
	if($('input[name=amount]').val() === ""){
181
		alert('Please enter amount');
182
		return false;
183
	}
7073 anupam.sin 184
 
7096 anupam.sin 185
	if(deviceType == 1 && $('#mobileSelector').val() === 0) {
186
		alert('Please select operator');
187
		return false;
188
	}
189
 
190
	if(deviceType == 2 && $('#dthSelector').val() === 0) {
191
		alert('Please select operator');
192
		return false;
193
	}
194
 
195
	if(rechargeType == 2) {
196
		if($('input[name=sim]').val() === ""){
197
			alert('Please enter SIM number');
7073 anupam.sin 198
			return false;
199
		}
7096 anupam.sin 200
		if($('input[name=caf]').val() === ""){
201
			alert('Please enter CAF number');
7073 anupam.sin 202
			return false;
203
		}
7096 anupam.sin 204
		if($('input[name=alternate]').val() === ""){
205
			alert('Please enter alternate number');
7073 anupam.sin 206
			return false;
207
		}
208
	}
7096 anupam.sin 209
}