Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7226 anupam.sin 1
$(function() {
7255 amit.gupta 2
 
3
	$("#query").autocomplete({ autoFocus: true, minLength: 3,
7323 anupam.sin 4
		source: "/storewebsite/auto-suggest",
7255 amit.gupta 5
		select: function( event, ui ) {
6
		this.value = ui.item.value;
7
		$('#formSearch').submit();
8
		return false;
9
		}
10
	}); 
11
 
7323 anupam.sin 12
	$("#formSearch").submit(function() {
13
		if($("#query").val() == "" || $("#query").val() == "Search for more items...") {
14
			return false;
15
		}
16
	});
17
 
7226 anupam.sin 18
	$('#pincodeForm').submit(function() {
19
 
20
		if($('#pincodeSubmit:hidden').length == 1) {
21
			return false;
22
		}
23
 
24
		if ($('#pincodeText').val().length != 6) {
25
			alert('Please enter 6 digit pin code');
26
			return false;
27
		}
28
 
29
		var result = $('#pincodeText').val().match(/^\d*$/);
30
		if(result == null || result.length == 0) {
31
			alert('Please enter a valid pin code');
32
			return false;
33
		}
34
 
7293 anupam.sin 35
		$('#priceDiv').empty();
7226 anupam.sin 36
		showLoading();
37
		$.ajax({
38
			type: "POST",
7268 anupam.sin 39
			url: "/storewebsite/estimate",
7226 anupam.sin 40
			dataType:"json",
7268 anupam.sin 41
			data:$('#pincodeForm').serialize(),
42
//			timeout: 10000,
7226 anupam.sin 43
			success:function(msg) {
44
				hideLoading();
45
				if(msg.length != 0) {
7293 anupam.sin 46
					if(msg.selling_price == 0.0) {
47
						$('#loading').hide();
48
						$('#shippingAddress').hide();
49
						$('#priceDiv').html("<div class='error'>There was some error. Please try again.</div>");
50
						$('#pincodeSubmit').show();
51
					} else {
52
						$('#priceDiv').html(
53
						"<div class='date'><span class='infoText'>Get this product by </span><span class='infoValue'>" + msg.delivery_estimate + "</span></div>" + 
7323 anupam.sin 54
						"<div class='price'><span class='infoText'>Total Price</span><span class='infoValue'>&nbsp;Rs.&nbsp;" + $('#shippingAddress input[name=price]').val() + "</span></div>" +
55
						"<div class='advance'><span class='infoText'>Advance to be paid</span><span id='advPrice' class='infoValue'>&nbsp;Rs.&nbsp;" + msg.min_advance_amount + "</span></div>");
7427 anupam.sin 56
						if(msg.min_advance_amount > parseFloat($('#shippingAddress input[name=price]').val())) {
57
							$('#shippingAddress input[name=advanceAmount]').val($('#shippingAddress input[name=price]').val());
58
							$('#editPriceBox').val($('#shippingAddress input[name=price]').val());
59
						} else {
60
							$('#shippingAddress input[name=advanceAmount]').val(msg.min_advance_amount);
61
							$('#editPriceBox').val(msg.min_advance_amount);
62
						}
7293 anupam.sin 63
						$('#shippingAddress input[name=deliveryDate]').val(msg.delivery_estimate);
64
						$('#shippingAddress input[name=minPrice]').val(msg.min_selling_price);
65
						$('#shippingAddress input[name=maxPrice]').val(msg.max_selling_price);
7323 anupam.sin 66
						$('#shippingAddress input[name=bestDealText]').val(msg.best_deal_text);
67
						$('#bestDealText').text(msg.best_deal_text);
68
						$('#bestDealContainer').show();
7293 anupam.sin 69
						$('#pincodeInput').val($('#pincodeText').val());
70
						$('#editPriceButton').show();
7427 anupam.sin 71
 
7293 anupam.sin 72
					}
73
 
7226 anupam.sin 74
				} else {
75
					$('#priceDiv').html("<div class='error'>No info found for this pincode. Please try again.</div>");
76
				}
77
			},
78
			error : function(msg) {
79
				$('#loading').hide();
80
				$('#shippingAddress').hide();
81
				$('#priceDiv').html("<div class='error'>There was some error. Please try again.</div>");
82
				$('#pincodeSubmit').show();
83
	        },
84
	        complete : function() {
85
	        	$('#pinSpan').html($('#pincodeText').val());
86
 
87
	        }
88
		});
89
		return false;
90
	});
91
 
92
	function showLoading() {
93
		$('#pincodeSubmit').hide();
94
		$('#shippingAddress').hide();
95
		$('#loading').show();
96
	}
97
 
98
	function hideLoading() {
99
		$('#loading').hide();
100
		$('#shippingAddress').show();
101
	}
102
 
103
	$('#changePincode').click(function() {
7323 anupam.sin 104
		window.location.reload();
7226 anupam.sin 105
	});
7248 anupam.sin 106
 
7386 anupam.sin 107
	$('#reloadSuccessPage').click(function() {
108
		window.location.reload();
109
	});
110
 
7248 anupam.sin 111
	$('#pincodeEdit').click(function(event){
7449 anupam.sin 112
		window.location.href = '/storewebsite/order-details!create?product_id=' + $('#createOrderForm input[name=product_id]').val() + '&price=' + $('#createOrderForm input[name=price]').val();
7248 anupam.sin 113
	});
114
 
115
	$('#addressEdit').click(function() {
116
		$('#createOrder, #showPinDiv, #showAddDiv').hide();
117
		$('#editAddBlock').show();
118
	});
119
 
120
	$('#saveEditedAdd').click(function() {
121
		var editedFields = $('#editAddBlock input');
7449 anupam.sin 122
		var msg = "";
123
		var displayAlert = false;
7248 anupam.sin 124
		editedFields.each(function(i, inputField) {
125
			if($(inputField).val() == "") {
7449 anupam.sin 126
				if($(inputField).attr('name') != 'line2') {
127
					msg = "Please enter correct " + $(inputField).attr('name');
128
					displayAlert = true;
129
					return;
130
				}
7248 anupam.sin 131
			}
132
 
133
			if ($(inputField).attr('name') == "phone") {
134
				if ($(inputField).val().length != 10) {
7449 anupam.sin 135
					msg = 'Please enter a 10 digit mobile number';
136
					displayAlert = true;
137
					return;
7248 anupam.sin 138
				}
139
 
140
				var result = $(inputField).val().match(/^\d*$/);
141
				if(result == null || result.length == 0) {
7449 anupam.sin 142
					msg = 'Please enter a valid mobile number';
143
					displayAlert = true;
144
					return;
7248 anupam.sin 145
				}
146
			}
147
 
148
			var nameToSearch = $(inputField).attr("name");
149
			$('#showAddDiv [name="' + nameToSearch + '"]').html($(inputField).val());
150
			$('#createOrderForm input[name="' + nameToSearch + '"]').val($(inputField).val());
151
		});
7449 anupam.sin 152
 
153
		if(displayAlert == true) {
154
			alert(msg);
155
		} else {
156
			$('#editAddBlock').hide();
157
			$('#createOrder, #showPinDiv, #showAddDiv').show();
158
		}
7248 anupam.sin 159
	});
160
 
7293 anupam.sin 161
	$('#editPriceButton').click(function() {
162
		$('#editPriceButton').hide();
163
		$('#editPriceSpan').show();
164
	});
165
 
166
	$('#priceFixButton').click(function() {
167
		var result = $('#editPriceBox').val().match(/^\d*$/);
168
		if(result == null || result.length == 0) {
169
			alert('Please enter a valid amount');
170
			return false;
171
		}
172
 
7427 anupam.sin 173
		if(parseFloat($('#editPriceBox').val()) > parseFloat($('#shippingAddress input[name=price]').val())) {
7358 anupam.sin 174
			alert('Advance cannot be more than Rs.' + $('#shippingAddress input[name=price]').val());
7293 anupam.sin 175
			return false;
176
		}
177
 
178
		if(parseFloat($('#editPriceBox').val()) < parseFloat($('#shippingAddress input[name=advanceAmount]').val())) {
7323 anupam.sin 179
			alert('Advance cannot be below Rs. ' + $('#shippingAddress input[name=advanceAmount]').val());
7293 anupam.sin 180
			return false;
181
		}
182
 
7323 anupam.sin 183
		$('#editPriceButton').show();
184
		$('#editPriceSpan').hide();
185
		$('#advPrice').empty();
186
		$('#advPrice').text(' Rs. ' + parseFloat($('#editPriceBox').val()).toFixed(1));
187
		$('#shippingAddress input[name=advanceAmount]').val($('#editPriceBox').val());
188
	});
189
 
190
	$('#editSellingPriceButton').click(function() {
191
		$('#editSellingPriceButton').hide();
192
		$('#pricePopupBox').show();
193
	});
194
 
195
	$('#cancelPriceEdit').click(function() {
196
		$('#pricePopupBox').hide();
197
		$('#editSellingPriceButton').show();
198
	});
199
 
200
	$('#savePriceEdit').click(function() {
201
		var result = ($('#sellingPriceBox').val().split('.')[0]).match(/^\d*$/);
202
		if(result == null || result.length == 0) {
203
			alert('Please enter a valid amount');
204
			return false;
205
		}
206
 
207
		if(parseFloat($('#sellingPriceBox').val()) > parseFloat($('#maxPrice').text())) {
208
			alert('You cannot sell this product at more than Rs.' + $('#maxPrice').text());
209
			return false;
210
		}
211
 
7358 anupam.sin 212
		if(parseFloat($('#sellingPriceBox').val()) < parseFloat($('#absMin').val())) {
213
			alert('You cannot sell below Rs.' + $('#absMin').val());
214
			return false;
215
		}
216
 
7323 anupam.sin 217
		if(parseFloat($('#sellingPriceBox').val()) < parseFloat($('#minPrice').text())) {
7427 anupam.sin 218
			alert('You will need permission of the zonal head to sell at this price');
7293 anupam.sin 219
		}
220
 
7323 anupam.sin 221
		$('#editSellingPriceButton').show();
222
		$('#pricePopupBox').hide();
223
 
224
		$('#mrp').html(parseFloat($('#sellingPriceBox').val()).toFixed(2));
7293 anupam.sin 225
	});
7343 anupam.sin 226
 
227
	$("#dateselector").change(function() {
228
		if($(this).val()=="3"){
229
			$("#daterange").show();
230
		}else {
231
			$("#daterange").hide();
232
		}
233
	});
7348 anupam.sin 234
 
7427 anupam.sin 235
	$("#dateselector1").change(function() {
236
		if($(this).val()=="3"){
237
			$("#daterange1").show();
238
		}else {
239
			$("#daterange1").hide();
240
		}
241
	});
242
 
7348 anupam.sin 243
	$(".returnButton").click(function() {
244
		$("#returnPopupOrder").val($(this).attr("order"));
245
		$("#returnPopupBox").show();
246
	});
247
 
248
	$("#cancelReturnRequest").click(function() {
249
		$("#returnPopupOrder").val("");
250
		$("#returnPopupBox").hide();
251
	});
7349 anupam.sin 252
 
253
	$(".refundButton").click(function() {
254
		$("#refundPopupOrder").val($(this).attr("order"));
255
		$("#refundPopupBox").show();
256
	});
257
 
258
	$("#cancelRefundRequest").click(function() {
259
		$("#refundPopupOrder").val("");
260
		$("#refundPopupBox").hide();
261
	});
262
 
7386 anupam.sin 263
	$('#createOrderForm input[name=cardAmount]').focusin(function() {
264
		$('#bankSelector').show();
265
	});
266
 
267
	$('#createOrderForm input[name=cardAmount]').focusout(function() {
268
		tmp = parseFloat($('#createOrderForm input[name=cardAmount]').val());
269
		if(isNaN(tmp) || tmp < 1) {
270
			$('#bankSelector').hide();
271
		}
272
		else {
273
			$('#bankSelector').show();
274
		}
275
	});
7226 anupam.sin 276
});
277
 
278
function validateAddress() {
7248 anupam.sin 279
	if ($('input[name=name]').val() == "") {
280
		alert("Please enter the customer's name");
281
		return false;
282
	}
283
 
284
	if ($('input[name=phone]').val().length != 10) {
285
		alert('Please enter a 10 digit mobile number');
286
		return false;
287
	}
288
 
289
	var result = $('input[name=phone]').val().match(/^\d*$/);
290
	if(result == null || result.length == 0) {
291
		alert('Please enter a valid mobile number');
292
		return false;
293
	}
294
 
7226 anupam.sin 295
	if ($('input[name=line1]').val() == "") {
296
		alert('Please enter a shipping address');
297
		return false;
298
	}
7358 anupam.sin 299
 
7226 anupam.sin 300
	if ($('input[name=city]').val() == "") {
301
		alert('Please enter the name of the city');
302
		return false;
303
	}
7386 anupam.sin 304
	if ($('#shipState').val() == "") {
7226 anupam.sin 305
		alert('Please enter the name of the state');
306
		return false;
307
	}
7386 anupam.sin 308
 
309
	if ($('input[name=email]').val() == "") {
310
		alert("Please enter the customer's name");
311
		return false;
312
	}
313
 
7226 anupam.sin 314
	return true;
7248 anupam.sin 315
}
316
 
317
function validatePaymentDetails() {
7386 anupam.sin 318
	if($('#createOrderForm input[name=advanceAmount]').val() == ""){
319
		total = 0;
320
	} else {
321
		total = parseFloat($('#createOrderForm input[name=advanceAmount]').val());
322
	}
323
 
324
	if($('#createOrderForm input[name=cashAmount]').val() == ""){
325
		cashAmount = 0;
326
	} else {
327
		cashAmount = parseFloat($('#createOrderForm input[name=cashAmount]').val());
328
	}
329
 
330
	if($('#createOrderForm input[name=cardAmount]').val() == ""){
331
		cardAmount = 0;
332
	} else {
333
		cardAmount = parseFloat($('#createOrderForm input[name=cardAmount]').val());
334
	}
335
 
336
	if(isNaN(total) || isNaN(cashAmount) || isNaN(cardAmount)) {
337
		alert("Please enter valid amounts");
338
		return false;
339
	}
340
 
341
	if(total != cashAmount + cardAmount) {
342
		alert("Sum of cash and card is not equal to advance amount");
343
		return false;
344
	}
345
 
346
	if(cardAmount > 0) {
347
		if($('#edcSelector').val() == "") {
348
			alert('Please select the name of EDC bank');
7248 anupam.sin 349
			return false;
350
		}
7426 anupam.sin 351
 
352
		if($('#createOrderForm input[name=approvalCode]').val() == "") {
353
			alert("Please enter approval code");
354
			return false;
355
		}
7248 anupam.sin 356
	}
7435 anupam.sin 357
 
358
	$('#createOrder').hide();
359
	$('#waitSpan').show();
360
	$('#addressEdit').hide();
361
	$('#pincodeEdit').hide();
7349 anupam.sin 362
}
363
 
364
function validateAmount() {
365
	var result = $('#refundAmountText').val().match(/^\d*$/);
366
	if(result == null || result.length == 0) {
367
		alert('Please enter a valid amount');
368
		return false;
369
	}
7226 anupam.sin 370
}