Subversion Repositories SmartDukaan

Rev

Rev 23882 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23783 ashik.ali 1
$(function() {
2
	$(".create-item").live('click', function() {
3
		loadCreateItem("main-content");
4
	});
5
 
6
	$(".scan-in-items").live('click', function() {
7
		loadScanInItems("main-content");
8
	});
9
 
10
	$(".scan-in-partner-items").live('click', function() {
11
		loadScanInPartnerItems("main-content");
12
	});
13
 
14
	$("#scanInPartnerItemButton").live('click', function() {
15
		var deliveryNoteId = $("#scanInPartnerItemModel .deliveryNoteId").val();
16
		submitScanInPartnerItem(deliveryNoteId);
17
		return false;
18
	});
19
 
20
	$("#deliveryNoteId").live("keyup", function(e) {
21
		var keyCode = e.keyCode || e.which;
22
    	if(keyCode == 13){
23
    		scanInPartnerItemDialog();
24
    	}
25
	});
26
 
27
	$("#scanInItemButton").live('click', function() {
28
		var imeis = [];
29
		var error = false;
30
		var errorText = "";
31
		$("#serialNumberContainer :input").each(function(){
32
			var input = $(this).val().trim();
33
			if (imeis.indexOf(input) !=-1 || !input){
34
				error = true;
35
				if (!input){
36
					$(this).addClass("border-highlight");
37
				}
38
			}
39
			imeis.push(input);
40
 
41
		});
42
		if (error){
43
			return false;
44
		}
45
		console.log("imeis : "+imeis);
46
		var itemId = $("#scanInItemModel .itemId").val();
47
		var quantity = $(".modal-body .itemQuantity>span").text();
48
		var reserved = $(".modal-body .itemReservedQuantity>span").text();
49
		submitScanInItem(itemId, quantity, reserved, imeis);
50
 
51
		return false;
52
	});
53
 
54
	$('#warehouses').live('change', function(){
55
		var warehouseId = $(this).val();
56
		loadItemsItemsByWarehouseId("warehouse-items-container", warehouseId);
57
	});
58
 
59
	$(".scan-out-items").live('click', function() {
60
		loadScanOutItems("main-content");
61
	});
62
 
63
	$("#scanOutItemButton").live('click', function() {
64
		var itemId = $("#scanOutItemModel .itemId").val();
65
		if(itemId == ""){
66
			alert("Please choose item");
67
			$("#scanOutItemModel .close").click();
68
			return;
69
		}
70
		var warehouseId = $("#scanOutItemModel .warehouseId").val();
71
		if(warehouseId == ""){
72
			alert("Please choose warehouse");
73
			$("#scanOutItemModel .close").click();
74
			return;
75
		}
76
		var userId = $("#scanOutItemModel .userId").val();
77
		if(userId == ""){
78
			alert("Please choose user");
79
			$("#scanOutItemModel .close").click();
80
			return;
81
		}
82
		var quantity = $(".modal-body .itemQuantity>span").text();
83
		var itemType = $("#scanOutItemModel .itemType").val();
84
		var imeis = [];
85
		if(itemType == 'SERIALIZED'){
86
			imeis = $("#itemSerialNumbers").val();
87
			console.log("imeis : "+imeis);
88
			if(imeis.length > quantity){
89
				alert("Serial numbers can not choosen more than quantity");
90
				return;
91
			}
92
		}
93
 
94
		submitScanOutItem(itemId, warehouseId, userId, quantity, imeis);
95
 
96
		return false;
97
	});
98
 
99
	$("#items-paginated .next").live('click', function() {
100
		loadPaginatedNextItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
101
		$(this).blur();
102
    });
103
 
104
	$("#items-paginated .previous").live('click', function() {
105
		loadPaginatedPreviousItems('/getPaginatedItems', null, 'items-paginated', 'items-table', null);
106
		$(this).blur();
107
    });
108
 
109
	$("#scan-in-items-paginated .next").live('click', function() {
110
		loadPaginatedNextItems('/getPaginatedScanInItems', null, 'scan-in-items-paginated', 'scan-in-items-table', null);
111
		$(this).blur();
112
    });
113
 
114
	$("#scan-in-items-paginated .previous").live('click', function() {
115
		loadPaginatedPreviousItems('/getPaginatedScanInItems', null, 'scan-in-items-paginated', 'scan-in-items-table', null);
116
		$(this).blur();
117
    });
118
 
119
	$("#scan-out-items-paginated .next").live('click', function() {
120
		loadPaginatedNextItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
121
		$(this).blur();
122
    });
123
 
124
	$("#scan-out-items-paginated .previous").live('click', function() {
125
		loadPaginatedPreviousItems('/getPaginatedScanOutItems', null, 'scan-out-items-paginated', 'scan-out-items-table', null);
126
		$(this).blur();
127
    });
128
 
129
	$("#scan-in-partner-items-paginated .next").live('click', function() {
130
		loadPaginatedNextItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-partner-items-table', null);
131
		$(this).blur();
132
    });
133
 
134
	$("#scan-in-partner-items-paginated .previous").live('click', function() {
135
		loadPaginatedPreviousItems('/getPaginatedScanInPartnerItems', null, 'scan-in-partner-items-paginated', 'scan-in-partner-items-table', null);
136
		$(this).blur();
137
    });
138
});
139
 
140
function scanInItemDialog(){
141
	var itemId = $('#items-for-scan-in').val();
142
	var itemDescription = $('#items-for-scan-in option:selected').text();
143
	var itemType = $('#items-for-scan-in option:selected').attr('itemType');
144
	var quantity = parseInt($('#quantity').val());
145
	if(quantity == undefined || quantity == "" || quantity <= 0 || isNaN(quantity)){
146
		quantity = 1;
147
	}
148
	var reserved = parseInt($('#reserved').val());
149
	if(reserved == undefined || reserved == "" || reserved <0 || isNaN(reserved)){
150
		reserved = 0;
151
	}
152
	console.log("itemId : "+itemId);
153
	console.log("itemDescription : "+itemDescription);
154
	console.log("itemType : "+itemType);
155
	console.log("quantity : "+quantity);
156
	console.log("reserved : "+reserved);
157
 
158
	$("#scanInItemModel .itemId").val(itemId);
159
 
160
	$(".modal-body .itemInformation>span").text(itemDescription);
161
	$(".modal-body .itemQuantity>span").text(quantity);
162
	$(".modal-body .itemReservedQuantity>span").text(reserved);
163
	$( "#serialNumberContainer" ).empty();
164
 
165
	if(itemType == "SERIALIZED"){
166
		$(".modal-body .modal-title").text("Enter Serial Numbers");
167
		var qty = parseInt(quantity);
168
		var divCode = '<div class="row">CONTENT</div><p></p>';
169
		var innerDiv = '<div class="col-sm-3">'+
170
		'<div class="input-group">'+
171
		'<input type="text" class="form-control">'+
172
		'</div>'+
173
		'</div>';
174
		while(qty!=0){
175
			var divText  = "";
176
			if (qty < 4){
177
				var cp = qty;
178
				for (var i=0;i<cp;i++ ){
179
					divText = divText + innerDiv;
180
					qty = qty - 1;
181
				}
182
			}else{
183
				for(var i=0;i<4;i++){
184
					divText = divText + innerDiv;
185
					qty = qty - 1;
186
				}
187
			}
188
			divText = divCode.replace("CONTENT", divText); 
189
			$("#serialNumberContainer")
190
			.append(divText)
191
		}
192
	}else{
193
		$(".modal-body .modal-title").text("");
194
	}
195
 
196
}
197
 
198
function submitScanInItem(itemId, quantity, reserved, serialNumbers){
199
	var postData = JSON.stringify({"itemId":parseInt(itemId), "quantity":parseInt(quantity), "reserved":parseInt(reserved), "serialNumbers":serialNumbers});
200
	doPostAjaxRequestWithJsonHandler(context+"/scanInItems", postData, function(response){
201
		$('#main-content').html(response);
202
		alert("Scanned in successfully");
203
	});
204
}
205
 
206
function scanOutItemDialog(){
207
	var itemId = $('#warehouse-items').val();
208
	var itemDescription = $('#warehouse-items option:selected').text();
209
	var itemType = $('#warehouse-items option:selected').attr('itemType');
210
	var warehouseId = $('#warehouses').val();
211
	var warehouseName = $('#warehouses option:selected').text();
212
	var userId = $('#fofo-users').val();
213
	var emailId = $('#fofo-users option:selected').text();
214
	var quantity = parseInt($('#quantity').val());
215
	if(quantity == undefined || quantity == "" || quantity <= 0 || isNaN(quantity)){
216
		quantity = 1;
217
	}
218
	console.log("itemId : "+itemId);
219
	console.log("itemDescription : "+itemDescription);
220
	console.log("itemType : "+itemType);
221
	console.log("warehouseId : "+warehouseId);
222
	console.log("warehouseName : "+warehouseName);
223
	console.log("userId : "+userId);
224
	console.log("emailId : "+emailId);
225
	console.log("quantity : "+quantity);
226
 
227
	$("#scanOutItemModel .itemId").val(itemId);
228
	$("#scanOutItemModel .itemType").val(itemType);
229
	$("#scanOutItemModel .warehouseId").val(warehouseId);
230
	$("#scanOutItemModel .userId").val(userId);
231
 
232
	$(".modal-body .itemInformation>span").text(itemDescription);
233
	$(".modal-body .warehouseInformation>span").text(warehouseName);
234
	$(".modal-body .userInformation>span").text(emailId);
235
	$(".modal-body .itemQuantity>span").text(quantity);
236
	$( "#serialNumberContainer" ).empty();
237
 
238
	if(itemType == "SERIALIZED"){
239
		loadItemSerialNumbers('serialNumberContainer', itemId, warehouseId);
240
	}else{
241
		$(".modal-body .modal-title").text("");
242
	}
243
 
244
}
245
 
246
function submitScanOutItem(itemId, warehouseId, userId, quantity, imeis){
247
	var postData = JSON.stringify({"itemId":parseInt(itemId), "warehouseId":parseInt(warehouseId), "userId":parseInt(userId), "quantity":parseInt(quantity), "serialNumbers":imeis});
248
	doPostAjaxRequestWithJsonHandler(context+"/scanOutItems", postData, function(response){
249
		$('#main-content').html(response);
250
		alert("Scanned out successfully");
251
	});
252
}
253
 
254
function scanInPartnerItemDialog(){
255
	var deliveryNoteId = $('#deliveryNoteId').val();
256
 
257
	console.log("deliveryNoteId : "+deliveryNoteId);
258
 
259
	$("#scanInPartnerItemModel .deliveryNoteId").val(deliveryNoteId);
260
	$(".modal-body .deliveryNoteInformation>span").text(deliveryNoteId);
261
 
262
	loadAdminDeliveryNoteDetails(deliveryNoteId);
263
}
264
 
265
function submitScanInPartnerItem(deliveryNoteId){
266
	doGetAjaxRequestHandler(context+"/scanInPartnerItems?deliveryNoteId="+deliveryNoteId, function(response){
267
		$('#main-content').html(response);
268
		alert("Scanned in successfully");
269
	});
270
}
271
 
272
function loadCreateItem(domId){
273
	doGetAjaxRequestHandler(context+"/createItem", function(response){
274
		$('#' + domId).html(response);
275
	});
276
}
277
 
278
function loadScanInItems(domId){
279
	doGetAjaxRequestHandler(context+"/getScanInItems", function(response){
280
		$('#' + domId).html(response);
281
	});
282
}
283
 
284
function loadScanInPartnerItems(domId){
285
	doGetAjaxRequestHandler(context+"/getScanInPartnerItems", function(response){
286
		$('#' + domId).html(response);
287
	});
288
}
289
 
290
function loadScanOutItems(domId){
291
	doGetAjaxRequestHandler(context+"/getScanOutItems", function(response){
292
		$('#' + domId).html(response);
293
	});
294
}
295
 
296
function loadItemSerialNumbers(domId, itemId, warehouseId){
297
	doGetAjaxRequestHandler(context+"/getSerialNumbersByItemId?itemId="+itemId+"&warehouseId="+warehouseId, function(response){
298
		$('#' + domId).html(response);
299
		configureItemSerialNumbersDropDown();
300
	});
301
}
302
 
303
function loadAdminDeliveryNoteDetails(deliveryNoteId){
304
	doGetAjaxRequestHandler(context+"/deliveryNoteDetails?deliveryNoteId="+deliveryNoteId, function(response){
305
		response = response.response;
306
		console.log(response);
307
		$(".modal-body .warehouseInformation>span").text(response.warehouseName);
308
		$(".modal-body .itemInformation>span").text(response.itemDescription);
309
		$(".modal-body .serialNumberInformation>span").text(response.serialNumber);
310
		$(".modal-body .itemQuantity>span").text(response.quantity);
311
	});
312
}
313
 
314
function loadItemsItemsByWarehouseId(domId, warehouseId){
315
	doGetAjaxRequestHandler(context+"/getItemsByWarehouseId?warehouseId="+warehouseId, function(response){
316
		$('#' + domId).html(response);
317
		configureWarehouseItemsDropDown();
318
	});
319
}
320
 
321
function configureVendorsDropDown(){
322
	$(document).ready(function() {
323
        $('#vendors').multiselect({
324
    		multiple:false,
325
        	includeSelectAllOption: true,
326
        	maxHeight: 200,
327
        	buttonWidth: '270px',
328
        	numberDisplayed: 1,
329
        	nonSelectedText: 'Vendors',
330
        	nSelectedText: ' - Vendors Selected',
331
        	allSelectedText: 'All Vendors Selected',
332
        	enableFiltering: true
333
        });
334
    });
335
}
336
 
337
function configureItemsForScanInDropDown(){
338
	$(document).ready(function() {
339
        $('#items-for-scan-in').multiselect({
340
    		multiple:false,
341
        	includeSelectAllOption: true,
342
        	maxHeight: 200,
343
        	buttonWidth: '280px',
344
        	numberDisplayed: 1,
345
        	nonSelectedText: 'Items',
346
        	nSelectedText: ' - Items Selected',
347
        	allSelectedText: 'All Items Selected',
348
        	enableFiltering: true
349
        });
350
    });
351
}
352
 
353
function configureWarehouseItemsDropDown(){
354
	$(document).ready(function() {
355
        $('#warehouse-items').multiselect({
356
    		multiple:false,
357
        	includeSelectAllOption: true,
358
        	maxHeight: 200,
359
        	buttonWidth: '200px',
360
        	numberDisplayed: 1,
361
        	nonSelectedText: 'Items',
362
        	nSelectedText: ' - Items Selected',
363
        	allSelectedText: 'All Items Selected',
364
        	enableFiltering: true
365
        });
366
    });
367
}
368
 
369
function configureWarehousesDropDown(){
370
	$(document).ready(function() {
371
        $('#warehouses').multiselect({
372
    		multiple:false,
373
        	includeSelectAllOption: true,
374
        	maxHeight: 200,
375
        	buttonWidth: '200px',
376
        	numberDisplayed: 1,
377
        	nonSelectedText: 'Warehouses',
378
        	nSelectedText: ' - Warehouses Selected',
379
        	allSelectedText: 'All Warehouses Selected',
380
        	enableFiltering: true
381
        });
382
    });
383
}
384
 
385
function configureFofoUsersDropDown(){
386
	$(document).ready(function() {
387
        $('#fofo-users').multiselect({
388
    		multiple:false,
389
        	includeSelectAllOption: true,
390
        	maxHeight: 200,
391
        	buttonWidth: '200px',
392
        	numberDisplayed: 1,
393
        	nonSelectedText: 'Users',
394
        	nSelectedText: ' - Users Selected',
395
        	allSelectedText: 'All Users Selected',
396
        	enableFiltering: true
397
        });
398
    });
399
}
400
 
401
function configureItemSerialNumbersDropDown(){
402
	$(document).ready(function() {
403
        $('#itemSerialNumbers').multiselect({
404
        	includeSelectAllOption: true,
405
        	multiple:true,
406
        	maxHeight: 200,
407
        	buttonWidth: '350px',
408
        	numberDisplayed: 1,
409
        	nonSelectedText: 'Serial Numbers',
410
        	nSelectedText: ' - Serial Numbers Selected',
411
        	allSelectedText: 'All Serial Numbers Selected',
412
        	enableFiltering: true
413
        });
414
    });
415
}