Subversion Repositories SmartDukaan

Rev

Rev 25721 | Rev 26131 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23405 amit.gupta 1
$(function() {
25721 tejbeer 2
	$(document).on('click',"a.allocation_po", function() {
3
		currentFofoId = 0;
4
		counterSize = '';
23786 amit.gupta 5
		loadIndent('main-content');
6
	});
25721 tejbeer 7
	$("button.mk_pause_button")
8
			.live(
9
					'click',
10
					function() {
11
						var clickedButton = $(this);
12
 
13
						var description = clickedButton.data("description");
14
						var catalogId = clickedButton.data("id");
15
						getColorsForItems(
16
								catalogId,
17
								0,
18
								"Active/pause " + description,
19
								function(itemIds) {
20
									console.log(itemIds);
21
									if (itemIds != null) {
22
										bootbox
23
												.confirm(
24
														"Confirm Update "
25
																+ clickedButton
26
																		.data("description")
27
																+ "?",
28
														function(result) {
29
															if (result) {
30
																coloredItems
31
																		.forEach(function(
32
																				item) {
33
																			item.active = itemIds
34
																					.indexOf(item.id
35
																							+ "") >= 0;
36
																			console
37
																					.log(coloredItems)
38
																		});
39
 
40
																doPostAjaxRequestWithJsonHandler(
41
																		context
42
																				+ "/indent/confirm-pause/",
43
																		JSON
44
																				.stringify(coloredItems),
45
																		function(
46
																				response) {
47
																			if (response) {
48
																				bootbox
49
																						.alert("Item/s  Updated Successfully");
50
																			} else {
51
																				bootbox
52
																						.alert("Could not pause item");
53
																			}
54
 
55
																		});
56
															}
57
														});
58
									}
59
								});
60
					});
61
	$("button.raise_po").live('click', function() {
23796 amit.gupta 62
		if (confirm("Please confirm the PO")) {
63
			raisePO();
64
		} else {
65
			return;
66
		}
67
	});
25721 tejbeer 68
	$("li.mk_counter_size").live('click', function() {
69
		if ($(this).hasClass('active')) {
23786 amit.gupta 70
			return;
71
		}
72
		currentFofoId = 0;
25721 tejbeer 73
		counterSize = $(this).find('a').html();
23786 amit.gupta 74
		loadIndent('main-content');
75
	});
25721 tejbeer 76
	$("li.brandLi").live('click', function() {
77
		if (!$(this).hasClass('active')) {
23786 amit.gupta 78
			$("table.brandPerformance").toggle();
79
			$("li.brandLi").removeClass('active');
80
			$(this).addClass('active');
81
		}
82
	});
25721 tejbeer 83
	$(document).on('click','a.create_indent',  function() {
84
		currentFofoId = 0;
85
		counterSize = '';
23405 amit.gupta 86
		loadIndent("main-content");
87
	});
23786 amit.gupta 88
	$("button.create_indent").live('click', function() {
89
		loadIndent("main-content");
90
	});
25721 tejbeer 91
 
92
	$("button.download_indent").live('click', function() {
24229 amit.gupta 93
		downloadIndent();
94
	})
23786 amit.gupta 95
 
25721 tejbeer 96
	$(document).on('change', "#entire-catalog-table input",
97
						function() {
98
							var catalogId = parseInt($(this).data("catalog-id"));
99
							var sellingPrice = parseInt($(this).data(
100
									"selling-price"));
101
							var quantity = parseInt($(this).val());
102
							if (quantity > 10) {
103
								alert("Quantity should not be above 10");
104
								if (catalogId in indentMap) {
105
									$(this).val(indentMap[catalogId].quantity);
106
								} else {
107
									$(this).val(0);
108
								}
109
								return;
23786 amit.gupta 110
							}
25721 tejbeer 111
							brandName = $(this).data("brand-name");
112
							description = $(this).data("description");
113
							if (!(brandName in indentMap)) {
114
								indentMap[brandName] = {};
23786 amit.gupta 115
							}
25721 tejbeer 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
								};
132
							}
133
 
134
							console.log(indentMap);
135
 
136
							doPostAjaxRequestHandler(context
137
									+ "/open-indent/save?catalogId="+catalogId+"&itemQty="+quantity
138
									, function(response) {
139
								console.log(response);
140
								if (response == 'true') {
141
								}
142
							});
143
							populateIndentSummary();
144
				});
145
 
146
 
147
 
148
 
149
	 /*
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();
190
		 * $('button.bk_toedit_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'); }); });
205
			 */
206
 
207
	$(".confirm_indent").live(
23786 amit.gupta 208
			'click',
209
			function() {
25721 tejbeer 210
			  if(confirm("Are you sure to confirm the indent")== true){
211
			 doPostAjaxRequestHandler(context + "/open-indent/confirm" ,
212
			  function(response) { 
213
 
214
			  console.log(response); 
215
			  if (response =='true') { 
216
				  alert("successfully confirm"); 
217
				  loadIndent('main-content');
218
			  } 
219
             }); 
220
 
221
 
222
			  }
223
 });
224
 
225
	/*
226
	 * $("button.bk_toedit_indent").live('click', function() {
227
	 * $('button.bk_toedit_indent').hide(); $('button.confirm_indent').hide();
228
	 * $('button.mk_submit_indent').show(); $('#indent-container1').hide();
229
	 * $('#indent-container').show();
230
	 * 
231
	 * });
232
	 */
23786 amit.gupta 233
 
23405 amit.gupta 234
});
235
 
23786 amit.gupta 236
function populateIndentSummary() {
25721 tejbeer 237
	$planSummary = $("#plansummary");
23786 amit.gupta 238
 
25721 tejbeer 239
	$planSummary.html('');
240
	changedItemIds=[];
241
	htmArr = [];
242
	$('button.confirm_indent').hide();
243
	for ( var brandName in indentMap) {
244
 
245
 
246
		allZero = true;
247
		trArray = [];
248
 
249
		for ( var itemId in indentMap[brandName]) {
250
			var description = indentMap[brandName][itemId]['description'];
251
 
252
			var itemQty = indentMap[brandName][itemId]['quantity'];
25736 tejbeer 253
 
25721 tejbeer 254
 
25736 tejbeer 255
			var sellingPrice = indentMap [brandName][itemId]['sellingPrice'];
256
			  var sellPrice = itemQty*sellingPrice;
257
 
25721 tejbeer 258
			if (itemQty != 0) {
259
				allZero = false;
260
 
261
				trString = `<tr>
25736 tejbeer 262
							<td style = "width:80%">${description}</td>
25721 tejbeer 263
							<td>${itemQty}</td>
25736 tejbeer 264
							<td class ="currency" >${sellPrice}</td>
265
						</tr>`
25721 tejbeer 266
				trArray.push(trString);
267
 
268
			} 
269
 
270
 
23786 amit.gupta 271
		}
25721 tejbeer 272
		if(!allZero) {
273
			$('button.confirm_indent').show();
274
			htmArr.push('<div>');
275
			htmArr.push('<h4>' + brandName + '</h4>');
25736 tejbeer 276
			htmArr.push('<table class="table table-condensed" id = "planning-table">');
25721 tejbeer 277
			htmArr.push(trArray.join(' '));
278
			htmArr.push('</table>');
279
			htmArr.push('</div>');
280
 
281
 
23786 amit.gupta 282
		}
25736 tejbeer 283
 
23405 amit.gupta 284
	}
25721 tejbeer 285
 
25736 tejbeer 286
 
287
 
288
 
289
 
25721 tejbeer 290
	$planSummary.html(htmArr.join(""));
25736 tejbeer 291
	var total= 0;
292
	$('#planning-table tr').each(function() {
293
 
294
 
295
		 var value = parseInt($('td', this).eq(2).text());
296
		 if (!isNaN(value)) {
297
             total += value;
298
         }
299
 
300
         console.log(total);
301
 
302
	 });
303
 
304
	divString = `<div style ="float:right"><b>Total:-</b><span class="currency">${total}</span></div>`
305
	 htmArr.push(divString);
306
	 	 $planSummary.html(htmArr.join(""));
307
 
308
 
309
	// $('#planning-table tfoot td').eq(2).text('Total: ' + total);
310
 
23405 amit.gupta 311
}
23786 amit.gupta 312
function loadIndent(domId) {
25721 tejbeer 313
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize="
314
			+ counterSize;
315
	doAjaxRequestHandler(context + url, "GET", function(response) {{}
23405 amit.gupta 316
		$('#' + domId).html(response);
317
	});
318
}
24229 amit.gupta 319
function downloadIndent() {
25721 tejbeer 320
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize="
321
			+ counterSize;
24229 amit.gupta 322
	doAjaxGetDownload(url, "indent.csv")
23796 amit.gupta 323
}
25721 tejbeer 324
function raisePO() {
325
	doPostAjaxRequestWithJsonHandler(context + "/indent/create-po", {},
326
			function(response) {
327
				if (response) {
328
					alert("PO Created Successfully");
329
					$('a.allocation_po').click();
330
				} else {
331
					alert("Problem while creating PO");
332
				}
333
			});
334
 
23405 amit.gupta 335
}