Subversion Repositories SmartDukaan

Rev

Rev 23343 | Rev 23500 | 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";
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();
23419 ashik.ali 224
		var size = $("#grn-history-paginated .size").text();
225
		if(parseInt(end) == parseInt(size)){
226
			var mod = parseInt(end) % 10;
227
			end = parseInt(end) + (10 - mod); 
228
		}
23343 ashik.ali 229
		var pre = end - 20;
230
		getGrnHistoryPreviousItems(start,end,pre,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
231
		$("#grn-history-paginated .previous").blur();
232
    });
233
 
234
	$("#grn-history-date-button").live('click', function() {
235
		var dateRange = $('#reportrange span').text();
236
		grnhistory.startTime = new Date(dateRange.split("-")[0]).getTime();
237
		grnhistory.endTime = new Date(dateRange.split("-")[1]).getTime();
238
		grnhistory.searchType = "dateFilter";
239
		grnhistory.searchText = "";
240
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
241
    });
242
 
243
    $(".grn-details").live('click',function(){
244
		var purchaseId = $(this).attr('data');
245
		console.log(purchaseId);
246
		loadGrnDetails(purchaseId,"grn-details-container");
247
	});
248
 
249
	$(".pending-grn-details").live('click',function(){
250
		console.log("pending-grn-details clicked");
251
		var orderId = $(this).attr('data');
252
		console.log("orderId : "+orderId);
253
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
254
	});
255
 
256
	$(".pending-grn").live('click',function(){
257
		var purchaseReference = $(this).attr('data');
258
		console.log(purchaseReference);
259
		loadPendingGrnDetails(purchaseReference,"main-content");
260
	});
261
 
262
});
263
 
264
 
265
function loadNewGrn(domId){
266
	//var response = doGetAjaxRequest(context+"/purchase");
267
	doAjaxRequestHandler(context+"/purchase", "GET", function(response){
268
		$('#' + domId).html(response);
269
	});
270
 
271
}
272
 
273
function getPurchaseByInvoiceNumber(){
274
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
275
	doAjaxRequestHandler(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber, "GET", function(response){
276
		$('#main-content').html(response);
277
	});
278
	//var response = doGetAjaxRequest(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber);
279
 
280
}
281
 
282
function loadPendingGrn(domId){
283
	doAjaxRequestHandler(context+"/pendingGrn", "GET", function(response){
284
		$('#' + domId).html(response);
285
	});
286
}
287
 
288
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
289
	doAjaxRequestHandler(context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
290
	        +"&startTime="+startTime
291
	        +"&endTime="+endTime, "GET", function(response){
292
		$('#' + domId).html(response);
293
	});
294
}
295
 
296
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
297
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
298
	        +"&startTime="+startTime
299
	        +"&endTime="+endTime+"&offset="+pre, "GET", function(response){
300
		$( "#grn-history-paginated .end" ).text(+end - +10);
301
		$( "#grn-history-paginated .start" ).text(+start - +10);
302
		$('#grn-history-table').html(response);
303
		$("#grn-history-paginated .next").prop('disabled', false);
304
		if (parseInt(pre)==0)
305
		{
306
			$("#grn-history-paginated .previous").prop('disabled', true);
307
		}
308
	});
309
 
310
}
311
 
312
 
313
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
314
	console.log(start);
315
	console.log(end);
316
	console.log(+end + +10);
317
	console.log(+start + +10);
318
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
319
	        +"&startTime="+startTime
320
	        +"&endTime="+endTime+"&offset="+end, "GET", function(response){
23419 ashik.ali 321
		var size = $("#grn-history-paginated .size").text();
322
		if((parseInt(end) + 10) > parseInt(size)){
323
			console.log("(end + 10) > size == true");
324
			$( "#grn-history-paginated .end" ).text(size);
325
		}else{
326
			console.log("(end + 10) > size == false");
327
			$( "#grn-history-paginated .end" ).text(+end + +10);
328
		}
23343 ashik.ali 329
		$( "#grn-history-paginated .start" ).text(+start + +10);
330
		var last = $( "#grn-history-paginated .end" ).text();
331
		var temp = $( "#grn-history-paginated .size" ).text();
332
		if (parseInt(last) >= parseInt(temp)){
333
			$("#grn-history-paginated .next").prop('disabled', true);
334
			//$( "#good-inventory-paginated .end" ).text(temp);
335
		}
336
	    $('#grn-history-table').html(response);
337
	    $("#grn-history-paginated .previous").prop('disabled', false);
338
	});
339
 
340
 
341
}
342
 
343
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
344
	doAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
345
	        +"&startTime="+startTime
346
	        +"&endTime="+endTime+"&offset="+pre, "GET", function(response){
347
		$( "#grn-history-paginated .end" ).text(+end - +10);
348
		$( "#grn-history-paginated .start" ).text(+start - +10);
349
		$('#grn-history-table').html(response);
350
		$("#grn-history-paginated .next").prop('disabled', false);
351
		if (parseInt(pre)==0)
352
		{
353
			$("#grn-history-paginated .previous").prop('disabled', true);
354
		}
355
	});
356
 
357
}
358
 
359
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
360
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
361
}
362
 
363
function findDuplicateSerialNumbers(value){
364
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
365
    return result;
366
}
367
 
368
function loadGrnDetails(purchaseId, domId){
369
	doAjaxRequestHandler(context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId, "GET", function(response){
370
		$('#' + domId).html(response);
371
		window.dispatchEvent(new Event('resize'));
372
	});	
373
}
374
 
375
function loadPendingGrnDetails(orderId, domId){
376
	doAjaxRequestHandler(context+"/pendingGrnDetails/?orderId="+orderId, "GET", function(response){
377
		$('#' + domId).html(response);
378
		window.dispatchEvent(new Event('resize'));
379
	});
380
 
381
}