Subversion Repositories SmartDukaan

Rev

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