Subversion Repositories SmartDukaan

Rev

Rev 24406 | Rev 24556 | 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() {
23786 amit.gupta 2
	$("a.allocation_po").live('click', function(){
23796 amit.gupta 3
		currentFofoId=0;
4
		counterSize='';
23786 amit.gupta 5
		loadIndent('main-content');
6
	});
23855 amit.gupta 7
	$("button.mk_pause_button").live('click', function(){
8
		var clickedButton = $(this);
9
		var description = clickedButton.data("description");
24406 amit.gupta 10
		var catalogId = clickedButton.data("id");
24410 amit.gupta 11
		getColorsForItems(catalogId, 0, "Active/pause " + description, function(itemIds){
24406 amit.gupta 12
			console.log(itemIds);
13
			if(itemIds!=null) {
14
				bootbox.confirm("Confirm Update " + clickedButton.data("description") + "?", function(result){
15
					if(result) {
16
						coloredItems.forEach(function(item){
17
							item.active = itemIds.indexOf(item.id) >= 0;
18
						});
19
						doPostAjaxRequestWithJsonHandler(context+"/indent/confirm-pause/", JSON.stringify(coloredItems), function(response) {
20
							if(response) {
21
								bootbox.alert("Item/s  Updated Successfully");
22
							} else {
23
								bootbox.alert("Could not pause item");
24
							}
25
						});
26
					}
27
				});
28
			}
29
		});
23855 amit.gupta 30
	});
23796 amit.gupta 31
	$("button.raise_po").live('click', function(){
32
		if (confirm("Please confirm the PO")) {
33
			raisePO();
34
		} else {
35
			return;
36
		}
37
	});
23786 amit.gupta 38
	$("li.mk_counter_size").live('click', function(){
39
		if($(this).hasClass('active')){
40
			return;
41
		}
42
		currentFofoId = 0;
43
		counterSize=$(this).find('a').html();
44
		loadIndent('main-content');
45
	});
46
	$("li.brandLi").live('click', function(){
47
		if(!$(this).hasClass('active')) {
48
			$("table.brandPerformance").toggle();
49
			$("li.brandLi").removeClass('active');
50
			$(this).addClass('active');
51
		}
52
	});
23405 amit.gupta 53
	$("a.create_indent").live('click', function() {
23786 amit.gupta 54
		currentFofoId=0;
55
		counterSize='';
23405 amit.gupta 56
		loadIndent("main-content");
57
	});
23786 amit.gupta 58
	$("button.create_indent").live('click', function() {
59
		loadIndent("main-content");
60
	});
24229 amit.gupta 61
 
62
	$("button.download_indent").live('click', function(){
63
		downloadIndent();
64
	})
23786 amit.gupta 65
 
66
	$("#entire-catalog-table input").live({
67
		change : function() {
24229 amit.gupta 68
			var catalogId = parseInt($(this).data("catalog-id"));
23786 amit.gupta 69
			var sellingPrice = parseInt($(this).data("selling-price"));
70
			var quantity = parseInt($(this).val());
71
			if (quantity > 10) {
72
				alert("Quantity should not be above 10");
24229 amit.gupta 73
				if (catalogId in indentMap) {
74
					$(this).val(indentMap[catalogId].quantity);
23405 amit.gupta 75
				} else {
23786 amit.gupta 76
					$(this).val(0);
23405 amit.gupta 77
				}
23786 amit.gupta 78
				return;
23405 amit.gupta 79
			}
23786 amit.gupta 80
			description = $(this).data("description");
24229 amit.gupta 81
			if (catalogId in indentMap) {
82
				indentMap[catalogId]["quantity"] = quantity;
83
				indentMap[catalogId]["sellingPrice"] = sellingPrice;
84
				indentMap[catalogId]["description"] = description;
85
				indentMap[catalogId]["catalogId"] = catalogId;
86
				indentMap[catalogId]["diff"] =  quantity - indentMap[catalogId]["initialQuantity"];
23786 amit.gupta 87
			} else {
24229 amit.gupta 88
				indentMap[catalogId] = {
23786 amit.gupta 89
					"quantity" : quantity,
90
					"sellingPrice" : sellingPrice,
91
					"description" : description,
24229 amit.gupta 92
					"catalogId" : catalogId,
23786 amit.gupta 93
					"initialQuantity" : 0,
94
					"diff" : quantity
95
				};
23405 amit.gupta 96
			}
23786 amit.gupta 97
			populateIndentSummary();
23405 amit.gupta 98
		}
99
	});
23786 amit.gupta 100
	$("button.mk_submit_indent")
101
			.live(
102
					'click',
103
					function() {
104
						confirmString = [];
105
						confirmString
106
								.push('<table class="table table-striped table-condensed table-bordered" id="entire-catalog-table">');
107
						confirmString.push('<tr>');
24229 amit.gupta 108
						confirmString.push('<th style="width:100px">Catalog Id</th>');
23786 amit.gupta 109
						confirmString.push('<th style="width:250px">Description</th>');
110
						confirmString.push('<th style="width:150px">Unit Price</th>');
111
						confirmString.push('<th style="width:150px">Quantity</th>');
112
						confirmString.push('<th style="width:200px">Item total</th>');
113
						confirmString.push('</tr>');
114
						changedItemIds.forEach(function(itemId){
115
							confirmString.push('<tr style="background-color:#9C7D7E">');
116
							confirmString.push('<td>' + itemId + '</td>');
117
							confirmString.push('<td>'
118
									+ indentMap[itemId].description
119
									+ '</td>');
120
							confirmString
121
							.push('<td style="text-align:left">'
122
									+ numberToComma(indentMap[itemId].sellingPrice)
123
									+ '</td>');
124
							confirmString
125
							.push('<td style="text-align:left">'
126
									+ indentMap[itemId].quantity + '(' + (indentMap[itemId].diff > 0 ? '+' : '-') + Math.abs(indentMap[itemId].diff) 
127
									+ ' pcs)</td>');
128
							confirmString
129
							.push('<td style="text-align:left">'
130
									+ numberToComma(indentMap[itemId].quantity
131
											* indentMap[itemId].sellingPrice)
132
											+ '</td>');
133
							confirmString.push('</tr>');
134
						});
135
						for ( var itemId in indentMap) {
136
							if (itemId.indexOf(changedItemIds) > 0){
137
								continue;
138
							}
139
							if (indentMap[itemId].quantity > 0) {
140
								confirmString.push('<tr>');
141
								confirmString.push('<td>' + itemId + '</td>');
142
								confirmString.push('<td>'
143
										+ indentMap[itemId].description
144
										+ '</td>');
145
								confirmString
146
										.push('<td style="text-align:left">'
147
												+ numberToComma(indentMap[itemId].sellingPrice)
148
												+ '</td>');
149
								confirmString
150
										.push('<td style="text-align:left">'
151
												+ indentMap[itemId].quantity
152
												+ '</td>');
153
								confirmString
154
										.push('<td style="text-align:left">'
155
												+ numberToComma(indentMap[itemId].quantity
156
														* indentMap[itemId].sellingPrice)
157
												+ '</td>');
158
								confirmString.push('</tr>');
159
							}
160
						}
161
						confirmString.push('</table>');
162
						$('#indent-container1').html(confirmString.join(''))
163
								.show();
164
						$('#indent-container').hide();
165
						$('button.mk_submit_indent').hide();
166
						$('button.bk_toedit_indent').show();
167
						$('button.confirm_indent').show();
168
					});
169
	$("button.confirm_indent").live(
170
			'click',
171
			function() {
172
				var itemQtyList = [];
24229 amit.gupta 173
				for (catalogId in indentMap) {
174
					diff = indentMap[catalogId]["quantity"] - indentMap[catalogId]["initialQuantity"];
23786 amit.gupta 175
					if(diff!=0) {
176
						itemQtyList.push({
24229 amit.gupta 177
							"quantity" : indentMap[catalogId]["quantity"],
178
							"catalogId" : indentMap[catalogId]["catalogId"]
23786 amit.gupta 179
						});
180
					}
181
				}
182
				doPostAjaxRequestWithJsonHandler(context + "/open-indent/save?fofoId=" + currentFofoId + "&counterSize=" + counterSize,
183
						JSON.stringify(itemQtyList), function(data) {
184
							alert('Indent has been created Successfully!');
185
							indentMap = {};
186
							loadIndent('main-content');
187
						});
188
			});
189
	$("button.bk_toedit_indent").live('click', function() {
23405 amit.gupta 190
		$('button.bk_toedit_indent').hide();
191
		$('button.confirm_indent').hide();
192
		$('button.mk_submit_indent').show();
193
		$('#indent-container1').hide();
194
		$('#indent-container').show();
23786 amit.gupta 195
 
23405 amit.gupta 196
	});
23786 amit.gupta 197
 
23405 amit.gupta 198
});
199
 
23786 amit.gupta 200
function populateIndentSummary() {
201
	var totalQty = 0;
23405 amit.gupta 202
	var totalAmount = 0;
203
	var totalItems = 0;
23786 amit.gupta 204
	var arr = [];
205
	changedItemIds = [];
206
	arr[0]=[0,0,0];
207
	arr[1]=[0,0,0];
208
	arr[2]=[0,0,0];
209
	arr[3]=[0,0,0];
210
 
211
	for ( var itemId in indentMap) {
212
		var itemQty = indentMap[itemId]['quantity'];
213
		var previousItemQty = indentMap[itemId]['initialQuantity'];
214
		var sellingPrcice = indentMap[itemId]['sellingPrice'];
215
		if(previousItemQty !=0) {
216
			arr[0][0]++;
217
		}
218
		if(itemQty !=0) {
219
			arr[3][0]++;
220
		}
221
		var diff = itemQty - previousItemQty;
222
		arr[0][1] += previousItemQty;
223
		arr[0][2] += previousItemQty* sellingPrcice;
224
		arr[3][1] += itemQty;
225
		arr[3][2] += itemQty * sellingPrcice;
226
		if (diff != 0) {
227
			changedItemIds.push(itemId);
228
			if (diff > 0) {
229
				arr[1][0]++;
230
				arr[1][1] += diff;
231
				arr[1][2] += (diff) * sellingPrcice;
232
			} else {
233
				arr[2][0]++;
234
				arr[2][1] += diff;
235
				arr[2][2] += diff * sellingPrcice;
23772 amit.gupta 236
			}
23405 amit.gupta 237
		}
238
	}
23786 amit.gupta 239
	totalQty = arr[3][1];
240
	if (totalQty === 0) {
23405 amit.gupta 241
		$('button.mk_submit_indent').hide();
242
	} else {
243
		$('button.mk_submit_indent').show();
244
	}
23786 amit.gupta 245
	$("#summary-table").find("td").each(function(index, ele){
246
		if(index%3==2){
247
			$(ele).html(numberToComma(arr[Math.floor(index/3)][2]));
248
		}else{
249
			$(ele).html(arr[Math.floor(index/3)][index%3]);
250
		}
251
 
252
	});
23405 amit.gupta 253
}
23786 amit.gupta 254
function loadIndent(domId) {
255
	var url = "/indent/loadIndent?fofoId=" + currentFofoId + "&counterSize=" + counterSize;
256
	doAjaxRequestHandler(context + url, "GET", function(response) {
23405 amit.gupta 257
		$('#' + domId).html(response);
258
	});
259
}
24229 amit.gupta 260
function downloadIndent() {
261
	var url = "/indent/download?fofoId=" + currentFofoId + "&counterSize=" + counterSize;
262
	doAjaxGetDownload(url, "indent.csv")
23796 amit.gupta 263
}
264
function raisePO(){
265
	doPostAjaxRequestWithJsonHandler(context+"/indent/create-po", {}, function(response) {
266
		if(response) {
267
			alert("PO Created Successfully");
268
			$('a.allocation_po').click();								
269
		} else {
270
			alert("Problem while creating PO");
271
		}
272
	});
273
 
23405 amit.gupta 274
}