Subversion Repositories SmartDukaan

Rev

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

Rev 4687 Rev 4754
Line -... Line 1...
-
 
1
function addNewRowForLineItem(table) {
-
 
2
    $(table).find('#sample-lineitem').clone(true).insertAfter($(table).find('tbody>tr:last'));
-
 
3
 
-
 
4
    var newRow = $(table).find('tbody>tr:last');
-
 
5
 
-
 
6
    // Enabling the new record added
-
 
7
    $(newRow).find('input').removeAttr('disabled');
-
 
8
    $(newRow).removeAttr('id');
-
 
9
 
-
 
10
    // Making this row visible
-
 
11
    $(newRow).show();
-
 
12
}
-
 
13
 
-
 
14
function updateModelNameXferPrice(trElement, itemId, supplierId) {
-
 
15
    $.ajax({
-
 
16
        type      : 'GET',
-
 
17
        url       : '/inventory/purchase-order!getModelNameXferPrice',
-
 
18
        data      : 'itemId=' + itemId + '&supplierId=' + supplierId,
-
 
19
        success   : function(response) {
-
 
20
            $(trElement).find('div#modelName').html(response.split('~')[0]);
-
 
21
            $(trElement).find('input[name="unitPrice"]').val(response.split('~')[1]);
-
 
22
        }
-
 
23
    });
-
 
24
}
-
 
25
 
-
 
26
function updateTotalAmount(supplierId) {
-
 
27
    var totalAmount = 0;
-
 
28
    var totalQuantity = 0;
-
 
29
 
-
 
30
    $('div#lineitems-' + supplierId + ' table tbody>tr').each(function(index, element) {
-
 
31
        // Ignoring the first sample row
-
 
32
        if (index == 0) {
-
 
33
            return;
-
 
34
        }
-
 
35
 
-
 
36
        var price = $(element).find('input[name="unitPrice"]').val();
-
 
37
        var quantity = $(element).find('input[name="quantity"]').val();
-
 
38
        var amount = price * quantity;
-
 
39
        totalAmount += amount;
-
 
40
        totalQuantity += (1 * quantity);
-
 
41
        var amountInput = $(element).find('div#amount');
-
 
42
        $(amountInput).html(amount);
-
 
43
    });
-
 
44
 
-
 
45
    $('#total-amount-' + supplierId).html(totalAmount);
-
 
46
    $('#total-quantity-' + supplierId).html(totalQuantity);
-
 
47
}
-
 
48
 
-
 
49
function validateForm() {
-
 
50
    return true;
-
 
51
}
-
 
52
 
-
 
53
function submitPurchaseOrderForm(form) {
-
 
54
    if (validateForm()) {
-
 
55
        // index starts from zero, Also we need to ignore first sample row
-
 
56
        $(form).find('tbody>tr').each(function(rowIndex, rowElement) {
-
 
57
            // Skipping first sample row
-
 
58
            if (rowIndex != 0) {
-
 
59
                $(rowElement).find('input').each(function(inputIndex, inputElement) {
-
 
60
                    if ($(inputElement).attr('name').indexOf('lineItems[') == -1) {
-
 
61
                        $(inputElement).attr('name', 'lineItems[' + (rowIndex - 1) + '].' + $(inputElement).attr('name'));
-
 
62
                    }
-
 
63
                });
-
 
64
            }
-
 
65
        });
-
 
66
 
-
 
67
        $.ajax({
-
 
68
            type      : 'POST',
-
 
69
            url       : '/inventory/purchase-order',
-
 
70
            data      : $(form).serialize(),
-
 
71
            success   : function(response) {
-
 
72
                var responseInteger = parseInt(response);
-
 
73
                if (responseInteger > 0) {
-
 
74
                    document.location.href = '/inventory/purchase-order/' + responseInteger + '/edit';
-
 
75
                }
-
 
76
                else {
-
 
77
                    alert(response);
-
 
78
                }
-
 
79
            }
-
 
80
        });
-
 
81
    }
-
 
82
}
-
 
83
 
-
 
84
function submitEditPurchaseOrderForm(form, purchaseOrderId) {
-
 
85
    if (validateForm()) {
-
 
86
        // index starts from zero, Also we need to ignore first sample row
-
 
87
        $(form).find('tbody>tr').each(function(rowIndex, rowElement) {
-
 
88
            // Skipping first sample row
-
 
89
            if (rowIndex != 0) {
-
 
90
                $(rowElement).find('input').each(function(inputIndex, inputElement) {
-
 
91
                    if ($(inputElement).attr('name').indexOf('lineItems[') == -1) {
-
 
92
                        $(inputElement).attr('name', 'lineItems[' + (rowIndex - 1) + '].' + $(inputElement).attr('name'));
-
 
93
                    }
-
 
94
                });
-
 
95
            }
-
 
96
        });
-
 
97
 
-
 
98
        $.ajax({
-
 
99
            type      : 'POST',
-
 
100
            url       : '/inventory/purchase-order!update',
-
 
101
            data      : $(form).serialize(),
-
 
102
            success   : function(response) {
-
 
103
                var responseInteger = parseInt(response);
-
 
104
                if (responseInteger > 0) {
-
 
105
                    document.location.href = '/inventory/purchase-order/' + responseInteger + '/edit';
-
 
106
                }
-
 
107
                else {
-
 
108
                    alert(response);
-
 
109
                }
-
 
110
            }
-
 
111
        });
-
 
112
    }    
-
 
113
}
1
114