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
								alert('Entered');
84
								if(this.selectedIndex == 0){
85
									alert('Textbox now show');
86
									$('div.mk_discount_row :last').html('');
87
									$('#rechargeDetailsForm [name="amount"]').show().val('');	
88
								}else {
89
									alert('In else ; testbox hide');
90
									var discount = $(this).find(":selected").attr("disc");
91
									$('#rechargeDetailsForm [name="amount"]').val($(this).val()).hide();	
92
									$('div.mk_discount_row :last').html('Discount more than rupees ' + discount + ' is not allowed');
93
								}
94
							});
7125 amit.gupta 95
						} else {
96
							$('div.mk_amount_row .input-div').html('<input type="text" name="amount" class="inputbox rupee padding48">');
97
							$('#discountText').remove();
98
						}
99
					}
100
				});
101
			}
102
		}
103
	});
7073 anupam.sin 104
 
7151 amit.gupta 105
 
7176 anupam.sin 106
 
7151 amit.gupta 107
	$("#dateselector").change(function() {
108
		if($(this).val()=="3"){
109
			$("#daterange").show();
110
		}else {
111
			$("#daterange").hide();
112
		}
113
	});
114
 
7073 anupam.sin 115
	function getRechargeProvider(deviceNumber, deviceType){
116
		return $.ajax({
117
			type: "POST",
7096 anupam.sin 118
			url: "/rch/home!getServiceProvider?deviceNumber=" + deviceNumber + "&deviceType=" + deviceType,
7073 anupam.sin 119
			success:function(msg){
120
				if(msg != ""){
121
					var deviceNumberInfo = msg.split(":");
7125 amit.gupta 122
					if($.trim(deviceNumberInfo[0]) == -1) {
123
						alert ("Service not reachable or invalid number");
124
					}
125
					if($('input.rechargetype:checked').val() == "2"){
126
						if(storeCircleCode != $.trim(deviceNumberInfo[1])){
127
							$('input[name="number"]').val("");
128
							alert('This number does not belong to your circle');
129
							return false;
130
						}
131
					}
7073 anupam.sin 132
					$('#rechargeDetailsForm select[name="mobileOperator"]').val($.trim(deviceNumberInfo[0]));
7096 anupam.sin 133
					$('#circlecode').val($.trim(deviceNumberInfo[1]));
7073 anupam.sin 134
					$('#mobileSelector').trigger('change');
7125 amit.gupta 135
					oldValue = deviceNumber;
7073 anupam.sin 136
				}
7125 amit.gupta 137
			},
138
			complete : function(){
139
				$('#rechargeDetailsForm input[name="number"]').bind('keyup blur', function(){
140
					var numvalue = $(this).val().substring(0,4);
141
					var count = $(this).val().length;
142
					if(count==10 && oldValue != numvalue){
143
						getRechargeProvider(numvalue, 1);
144
					}
145
				});
146
			},
147
			beforeSend : function(){
148
				$('#rechargeDetailsForm input[name="number"]').unbind('keyup blur');
7073 anupam.sin 149
			}
150
		});
151
	}
7176 anupam.sin 152
 
153
	$(document).ready(function(){
154
		var rechargeType = $('input.rechargetype:checked').val();
155
		if(rechargeType == 2) {
156
			$('#frc-div').show();
157
			$('#mobileSelector').trigger('change');
158
			//$('#rechargeDetailsForm input[name="number"]').keyup();
159
		}
160
	});
161
 
7096 anupam.sin 162
});
163
 
164
function validateAllFields() {
165
	var rechargeType = $('input.rechargetype:checked').val();
166
	//1 is for Normal
167
	//2 for New Connection(FRC)
168
	var devicetype = $('input.devicetype:checked').val();
169
	//1 is for Mobile
170
	//2 for DTH
171
	if($('input[name=number]').val() === ""){
172
		alert('Please enter device number');
173
		return false;
174
	}
175
	if($('input[name=name]').val() === ""){
176
		alert('Please enter customer name');
177
		return false;
178
	}
7151 amit.gupta 179
	if($('input[name=number]').val() != $('input[name=repeat]').val()){
180
		alert('Please confirm the device number.');
181
		return false;
182
	}
7096 anupam.sin 183
	if($('input[name=amount]').val() === ""){
184
		alert('Please enter amount');
185
		return false;
186
	}
7073 anupam.sin 187
 
7096 anupam.sin 188
	if(deviceType == 1 && $('#mobileSelector').val() === 0) {
189
		alert('Please select operator');
190
		return false;
191
	}
192
 
193
	if(deviceType == 2 && $('#dthSelector').val() === 0) {
194
		alert('Please select operator');
195
		return false;
196
	}
197
 
198
	if(rechargeType == 2) {
199
		if($('input[name=sim]').val() === ""){
200
			alert('Please enter SIM number');
7073 anupam.sin 201
			return false;
202
		}
7096 anupam.sin 203
		if($('input[name=caf]').val() === ""){
204
			alert('Please enter CAF number');
7073 anupam.sin 205
			return false;
206
		}
7096 anupam.sin 207
		if($('input[name=alternate]').val() === ""){
208
			alert('Please enter alternate number');
7073 anupam.sin 209
			return false;
210
		}
211
	}
7096 anupam.sin 212
}