| 22245 |
ashik.ali |
1 |
$().ready(function() {
|
|
|
2 |
$("form#cd input").each(function(){
|
|
|
3 |
$(this).attr('autocomplete', 'off');
|
|
|
4 |
});
|
|
|
5 |
});
|
|
|
6 |
$().ready(function() {
|
| 23419 |
ashik.ali |
7 |
// validate the comment form when it is submitted
|
|
|
8 |
$('#cd').validate({
|
| 22245 |
ashik.ali |
9 |
rules:{
|
|
|
10 |
name:{
|
|
|
11 |
required:true
|
|
|
12 |
},
|
|
|
13 |
email:{
|
|
|
14 |
required:true,
|
|
|
15 |
email:true
|
|
|
16 |
},
|
|
|
17 |
line1:{
|
|
|
18 |
required:true
|
|
|
19 |
},
|
|
|
20 |
state:{
|
|
|
21 |
required:true
|
|
|
22 |
},
|
|
|
23 |
city:{
|
|
|
24 |
required:true
|
|
|
25 |
},
|
|
|
26 |
pincode:{
|
|
|
27 |
required:true,
|
|
|
28 |
digits:true,
|
|
|
29 |
minlength: 6,
|
|
|
30 |
maxlength: 6,
|
|
|
31 |
},
|
|
|
32 |
phone:{
|
|
|
33 |
required:true,
|
|
|
34 |
minlength:10,
|
|
|
35 |
maxlength:10,
|
|
|
36 |
digits:true
|
|
|
37 |
},
|
|
|
38 |
},
|
|
|
39 |
messages:{
|
|
|
40 |
name:{
|
|
|
41 |
required:"Please enter the name"
|
|
|
42 |
},
|
|
|
43 |
line1:{
|
|
|
44 |
required:"Please enter the address"
|
|
|
45 |
},
|
|
|
46 |
state:{
|
|
|
47 |
required: "Please select a state"
|
|
|
48 |
},
|
|
|
49 |
city:{
|
|
|
50 |
required: "Please enter the city"
|
|
|
51 |
},
|
|
|
52 |
email:{
|
|
|
53 |
require: "Please enter a valid email address"
|
|
|
54 |
},
|
|
|
55 |
pincode:{
|
|
|
56 |
required: "Please enter the pincode",
|
|
|
57 |
digits:"Please enter a valid pincode"
|
|
|
58 |
},
|
|
|
59 |
phone:{
|
|
|
60 |
required: "Please enter the phone number",
|
|
|
61 |
digits:"Please enter a valid number",
|
|
|
62 |
minlength:"Number should be of 10 digits"
|
|
|
63 |
}
|
|
|
64 |
},
|
|
|
65 |
submitHandler: function (form, event) {
|
|
|
66 |
event.preventDefault();
|
|
|
67 |
var payload = orderDetailsPayload();
|
|
|
68 |
if(!validateOrderDetails()){
|
|
|
69 |
alert("Please fix highlighted errors");
|
|
|
70 |
return false;
|
|
|
71 |
}
|
| 23783 |
ashik.ali |
72 |
doPostAjaxRequestWithJsonHandler(context+"/create-order", payload, function(response){
|
| 23353 |
ashik.ali |
73 |
emptyBag();
|
|
|
74 |
$('#main-content').html(response);
|
|
|
75 |
});
|
|
|
76 |
return false; // required to block normal submit since you used ajax
|
| 22245 |
ashik.ali |
77 |
}
|
|
|
78 |
});
|
|
|
79 |
|
| 23873 |
amit.gupta |
80 |
$("input.unitPrice").change(function() {
|
| 22245 |
ashik.ali |
81 |
var $element = $(this);
|
| 23820 |
amit.gupta |
82 |
var unitPrice = parseFloat($element.val());
|
|
|
83 |
if(!isNaN(unitPrice)) {
|
| 23873 |
amit.gupta |
84 |
var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
|
| 23820 |
amit.gupta |
85 |
var mopPrice = parseFloat($(this).attr('mopPrice'));
|
|
|
86 |
var dp = parseFloat($(this).attr('dp'));
|
| 24052 |
amit.gupta |
87 |
var mrp = parseFloat($(this).attr('mrp'));
|
|
|
88 |
if(mrp != 0 && unitPrice > mrp) {
|
|
|
89 |
alert("Selling Price should not be greater than MRP");
|
|
|
90 |
$element.addClass("border-highlight");
|
|
|
91 |
} else if(!accessoriesDeals && unitPrice < mopPrice){
|
| 23873 |
amit.gupta |
92 |
alert("Selling Price must be greater than equal to MOP");
|
| 23820 |
amit.gupta |
93 |
$element.addClass("border-highlight");
|
| 23873 |
amit.gupta |
94 |
}else if(itemType=='SERIALIZED' && unitPrice < mop){
|
|
|
95 |
alert("Selling Price must be greater than equal to MOP");
|
| 23820 |
amit.gupta |
96 |
$element.addClass("border-highlight");
|
| 23873 |
amit.gupta |
97 |
}else if(itemType=='NON_SERIALIZED' && unitPrice < dp){
|
|
|
98 |
alert("Selling Price must be greater than equal to DP");
|
|
|
99 |
$element.addClass("border-highlight");
|
| 23820 |
amit.gupta |
100 |
}else{
|
|
|
101 |
$element.removeClass("border-highlight")
|
|
|
102 |
if(unitPrice == mopPrice){
|
|
|
103 |
$("input.discountAmount").removeAttr("readonly");
|
|
|
104 |
}
|
| 23353 |
ashik.ali |
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 |
});
|
| 23820 |
amit.gupta |
115 |
}
|
| 22354 |
ashik.ali |
116 |
}
|
| 22245 |
ashik.ali |
117 |
});
|
| 22354 |
ashik.ali |
118 |
|
| 23569 |
govind |
119 |
$( "input.phone").change(function() {
|
| 22354 |
ashik.ali |
120 |
console.log("phone blur called");
|
|
|
121 |
var mobileNumber = $(this).val();
|
| 23405 |
amit.gupta |
122 |
if(mobileNumber.length < 10) {
|
|
|
123 |
return;
|
|
|
124 |
}
|
| 22354 |
ashik.ali |
125 |
writeOldCustomerDetailsByMobileNumber(mobileNumber);
|
| 23419 |
ashik.ali |
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);
|
| 23434 |
ashik.ali |
132 |
calculateTotalAmount();
|
| 23419 |
ashik.ali |
133 |
checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds);
|
| 22354 |
ashik.ali |
134 |
});
|
| 22245 |
ashik.ali |
135 |
|
| 23343 |
ashik.ali |
136 |
});
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
function validateOrderDetails(){
|
|
|
140 |
var sNumbers = [];
|
|
|
141 |
var error = false;
|
|
|
142 |
$("form#cd input.serialNumber").each(function(){
|
|
|
143 |
var input = $(this).val().trim();
|
|
|
144 |
var itemType = $(this).attr("itemType");
|
|
|
145 |
$(this).removeClass("border-highlight");
|
|
|
146 |
if (sNumbers.indexOf(input) !=-1 || (itemType ==='SERIALIZED' && !input)){
|
|
|
147 |
error = true;
|
|
|
148 |
$(this).addClass("border-highlight");
|
|
|
149 |
}
|
|
|
150 |
sNumbers.push(input);
|
|
|
151 |
});
|
|
|
152 |
|
|
|
153 |
$("form#cd input.unitPrice").each(function(){
|
|
|
154 |
var input = $(this).val().trim();
|
|
|
155 |
$(this).removeClass("border-highlight");
|
|
|
156 |
if (!input || parseInt(input)<=0 || isNaN(input)){
|
|
|
157 |
error=true;
|
|
|
158 |
$(this).addClass("border-highlight");
|
|
|
159 |
}
|
|
|
160 |
});
|
|
|
161 |
|
|
|
162 |
// checking input discountAmount is not greater than maxDiscountAmount
|
|
|
163 |
$("form#cd input.discountAmount").each(function(){
|
|
|
164 |
var input = $(this).val().trim();
|
|
|
165 |
var mop = $(this).attr("mop");
|
|
|
166 |
|
|
|
167 |
if(mop){
|
|
|
168 |
var maxDiscountPriceRangeString = $(this).attr("placeholder");
|
|
|
169 |
var maxDiscountPrice = 0;
|
|
|
170 |
if(maxDiscountPriceRangeString != undefined && maxDiscountPriceRangeString != ''){
|
|
|
171 |
maxDiscountPrice = maxDiscountPriceRangeString.substring(6);
|
|
|
172 |
}
|
|
|
173 |
$(this).removeClass("border-highlight");
|
|
|
174 |
if (!input || parseFloat(input)<0 || isNaN(input)){
|
|
|
175 |
alert("DiscountAmount value can not be lesser than 0 or invalid value");
|
|
|
176 |
error=true;
|
|
|
177 |
$(this).addClass("border-highlight");
|
|
|
178 |
}
|
|
|
179 |
if(parseFloat(input) > maxDiscountPrice){
|
|
|
180 |
alert("DiscountAmount [" + parseFloat(input) + "] value can not be greater than the suggested maxDiscountPrice [" + maxDiscountPrice + "]");
|
|
|
181 |
error=true;
|
|
|
182 |
$(this).addClass("border-highlight");
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
});
|
|
|
186 |
|
| 23370 |
ashik.ali |
187 |
var gstNumber = $("form#cd input[name=gstNumber]").val();
|
|
|
188 |
$("form#cd input[name=gstNumber]").removeClass("border-highlight");
|
|
|
189 |
if(gstNumber.length > 0 && gstNumber.length != 15){
|
|
|
190 |
alert("Please provide valid gstNumber");
|
|
|
191 |
error = true;
|
|
|
192 |
$("form#cd input[name=gstNumber]").addClass("border-highlight");
|
|
|
193 |
}
|
|
|
194 |
|
| 23440 |
ashik.ali |
195 |
/*if(localStorage.getItem('otpVerified') == null || localStorage.getItem('otpVerified') == "false"){
|
| 23434 |
ashik.ali |
196 |
alert("Please verify prebooking orders otp");
|
|
|
197 |
error = true;
|
| 23440 |
ashik.ali |
198 |
}*/
|
| 23434 |
ashik.ali |
199 |
|
| 23343 |
ashik.ali |
200 |
var amount = 0;
|
|
|
201 |
var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
|
| 23434 |
ashik.ali |
202 |
var totalAdvanceAmount = parseFloat($("form#cd input.totalAdvanceAmount").val());
|
| 23343 |
ashik.ali |
203 |
|
| 23434 |
ashik.ali |
204 |
netPayableAmount = netPayableAmount - totalAdvanceAmount;
|
| 23343 |
ashik.ali |
205 |
|
|
|
206 |
$("form#cd input.amount").each(function(){
|
|
|
207 |
if ($(this).val() == ""){
|
|
|
208 |
$(this).val(0);
|
|
|
209 |
}
|
|
|
210 |
var tmpAmount = parseFloat($(this).val());
|
|
|
211 |
amount = amount + tmpAmount;
|
|
|
212 |
});
|
|
|
213 |
|
|
|
214 |
console.log(amount);
|
|
|
215 |
console.log(netPayableAmount);
|
|
|
216 |
|
|
|
217 |
if (amount != netPayableAmount){
|
|
|
218 |
if(amount < netPayableAmount){
|
|
|
219 |
alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
|
|
|
220 |
}else{
|
|
|
221 |
alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
|
|
|
222 |
}
|
|
|
223 |
$("form#cd input.netPayableAmount").each(function(){
|
|
|
224 |
$(this).addClass("border-highlight");
|
|
|
225 |
});
|
|
|
226 |
error = true;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
if (error){
|
|
|
230 |
return false;
|
|
|
231 |
}
|
|
|
232 |
return true;
|
|
|
233 |
|
| 23347 |
ashik.ali |
234 |
}
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
function getSerialNumbersFromOrder($el){
|
|
|
238 |
var $serialNumberElement = $el.find('.serialNumber');
|
|
|
239 |
if($serialNumberElement.val() == ''){
|
|
|
240 |
return null;
|
|
|
241 |
}
|
|
|
242 |
var insuranceAmount = parseFloat($el.find('.insuranceAmount').val());
|
|
|
243 |
if(insuranceAmount > 0){
|
|
|
244 |
insurance = true;
|
|
|
245 |
globalInsurace = true;
|
|
|
246 |
}else{
|
|
|
247 |
insurance = false;
|
|
|
248 |
}
|
|
|
249 |
return {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
function orderDetailsPayload(){
|
| 23419 |
ashik.ali |
253 |
var orderObj = {};
|
|
|
254 |
var priceQtyArray = [];
|
|
|
255 |
var customerObj = {};
|
|
|
256 |
var paymentOptionIdAmount = [];
|
|
|
257 |
var globalInsurance = false;
|
|
|
258 |
|
|
|
259 |
$("form#cd input.serialNumber").each(function(){
|
|
|
260 |
var itemId = parseInt($(this).attr("itemId"));
|
|
|
261 |
if (orderObj.hasOwnProperty('fofoOrderItems')){
|
|
|
262 |
var itemDetails = orderObj['fofoOrderItems'];
|
|
|
263 |
if (itemDetails.hasOwnProperty(itemId)){
|
|
|
264 |
var serialNumbers = itemDetails[itemId];
|
|
|
265 |
serialNumbers.push($(this).val());
|
|
|
266 |
itemDetails[itemId] = serialNumbers;
|
| 23347 |
ashik.ali |
267 |
}else{
|
|
|
268 |
var serialNumbers = [];
|
|
|
269 |
serialNumbers.push($(this).val());
|
| 23419 |
ashik.ali |
270 |
itemDetails[itemId] = serialNumbers;
|
| 23347 |
ashik.ali |
271 |
}
|
| 23419 |
ashik.ali |
272 |
}else{
|
|
|
273 |
var serialNumbers = [];
|
|
|
274 |
serialNumbers.push($(this).val());
|
|
|
275 |
var tmp ={};
|
|
|
276 |
tmp[itemId] = serialNumbers;
|
|
|
277 |
orderObj['fofoOrderItems'] = tmp;
|
|
|
278 |
}
|
|
|
279 |
});
|
|
|
280 |
console.log( JSON.stringify(orderObj));
|
|
|
281 |
$("#order-details").find("tr:not(:first-child)").each(function(index, el){
|
|
|
282 |
//console.log(el);
|
|
|
283 |
//console.log(index);
|
|
|
284 |
var $el = $(el);
|
|
|
285 |
var $unitPriceElement = $el.find('.unitPrice');
|
|
|
286 |
var $discountAmountElement = $el.find('.discountAmount');
|
| 23347 |
ashik.ali |
287 |
|
| 23419 |
ashik.ali |
288 |
var itemId = parseInt($unitPriceElement.attr("itemId"));
|
|
|
289 |
var unitPrice = parseFloat($unitPriceElement.val());
|
|
|
290 |
var qty = parseInt($unitPriceElement.attr("quantity"));
|
|
|
291 |
var discountAmount = parseFloat($discountAmountElement.val());
|
|
|
292 |
var mop = $discountAmountElement.attr("mop");
|
| 23434 |
ashik.ali |
293 |
var prebookingOrder = false;
|
|
|
294 |
$('.prebooking-order-details').each(function(){
|
|
|
295 |
if($(this).find('.useAdvanceAmount').is(':checked')){
|
|
|
296 |
var prebookingOrderItemId = parseInt($(this).find('.prebooking-item-id').text());
|
|
|
297 |
if(prebookingOrderItemId == itemId){
|
|
|
298 |
prebookingOrder = true;
|
|
|
299 |
}
|
|
|
300 |
}
|
|
|
301 |
});
|
|
|
302 |
|
|
|
303 |
var tmpObj = {'itemId':itemId,'sellingPrice':unitPrice,'quantity':qty, 'prebookingOrder':prebookingOrder};
|
| 23419 |
ashik.ali |
304 |
tmpObj.discountAmount = discountAmount;
|
| 23873 |
amit.gupta |
305 |
|
| 23419 |
ashik.ali |
306 |
if (orderObj['fofoOrderItems'][itemId] === undefined){
|
|
|
307 |
tmpObj['serialNumberDetails'] =[];
|
|
|
308 |
}else{
|
|
|
309 |
//tmpObj['serialNumbers'] = orderObj['fofoLineItems'][itemId];
|
|
|
310 |
tmpObj['serialNumberDetails'] = [];
|
|
|
311 |
}
|
|
|
312 |
var found = false;
|
|
|
313 |
for(var i = 0; i < priceQtyArray.length; i++){
|
|
|
314 |
if (priceQtyArray[i]["itemId"] == itemId){
|
|
|
315 |
priceQtyArray[i]["quantity"] = priceQtyArray[i]["quantity"] + 1;
|
|
|
316 |
found = true;
|
|
|
317 |
break;
|
| 23347 |
ashik.ali |
318 |
}
|
| 23419 |
ashik.ali |
319 |
}
|
|
|
320 |
if(!found){
|
|
|
321 |
priceQtyArray.push(tmpObj);
|
|
|
322 |
}
|
|
|
323 |
});
|
| 23347 |
ashik.ali |
324 |
|
| 23419 |
ashik.ali |
325 |
$("#order-details").find("tr:not(:first-child)").each(function(index,el){
|
|
|
326 |
//console.log(el);
|
|
|
327 |
//console.log(index);
|
|
|
328 |
var $serialNumberElement = $(el).find('.serialNumber');
|
|
|
329 |
var itemId = parseInt($serialNumberElement.attr("itemId"));
|
|
|
330 |
var insuranceAmount = parseFloat($(el).find('.insuranceAmount').val());
|
|
|
331 |
//if (priceQtyArray['fofoLineItems'][itemId] !=undefined){
|
|
|
332 |
|
|
|
333 |
//}
|
|
|
334 |
//console.log($serialNumberElement.val());
|
|
|
335 |
//console.log(itemId);
|
|
|
336 |
for(var i = 0; i < priceQtyArray.length; i++){
|
|
|
337 |
console.log(priceQtyArray[i]["itemId"]);
|
|
|
338 |
if (priceQtyArray[i]["itemId"] == itemId){
|
|
|
339 |
if(insuranceAmount > 0){
|
|
|
340 |
insurance = true;
|
|
|
341 |
globalInsurance = true;
|
|
|
342 |
}else{
|
|
|
343 |
insurance = false;
|
| 23347 |
ashik.ali |
344 |
}
|
| 23419 |
ashik.ali |
345 |
var serialNumberDetails = {'serialNumber':$serialNumberElement.val(),'insurance':insurance,'amount':insuranceAmount}
|
|
|
346 |
priceQtyArray[i]['serialNumberDetails'].push(serialNumberDetails);
|
| 23353 |
ashik.ali |
347 |
}
|
| 23419 |
ashik.ali |
348 |
}
|
|
|
349 |
});
|
|
|
350 |
|
|
|
351 |
console.log("priceQtyArray : "+JSON.stringify(priceQtyArray));
|
|
|
352 |
customerObj['firstName'] = $("form#cd input[name=firstName]").val();
|
|
|
353 |
customerObj['lastName'] = $("form#cd input[name=lastName]").val();
|
|
|
354 |
customerObj['mobileNumber'] = $("form#cd input[name=phone]").val();
|
|
|
355 |
customerObj['emailId'] = $("form#cd input[name=email]").val();
|
|
|
356 |
customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
|
| 23888 |
amit.gupta |
357 |
//customerObj['dateOfBirth'] = startDate;
|
| 23419 |
ashik.ali |
358 |
var customerAddress = {};
|
|
|
359 |
customerAddress['name'] = $("form#cd input[name=firstName]").val() + " " + $("form#cd input[name=lastName]").val();
|
|
|
360 |
customerAddress['line1'] = $("form#cd input[name=line1]").val();
|
|
|
361 |
customerAddress['line2'] = $("form#cd input[name=line2]").val();
|
|
|
362 |
customerAddress['landmark'] = $("form#cd input[name=landmark]").val();
|
|
|
363 |
customerAddress['city'] = $("form#cd input[name=city]").val();
|
|
|
364 |
customerAddress['state'] = $('select[name=state] option:selected').val();
|
|
|
365 |
customerAddress['pinCode'] = $("form#cd input[name=pinCode]").val();
|
|
|
366 |
customerAddress['phoneNumber'] = $("form#cd input[name=alternatePhone]").val();
|
|
|
367 |
customerAddress['country'] = "India";
|
|
|
368 |
customerObj['customerAddressId'] = parseInt($("form#cd input[name=phone]").attr("addressId"));
|
|
|
369 |
customerObj['address'] = customerAddress;
|
|
|
370 |
console.log( JSON.stringify(customerObj));
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
|
|
|
374 |
//console.log("paymentOptionSize = "+paymentOptionSize);
|
|
|
375 |
for(var index = 0; index < paymentOptionSize; index++){
|
|
|
376 |
var paymentOptionAmount = 0.0;
|
|
|
377 |
if($('#paymentOptionIdAmount'+index).val() != ""){
|
|
|
378 |
paymentOptionAmount = parseFloat($('#paymentOptionIdAmount'+index).val());
|
| 23367 |
ashik.ali |
379 |
}
|
| 23419 |
ashik.ali |
380 |
var paymentOptionId = $('#paymentOptionIdAmount'+index).attr("paymentOptionId");
|
|
|
381 |
var paymentOptionIdAmountObject = {};
|
|
|
382 |
paymentOptionIdAmountObject['paymentOptionId'] = paymentOptionId;
|
|
|
383 |
paymentOptionIdAmountObject['amount'] = paymentOptionAmount;
|
|
|
384 |
paymentOptionIdAmount.push(paymentOptionIdAmountObject);
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
console.log( JSON.stringify(paymentOptionIdAmount));
|
|
|
388 |
|
|
|
389 |
var retObj = {};
|
|
|
390 |
if(globalInsurance){
|
| 23888 |
amit.gupta |
391 |
retObj['customerDateOfBirth'] = startDate;
|
| 23419 |
ashik.ali |
392 |
}
|
|
|
393 |
|
|
|
394 |
retObj['fofoOrderItems'] = (priceQtyArray);
|
|
|
395 |
retObj['customer'] = (customerObj);
|
|
|
396 |
retObj['paymentOptions'] = (paymentOptionIdAmount);
|
|
|
397 |
|
|
|
398 |
console.log(retObj);
|
|
|
399 |
return JSON.stringify(retObj);
|
| 23347 |
ashik.ali |
400 |
}
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
function writeOldCustomerDetailsByMobileNumber(mobileNumber){
|
| 23353 |
ashik.ali |
404 |
doAjaxRequestHandler(context+"/customer/mobileNumber?mobileNumber="+mobileNumber, "GET", function(response){
|
|
|
405 |
var customer = response.response;
|
|
|
406 |
$('#firstName').attr('value', customer.firstName);
|
|
|
407 |
$('#lastName').attr('value', customer.lastName);
|
|
|
408 |
$('#email').attr('value', customer.emailId);
|
|
|
409 |
//$('#phone').attr('value', customer.mobileNumber);
|
| 23443 |
amit.gupta |
410 |
if(customer.address !== null) {
|
|
|
411 |
$('#alternatePhone').attr('value', customer.address.phoneNumber);
|
|
|
412 |
$('#line1').attr('value', customer.address.line1);
|
|
|
413 |
$('#line2').attr('value', customer.address.line2);
|
|
|
414 |
$('#landmark').attr('value', customer.address.landmark);
|
|
|
415 |
$('#pinCode').attr('value', customer.address.pinCode);
|
|
|
416 |
$('#city').attr('value', customer.address.city);
|
|
|
417 |
$('#state').attr('value', customer.address.state).prop('selected',true);
|
|
|
418 |
$('#phone').attr('addressId', customer.address.id);
|
|
|
419 |
}
|
| 23353 |
ashik.ali |
420 |
//$('#state').val(customer.address.state).prop('selected', true);
|
|
|
421 |
});
|
| 23419 |
ashik.ali |
422 |
}
|
|
|
423 |
|
|
|
424 |
$(document).on('change', '.prebooking-order-details', function(){
|
|
|
425 |
|
|
|
426 |
var itemIdQuantityMap = {};
|
|
|
427 |
$("#order-details").find("tr:not(:first-child)").each(function(index, el){
|
|
|
428 |
//console.log(el);
|
|
|
429 |
//console.log(index);
|
|
|
430 |
var $el = $(el);
|
|
|
431 |
var $unitPriceElement = $el.find('.unitPrice');
|
|
|
432 |
|
|
|
433 |
var itemId = parseInt($unitPriceElement.attr("itemId"));
|
|
|
434 |
var qty = parseInt($unitPriceElement.attr("quantity"));
|
|
|
435 |
if(itemIdQuantityMap[itemId] == null){
|
|
|
436 |
itemIdQuantityMap[itemId] = qty;
|
|
|
437 |
}else{
|
|
|
438 |
itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
});
|
|
|
442 |
|
|
|
443 |
console.log(itemIdQuantityMap);
|
|
|
444 |
|
|
|
445 |
console.log("use advance amount clicked");
|
|
|
446 |
if ($('.useAdvanceAmount').is(':checked')) {
|
|
|
447 |
//$(this).val('true');
|
| 23434 |
ashik.ali |
448 |
if(localStorage.getItem('otpVerified') != null && localStorage.getItem("otpVerified") == true){
|
|
|
449 |
$('#customer-otp-details').html('');
|
|
|
450 |
}else{
|
|
|
451 |
var customerOtpDetailsDiv='<div class="row">'
|
|
|
452 |
+'<div class="col-lg-2 form-group">'
|
|
|
453 |
+'<button class="btn btn-primary" id="generate-otp-button" onclick="generateOtp()" type="button">Generate Otp</button>'
|
|
|
454 |
+'</div>'
|
|
|
455 |
+'<div class="col-lg-2 form-group">'
|
|
|
456 |
+'<input placeholder = "OTP" id="otpValue" name="otpValue" type="text" class="form-control input-sm">'
|
|
|
457 |
+'</div>'
|
|
|
458 |
+'<div class="col-lg-2 form-group">'
|
|
|
459 |
+'<button class="btn btn-primary" id="validate-otp-button" onclick="validateOtp()" type="button">Validate Otp</button>'
|
|
|
460 |
+'</div>';
|
|
|
461 |
+'</div>';
|
|
|
462 |
$('#customer-otp-details').html(customerOtpDetailsDiv);
|
|
|
463 |
}
|
| 23419 |
ashik.ali |
464 |
}else{
|
|
|
465 |
//$(this).val('false');
|
|
|
466 |
$('#customer-otp-details').html('');
|
|
|
467 |
}
|
|
|
468 |
if($(this).find('.useAdvanceAmount').is(':checked')){
|
|
|
469 |
$(this).find('.useAdvanceAmount').val('true');
|
|
|
470 |
var advanceAmount = $(this).find('.prebooking-advance-amount').text();
|
|
|
471 |
console.log("- advanceAmount : "+advanceAmount);
|
|
|
472 |
var quantity = $(this).find('.prebooking-available-quantity').text();
|
|
|
473 |
console.log("available quantity : "+quantity);
|
|
|
474 |
var itemId = parseInt($(this).find('.prebooking-item-id').text());
|
|
|
475 |
console.log("itemId : "+itemId);
|
|
|
476 |
var prebookingAmount = 0.0;
|
|
|
477 |
if(itemIdQuantityMap[itemId] < parseInt(quantity)){
|
|
|
478 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
|
|
|
479 |
}else{
|
|
|
480 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
|
|
|
481 |
}
|
|
|
482 |
console.log("prebookingAmount : "+prebookingAmount);
|
| 23434 |
ashik.ali |
483 |
|
|
|
484 |
|
|
|
485 |
//calculateTotalAmount();
|
|
|
486 |
//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
|
|
|
487 |
//console.log("netPayableAmount : "+netPayableAmount);
|
|
|
488 |
//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) - prebookingAmount);
|
|
|
489 |
$('#cd').find('input.totalAdvanceAmount').val(prebookingAmount);
|
| 23419 |
ashik.ali |
490 |
}else if(!$(this).find('.useAdvanceAmount').is(':checked')){
|
|
|
491 |
$(this).find('.useAdvanceAmount').val('false');
|
|
|
492 |
var advanceAmount = $(this).find('.prebooking-advance-amount').text();
|
|
|
493 |
console.log("+ advanceAmount : "+advanceAmount);
|
|
|
494 |
var quantity = $(this).find('.prebooking-available-quantity').text();
|
|
|
495 |
console.log("available quantity : "+quantity);
|
|
|
496 |
var itemId = parseInt($(this).find('.prebooking-item-id').text());
|
|
|
497 |
console.log("itemId : "+itemId);
|
|
|
498 |
var prebookingAmount = 0.0;
|
|
|
499 |
if(itemIdQuantityMap[itemId] < parseInt(quantity)){
|
|
|
500 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
|
|
|
501 |
console.log("used quantity : "+itemIdQuantityMap[itemId]);
|
|
|
502 |
}else{
|
|
|
503 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
|
|
|
504 |
console.log("used quantity : "+quantity);
|
|
|
505 |
}
|
|
|
506 |
console.log("prebookingAmount : "+prebookingAmount);
|
| 23434 |
ashik.ali |
507 |
//calculateTotalAmount();
|
|
|
508 |
//var netPayableAmount = $('#cd').find('input.netPayableAmount').val();
|
|
|
509 |
//console.log("netPayableAmount : "+netPayableAmount);
|
|
|
510 |
//$('#cd').find('input.netPayableAmount').val(parseFloat(netPayableAmount) + prebookingAmount);
|
|
|
511 |
var totalAdvanceAmount = $('#cd').find('input.totalAdvanceAmount').val();
|
|
|
512 |
$('#cd').find('input.totalAdvanceAmount').val(parseFloat(totalAdvanceAmount) - prebookingAmount);
|
| 23419 |
ashik.ali |
513 |
}
|
|
|
514 |
});
|
|
|
515 |
|
|
|
516 |
/*$(document).on('change', '.useAdvanceAmount', function() {
|
|
|
517 |
if($(this).is(':checked')){
|
|
|
518 |
$(this).val('true');
|
|
|
519 |
}else{
|
|
|
520 |
$(this).val('false');
|
|
|
521 |
}
|
|
|
522 |
});*/
|
|
|
523 |
|
|
|
524 |
function generateOtp(){
|
|
|
525 |
console.log("generate Otp button clicked")
|
|
|
526 |
var itemIdQuantityMap = {};
|
|
|
527 |
$("#order-details").find("tr:not(:first-child)").each(function(index, el){
|
|
|
528 |
//console.log(el);
|
|
|
529 |
//console.log(index);
|
|
|
530 |
var $el = $(el);
|
|
|
531 |
var $unitPriceElement = $el.find('.unitPrice');
|
|
|
532 |
|
|
|
533 |
var itemId = parseInt($unitPriceElement.attr("itemId"));
|
|
|
534 |
var qty = parseInt($unitPriceElement.attr("quantity"));
|
|
|
535 |
if(itemIdQuantityMap[itemId] == null){
|
|
|
536 |
itemIdQuantityMap[itemId] = qty;
|
|
|
537 |
}else{
|
|
|
538 |
itemIdQuantityMap[itemId] = itemIdQuantityMap[itemId] + qty;
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
});
|
|
|
542 |
|
|
|
543 |
//console.log(itemIdQuantityMap);
|
|
|
544 |
var itemIdAdvanceAmountMap = {};
|
|
|
545 |
$('.prebooking-order-details').each(function(){
|
|
|
546 |
if($(this).find('.useAdvanceAmount').is(':checked')){
|
|
|
547 |
var advanceAmount = $(this).find('.prebooking-advance-amount').text();
|
|
|
548 |
//console.log("- advanceAmount : "+advanceAmount);
|
|
|
549 |
var quantity = $(this).find('.prebooking-available-quantity').text();
|
|
|
550 |
//console.log("available quantity : "+quantity);
|
|
|
551 |
var itemId = parseInt($(this).find('.prebooking-item-id').text());
|
|
|
552 |
//console.log("itemId : "+itemId);
|
|
|
553 |
var prebookingAmount = 0.0;
|
|
|
554 |
if(itemIdQuantityMap[itemId] < parseInt(quantity)){
|
|
|
555 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(itemIdQuantityMap[itemId]);
|
|
|
556 |
}else{
|
|
|
557 |
prebookingAmount = parseFloat(advanceAmount) * parseFloat(quantity);
|
|
|
558 |
}
|
|
|
559 |
itemIdAdvanceAmountMap[itemId] = prebookingAmount;
|
|
|
560 |
}
|
|
|
561 |
});
|
|
|
562 |
console.log(itemIdAdvanceAmountMap);
|
|
|
563 |
var mobileNumber = $("form#cd input[name=phone]").val();
|
|
|
564 |
var emailId = $("form#cd input[name=email]").val();
|
|
|
565 |
var url = context+'/generateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId;
|
|
|
566 |
doAjaxRequestWithJsonHandler(url, "POST", JSON.stringify(itemIdAdvanceAmountMap), function(response){
|
|
|
567 |
console.log("generate Otp response : "+JSON.stringify(response));
|
| 23434 |
ashik.ali |
568 |
alert("OTP has been generated successfully, Please verify OTP for further process");
|
| 23419 |
ashik.ali |
569 |
var otpId = parseInt(response.response);
|
|
|
570 |
localStorage.setItem("otpId", otpId);
|
|
|
571 |
localStorage.setItem("otpVerified", false);
|
|
|
572 |
});
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
function validateOtp(){
|
|
|
576 |
console.log("validateOtp button click");
|
|
|
577 |
var mobileNumber = $("form#cd input[name=phone]").val();
|
|
|
578 |
var emailId = $("form#cd input[name=email]").val();
|
|
|
579 |
var otpId = parseInt(localStorage.getItem('otpId'));
|
|
|
580 |
var otpValue = $('#otpValue').val();
|
|
|
581 |
if(otpId == null || otpValue == ""){
|
|
|
582 |
alert("Please enter otpValue");
|
|
|
583 |
}else{
|
|
|
584 |
var url = context+'/validateOtp?customerMobileNumber='+mobileNumber+'&customerEmailId='+emailId+'&otpId='+otpId+'&otpValue='+otpValue;
|
|
|
585 |
doAjaxRequestHandler(url, "GET", function(response){
|
|
|
586 |
alert(response.response);
|
|
|
587 |
localStorage.removeItem("otpId");
|
| 23434 |
ashik.ali |
588 |
$('#customer-otp-details').html('');
|
|
|
589 |
//$('#generate-otp-button').prop("disabled", true);
|
|
|
590 |
//$('#otpValue').prop("disabled", true);
|
|
|
591 |
//$('#validate-otp-button').prop("disabled", true);
|
| 23419 |
ashik.ali |
592 |
localStorage.setItem("otpVerified", true);
|
|
|
593 |
});
|
|
|
594 |
}
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
|
|
|
598 |
function checkPrebookingOrdersByCustomerMobileNumber(mobileNumber, itemIds){
|
|
|
599 |
//window.dispatchEvent(new Event('resize'));
|
|
|
600 |
|
|
|
601 |
doAjaxRequestWithJsonHandler(context+"/getPrebookingOrdersByCustomerMobileNumber?customerMobileNumber="+mobileNumber, "POST", JSON.stringify(itemIds), function(response){
|
|
|
602 |
$('#prebooking-order-details').html(response);
|
|
|
603 |
});
|
| 23343 |
ashik.ali |
604 |
}
|