| 33261 |
ranu |
1 |
var authorisedWarehouses = [];
|
| 33741 |
amit.gupta |
2 |
const SELF_PICKUP = "4";
|
|
|
3 |
const RUNNER = "5";
|
| 33261 |
ranu |
4 |
|
| 34373 |
tejus.loha |
5 |
function checkSamePincodeAndGiveDistanceField(transactionId, warehouseId) {
|
|
|
6 |
doGetAjaxRequestHandler(`${context}/om/checkAddressPin/${transactionId}/${warehouseId}`, function (response) {
|
|
|
7 |
if (response.isSamePincode) {
|
|
|
8 |
$("#samePinCheck").val(true);
|
|
|
9 |
$('div.mk_distanceField').show();
|
|
|
10 |
if (response.distance != 0) {
|
|
|
11 |
$('div.mk_distanceField').val(response.distance);
|
|
|
12 |
} else {
|
|
|
13 |
$('div.mk_distanceField').val("");
|
|
|
14 |
}
|
|
|
15 |
} else {
|
|
|
16 |
$("#samePinCheck").val(false);
|
|
|
17 |
$('div.mk_distanceField').hide();
|
|
|
18 |
|
|
|
19 |
}
|
|
|
20 |
});
|
|
|
21 |
}
|
|
|
22 |
|
| 33247 |
ranu |
23 |
$(function () {
|
|
|
24 |
$(document).on('click', ".warehouse-management", function () {
|
| 33261 |
ranu |
25 |
getAuthorisedWarehouseList(function (warehouseId) {
|
| 33247 |
ranu |
26 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
27 |
});
|
|
|
28 |
|
|
|
29 |
});
|
|
|
30 |
|
| 33261 |
ranu |
31 |
$(document).on('change', "#selectedWarehouse", function () {
|
|
|
32 |
var warehouseId = $(this).val();
|
|
|
33 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
34 |
});
|
|
|
35 |
|
| 33247 |
ranu |
36 |
$(document).on('click', ".order_by_transaction", function () {
|
|
|
37 |
var transactionId = $(this).data("transaction");
|
|
|
38 |
var warehouseId = $("#selectedWarehouse").val();
|
| 33269 |
ranu |
39 |
|
|
|
40 |
// add and remive active class
|
|
|
41 |
$(this).addClass("active-tr");
|
|
|
42 |
|
|
|
43 |
$(".order_by_transaction").not(this).removeClass("active-tr");
|
|
|
44 |
|
| 33247 |
ranu |
45 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
46 |
});
|
|
|
47 |
|
| 33257 |
ranu |
48 |
$(document).on('click', ".change-warehouse-save-mk", function () {
|
|
|
49 |
var selectedFromBillingWarehouse = $("#selectedFromBillingWarehouse").val();
|
|
|
50 |
var orderId = $("#selectedFromBillingWarehouse").data('orderid');
|
|
|
51 |
doPostAjaxRequestHandler(context + `/om/changeBillingWarehouse/?billingFromWarehouseId=${selectedFromBillingWarehouse}&orderId=${orderId}`, function (response) {
|
|
|
52 |
if (response.response === true) {
|
|
|
53 |
var warehouseId = $("#selectedWarehouse").val();
|
|
|
54 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
55 |
} else {
|
|
|
56 |
alert('Something went wrong');
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
});
|
|
|
60 |
});
|
|
|
61 |
|
| 33403 |
amit.gupta |
62 |
$(document).on('click', ".mk_moveToBill", function () {
|
|
|
63 |
var warehouseId = $(this).data("warehouseid");
|
| 33404 |
amit.gupta |
64 |
var transactionId = $(this).data("transactionid");
|
| 33403 |
amit.gupta |
65 |
var orderId = $(this).data("orderid");
|
|
|
66 |
doGetAjaxRequestHandler(`${context}/om/moveToBill?warehouseId=${warehouseId}&orderId=${orderId}`, function (response) {
|
| 36536 |
amit |
67 |
var result = response.response || response;
|
| 36532 |
amit |
68 |
if (result.moved === true) {
|
|
|
69 |
alert("Order moved successfully");
|
|
|
70 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
71 |
return;
|
|
|
72 |
}
|
|
|
73 |
if (result.needsInput) {
|
|
|
74 |
var msg = "Order Qty: " + result.orderQty +
|
|
|
75 |
"\nNet Available (free stock): " + result.netAvailability +
|
|
|
76 |
"\nMax Available (includes reserved): " + result.maxAvailability +
|
|
|
77 |
"\n\nWarehouses:";
|
|
|
78 |
for (var i = 0; i < result.warehouses.length; i++) {
|
|
|
79 |
var wh = result.warehouses[i];
|
|
|
80 |
msg += "\n WH " + wh.warehouseId + " - Available: " + wh.availability + ", Reserved: " + wh.reserved + ", Net: " + wh.netAvailability;
|
|
|
81 |
}
|
|
|
82 |
msg += "\n\nEnter qty to move and warehouse ID (e.g. 5,3 for qty=5 to warehouse 3):";
|
|
|
83 |
var input = prompt(msg);
|
|
|
84 |
if (input) {
|
|
|
85 |
var parts = input.split(",");
|
|
|
86 |
var qty = parseInt(parts[0].trim());
|
|
|
87 |
var fWhId = parseInt(parts[1].trim());
|
|
|
88 |
if (isNaN(qty) || isNaN(fWhId)) {
|
|
|
89 |
alert("Invalid input");
|
|
|
90 |
return;
|
|
|
91 |
}
|
|
|
92 |
doGetAjaxRequestHandler(`${context}/om/moveToBillWithQty?orderId=${orderId}&qty=${qty}&fulfilmentWarehouseId=${fWhId}`, function () {
|
|
|
93 |
alert("Order moved successfully");
|
|
|
94 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
95 |
});
|
|
|
96 |
}
|
|
|
97 |
} else {
|
|
|
98 |
alert(result.message || "Could not move order");
|
|
|
99 |
}
|
| 33403 |
amit.gupta |
100 |
});
|
|
|
101 |
});
|
| 33257 |
ranu |
102 |
$(document).on('click', ".changeWarehouse-mk", function () {
|
|
|
103 |
var itemId = $(this).data("itemid");
|
|
|
104 |
var warehouseId = $(this).data("warehouseid");
|
|
|
105 |
var orderId = $(this).data("orderid");
|
|
|
106 |
console.log('warehouse', warehouseId);
|
|
|
107 |
console.log('itemId', itemId);
|
| 33356 |
ranu |
108 |
doGetAjaxRequestHandler(`${context}/om/formWarehouseByItemId/?warehouseId=${warehouseId}&itemId=${itemId}&orderId=${orderId}`, function (response) {
|
| 33257 |
ranu |
109 |
console.log(response);
|
|
|
110 |
if (response && response.response && Array.isArray(response.response)) {
|
| 33261 |
ranu |
111 |
console.log("response2222 warehouse", response.response);
|
| 33387 |
amit.gupta |
112 |
if (response.response.length > 0) {
|
| 33261 |
ranu |
113 |
var selectOptions = '';
|
|
|
114 |
response.response.forEach(function (warehouse) {
|
|
|
115 |
selectOptions += `<option value="${warehouse.warehouseFrom}">${warehouse.warehouseFromName}</option>`;
|
|
|
116 |
});
|
|
|
117 |
// Populate the modal with the select dropdown
|
| 33451 |
ranu |
118 |
$('#changeWarehouseModal .modal-body .brand-mapping-warehouse-mk').html(`<select id="selectedFromBillingWarehouse" data-orderid="${orderId}" class="form-control">${selectOptions}</select>`);
|
|
|
119 |
$('.all-warehouse-map').attr("data-orderid", orderId); //setter
|
| 33261 |
ranu |
120 |
$('.change-warehouse-save-mk').css("display", "block");
|
|
|
121 |
} else {
|
|
|
122 |
$('#changeWarehouseModal .modal-body').html(`No other warehouse found for change`);
|
|
|
123 |
$('.change-warehouse-save-mk').css("display", "none");
|
|
|
124 |
}
|
| 33257 |
ranu |
125 |
} else {
|
|
|
126 |
console.log('error: invalid response structure');
|
|
|
127 |
}
|
|
|
128 |
});
|
|
|
129 |
});
|
|
|
130 |
|
|
|
131 |
|
| 33247 |
ranu |
132 |
$(document).on('click', ".order_accepted", function () {
|
|
|
133 |
var transactionId = $("#selectedTransactionId").text();
|
| 33741 |
amit.gupta |
134 |
var providerId = $("select.mk_provider>:selected").data("providerid");
|
| 34373 |
tejus.loha |
135 |
let distance = "";
|
|
|
136 |
let isSamePinCheck = $("#samePinCheck").val();
|
|
|
137 |
console.log("distance - ", distance);
|
|
|
138 |
console.log("isSamePinCheck - ", isSamePinCheck);
|
|
|
139 |
if (isNaN(providerId)) {
|
| 33741 |
amit.gupta |
140 |
alert("Choose Provider");
|
|
|
141 |
return;
|
|
|
142 |
}
|
|
|
143 |
let vehicleNumber = null;
|
|
|
144 |
if (providerId == SELF_PICKUP) {
|
|
|
145 |
vehicleNumber = $('.mk_vehicleNumber').val();
|
|
|
146 |
if (vehicleNumber == "") {
|
|
|
147 |
alert("Vehicle Number is required");
|
|
|
148 |
return;
|
|
|
149 |
}
|
|
|
150 |
} else if (providerId == RUNNER) {
|
| 34373 |
tejus.loha |
151 |
if ($('.mk_rider>select').prop('selectedIndex') == 0) {
|
| 33741 |
amit.gupta |
152 |
alert("Choose Rider");
|
|
|
153 |
return;
|
|
|
154 |
}
|
| 34373 |
tejus.loha |
155 |
if (isSamePinCheck == "true") {
|
|
|
156 |
distance = $(".mk_distanceValue").val();
|
|
|
157 |
if (!distance) {
|
|
|
158 |
alert("Please Enter Approx Distance");
|
|
|
159 |
return;
|
|
|
160 |
}
|
|
|
161 |
}
|
| 33741 |
amit.gupta |
162 |
vehicleNumber = $('.mk_rider select').val();
|
|
|
163 |
}
|
| 34373 |
tejus.loha |
164 |
console.log("distance after Check- ", distance);
|
| 33247 |
ranu |
165 |
var warehouseId = $("#selectedWarehouseId").val();
|
|
|
166 |
var orderBillingModels = []; // Array to store OrderBillingModel objects
|
|
|
167 |
$("#wareHouseTransactionTable > tbody > tr").each(function (rowIndex) {
|
|
|
168 |
if ($(this).hasClass('main-tr')) {
|
|
|
169 |
var orderId = parseInt($(this).find(".orderId").text().trim());
|
|
|
170 |
var fillQuantityInput = $(this).find(".filledQty");
|
|
|
171 |
var fillQuantity = fillQuantityInput.length ? parseInt(fillQuantityInput.val().trim()) : 0; // Get fill quantity from input field if it exists
|
|
|
172 |
var serialNumbers = [];
|
|
|
173 |
|
|
|
174 |
var imeiInputAvailability = $(this).find(".imeis-to-grn");
|
|
|
175 |
if (imeiInputAvailability.length) {
|
|
|
176 |
var imeiInput = ($(this).find(".imeis-to-grn")).tagsinput('items'); // Get selected serial numbers
|
|
|
177 |
if (imeiInput.length) {
|
|
|
178 |
imeiInput.forEach((imei) => {
|
|
|
179 |
serialNumbers.push(imei);
|
|
|
180 |
});
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
// Determine the quantity to bill based on serial numbers and fill quantity
|
|
|
185 |
var quantityToBill;
|
|
|
186 |
if (serialNumbers.length) {
|
|
|
187 |
quantityToBill = serialNumbers.length;
|
|
|
188 |
} else {
|
|
|
189 |
quantityToBill = fillQuantity;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
// Create OrderBillingModel object
|
|
|
193 |
var orderBillingModel = {
|
|
|
194 |
orderId: orderId,
|
|
|
195 |
serialNumbersToBill: serialNumbers,
|
| 33741 |
amit.gupta |
196 |
quantityToBill: quantityToBill,
|
| 34373 |
tejus.loha |
197 |
logisticsProviderId: providerId,
|
|
|
198 |
vehicleNumber: vehicleNumber,
|
|
|
199 |
distance: distance
|
| 33247 |
ranu |
200 |
};
|
|
|
201 |
|
|
|
202 |
// Add OrderBillingModel object to the array
|
|
|
203 |
orderBillingModels.push(orderBillingModel);
|
|
|
204 |
}
|
|
|
205 |
});
|
|
|
206 |
|
|
|
207 |
// Convert orderBillingModels array to JSON string
|
|
|
208 |
var requestBody = JSON.stringify(orderBillingModels);
|
|
|
209 |
|
|
|
210 |
// Perform further actions with the requestBody, such as sending it in an AJAX request
|
|
|
211 |
console.log('Request Body:', requestBody);
|
|
|
212 |
|
| 33271 |
amit.gupta |
213 |
doPostAjaxRequestWithJsonHandler(`${context}/om/addBillingDetailsForGrouppedOrders/?warehouseId=${warehouseId}&transactionId=${transactionId}`, requestBody, function (invoiceNumber) {
|
| 33270 |
amit.gupta |
214 |
if (invoiceNumber) {
|
| 33247 |
ranu |
215 |
alert("bill generated successfully");
|
| 33289 |
amit.gupta |
216 |
setTimeout(function () {
|
| 33277 |
amit.gupta |
217 |
window.open(`${context}/om/downloadInvoice/${invoiceNumber}`, "_blank");
|
| 33403 |
amit.gupta |
218 |
}, 3000,);
|
| 33263 |
ranu |
219 |
loadAllTransaction(warehouseId, "main-content");
|
| 33247 |
ranu |
220 |
} else {
|
|
|
221 |
alert("something went wrong");
|
|
|
222 |
}
|
|
|
223 |
});
|
|
|
224 |
|
|
|
225 |
});
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
});
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
function loadAllTransaction(warehouseId, domId) {
|
|
|
232 |
doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
|
|
|
233 |
$('#' + domId).html(response);
|
|
|
234 |
var transactionId = $("#firstTxnId").val();
|
|
|
235 |
$("#selectedWarehouse").val(warehouseId);
|
|
|
236 |
console.log("Transaction ID:", transactionId);
|
| 33261 |
ranu |
237 |
|
|
|
238 |
var selectOptions = '';
|
|
|
239 |
authorisedWarehouses.forEach(function (warehouse) {
|
|
|
240 |
var selected = (warehouse.id == warehouseId) ? 'selected' : '';
|
|
|
241 |
|
|
|
242 |
selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
|
|
|
243 |
});
|
|
|
244 |
$('#authWarehousesList').html(`<select class="form-control" id="selectedWarehouse">${selectOptions}</select>`);
|
|
|
245 |
|
| 33247 |
ranu |
246 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
247 |
});
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
|
|
|
251 |
var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
|
|
|
252 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
253 |
$('#' + detailContainer).html(response);
|
|
|
254 |
$("#selectedTransactionId").text(transactionId);
|
|
|
255 |
$("#selectedWarehouseId").val(warehouseId);
|
| 34373 |
tejus.loha |
256 |
|
| 33247 |
ranu |
257 |
});
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
|
| 33261 |
ranu |
261 |
function getAuthorisedWarehouseList(callback) {
|
| 33247 |
ranu |
262 |
bootBoxObj = {
|
|
|
263 |
size: "small",
|
|
|
264 |
title: "Choose Warehouse",
|
|
|
265 |
callback: callback,
|
|
|
266 |
inputType: 'select',
|
|
|
267 |
inputOptions: typeof inputOptions == "undefined" ? undefined
|
|
|
268 |
: inputOptions
|
|
|
269 |
}
|
|
|
270 |
if (typeof inputOptions == "undefined") {
|
| 33261 |
ranu |
271 |
doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (response) {
|
|
|
272 |
console.log("responseeee warehouse", response);
|
|
|
273 |
authorisedWarehouses = JSON.parse(response);
|
|
|
274 |
|
| 33247 |
ranu |
275 |
inputOptions = [];
|
| 33261 |
ranu |
276 |
authorisedWarehouses.forEach(function (warehouse) {
|
| 33247 |
ranu |
277 |
inputOptions.push({
|
|
|
278 |
text: warehouse.name,
|
|
|
279 |
value: warehouse.id,
|
|
|
280 |
});
|
|
|
281 |
});
|
|
|
282 |
bootBoxObj['inputOptions'] = inputOptions;
|
|
|
283 |
bootbox.prompt(bootBoxObj);
|
|
|
284 |
});
|
|
|
285 |
} else if (inputOptions.length == 1) {
|
|
|
286 |
callback(inputOptions[0].warehouse.id);
|
|
|
287 |
} else {
|
|
|
288 |
bootbox.prompt(bootBoxObj);
|
|
|
289 |
}
|
| 33261 |
ranu |
290 |
}
|
| 33247 |
ranu |
291 |
|
| 33261 |
ranu |
292 |
|
|
|
293 |
|