| 33261 |
ranu |
1 |
var authorisedWarehouses = [];
|
|
|
2 |
|
| 33247 |
ranu |
3 |
$(function () {
|
|
|
4 |
$(document).on('click', ".warehouse-management", function () {
|
| 33261 |
ranu |
5 |
getAuthorisedWarehouseList(function (warehouseId) {
|
| 33247 |
ranu |
6 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
7 |
});
|
|
|
8 |
|
|
|
9 |
});
|
|
|
10 |
|
| 33261 |
ranu |
11 |
$(document).on('change', "#selectedWarehouse", function () {
|
|
|
12 |
var warehouseId = $(this).val();
|
|
|
13 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
14 |
});
|
|
|
15 |
|
| 33247 |
ranu |
16 |
$(document).on('click', ".order_by_transaction", function () {
|
|
|
17 |
var transactionId = $(this).data("transaction");
|
|
|
18 |
var warehouseId = $("#selectedWarehouse").val();
|
| 33269 |
ranu |
19 |
|
|
|
20 |
// add and remive active class
|
|
|
21 |
$(this).addClass("active-tr");
|
|
|
22 |
|
|
|
23 |
$(".order_by_transaction").not(this).removeClass("active-tr");
|
|
|
24 |
|
| 33247 |
ranu |
25 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
26 |
});
|
|
|
27 |
|
| 33257 |
ranu |
28 |
$(document).on('click', ".change-warehouse-save-mk", function () {
|
|
|
29 |
var selectedFromBillingWarehouse = $("#selectedFromBillingWarehouse").val();
|
|
|
30 |
var orderId = $("#selectedFromBillingWarehouse").data('orderid');
|
|
|
31 |
doPostAjaxRequestHandler(context + `/om/changeBillingWarehouse/?billingFromWarehouseId=${selectedFromBillingWarehouse}&orderId=${orderId}`, function (response) {
|
|
|
32 |
if (response.response === true) {
|
|
|
33 |
var warehouseId = $("#selectedWarehouse").val();
|
|
|
34 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
35 |
} else {
|
|
|
36 |
alert('Something went wrong');
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
});
|
|
|
40 |
});
|
|
|
41 |
|
|
|
42 |
$(document).on('click', ".changeWarehouse-mk", function () {
|
|
|
43 |
var itemId = $(this).data("itemid");
|
|
|
44 |
var warehouseId = $(this).data("warehouseid");
|
|
|
45 |
var orderId = $(this).data("orderid");
|
|
|
46 |
console.log('warehouse', warehouseId);
|
|
|
47 |
console.log('itemId', itemId);
|
| 33356 |
ranu |
48 |
doGetAjaxRequestHandler(`${context}/om/formWarehouseByItemId/?warehouseId=${warehouseId}&itemId=${itemId}&orderId=${orderId}`, function (response) {
|
| 33257 |
ranu |
49 |
console.log(response);
|
|
|
50 |
if (response && response.response && Array.isArray(response.response)) {
|
| 33261 |
ranu |
51 |
console.log("response2222 warehouse", response.response);
|
| 33387 |
amit.gupta |
52 |
if (response.response.length > 0) {
|
| 33261 |
ranu |
53 |
var selectOptions = '';
|
|
|
54 |
response.response.forEach(function (warehouse) {
|
|
|
55 |
selectOptions += `<option value="${warehouse.warehouseFrom}">${warehouse.warehouseFromName}</option>`;
|
|
|
56 |
});
|
|
|
57 |
// Populate the modal with the select dropdown
|
|
|
58 |
$('#changeWarehouseModal .modal-body').html(`<select id="selectedFromBillingWarehouse" data-orderid="${orderId}" class="form-control">${selectOptions}</select>`);
|
|
|
59 |
$('.change-warehouse-save-mk').css("display", "block");
|
|
|
60 |
} else {
|
|
|
61 |
$('#changeWarehouseModal .modal-body').html(`No other warehouse found for change`);
|
|
|
62 |
$('.change-warehouse-save-mk').css("display", "none");
|
|
|
63 |
}
|
| 33257 |
ranu |
64 |
} else {
|
|
|
65 |
console.log('error: invalid response structure');
|
|
|
66 |
}
|
|
|
67 |
});
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
|
| 33247 |
ranu |
71 |
$(document).on('click', ".order_accepted", function () {
|
|
|
72 |
var transactionId = $("#selectedTransactionId").text();
|
|
|
73 |
var warehouseId = $("#selectedWarehouseId").val();
|
|
|
74 |
var orderBillingModels = []; // Array to store OrderBillingModel objects
|
|
|
75 |
$("#wareHouseTransactionTable > tbody > tr").each(function (rowIndex) {
|
|
|
76 |
if ($(this).hasClass('main-tr')) {
|
|
|
77 |
var orderId = parseInt($(this).find(".orderId").text().trim());
|
|
|
78 |
var fillQuantityInput = $(this).find(".filledQty");
|
|
|
79 |
var fillQuantity = fillQuantityInput.length ? parseInt(fillQuantityInput.val().trim()) : 0; // Get fill quantity from input field if it exists
|
|
|
80 |
var serialNumbers = [];
|
|
|
81 |
|
|
|
82 |
var imeiInputAvailability = $(this).find(".imeis-to-grn");
|
|
|
83 |
if (imeiInputAvailability.length) {
|
|
|
84 |
var imeiInput = ($(this).find(".imeis-to-grn")).tagsinput('items'); // Get selected serial numbers
|
|
|
85 |
if (imeiInput.length) {
|
|
|
86 |
imeiInput.forEach((imei) => {
|
|
|
87 |
serialNumbers.push(imei);
|
|
|
88 |
});
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
// Determine the quantity to bill based on serial numbers and fill quantity
|
|
|
93 |
var quantityToBill;
|
|
|
94 |
if (serialNumbers.length) {
|
|
|
95 |
quantityToBill = serialNumbers.length;
|
|
|
96 |
} else {
|
|
|
97 |
quantityToBill = fillQuantity;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// Create OrderBillingModel object
|
|
|
101 |
var orderBillingModel = {
|
|
|
102 |
orderId: orderId,
|
|
|
103 |
serialNumbersToBill: serialNumbers,
|
|
|
104 |
quantityToBill: quantityToBill
|
|
|
105 |
};
|
|
|
106 |
|
|
|
107 |
// Add OrderBillingModel object to the array
|
|
|
108 |
orderBillingModels.push(orderBillingModel);
|
|
|
109 |
}
|
|
|
110 |
});
|
|
|
111 |
|
|
|
112 |
// Convert orderBillingModels array to JSON string
|
|
|
113 |
var requestBody = JSON.stringify(orderBillingModels);
|
|
|
114 |
|
|
|
115 |
// Perform further actions with the requestBody, such as sending it in an AJAX request
|
|
|
116 |
console.log('Request Body:', requestBody);
|
|
|
117 |
|
| 33271 |
amit.gupta |
118 |
doPostAjaxRequestWithJsonHandler(`${context}/om/addBillingDetailsForGrouppedOrders/?warehouseId=${warehouseId}&transactionId=${transactionId}`, requestBody, function (invoiceNumber) {
|
| 33270 |
amit.gupta |
119 |
if (invoiceNumber) {
|
| 33247 |
ranu |
120 |
alert("bill generated successfully");
|
| 33289 |
amit.gupta |
121 |
setTimeout(function () {
|
| 33277 |
amit.gupta |
122 |
window.open(`${context}/om/downloadInvoice/${invoiceNumber}`, "_blank");
|
| 33289 |
amit.gupta |
123 |
}, 3000, );
|
| 33263 |
ranu |
124 |
loadAllTransaction(warehouseId, "main-content");
|
| 33247 |
ranu |
125 |
} else {
|
|
|
126 |
alert("something went wrong");
|
|
|
127 |
}
|
|
|
128 |
});
|
|
|
129 |
|
|
|
130 |
});
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
});
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
function loadAllTransaction(warehouseId, domId) {
|
|
|
137 |
doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
|
|
|
138 |
$('#' + domId).html(response);
|
|
|
139 |
var transactionId = $("#firstTxnId").val();
|
|
|
140 |
$("#selectedWarehouse").val(warehouseId);
|
|
|
141 |
console.log("Transaction ID:", transactionId);
|
| 33261 |
ranu |
142 |
|
|
|
143 |
var selectOptions = '';
|
|
|
144 |
authorisedWarehouses.forEach(function (warehouse) {
|
|
|
145 |
var selected = (warehouse.id == warehouseId) ? 'selected' : '';
|
|
|
146 |
|
|
|
147 |
selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
|
|
|
148 |
});
|
|
|
149 |
$('#authWarehousesList').html(`<select class="form-control" id="selectedWarehouse">${selectOptions}</select>`);
|
|
|
150 |
|
| 33247 |
ranu |
151 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
152 |
});
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
|
|
|
156 |
var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
|
|
|
157 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
158 |
$('#' + detailContainer).html(response);
|
|
|
159 |
$("#selectedTransactionId").text(transactionId);
|
|
|
160 |
$("#selectedWarehouseId").val(warehouseId);
|
|
|
161 |
});
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
|
| 33261 |
ranu |
165 |
function getAuthorisedWarehouseList(callback) {
|
| 33247 |
ranu |
166 |
bootBoxObj = {
|
|
|
167 |
size: "small",
|
|
|
168 |
title: "Choose Warehouse",
|
|
|
169 |
callback: callback,
|
|
|
170 |
inputType: 'select',
|
|
|
171 |
inputOptions: typeof inputOptions == "undefined" ? undefined
|
|
|
172 |
: inputOptions
|
|
|
173 |
}
|
|
|
174 |
if (typeof inputOptions == "undefined") {
|
| 33261 |
ranu |
175 |
doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (response) {
|
|
|
176 |
console.log("responseeee warehouse", response);
|
|
|
177 |
authorisedWarehouses = JSON.parse(response);
|
|
|
178 |
|
| 33247 |
ranu |
179 |
inputOptions = [];
|
| 33261 |
ranu |
180 |
authorisedWarehouses.forEach(function (warehouse) {
|
| 33247 |
ranu |
181 |
inputOptions.push({
|
|
|
182 |
text: warehouse.name,
|
|
|
183 |
value: warehouse.id,
|
|
|
184 |
});
|
|
|
185 |
});
|
|
|
186 |
bootBoxObj['inputOptions'] = inputOptions;
|
|
|
187 |
bootbox.prompt(bootBoxObj);
|
|
|
188 |
});
|
|
|
189 |
} else if (inputOptions.length == 1) {
|
|
|
190 |
callback(inputOptions[0].warehouse.id);
|
|
|
191 |
} else {
|
|
|
192 |
bootbox.prompt(bootBoxObj);
|
|
|
193 |
}
|
| 33261 |
ranu |
194 |
}
|
| 33247 |
ranu |
195 |
|
| 33261 |
ranu |
196 |
|
|
|
197 |
|