Subversion Repositories SmartDukaan

Rev

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