Subversion Repositories SmartDukaan

Rev

Rev 23886 | Rev 24456 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23343 ashik.ali 1
var grnhistory= grnhistory || {};
2
grnhistory.searchText = "";
3
grnhistory.searchType = "";
4
grnhistory.startTime = "0";
5
grnhistory.endTime = "0";
23886 amit.gupta 6
dateRangeCallback(moment(), moment());
23343 ashik.ali 7
 
8
$(function() {
9
	$(".new_grn").live('click', function() {
10
		loadNewGrn("main-content");
11
	});
12
 
13
	$(".grn_history").live('click', function() {
23886 amit.gupta 14
		loadGrnHistory("main-content","","",startDate,endDate);
23343 ashik.ali 15
	});
16
 
17
	$(".pending_grn").live('click', function() {
23886 amit.gupta 18
		loadPendingGrn("main-content");
23343 ashik.ali 19
	});
20
 
21
	$("td.startGrnSerialized").live('click', function() {
22
		var invoiceNumber = $(this).attr('invoiceNumber');
23
		var quantity = $(this).attr('quantity');
24
		var displayName = $(this).attr('displayName');
25
		var itemId = $(this).attr('itemId');
26
		console.log(quantity);
27
		$(".modal-body .grnInvoiceNumber>span").text(invoiceNumber);
28
		$(".modal-body .grnProductInfo>span").text(displayName);
29
		$("#scanModel .invoiceNumber").val(invoiceNumber);
30
		$("#scanModel .itemId").val(itemId);
31
		$( "#grnImeiInformation" ).empty();
32
		var qty = parseInt(quantity);
33
		var divCode = '<div class="row">CONTENT</div><p></p>';
34
		var innerDiv = '<div class="col-sm-3">'+
35
		'<div class="input-group">'+
36
		'<input type="text" class="form-control">'+
37
		'</div>'+
38
		'</div>';
39
		while(qty!=0){
40
			var divText  = "";
41
			if (qty < 4){
42
				var cp = qty;
43
				for (var i=0;i<cp;i++ ){
44
					divText = divText + innerDiv;
45
					qty = qty - 1;
46
				}
47
			}
48
			else{
49
				for(var i=0;i<4;i++){
50
					divText = divText + innerDiv;
51
					qty = qty - 1;
52
				}
53
			}
54
			divText = divCode.replace("CONTENT",divText); 
55
			$("#grnImeiInformation")
56
			.append(divText)
57
		}
58
	});
59
 
60
	$("td.startGrnNonSerialized").live('click', function() {
61
		var invoiceNumber = $(this).attr('invoiceNumber');
62
		var quantity = $(this).attr('quantity');
63
		var displayName = $(this).attr('displayName');
64
		var itemId = $(this).attr('itemId');
65
		console.log(quantity);
66
		$("#scanNonSerializedModel .modal-body .grnInvoiceNumber>span").text(invoiceNumber);
67
		$("#scanNonSerializedModel .modal-body .grnProductInfo>span").text(displayName);
68
		$("#scanNonSerializedModel .invoiceNumber").val(invoiceNumber);
69
		$("#scanNonSerializedModel .itemId").val(itemId);
70
		$( "#grnImeiInformation" ).empty();
71
		var qty = parseInt(quantity);
72
		var divCode = '<div class="row">CONTENT</div><p></p>';
73
		var innerDiv = '<div class="col-sm-3">'+
74
		'<div class="input-group">'+
75
		'<input type="text" class="form-control">'+
76
		'</div>'+
77
		'</div>';
78
		while(qty!=0){
79
			var divText  = "";
80
			if (qty < 4){
81
				var cp = qty;
82
				for (var i=0;i<cp;i++ ){
83
					divText = divText + innerDiv;
84
					qty = qty - 1;
85
				}
86
			}
87
			else{
88
				for(var i=0;i<4;i++){
89
					divText = divText + innerDiv;
90
					qty = qty - 1;
91
				}
92
			}
93
			divText = divCode.replace("CONTENT",divText); 
94
			$("#grnImeiInformation")
95
			.append(divText)
96
		}
97
	});
98
 
99
	$("#grnSubmitSerialized").live('click', function(){
100
		var imeis = [];
101
		var error = false;
102
		var errorText = "";
103
		$("#grnImeiInformation :input").each(function(){
104
			var input = $(this).val().trim();
105
			if (imeis.indexOf(input) !=-1 || !input){
106
				error = true;
107
				if (!input){
108
					$(this).addClass("border-highlight");
109
				}
110
			}
111
			imeis.push(input);
112
 
113
		});
114
		if (error){
115
			return false;
116
		}
117
		var invoiceNumber = $("#scanModel .invoiceNumber").val();
118
		var itemId = $("#scanModel .itemId").val();
119
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"serialNumbers":imeis});
23500 ashik.ali 120
		doPostAjaxRequestWithJsonHandler(context+"/scanSerialized", postData, function(response){
121
			alert("Purchase booked successfully");
24435 amit.gupta 122
			$("#scanModel").one("hidden.bs.modal", function () {
23500 ashik.ali 123
				$("#purchase-reference-submit-button").click();
124
			});
24435 amit.gupta 125
			$('#scanModel').modal('hide');
23343 ashik.ali 126
		});
127
		return false;
128
	});
129
 
130
	$("#grnNonSerializedSubmit").live('click', function(){
131
		var error = false;
132
		var errorText = "";
133
		if (error){
134
			return false;
135
		}
136
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
137
		var itemId = $("#scanNonSerializedModel .itemId").val();
138
		var quantity = $("#scanNonSerializedModel .quantity").val();
139
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
23500 ashik.ali 140
		doPostAjaxRequestWithJsonHandler(context+"/scanNonSerialized", postData, function(response){
141
			alert("Purchase booked successfully");
24435 amit.gupta 142
			$("#scanNonSerializedModel").one("hidden.bs.modal", function () {
23500 ashik.ali 143
				$("#purchase-reference-submit-button").click();
144
			});
24435 amit.gupta 145
			$('#scanNonSerializedModel').modal('hide');
23343 ashik.ali 146
		});
147
		return false;
148
	});
149
 
150
	$("#grnImeiInformation :input").live('change paste keyup mouseup', function() {
151
		if ($(this).val().trim() != "") {
152
			console.log('The text box really changed this time');
153
			$('#grnImeiInformation :input').removeClass("border-highlight");
154
			if(findDuplicateSerialNumbers( $(this).val().trim()) > 0){
155
				var inputs = $("#grnImeiInformation :input[value="+$(this).val().trim()+"]");
156
				if(inputs.length > 1){
157
					inputs.each(function(){$(this).addClass("border-highlight")});
158
				}
159
			}
160
		}
161
	});
162
 
163
 
164
	$("#grnImeiInformation :input").live('paste', function() {
165
		if ($(this).val().trim() != "") {
166
			console.log('paste event');
167
			$(this).next("input .form-control").focus();
168
		}
169
	});
170
 
171
	$("#airwayBillOrInvoiceNumberText").live("keyup", function(e) {
172
		var keyCode = e.keyCode || e.which;
173
    	if(keyCode == 13){
174
        	$("#purchase-reference-submit-button").click();
175
    	}
176
	});
177
 
178
	$("#grn-history-search-button").live('click', function() {
179
		grnhistory.searchText = $("#grn-history-search-text").val();
180
		grnhistory.searchType = "purchaseReference";
23886 amit.gupta 181
		grnhistory.startTime = startDate;
182
		grnhistory.endTime = endDate;
23343 ashik.ali 183
		if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText){
184
			grnhistory.searchText = "";
185
		}
186
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
187
    });
188
 
189
	$("#grn-history-search-text").live("keyup", function(e) {
190
		var keyCode = e.keyCode || e.which;
191
    	if(keyCode == 13){
192
        	$("#grn-history-search-button").click();
193
    	}
194
	});
195
 
196
	$("#grn-history-paginated .next").live('click', function() {
23629 ashik.ali 197
		var params = {};
198
		params['purchaseReference'] = grnhistory.searchText;
199
		params['searchType'] = grnhistory.searchType;
200
		params['startTime'] = grnhistory.startTime;
201
		params['endTime'] = grnhistory.endTime;
202
		loadPaginatedNextItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
203
		$(this).blur();
23343 ashik.ali 204
 
205
    });
206
 
207
	$("#grn-history-paginated .previous").live('click', function() {
23629 ashik.ali 208
		var params = {};
209
		params['purchaseReference'] = grnhistory.searchText;
210
		params['searchType'] = grnhistory.searchType;
211
		params['startTime'] = grnhistory.startTime;
212
		params['endTime'] = grnhistory.endTime;
213
		loadPaginatedPreviousItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
214
		$(this).blur();
215
 
23343 ashik.ali 216
    });
217
 
218
	$("#grn-history-date-button").live('click', function() {
219
		var dateRange = $('#reportrange span').text();
23886 amit.gupta 220
		grnhistory.startTime = startDate;
221
		grnhistory.endTime = endDate;
23343 ashik.ali 222
		grnhistory.searchType = "dateFilter";
223
		grnhistory.searchText = "";
224
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
225
    });
226
 
227
    $(".grn-details").live('click',function(){
228
		var purchaseId = $(this).attr('data');
229
		console.log(purchaseId);
230
		loadGrnDetails(purchaseId,"grn-details-container");
231
	});
232
 
233
	$(".pending-grn-details").live('click',function(){
234
		console.log("pending-grn-details clicked");
235
		var orderId = $(this).attr('data');
236
		console.log("orderId : "+orderId);
237
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
238
	});
239
 
240
	$(".pending-grn").live('click',function(){
241
		var purchaseReference = $(this).attr('data');
242
		console.log(purchaseReference);
243
		loadPendingGrnDetails(purchaseReference,"main-content");
244
	});
245
 
246
});
247
 
248
 
249
function loadNewGrn(domId){
250
	//var response = doGetAjaxRequest(context+"/purchase");
23500 ashik.ali 251
	doGetAjaxRequestHandler(context+"/purchase", function(response){
23343 ashik.ali 252
		$('#' + domId).html(response);
253
	});
254
 
255
}
256
 
257
function getPurchaseByInvoiceNumber(){
258
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
23500 ashik.ali 259
	doGetAjaxRequestHandler(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber, function(response){
23343 ashik.ali 260
		$('#main-content').html(response);
261
	});
262
}
263
 
264
function loadPendingGrn(domId){
23500 ashik.ali 265
	doGetAjaxRequestHandler(context+"/pendingGrn", function(response){
23343 ashik.ali 266
		$('#' + domId).html(response);
267
	});
268
}
269
 
270
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
23783 ashik.ali 271
	doGetAjaxRequestHandler(context+"/grnHistory?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 272
	        +"&startTime="+startTime
23500 ashik.ali 273
	        +"&endTime="+endTime, function(response){
23343 ashik.ali 274
		$('#' + domId).html(response);
275
	});
276
}
277
 
278
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
279
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
280
}
281
 
282
function findDuplicateSerialNumbers(value){
283
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
284
    return result;
285
}
286
 
287
function loadGrnDetails(purchaseId, domId){
23783 ashik.ali 288
	doGetAjaxRequestHandler(context+"/grnHistoryDetailByPurchaseId?purchaseId="+purchaseId, function(response){
23343 ashik.ali 289
		$('#' + domId).html(response);
290
		window.dispatchEvent(new Event('resize'));
291
	});	
292
}
293
 
294
function loadPendingGrnDetails(orderId, domId){
23783 ashik.ali 295
	doGetAjaxRequestHandler(context+"/pendingGrnDetails?orderId="+orderId, function(response){
23343 ashik.ali 296
		$('#' + domId).html(response);
297
		window.dispatchEvent(new Event('resize'));
298
	});
299
 
300
}