Subversion Repositories SmartDukaan

Rev

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

Rev 35232 Rev 35458
Line 1... Line 1...
1
var customerId;
1
var customerId;
-
 
2
var customerInfo;
-
 
3
var billingInfo;
-
 
4
var selectedAddressId;
2
 
5
 
3
function formLoaded() {
6
function formLoaded() {
4
    $("form#cd input").each(function () {
7
    $("form#cd input").each(function () {
5
        $(this).attr('autocomplete', 'off');
8
        $(this).attr('autocomplete', 'off');
6
    });
9
    });
Line 158... Line 161...
158
            var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
161
            var itemType = parseFloat($(this).closest('tr').find('.serialNumber').attr("itemType"));
159
            var mopPrice = parseFloat($(this).attr('mopPrice'));
162
            var mopPrice = parseFloat($(this).attr('mopPrice'));
160
            var isMop = JSON.parse($(this).attr('isMop'));
163
            var isMop = JSON.parse($(this).attr('isMop'));
161
            var dp = parseFloat($(this).attr('dp'));
164
            var dp = parseFloat($(this).attr('dp'));
162
            var mrp = parseFloat($(this).attr('mrp'));
165
            var mrp = parseFloat($(this).attr('mrp'));
163
            if (mrp != 0 && unitPrice > mrp) {
166
            if (mrp !== 0 && unitPrice > mrp) {
164
                alert("Selling Price should not be greater than MRP");
167
                alert("Selling Price should not be greater than MRP");
165
                $element.addClass("border-highlight");
168
                $element.addClass("border-highlight");
166
            } else if (!accessoriesDeals && unitPrice < mopPrice) {
169
            } else if (!accessoriesDeals && unitPrice < mopPrice) {
167
                alert("Selling Price must be greater than equal to MOP");
170
                alert("Selling Price must be greater than equal to MOP");
168
                $element.addClass("border-highlight");
171
                $element.addClass("border-highlight");
169
            } else if (itemType == 'SERIALIZED' && unitPrice < mopPrice) {
172
            } else if (itemType === 'SERIALIZED' && unitPrice < mopPrice) {
170
                if (isMop) {
173
                if (isMop) {
171
                    alert("Selling Price must be greater than equal to MOP");
174
                    alert("Selling Price must be greater than equal to MOP");
172
                    $element.addClass("border-highlight");
175
                    $element.addClass("border-highlight");
173
                }
176
                }
174
            } else if (itemType == 'NON_SERIALIZED' && unitPrice < dp) {
177
            } else if (itemType === 'NON_SERIALIZED' && unitPrice < dp) {
175
                alert("Selling Price must be greater than equal to DP");
178
                alert("Selling Price must be greater than equal to DP");
176
                $element.addClass("border-highlight");
179
                $element.addClass("border-highlight");
177
            } else {
180
            } else {
178
                $element.removeClass("border-highlight");
181
                $element.removeClass("border-highlight");
179
            }
182
            }
Line 215... Line 218...
215
            alert("Invalid email id");
218
            alert("Invalid email id");
216
        }
219
        }
217
 
220
 
218
    });
221
    });
219
    $(document).on('click', 'button.mk_add_customer', function () {
222
    $(document).on('click', 'button.mk_add_customer', function () {
220
        customerObj = {}
223
        var customerObj = {};
221
        if ($("input.firstName").val().length == 0) {
224
        if ($("input.firstName").val().length === 0) {
222
            alert("First Name is required");
225
            alert("First Name is required");
223
            return false;
226
            return false;
224
        }
227
        }
225
        customerObj['firstName'] = $("input.firstName").val();
228
        customerObj['firstName'] = $("input.firstName").val();
226
        customerObj['lastName'] = $("input.lastName").val();
229
        customerObj['lastName'] = $("input.lastName").val();
227
        customerObj['emailId'] = $("#emailId").val();
230
        customerObj['emailId'] = $("#emailId").val();
228
 
-
 
229
        console.log(customerObj['emailId']);
-
 
230
        customerObj['mobileNumber'] = $("input.phone").val();
231
        customerObj['mobileNumber'] = $("input.phone").val();
231
 
232
 
232
        if (customerObj['emailId']) {
233
        if (customerObj['emailId']) {
233
            if (!validateEmail(customerObj['emailId'])) {
234
            if (!validateEmail(customerObj['emailId'])) {
234
                alert("Invalid email id");
235
                alert("Invalid email id");
Line 289... Line 290...
289
        }
290
        }
290
    });
291
    });
291
 
292
 
292
    var gstNumber = $("form#cd input[name=gstNumber]").val();
293
    var gstNumber = $("form#cd input[name=gstNumber]").val();
293
    $("form#cd input[name=gstNumber]").removeClass("border-highlight");
294
    $("form#cd input[name=gstNumber]").removeClass("border-highlight");
294
    if (gstNumber.length > 0 && gstNumber.length != 15) {
295
    if (gstNumber.length > 0 && gstNumber.length !== 15) {
295
        alert("Please provide valid gstNumber");
296
        alert("Please provide valid gstNumber");
296
        error = true;
297
        error = true;
297
        $("form#cd input[name=gstNumber]").addClass("border-highlight");
298
        $("form#cd input[name=gstNumber]").addClass("border-highlight");
298
    }
299
    }
299
 
300
 
300
    var amount = 0;
301
    var amount = 0;
301
    var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
302
    var netPayableAmount = parseFloat($("form#cd input.netPayableAmount").val());
302
    $("form#cd input.amount").each(function () {
303
    $("form#cd input.amount").each(function () {
303
        if ($(this).val() == "") {
304
        if ($(this).val() === "") {
304
            $(this).val(0);
305
            $(this).val(0);
305
        }
306
        }
306
        var tmpAmount = parseFloat($(this).val());
307
        var tmpAmount = parseFloat($(this).val());
307
        amount = amount + tmpAmount;
308
        amount = amount + tmpAmount;
308
    });
309
    });
309
 
310
 
310
    console.log(amount);
-
 
311
    console.log(netPayableAmount);
-
 
312
 
-
 
313
    if (amount != netPayableAmount) {
311
    if (amount !== netPayableAmount) {
314
        if (amount < netPayableAmount) {
312
        if (amount < netPayableAmount) {
315
            alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
313
            alert("[" + (netPayableAmount - amount) + "] is more required to complete the payment");
316
        } else {
314
        } else {
317
            alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
315
            alert("[" + (amount - netPayableAmount) + "] is extra amount, please reduce the amount");
318
        }
316
        }
Line 330... Line 328...
330
}
328
}
331
 
329
 
332
 
330
 
333
function getSerialNumbersFromOrder($el) {
331
function getSerialNumbersFromOrder($el) {
334
    var $serialNumberElement = $el.find('.serialNumber');
332
    var $serialNumberElement = $el.find('.serialNumber');
335
    if ($serialNumberElement.val() == '') {
333
    if ($serialNumberElement.val() === '') {
336
        return null;
334
        return null;
337
    }
335
    }
338
    var insuranceAmount = parseFloat($el.find('.insuranceamount').val());
336
    var insuranceAmount = parseFloat($el.find('.insuranceamount').val());
339
    if (insuranceAmount > 0) {
337
    var hasInsurance = insuranceAmount > 0;
340
        insurance = true;
-
 
341
        globalInsurace = true;
-
 
342
    } else {
-
 
343
        insurance = false;
-
 
344
    }
-
 
345
    return {'serialNumber': $serialNumberElement.val(), 'insurance': insurance, 'amount': insuranceAmount}
338
    return {'serialNumber': $serialNumberElement.val(), 'insurance': hasInsurance, 'amount': insuranceAmount};
346
}
339
}
347
 
340
 
348
function orderDetailsPayload() {
341
function orderDetailsPayload() {
349
    var priceQtyArray = [];
342
    var priceQtyArray = [];
350
    var customerObj = {};
343
    var customerObj = {};
351
    var paymentOptionIdAmount = [];
344
    var paymentOptionIdAmount = [];
352
    var globalInsurance = false;
345
    var globalInsurance = false;
353
 
346
 
354
    $("#order-items").find("tr:not(:first-child)").each(function (index, el) {
347
    $("#order-items").find("tr:not(:first-child)").each(function (index, el) {
355
        console.log("el------------", el);
-
 
356
            // console.log(index);
-
 
357
            var $el = $(el);
348
            var $el = $(el);
358
            var $customerOfferItemId = $el.find('.offerSelect');
349
            var $customerOfferItemId = $el.find('.offerSelect');
359
            var $unitPriceElement = $el.find('.unitPrice');
350
            var $unitPriceElement = $el.find('.unitPrice');
360
            var itemId = parseInt($unitPriceElement.attr("itemId"));
351
            var itemId = parseInt($unitPriceElement.attr("itemId"));
361
            var qty = parseInt($unitPriceElement.attr("quantity"));
352
            var qty = parseInt($unitPriceElement.attr("quantity"));
Line 463... Line 454...
463
    )
454
    )
464
    ;
455
    ;
465
 
456
 
466
 
457
 
467
    customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
458
    customerObj['gstNumber'] = $("form#cd input[name=gstNumber]").val();
468
    if (customerId == undefined) {
459
    if (customerId === undefined) {
469
        alert("Please choose customer");
460
        alert("Please choose customer");
470
        return false;
461
        return false;
471
    }
462
    }
472
    if ($("#customer-address").data("addressselected") == "true") {
463
    if ($("#customer-address").data("addressselected") === "true") {
473
        alert("Please select address");
464
        alert("Please select address");
474
        return false;
465
        return false;
475
    }
466
    }
476
    customerObj['customerId'] = customerId;
467
    customerObj['customerId'] = customerId;
477
// Check if selectedAddressId is defined and not empty
468
// Check if selectedAddressId is defined and not empty
Line 484... Line 475...
484
    customerObj['gender'] = $("#gender").val();
475
    customerObj['gender'] = $("#gender").val();
485
    customerObj['dateOfBirth'] = getDatesFromPicker("#dateOfBirth").startDate;
476
    customerObj['dateOfBirth'] = getDatesFromPicker("#dateOfBirth").startDate;
486
 
477
 
487
 
478
 
488
    var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
479
    var paymentOptionSize = parseInt($('#payment-option-id-amount-container').attr("paymentOptionSize"));
489
// console.log("paymentOptionSize = "+paymentOptionSize);
-
 
490
    for (var index = 0; index < paymentOptionSize; index++) {
480
    for (var index = 0; index < paymentOptionSize; index++) {
491
        var paymentOptionAmount = 0.0;
481
        var paymentOptionAmount = 0.0;
492
        if ($('#paymentOptionIdAmount' + index).val() != "") {
482
        if ($('#paymentOptionIdAmount' + index).val() !== "") {
493
            paymentOptionAmount = parseFloat($('#paymentOptionIdAmount' + index).val());
483
            paymentOptionAmount = parseFloat($('#paymentOptionIdAmount' + index).val());
494
        }
484
        }
495
        var paymentOptionId = $('#paymentOptionIdAmount' + index).attr("paymentOptionId");
485
        var paymentOptionId = $('#paymentOptionIdAmount' + index).attr("paymentOptionId");
496
        var paymentOptionIdAmountObject = {};
486
        var paymentOptionIdAmountObject = {};
497
        paymentOptionIdAmountObject['paymentOptionId'] = paymentOptionId;
487
        paymentOptionIdAmountObject['paymentOptionId'] = paymentOptionId;
Line 504... Line 494...
504
    retObj['paymentOptions'] = (paymentOptionIdAmount);
494
    retObj['paymentOptions'] = (paymentOptionIdAmount);
505
    retObj['poId'] = $('#poid').val();
495
    retObj['poId'] = $('#poid').val();
506
 
496
 
507
    retObj['poItemId'] = $('#poItemId').val();
497
    retObj['poItemId'] = $('#poItemId').val();
508
 
498
 
509
    console.log(retObj);
-
 
510
    return JSON.stringify(retObj);
499
    return JSON.stringify(retObj);
511
}
500
}
512
 
501
 
513
function resetInputs() {
502
function resetInputs() {
514
    $("div.customerinfo").html(customerInfo);
503
    $("div.customerinfo").html(customerInfo);
515
    $("div.billinginfo").html(billingInfo).hide();
504
    $("div.billinginfo").html(billingInfo).hide();
516
}
505
}
517
 
506
 
518
function writeOldCustomerDetailsByMobileNumber(mobileNumber) {
507
function writeOldCustomerDetailsByMobileNumber(mobileNumber) {
519
    doAjaxRequestHandler(context + "/customer/mobileNumber?mobileNumber=" + mobileNumber, "GET", function (response) {
508
    doAjaxRequestHandler(context + "/customer/mobileNumber?mobileNumber=" + mobileNumber, "GET", function (response) {
520
        if (response.response == '') {
509
        if (response.response === '') {
521
            return;
510
            return;
522
        }
511
        }
523
        var customer = response.response;
512
        var customer = response.response;
524
        if (customer == null) {
513
        if (customer === null) {
525
            $('input.phone').attr('value', mobileNumber).attr('readonly', true);
514
            $('input.phone').attr('value', mobileNumber).attr('readonly', true);
526
            $('button.mk_add_customer').show();
515
            $('button.mk_add_customer').show();
527
 
-
 
528
            return;
516
            return;
529
        }
517
        }
530
        $('input.firstName').attr('value', customer.firstName).attr('readonly', true);
518
        $('input.firstName').attr('value', customer.firstName).attr('readonly', true);
531
        $('input.lastName').attr('value', customer.lastName).attr('readonly', true);
519
        $('input.lastName').attr('value', customer.lastName).attr('readonly', true);
532
        $('input.phone').attr('value', customer.mobileNumber).attr('readonly', true);
520
        $('input.phone').attr('value', customer.mobileNumber).attr('readonly', true);
533
        if (customer.emailId != null && customer.emailId != '') {
521
        if (customer.emailId !== null && customer.emailId !== '') {
534
            $('#emailId').attr('value', customer.emailId).attr('readonly', true);
522
            $('#emailId').attr('value', customer.emailId).attr('readonly', true);
535
            console.log('helo');
-
 
536
        } else {
523
        } else {
537
            $('button.mk_add_email').show();
524
            $('button.mk_add_email').show();
538
        }
525
        }
539
        $('#firstName').val(customer.firstName);
526
        $('#firstName').val(customer.firstName);
540
        $('#lastName').val(customer.lastName);
527
        $('#lastName').val(customer.lastName);
541
        $('#alternatePhone').val(customer.mobileNumber);
528
        $('#alternatePhone').val(customer.mobileNumber);
542
        customerId = customer.customerId;
529
        customerId = customer.customerId;
543
        $("div.billinginfo").show();
530
        $("div.billinginfo").show();
544
        trs = [];
531
        var trs = [];
545
        if (customer.addresses != null) {
532
        if (customer.addresses !== null) {
-
 
533
            for (var i = 0; i < customer.addresses.length; i++) {
546
            for (address of customer.addresses) {
534
                var address = customer.addresses[i];
547
                if (pendingPO != null) {
535
                if (pendingPO !== null) {
548
 
-
 
549
                    if (pendingPO.customerAddressId == address.id) {
536
                    if (pendingPO.customerAddressId === address.id) {
550
                        trs.push(getAddressTr(address));
537
                        trs.push(getAddressTr(address));
551
                    }
538
                    }
552
                } else {
539
                } else {
553
                    trs.push(getAddressTr(address));
540
                    trs.push(getAddressTr(address));
554
                }
541
                }
555
            }
542
            }
556
        }
543
        }
557
        $("#address-body").html(trs.join(""));
544
        $("#address-body").html(trs.join(""));
558
 
-
 
559
    });
545
    });
560
}
546
}
561
 
547
 
562
function getAddressTr(address) {
548
function getAddressTr(address) {
563
    var tr = [];
549
    var tr = [];