Subversion Repositories SmartDukaan

Rev

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