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