| 23405 |
amit.gupta |
1 |
$(function() {
|
|
|
2 |
$("a.create_indent").live('click', function() {
|
|
|
3 |
loadIndent("main-content");
|
|
|
4 |
});
|
|
|
5 |
$("a.in_process_indent").live('click', function() {
|
|
|
6 |
loadInprocessIndent("main-content");
|
|
|
7 |
});
|
|
|
8 |
|
|
|
9 |
$("#entire-catalog-table input").live(
|
|
|
10 |
{
|
|
|
11 |
change: function(){
|
|
|
12 |
var itemId = parseInt($(this).data("item-id"));
|
|
|
13 |
var sellingPrice = parseInt($(this).data("selling-price"));
|
|
|
14 |
var quantity = parseInt($(this).val());
|
|
|
15 |
if(quantity>10){
|
|
|
16 |
alert("Quantity should not be above 10");
|
|
|
17 |
if(itemId in indentMap){
|
|
|
18 |
$(this).val(indentMap[itemId].quantity);
|
|
|
19 |
} else {
|
|
|
20 |
$(this).val(0);
|
|
|
21 |
}
|
|
|
22 |
return;
|
|
|
23 |
}
|
|
|
24 |
description = $(this).data("description");
|
|
|
25 |
if(itemId in indentMap) {
|
|
|
26 |
indentMap[itemId]["quantity"] = quantity;
|
|
|
27 |
indentMap[itemId]["sellingPrice"] = sellingPrice;
|
|
|
28 |
indentMap[itemId]["description"] = description;
|
|
|
29 |
indentMap[itemId]["itemId"] = itemId;
|
|
|
30 |
} else {
|
|
|
31 |
indentMap[itemId] = {"quantity": quantity, "sellingPrice":sellingPrice, "description":description, "itemId":itemId};
|
|
|
32 |
}
|
| 23772 |
amit.gupta |
33 |
populateIndentSummary();
|
|
|
34 |
/*if ('timeout' in indentMap[itemId]) {
|
| 23405 |
amit.gupta |
35 |
clearTimeout(indentMap[itemId].timeout);
|
|
|
36 |
}
|
|
|
37 |
var somefunction= (function () {
|
|
|
38 |
return function() {
|
|
|
39 |
if(itemId in indentMap) {
|
|
|
40 |
doAjaxRequestWithJsonHandler(context+"/indent-item/save", 'PUT', JSON.stringify(indentMap[itemId]), populateIndentSummary);
|
|
|
41 |
} else {
|
|
|
42 |
doAjaxRequestWithJsonHandler(context+"/indent-item/save", 'PUT', JSON.stringify({itemId:itemId, quantity:0}), populateIndentSummary);
|
|
|
43 |
}
|
|
|
44 |
};
|
|
|
45 |
})();
|
| 23772 |
amit.gupta |
46 |
indentMap[itemId].timeout = setTimeout(somefunction, 1000);*/
|
| 23405 |
amit.gupta |
47 |
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
);
|
|
|
51 |
$("button.mk_submit_indent").live('click', function(){
|
|
|
52 |
confirmString = [];
|
|
|
53 |
confirmString.push('<table class="table table-striped table-condensed table-bordered" id="entire-catalog-table">');
|
|
|
54 |
confirmString.push('<tr>');
|
|
|
55 |
confirmString.push('<th>Item Id</th>');
|
|
|
56 |
confirmString.push('<th>Description</th>');
|
|
|
57 |
confirmString.push('<th>Unit Price</th>');
|
|
|
58 |
confirmString.push('<th>Quantity</th>');
|
|
|
59 |
confirmString.push('<th>Item total</th>');
|
|
|
60 |
confirmString.push('</tr>');
|
|
|
61 |
for(var itemId in indentMap) {
|
|
|
62 |
if(indentMap[itemId].quantity > 0) {
|
|
|
63 |
confirmString.push('<tr>');
|
|
|
64 |
confirmString.push('<td>'+ itemId +'</td>');
|
|
|
65 |
confirmString.push('<td>'+ indentMap[itemId].description +'</td>');
|
|
|
66 |
confirmString.push('<td style="text-align:left">' + numberToComma(indentMap[itemId].sellingPrice) +'</td>');
|
|
|
67 |
confirmString.push('<td style="text-align:left">' + indentMap[itemId].quantity +'</td>');
|
|
|
68 |
confirmString.push('<td style="text-align:left">' + numberToComma(indentMap[itemId].quantity*indentMap[itemId].sellingPrice) +'</td>');
|
|
|
69 |
confirmString.push('</tr>');
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
confirmString.push('</table>');
|
|
|
73 |
$('#indent-container1').html(confirmString.join('')).show();
|
|
|
74 |
$('#indent-container').hide();
|
|
|
75 |
$('button.mk_submit_indent').hide();
|
|
|
76 |
$('button.bk_toedit_indent').show();
|
|
|
77 |
$('button.confirm_indent').show();
|
|
|
78 |
});
|
|
|
79 |
$("button.confirm_indent").live('click', function(){
|
| 23772 |
amit.gupta |
80 |
var itemQtyList = [];
|
|
|
81 |
for(itemId in indentMap) {
|
|
|
82 |
itemQtyList.push({"quantity":indentMap[itemId]["quantity"], "itemId": indentMap[itemId]["itemId"]});
|
|
|
83 |
}
|
|
|
84 |
doPostAjaxRequestWithJsonHandler(context+"/open-indent/save", JSON.stringify(itemQtyList), function(data){
|
| 23405 |
amit.gupta |
85 |
alert('Indent has been created Successfully!');
|
|
|
86 |
indentMap={};
|
| 23772 |
amit.gupta |
87 |
loadIndent('main-content');
|
| 23405 |
amit.gupta |
88 |
});
|
|
|
89 |
});
|
|
|
90 |
$("button.bk_toedit_indent").live('click', function(){
|
|
|
91 |
$('button.bk_toedit_indent').hide();
|
|
|
92 |
$('button.confirm_indent').hide();
|
|
|
93 |
$('button.mk_submit_indent').show();
|
|
|
94 |
$('#indent-container1').hide();
|
|
|
95 |
$('#indent-container').show();
|
|
|
96 |
|
|
|
97 |
});
|
|
|
98 |
|
|
|
99 |
});
|
|
|
100 |
|
|
|
101 |
function populateIndentSummary(){
|
|
|
102 |
var totalQty=0;
|
|
|
103 |
var totalAmount = 0;
|
|
|
104 |
var totalItems = 0;
|
| 23772 |
amit.gupta |
105 |
var diffAmount = 0;
|
|
|
106 |
var diffPcs = 0;
|
| 23405 |
amit.gupta |
107 |
for (var itemId in indentMap) {
|
|
|
108 |
if(indentMap[itemId]['quantity'] > 0){
|
|
|
109 |
totalQty += indentMap[itemId]['quantity'];
|
|
|
110 |
totalAmount += indentMap[itemId]['sellingPrice']*indentMap[itemId]['quantity'];
|
|
|
111 |
totalItems++;
|
| 23772 |
amit.gupta |
112 |
if(indentMap['quantity'] - indentMap['previousQuantity'] != 0) {
|
|
|
113 |
if (indentMap['quantity'] - indentMap['previousQuantity'] > 0) {
|
|
|
114 |
|
|
|
115 |
} else {
|
|
|
116 |
|
|
|
117 |
}
|
|
|
118 |
}
|
| 23405 |
amit.gupta |
119 |
} else {
|
|
|
120 |
delete(indentMap[itemId]);
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
if(totalQty===0){
|
|
|
124 |
$('button.mk_submit_indent').hide();
|
|
|
125 |
} else {
|
|
|
126 |
$('button.mk_submit_indent').show();
|
|
|
127 |
}
|
|
|
128 |
$("#itemCount").html(numberToComma(totalItems));
|
|
|
129 |
$("#totalItemQty").html(numberToComma(totalQty));
|
|
|
130 |
$("#totalAmount").html(numberToComma(totalAmount));
|
|
|
131 |
}
|
|
|
132 |
function loadIndent(domId){
|
|
|
133 |
doAjaxRequestHandler(context+"/indent/loadIndent", "GET", function(response){
|
|
|
134 |
$('#' + domId).html(response);
|
|
|
135 |
});
|
|
|
136 |
}
|
|
|
137 |
function loadInprocessIndent(domId){
|
|
|
138 |
doAjaxRequestHandler(context+"/indent/inProcess", "GET", function(response){
|
|
|
139 |
$('#' + domId).html(response);
|
|
|
140 |
});
|
|
|
141 |
}
|