Subversion Repositories SmartDukaan

Rev

Rev 26131 | Rev 26721 | 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
	});
26131 tejbeer 68
 
25721 tejbeer 69
	$("li.mk_counter_size").live('click', function() {
70
		if ($(this).hasClass('active')) {
23786 amit.gupta 71
			return;
72
		}
73
		currentFofoId = 0;
25721 tejbeer 74
		counterSize = $(this).find('a').html();
23786 amit.gupta 75
		loadIndent('main-content');
76
	});
25721 tejbeer 77
	$("li.brandLi").live('click', function() {
78
		if (!$(this).hasClass('active')) {
23786 amit.gupta 79
			$("table.brandPerformance").toggle();
80
			$("li.brandLi").removeClass('active');
81
			$(this).addClass('active');
82
		}
83
	});
26131 tejbeer 84
 
85
	$(".previous-month").live('click',function(){
86
		currentFofoId = 0;
87
		counterSize = '';
88
		loadPreviousMonthIndent('main-content');
89
	});
90
 
91
	$(".current-month").live('click',function(){
92
		currentFofoId = 0;
93
		counterSize = '';
94
		loadIndent('main-content');
95
	});
25721 tejbeer 96
	$(document).on('click','a.create_indent',  function() {
97
		currentFofoId = 0;
98
		counterSize = '';
23405 amit.gupta 99
		loadIndent("main-content");
100
	});
23786 amit.gupta 101
	$("button.create_indent").live('click', function() {
102
		loadIndent("main-content");
103
	});
25721 tejbeer 104
 
105
	$("button.download_indent").live('click', function() {
24229 amit.gupta 106
		downloadIndent();
107
	})
23786 amit.gupta 108
 
25721 tejbeer 109
	$(document).on('change', "#entire-catalog-table input",
110
						function() {
111
							var catalogId = parseInt($(this).data("catalog-id"));
112
							var sellingPrice = parseInt($(this).data(
113
									"selling-price"));
114
							var quantity = parseInt($(this).val());
26293 tejbeer 115
							if (quantity > 40) {
116
								alert("Quantity should not be above 40");
25721 tejbeer 117
								if (catalogId in indentMap) {
118
									$(this).val(indentMap[catalogId].quantity);
119
								} else {
120
									$(this).val(0);
121
								}
122
								return;
23786 amit.gupta 123
							}
25721 tejbeer 124
							brandName = $(this).data("brand-name");
125
							description = $(this).data("description");
126
							if (!(brandName in indentMap)) {
127
								indentMap[brandName] = {};
23786 amit.gupta 128
							}
25721 tejbeer 129
							if (catalogId in indentMap[brandName]) {
130
								indentMap[brandName][catalogId]["quantity"] = quantity;
131
								indentMap[brandName][catalogId]["sellingPrice"] = sellingPrice;
132
								indentMap[brandName][catalogId]["description"] = description;
133
								indentMap[brandName][catalogId]["catalogId"] = catalogId;
134
								indentMap[brandName][catalogId]["diff"] = quantity
135
										- indentMap[brandName][catalogId]["initialQuantity"];
136
							} else {
137
								indentMap[brandName][catalogId] = {
138
									"quantity" : quantity,
139
									"sellingPrice" : sellingPrice,
140
									"description" : description,
141
									"catalogId" : catalogId,
142
									"initialQuantity" : 0,
143
									"diff" : quantity
144
								};
145
							}
146
 
147
							console.log(indentMap);
148
 
149
							doPostAjaxRequestHandler(context
150
									+ "/open-indent/save?catalogId="+catalogId+"&itemQty="+quantity
151
									, function(response) {
152
								console.log(response);
153
								if (response == 'true') {
154
								}
155
							});
156
							populateIndentSummary();
157
				});
158
 
159
 
160
 
161
 
162
	 /*
163
		 * $("button.mk_submit_indent") .live( 'click', function() {
164
		 * confirmString =[]; confirmString .push('<table class="table
165
		 * table-striped table-condensed table-bordered"
166
		 * id="entire-catalog-table">'); confirmString.push('<tr>');
167
		 * confirmString .push('<th style="width:100px">Catalog Id</th>');
168
		 * confirmString .push('<th style="width:250px">Description</th>');
169
		 * confirmString .push('<th style="width:150px">Unit Price</th>');
170
		 * confirmString .push('<th style="width:150px">Quantity</th>');
171
		 * confirmString .push('<th style="width:200px">Item total</th>');
172
		 * confirmString.push('</tr>'); changedItemIds
173
		 * .forEach(function(itemId) {
174
		 * 
175
		 * confirmString .push('<tr style="background-color:#9C7D7E">');
176
		 * confirmString.push('<td>' + itemId + '</td>');
177
		 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
178
		 * confirmString .push('<td style="text-align:left">' +
179
		 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
180
		 * confirmString.push('<td style="text-align:left">' +
181
		 * indentMap[itemId].quantity + '(' +(indentMap[itemId].diff > 0 ? '+' :
182
		 * '-') + Math.abs(indentMap[itemId].diff) + ' pcs)</td>');
183
		 * confirmString .push('<td style="text-align:left">'
184
		 * +numberToComma(indentMap[itemId].quantity,
185
		 * indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>');
186
		 * });
187
		 * 
188
		 * 
189
		 * 
190
		 * for ( var itemId in indentMap) { if(itemId.indexOf(changedItemIds) >
191
		 * 0) { continue; } if(indentMap[itemId].quantity > 0) {
192
		 * confirmString.push('<tr>'); confirmString.push('<td>' + itemId + '</td>');
193
		 * confirmString.push('<td>' +indentMap[itemId].description + '</td>');
194
		 * confirmString .push('<td style="text-align:left">' +
195
		 * numberToComma(indentMap[itemId].sellingPrice) + '</td>');
196
		 * confirmString.push('<td style="text-align:left">' +
197
		 * indentMap[itemId].quantity + '</td>'); confirmString .push('<td style="text-align:left">' +
198
		 * numberToComma(indentMap[itemId].quantity
199
		 * ,indentMap[itemId].sellingPrice) + '</td>'); confirmString.push('</tr>'); } }
200
		 * confirmString.push('</table>');
201
		 * $('#indent-container1').html(confirmString.join('')) .show();
202
		 * $('#indent-container').hide(); $('button.mk_submit_indent').hide();
203
		 * $('button.bk_toedit_indent').show();
204
		 * $('button.confirm_indent').show();
205
		 */
206
		  /*
207
			 * $("button.confirm_indent").live( 'click', function() { var
208
			 * itemQtyList = []; for (catalogId in indentMap) { diff =
209
			 * indentMap[catalogId]["quantity"] -
210
			 * indentMap[catalogId]["initialQuantity"]; if (diff != 0) {
211
			 * itemQtyList.push({ "quantity" : indentMap[catalogId]["quantity"],
212
			 * "catalogId" : indentMap[catalogId]["catalogId"] }); } }
213
			 * doPostAjaxRequestWithJsonHandler(context +
214
			 * "/open-indent/save?fofoId=" + currentFofoId + "&counxterSize=" +
215
			 * counterSize, JSON .stringify(itemQtyList), function(data) {
216
			 * alert('Indent has been created Successfully!'); indentMap = {};
217
			 * loadIndent('main-content'); }); });
218
			 */
219
 
220
	$(".confirm_indent").live(
23786 amit.gupta 221
			'click',
222
			function() {
25721 tejbeer 223
			  if(confirm("Are you sure to confirm the indent")== true){
224
			 doPostAjaxRequestHandler(context + "/open-indent/confirm" ,
225
			  function(response) { 
226
 
227
			  console.log(response); 
228
			  if (response =='true') { 
229
				  alert("successfully confirm"); 
230
				  loadIndent('main-content');
231
			  } 
232
             }); 
233
 
234
 
235
			  }
236
 });
237
 
238
	/*
239
	 * $("button.bk_toedit_indent").live('click', function() {
240
	 * $('button.bk_toedit_indent').hide(); $('button.confirm_indent').hide();
241
	 * $('button.mk_submit_indent').show(); $('#indent-container1').hide();
242
	 * $('#indent-container').show();
243
	 * 
244
	 * });
245
	 */
23786 amit.gupta 246
 
23405 amit.gupta 247
});
248
 
23786 amit.gupta 249
function populateIndentSummary() {
25721 tejbeer 250
	$planSummary = $("#plansummary");
23786 amit.gupta 251
 
25721 tejbeer 252
	$planSummary.html('');
253
	changedItemIds=[];
254
	htmArr = [];
255
	$('button.confirm_indent').hide();
256
	for ( var brandName in indentMap) {
257
 
258
 
259
		allZero = true;
260
		trArray = [];
261
 
262
		for ( var itemId in indentMap[brandName]) {
263
			var description = indentMap[brandName][itemId]['description'];
264
 
265
			var itemQty = indentMap[brandName][itemId]['quantity'];
25736 tejbeer 266
 
25721 tejbeer 267
 
25736 tejbeer 268
			var sellingPrice = indentMap [brandName][itemId]['sellingPrice'];
269
			  var sellPrice = itemQty*sellingPrice;
270
 
25721 tejbeer 271
			if (itemQty != 0) {
272
				allZero = false;
273
 
274
				trString = `<tr>
25736 tejbeer 275
							<td style = "width:80%">${description}</td>
25721 tejbeer 276
							<td>${itemQty}</td>
25736 tejbeer 277
							<td class ="currency" >${sellPrice}</td>
278
						</tr>`
25721 tejbeer 279
				trArray.push(trString);
280
 
281
			} 
282
 
283
 
23786 amit.gupta 284
		}
25721 tejbeer 285
		if(!allZero) {
286
			$('button.confirm_indent').show();
287
			htmArr.push('<div>');
288
			htmArr.push('<h4>' + brandName + '</h4>');
25736 tejbeer 289
			htmArr.push('<table class="table table-condensed" id = "planning-table">');
25721 tejbeer 290
			htmArr.push(trArray.join(' '));
291
			htmArr.push('</table>');
292
			htmArr.push('</div>');
293
 
294
 
23786 amit.gupta 295
		}
25736 tejbeer 296
 
23405 amit.gupta 297
	}
25721 tejbeer 298
 
25736 tejbeer 299
 
300
 
301
 
302
 
25721 tejbeer 303
	$planSummary.html(htmArr.join(""));
25736 tejbeer 304
	var total= 0;
305
	$('#planning-table tr').each(function() {
306
 
307
 
308
		 var value = parseInt($('td', this).eq(2).text());
309
		 if (!isNaN(value)) {
310
             total += value;
311
         }
312
 
313
         console.log(total);
314
 
315
	 });
316
 
317
	divString = `<div style ="float:right"><b>Total:-</b><span class="currency">${total}</span></div>`
318
	 htmArr.push(divString);
319
	 	 $planSummary.html(htmArr.join(""));
320
 
321
 
322
	// $('#planning-table tfoot td').eq(2).text('Total: ' + total);
323
 
23405 amit.gupta 324
}
23786 amit.gupta 325
function loadIndent(domId) {
25721 tejbeer 326
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize="
327
			+ counterSize;
328
	doAjaxRequestHandler(context + url, "GET", function(response) {{}
23405 amit.gupta 329
		$('#' + domId).html(response);
330
	});
331
}
26131 tejbeer 332
 
333
function loadPreviousMonthIndent(domId) {
334
	var url = "/indent/loadIndentPreviousMonth?fofoId=" + currentFofoId + "&counterSize="
335
			+ counterSize;
336
	doAjaxRequestHandler(context + url, "GET", function(response) {{}
337
		$('#' + domId).html(response);
338
	});
339
}
24229 amit.gupta 340
function downloadIndent() {
25721 tejbeer 341
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize="
342
			+ counterSize;
24229 amit.gupta 343
	doAjaxGetDownload(url, "indent.csv")
23796 amit.gupta 344
}
25721 tejbeer 345
function raisePO() {
346
	doPostAjaxRequestWithJsonHandler(context + "/indent/create-po", {},
347
			function(response) {
348
				if (response) {
349
					alert("PO Created Successfully");
350
					$('a.allocation_po').click();
351
				} else {
352
					alert("Problem while creating PO");
353
				}
354
			});
355
 
23405 amit.gupta 356
}