Subversion Repositories SmartDukaan

Rev

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