Subversion Repositories SmartDukaan

Rev

Rev 23772 | Rev 23796 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23772 Rev 23786
Line 1... Line 1...
1
$(function() {
1
$(function() {
-
 
2
	$("a.allocation_po").live('click', function(){
-
 
3
		loadIndent('main-content');
-
 
4
	});
-
 
5
	$("li.mk_counter_size").live('click', function(){
-
 
6
		if($(this).hasClass('active')){
-
 
7
			return;
-
 
8
		}
-
 
9
		currentFofoId = 0;
-
 
10
		counterSize=$(this).find('a').html();
-
 
11
		loadIndent('main-content');
-
 
12
	});
-
 
13
	$("li.brandLi").live('click', function(){
-
 
14
		if(!$(this).hasClass('active')) {
-
 
15
			$("table.brandPerformance").toggle();
-
 
16
			$("li.brandLi").removeClass('active');
-
 
17
			$(this).addClass('active');
-
 
18
		}
-
 
19
	});
2
	$("a.create_indent").live('click', function() {
20
	$("a.create_indent").live('click', function() {
-
 
21
		currentFofoId=0;
-
 
22
		counterSize='';
-
 
23
		loadIndent("main-content");
-
 
24
	});
-
 
25
	$("button.create_indent").live('click', function() {
3
		loadIndent("main-content");
26
		loadIndent("main-content");
4
	});
27
	});
5
	$("a.in_process_indent").live('click', function() {
28
	$("a.in_process_indent").live('click', function() {
6
		loadInprocessIndent("main-content");
29
		loadInprocessIndent("main-content");
7
	});
30
	});
8
	
31
 
9
	$("#entire-catalog-table input").live(
32
	$("#entire-catalog-table input").live({
10
		{
-
 
11
			change: function(){
33
		change : function() {
12
				var itemId = parseInt($(this).data("item-id"));
34
			var itemId = parseInt($(this).data("item-id"));
13
				var sellingPrice = parseInt($(this).data("selling-price"));
35
			var sellingPrice = parseInt($(this).data("selling-price"));
14
				var quantity = parseInt($(this).val());
36
			var quantity = parseInt($(this).val());
15
				if(quantity>10){
37
			if (quantity > 10) {
16
					alert("Quantity should not be above 10");
38
				alert("Quantity should not be above 10");
17
					if(itemId in indentMap){
39
				if (itemId in indentMap) {
18
						$(this).val(indentMap[itemId].quantity);
40
					$(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 {
41
				} else {
31
					indentMap[itemId] = {"quantity": quantity, "sellingPrice":sellingPrice, "description":description, "itemId":itemId};
42
					$(this).val(0);
32
				}
43
				}
33
				populateIndentSummary();
-
 
34
				/*if ('timeout' in indentMap[itemId]) {
-
 
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
				    };
44
				return;
45
				})();
-
 
46
				indentMap[itemId].timeout = setTimeout(somefunction, 1000);*/
-
 
47
				
-
 
48
			}
45
			}
49
		}
-
 
50
	);
-
 
51
	$("button.mk_submit_indent").live('click', function(){
46
			description = $(this).data("description");
52
		confirmString = [];
-
 
53
		confirmString.push('<table class="table table-striped table-condensed table-bordered" id="entire-catalog-table">');
-
 
54
		confirmString.push('<tr>');
47
			if (itemId in indentMap) {
55
		confirmString.push('<th>Item Id</th>');
48
				indentMap[itemId]["quantity"] = quantity;
56
		confirmString.push('<th>Description</th>');
49
				indentMap[itemId]["sellingPrice"] = sellingPrice;
57
		confirmString.push('<th>Unit Price</th>');
50
				indentMap[itemId]["description"] = description;
58
		confirmString.push('<th>Quantity</th>');
51
				indentMap[itemId]["itemId"] = itemId;
59
		confirmString.push('<th>Item total</th>');
52
				indentMap[itemId]["diff"] =  quantity - indentMap[itemId]["initialQuantity"];
60
		confirmString.push('</tr>');
53
			} else {
61
		for(var itemId in indentMap) {
54
				indentMap[itemId] = {
62
			if(indentMap[itemId].quantity > 0) {
55
					"quantity" : quantity,
63
				confirmString.push('<tr>');
56
					"sellingPrice" : sellingPrice,
64
				confirmString.push('<td>'+ itemId +'</td>');
57
					"description" : description,
65
				confirmString.push('<td>'+ indentMap[itemId].description +'</td>');
58
					"itemId" : itemId,
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>');
59
					"initialQuantity" : 0,
68
				confirmString.push('<td style="text-align:left">' + numberToComma(indentMap[itemId].quantity*indentMap[itemId].sellingPrice) +'</td>');
-
 
69
				confirmString.push('</tr>');
60
					"diff" : quantity
-
 
61
				};
70
			}
62
			}
-
 
63
			populateIndentSummary();
-
 
64
			/*
-
 
65
			 * if ('timeout' in indentMap[itemId]) {
-
 
66
			 * clearTimeout(indentMap[itemId].timeout); } var somefunction=
-
 
67
			 * (function () { return function() { if(itemId in indentMap) {
-
 
68
			 * doAjaxRequestWithJsonHandler(context+"/indent-item/save", 'PUT',
-
 
69
			 * JSON.stringify(indentMap[itemId]), populateIndentSummary); } else {
-
 
70
			 * doAjaxRequestWithJsonHandler(context+"/indent-item/save", 'PUT',
-
 
71
			 * JSON.stringify({itemId:itemId, quantity:0}),
-
 
72
			 * populateIndentSummary); } }; })(); indentMap[itemId].timeout =
-
 
73
			 * setTimeout(somefunction, 1000);
-
 
74
			 */
-
 
75
 
71
		}
76
		}
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(){
-
 
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){
-
 
85
			alert('Indent has been created Successfully!');
-
 
86
			indentMap={};
-
 
87
			loadIndent('main-content');
-
 
88
		});
-
 
89
	});
77
	});
-
 
78
	$("button.mk_submit_indent")
-
 
79
			.live(
-
 
80
					'click',
-
 
81
					function() {
-
 
82
						confirmString = [];
-
 
83
						confirmString
-
 
84
								.push('<table class="table table-striped table-condensed table-bordered" id="entire-catalog-table">');
-
 
85
						confirmString.push('<tr>');
-
 
86
						confirmString.push('<th style="width:100px">Item Id</th>');
-
 
87
						confirmString.push('<th style="width:250px">Description</th>');
-
 
88
						confirmString.push('<th style="width:150px">Unit Price</th>');
-
 
89
						confirmString.push('<th style="width:150px">Quantity</th>');
-
 
90
						confirmString.push('<th style="width:200px">Item total</th>');
-
 
91
						confirmString.push('</tr>');
-
 
92
						changedItemIds.forEach(function(itemId){
-
 
93
							confirmString.push('<tr style="background-color:#9C7D7E">');
-
 
94
							confirmString.push('<td>' + itemId + '</td>');
-
 
95
							confirmString.push('<td>'
-
 
96
									+ indentMap[itemId].description
-
 
97
									+ '</td>');
-
 
98
							confirmString
-
 
99
							.push('<td style="text-align:left">'
-
 
100
									+ numberToComma(indentMap[itemId].sellingPrice)
-
 
101
									+ '</td>');
-
 
102
							confirmString
-
 
103
							.push('<td style="text-align:left">'
-
 
104
									+ indentMap[itemId].quantity + '(' + (indentMap[itemId].diff > 0 ? '+' : '-') + Math.abs(indentMap[itemId].diff) 
-
 
105
									+ ' pcs)</td>');
-
 
106
							confirmString
-
 
107
							.push('<td style="text-align:left">'
-
 
108
									+ numberToComma(indentMap[itemId].quantity
-
 
109
											* indentMap[itemId].sellingPrice)
-
 
110
											+ '</td>');
-
 
111
							confirmString.push('</tr>');
-
 
112
						});
-
 
113
						for ( var itemId in indentMap) {
-
 
114
							if (itemId.indexOf(changedItemIds) > 0){
-
 
115
								continue;
-
 
116
							}
-
 
117
							if (indentMap[itemId].quantity > 0) {
-
 
118
								confirmString.push('<tr>');
-
 
119
								confirmString.push('<td>' + itemId + '</td>');
-
 
120
								confirmString.push('<td>'
-
 
121
										+ indentMap[itemId].description
-
 
122
										+ '</td>');
-
 
123
								confirmString
-
 
124
										.push('<td style="text-align:left">'
-
 
125
												+ numberToComma(indentMap[itemId].sellingPrice)
-
 
126
												+ '</td>');
-
 
127
								confirmString
-
 
128
										.push('<td style="text-align:left">'
-
 
129
												+ indentMap[itemId].quantity
-
 
130
												+ '</td>');
-
 
131
								confirmString
-
 
132
										.push('<td style="text-align:left">'
-
 
133
												+ numberToComma(indentMap[itemId].quantity
-
 
134
														* indentMap[itemId].sellingPrice)
-
 
135
												+ '</td>');
-
 
136
								confirmString.push('</tr>');
-
 
137
							}
-
 
138
						}
-
 
139
						confirmString.push('</table>');
-
 
140
						$('#indent-container1').html(confirmString.join(''))
-
 
141
								.show();
-
 
142
						$('#indent-container').hide();
-
 
143
						$('button.mk_submit_indent').hide();
-
 
144
						$('button.bk_toedit_indent').show();
-
 
145
						$('button.confirm_indent').show();
-
 
146
					});
-
 
147
	$("button.confirm_indent").live(
-
 
148
			'click',
-
 
149
			function() {
-
 
150
				var itemQtyList = [];
-
 
151
				for (itemId in indentMap) {
-
 
152
					diff = indentMap[itemId]["quantity"] - indentMap[itemId]["initialQuantity"];
-
 
153
					if(diff!=0) {
-
 
154
						itemQtyList.push({
-
 
155
							"quantity" : indentMap[itemId]["quantity"],
-
 
156
							"itemId" : indentMap[itemId]["itemId"]
-
 
157
						});
-
 
158
					}
-
 
159
				}
-
 
160
				doPostAjaxRequestWithJsonHandler(context + "/open-indent/save?fofoId=" + currentFofoId + "&counterSize=" + counterSize,
-
 
161
						JSON.stringify(itemQtyList), function(data) {
-
 
162
							alert('Indent has been created Successfully!');
-
 
163
							indentMap = {};
-
 
164
							loadIndent('main-content');
-
 
165
						});
-
 
166
			});
90
	$("button.bk_toedit_indent").live('click', function(){
167
	$("button.bk_toedit_indent").live('click', function() {
91
		$('button.bk_toedit_indent').hide();
168
		$('button.bk_toedit_indent').hide();
92
		$('button.confirm_indent').hide();
169
		$('button.confirm_indent').hide();
93
		$('button.mk_submit_indent').show();
170
		$('button.mk_submit_indent').show();
94
		$('#indent-container1').hide();
171
		$('#indent-container1').hide();
95
		$('#indent-container').show();
172
		$('#indent-container').show();
96
		
173
 
97
	});
174
	});
98
	
175
 
99
});
176
});
100
 
177
 
101
function populateIndentSummary(){
178
function populateIndentSummary() {
102
	var totalQty=0;
179
	var totalQty = 0;
103
	var totalAmount = 0;
180
	var totalAmount = 0;
104
	var totalItems = 0;
181
	var totalItems = 0;
105
	var diffAmount = 0;
182
	var arr = [];
106
	var diffPcs = 0;
183
	changedItemIds = [];
-
 
184
	arr[0]=[0,0,0];
-
 
185
	arr[1]=[0,0,0];
-
 
186
	arr[2]=[0,0,0];
-
 
187
	arr[3]=[0,0,0];
-
 
188
 
107
	for (var itemId in indentMap) {
189
	for ( var itemId in indentMap) {
108
		if(indentMap[itemId]['quantity'] > 0){
190
		var itemQty = indentMap[itemId]['quantity'];
109
			totalQty += indentMap[itemId]['quantity'];  
191
		var previousItemQty = indentMap[itemId]['initialQuantity'];
110
			totalAmount += indentMap[itemId]['sellingPrice']*indentMap[itemId]['quantity'];  
192
		var sellingPrcice = indentMap[itemId]['sellingPrice'];
-
 
193
		if(previousItemQty !=0) {
-
 
194
			arr[0][0]++;
-
 
195
		}
-
 
196
		if(itemQty !=0) {
111
			totalItems++;
197
			arr[3][0]++;
-
 
198
		}
112
			if(indentMap['quantity'] - indentMap['previousQuantity'] != 0) {
199
		var diff = itemQty - previousItemQty;
-
 
200
		arr[0][1] += previousItemQty;
113
				if (indentMap['quantity'] - indentMap['previousQuantity'] > 0) {
201
		arr[0][2] += previousItemQty* sellingPrcice;
-
 
202
		arr[3][1] += itemQty;
-
 
203
		arr[3][2] += itemQty * sellingPrcice;
-
 
204
		if (diff != 0) {
-
 
205
			changedItemIds.push(itemId);
-
 
206
			if (diff > 0) {
114
					
207
				arr[1][0]++;
-
 
208
				arr[1][1] += diff;
-
 
209
				arr[1][2] += (diff) * sellingPrcice;
115
				} else {
210
			} else {
116
					
211
				arr[2][0]++;
117
				}
212
				arr[2][1] += diff;
-
 
213
				arr[2][2] += diff * sellingPrcice;
118
			}
214
			}
119
		} else {
-
 
120
			delete(indentMap[itemId]);
-
 
121
		}
215
		}
122
	}
216
	}
-
 
217
	totalQty = arr[3][1];
123
	if(totalQty===0){
218
	if (totalQty === 0) {
124
		$('button.mk_submit_indent').hide();
219
		$('button.mk_submit_indent').hide();
125
	} else {
220
	} else {
126
		$('button.mk_submit_indent').show();
221
		$('button.mk_submit_indent').show();
127
	}
222
	}
128
	$("#itemCount").html(numberToComma(totalItems));
223
	$("#summary-table").find("td").each(function(index, ele){
-
 
224
		if(index%3==2){
129
	$("#totalItemQty").html(numberToComma(totalQty));
225
			$(ele).html(numberToComma(arr[Math.floor(index/3)][2]));
-
 
226
		}else{
130
	$("#totalAmount").html(numberToComma(totalAmount));
227
			$(ele).html(arr[Math.floor(index/3)][index%3]);
-
 
228
		}
-
 
229
		
-
 
230
	});
131
}
231
}
132
function loadIndent(domId){
232
function loadIndent(domId) {
-
 
233
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize=" + counterSize;
133
	doAjaxRequestHandler(context+"/indent/loadIndent", "GET", function(response){
234
	doAjaxRequestHandler(context + url, "GET", function(response) {
134
		$('#' + domId).html(response);
235
		$('#' + domId).html(response);
135
	});
236
	});
136
}
237
}
137
function loadInprocessIndent(domId){
238
function loadInprocessIndent(domId) {
138
	doAjaxRequestHandler(context+"/indent/inProcess", "GET", function(response){
239
	doAjaxRequestHandler(context + "/indent/inProcess", "GET", function(
-
 
240
			response) {
139
		$('#' + domId).html(response);
241
		$('#' + domId).html(response);
140
	});
242
	});
141
}
243
}
142
244