Subversion Repositories SmartDukaan

Rev

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