Subversion Repositories SmartDukaan

Rev

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