Subversion Repositories SmartDukaan

Rev

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