Subversion Repositories SmartDukaan

Rev

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