Subversion Repositories SmartDukaan

Rev

Rev 35555 | 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 () {
32584 raveendra. 13
		loadGrnHistory("main-content", "", "", moment().format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS), moment().format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS));
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>';
33995 vikas.jang 73
	while (qty > 0) {
30701 amit.gupta 74
		var divText = "";
35459 amit 75
		if (qty < 4) {
76
			var cp = qty;
77
			for (var i = 0; i < cp; i++) {
78
				divText = divText + innerDiv;
79
				qty = qty - 1;
80
			}
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 () {
30702 amit.gupta 94
	let imeis = [];
95
	$("#grnImeiInformation :input:checked").each(function () {
30701 amit.gupta 96
		var input = $(this).val().trim();
97
		imeis.push(input);
98
	});
30702 amit.gupta 99
	let invoiceNumber = $("#scanModel .invoiceNumber").val();
100
	let itemId = $("#scanModel .itemId").val();
101
	let postData = JSON.stringify({
30701 amit.gupta 102
		"itemId": parseInt(itemId),
103
		"invoiceNumber": invoiceNumber,
104
		"serialNumbers": imeis
105
	});
106
	doPostAjaxRequestWithJsonHandler(context + "/scanSerialized", postData, function (response) {
107
		bootbox.alert("Purchase booked successfully", function () {
108
			$('#scanModel').on('hidden.bs.modal', function (event) {
109
				$("#purchase-reference-submit-button").click();
110
				$(this).off(event);
27198 amit.gupta 111
			});
30701 amit.gupta 112
			$('#scanModel').modal('hide');
23343 ashik.ali 113
		});
30701 amit.gupta 114
	});
115
	return false;
116
});
117
 
118
$(document).on('click', "#grnNonSerializedSubmit", function () {
119
	var error = false;
120
	var errorText = "";
121
	if (error) {
23343 ashik.ali 122
		return false;
30701 amit.gupta 123
	}
124
	var invoiceNumber = $("#scanNonSerializedModel .invoiceNumber").val();
125
	var itemId = $("#scanNonSerializedModel .itemId").val();
126
	var quantity = $("#scanNonSerializedModel .quantity").val();
127
	var postData = JSON.stringify({
128
		"itemId": parseInt(itemId),
129
		"invoiceNumber": invoiceNumber,
130
		"quantity": parseInt(quantity)
23343 ashik.ali 131
	});
30701 amit.gupta 132
	doPostAjaxRequestWithJsonHandler(context + "/scanNonSerialized", postData, function (response) {
133
		bootbox.alert("Purchase booked successfully", function () {
134
			$('#scanNonSerializedModel').on('hidden.bs.modal', function (event) {
135
				$(this).off(event);
136
				$("#purchase-reference-submit-button").click();
27198 amit.gupta 137
			});
30701 amit.gupta 138
			$('#scanNonSerializedModel').modal('hide');
23343 ashik.ali 139
		});
140
	});
30701 amit.gupta 141
	return false;
142
});
23343 ashik.ali 143
 
30701 amit.gupta 144
$(document).on('change', "#grnImeiInformation :input", function () {
35459 amit 145
	if ($(this).val().trim() != "") {
146
		console.log('The text box really changed this time');
30701 amit.gupta 147
		$('#grnImeiInformation :input').removeClass("border-highlight");
35459 amit 148
		if (findDuplicateSerialNumbers($(this).val().trim()) > 0) {
149
			var inputs = $("#grnImeiInformation :input[value=" + $(this).val().trim() + "]");
30701 amit.gupta 150
			if (inputs.length > 1) {
151
				inputs.each(function () {
35459 amit 152
					$(this).addClass("border-highlight")
30701 amit.gupta 153
				});
23343 ashik.ali 154
			}
155
		}
30701 amit.gupta 156
	}
157
});
30694 amit.gupta 158
 
35459 amit 159
 
30701 amit.gupta 160
$(document).on('paste', "#grnImeiInformation :input", function () {
35459 amit 161
	if ($(this).val().trim() != "") {
162
		console.log('paste event');
30701 amit.gupta 163
		$(this).next("input .form-control").focus();
164
	}
165
});
23343 ashik.ali 166
 
30701 amit.gupta 167
$(document).on("keyup", "#airwayBillOrInvoiceNumberText", function (e) {
168
	var keyCode = e.keyCode || e.which;
35459 amit 169
	if (keyCode == 13) {
30701 amit.gupta 170
		$("#purchase-reference-submit-button").click();
171
	}
172
});
23343 ashik.ali 173
 
30701 amit.gupta 174
$(document).on('click', "#grn-history-search-button", function () {
175
	grnhistory.searchText = $("#grn-history-search-text").val();
176
	grnhistory.searchType = "purchaseReference";
35459 amit 177
	grnhistory.startTime = startDate;
178
	grnhistory.endTime = endDate;
179
	if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText) {
30701 amit.gupta 180
		grnhistory.searchText = "";
181
	}
182
	loadGrnHistorySearchInfo(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
183
});
30694 amit.gupta 184
 
30701 amit.gupta 185
$(document).on('click', "#grn-history-download-button", function () {
186
	grnhistory.searchText = $("#grn-history-search-text").val();
187
	grnhistory.searchType = "purchaseReference";
35459 amit 188
	grnhistory.startTime = startDate;
189
	grnhistory.endTime = endDate;
190
	if (typeof (grnhistory.searchText) == "undefined" || !grnhistory.searchText) {
30701 amit.gupta 191
		grnhistory.searchText = "";
192
	}
193
	downloadPurchaseInvoices(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
194
});
30694 amit.gupta 195
 
30701 amit.gupta 196
$(document).on("keyup", "#grn-history-search-text", function (e) {
197
	var keyCode = e.keyCode || e.which;
35459 amit 198
	if (keyCode == 13) {
30701 amit.gupta 199
		$("#grn-history-search-button").click();
200
	}
201
});
23343 ashik.ali 202
 
30701 amit.gupta 203
$(document).on('click', "#grn-history-paginated .next", function () {
204
	var params = {};
205
	params['purchaseReference'] = grnhistory.searchText;
206
	params['searchType'] = grnhistory.searchType;
207
	params['startTime'] = grnhistory.startTime;
208
	params['endTime'] = grnhistory.endTime;
209
	loadPaginatedNextItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
210
	$(this).blur();
30694 amit.gupta 211
 
30701 amit.gupta 212
});
30694 amit.gupta 213
 
30701 amit.gupta 214
$(document).on('click', "#grn-history-paginated .previous", function () {
215
	var params = {};
216
	params['purchaseReference'] = grnhistory.searchText;
217
	params['searchType'] = grnhistory.searchType;
218
	params['startTime'] = grnhistory.startTime;
219
	params['endTime'] = grnhistory.endTime;
220
	loadPaginatedPreviousItems('/getPaginatedGrnHistory', params, 'grn-history-paginated', 'grn-history-table', null);
221
	$(this).blur();
30694 amit.gupta 222
 
30701 amit.gupta 223
});
30694 amit.gupta 224
 
30701 amit.gupta 225
$(document).on('click', "#grn-history-date-button", function () {
226
	var dateRange = $('#reportrange span').text();
227
	grnhistory.startTime = getDatesFromPicker($("#grnDateRange")).startDate;
228
	grnhistory.endTime = getDatesFromPicker($("#grnDateRange")).endDate;
229
	grnhistory.searchType = "dateFilter";
230
	grnhistory.searchText = "";
231
	loadGrnHistorySearchInfo(grnhistory.searchText, grnhistory.searchType, grnhistory.startTime, grnhistory.endTime);
232
});
23343 ashik.ali 233
 
30701 amit.gupta 234
$(document).on('click', ".grn-details", function () {
235
	var purchaseId = $(this).attr('data');
236
	console.log(purchaseId);
237
	loadGrnDetails(purchaseId, "grn-details-container");
238
});
30694 amit.gupta 239
 
30701 amit.gupta 240
$(document).on('click', ".pending-grn-details", function () {
241
	console.log("pending-grn-details clicked");
242
	var orderId = $(this).attr('data');
243
	console.log("orderId : " + orderId);
244
	loadPendingGrnDetails(orderId, "pending-grn-details-container");
245
});
23343 ashik.ali 246
 
30701 amit.gupta 247
$(document).on('click', ".pending-grn", function () {
248
	var purchaseReference = $(this).attr('data');
249
	console.log(purchaseReference);
250
	loadPendingGrnDetails(purchaseReference, "main-content");
23343 ashik.ali 251
});
252
 
253
 
30466 amit.gupta 254
function loadNewGrn(domId, invoiceNumber) {
35459 amit 255
	//var response = doGetAjaxRequest(context+"/purchase");
30466 amit.gupta 256
	doGetAjaxRequestHandler(context + "/purchase", function (response) {
23343 ashik.ali 257
		$('#' + domId).html(response);
35459 amit 258
		if (invoiceNumber != undefined) {
30466 amit.gupta 259
			$("#airwayBillOrInvoiceNumberText").val(invoiceNumber);
260
			$("#purchase-reference-submit-button").click();
261
		}
23343 ashik.ali 262
	});
35459 amit 263
 
23343 ashik.ali 264
}
265
 
30694 amit.gupta 266
function getPurchaseByInvoiceNumber() {
23343 ashik.ali 267
	var airwayBillOrInvoiceNumber = $('#airwayBillOrInvoiceNumberText').val();
30694 amit.gupta 268
	doGetAjaxRequestHandler(context + "/purchaseByInvoiceNumber?airwayBillOrInvoiceNumber=" + airwayBillOrInvoiceNumber, function (response) {
23343 ashik.ali 269
		$('#main-content').html(response);
270
	});
271
}
272
 
30694 amit.gupta 273
function loadPendingGrn(domId) {
274
	doGetAjaxRequestHandler(context + "/pendingGrn", function (response) {
23343 ashik.ali 275
		$('#' + domId).html(response);
276
	});
277
}
278
 
30694 amit.gupta 279
function loadGrnHistory(domId, purchase_reference, searchType, startTime, endTime) {
280
	doGetAjaxRequestHandler(context + "/grnHistory?purchaseReference=" + purchase_reference + "&searchType=" + searchType
281
		+ "&startTime=" + startTime
282
		+ "&endTime=" + endTime, function (response) {
23343 ashik.ali 283
		$('#' + domId).html(response);
284
	});
285
}
286
 
30694 amit.gupta 287
function loadGrnHistorySearchInfo(search_text, searchType, startTime, endTime) {
288
	loadGrnHistory("main-content", search_text, searchType, startTime, endTime);
23343 ashik.ali 289
}
290
 
30694 amit.gupta 291
function downloadPurchaseInvoice(search_text, searchType, startTime, endTime) {
35459 amit 292
	purchaseInvoice_url = context + "/grnHistory?purchaseReference=" + purchase_reference + "&searchType=" + searchType
30694 amit.gupta 293
		+ "&startTime=" + startTime + "&endTime=" + endTime;
26013 amit.gupta 294
}
295
 
30694 amit.gupta 296
function findDuplicateSerialNumbers(value) {
297
	var result = $("#grnImeiInformation :input[value='" + value + "']").length - 1;
298
	return result;
23343 ashik.ali 299
}
300
 
30694 amit.gupta 301
function loadGrnDetails(purchaseId, domId) {
302
	doGetAjaxRequestHandler(context + "/grnHistoryDetailByPurchaseId?purchaseId=" + purchaseId, function (response) {
23343 ashik.ali 303
		$('#' + domId).html(response);
304
		window.dispatchEvent(new Event('resize'));
30694 amit.gupta 305
	});
23343 ashik.ali 306
}
307
 
30694 amit.gupta 308
function loadPendingGrnDetails(orderId, domId) {
309
	doGetAjaxRequestHandler(context + "/pendingGrnDetails?orderId=" + orderId, function (response) {
23343 ashik.ali 310
		$('#' + domId).html(response);
311
		window.dispatchEvent(new Event('resize'));
312
	});
30694 amit.gupta 313
 
23343 ashik.ali 314
}
30694 amit.gupta 315
 
316
function grnPartial(invoiceNumber) {
35459 amit 317
	let serialNumbers = $("#all-imeis").tagsinput('items');
318
	if (serialNumbers.length == 0) {
319
		alert("Pls add imeis");
30702 amit.gupta 320
		$("#all-imeis").focus();
321
		return false;
322
	}
30694 amit.gupta 323
	let imeisJson = {
324
		serialNumbers: serialNumbers,
325
		invoiceNumber: invoiceNumber
326
	}
327
	doPostAjaxRequestWithJsonHandler(`${context}/purchase/grn-imeis`, JSON.stringify(imeisJson), function (data) {
328
		let response = data.response;
329
		if (response) {
330
			alert("Purchase booked successfully");
331
			$("#purchase-reference-submit-button").click();
332
		}
333
	});
334
}
34163 ranu 335
 
336
$(document).on('click', ".hid-allocation", function () {
35556 ranu 337
	doGetAjaxRequestHandler(context + "/pur-sale-ratio/stock/hid-allocation",
34163 ranu 338
		function (response) {
35556 ranu 339
			$('#' + 'main-content').html(response);
34163 ranu 340
		});
341
});
342
 
343
$(document).on('click', '.partner-hid-allocation', function () {
344
	partnerHidAllocationList();
345
});
346
 
347
function partnerHidAllocationList() {
35459 amit 348
	if (typeof partnerId != "undefined") {
34163 ranu 349
		doGetAjaxRequestHandler(context + "/pur-sale-ratio/stock/hid-catalog-allocation-list?fofoId=" + partnerId,
350
			function (response) {
351
				$('.hid-allocation-conatiner').html(response);
352
			});
353
	} else {
354
		doGetAjaxRequestHandler(context + "/pur-sale-ratio/stock/hid-catalog-allocation-list?fofoId=0",
355
			function (response) {
356
				$('.hid-allocation-conatiner').html(response);
34198 ranu 357
            });
358
    }
359
 
360
}
361
 
362
var table = $('.hidCatalogAllocationList').DataTable();
363
$(document).on('dblclick', '.hidCatalogAllocationList tbody tr', function () {
364
    var data = table.row(this).data();
365
    $(this).find(":input").attr('disabled', false).show();
366
});
367
 
368
$(document).on('click', ".generate-allocation-request", function () {
369
    var catalogid = $(this).data('catalogid');
370
    const self = this;
371
    if (confirm("Are you sure you want to generate a request for allocation limit")) {
372
        var requestedAllocation = $(this).closest('tr').find('input[name="allocation-limit"]').val();
373
 
374
        if (!requestedAllocation) {
375
            alert("Please enter a requested allocation before submitting.");
376
            return;
377
        }
378
 
379
        doGetAjaxRequestHandler(`${context}/pur-sale-ratio/generate-allocation-request?catalogId=${catalogid}&fofoId=${partnerId}&requestedAllocation=${requestedAllocation}`, function (response) {
380
            if (response) {
381
                alert("Allocation request has been sent.");
382
                partnerHidAllocationList();
383
            }
384
        });
34163 ranu 385
	}
34198 ranu 386
});
387
 
34295 ranu 388
$(document).on('click', '.edit-allocation', function () {
389
	var $row = $(this).closest('tr'); // Get the closest table row
390
	var $input = $row.find('.reuested_allocation'); // Find the input inside the row
391
	$input.prop('disabled', false).focus(); // Enable input and focus on it
392
});
34198 ranu 393
 
34295 ranu 394
$(document).on('click', ".allocation-request-edit", function () {
395
	var $row = $(this).closest('tr');
396
	var allocationId = $(this).data('id');
397
	var requestedAllocation = $row.find('.reuested_allocation').val();
398
 
399
	if (!requestedAllocation) {
400
		alert("Please enter a requested allocation before submitting.");
401
		return;
402
	}
403
 
404
	if (confirm("Are you sure you want to update the allocation?")) {
405
		doGetAjaxRequestHandler(`${context}/pur-sale-ratio/edit-allocation-request?allocationId=${allocationId}&requestedAllocation=${requestedAllocation}`, function (response) {
406
			if (response) {
407
				alert("Allocation request has been sent.");
408
				loadRequestedAllocations();
409
			}
410
		});
411
	}
412
});
413
 
414
 
34198 ranu 415
$(document).on('click', ".reuested-allocations", function () {
416
    loadRequestedAllocations();
417
});
418
 
419
$(document).on('click', ".allocation-request-approve-reject", function () {
420
    var id = $(this).data('id');
421
    var status = $(this).data('status');
422
    doGetAjaxRequestHandler(context + `/pur-sale-ratio/allocation-request-approve-reject?id=${id}&status=${status}`,
423
        function (response) {
424
            loadRequestedAllocations();
425
        });
426
});
427
 
428
function loadRequestedAllocations() {
429
    doGetAjaxRequestHandler(context + "/pur-sale-ratio/requested-allocations",
430
        function (response) {
431
            $('#' + 'main-content').html(response);
432
        });
34163 ranu 433
}
434
 
435