Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7149 amar.kumar 1
$(function(){
2
	$('input[name$=itemId]').live('change', function(){
3
		updateItemDetails($(this).closest('tr'), $(this).val());
4
	});
5
 
6
	$('#addrow').live('click', function(){
7
		addNewRowForLineItem($('table#indentTable'));
8
	});
9
 
10
	$('a#remove-lineitem').live('click', function(){
11
		$(this).closest('tr').remove();
12
	});
13
 
14
	$('#generateIndentSheet').live('click', function(){
15
		downloadIndentSheet();
16
	});
17
});
18
 
19
function updateItemDetails(rowDom, itemId) {
20
	$.ajax({
21
		type	:	'GET',
22
		url		:	'/inventory/hotspot-indent!getItemDetails',
23
		data	:	'itemId=' + itemId,
24
		success	:	function(response) {
25
			itemdetail = eval('(' + response + ')');
26
			$(rowDom).find('div#modelName').html(itemdetail.modelName);
27
			$(rowDom).find('div#availableQty').html(itemdetail.availableQty);
28
			$(rowDom).find('div#reservedQty').html(itemdetail.reservedQty);
29
			$(rowDom).find('div#previouslyOrderedQty').html(itemdetail.openPOCount);
30
			$(rowDom).find('div#avgSale').html(itemdetail.detailedAvgSales);
31
			$(rowDom).find('div#minStockLevel').html(itemdetail.minStockLevel);
32
			$(rowDom).find('div#numberOfDaysStock').html(itemdetail.numDaysStock);
33
			$(rowDom).find('div#additionalQty').html(itemdetail.additionalQty);
34
		}
35
	});
36
}
37
 
38
function addNewRowForLineItem(table) {
39
    $(table).find('#new-item-detail').clone(true).insertAfter($(table).find('tbody>tr:last'));
40
 
41
    var newRow = $(table).find('tbody>tr:last');
42
 
43
    // Enabling the new record added
44
    $(newRow).find('input').removeAttr('disabled');
45
    $(newRow).removeAttr('id');
46
 
47
    // Making this row visible
48
    $(newRow).show();
49
}
50
 
51
function downloadIndentSheet() {
52
	var jsonData = '[';
53
	var rowCount = 0;
54
	$('#indentTable tr').each(function(){
55
		rowCount++;
56
		if(rowCount<=2){
57
			;
58
		} else {
59
			jsonData = jsonData + '{"itemId":"';
60
			jsonData = jsonData + $(this).find('input.itemId').val();
61
			jsonData = jsonData + '","quantity":"';
62
			jsonData = jsonData + $(this).find('input.quantity').val();
63
			jsonData = jsonData + '"},'
64
		}
65
	});
66
	jsonData = jsonData.substring(0,jsonData.length-1);
67
	jsonData = jsonData + ']';
68
 
69
	$('<form id = "tempForm" method = "POST" action = "/inventory/hotspot-indent/">').appendTo('body');
70
	$('form#tempForm').append($('<input id = "jsoninput" name = "jsonData" value ='+jsonData +'>'));
71
	$('form#tempForm').submit();
72
}