Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
30017 amit.gupta 1
$(function () {
2
	$(document).on('click', "a.allocation_po", function () {
25721 tejbeer 3
		currentFofoId = 0;
4
		counterSize = '';
23786 amit.gupta 5
		loadIndent('main-content');
6
	});
30017 amit.gupta 7
 
27755 amit.gupta 8
	$(document).on('click', ".partners_allocation",
30017 amit.gupta 9
		function () {
26721 tejbeer 10
 
30017 amit.gupta 11
			doGetAjaxRequestHandler(context + "/getPartnerAllocation", function (response) {
12
				$('#' + 'main-content').html(response);
13
 
26721 tejbeer 14
			});
30017 amit.gupta 15
 
16
		});
17
 
27755 amit.gupta 18
	$(document).on('click', ".partnerAllocation",
30017 amit.gupta 19
		function () {
20
 
21
			var fofoId = $('#fofo-users').val()
22
			console.log(fofoId)
23
			var url = "/indent/loadIndent?fofoId=" + fofoId + "&counterSize="
26721 tejbeer 24
				+ "TEN_LAC";
30017 amit.gupta 25
			doAjaxRequestHandler(context + url, "GET", function (response) {
26
				{
27
				}
28
 
29
 
30
				$('.partner-indent-container').html(response);
26721 tejbeer 31
			});
30017 amit.gupta 32
		});
33
 
34
 
27755 amit.gupta 35
	$(document).on('click', "button.mk_pause_button",
30017 amit.gupta 36
		function () {
37
			var clickedButton = $(this);
25721 tejbeer 38
 
30017 amit.gupta 39
			var description = clickedButton.data("description");
40
			var catalogId = clickedButton.data("id");
41
			getColorsForItems(
42
				catalogId,
43
				0,
44
				"Active/pause " + description,
45
				function (itemIds) {
46
					console.log(itemIds);
47
					if (itemIds != null) {
48
						bootbox
49
							.confirm(
50
								"Confirm Update "
51
								+ clickedButton
52
									.data("description")
53
								+ "?",
54
								function (result) {
55
									console.log(result)
56
									if (result) {
57
										coloredItems
58
											.forEach(function (
59
												item) {
60
												item.active = itemIds
61
													.indexOf(item.id
62
														+ "") >= 0;
63
												console
64
													.log(coloredItems)
65
											});
25721 tejbeer 66
 
30017 amit.gupta 67
										doPostAjaxRequestWithJsonHandler(
68
											context
69
											+ "/indent/confirm-pause/",
70
											JSON
71
												.stringify(coloredItems),
72
											function (
73
												response) {
74
												if (response) {
75
													bootbox
76
														.alert("Item/s  Updated Successfully");
77
												} else {
78
													bootbox
79
														.alert("Could not pause item");
80
												}
25721 tejbeer 81
 
30017 amit.gupta 82
											});
25721 tejbeer 83
									}
84
								});
30017 amit.gupta 85
					}
86
				});
87
		});
88
	$(document).on('click', "button.raise_po", function () {
23796 amit.gupta 89
		if (confirm("Please confirm the PO")) {
90
			raisePO();
91
		} else {
92
			return;
93
		}
94
	});
26131 tejbeer 95
 
30017 amit.gupta 96
	$(document).on('click', "li.mk_counter_size", function () {
25721 tejbeer 97
		if ($(this).hasClass('active')) {
23786 amit.gupta 98
			return;
99
		}
100
		currentFofoId = 0;
25721 tejbeer 101
		counterSize = $(this).find('a').html();
23786 amit.gupta 102
		loadIndent('main-content');
103
	});
30017 amit.gupta 104
	$(document).on('click', "li.brandLi", function () {
25721 tejbeer 105
		if (!$(this).hasClass('active')) {
23786 amit.gupta 106
			$("table.brandPerformance").toggle();
107
			$("li.brandLi").removeClass('active');
108
			$(this).addClass('active');
109
		}
110
	});
30017 amit.gupta 111
 
112
	$(document).on('click', ".previous-month", function () {
26131 tejbeer 113
		currentFofoId = 0;
114
		counterSize = '';
115
		loadPreviousMonthIndent('main-content');
116
	});
30017 amit.gupta 117
 
118
	$(document).on('click', ".current-month", function () {
26131 tejbeer 119
		currentFofoId = 0;
120
		counterSize = '';
121
		loadIndent('main-content');
122
	});
30017 amit.gupta 123
	$(document).on('click', 'a.create_indent', function () {
25721 tejbeer 124
		currentFofoId = 0;
125
		counterSize = '';
23405 amit.gupta 126
		loadIndent("main-content");
127
	});
30017 amit.gupta 128
	$(document).on('click', "button.create_indent", function () {
23786 amit.gupta 129
		loadIndent("main-content");
130
	});
25721 tejbeer 131
 
30017 amit.gupta 132
	$(document).on('click', "button.download_indent", function () {
24229 amit.gupta 133
		downloadIndent();
134
	})
23786 amit.gupta 135
 
25721 tejbeer 136
	$(document).on('change', "#entire-catalog-table input",
30017 amit.gupta 137
		function () {
138
			var catalogId = parseInt($(this).data("catalog-id"));
139
			var sellingPrice = parseInt($(this).data(
140
				"selling-price"));
141
			var quantity = parseInt($(this).val());
142
			if (quantity > 40) {
143
				alert("Quantity should not be above 40");
144
				if (catalogId in indentMap) {
145
					$(this).val(indentMap[catalogId].quantity);
146
				} else {
147
					$(this).val(0);
148
				}
149
				return;
150
			}
151
			brandName = $(this).data("brand-name");
152
			description = $(this).data("description");
153
			if (!(brandName in indentMap)) {
154
				indentMap[brandName] = {};
155
			}
156
			if (catalogId in indentMap[brandName]) {
157
				indentMap[brandName][catalogId]["quantity"] = quantity;
158
				indentMap[brandName][catalogId]["sellingPrice"] = sellingPrice;
159
				indentMap[brandName][catalogId]["description"] = description;
160
				indentMap[brandName][catalogId]["catalogId"] = catalogId;
161
				indentMap[brandName][catalogId]["diff"] = quantity
162
					- indentMap[brandName][catalogId]["initialQuantity"];
163
			} else {
164
				indentMap[brandName][catalogId] = {
165
					"quantity": quantity,
166
					"sellingPrice": sellingPrice,
167
					"description": description,
168
					"catalogId": catalogId,
169
					"initialQuantity": 0,
170
					"diff": quantity
171
				};
172
			}
25721 tejbeer 173
 
30017 amit.gupta 174
			console.log(indentMap);
175
			console.log(currentFofoId)
176
			doPostAjaxRequestHandler(context
177
				+ "/open-indent/save?catalogId=" + catalogId + "&itemQty=" + quantity + "&fofoId=" + currentFofoId
178
				, function (response) {
179
					console.log(response);
180
					if (response == 'true') {
181
					}
25721 tejbeer 182
				});
30017 amit.gupta 183
			populateIndentSummary();
184
		});
25721 tejbeer 185
 
186
 
30017 amit.gupta 187
	/*
188
		* $(document).on('click', "button.mk_submit_indent", function() {
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
	/*
232
	   * $(document).on('click', "button.confirm_indent", function() { var
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",
30017 amit.gupta 246
		function () {
247
			if (confirm("Are you sure to confirm the indent") == true) {
248
				doPostAjaxRequestHandler(context + "/open-indent/confirm?fofoId=" + currentFofoId,
249
					function (response) {
250
 
251
						console.log(response);
252
						if (response == 'true') {
253
							alert("successfully confirm");
254
							// loadIndent('main-content');
255
						}
256
					});
257
 
258
 
259
			}
260
		});
261
 
25721 tejbeer 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();
30017 amit.gupta 267
	 *
25721 tejbeer 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('');
30017 amit.gupta 277
	changedItemIds = [];
25721 tejbeer 278
	htmArr = [];
279
	$('button.confirm_indent').hide();
30017 amit.gupta 280
	for (var brandName in indentMap) {
25721 tejbeer 281
 
30017 amit.gupta 282
 
25721 tejbeer 283
		allZero = true;
284
		trArray = [];
30017 amit.gupta 285
 
286
		for (var itemId in indentMap[brandName]) {
25721 tejbeer 287
			var description = indentMap[brandName][itemId]['description'];
288
 
289
			var itemQty = indentMap[brandName][itemId]['quantity'];
30017 amit.gupta 290
 
291
 
25736 tejbeer 292
			var sellingPrice = indentMap [brandName][itemId]['sellingPrice'];
30017 amit.gupta 293
			var sellPrice = itemQty * sellingPrice;
294
 
25721 tejbeer 295
			if (itemQty != 0) {
296
				allZero = false;
30017 amit.gupta 297
 
25721 tejbeer 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
 
30017 amit.gupta 305
			}
306
 
307
 
23786 amit.gupta 308
		}
30017 amit.gupta 309
		if (!allZero) {
25721 tejbeer 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>');
30017 amit.gupta 317
 
318
 
23786 amit.gupta 319
		}
25736 tejbeer 320
 
23405 amit.gupta 321
	}
25721 tejbeer 322
 
30017 amit.gupta 323
 
25721 tejbeer 324
	$planSummary.html(htmArr.join(""));
30017 amit.gupta 325
	var total = 0;
326
	$('#planning-table tr').each(function () {
327
 
328
 
329
		var value = parseInt($('td', this).eq(2).text());
330
		if (!isNaN(value)) {
331
			total += value;
332
		}
333
 
334
		console.log(total);
335
 
336
	});
337
 
25736 tejbeer 338
	divString = `<div style ="float:right"><b>Total:-</b><span class="currency">${total}</span></div>`
30017 amit.gupta 339
	htmArr.push(divString);
340
	$planSummary.html(htmArr.join(""));
341
 
342
 
25736 tejbeer 343
	// $('#planning-table tfoot td').eq(2).text('Total: ' + total);
30017 amit.gupta 344
 
23405 amit.gupta 345
}
30017 amit.gupta 346
 
23786 amit.gupta 347
function loadIndent(domId) {
25721 tejbeer 348
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize="
30017 amit.gupta 349
		+ counterSize;
350
	doAjaxRequestHandler(context + url, "GET", function (response) {
351
		{
352
		}
23405 amit.gupta 353
		$('#' + domId).html(response);
354
	});
355
}
26131 tejbeer 356
 
357
function loadPreviousMonthIndent(domId) {
358
	var url = "/indent/loadIndentPreviousMonth?fofoId=" + currentFofoId + "&counterSize="
30017 amit.gupta 359
		+ counterSize;
360
	doAjaxRequestHandler(context + url, "GET", function (response) {
361
		{
362
		}
26131 tejbeer 363
		$('#' + domId).html(response);
364
	});
365
}
30017 amit.gupta 366
 
24229 amit.gupta 367
function downloadIndent() {
25721 tejbeer 368
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize="
30017 amit.gupta 369
		+ counterSize;
24229 amit.gupta 370
	doAjaxGetDownload(url, "indent.csv")
23796 amit.gupta 371
}
30017 amit.gupta 372
 
25721 tejbeer 373
function raisePO() {
374
	doPostAjaxRequestWithJsonHandler(context + "/indent/create-po", {},
30017 amit.gupta 375
		function (response) {
376
			if (response) {
377
				alert("PO Created Successfully");
378
				$('a.allocation_po').click();
379
			} else {
380
				alert("Problem while creating PO");
381
			}
382
		});
25721 tejbeer 383
 
23405 amit.gupta 384
}