| 33247 |
ranu |
1 |
$(function () {
|
|
|
2 |
$(document).on('click', ".warehouse-management", function () {
|
|
|
3 |
getAuthorisedWarehousesList(function (warehouseId) {
|
|
|
4 |
loadAllTransaction(warehouseId, "main-content");
|
|
|
5 |
});
|
|
|
6 |
|
|
|
7 |
});
|
|
|
8 |
|
|
|
9 |
$(document).on('click', ".order_by_transaction", function () {
|
|
|
10 |
var transactionId = $(this).data("transaction");
|
|
|
11 |
var warehouseId = $("#selectedWarehouse").val();
|
|
|
12 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
13 |
});
|
|
|
14 |
|
|
|
15 |
$(document).on('click', ".order_accepted", function () {
|
|
|
16 |
var transactionId = $("#selectedTransactionId").text();
|
|
|
17 |
var warehouseId = $("#selectedWarehouseId").val();
|
|
|
18 |
var orderBillingModels = []; // Array to store OrderBillingModel objects
|
|
|
19 |
$("#wareHouseTransactionTable > tbody > tr").each(function (rowIndex) {
|
|
|
20 |
if ($(this).hasClass('main-tr')) {
|
|
|
21 |
var orderId = parseInt($(this).find(".orderId").text().trim());
|
|
|
22 |
var fillQuantityInput = $(this).find(".filledQty");
|
|
|
23 |
var fillQuantity = fillQuantityInput.length ? parseInt(fillQuantityInput.val().trim()) : 0; // Get fill quantity from input field if it exists
|
|
|
24 |
var serialNumbers = [];
|
|
|
25 |
|
|
|
26 |
var imeiInputAvailability = $(this).find(".imeis-to-grn");
|
|
|
27 |
if (imeiInputAvailability.length) {
|
|
|
28 |
var imeiInput = ($(this).find(".imeis-to-grn")).tagsinput('items'); // Get selected serial numbers
|
|
|
29 |
if (imeiInput.length) {
|
|
|
30 |
imeiInput.forEach((imei) => {
|
|
|
31 |
serialNumbers.push(imei);
|
|
|
32 |
});
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
// Determine the quantity to bill based on serial numbers and fill quantity
|
|
|
37 |
var quantityToBill;
|
|
|
38 |
if (serialNumbers.length) {
|
|
|
39 |
quantityToBill = serialNumbers.length;
|
|
|
40 |
} else {
|
|
|
41 |
quantityToBill = fillQuantity;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
// Create OrderBillingModel object
|
|
|
45 |
var orderBillingModel = {
|
|
|
46 |
orderId: orderId,
|
|
|
47 |
serialNumbersToBill: serialNumbers,
|
|
|
48 |
quantityToBill: quantityToBill
|
|
|
49 |
};
|
|
|
50 |
|
|
|
51 |
// Add OrderBillingModel object to the array
|
|
|
52 |
orderBillingModels.push(orderBillingModel);
|
|
|
53 |
}
|
|
|
54 |
});
|
|
|
55 |
|
|
|
56 |
// Convert orderBillingModels array to JSON string
|
|
|
57 |
var requestBody = JSON.stringify(orderBillingModels);
|
|
|
58 |
|
|
|
59 |
// Perform further actions with the requestBody, such as sending it in an AJAX request
|
|
|
60 |
console.log('Request Body:', requestBody);
|
|
|
61 |
|
|
|
62 |
doPostAjaxRequestWithJsonHandler(`${context}/om/addBillingDetailsForGrouppedOrders/?warehouseId=${warehouseId}&transactionId=${transactionId}`, requestBody, function (response) {
|
|
|
63 |
if (response) {
|
|
|
64 |
alert("bill generated successfully");
|
|
|
65 |
} else {
|
|
|
66 |
alert("something went wrong");
|
|
|
67 |
}
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
});
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
function loadAllTransaction(warehouseId, domId) {
|
|
|
77 |
doGetAjaxRequestHandler(context + "/om/transactions/?warehouseId=" + warehouseId + "&orderStatus=SUBMITTED_FOR_PROCESSING", function (response) {
|
|
|
78 |
$('#' + domId).html(response);
|
|
|
79 |
var transactionId = $("#firstTxnId").val();
|
|
|
80 |
$("#selectedWarehouse").val(warehouseId);
|
|
|
81 |
console.log("Transaction ID:", transactionId);
|
|
|
82 |
loadTransactionDetail(transactionId, warehouseId, "transaction-detail-container");
|
|
|
83 |
});
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
function loadTransactionDetail(transactionId, warehouseId, detailContainer) {
|
|
|
87 |
var url = context + "/om/orderByTransaction/?transactionId=" + transactionId + "&warehouseId=" + warehouseId;
|
|
|
88 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
89 |
$('#' + detailContainer).html(response);
|
|
|
90 |
$("#selectedTransactionId").text(transactionId);
|
|
|
91 |
$("#selectedWarehouseId").val(warehouseId);
|
|
|
92 |
});
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
function getAuthorisedWarehousesList(callback) {
|
|
|
97 |
bootBoxObj = {
|
|
|
98 |
size: "small",
|
|
|
99 |
title: "Choose Warehouse",
|
|
|
100 |
callback: callback,
|
|
|
101 |
inputType: 'select',
|
|
|
102 |
inputOptions: typeof inputOptions == "undefined" ? undefined
|
|
|
103 |
: inputOptions
|
|
|
104 |
}
|
|
|
105 |
if (typeof inputOptions == "undefined") {
|
|
|
106 |
doGetAjaxRequestHandler(context + "/authorisedWarehouses", function (
|
|
|
107 |
response) {
|
|
|
108 |
console.log("response warehouse", response);
|
|
|
109 |
response = JSON.parse(response);
|
|
|
110 |
inputOptions = [];
|
|
|
111 |
response.forEach(function (warehouse) {
|
|
|
112 |
inputOptions.push({
|
|
|
113 |
text: warehouse.name,
|
|
|
114 |
value: warehouse.id,
|
|
|
115 |
});
|
|
|
116 |
});
|
|
|
117 |
bootBoxObj['inputOptions'] = inputOptions;
|
|
|
118 |
bootbox.prompt(bootBoxObj);
|
|
|
119 |
});
|
|
|
120 |
} else if (inputOptions.length == 1) {
|
|
|
121 |
callback(inputOptions[0].warehouse.id);
|
|
|
122 |
} else {
|
|
|
123 |
bootbox.prompt(bootBoxObj);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
}
|