Subversion Repositories SmartDukaan

Rev

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