Subversion Repositories SmartDukaan

Rev

Rev 30694 | Rev 30702 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30694 amit.gupta 1
var grnhistory = grnhistory || {};
23343 ashik.ali 2
grnhistory.searchText = "";
3
grnhistory.searchType = "";
4
grnhistory.startTime = "0";
5
grnhistory.endTime = "0";
6
 
30694 amit.gupta 7
$(function () {
8
	$(document).on('click', ".new_grn", function () {
23343 ashik.ali 9
		loadNewGrn("main-content");
10
	});
11
 
30694 amit.gupta 12
	$(document).on('click', ".grn_history", function () {
30599 amit.gupta 13
		loadGrnHistory("main-content", "", "", moment(), moment);
23343 ashik.ali 14
	});
30694 amit.gupta 15
 
16
	$(document).on('click', ".pending_grn", function () {
23886 amit.gupta 17
		loadPendingGrn("main-content");
23343 ashik.ali 18
	});
19
 
30694 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);
30694 amit.gupta 30
		$("#grnImeiInformation").empty();
23343 ashik.ali 31
		var qty = parseInt(quantity);
32
		var divCode = '<div class="row">CONTENT</div><p></p>';
30701 amit.gupta 33
		doGetAjaxRequestHandler(`/purchase/get-imeis?invoiceNumber=${invoiceNumber}&itemId=${itemId}`, function (data) {
34
			let response = data.response;
35
			let index = 0;
36
			while (index < response.length) {
37
				let currentRow = response.length - index < 4 ? response.length - index : 4;
38
				let rowArr = [];
39
				for (let i = 0; i < currentRow; i++) {
40
					let checkedDiv =
41
						`<div class="col-sm-3">
42
						<label class="checkbox-inline">
43
							<input type="checkbox" value="${response[index]}"> ${response[index]}
44
						</label>
45
					</div>`;
46
					rowArr.push(checkedDiv);
47
					index++;
23343 ashik.ali 48
				}
30701 amit.gupta 49
				$("#grnImeiInformation").append(divCode.replace("CONTENT", rowArr.join("")));
23343 ashik.ali 50
			}
30701 amit.gupta 51
		});
23343 ashik.ali 52
	});
30701 amit.gupta 53
});
23343 ashik.ali 54
 
30701 amit.gupta 55
$(document).on('click', "td.startGrnNonSerialized", function () {
56
	var invoiceNumber = $(this).attr('invoiceNumber');
57
	var quantity = $(this).attr('quantity');
58
	var displayName = $(this).attr('displayName');
59
	var itemId = $(this).attr('itemId');
60
	console.log(quantity);
61
	$("#scanNonSerializedModel .modal-body .grnInvoiceNumber>span").text(invoiceNumber);
62
	$("#scanNonSerializedModel .modal-body .grnProductInfo>span").text(displayName);
63
	$("#scanNonSerializedModel .invoiceNumber").val(invoiceNumber);
64
	$("#scanNonSerializedModel .itemId").val(itemId);
65
	$("#grnImeiInformation").empty();
66
	var qty = parseInt(quantity);
67
	var divCode = '<div class="row">CONTENT</div><p></p>';
68
	var innerDiv = '<div class="col-sm-3">' +
69
		'<div class="input-group">' +
70
		'<input type="text" class="form-control">' +
71
		'</div>' +
72
		'</div>';
73
	while (qty != 0) {
74
		var divText = "";
75
		if (qty < 4) {
76
			var cp = qty;
77
			for (var i = 0; i < cp; i++) {
78
				divText = divText + innerDiv;
79
				qty = qty - 1;
23343 ashik.ali 80
			}
30701 amit.gupta 81
		} else {
82
			for (var i = 0; i < 4; i++) {
83
				divText = divText + innerDiv;
84
				qty = qty - 1;
85
			}
23343 ashik.ali 86
		}
30701 amit.gupta 87
		divText = divCode.replace("CONTENT", divText);
88
		$("#grnImeiInformation")
89
			.append(divText)
90
	}
91
});
30694 amit.gupta 92
 
30701 amit.gupta 93
$(document).on('click', "#grnSubmitSerialized", function () {
94
	var imeis = [];
95
	var error = false;
96
	var errorText = "";
97
	$("#grnImeiInformation :input").each(function () {
98
		var input = $(this).val().trim();
99
		if (imeis.indexOf(input) != -1 || !input) {
100
			error = true;
101
			if (!input) {
102
				$(this).addClass("border-highlight");
23343 ashik.ali 103
			}
30701 amit.gupta 104
		}
105
		imeis.push(input);
30694 amit.gupta 106
 
30701 amit.gupta 107
	});
108
	if (error) {
109
		return false;
110
	}
111
	var invoiceNumber = $("#scanModel .invoiceNumber").val();
112
	var itemId = $("#scanModel .itemId").val();
113
	var postData = JSON.stringify({
114
		"itemId": parseInt(itemId),
115
		"invoiceNumber": invoiceNumber,
116
		"serialNumbers": imeis
117
	});
118
	doPostAjaxRequestWithJsonHandler(context + "/scanSerialized", postData, function (response) {
119
		bootbox.alert("Purchase booked successfully", function () {
120
			$('#scanModel').on('hidden.bs.modal', function (event) {
121
				$("#purchase-reference-submit-button").click();
122
				$(this).off(event);
27198 amit.gupta 123
			});
30701 amit.gupta 124
			$('#scanModel').modal('hide');
23343 ashik.ali 125
		});
30701 amit.gupta 126
	});
127
	return false;
128
});
129
 
130
$(document).on('click', "#grnNonSerializedSubmit", function () {
131
	var error = false;
132
	var errorText = "";
133
	if (error) {
23343 ashik.ali 134
		return false;
30701 amit.gupta 135
	}
136
	var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
137
	var itemId = $("#scanNonSerializedModel .itemId").val();
138
	var quantity = $("#scanNonSerializedModel .quantity").val();
139
	var postData = JSON.stringify({
140
		"itemId": parseInt(itemId),
141
		"invoiceNumber": invoiceNumber,
142
		"quantity": parseInt(quantity)
23343 ashik.ali 143
	});
30701 amit.gupta 144
	doPostAjaxRequestWithJsonHandler(context + "/scanNonSerialized", postData, function (response) {
145
		bootbox.alert("Purchase booked successfully", function () {
146
			$('#scanNonSerializedModel').on('hidden.bs.modal', function (event) {
147
				$(this).off(event);
148
				$("#purchase-reference-submit-button").click();
27198 amit.gupta 149
			});
30701 amit.gupta 150
			$('#scanNonSerializedModel').modal('hide');
23343 ashik.ali 151
		});
152
	});
30701 amit.gupta 153
	return false;
154
});
23343 ashik.ali 155
 
30701 amit.gupta 156
$(document).on('change', "#grnImeiInformation :input", function () {
157
	if ($(this).val().trim() != "") {
158
		console.log('The text box really changed this time');
159
		$('#grnImeiInformation :input').removeClass("border-highlight");
160
		if (findDuplicateSerialNumbers($(this).val().trim()) > 0) {
161
			var inputs = $("#grnImeiInformation :input[value=" + $(this).val().trim() + "]");
162
			if (inputs.length > 1) {
163
				inputs.each(function () {
164
					$(this).addClass("border-highlight")
165
				});
23343 ashik.ali 166
			}
167
		}
30701 amit.gupta 168
	}
169
});
30694 amit.gupta 170
 
171
 
30701 amit.gupta 172
$(document).on('paste', "#grnImeiInformation :input", function () {
173
	if ($(this).val().trim() != "") {
174
		console.log('paste event');
175
		$(this).next("input .form-control").focus();
176
	}
177
});
23343 ashik.ali 178
 
30701 amit.gupta 179
$(document).on("keyup", "#airwayBillOrInvoiceNumberText", function (e) {
180
	var keyCode = e.keyCode || e.which;
181
	if (keyCode == 13) {
182
		$("#purchase-reference-submit-button").click();
183
	}
184
});
23343 ashik.ali 185
 
30701 amit.gupta 186
$(document).on('click', "#grn-history-search-button", function () {
187
	grnhistory.searchText = $("#grn-history-search-text").val();
188
	grnhistory.searchType = "purchaseReference";
189
	grnhistory.startTime = startDate;
190
	grnhistory.endTime = endDate;
191
	if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText) {
192
		grnhistory.searchText = "";
193
	}
194
	loadGrnHistorySearchInfo(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
195
});
30694 amit.gupta 196
 
30701 amit.gupta 197
$(document).on('click', "#grn-history-download-button", function () {
198
	grnhistory.searchText = $("#grn-history-search-text").val();
199
	grnhistory.searchType = "purchaseReference";
200
	grnhistory.startTime = startDate;
201
	grnhistory.endTime = endDate;
202
	if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText) {
203
		grnhistory.searchText = "";
204
	}
205
	downloadPurchaseInvoices(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
206
});
30694 amit.gupta 207
 
30701 amit.gupta 208
$(document).on("keyup", "#grn-history-search-text", function (e) {
209
	var keyCode = e.keyCode || e.which;
210
	if (keyCode == 13) {
211
		$("#grn-history-search-button").click();
212
	}
213
});
23343 ashik.ali 214
 
30701 amit.gupta 215
$(document).on('click', "#grn-history-paginated .next", function () {
216
	var params = {};
217
	params['purchaseReference'] = grnhistory.searchText;
218
	params['searchType'] = grnhistory.searchType;
219
	params['startTime'] = grnhistory.startTime;
220
	params['endTime'] = grnhistory.endTime;
221
	loadPaginatedNextItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
222
	$(this).blur();
30694 amit.gupta 223
 
30701 amit.gupta 224
});
30694 amit.gupta 225
 
30701 amit.gupta 226
$(document).on('click', "#grn-history-paginated .previous", function () {
227
	var params = {};
228
	params['purchaseReference'] = grnhistory.searchText;
229
	params['searchType'] = grnhistory.searchType;
230
	params['startTime'] = grnhistory.startTime;
231
	params['endTime'] = grnhistory.endTime;
232
	loadPaginatedPreviousItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
233
	$(this).blur();
30694 amit.gupta 234
 
30701 amit.gupta 235
});
30694 amit.gupta 236
 
30701 amit.gupta 237
$(document).on('click', "#grn-history-date-button", function () {
238
	var dateRange = $('#reportrange span').text();
239
	grnhistory.startTime = getDatesFromPicker($("#grnDateRange")).startDate;
240
	grnhistory.endTime = getDatesFromPicker($("#grnDateRange")).endDate;
241
	grnhistory.searchType = "dateFilter";
242
	grnhistory.searchText = "";
243
	loadGrnHistorySearchInfo(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
244
});
23343 ashik.ali 245
 
30701 amit.gupta 246
$(document).on('click', ".grn-details", function () {
247
	var purchaseId = $(this).attr('data');
248
	console.log(purchaseId);
249
	loadGrnDetails(purchaseId, "grn-details-container");
250
});
30694 amit.gupta 251
 
30701 amit.gupta 252
$(document).on('click', ".pending-grn-details", function () {
253
	console.log("pending-grn-details clicked");
254
	var orderId = $(this).attr('data');
255
	console.log("orderId : " + orderId);
256
	loadPendingGrnDetails(orderId, "pending-grn-details-container");
257
});
23343 ashik.ali 258
 
30701 amit.gupta 259
$(document).on('click', ".pending-grn", function () {
260
	var purchaseReference = $(this).attr('data');
261
	console.log(purchaseReference);
262
	loadPendingGrnDetails(purchaseReference, "main-content");
23343 ashik.ali 263
});
264
 
265
 
30466 amit.gupta 266
function loadNewGrn(domId, invoiceNumber) {
23343 ashik.ali 267
	//var response = doGetAjaxRequest(context+"/purchase");
30466 amit.gupta 268
	doGetAjaxRequestHandler(context + "/purchase", function (response) {
23343 ashik.ali 269
		$('#' + domId).html(response);
30466 amit.gupta 270
		if (invoiceNumber != undefined) {
271
			$("#airwayBillOrInvoiceNumberText").val(invoiceNumber);
272
			$("#purchase-reference-submit-button").click();
273
		}
23343 ashik.ali 274
	});
30466 amit.gupta 275
 
23343 ashik.ali 276
}
277
 
30694 amit.gupta 278
function getPurchaseByInvoiceNumber() {
23343 ashik.ali 279
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
30694 amit.gupta 280
	doGetAjaxRequestHandler(context + "/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber=" + airwayBillOrInvoiceNumber, function (response) {
23343 ashik.ali 281
		$('#main-content').html(response);
282
	});
283
}
284
 
30694 amit.gupta 285
function loadPendingGrn(domId) {
286
	doGetAjaxRequestHandler(context + "/pendingGrn", function (response) {
23343 ashik.ali 287
		$('#' + domId).html(response);
288
	});
289
}
290
 
30694 amit.gupta 291
function loadGrnHistory(domId, purchase_reference, searchType, startTime, endTime) {
292
	doGetAjaxRequestHandler(context + "/grnHistory?purchaseReference=" + purchase_reference + "&searchType=" + searchType
293
		+ "&startTime=" + startTime
294
		+ "&endTime=" + endTime, function (response) {
23343 ashik.ali 295
		$('#' + domId).html(response);
296
	});
297
}
298
 
30694 amit.gupta 299
function loadGrnHistorySearchInfo(search_text, searchType, startTime, endTime) {
300
	loadGrnHistory("main-content", search_text, searchType, startTime, endTime);
23343 ashik.ali 301
}
302
 
30694 amit.gupta 303
function downloadPurchaseInvoice(search_text, searchType, startTime, endTime) {
304
	purchaseInvoice_url = context + "/grnHistory?purchaseReference=" + purchase_reference + "&searchType=" + searchType
305
		+ "&startTime=" + startTime + "&endTime=" + endTime;
26013 amit.gupta 306
}
307
 
30694 amit.gupta 308
function findDuplicateSerialNumbers(value) {
309
	var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
310
	return result;
23343 ashik.ali 311
}
312
 
30694 amit.gupta 313
function loadGrnDetails(purchaseId, domId) {
314
	doGetAjaxRequestHandler(context + "/grnHistoryDetailByPurchaseId?purchaseId=" + purchaseId, function (response) {
23343 ashik.ali 315
		$('#' + domId).html(response);
316
		window.dispatchEvent(new Event('resize'));
30694 amit.gupta 317
	});
23343 ashik.ali 318
}
319
 
30694 amit.gupta 320
function loadPendingGrnDetails(orderId, domId) {
321
	doGetAjaxRequestHandler(context + "/pendingGrnDetails?orderId=" + orderId, function (response) {
23343 ashik.ali 322
		$('#' + domId).html(response);
323
		window.dispatchEvent(new Event('resize'));
324
	});
30694 amit.gupta 325
 
23343 ashik.ali 326
}
30694 amit.gupta 327
 
328
function grnPartial(invoiceNumber) {
329
	let serialNumbers = $("#all-imeis").tagsinput('items')
330
	let imeisJson = {
331
		serialNumbers: serialNumbers,
332
		invoiceNumber: invoiceNumber
333
	}
334
	doPostAjaxRequestWithJsonHandler(`${context}/purchase/grn-imeis`, JSON.stringify(imeisJson), function (data) {
335
		let response = data.response;
336
		if (response) {
337
			alert("Purchase booked successfully");
338
			$("#purchase-reference-submit-button").click();
339
		}
340
	});
341
}