Subversion Repositories SmartDukaan

Rev

Rev 23419 | Go to most recent revision | Details | 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";
6
 
7
$(function() {
8
	$(".new_grn").live('click', function() {
9
		loadNewGrn("main-content");
10
	});
11
 
12
	$(".grn_history").live('click', function() {
13
		loadGrnHistory("main-content","","","0","0");
14
	});
15
 
16
	$(".pending_grn").live('click', function() {
17
		loadPendingGrn("main-content", "", "", "0", "0");
18
	});
19
 
20
	$("td.startGrnSerialized").live('click', function() {
21
		var invoiceNumber = $(this).attr('invoiceNumber');
22
		var quantity = $(this).attr('quantity');
23
		var displayName = $(this).attr('displayName');
24
		var itemId = $(this).attr('itemId');
25
		console.log(quantity);
26
		$(".modal-body .grnInvoiceNumber>span").text(invoiceNumber);
27
		$(".modal-body .grnProductInfo>span").text(displayName);
28
		$("#scanModel .invoiceNumber").val(invoiceNumber);
29
		$("#scanModel .itemId").val(itemId);
30
		$( "#grnImeiInformation" ).empty();
31
		var qty = parseInt(quantity);
32
		var divCode = '<div class="row">CONTENT</div><p></p>';
33
		var innerDiv = '<div class="col-sm-3">'+
34
		'<div class="input-group">'+
35
		'<input type="text" class="form-control">'+
36
		'</div>'+
37
		'</div>';
38
		while(qty!=0){
39
			var divText  = "";
40
			if (qty < 4){
41
				var cp = qty;
42
				for (var i=0;i<cp;i++ ){
43
					divText = divText + innerDiv;
44
					qty = qty - 1;
45
				}
46
			}
47
			else{
48
				for(var i=0;i<4;i++){
49
					divText = divText + innerDiv;
50
					qty = qty - 1;
51
				}
52
			}
53
			divText = divCode.replace("CONTENT",divText); 
54
			$("#grnImeiInformation")
55
			.append(divText)
56
		}
57
	});
58
 
59
	$("td.startGrnNonSerialized").live('click', function() {
60
		var invoiceNumber = $(this).attr('invoiceNumber');
61
		var quantity = $(this).attr('quantity');
62
		var displayName = $(this).attr('displayName');
63
		var itemId = $(this).attr('itemId');
64
		console.log(quantity);
65
		$("#scanNonSerializedModel .modal-body .grnInvoiceNumber>span").text(invoiceNumber);
66
		$("#scanNonSerializedModel .modal-body .grnProductInfo>span").text(displayName);
67
		$("#scanNonSerializedModel .invoiceNumber").val(invoiceNumber);
68
		$("#scanNonSerializedModel .itemId").val(itemId);
69
		$( "#grnImeiInformation" ).empty();
70
		var qty = parseInt(quantity);
71
		var divCode = '<div class="row">CONTENT</div><p></p>';
72
		var innerDiv = '<div class="col-sm-3">'+
73
		'<div class="input-group">'+
74
		'<input type="text" class="form-control">'+
75
		'</div>'+
76
		'</div>';
77
		while(qty!=0){
78
			var divText  = "";
79
			if (qty < 4){
80
				var cp = qty;
81
				for (var i=0;i<cp;i++ ){
82
					divText = divText + innerDiv;
83
					qty = qty - 1;
84
				}
85
			}
86
			else{
87
				for(var i=0;i<4;i++){
88
					divText = divText + innerDiv;
89
					qty = qty - 1;
90
				}
91
			}
92
			divText = divCode.replace("CONTENT",divText); 
93
			$("#grnImeiInformation")
94
			.append(divText)
95
		}
96
	});
97
 
98
	$("#grnSubmitSerialized").live('click', function(){
99
		var imeis = [];
100
		var error = false;
101
		var errorText = "";
102
		$("#grnImeiInformation :input").each(function(){
103
			var input = $(this).val().trim();
104
			if (imeis.indexOf(input) !=-1 || !input){
105
				error = true;
106
				if (!input){
107
					$(this).addClass("border-highlight");
108
				}
109
			}
110
			imeis.push(input);
111
 
112
		});
113
		if (error){
114
			return false;
115
		}
116
		var invoiceNumber = $("#scanModel .invoiceNumber").val();
117
		var itemId = $("#scanModel .itemId").val();
118
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"serialNumbers":imeis});
119
		jQuery.ajax({
120
			url: context+"/scanSerialized",
121
			type: 'POST',
122
			data: postData,
123
			contentType:'application/json',
124
			async: false,
125
			success: function (data) {
126
				alert("Purchase booked successfully");
127
				$('#scanModel').modal('hide');
128
				$("#scanModel").on("hidden.bs.modal", function () {
129
					$("#purchase-reference-submit-button").click();
130
				});
131
			},
132
			cache: false,
133
			processData: false
134
		});
135
		return false;
136
	});
137
 
138
	$("#grnNonSerializedSubmit").live('click', function(){
139
		var error = false;
140
		var errorText = "";
141
		if (error){
142
			return false;
143
		}
144
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
145
		var itemId = $("#scanNonSerializedModel .itemId").val();
146
		var quantity = $("#scanNonSerializedModel .quantity").val();
147
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
148
		jQuery.ajax({
149
			url: context+"/scanNonSerialized",
150
			type: 'POST',
151
			data: postData,
152
			contentType:'application/json',
153
			async: false,
154
			success: function (data) {
155
				alert("Purchase booked successfully");
156
				$('#scanNonSerializedModel').modal('hide');
157
				$("#scanNonSerializedModel").on("hidden.bs.modal", function () {
158
					$("#purchase-reference-submit-button").click();
159
				});
160
			},
161
			cache: false,
162
			processData: false
163
		});
164
		return false;
165
	});
166
 
167
	$("#grnImeiInformation :input").live('change paste keyup mouseup', function() {
168
		if ($(this).val().trim() != "") {
169
			console.log('The text box really changed this time');
170
			$('#grnImeiInformation :input').removeClass("border-highlight");
171
			if(findDuplicateSerialNumbers( $(this).val().trim()) > 0){
172
				var inputs = $("#grnImeiInformation :input[value="+$(this).val().trim()+"]");
173
				if(inputs.length > 1){
174
					inputs.each(function(){$(this).addClass("border-highlight")});
175
				}
176
			}
177
		}
178
	});
179
 
180
 
181
	$("#grnImeiInformation :input").live('paste', function() {
182
		if ($(this).val().trim() != "") {
183
			console.log('paste event');
184
			$(this).next("input .form-control").focus();
185
		}
186
	});
187
 
188
	$("#airwayBillOrInvoiceNumberText").live("keyup", function(e) {
189
		var keyCode = e.keyCode || e.which;
190
    	if(keyCode == 13){
191
        	$("#purchase-reference-submit-button").click();
192
    	}
193
	});
194
 
195
	$("#grn-history-search-button").live('click', function() {
196
		grnhistory.searchText = $("#grn-history-search-text").val();
197
		grnhistory.searchType = "purchaseReference";
198
		grnhistory.startTime = "0";
199
		grnhistory.endTime = "0";
200
		if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText){
201
			grnhistory.searchText = "";
202
		}
203
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
204
    });
205
 
206
	$("#grn-history-search-text").live("keyup", function(e) {
207
		var keyCode = e.keyCode || e.which;
208
    	if(keyCode == 13){
209
        	$("#grn-history-search-button").click();
210
    	}
211
	});
212
 
213
	$("#grn-history-paginated .next").live('click', function() {
214
		var start = $( "#grn-history-paginated .start" ).text();
215
		var end = $( "#grn-history-paginated .end" ).text();
216
		getGrnHistoryNextItems(start,end,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
217
		$("#grn-history-paginated .next").blur();
218
 
219
    });
220
 
221
	$("#grn-history-paginated .previous").live('click', function() {
222
		var start = $( "#grn-history-paginated .start" ).text();
223
		var end =  $( "#grn-history-paginated .end" ).text();
224
		var pre = end - 20;
225
		getGrnHistoryPreviousItems(start,end,pre,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
226
		$("#grn-history-paginated .previous").blur();
227
    });
228
 
229
	$("#grn-history-date-button").live('click', function() {
230
		var dateRange = $('#reportrange span').text();
231
		grnhistory.startTime = new Date(dateRange.split("-")[0]).getTime();
232
		grnhistory.endTime = new Date(dateRange.split("-")[1]).getTime();
233
		grnhistory.searchType = "dateFilter";
234
		grnhistory.searchText = "";
235
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
236
    });
237
 
238
    $(".grn-details").live('click',function(){
239
		var purchaseId = $(this).attr('data');
240
		console.log(purchaseId);
241
		loadGrnDetails(purchaseId,"grn-details-container");
242
	});
243
 
244
	$(".pending-grn-details").live('click',function(){
245
		console.log("pending-grn-details clicked");
246
		var orderId = $(this).attr('data');
247
		console.log("orderId : "+orderId);
248
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
249
	});
250
 
251
	$(".pending-grn").live('click',function(){
252
		var purchaseReference = $(this).attr('data');
253
		console.log(purchaseReference);
254
		loadPendingGrnDetails(purchaseReference,"main-content");
255
	});
256
 
257
});
258
 
259
 
260
function loadNewGrn(domId){
261
	//var response = doGetAjaxRequest(context+"/purchase");
262
	doAjaxRequestHandler(context+"/purchase", "GET", function(response){
263
		$('#' + domId).html(response);
264
	});
265
 
266
}
267
 
268
function getPurchaseByInvoiceNumber(){
269
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
270
	doAjaxRequestHandler(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber, "GET", function(response){
271
		$('#main-content').html(response);
272
	});
273
	//var response = doGetAjaxRequest(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber);
274
 
275
}
276
 
277
function loadPendingGrn(domId){
278
	doAjaxRequestHandler(context+"/pendingGrn", "GET", function(response){
279
		$('#' + domId).html(response);
280
	});
281
}
282
 
283
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
284
	doAjaxRequestHandler(context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
285
	        +"&startTime="+startTime
286
	        +"&endTime="+endTime, "GET", function(response){
287
		$('#' + domId).html(response);
288
	});
289
}
290
 
291
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
292
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
293
	        +"&startTime="+startTime
294
	        +"&endTime="+endTime+"&offset="+pre, "GET", function(response){
295
		$( "#grn-history-paginated .end" ).text(+end - +10);
296
		$( "#grn-history-paginated .start" ).text(+start - +10);
297
		$('#grn-history-table').html(response);
298
		$("#grn-history-paginated .next").prop('disabled', false);
299
		if (parseInt(pre)==0)
300
		{
301
			$("#grn-history-paginated .previous").prop('disabled', true);
302
		}
303
	});
304
 
305
}
306
 
307
 
308
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
309
	console.log(start);
310
	console.log(end);
311
	console.log(+end + +10);
312
	console.log(+start + +10);
313
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
314
	        +"&startTime="+startTime
315
	        +"&endTime="+endTime+"&offset="+end, "GET", function(response){
316
		$( "#grn-history-paginated .end" ).text(+end + +10);
317
		$( "#grn-history-paginated .start" ).text(+start + +10);
318
		var last = $( "#grn-history-paginated .end" ).text();
319
		var temp = $( "#grn-history-paginated .size" ).text();
320
		if (parseInt(last) >= parseInt(temp)){
321
			$("#grn-history-paginated .next").prop('disabled', true);
322
			//$( "#good-inventory-paginated .end" ).text(temp);
323
		}
324
	    $('#grn-history-table').html(response);
325
	    $("#grn-history-paginated .previous").prop('disabled', false);
326
	});
327
 
328
 
329
}
330
 
331
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
332
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
333
	        +"&startTime="+startTime
334
	        +"&endTime="+endTime+"&offset="+pre, "GET", function(response){
335
		$( "#grn-history-paginated .end" ).text(+end - +10);
336
		$( "#grn-history-paginated .start" ).text(+start - +10);
337
		$('#grn-history-table').html(response);
338
		$("#grn-history-paginated .next").prop('disabled', false);
339
		if (parseInt(pre)==0)
340
		{
341
			$("#grn-history-paginated .previous").prop('disabled', true);
342
		}
343
	});
344
 
345
}
346
 
347
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
348
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
349
}
350
 
351
function findDuplicateSerialNumbers(value){
352
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
353
    return result;
354
}
355
 
356
function loadGrnDetails(purchaseId, domId){
357
	doAjaxRequestHandler(context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId, "GET", function(response){
358
		$('#' + domId).html(response);
359
		window.dispatchEvent(new Event('resize'));
360
	});	
361
}
362
 
363
function loadPendingGrnDetails(orderId, domId){
364
	doAjaxRequestHandler(context+"/pendingGrnDetails/?orderId="+orderId, "GET", function(response){
365
		$('#' + domId).html(response);
366
		window.dispatchEvent(new Event('resize'));
367
	});
368
 
369
}