Subversion Repositories SmartDukaan

Rev

Rev 4754 | Rev 7676 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4754 mandeep.dh 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
 
7410 amar.kumar 26
function closePO(id){
27
	$.ajax({
28
        type      : 'GET',
29
        url       : '/inventory/purchase-order!closePO',
30
        data      : 'id=' + id,
31
        success   : function(response) {
32
            window.location.href = "/inventory/purchase-order";
33
        },
34
		error	  : function(response) {
35
			alert("Error in closing PO");
36
		}
37
    });
38
}
39
 
4754 mandeep.dh 40
function updateTotalAmount(supplierId) {
41
    var totalAmount = 0;
42
    var totalQuantity = 0;
43
 
44
    $('div#lineitems-' + supplierId + ' table tbody>tr').each(function(index, element) {
45
        // Ignoring the first sample row
46
        if (index == 0) {
47
            return;
48
        }
49
 
50
        var price = $(element).find('input[name="unitPrice"]').val();
51
        var quantity = $(element).find('input[name="quantity"]').val();
52
        var amount = price * quantity;
53
        totalAmount += amount;
54
        totalQuantity += (1 * quantity);
55
        var amountInput = $(element).find('div#amount');
56
        $(amountInput).html(amount);
57
    });
58
 
59
    $('#total-amount-' + supplierId).html(totalAmount);
60
    $('#total-quantity-' + supplierId).html(totalQuantity);
61
}
62
 
63
function validateForm() {
64
    return true;
65
}
66
 
67
function submitPurchaseOrderForm(form) {
68
    if (validateForm()) {
69
        // index starts from zero, Also we need to ignore first sample row
70
        $(form).find('tbody>tr').each(function(rowIndex, rowElement) {
71
            // Skipping first sample row
72
            if (rowIndex != 0) {
73
                $(rowElement).find('input').each(function(inputIndex, inputElement) {
74
                    if ($(inputElement).attr('name').indexOf('lineItems[') == -1) {
75
                        $(inputElement).attr('name', 'lineItems[' + (rowIndex - 1) + '].' + $(inputElement).attr('name'));
76
                    }
77
                });
78
            }
79
        });
80
 
81
        $.ajax({
82
            type      : 'POST',
83
            url       : '/inventory/purchase-order',
84
            data      : $(form).serialize(),
85
            success   : function(response) {
86
                var responseInteger = parseInt(response);
87
                if (responseInteger > 0) {
88
                    document.location.href = '/inventory/purchase-order/' + responseInteger + '/edit';
89
                }
90
                else {
91
                    alert(response);
92
                }
93
            }
94
        });
95
    }
96
}
97
 
98
function submitEditPurchaseOrderForm(form, purchaseOrderId) {
99
    if (validateForm()) {
100
        // index starts from zero, Also we need to ignore first sample row
101
        $(form).find('tbody>tr').each(function(rowIndex, rowElement) {
102
            // Skipping first sample row
103
            if (rowIndex != 0) {
104
                $(rowElement).find('input').each(function(inputIndex, inputElement) {
105
                    if ($(inputElement).attr('name').indexOf('lineItems[') == -1) {
106
                        $(inputElement).attr('name', 'lineItems[' + (rowIndex - 1) + '].' + $(inputElement).attr('name'));
107
                    }
108
                });
109
            }
110
        });
111
 
112
        $.ajax({
113
            type      : 'POST',
114
            url       : '/inventory/purchase-order!update',
115
            data      : $(form).serialize(),
116
            success   : function(response) {
117
                var responseInteger = parseInt(response);
118
                if (responseInteger > 0) {
119
                    document.location.href = '/inventory/purchase-order/' + responseInteger + '/edit';
120
                }
121
                else {
122
                    alert(response);
123
                }
124
            }
125
        });
126
    }    
127
}