| 33257 |
ranu |
1 |
$(function () {
|
|
|
2 |
$(document).on('click', ".billed-invoice", function () {
|
| 33261 |
ranu |
3 |
getAuthorisedWarehouseList(function (warehouseId) {
|
| 33257 |
ranu |
4 |
loadAllInvoice(warehouseId, "main-content");
|
|
|
5 |
});
|
|
|
6 |
|
|
|
7 |
});
|
|
|
8 |
|
| 33261 |
ranu |
9 |
$(document).on('change', "#WarehouseList", function () {
|
|
|
10 |
var warehouseId = $(this).val();
|
|
|
11 |
loadAllInvoice(warehouseId, "main-content");
|
|
|
12 |
});
|
|
|
13 |
|
| 33257 |
ranu |
14 |
$(document).on('click', ".invoice-orders", function () {
|
|
|
15 |
var invoiceNumber = $(this).data("invoice");
|
|
|
16 |
loadInvoiceDetail(invoiceNumber, "invoice-detail-container");
|
|
|
17 |
});
|
|
|
18 |
|
|
|
19 |
$(document).on('click', ".invoice-download", function () {
|
|
|
20 |
var invoiceNumber = $(this).data("invoice");
|
|
|
21 |
doGetAjaxRequestHandler(context + "/om/downloadInvoice/?invoiceNumber=" + invoiceNumber, function (response) {
|
|
|
22 |
if (response.statusCode === "200" && response.responseStatus === "SUCCESS") {
|
|
|
23 |
console.log(response.response);
|
|
|
24 |
window.open(response.response);
|
|
|
25 |
} else {
|
|
|
26 |
console.error("Error occurred:", response.statusMessage);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
});
|
|
|
30 |
});
|
|
|
31 |
});
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
function loadAllInvoice(warehouseId, domId) {
|
|
|
35 |
doGetAjaxRequestHandler(context + "/om/billedInvoice/?warehouseId=" + warehouseId, function (response) {
|
|
|
36 |
$('#' + domId).html(response);
|
|
|
37 |
var invoiceNumber = $("#firstInvoiceNumber").val();
|
|
|
38 |
$("#selectedWarehouse").val(warehouseId);
|
|
|
39 |
console.log("invoiceNumber:", invoiceNumber);
|
| 33261 |
ranu |
40 |
|
|
|
41 |
var selectOptions = '';
|
|
|
42 |
authorisedWarehouses.forEach(function (warehouse) {
|
|
|
43 |
var selected = (warehouse.id == warehouseId) ? 'selected' : '';
|
|
|
44 |
|
|
|
45 |
selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
|
|
|
46 |
});
|
|
|
47 |
$('#authWarehousesList').html(`<select class="form-control" id="WarehouseList">${selectOptions}</select>`);
|
|
|
48 |
|
| 33257 |
ranu |
49 |
loadInvoiceDetail(invoiceNumber, "invoice-detail-container");
|
|
|
50 |
});
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
function loadInvoiceDetail(invoiceNumber, detailContainer) {
|
|
|
54 |
var url = context + "/om/billed-invoice-orders/?invoiceNumber=" + invoiceNumber;
|
|
|
55 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
56 |
$('#' + detailContainer).html(response);
|
|
|
57 |
$("#selectedInvoiceNumber").text(invoiceNumber);
|
|
|
58 |
});
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
function getAuthorisedWarehousesList(callback) {
|
|
|
63 |
bootBoxObj = {
|
|
|
64 |
size: "small",
|
|
|
65 |
title: "Choose Warehouse",
|
|
|
66 |
callback: callback,
|
|
|
67 |
inputType: 'select',
|
|
|
68 |
inputOptions: typeof inputOptions == "undefined" ? undefined
|
|
|
69 |
: inputOptions
|
|
|
70 |
}
|
|
|
71 |
if (typeof inputOptions == "undefined") {
|
|
|
72 |
doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
|
|
|
73 |
response) {
|
|
|
74 |
console.log("response warehouse", response);
|
|
|
75 |
response = JSON.parse(response);
|
|
|
76 |
inputOptions = [];
|
|
|
77 |
response.forEach(function (warehouse) {
|
|
|
78 |
inputOptions.push({
|
|
|
79 |
text: warehouse.name,
|
|
|
80 |
value: warehouse.id,
|
|
|
81 |
});
|
|
|
82 |
});
|
|
|
83 |
bootBoxObj['inputOptions'] = inputOptions;
|
|
|
84 |
bootbox.prompt(bootBoxObj);
|
|
|
85 |
});
|
|
|
86 |
} else if (inputOptions.length == 1) {
|
|
|
87 |
callback(inputOptions[0].warehouse.id);
|
|
|
88 |
} else {
|
|
|
89 |
bootbox.prompt(bootBoxObj);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|