Subversion Repositories SmartDukaan

Rev

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

Rev 24556 Rev 25721
Line 1... Line 1...
1
$(function() {
1
$(function() {
2
	$("a.allocation_po").live('click', function(){
2
	$(document).on('click',"a.allocation_po", function() {
3
		currentFofoId=0;
3
		currentFofoId = 0;
4
		counterSize='';
4
		counterSize = '';
5
		loadIndent('main-content');
5
		loadIndent('main-content');
6
	});
6
	});
7
	$("button.mk_pause_button").live('click', function(){
7
	$("button.mk_pause_button")
-
 
8
			.live(
-
 
9
					'click',
-
 
10
					function() {
8
		var clickedButton = $(this);
11
						var clickedButton = $(this);
9
		
12
 
10
		var description = clickedButton.data("description");
13
						var description = clickedButton.data("description");
11
		var catalogId = clickedButton.data("id");
14
						var catalogId = clickedButton.data("id");
-
 
15
						getColorsForItems(
-
 
16
								catalogId,
-
 
17
								0,
12
		getColorsForItems(catalogId, 0, "Active/pause " + description, function(itemIds){
18
								"Active/pause " + description,
-
 
19
								function(itemIds) {
13
			console.log(itemIds);
20
									console.log(itemIds);
14
			if(itemIds!=null) {
21
									if (itemIds != null) {
-
 
22
										bootbox
-
 
23
												.confirm(
-
 
24
														"Confirm Update "
-
 
25
																+ clickedButton
15
				bootbox.confirm("Confirm Update " + clickedButton.data("description") + "?", function(result){
26
																		.data("description")
-
 
27
																+ "?",
-
 
28
														function(result) {
16
					if(result) {
29
															if (result) {
-
 
30
																coloredItems
17
						coloredItems.forEach(function(item){
31
																		.forEach(function(
-
 
32
																				item) {
-
 
33
																			item.active = itemIds
18
							item.active = itemIds.indexOf(item.id+"") >= 0;
34
																					.indexOf(item.id
-
 
35
																							+ "") >= 0;
-
 
36
																			console
19
							console.log(coloredItems)
37
																					.log(coloredItems)
20
						});
38
																		});
-
 
39
 
-
 
40
																doPostAjaxRequestWithJsonHandler(
-
 
41
																		context
-
 
42
																				+ "/indent/confirm-pause/",
21
						
43
																		JSON
22
						doPostAjaxRequestWithJsonHandler(context+"/indent/confirm-pause/", JSON.stringify(coloredItems), function(response) {
44
																				.stringify(coloredItems),
-
 
45
																		function(
-
 
46
																				response) {
23
							if(response) {
47
																			if (response) {
-
 
48
																				bootbox
24
								bootbox.alert("Item/s  Updated Successfully");
49
																						.alert("Item/s  Updated Successfully");
25
							} else {
50
																			} else {
-
 
51
																				bootbox
26
								bootbox.alert("Could not pause item");
52
																						.alert("Could not pause item");
27
							}
53
																			}
28
							
54
 
29
						});
55
																		});
30
					}
56
															}
31
				});
57
														});
32
			}
58
									}
33
		});
59
								});
34
	});
60
					});
35
	$("button.raise_po").live('click', function(){
61
	$("button.raise_po").live('click', function() {
36
		if (confirm("Please confirm the PO")) {
62
		if (confirm("Please confirm the PO")) {
37
			raisePO();
63
			raisePO();
38
		} else {
64
		} else {
39
			return;
65
			return;
40
		}
66
		}
41
	});
67
	});
42
	$("li.mk_counter_size").live('click', function(){
68
	$("li.mk_counter_size").live('click', function() {
43
		if($(this).hasClass('active')){
69
		if ($(this).hasClass('active')) {
44
			return;
70
			return;
45
		}
71
		}
46
		currentFofoId = 0;
72
		currentFofoId = 0;
47
		counterSize=$(this).find('a').html();
73
		counterSize = $(this).find('a').html();
48
		loadIndent('main-content');
74
		loadIndent('main-content');
49
	});
75
	});
50
	$("li.brandLi").live('click', function(){
76
	$("li.brandLi").live('click', function() {
51
		if(!$(this).hasClass('active')) {
77
		if (!$(this).hasClass('active')) {
52
			$("table.brandPerformance").toggle();
78
			$("table.brandPerformance").toggle();
53
			$("li.brandLi").removeClass('active');
79
			$("li.brandLi").removeClass('active');
54
			$(this).addClass('active');
80
			$(this).addClass('active');
55
		}
81
		}
56
	});
82
	});
57
	$("a.create_indent").live('click', function() {
83
	$(document).on('click','a.create_indent',  function() {
58
		currentFofoId=0;
84
		currentFofoId = 0;
59
		counterSize='';
85
		counterSize = '';
60
		loadIndent("main-content");
86
		loadIndent("main-content");
61
	});
87
	});
62
	$("button.create_indent").live('click', function() {
88
	$("button.create_indent").live('click', function() {
63
		loadIndent("main-content");
89
		loadIndent("main-content");
64
	});
90
	});
65
	
91
 
66
	$("button.download_indent").live('click', function(){
92
	$("button.download_indent").live('click', function() {
67
		downloadIndent();
93
		downloadIndent();
68
	})
94
	})
69
 
95
 
70
	$("#entire-catalog-table input").live({
96
	$(document).on('change', "#entire-catalog-table input",
71
		change : function() {
97
						function() {
72
			var catalogId = parseInt($(this).data("catalog-id"));
98
							var catalogId = parseInt($(this).data("catalog-id"));
73
			var sellingPrice = parseInt($(this).data("selling-price"));
99
							var sellingPrice = parseInt($(this).data(
-
 
100
									"selling-price"));
74
			var quantity = parseInt($(this).val());
101
							var quantity = parseInt($(this).val());
75
			if (quantity > 10) {
102
							if (quantity > 10) {
76
				alert("Quantity should not be above 10");
103
								alert("Quantity should not be above 10");
77
				if (catalogId in indentMap) {
104
								if (catalogId in indentMap) {
78
					$(this).val(indentMap[catalogId].quantity);
105
									$(this).val(indentMap[catalogId].quantity);
79
				} else {
106
								} else {
80
					$(this).val(0);
107
									$(this).val(0);
81
				}
-
 
82
				return;
-
 
83
			}
-
 
84
			description = $(this).data("description");
-
 
85
			if (catalogId in indentMap) {
-
 
86
				indentMap[catalogId]["quantity"] = quantity;
-
 
87
				indentMap[catalogId]["sellingPrice"] = sellingPrice;
-
 
88
				indentMap[catalogId]["description"] = description;
-
 
89
				indentMap[catalogId]["catalogId"] = catalogId;
-
 
90
				indentMap[catalogId]["diff"] =  quantity - indentMap[catalogId]["initialQuantity"];
-
 
91
			} else {
-
 
92
				indentMap[catalogId] = {
-
 
93
					"quantity" : quantity,
-
 
94
					"sellingPrice" : sellingPrice,
-
 
95
					"description" : description,
-
 
96
					"catalogId" : catalogId,
-
 
97
					"initialQuantity" : 0,
-
 
98
					"diff" : quantity
-
 
99
				};
-
 
100
			}
-
 
101
			populateIndentSummary();
-
 
102
		}
-
 
103
	});
-
 
104
	$("button.mk_submit_indent")
-
 
105
			.live(
-
 
106
					'click',
-
 
107
					function() {
-
 
108
						confirmString = [];
-
 
109
						confirmString
-
 
110
								.push('<table class="table table-striped table-condensed table-bordered" id="entire-catalog-table">');
-
 
111
						confirmString.push('<tr>');
-
 
112
						confirmString.push('<th style="width:100px">Catalog Id</th>');
-
 
113
						confirmString.push('<th style="width:250px">Description</th>');
-
 
114
						confirmString.push('<th style="width:150px">Unit Price</th>');
-
 
115
						confirmString.push('<th style="width:150px">Quantity</th>');
-
 
116
						confirmString.push('<th style="width:200px">Item total</th>');
-
 
117
						confirmString.push('</tr>');
-
 
118
						changedItemIds.forEach(function(itemId){
-
 
119
							confirmString.push('<tr style="background-color:#9C7D7E">');
-
 
120
							confirmString.push('<td>' + itemId + '</td>');
-
 
121
							confirmString.push('<td>'
-
 
122
									+ indentMap[itemId].description
-
 
123
									+ '</td>');
-
 
124
							confirmString
-
 
125
							.push('<td style="text-align:left">'
-
 
126
									+ numberToComma(indentMap[itemId].sellingPrice)
-
 
127
									+ '</td>');
-
 
128
							confirmString
-
 
129
							.push('<td style="text-align:left">'
-
 
130
									+ indentMap[itemId].quantity + '(' + (indentMap[itemId].diff > 0 ? '+' : '-') + Math.abs(indentMap[itemId].diff) 
-
 
131
									+ ' pcs)</td>');
-
 
132
							confirmString
-
 
133
							.push('<td style="text-align:left">'
-
 
134
									+ numberToComma(indentMap[itemId].quantity
-
 
135
											* indentMap[itemId].sellingPrice)
-
 
136
											+ '</td>');
-
 
137
							confirmString.push('</tr>');
-
 
138
						});
108
								}
139
						for ( var itemId in indentMap) {
-
 
140
							if (itemId.indexOf(changedItemIds) > 0){
-
 
141
								continue;
109
								return;
142
							}
110
							}
143
							if (indentMap[itemId].quantity > 0) {
-
 
144
								confirmString.push('<tr>');
111
							brandName = $(this).data("brand-name");
145
								confirmString.push('<td>' + itemId + '</td>');
-
 
146
								confirmString.push('<td>'
-
 
147
										+ indentMap[itemId].description
112
							description = $(this).data("description");
148
										+ '</td>');
-
 
149
								confirmString
-
 
150
										.push('<td style="text-align:left">'
-
 
151
												+ numberToComma(indentMap[itemId].sellingPrice)
-
 
152
												+ '</td>');
-
 
153
								confirmString
-
 
154
										.push('<td style="text-align:left">'
-
 
155
												+ indentMap[itemId].quantity
113
							if (!(brandName in indentMap)) {
156
												+ '</td>');
-
 
157
								confirmString
-
 
158
										.push('<td style="text-align:left">'
-
 
159
												+ numberToComma(indentMap[itemId].quantity
-
 
160
														* indentMap[itemId].sellingPrice)
114
								indentMap[brandName] = {};
161
												+ '</td>');
-
 
162
								confirmString.push('</tr>');
-
 
163
							}
115
							}
-
 
116
							if (catalogId in indentMap[brandName]) {
-
 
117
								indentMap[brandName][catalogId]["quantity"] = quantity;
-
 
118
								indentMap[brandName][catalogId]["sellingPrice"] = sellingPrice;
-
 
119
								indentMap[brandName][catalogId]["description"] = description;
-
 
120
								indentMap[brandName][catalogId]["catalogId"] = catalogId;
-
 
121
								indentMap[brandName][catalogId]["diff"] = quantity
-
 
122
										- indentMap[brandName][catalogId]["initialQuantity"];
-
 
123
							} else {
-
 
124
								indentMap[brandName][catalogId] = {
-
 
125
									"quantity" : quantity,
-
 
126
									"sellingPrice" : sellingPrice,
-
 
127
									"description" : description,
-
 
128
									"catalogId" : catalogId,
-
 
129
									"initialQuantity" : 0,
-
 
130
									"diff" : quantity
-
 
131
								};
164
						}
132
							}
-
 
133
 
165
						confirmString.push('</table>');
134
							console.log(indentMap);
-
 
135
							
-
 
136
							doPostAjaxRequestHandler(context
166
						$('#indent-container1').html(confirmString.join(''))
137
									+ "/open-indent/save?catalogId="+catalogId+"&itemQty="+quantity
-
 
138
									, function(response) {
-
 
139
								console.log(response);
-
 
140
								if (response == 'true') {
-
 
141
								}
167
								.show();
142
							});
168
						$('#indent-container').hide();
143
							populateIndentSummary();
-
 
144
				});
-
 
145
	
-
 
146
 
-
 
147
 
-
 
148
	
-
 
149
	 /*
169
						$('button.mk_submit_indent').hide();
150
		 * $("button.mk_submit_indent") .live( 'click', function() {
-
 
151
		 * confirmString =[]; confirmString .push('<table class="table
-
 
152
		 * table-striped table-condensed table-bordered"
-
 
153
		 * id="entire-catalog-table">'); confirmString.push('<tr>');
-
 
154
		 * confirmString .push('<th style="width:100px">Catalog Id</th>');
-
 
155
		 * confirmString .push('<th style="width:250px">Description</th>');
-
 
156
		 * confirmString .push('<th style="width:150px">Unit Price</th>');
-
 
157
		 * confirmString .push('<th style="width:150px">Quantity</th>');
-
 
158
		 * confirmString .push('<th style="width:200px">Item total</th>');
-
 
159
		 * confirmString.push('</tr>'); changedItemIds
-
 
160
		 * .forEach(function(itemId) {
-
 
161
		 * 
-
 
162
		 * confirmString .push('<tr style="background-color:#9C7D7E">');
-
 
163
		 * confirmString.push('<td>' + itemId + '</td>');
-
 
164
		 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
-
 
165
		 * confirmString .push('<td style="text-align:left">' +
-
 
166
		 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
-
 
167
		 * confirmString.push('<td style="text-align:left">' +
-
 
168
		 * indentMap[itemId].quantity + '(' +(indentMap[itemId].diff > 0 ? '+' :
-
 
169
		 * '-') + Math.abs(indentMap[itemId].diff) + ' pcs)</td>');
-
 
170
		 * confirmString .push('<td style="text-align:left">'
-
 
171
		 * +numberToComma(indentMap[itemId].quantity,
-
 
172
		 * indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>');
-
 
173
		 * });
-
 
174
		 * 
-
 
175
		 * 
-
 
176
		 * 
-
 
177
		 * for ( var itemId in indentMap) { if(itemId.indexOf(changedItemIds) >
-
 
178
		 * 0) { continue; } if(indentMap[itemId].quantity > 0) {
-
 
179
		 * confirmString.push('<tr>'); confirmString.push('<td>' + itemId + '</td>');
-
 
180
		 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
-
 
181
		 * confirmString .push('<td style="text-align:left">' +
-
 
182
		 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
-
 
183
		 * confirmString.push('<td style="text-align:left">' +
-
 
184
		 * indentMap[itemId].quantity + '</td>'); confirmString .push('<td style="text-align:left">' +
-
 
185
		 * numberToComma(indentMap[itemId].quantity
-
 
186
		 * ,indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>'); } }
-
 
187
		 * confirmString.push('</table>');
-
 
188
		 * $('#indent-container1').html(confirmString.join('')) .show();
-
 
189
		 * $('#indent-container').hide(); $('button.mk_submit_indent').hide();
170
						$('button.bk_toedit_indent').show();
190
		 * $('button.bk_toedit_indent').show();
171
						$('button.confirm_indent').show();
191
		 * $('button.confirm_indent').show();
-
 
192
		 */
-
 
193
		  /*
-
 
194
			 * $("button.confirm_indent").live( 'click', function() { var
-
 
195
			 * itemQtyList = []; for (catalogId in indentMap) { diff =
-
 
196
			 * indentMap[catalogId]["quantity"] -
-
 
197
			 * indentMap[catalogId]["initialQuantity"]; if (diff != 0) {
-
 
198
			 * itemQtyList.push({ "quantity" : indentMap[catalogId]["quantity"],
-
 
199
			 * "catalogId" : indentMap[catalogId]["catalogId"] }); } }
-
 
200
			 * doPostAjaxRequestWithJsonHandler(context +
-
 
201
			 * "/open-indent/save?fofoId=" + currentFofoId + "&counxterSize=" +
-
 
202
			 * counterSize, JSON .stringify(itemQtyList), function(data) {
-
 
203
			 * alert('Indent has been created Successfully!'); indentMap = {};
-
 
204
			 * loadIndent('main-content'); }); });
172
					});
205
			 */
-
 
206
	
173
	$("button.confirm_indent").live(
207
	$(".confirm_indent").live(
174
			'click',
208
			'click',
175
			function() {
209
			function() {
176
				var itemQtyList = [];
-
 
177
				for (catalogId in indentMap) {
210
			  if(confirm("Are you sure to confirm the indent")== true){
178
					diff = indentMap[catalogId]["quantity"] - indentMap[catalogId]["initialQuantity"];
211
			 doPostAjaxRequestHandler(context + "/open-indent/confirm" ,
179
					if(diff!=0) {
212
			  function(response) { 
-
 
213
				  
180
						itemQtyList.push({
214
			  console.log(response); 
-
 
215
			  if (response =='true') { 
181
							"quantity" : indentMap[catalogId]["quantity"],
216
				  alert("successfully confirm"); 
182
							"catalogId" : indentMap[catalogId]["catalogId"]
217
				  loadIndent('main-content');
183
						});
218
			  } 
-
 
219
             }); 
184
					}
220
			 
185
				}
221
	
186
				doPostAjaxRequestWithJsonHandler(context + "/open-indent/save?fofoId=" + currentFofoId + "&counterSize=" + counterSize,
-
 
187
						JSON.stringify(itemQtyList), function(data) {
-
 
188
							alert('Indent has been created Successfully!');
-
 
189
							indentMap = {};
222
			  }
190
							loadIndent('main-content');
-
 
191
						});
223
 });
192
			});
224
		
-
 
225
	/*
193
	$("button.bk_toedit_indent").live('click', function() {
226
	 * $("button.bk_toedit_indent").live('click', function() {
194
		$('button.bk_toedit_indent').hide();
227
	 * $('button.bk_toedit_indent').hide(); $('button.confirm_indent').hide();
195
		$('button.confirm_indent').hide();
-
 
196
		$('button.mk_submit_indent').show();
228
	 * $('button.mk_submit_indent').show(); $('#indent-container1').hide();
197
		$('#indent-container1').hide();
-
 
198
		$('#indent-container').show();
229
	 * $('#indent-container').show();
199
 
230
	 * 
200
	});
231
	 * });
-
 
232
	 */
201
 
233
 
202
});
234
});
203
 
235
 
204
function populateIndentSummary() {
236
function populateIndentSummary() {
205
	var totalQty = 0;
237
	$planSummary = $("#plansummary");
-
 
238
 
206
	var totalAmount = 0;
239
	$planSummary.html('');
207
	var totalItems = 0;
240
	changedItemIds=[];
208
	var arr = [];
241
	htmArr = [];
209
	changedItemIds = [];
242
	$('button.confirm_indent').hide();
210
	arr[0]=[0,0,0];
243
	for ( var brandName in indentMap) {
-
 
244
 
211
	arr[1]=[0,0,0];
245
		
212
	arr[2]=[0,0,0];
246
		allZero = true;
213
	arr[3]=[0,0,0];
247
		trArray = [];
214
 
248
	
215
	for ( var itemId in indentMap) {
249
		for ( var itemId in indentMap[brandName]) {
216
		var itemQty = indentMap[itemId]['quantity'];
250
			var description = indentMap[brandName][itemId]['description'];
-
 
251
 
217
		var previousItemQty = indentMap[itemId]['initialQuantity'];
252
			var itemQty = indentMap[brandName][itemId]['quantity'];
218
		var sellingPrcice = indentMap[itemId]['sellingPrice'];
-
 
219
		if(previousItemQty !=0) {
-
 
220
			arr[0][0]++;
-
 
221
		}
253
			
222
		if(itemQty !=0) {
254
			if (itemQty != 0) {
223
			arr[3][0]++;
255
				allZero = false;
224
		}
256
				
225
		var diff = itemQty - previousItemQty;
-
 
226
		arr[0][1] += previousItemQty;
-
 
227
		arr[0][2] += previousItemQty* sellingPrcice;
-
 
228
		arr[3][1] += itemQty;
257
				trString = `<tr>
229
		arr[3][2] += itemQty * sellingPrcice;
258
							<td style = "width:90%">${description}</td>
230
		if (diff != 0) {
-
 
231
			changedItemIds.push(itemId);
259
							<td>${itemQty}</td>
232
			if (diff > 0) {
-
 
233
				arr[1][0]++;
260
						</tr>`;
234
				arr[1][1] += diff;
261
				trArray.push(trString);
235
				arr[1][2] += (diff) * sellingPrcice;
-
 
236
			} else {
262
				
237
				arr[2][0]++;
263
			} 
238
				arr[2][1] += diff;
-
 
239
				arr[2][2] += diff * sellingPrcice;
-
 
240
			}
264
			
-
 
265
 
241
		}
266
		}
242
	}
-
 
243
	totalQty = arr[3][1];
-
 
244
	if (totalQty === 0) {
267
		if(!allZero) {
245
		$('button.mk_submit_indent').hide();
268
			$('button.confirm_indent').show();
246
	} else {
269
			htmArr.push('<div>');
-
 
270
			htmArr.push('<h4>' + brandName + '</h4>');
-
 
271
			htmArr.push('<table class="table table-condensed">');
247
		$('button.mk_submit_indent').show();
272
			htmArr.push(trArray.join(' '));
248
	}
273
			
249
	$("#summary-table").find("td").each(function(index, ele){
-
 
250
		if(index%3==2){
274
			htmArr.push('</table>');
251
			$(ele).html(numberToComma(arr[Math.floor(index/3)][2]));
275
			htmArr.push('</div>');
-
 
276
		
252
		}else{
277
			
253
			$(ele).html(arr[Math.floor(index/3)][index%3]);
-
 
254
		}
278
		}
255
		
279
		
256
	});
280
	}
-
 
281
 
-
 
282
	$planSummary.html(htmArr.join(""));
257
}
283
}
258
function loadIndent(domId) {
284
function loadIndent(domId) {
259
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize=" + counterSize;
285
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize="
-
 
286
			+ counterSize;
260
	doAjaxRequestHandler(context + url, "GET", function(response) {
287
	doAjaxRequestHandler(context + url, "GET", function(response) {{}
261
		$('#' + domId).html(response);
288
		$('#' + domId).html(response);
262
	});
289
	});
263
}
290
}
264
function downloadIndent() {
291
function downloadIndent() {
265
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize=" + counterSize;
292
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize="
-
 
293
			+ counterSize;
266
	doAjaxGetDownload(url, "indent.csv")
294
	doAjaxGetDownload(url, "indent.csv")
267
}
295
}
268
function raisePO(){
296
function raisePO() {
269
	doPostAjaxRequestWithJsonHandler(context+"/indent/create-po", {}, function(response) {
297
	doPostAjaxRequestWithJsonHandler(context + "/indent/create-po", {},
-
 
298
			function(response) {
270
		if(response) {
299
				if (response) {
271
			alert("PO Created Successfully");
300
					alert("PO Created Successfully");
272
			$('a.allocation_po').click();								
301
					$('a.allocation_po').click();
273
		} else {
302
				} else {
274
			alert("Problem while creating PO");
303
					alert("Problem while creating PO");
275
		}
304
				}
276
	});
305
			});
277
	
306
 
278
}
307
}
279
308