Subversion Repositories SmartDukaan

Rev

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