Subversion Repositories SmartDukaan

Rev

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

Rev 31274 Rev 31855
Line 1... Line 1...
1
var customerId;
1
var customerId;
2
 
2
 
3
function formLoaded() {
3
function formLoaded() {
4
	$("form#cd input").each(function () {
4
	$("form#cd input").each(function() {
5
		$(this).attr('autocomplete', 'off');
5
		$(this).attr('autocomplete', 'off');
6
	});
6
	});
7
	$('form#cd').validate({
7
	$('form#cd').validate({
8
		rules: {
8
		rules: {
9
			name: {
9
			name: {
Line 59... Line 59...
59
				required: "Required",
59
				required: "Required",
60
				digits: "Invalid number",
60
				digits: "Invalid number",
61
				minlength: "Number should be of 10 digits"
61
				minlength: "Number should be of 10 digits"
62
			}
62
			}
63
		},
63
		},
64
		submitHandler: function (form, event) {
64
		submitHandler: function(form, event) {
65
			event.preventDefault();
65
			event.preventDefault();
66
			var payload = orderDetailsPayload();
66
			var payload = orderDetailsPayload();
67
			if (!validateOrderDetails()) {
67
			if (!validateOrderDetails()) {
68
				alert("Please fix highlighted errors");
68
				alert("Please fix highlighted errors");
69
				return false;
69
				return false;
70
			}
70
			}
71
			doPostAjaxRequestWithJsonHandler(context + "/create-order", payload, function (response) {
71
			doPostAjaxRequestWithJsonHandler(context + "/create-order", payload, function(response) {
72
				emptyBag();
72
				emptyBag();
73
				$('#main-content').html(response);
73
				$('#main-content').html(response);
74
			});
74
			});
75
			return false; // required to block normal submit since you used
75
			return false; // required to block normal submit since you used
76
			// ajax
76
			// ajax
Line 126... Line 126...
126
				required: "Required",
126
				required: "Required",
127
				digits: "Invalid number",
127
				digits: "Invalid number",
128
				minlength: "Number should be of 10 digits"
128
				minlength: "Number should be of 10 digits"
129
			}
129
			}
130
		},
130
		},
131
		submitHandler: function (form, event) {
131
		submitHandler: function(form, event) {
132
			event.preventDefault();
132
			event.preventDefault();
133
			let customerAddress = {};
133
			let customerAddress = {};
134
			customerAddress['name'] = $("#firstName").val();
134
			customerAddress['name'] = $("#firstName").val();
135
			customerAddress['lastName'] = $("#lastName").val();
135
			customerAddress['lastName'] = $("#lastName").val();
136
			customerAddress['line1'] = $("#line1").val();
136
			customerAddress['line1'] = $("#line1").val();
Line 139... Line 139...
139
			customerAddress['city'] = $("#city").val();
139
			customerAddress['city'] = $("#city").val();
140
			customerAddress['state'] = $('select[name=state] option:selected').val();
140
			customerAddress['state'] = $('select[name=state] option:selected').val();
141
			customerAddress['pinCode'] = $("#pinCode").val();
141
			customerAddress['pinCode'] = $("#pinCode").val();
142
			customerAddress['phoneNumber'] = $("#alternatePhone").val();
142
			customerAddress['phoneNumber'] = $("#alternatePhone").val();
143
			customerAddress['country'] = "India";
143
			customerAddress['country'] = "India";
144
			doPostAjaxRequestWithJsonHandler(`${context}/customer/address?customerId=${customerId}`, JSON.stringify(customerAddress), function (response) {
144
			doPostAjaxRequestWithJsonHandler(`${context}/customer/address?customerId=${customerId}`, JSON.stringify(customerAddress), function(response) {
145
				$("#address-body").prepend(getAddressTr(response.response));
145
				$("#address-body").prepend(getAddressTr(response.response));
146
				$('#newaddressModal').modal('toggle');
146
				$('#newaddressModal').modal('toggle');
147
				$("#address-body").find('a.select-address').click();
147
				$("#address-body").find('a.select-address').click();
148
			});
148
			});
149
		}
149
		}
150
 
150
 
151
	});
151
	});
152
 
152
 
153
	$("input.unitPrice").on('change', function () {
153
	$("input.unitPrice").on('change', function() {
154
		var $element = $(this);
154
		var $element = $(this);
155
		var unitPrice = parseFloat($element.val());
155
		var unitPrice = parseFloat($element.val());
156
		if (!isNaN(unitPrice)) {
156
		if (!isNaN(unitPrice)) {
157
			var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
157
			var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
158
			var mopPrice = parseFloat($(this).attr('mopPrice'));
158
			var mopPrice = parseFloat($(this).attr('mopPrice'));
Line 183... Line 183...
183
		calculateTotalAmount();
183
		calculateTotalAmount();
184
	});
184
	});
185
	customerInfo = $("div.customerinfo").html();
185
	customerInfo = $("div.customerinfo").html();
186
	billingInfo = $("div.billinginfo").html();
186
	billingInfo = $("div.billinginfo").html();
187
 
187
 
188
	$("input.search-phone").change(function () {
188
	$("input.search-phone").change(function() {
189
		resetInputs();
189
		resetInputs();
190
		var mobileNumber = $(this).val();
190
		var mobileNumber = $(this).val();
191
		console.log(mobileNumber)
191
		console.log(mobileNumber)
192
		if (mobileNumber.length < 10 || mobileNumber.length > 10) {
192
		if (mobileNumber.length < 10 || mobileNumber.length > 10) {
193
			alert("Mobile Number is must be 10 digits");
193
			alert("Mobile Number is must be 10 digits");
Line 195... Line 195...
195
		} else {
195
		} else {
196
			writeOldCustomerDetailsByMobileNumber(mobileNumber);
196
			writeOldCustomerDetailsByMobileNumber(mobileNumber);
197
		}
197
		}
198
	});
198
	});
199
 
199
 
200
	$(document).on('click', 'button.new-address-btn', function () {
200
	$(document).on('click', 'button.new-address-btn', function() {
201
		$('#newaddressModal').modal({show: true});
201
		$('#newaddressModal').modal({ show: true });
202
	});
202
	});
203
 
203
 
204
	$(document).on('click', 'button.mk_add_email', function () {
204
	$(document).on('click', 'button.mk_add_email', function() {
205
		let customerObj = {};
205
		let customerObj = {};
206
		customerObj['customerId'] = customerId;
206
		customerObj['customerId'] = customerId;
207
		customerObj['emailId'] = $("#emailId").val();
207
		customerObj['emailId'] = $("#emailId").val();
208
		if (validateEmail(customerObj['emailId'])) {
208
		if (validateEmail(customerObj['emailId'])) {
209
			doPostAjaxRequestWithJsonHandler(`${context}/customer/add-email`, JSON.stringify(customerObj), function (response) {
209
			doPostAjaxRequestWithJsonHandler(`${context}/customer/add-email`, JSON.stringify(customerObj), function(response) {
210
				alert("Email added");
210
				alert("Email added");
211
				$("input.search-phone").val(customerObj['mobileNumber']).change();
211
				$("input.search-phone").val(customerObj['mobileNumber']).change();
212
			});
212
			});
213
		} else {
213
		} else {
214
			alert("Invalid email id");
214
			alert("Invalid email id");
215
		}
215
		}
216
 
216
 
217
	});
217
	});
218
	$(document).on('click', 'button.mk_add_customer', function () {
218
	$(document).on('click', 'button.mk_add_customer', function() {
219
		customerObj = {}
219
		customerObj = {}
220
		if ($("input.firstName").val().length == 0) {
220
		if ($("input.firstName").val().length == 0) {
221
			alert("First Name is required");
221
			alert("First Name is required");
222
			return false;
222
			return false;
223
		}
223
		}
Line 225... Line 225...
225
		customerObj['lastName'] = $("input.lastName").val();
225
		customerObj['lastName'] = $("input.lastName").val();
226
		customerObj['emailId'] = $("#emailId").val();
226
		customerObj['emailId'] = $("#emailId").val();
227
 
227
 
228
		console.log(customerObj['emailId']);
228
		console.log(customerObj['emailId']);
229
		customerObj['mobileNumber'] = $("input.phone").val();
229
		customerObj['mobileNumber'] = $("input.phone").val();
-
 
230
 
-
 
231
		if (customerObj['emailId']) {
-
 
232
			if (!validateEmail(customerObj['emailId'])) {
-
 
233
				alert("Invalid email id");
-
 
234
				return false;
-
 
235
			}
-
 
236
		}
-
 
237
 
-
 
238
 
-
 
239
 
230
		doPostAjaxRequestWithJsonHandler(`${context}/customer/add`, JSON.stringify(customerObj), function (response) {
240
		doPostAjaxRequestWithJsonHandler(`${context}/customer/add`, JSON.stringify(customerObj), function(response) {
231
			alert("Customer added");
241
			alert("Customer added");
232
			$("input.search-phone").change();
242
			$("input.search-phone").change();
233
		});
243
		});
234
 
244
 
235
 
245
 
236
	});
246
	});
237
	$(document).on('click', 'a.select-address', function () {
247
	$(document).on('click', 'a.select-address', function() {
238
		$(this).closest('table').data("addressselected", "true").find('td').css("font-weight", "normal");
248
		$(this).closest('table').data("addressselected", "true").find('td').css("font-weight", "normal");
239
		$(this).closest('tr').find('td').css("font-weight", "bold");
249
		$(this).closest('tr').find('td').css("font-weight", "bold");
240
		selectedAddressId = $(this).data("addressid");
250
		selectedAddressId = $(this).data("addressid");
241
	});
251
	});
242
	$(document).on('click', 'button.btn-add-address', function() {
252
	$(document).on('click', 'button.btn-add-address', function() {
Line 245... Line 255...
245
 
255
 
246
}
256
}
247
function validateOrderDetails() {
257
function validateOrderDetails() {
248
	var sNumbers = [];
258
	var sNumbers = [];
249
	var error = false;
259
	var error = false;
250
	$("form#cd input.serialNumber").each(function () {
260
	$("form#cd input.serialNumber").each(function() {
251
		var input = $(this).val().trim();
261
		var input = $(this).val().trim();
252
		var itemType = $(this).attr("itemType");
262
		var itemType = $(this).attr("itemType");
253
		$(this).removeClass("border-highlight");
263
		$(this).removeClass("border-highlight");
254
		if (sNumbers.indexOf(input) != -1 || (itemType === 'SERIALIZED' && !input)) {
264
		if (sNumbers.indexOf(input) != -1 || (itemType === 'SERIALIZED' && !input)) {
255
			error = true;
265
			error = true;
256
			$(this).addClass("border-highlight");
266
			$(this).addClass("border-highlight");
257
		}
267
		}
258
		sNumbers.push(input);
268
		sNumbers.push(input);
259
	});
269
	});
260
 
270
 
261
	$("form#cd input.unitPrice").each(function () {
271
	$("form#cd input.unitPrice").each(function() {
262
		var input = $(this).val().trim();
272
		var input = $(this).val().trim();
263
		$(this).removeClass("border-highlight");
273
		$(this).removeClass("border-highlight");
264
		if (!input || parseInt(input) <= 0 || isNaN(input)) {
274
		if (!input || parseInt(input) <= 0 || isNaN(input)) {
265
			error = true;
275
			error = true;
266
			$(this).addClass("border-highlight");
276
			$(this).addClass("border-highlight");
Line 275... Line 285...
275
		$("form#cd input[name=gstNumber]").addClass("border-highlight");
285
		$("form#cd input[name=gstNumber]").addClass("border-highlight");
276
	}
286
	}
277
 
287
 
278
	var amount = 0;
288
	var amount = 0;
279
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
289
	var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
280
	$("form#cd input.amount").each(function () {
290
	$("form#cd input.amount").each(function() {
281
		if ($(this).val() == "") {
291
		if ($(this).val() == "") {
282
			$(this).val(0);
292
			$(this).val(0);
283
		}
293
		}
284
		var tmpAmount = parseFloat($(this).val());
294
		var tmpAmount = parseFloat($(this).val());
285
		amount = amount + tmpAmount;
295
		amount = amount + tmpAmount;
Line 292... Line 302...
292
		if (amount < netPayableAmount) {
302
		if (amount < netPayableAmount) {
293
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
303
			alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
294
		} else {
304
		} else {
295
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
305
			alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
296
		}
306
		}
297
		$("form#cd input.netPayableAmount").each(function () {
307
		$("form#cd input.netPayableAmount").each(function() {
298
			$(this).addClass("border-highlight");
308
			$(this).addClass("border-highlight");
299
		});
309
		});
300
		error = true;
310
		error = true;
301
	}
311
	}
302
 
312
 
Line 318... Line 328...
318
		insurance = true;
328
		insurance = true;
319
		globalInsurace = true;
329
		globalInsurace = true;
320
	} else {
330
	} else {
321
		insurance = false;
331
		insurance = false;
322
	}
332
	}
323
	return {'serialNumber': $serialNumberElement.val(), 'insurance': insurance, 'amount': insuranceAmount}
333
	return { 'serialNumber': $serialNumberElement.val(), 'insurance': insurance, 'amount': insuranceAmount }
324
}
334
}
325
 
335
 
326
function orderDetailsPayload() {
336
function orderDetailsPayload() {
327
	var orderObj = {};
337
	var orderObj = {};
328
	var priceQtyArray = [];
338
	var priceQtyArray = [];
329
	var customerObj = {};
339
	var customerObj = {};
330
	var paymentOptionIdAmount = [];
340
	var paymentOptionIdAmount = [];
331
	var globalInsurance = false;
341
	var globalInsurance = false;
332
 
342
 
333
	$("form#cd input.serialNumber").each(function () {
343
	$("form#cd input.serialNumber").each(function() {
334
		var itemId = parseInt($(this).attr("itemId"));
344
		var itemId = parseInt($(this).attr("itemId"));
335
		if (orderObj.hasOwnProperty('fofoOrderItems')) {
345
		if (orderObj.hasOwnProperty('fofoOrderItems')) {
336
			var itemDetails = orderObj['fofoOrderItems'];
346
			var itemDetails = orderObj['fofoOrderItems'];
337
			if (itemDetails.hasOwnProperty(itemId)) {
347
			if (itemDetails.hasOwnProperty(itemId)) {
338
				var serialNumbers = itemDetails[itemId];
348
				var serialNumbers = itemDetails[itemId];
Line 350... Line 360...
350
			tmp[itemId] = serialNumbers;
360
			tmp[itemId] = serialNumbers;
351
			orderObj['fofoOrderItems'] = tmp;
361
			orderObj['fofoOrderItems'] = tmp;
352
		}
362
		}
353
	});
363
	});
354
	console.log(JSON.stringify(orderObj));
364
	console.log(JSON.stringify(orderObj));
355
	$("#order-items").find("tr:not(:first-child)").each(function (index, el) {
365
	$("#order-items").find("tr:not(:first-child)").each(function(index, el) {
356
		// console.log(el);
366
		// console.log(el);
357
		// console.log(index);
367
		// console.log(index);
358
		var $el = $(el);
368
		var $el = $(el);
359
		var $unitPriceElement = $el.find('.unitPrice');
369
		var $unitPriceElement = $el.find('.unitPrice');
360
		var $discountElement = $el.find('.discount');
370
		var $discountElement = $el.find('.discount');
Line 390... Line 400...
390
		if (!found) {
400
		if (!found) {
391
			priceQtyArray.push(tmpObj);
401
			priceQtyArray.push(tmpObj);
392
		}
402
		}
393
	});
403
	});
394
 
404
 
395
	$("#order-items").find("tr:not(:first-child)").each(function (index, el) {
405
	$("#order-items").find("tr:not(:first-child)").each(function(index, el) {
396
		// console.log(el);
406
		// console.log(el);
397
		// console.log(index);
407
		// console.log(index);
398
		var $serialNumberElement = $(el).find('.serialNumber');
408
		var $serialNumberElement = $(el).find('.serialNumber');
399
		var itemId = parseInt($serialNumberElement.attr("itemId"));
409
		var itemId = parseInt($serialNumberElement.attr("itemId"));
400
		var insuranceEle = $(el).find('.insuranceamount');
410
		var insuranceEle = $(el).find('.insuranceamount');
Line 462... Line 472...
462
	$("div.customerinfo").html(customerInfo);
472
	$("div.customerinfo").html(customerInfo);
463
	$("div.billinginfo").html(billingInfo).hide();
473
	$("div.billinginfo").html(billingInfo).hide();
464
}
474
}
465
 
475
 
466
function writeOldCustomerDetailsByMobileNumber(mobileNumber) {
476
function writeOldCustomerDetailsByMobileNumber(mobileNumber) {
467
	doAjaxRequestHandler(context + "/customer/mobileNumber?mobileNumber=" + mobileNumber, "GET", function (response) {
477
	doAjaxRequestHandler(context + "/customer/mobileNumber?mobileNumber=" + mobileNumber, "GET", function(response) {
468
		if (response.response == '') {
478
		if (response.response == '') {
469
			return;
479
			return;
470
		}
480
		}
471
		var customer = response.response;
481
		var customer = response.response;
472
		if (customer == null) {
482
		if (customer == null) {