Subversion Repositories SmartDukaan

Rev

Rev 23419 | Rev 23629 | 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});
23500 ashik.ali 119
		doPostAjaxRequestWithJsonHandler(context+"/scanSerialized", postData, function(response){
120
			alert("Purchase booked successfully");
121
			$('#scanModel').modal('hide');
122
			$("#scanModel").on("hidden.bs.modal", function () {
123
				$("#purchase-reference-submit-button").click();
124
			});
23343 ashik.ali 125
		});
126
		return false;
127
	});
128
 
129
	$("#grnNonSerializedSubmit").live('click', function(){
130
		var error = false;
131
		var errorText = "";
132
		if (error){
133
			return false;
134
		}
135
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
136
		var itemId = $("#scanNonSerializedModel .itemId").val();
137
		var quantity = $("#scanNonSerializedModel .quantity").val();
138
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
23500 ashik.ali 139
		doPostAjaxRequestWithJsonHandler(context+"/scanNonSerialized", postData, function(response){
140
			alert("Purchase booked successfully");
141
			$('#scanNonSerializedModel').modal('hide');
142
			$("#scanNonSerializedModel").on("hidden.bs.modal", function () {
143
				$("#purchase-reference-submit-button").click();
144
			});
23343 ashik.ali 145
		});
146
		return false;
147
	});
148
 
149
	$("#grnImeiInformation :input").live('change paste keyup mouseup', function() {
150
		if ($(this).val().trim() != "") {
151
			console.log('The text box really changed this time');
152
			$('#grnImeiInformation :input').removeClass("border-highlight");
153
			if(findDuplicateSerialNumbers( $(this).val().trim()) > 0){
154
				var inputs = $("#grnImeiInformation :input[value="+$(this).val().trim()+"]");
155
				if(inputs.length > 1){
156
					inputs.each(function(){$(this).addClass("border-highlight")});
157
				}
158
			}
159
		}
160
	});
161
 
162
 
163
	$("#grnImeiInformation :input").live('paste', function() {
164
		if ($(this).val().trim() != "") {
165
			console.log('paste event');
166
			$(this).next("input .form-control").focus();
167
		}
168
	});
169
 
170
	$("#airwayBillOrInvoiceNumberText").live("keyup", function(e) {
171
		var keyCode = e.keyCode || e.which;
172
    	if(keyCode == 13){
173
        	$("#purchase-reference-submit-button").click();
174
    	}
175
	});
176
 
177
	$("#grn-history-search-button").live('click', function() {
178
		grnhistory.searchText = $("#grn-history-search-text").val();
179
		grnhistory.searchType = "purchaseReference";
180
		grnhistory.startTime = "0";
181
		grnhistory.endTime = "0";
182
		if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText){
183
			grnhistory.searchText = "";
184
		}
185
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
186
    });
187
 
188
	$("#grn-history-search-text").live("keyup", function(e) {
189
		var keyCode = e.keyCode || e.which;
190
    	if(keyCode == 13){
191
        	$("#grn-history-search-button").click();
192
    	}
193
	});
194
 
195
	$("#grn-history-paginated .next").live('click', function() {
196
		var start = $( "#grn-history-paginated .start" ).text();
197
		var end = $( "#grn-history-paginated .end" ).text();
198
		getGrnHistoryNextItems(start,end,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
199
		$("#grn-history-paginated .next").blur();
200
 
201
    });
202
 
203
	$("#grn-history-paginated .previous").live('click', function() {
204
		var start = $( "#grn-history-paginated .start" ).text();
205
		var end =  $( "#grn-history-paginated .end" ).text();
23419 ashik.ali 206
		var size = $("#grn-history-paginated .size").text();
207
		if(parseInt(end) == parseInt(size)){
208
			var mod = parseInt(end) % 10;
209
			end = parseInt(end) + (10 - mod); 
210
		}
23343 ashik.ali 211
		var pre = end - 20;
212
		getGrnHistoryPreviousItems(start,end,pre,grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
213
		$("#grn-history-paginated .previous").blur();
214
    });
215
 
216
	$("#grn-history-date-button").live('click', function() {
217
		var dateRange = $('#reportrange span').text();
218
		grnhistory.startTime = new Date(dateRange.split("-")[0]).getTime();
219
		grnhistory.endTime = new Date(dateRange.split("-")[1]).getTime();
220
		grnhistory.searchType = "dateFilter";
221
		grnhistory.searchText = "";
222
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
223
    });
224
 
225
    $(".grn-details").live('click',function(){
226
		var purchaseId = $(this).attr('data');
227
		console.log(purchaseId);
228
		loadGrnDetails(purchaseId,"grn-details-container");
229
	});
230
 
231
	$(".pending-grn-details").live('click',function(){
232
		console.log("pending-grn-details clicked");
233
		var orderId = $(this).attr('data');
234
		console.log("orderId : "+orderId);
235
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
236
	});
237
 
238
	$(".pending-grn").live('click',function(){
239
		var purchaseReference = $(this).attr('data');
240
		console.log(purchaseReference);
241
		loadPendingGrnDetails(purchaseReference,"main-content");
242
	});
243
 
244
});
245
 
246
 
247
function loadNewGrn(domId){
248
	//var response = doGetAjaxRequest(context+"/purchase");
23500 ashik.ali 249
	doGetAjaxRequestHandler(context+"/purchase", function(response){
23343 ashik.ali 250
		$('#' + domId).html(response);
251
	});
252
 
253
}
254
 
255
function getPurchaseByInvoiceNumber(){
256
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
23500 ashik.ali 257
	doGetAjaxRequestHandler(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber, function(response){
23343 ashik.ali 258
		$('#main-content').html(response);
259
	});
260
}
261
 
262
function loadPendingGrn(domId){
23500 ashik.ali 263
	doGetAjaxRequestHandler(context+"/pendingGrn", function(response){
23343 ashik.ali 264
		$('#' + domId).html(response);
265
	});
266
}
267
 
268
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
23500 ashik.ali 269
	doGetAjaxRequestHandler(context+"/grnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 270
	        +"&startTime="+startTime
23500 ashik.ali 271
	        +"&endTime="+endTime, function(response){
23343 ashik.ali 272
		$('#' + domId).html(response);
273
	});
274
}
275
 
276
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
23500 ashik.ali 277
	doGetAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 278
	        +"&startTime="+startTime
23500 ashik.ali 279
	        +"&endTime="+endTime+"&offset="+pre, function(response){
23343 ashik.ali 280
		$( "#grn-history-paginated .end" ).text(+end - +10);
281
		$( "#grn-history-paginated .start" ).text(+start - +10);
282
		$('#grn-history-table').html(response);
283
		$("#grn-history-paginated .next").prop('disabled', false);
23500 ashik.ali 284
		if (parseInt(pre)==0){
23343 ashik.ali 285
			$("#grn-history-paginated .previous").prop('disabled', true);
286
		}
287
	});
288
 
289
}
290
 
291
 
292
function getGrnHistoryNextItems(start, end, purchase_reference, searchType,startTime,endTime){
293
	console.log(start);
294
	console.log(end);
295
	console.log(+end + +10);
296
	console.log(+start + +10);
23500 ashik.ali 297
	doGetAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 298
	        +"&startTime="+startTime
23500 ashik.ali 299
	        +"&endTime="+endTime+"&offset="+end, function(response){
23419 ashik.ali 300
		var size = $("#grn-history-paginated .size").text();
301
		if((parseInt(end) + 10) > parseInt(size)){
302
			console.log("(end + 10) > size == true");
303
			$( "#grn-history-paginated .end" ).text(size);
304
		}else{
305
			console.log("(end + 10) > size == false");
306
			$( "#grn-history-paginated .end" ).text(+end + +10);
307
		}
23343 ashik.ali 308
		$( "#grn-history-paginated .start" ).text(+start + +10);
309
		var last = $( "#grn-history-paginated .end" ).text();
310
		var temp = $( "#grn-history-paginated .size" ).text();
311
		if (parseInt(last) >= parseInt(temp)){
312
			$("#grn-history-paginated .next").prop('disabled', true);
313
			//$( "#good-inventory-paginated .end" ).text(temp);
314
		}
315
	    $('#grn-history-table').html(response);
316
	    $("#grn-history-paginated .previous").prop('disabled', false);
317
	});
318
 
319
 
320
}
321
 
322
function getGrnHistoryPreviousItems(start,end,pre,purchase_reference, searchType,startTime,endTime){
23500 ashik.ali 323
	doGetAjaxRequestHandler(context+"/getPaginatedGrnHistory/?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 324
	        +"&startTime="+startTime
23500 ashik.ali 325
	        +"&endTime="+endTime+"&offset="+pre, function(response){
23343 ashik.ali 326
		$( "#grn-history-paginated .end" ).text(+end - +10);
327
		$( "#grn-history-paginated .start" ).text(+start - +10);
328
		$('#grn-history-table').html(response);
329
		$("#grn-history-paginated .next").prop('disabled', false);
330
		if (parseInt(pre)==0)
331
		{
332
			$("#grn-history-paginated .previous").prop('disabled', true);
333
		}
334
	});
335
 
336
}
337
 
338
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
339
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
340
}
341
 
342
function findDuplicateSerialNumbers(value){
343
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
344
    return result;
345
}
346
 
347
function loadGrnDetails(purchaseId, domId){
23500 ashik.ali 348
	doGetAjaxRequestHandler(context+"/grnHistoryDetailByPurchaseId/?purchaseId="+purchaseId, function(response){
23343 ashik.ali 349
		$('#' + domId).html(response);
350
		window.dispatchEvent(new Event('resize'));
351
	});	
352
}
353
 
354
function loadPendingGrnDetails(orderId, domId){
23500 ashik.ali 355
	doGetAjaxRequestHandler(context+"/pendingGrnDetails/?orderId="+orderId, function(response){
23343 ashik.ali 356
		$('#' + domId).html(response);
357
		window.dispatchEvent(new Event('resize'));
358
	});
359
 
360
}