| 4207 |
mandeep.dh |
1 |
function addNewRowForItem() {
|
|
|
2 |
$('table#bulk-order-items tbody>tr:first').clone(true).insertAfter($('table#bulk-order-items tbody>tr:last'));
|
|
|
3 |
|
|
|
4 |
var newRow = $('table#bulk-order-items tbody>tr:last');
|
|
|
5 |
|
|
|
6 |
// Enabling the new record added
|
|
|
7 |
$(newRow).find('input').removeAttr('disabled');
|
|
|
8 |
|
|
|
9 |
// Making this row visible
|
|
|
10 |
$(newRow).show();
|
|
|
11 |
}
|
|
|
12 |
|
|
|
13 |
function validateForm() {
|
|
|
14 |
return true;
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
function updateTotalAmount() {
|
|
|
18 |
var totalAmount = 0;
|
|
|
19 |
|
|
|
20 |
$('table#bulk-order-items tbody>tr').each(function(index, element) {
|
|
|
21 |
// Ignoring the first sample row
|
|
|
22 |
if (index == 0) {
|
|
|
23 |
return;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
var price = $(element).find('input[name="unit_price"]').val();
|
|
|
27 |
var quantity = $(element).find('input[name="quantity"]').val();
|
|
|
28 |
var amount = price * quantity;
|
|
|
29 |
totalAmount += amount;
|
|
|
30 |
var amountInput = $(element).find('div#item-amount');
|
|
|
31 |
$(amountInput).html(amount);
|
|
|
32 |
});
|
|
|
33 |
|
|
|
34 |
$('#bulk-order-total-amount').val(totalAmount);
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
function submitBulkOrderForm() {
|
|
|
38 |
if (validateForm()) {
|
|
|
39 |
// index starts from zero, Also we need to ignore first sample row
|
|
|
40 |
$('table#bulk-order-items tbody>tr').each(function(rowIndex, rowElement) {
|
|
|
41 |
// Skipping first sample row
|
|
|
42 |
if (rowIndex != 0) {
|
|
|
43 |
$(rowElement).find('input').each(function(inputIndex, inputElement) {
|
|
|
44 |
if ($(inputElement).attr('name').indexOf('lineItems[') == -1) {
|
|
|
45 |
$(inputElement).attr('name', 'lineItems[' + (rowIndex - 1) + '].' + $(inputElement).attr('name'));
|
|
|
46 |
}
|
|
|
47 |
});
|
|
|
48 |
}
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
$('div#error').empty();
|
|
|
52 |
|
|
|
53 |
$.ajax({
|
|
|
54 |
type : 'POST',
|
|
|
55 |
url : '/Support/bulk-order',
|
|
|
56 |
data : $('form#bulk-order').serialize(),
|
|
|
57 |
success : function(response) {
|
|
|
58 |
if ($(response).attr('id') == 'error') {
|
|
|
59 |
$('div#error').html(response);
|
|
|
60 |
}
|
|
|
61 |
else {
|
|
|
62 |
document.write(response);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
});
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
function updateModelName(trElement, itemId) {
|
|
|
70 |
$.ajax({
|
|
|
71 |
type : 'GET',
|
|
|
72 |
url : '/Support/bulk-order!getModelName',
|
|
|
73 |
data : 'itemId=' + itemId,
|
|
|
74 |
success : function(response) {
|
|
|
75 |
$(trElement).find('div#model_name').html(response);
|
|
|
76 |
}
|
|
|
77 |
});
|
|
|
78 |
}
|