Subversion Repositories SmartDukaan

Rev

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