Subversion Repositories SmartDukaan

Rev

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