| 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 |
} else {
|
| 36540 |
amit |
72 |
alert(result.message || "No available inventory found");
|
| 36532 |
amit |
73 |
}
|
| 33403 |
amit.gupta |
74 |
});
|
|
|
75 |
});
|
| 33257 |
ranu |
76 |
$(document).on('click', ".changeWarehouse-mk", function () {
|
|
|
77 |
var itemId = $(this).data("itemid");
|
|
|
78 |
var warehouseId = $(this).data("warehouseid");
|
|
|
79 |
var orderId = $(this).data("orderid");
|
|
|
80 |
console.log('warehouse', warehouseId);
|
|
|
81 |
console.log('itemId', itemId);
|
| 33356 |
ranu |
82 |
doGetAjaxRequestHandler(`${context}/om/formWarehouseByItemId/?warehouseId=${warehouseId}&itemId=${itemId}&orderId=${orderId}`, function (response) {
|
| 33257 |
ranu |
83 |
console.log(response);
|
|
|
84 |
if (response && response.response && Array.isArray(response.response)) {
|
| 33261 |
ranu |
85 |
console.log("response2222 warehouse", response.response);
|
| 33387 |
amit.gupta |
86 |
if (response.response.length > 0) {
|
| 33261 |
ranu |
87 |
var selectOptions = '';
|
|
|
88 |
response.response.forEach(function (warehouse) {
|
|
|
89 |
selectOptions += `<option value="${warehouse.warehouseFrom}">${warehouse.warehouseFromName}</option>`;
|
|
|
90 |
});
|
|
|
91 |
// Populate the modal with the select dropdown
|
| 33451 |
ranu |
92 |
$('#changeWarehouseModal .modal-body .brand-mapping-warehouse-mk').html(`<select id="selectedFromBillingWarehouse" data-orderid="${orderId}" class="form-control">${selectOptions}</select>`);
|
|
|
93 |
$('.all-warehouse-map').attr("data-orderid", orderId); //setter
|
| 33261 |
ranu |
94 |
$('.change-warehouse-save-mk').css("display", "block");
|
|
|
95 |
} else {
|
|
|
96 |
$('#changeWarehouseModal .modal-body').html(`No other warehouse found for change`);
|
|
|
97 |
$('.change-warehouse-save-mk').css("display", "none");
|
|
|
98 |
}
|
| 33257 |
ranu |
99 |
} else {
|
|
|
100 |
console.log('error: invalid response structure');
|
|
|
101 |
}
|
|
|
102 |
});
|
|
|
103 |
});
|
|
|
104 |
|
|
|
105 |
|
| 33247 |
ranu |
106 |
$(document).on('click', ".order_accepted", function () {
|
|
|
107 |
var transactionId = $("#selectedTransactionId").text();
|
| 33741 |
amit.gupta |
108 |
var providerId = $("select.mk_provider>:selected").data("providerid");
|
| 34373 |
tejus.loha |
109 |
let distance = "";
|
|
|
110 |
let isSamePinCheck = $("#samePinCheck").val();
|
|
|
111 |
console.log("distance - ", distance);
|
|
|
112 |
console.log("isSamePinCheck - ", isSamePinCheck);
|
|
|
113 |
if (isNaN(providerId)) {
|
| 33741 |
amit.gupta |
114 |
alert("Choose Provider");
|
|
|
115 |
return;
|
|
|
116 |
}
|
|
|
117 |
let vehicleNumber = null;
|
|
|
118 |
if (providerId == SELF_PICKUP) {
|
|
|
119 |
vehicleNumber = $('.mk_vehicleNumber').val();
|
|
|
120 |
if (vehicleNumber == "") {
|
|
|
121 |
alert("Vehicle Number is required");
|
|
|
122 |
return;
|
|
|
123 |
}
|
|
|
124 |
} else if (providerId == RUNNER) {
|
| 34373 |
tejus.loha |
125 |
if ($('.mk_rider>select').prop('selectedIndex') == 0) {
|
| 33741 |
amit.gupta |
126 |
alert("Choose Rider");
|
|
|
127 |
return;
|
|
|
128 |
}
|
| 34373 |
tejus.loha |
129 |
if (isSamePinCheck == "true") {
|
|
|
130 |
distance = $(".mk_distanceValue").val();
|
|
|
131 |
if (!distance) {
|
|
|
132 |
alert("Please Enter Approx Distance");
|
|
|
133 |
return;
|
|
|
134 |
}
|
|
|
135 |
}
|
| 33741 |
amit.gupta |
136 |
vehicleNumber = $('.mk_rider select').val();
|
|
|
137 |
}
|
| 34373 |
tejus.loha |
138 |
console.log("distance after Check- ", distance);
|
| 33247 |
ranu |
139 |
var warehouseId = $("#selectedWarehouseId").val();
|
|
|
140 |
var orderBillingModels = []; // Array to store OrderBillingModel objects
|
|
|
141 |
$("#wareHouseTransactionTable > tbody > tr").each(function (rowIndex) {
|
|
|
142 |
if ($(this).hasClass('main-tr')) {
|
|
|
143 |
var orderId = parseInt($(this).find(".orderId").text().trim());
|
|
|
144 |
var fillQuantityInput = $(this).find(".filledQty");
|
|
|
145 |
var fillQuantity = fillQuantityInput.length ? parseInt(fillQuantityInput.val().trim()) : 0; // Get fill quantity from input field if it exists
|
|
|
146 |
var serialNumbers = [];
|
|
|
147 |
|
|
|
148 |
var imeiInputAvailability = $(this).find(".imeis-to-grn");
|
|
|
149 |
if (imeiInputAvailability.length) {
|
|
|
150 |
var imeiInput = ($(this).find(".imeis-to-grn")).tagsinput('items'); // Get selected serial numbers
|
|
|
151 |
if (imeiInput.length) {
|
|
|
152 |
imeiInput.forEach((imei) => {
|
|
|
153 |
serialNumbers.push(imei);
|
|
|
154 |
});
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
// Determine the quantity to bill based on serial numbers and fill quantity
|
|
|
159 |
var quantityToBill;
|
|
|
160 |
if (serialNumbers.length) {
|
|
|
161 |
quantityToBill = serialNumbers.length;
|
|
|
162 |
} else {
|
|
|
163 |
quantityToBill = fillQuantity;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
// Create OrderBillingModel object
|
|
|
167 |
var orderBillingModel = {
|
|
|
168 |
orderId: orderId,
|
|
|
169 |
serialNumbersToBill: serialNumbers,
|
| 33741 |
amit.gupta |
170 |
quantityToBill: quantityToBill,
|
| 34373 |
tejus.loha |
171 |
logisticsProviderId: providerId,
|
|
|
172 |
vehicleNumber: vehicleNumber,
|
|
|
173 |
distance: distance
|
| 33247 |
ranu |
174 |
};
|
|
|
175 |
|
|
|
176 |
// Add OrderBillingModel object to the array
|
|
|
177 |
orderBillingModels.push(orderBillingModel);
|
|
|
178 |
}
|
|
|
179 |
});
|
|
|
180 |
|
|
|
181 |
// Convert orderBillingModels array to JSON string
|
|
|
182 |
var requestBody = JSON.stringify(orderBillingModels);
|
|
|
183 |
|
|
|
184 |
// Perform further actions with the requestBody, such as sending it in an AJAX request
|
|
|
185 |
console.log('Request Body:', requestBody);
|
|
|
186 |
|
| 33271 |
amit.gupta |
187 |
doPostAjaxRequestWithJsonHandler(`${context}/om/addBillingDetailsForGrouppedOrders/?warehouseId=${warehouseId}&transactionId=${transactionId}`, requestBody, function (invoiceNumber) {
|
| 33270 |
amit.gupta |
188 |
if (invoiceNumber) {
|
| 33247 |
ranu |
189 |
alert("bill generated successfully");
|
| 33289 |
amit.gupta |
190 |
setTimeout(function () {
|
| 33277 |
amit.gupta |
191 |
window.open(`${context}/om/downloadInvoice/${invoiceNumber}`, "_blank");
|
| 33403 |
amit.gupta |
192 |
}, 3000,);
|
| 33263 |
ranu |
193 |
loadAllTransaction(warehouseId, "main-content");
|
| 33247 |
ranu |
194 |
} else {
|
|
|
195 |
alert("something went wrong");
|
|
|
196 |
}
|
|
|
197 |
});
|
|
|
198 |
|
|
|
199 |
});
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
});
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
function loadAllTransaction(warehouseId, domId) {
|
|
|
206 |
doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
|
|
|
207 |
$('#' + domId).html(response);
|
|
|
208 |
var transactionId = $("#firstTxnId").val();
|
|
|
209 |
$("#selectedWarehouse").val(warehouseId);
|
|
|
210 |
console.log("Transaction ID:", transactionId);
|
| 33261 |
ranu |
211 |
|
|
|
212 |
var selectOptions = '';
|
|
|
213 |
authorisedWarehouses.forEach(function (warehouse) {
|
|
|
214 |
var selected = (warehouse.id == warehouseId) ? 'selected' : '';
|
|
|
215 |
|
|
|
216 |
selectOptions += `<option value="${warehouse.id}" ${selected}>${warehouse.name}</option>`;
|
|
|
217 |
});
|
|
|
218 |
$('#authWarehousesList').html(`<select class="form-control" id="selectedWarehouse">${selectOptions}</select>`);
|
|
|
219 |
|
| 33247 |
ranu |
220 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
221 |
});
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
|
|
|
225 |
var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
|
|
|
226 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
227 |
$('#' + detailContainer).html(response);
|
|
|
228 |
$("#selectedTransactionId").text(transactionId);
|
|
|
229 |
$("#selectedWarehouseId").val(warehouseId);
|
| 34373 |
tejus.loha |
230 |
|
| 33247 |
ranu |
231 |
});
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
|
| 33261 |
ranu |
235 |
function getAuthorisedWarehouseList(callback) {
|
| 33247 |
ranu |
236 |
bootBoxObj = {
|
|
|
237 |
size: "small",
|
|
|
238 |
title: "Choose Warehouse",
|
|
|
239 |
callback: callback,
|
|
|
240 |
inputType: 'select',
|
|
|
241 |
inputOptions: typeof inputOptions == "undefined" ? undefined
|
|
|
242 |
: inputOptions
|
|
|
243 |
}
|
|
|
244 |
if (typeof inputOptions == "undefined") {
|
| 33261 |
ranu |
245 |
doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (response) {
|
|
|
246 |
console.log("responseeee warehouse", response);
|
|
|
247 |
authorisedWarehouses = JSON.parse(response);
|
|
|
248 |
|
| 33247 |
ranu |
249 |
inputOptions = [];
|
| 33261 |
ranu |
250 |
authorisedWarehouses.forEach(function (warehouse) {
|
| 33247 |
ranu |
251 |
inputOptions.push({
|
|
|
252 |
text: warehouse.name,
|
|
|
253 |
value: warehouse.id,
|
|
|
254 |
});
|
|
|
255 |
});
|
|
|
256 |
bootBoxObj['inputOptions'] = inputOptions;
|
|
|
257 |
bootbox.prompt(bootBoxObj);
|
|
|
258 |
});
|
|
|
259 |
} else if (inputOptions.length == 1) {
|
|
|
260 |
callback(inputOptions[0].warehouse.id);
|
|
|
261 |
} else {
|
|
|
262 |
bootbox.prompt(bootBoxObj);
|
|
|
263 |
}
|
| 33261 |
ranu |
264 |
}
|
| 33247 |
ranu |
265 |
|
| 33261 |
ranu |
266 |
|
|
|
267 |
|