Subversion Repositories SmartDukaan

Rev

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