Subversion Repositories SmartDukaan

Rev

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

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