Subversion Repositories SmartDukaan

Rev

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

Rev 32469 Rev 33149
Line 1... Line 1...
1
$(function () {
1
$(function () {
2
    //Price change handler
2
    //Price change handler
3
    $(document).on('change', "form#cd input.unitPrice,form#cd input.discount", function () {
3
    $(document).on('change', "form#cd input.unitPrice, form#cd input.discount", function () {
-
 
4
        var $row = $(this).closest('tr'); // Get the closest <tr> parent of the changed input
4
 
5
 
5
        var unitPrice = parseFloat($('form#cd input.unitPrice').val());
6
        var unitPrice = parseFloat($row.find('input.unitPrice').val());
6
        if (isNaN(unitPrice)) {
7
        if (isNaN(unitPrice)) {
7
            unitPrice = 0;
8
            unitPrice = 0;
8
        }
9
        }
9
        var discount = parseFloat($('form#cd input.discount').val());
10
        var discount = parseFloat($row.find('input.discount').val());
10
        var maxDiscount = parseFloat($('form#cd input.discount').data('maxdiscount'));
11
        var maxDiscount = parseFloat($row.find('input.discount').data('maxdiscount'));
11
        if (isNaN(discount)) {
12
        if (isNaN(discount)) {
12
            discount = 0;
13
            discount = 0;
13
        }
14
        }
14
        if (isNaN(maxDiscount)) {
15
        if (isNaN(maxDiscount)) {
15
            maxDiscount = 0;
16
            maxDiscount = 0;
16
        }
17
        }
17
        if (discount > maxDiscount) {
18
        if (discount > maxDiscount) {
18
            alert("Discount cant be greater than max Discount");
19
            alert("Discount can't be greater than max Discount");
19
            $('form#cd input.discount').val(maxDiscount);
20
            $row.find('input.discount').val(maxDiscount);
20
            $(this).focus();
21
            $(this).focus();
21
            return;
22
            return;
22
        }
23
        }
23
        if (unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)) {
24
        if (unitPrice < 0 || (unitPrice > 0 && unitPrice - discount < 0)) {
24
            alert("Invalid unit/discount price");
25
            alert("Invalid unit/discount price");
25
            $(this).focus();
26
            $(this).focus();
26
            return;
27
            return;
27
        }
28
        }
28
        let lines = $("#order-items").find('tbody>tr:gt(0)').length;
29
        let lines = $("#order-items").find('tbody>tr:gt(0)').length;
29
        if (lines > 3) {
30
        if (lines > 3) {
30
            calculateTotalAmount(this);
31
            calculateTotalAmount($row);
31
        } else {
32
        } else {
32
            calculateTotalAmount();
33
            calculateTotalAmount();
33
        }
34
        }
34
        $('.mk_check_plans').trigger('click', ['manual']);
35
        $row.find('.mk_check_plans').trigger('click', ['manual']); // Trigger the button within the same row
35
 
-
 
36
    });
36
    });
37
 
37
 
38
 
38
 
-
 
39
 
39
    $(document).on('change', "form#cd input.insuranceamount", function () {
40
    $(document).on('change', "form#cd input.insuranceamount", function () {
40
        calculateTotalAmount();
41
        calculateTotalAmount();
41
    });
42
    });
42
 
43
 
43
    $(document).on('click', ".create-order", function () {
44
    $(document).on('click', ".create-order", function () {
44
        checkout("main-content");
45
        checkout("main-content");
45
    });
46
    });
46
 
47
 
47
    $(document).on('click', ".mk_check_plans", function (event, source) {
48
    $(document).on('click', ".mk_check_plans", function (event, source) {
-
 
49
        console.log("checkPlansssssss99999");
48
        let lines = $("#order-items").find('tbody>tr:gt(0)').length;
50
        let lines = $("#order-items").find('tbody>tr:gt(0)').length;
49
        if (lines > 3) {
51
        if (lines > 3) {
50
            //No need to check plans
52
            //No need to check plans
51
            return;
53
            return;
52
        }
54
        }