Subversion Repositories SmartDukaan

Rev

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