Subversion Repositories SmartDukaan

Rev

Rev 24456 | Rev 26013 | 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){
24456 amit.gupta 121
			if(typeof loaderDialogObj!="undefined")
122
				loaderDialogObj.modal('hide');
24457 amit.gupta 123
			setTimeout(function(){
124
				bootbox.alert("Purchase booked successfully");
125
				$("#scanModel").one("hidden.bs.modal", function () {
126
					$("#purchase-reference-submit-button").click();
127
				});
128
				$('#scanModel').modal('hide');
129
			}, 300);
23343 ashik.ali 130
		});
131
		return false;
132
	});
133
 
134
	$("#grnNonSerializedSubmit").live('click', function(){
135
		var error = false;
136
		var errorText = "";
137
		if (error){
138
			return false;
139
		}
140
		var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
141
		var itemId = $("#scanNonSerializedModel .itemId").val();
142
		var quantity = $("#scanNonSerializedModel .quantity").val();
143
		var postData = JSON.stringify({"itemId":parseInt(itemId),"invoiceNumber":invoiceNumber,"quantity":parseInt(quantity)});
23500 ashik.ali 144
		doPostAjaxRequestWithJsonHandler(context+"/scanNonSerialized", postData, function(response){
24456 amit.gupta 145
			if(typeof loaderDialogObj!="undefined")
146
				loaderDialogObj.modal('hide');
24457 amit.gupta 147
			setTimeout(function(){
148
				bootbox.alert("Purchase booked successfully");
149
				$("#scanModel").one("hidden.bs.modal", function () {
150
					$("#purchase-reference-submit-button").click();
151
				});
152
				$('#scanModel').modal('hide');
153
			}, 300);
23343 ashik.ali 154
		});
155
		return false;
156
	});
157
 
24456 amit.gupta 158
	$("#grnImeiInformation :input").live('change', function() {
23343 ashik.ali 159
		if ($(this).val().trim() != "") {
160
			console.log('The text box really changed this time');
161
			$('#grnImeiInformation :input').removeClass("border-highlight");
162
			if(findDuplicateSerialNumbers( $(this).val().trim()) > 0){
163
				var inputs = $("#grnImeiInformation :input[value="+$(this).val().trim()+"]");
164
				if(inputs.length > 1){
165
					inputs.each(function(){$(this).addClass("border-highlight")});
166
				}
167
			}
168
		}
169
	});
170
 
171
 
172
	$("#grnImeiInformation :input").live('paste', function() {
173
		if ($(this).val().trim() != "") {
174
			console.log('paste event');
175
			$(this).next("input .form-control").focus();
176
		}
177
	});
178
 
179
	$("#airwayBillOrInvoiceNumberText").live("keyup", function(e) {
180
		var keyCode = e.keyCode || e.which;
181
    	if(keyCode == 13){
182
        	$("#purchase-reference-submit-button").click();
183
    	}
184
	});
185
 
186
	$("#grn-history-search-button").live('click', function() {
187
		grnhistory.searchText = $("#grn-history-search-text").val();
188
		grnhistory.searchType = "purchaseReference";
23886 amit.gupta 189
		grnhistory.startTime = startDate;
190
		grnhistory.endTime = endDate;
23343 ashik.ali 191
		if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText){
192
			grnhistory.searchText = "";
193
		}
194
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
195
    });
196
 
197
	$("#grn-history-search-text").live("keyup", function(e) {
198
		var keyCode = e.keyCode || e.which;
199
    	if(keyCode == 13){
200
        	$("#grn-history-search-button").click();
201
    	}
202
	});
203
 
204
	$("#grn-history-paginated .next").live('click', function() {
23629 ashik.ali 205
		var params = {};
206
		params['purchaseReference'] = grnhistory.searchText;
207
		params['searchType'] = grnhistory.searchType;
208
		params['startTime'] = grnhistory.startTime;
209
		params['endTime'] = grnhistory.endTime;
210
		loadPaginatedNextItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
211
		$(this).blur();
23343 ashik.ali 212
 
213
    });
214
 
215
	$("#grn-history-paginated .previous").live('click', function() {
23629 ashik.ali 216
		var params = {};
217
		params['purchaseReference'] = grnhistory.searchText;
218
		params['searchType'] = grnhistory.searchType;
219
		params['startTime'] = grnhistory.startTime;
220
		params['endTime'] = grnhistory.endTime;
221
		loadPaginatedPreviousItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
222
		$(this).blur();
223
 
23343 ashik.ali 224
    });
225
 
226
	$("#grn-history-date-button").live('click', function() {
227
		var dateRange = $('#reportrange span').text();
23886 amit.gupta 228
		grnhistory.startTime = startDate;
229
		grnhistory.endTime = endDate;
23343 ashik.ali 230
		grnhistory.searchType = "dateFilter";
231
		grnhistory.searchText = "";
232
		loadGrnHistorySearchInfo(grnhistory.searchText,grnhistory.searchType,grnhistory.startTime,grnhistory.endTime);
233
    });
234
 
235
    $(".grn-details").live('click',function(){
236
		var purchaseId = $(this).attr('data');
237
		console.log(purchaseId);
238
		loadGrnDetails(purchaseId,"grn-details-container");
239
	});
240
 
241
	$(".pending-grn-details").live('click',function(){
242
		console.log("pending-grn-details clicked");
243
		var orderId = $(this).attr('data');
244
		console.log("orderId : "+orderId);
245
		loadPendingGrnDetails(orderId, "pending-grn-details-container");
246
	});
247
 
248
	$(".pending-grn").live('click',function(){
249
		var purchaseReference = $(this).attr('data');
250
		console.log(purchaseReference);
251
		loadPendingGrnDetails(purchaseReference,"main-content");
252
	});
253
 
254
});
255
 
256
 
257
function loadNewGrn(domId){
258
	//var response = doGetAjaxRequest(context+"/purchase");
23500 ashik.ali 259
	doGetAjaxRequestHandler(context+"/purchase", function(response){
23343 ashik.ali 260
		$('#' + domId).html(response);
261
	});
262
 
263
}
264
 
265
function getPurchaseByInvoiceNumber(){
266
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
23500 ashik.ali 267
	doGetAjaxRequestHandler(context+"/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber="+airwayBillOrInvoiceNumber, function(response){
23343 ashik.ali 268
		$('#main-content').html(response);
269
	});
270
}
271
 
272
function loadPendingGrn(domId){
23500 ashik.ali 273
	doGetAjaxRequestHandler(context+"/pendingGrn", function(response){
23343 ashik.ali 274
		$('#' + domId).html(response);
275
	});
276
}
277
 
278
function loadGrnHistory(domId,purchase_reference,searchType, startTime, endTime){
23783 ashik.ali 279
	doGetAjaxRequestHandler(context+"/grnHistory?purchaseReference="+purchase_reference+"&searchType="+searchType
23343 ashik.ali 280
	        +"&startTime="+startTime
23500 ashik.ali 281
	        +"&endTime="+endTime, function(response){
23343 ashik.ali 282
		$('#' + domId).html(response);
283
	});
284
}
285
 
286
function loadGrnHistorySearchInfo(search_text,searchType,startTime,endTime){
287
	loadGrnHistory("main-content",search_text,searchType,startTime,endTime);
288
}
289
 
290
function findDuplicateSerialNumbers(value){
291
    var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
292
    return result;
293
}
294
 
295
function loadGrnDetails(purchaseId, domId){
23783 ashik.ali 296
	doGetAjaxRequestHandler(context+"/grnHistoryDetailByPurchaseId?purchaseId="+purchaseId, function(response){
23343 ashik.ali 297
		$('#' + domId).html(response);
298
		window.dispatchEvent(new Event('resize'));
299
	});	
300
}
301
 
302
function loadPendingGrnDetails(orderId, domId){
23783 ashik.ali 303
	doGetAjaxRequestHandler(context+"/pendingGrnDetails?orderId="+orderId, function(response){
23343 ashik.ali 304
		$('#' + domId).html(response);
305
		window.dispatchEvent(new Event('resize'));
306
	});
307
 
308
}