Subversion Repositories SmartDukaan

Rev

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

Rev 24087 Rev 24440
Line 1... Line 1...
1
$().ready(function() {
1
function formLoaded() {
2
	$("form#cd input").each(function(){
2
	$("form#cd input").each(function(){
3
		$(this).attr('autocomplete', 'off');
3
		$(this).attr('autocomplete', 'off');
4
	});
4
	});
5
});
-
 
6
$().ready(function() {
-
 
7
    // validate the comment form when it is submitted
-
 
8
    $('#cd').validate({
5
    $('form#cd').validate({
9
		rules:{
6
		rules:{
10
			name:{
7
			name:{
11
				required:true
8
				required:true
12
			},
9
			},
13
			email:{
10
			email:{
Line 36... Line 33...
36
				digits:true
33
				digits:true
37
			},
34
			},
38
		},
35
		},
39
		messages:{
36
		messages:{
40
			name:{
37
			name:{
41
				required:"Please enter the name"
38
				required:"Required"
42
			},
39
			},
43
			line1:{
40
			line1:{
44
				required:"Please enter the address"
41
				required:"Required"
45
			},
42
			},
46
			state:{
43
			state:{
47
				required: "Please select a state"
44
				required: "State required"
48
			},
45
			},
49
			city:{
46
			city:{
50
				required: "Please enter the city"
47
				required: "City required"
51
			},
48
			},
52
			email:{
49
			email:{
53
				require: "Please enter a valid email address"
50
				require: "Required"
54
			},
51
			},
55
			pincode:{
52
			pincode:{
56
				required: "Please enter the pincode",
53
				required: "Required",
57
				digits:"Please enter a valid pincode"
54
				digits:"Invalid pin"
58
			},
55
			},
59
			phone:{
56
			phone:{
60
				required: "Please enter the phone number",
57
				required: "Required",
61
				digits:"Please enter a valid number",
58
				digits:"Invalid number",
62
				minlength:"Number should be of 10 digits"
59
				minlength:"Number should be of 10 digits"
63
			}
60
			}
64
		},
61
		},
65
		submitHandler: function (form, event) {
62
		submitHandler: function (form, event) {
66
			event.preventDefault();
63
			event.preventDefault();
Line 71... Line 68...
71
			}
68
			}
72
			doPostAjaxRequestWithJsonHandler(context+"/create-order", payload, function(response){
69
			doPostAjaxRequestWithJsonHandler(context+"/create-order", payload, function(response){
73
				emptyBag();
70
				emptyBag();
74
				$('#main-content').html(response);
71
				$('#main-content').html(response);
75
			});
72
			});
76
            return false; // required to block normal submit since you used ajax
73
            return false; // required to block normal submit since you used
-
 
74
							// ajax
77
         }
75
         }
78
	});
76
	});
79
    
77
    
80
	$("input.unitPrice").change(function() {
78
	$("input.unitPrice").on('change', function() {
81
		var $element = $(this);
79
		var $element = $(this);
82
		var unitPrice = parseFloat($element.val());
80
		var unitPrice = parseFloat($element.val());
83
		if(!isNaN(unitPrice)) {
81
		if(!isNaN(unitPrice)) {
84
			var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
82
			var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
85
			var mopPrice = parseFloat($(this).attr('mopPrice'));
83
			var mopPrice = parseFloat($(this).attr('mopPrice'));
Line 89... Line 87...
89
				alert("Selling Price should not be greater than MRP");
87
				alert("Selling Price should not be greater than MRP");
90
				$element.addClass("border-highlight");
88
				$element.addClass("border-highlight");
91
			} else if(!accessoriesDeals && unitPrice < mopPrice){
89
			} else if(!accessoriesDeals && unitPrice < mopPrice){
92
				alert("Selling Price must be greater than equal to MOP");
90
				alert("Selling Price must be greater than equal to MOP");
93
				$element.addClass("border-highlight");
91
				$element.addClass("border-highlight");
94
			}else if(itemType=='SERIALIZED' && unitPrice < mop){
92
			}else if(itemType=='SERIALIZED' && unitPrice < mopPrice){
95
				alert("Selling Price must be greater than equal to MOP");
93
				alert("Selling Price must be greater than equal to MOP");
96
				$element.addClass("border-highlight");
94
				$element.addClass("border-highlight");
97
			}else if(itemType=='NON_SERIALIZED' && unitPrice < dp){
95
			}else if(itemType=='NON_SERIALIZED' && unitPrice < dp){
98
				alert("Selling Price must be greater than equal to DP");
96
				alert("Selling Price must be greater than equal to DP");
99
				$element.addClass("border-highlight");
97
				$element.addClass("border-highlight");
100
			}else{
98
			}else{
101
				$element.removeClass("border-highlight")
99
				$element.removeClass("border-highlight");
102
				if(unitPrice == mopPrice){
-
 
103
					$("input.discountAmount").removeAttr("readonly");
-
 
104
				}
-
 
105
				doAjaxRequestHandler(context+"/insurancePrices?price="+unitPrice, "GET", function(response){
-
 
106
					console.log("response : "+JSON.stringify(response));
-
 
107
					var insurancePriceMap = response.response;
-
 
108
					for(key in insurancePriceMap){
-
 
109
						var dealerPrice = insurancePriceMap[key].dealerPrice;
-
 
110
						var sellingPrice = insurancePriceMap[key].sellingPrice;
-
 
111
						$element.closest('tr').find('.insuranceAmount').attr("placeholder", dealerPrice + "-" + sellingPrice);
-
 
112
						break;
-
 
113
					}
-
 
114
				});
-
 
115
			}
100
			}
-
 
101
			// Clear insurance values if price changes
-
 
102
			$(this).closest('tr').find('.insuranceid').val("");
-
 
103
			$(this).closest('tr').find('.insuranceamount').val("0");
116
		}
104
		}
-
 
105
		calculateTotalAmount();
117
	});
106
	});
118
	
107
	
119
	$( "input.phone").change(function() {
108
	$( "input.phone").change(function() {
120
		console.log("phone blur called");
109
		console.log("phone blur called");
121
		var mobileNumber = $(this).val();
110
		var mobileNumber = $(this).val();
122
		if(mobileNumber.length < 10) {
111
		if(mobileNumber.length < 10) {
123
			return;
112
			return;
124
		}
113
		}
125
		writeOldCustomerDetailsByMobileNumber(mobileNumber);
114
		writeOldCustomerDetailsByMobileNumber(mobileNumber);
126
		var itemIds = [];
-
 
127
		$("form#cd input.serialNumber").each(function(){
-
 
128
			var itemId = parseInt($(this).attr("itemId"));
-
 
129
			itemIds.push(itemId);
-
 
130
		});
-
 
131
		console.log(itemIds);
-
 
132
		calculateTotalAmount();
-
 
133
	});
115
	});
134
  
-
 
135
});
-
 
136
 
116
	
137
 
117
}
138
function validateOrderDetails(){
118
function validateOrderDetails(){
139
	var sNumbers = [];
119
	var sNumbers = [];
140
	var error = false;
120
	var error = false;
141
	$("form#cd input.serialNumber").each(function(){
121
	$("form#cd input.serialNumber").each(function(){
142
		var input = $(this).val().trim();
122
		var input = $(this).val().trim();
Line 156... Line 136...
156
			error=true;
136
			error=true;
157
			$(this).addClass("border-highlight");
137
			$(this).addClass("border-highlight");
158
		}
138
		}
159
	});
139
	});
160
	
140
	
161
	// checking input discountAmount is not greater than maxDiscountAmount
-
 
162
	$("form#cd input.discountAmount").each(function(){
-
 
163
		var input = $(this).val().trim();
-
 
164
		var mop = $(this).attr("mop");
-
 
165
		
-
 
166
		if(mop){
-
 
167
			var maxDiscountPriceRangeString = $(this).attr("placeholder");
-
 
168
			var maxDiscountPrice = 0;
-
 
169
			if(maxDiscountPriceRangeString != undefined && maxDiscountPriceRangeString != ''){
-
 
170
				maxDiscountPrice = maxDiscountPriceRangeString.substring(6);
-
 
171
			}
-
 
172
			$(this).removeClass("border-highlight");
-
 
173
			if (!input || parseFloat(input)<0 || isNaN(input)){
-
 
174
				alert("DiscountAmount value can not be lesser than 0 or invalid value");
-
 
175
				error=true;
-
 
176
				$(this).addClass("border-highlight");
-
 
177
			}
-
 
178
			if(parseFloat(input) > maxDiscountPrice){
-
 
179
				alert("DiscountAmount [" + parseFloat(input) + "] value can not be greater than the suggested maxDiscountPrice [" + maxDiscountPrice + "]");
-
 
180
				error=true;
-
 
181
				$(this).addClass("border-highlight");
-
 
182
			}
-
 
183
		}
-
 
184
	});
-
 
185
	
-
 
186
	var gstNumber = $("form#cd input[name=gstNumber]").val();
141
	var gstNumber = $("form#cd input[name=gstNumber]").val();
187
	$("form#cd input[name=gstNumber]").removeClass("border-highlight");
142
	$("form#cd input[name=gstNumber]").removeClass("border-highlight");
188
	if(gstNumber.length > 0 && gstNumber.length != 15){
143
	if(gstNumber.length > 0 && gstNumber.length != 15){
189
		alert("Please provide valid gstNumber");
144
		alert("Please provide valid gstNumber");
190
		error = true;
145
		error = true;
191
		$("form#cd input[name=gstNumber]").addClass("border-highlight");
146
		$("form#cd input[name=gstNumber]").addClass("border-highlight");
192
	}
147
	}
193
	
148
	
194
	var amount = 0;
149
	var amount = 0;
195
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
150
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
196
	var totalAdvanceAmount = parseFloat($("form#cd input.totalAdvanceAmount").val());
-
 
197
	
-
 
198
	netPayableAmount = netPayableAmount - totalAdvanceAmount;
-
 
199
	
-
 
200
	$("form#cd input.amount").each(function(){
151
	$("form#cd input.amount").each(function(){
201
		if ($(this).val() == ""){
152
		if ($(this).val() == ""){
202
			$(this).val(0);
153
			$(this).val(0);
203
		}
154
		}
204
		var tmpAmount = parseFloat($(this).val());
155
		var tmpAmount = parseFloat($(this).val());
Line 231... Line 182...
231
function getSerialNumbersFromOrder($el){
182
function getSerialNumbersFromOrder($el){
232
	var $serialNumberElement = $el.find('.serialNumber');
183
	var $serialNumberElement = $el.find('.serialNumber');
233
	if($serialNumberElement.val() == ''){
184
	if($serialNumberElement.val() == ''){
234
		return null;
185
		return null;
235
	}
186
	}
236
	var insuranceAmount = parseFloat($el.find('.insuranceAmount').val());
187
	var insuranceAmount = parseFloat($el.find('.insuranceamount').val());
237
	if(insuranceAmount > 0){
188
	if(insuranceAmount > 0){
238
		insurance = true;
189
		insurance = true;
239
		globalInsurace = true;
190
		globalInsurace = true;
240
	}else{
191
	}else{
241
		insurance = false;
192
		insurance = false;
Line 271... Line 222...
271
			orderObj['fofoOrderItems'] = tmp;
222
			orderObj['fofoOrderItems'] = tmp;
272
		}
223
		}
273
	});
224
	});
274
	console.log( JSON.stringify(orderObj));
225
	console.log( JSON.stringify(orderObj));
275
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
226
	$("#order-details").find("tr:not(:first-child)").each(function(index, el){
276
		//console.log(el);
227
		// console.log(el);
277
		//console.log(index);
228
		// console.log(index);
278
		var $el = $(el);
229
		var $el = $(el);
279
		var $unitPriceElement = $el.find('.unitPrice');
230
		var $unitPriceElement = $el.find('.unitPrice');
280
		var $discountAmountElement = $el.find('.discountAmount');
-
 
281
			
231
			
282
		var itemId = parseInt($unitPriceElement.attr("itemId"));
232
		var itemId = parseInt($unitPriceElement.attr("itemId"));
283
		var unitPrice = parseFloat($unitPriceElement.val());
233
		var unitPrice = parseFloat($unitPriceElement.val());
284
		var qty = parseInt($unitPriceElement.attr("quantity"));
234
		var qty = parseInt($unitPriceElement.attr("quantity"));
285
		var discountAmount = parseFloat($discountAmountElement.val());
-
 
286
		var mop = $discountAmountElement.attr("mop");
-
 
287
		var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
235
		var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty};
288
		tmpObj.discountAmount = discountAmount;
-
 
289
 
236
 
290
		if (orderObj['fofoOrderItems'][itemId] === undefined){
237
		if (orderObj['fofoOrderItems'][itemId] === undefined){
291
			tmpObj['serialNumberDetails'] =[];
238
			tmpObj['serialNumberDetails'] =[];
292
		}else{
239
		}else{
293
			//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
240
			// tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
294
			tmpObj['serialNumberDetails'] = [];
241
			tmpObj['serialNumberDetails'] = [];
295
		}
242
		}
296
		var found = false;
243
		var found = false;
297
		for(var i = 0; i < priceQtyArray.length; i++){			
244
		for(var i = 0; i < priceQtyArray.length; i++){			
298
			if (priceQtyArray[i]["itemId"] == itemId){
245
			if (priceQtyArray[i]["itemId"] == itemId){
Line 305... Line 252...
305
			priceQtyArray.push(tmpObj);
252
			priceQtyArray.push(tmpObj);
306
		}
253
		}
307
	});	
254
	});	
308
		
255
		
309
	$("#order-details").find("tr:not(:first-child)").each(function(index,el){
256
	$("#order-details").find("tr:not(:first-child)").each(function(index,el){
310
		//console.log(el);
257
		// console.log(el);
311
		//console.log(index);
258
		// console.log(index);
312
		var $serialNumberElement = $(el).find('.serialNumber');
259
		var $serialNumberElement = $(el).find('.serialNumber');
313
		var itemId = parseInt($serialNumberElement.attr("itemId"));
260
		var itemId = parseInt($serialNumberElement.attr("itemId"));
314
		var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
261
		var insuranceEle = $(el).find('.insuranceamount');
315
		//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
-
 
316
			
-
 
317
		//}
-
 
318
		//console.log($serialNumberElement.val());
-
 
319
		//console.log(itemId);
262
		var insuranceAmount = 0;
320
		for(var i = 0; i < priceQtyArray.length; i++){
263
		if(insuranceEle.length > 0) {
321
			console.log(priceQtyArray[i]["itemId"]);
264
			insuranceAmount = parseFloat(insuranceEle.val());
-
 
265
		}
322
			if (priceQtyArray[i]["itemId"] == itemId){
266
		var insuranceId = "";
323
				if(insuranceAmount > 0){
267
		if(insuranceAmount > 0) {
324
					insurance = true;
-
 
325
					globalInsurance = true;
-
 
326
				}else{
-
 
327
					insurance = false;
268
			insuranceId = $(el).find('.insuranceid').val();
328
				}
269
		}
329
				var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
270
		var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insuranceId,'amount':insuranceAmount}
330
				priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
271
		priceQtyArray[index]['serialNumberDetails'].push(serialNumberDetails);
331
			}
-
 
332
        }
272
        
333
	});
273
	});
334
	
274
	
335
	console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
-
 
336
	customerObj['firstName'] = $("form#cd input[name=firstName]").val();
275
	customerObj['firstName'] = $("form#cd input[name=firstName]").val();
337
	customerObj['lastName'] = $("form#cd input[name=lastName]").val();
276
	customerObj['lastName'] = $("form#cd input[name=lastName]").val();
338
	customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
277
	customerObj['mobileNumber'] = $("form#cd input[name=phone]").val(); 
339
	customerObj['emailId'] = $("form#cd input[name=email]").val();
278
	customerObj['emailId'] = $("form#cd input[name=email]").val();
340
	customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
279
	customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
341
	//customerObj['dateOfBirth'] = startDate;
280
	// customerObj['dateOfBirth'] = startDate;
342
	var customerAddress = {};
281
	var customerAddress = {};
343
	customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
282
	customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
344
	customerAddress['line1'] = $("form#cd input[name=line1]").val();
283
	customerAddress['line1'] = $("form#cd input[name=line1]").val();
345
	customerAddress['line2'] = $("form#cd input[name=line2]").val();
284
	customerAddress['line2'] = $("form#cd input[name=line2]").val();
346
	customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
285
	customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
Line 349... Line 288...
349
	customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
288
	customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
350
	customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
289
	customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
351
	customerAddress['country'] = "India";
290
	customerAddress['country'] = "India";
352
	customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
291
	customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
353
	customerObj['address'] = customerAddress; 
292
	customerObj['address'] = customerAddress; 
-
 
293
	customerObj['gender'] = $("#gender").val();
-
 
294
	customerObj['dateOfBirth'] = startDate;
354
	console.log( JSON.stringify(customerObj));
295
	localStorage.setItem("customerDetails", JSON.stringify(customerObj));
355
	
296
	
356
	
297
	
357
	var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
298
	var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
358
	//console.log("paymentOptionSize = "+paymentOptionSize);
299
	// console.log("paymentOptionSize = "+paymentOptionSize);
359
	for(var index = 0; index < paymentOptionSize; index++){
300
	for(var index = 0; index < paymentOptionSize; index++){
360
		var paymentOptionAmount = 0.0;
301
		var paymentOptionAmount = 0.0;
361
		if($('#paymentOptionIdAmount'+index).val() != ""){
302
		if($('#paymentOptionIdAmount'+index).val() != ""){
362
			paymentOptionAmount = parseFloat($('#paymentOptionIdAmount'+index).val());
303
			paymentOptionAmount = parseFloat($('#paymentOptionIdAmount'+index).val());
363
		}
304
		}
Line 369... Line 310...
369
	}
310
	}
370
	
311
	
371
	console.log( JSON.stringify(paymentOptionIdAmount));
312
	console.log( JSON.stringify(paymentOptionIdAmount));
372
	
313
	
373
	var retObj = {};
314
	var retObj = {};
374
	if(globalInsurance){
-
 
375
		retObj['customerDateOfBirth'] = startDate;
-
 
376
	}
-
 
377
	
-
 
378
	retObj['fofoOrderItems'] = (priceQtyArray);
315
	retObj['fofoOrderItems'] = (priceQtyArray);
379
	retObj['customer'] = (customerObj);
316
	retObj['customer'] = (customerObj);
380
	retObj['paymentOptions'] =  (paymentOptionIdAmount);
317
	retObj['paymentOptions'] =  (paymentOptionIdAmount);
381
	
318
	
382
	console.log(retObj);
319
	console.log(retObj);
Line 391... Line 328...
391
		}
328
		}
392
		var customer = response.response;
329
		var customer = response.response;
393
	    $('#firstName').attr('value', customer.firstName);
330
	    $('#firstName').attr('value', customer.firstName);
394
	    $('#lastName').attr('value', customer.lastName);
331
	    $('#lastName').attr('value', customer.lastName);
395
	    $('#email').attr('value', customer.emailId);
332
	    $('#email').attr('value', customer.emailId);
396
	    //$('#phone').attr('value', customer.mobileNumber);
333
	    // $('#phone').attr('value', customer.mobileNumber);
397
	    if(customer.address !== null) {
334
	    if(customer.address !== null) {
398
	    	$('#alternatePhone').attr('value', customer.address.phoneNumber);
335
	    	$('#alternatePhone').attr('value', customer.address.phoneNumber);
399
	    	$('#line1').attr('value', customer.address.line1);
336
	    	$('#line1').attr('value', customer.address.line1);
400
	    	$('#line2').attr('value', customer.address.line2);
337
	    	$('#line2').attr('value', customer.address.line2);
401
	    	$('#landmark').attr('value', customer.address.landmark);
338
	    	$('#landmark').attr('value', customer.address.landmark);
402
	    	$('#pinCode').attr('value', customer.address.pinCode);
339
	    	$('#pinCode').attr('value', customer.address.pinCode);
403
	    	$('#city').attr('value', customer.address.city);
340
	    	$('#city').attr('value', customer.address.city);
404
	    	$('#state').attr('value', customer.address.state).prop('selected',true);
341
	    	$('#state').attr('value', customer.address.state).prop('selected',true);
405
	    	$('#phone').attr('addressId', customer.address.id);
342
	    	$('#phone').attr('addressId', customer.address.id);
406
	    }
343
	    }
407
	    //$('#state').val(customer.address.state).prop('selected', true);
344
	    // $('#state').val(customer.address.state).prop('selected', true);
408
	});
345
	});
409
}
346
}
410
347