| 33661 |
ranu |
1 |
var retailerName;
|
|
|
2 |
var fofoId;
|
|
|
3 |
var detailPoId;
|
|
|
4 |
$(function () {
|
|
|
5 |
$(document).on('click', ".suggested-monthly-po", function () {
|
|
|
6 |
getAllOpenPo("main-content");
|
|
|
7 |
});
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
$(document).on('click', "#suggested-monthly-po .podetail", function () {
|
|
|
11 |
var poId = $(this).data("poid");
|
|
|
12 |
fofoId = $(this).data("fofoid");
|
|
|
13 |
detailPoId = poId;
|
|
|
14 |
retailerName = $(this).find('td:nth-child(1) span').text().trim();
|
|
|
15 |
|
|
|
16 |
$(this).addClass("active-tr");
|
|
|
17 |
$(".podetail").not(this).removeClass("active-tr");
|
|
|
18 |
|
|
|
19 |
getPoDetailOrder(poId, "suggested-monthly-po-detail");
|
|
|
20 |
});
|
|
|
21 |
|
|
|
22 |
});
|
|
|
23 |
|
|
|
24 |
function getAllOpenPo(domId) {
|
|
|
25 |
doGetAjaxRequestHandler(context + "/getMonthlySuggestedPo", function (response) {
|
|
|
26 |
$('#' + domId).html(response);
|
|
|
27 |
|
|
|
28 |
// Destroy the existing DataTable instance if it exists
|
|
|
29 |
if ($.fn.DataTable.isDataTable('#suggested-monthly-po')) {
|
|
|
30 |
$('#suggested-monthly-po').DataTable().destroy();
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
// Initialize DataTable
|
|
|
34 |
var table = $('#suggested-monthly-po').DataTable({
|
|
|
35 |
"bPaginate": true,
|
|
|
36 |
"pageLength": 25,
|
|
|
37 |
"bLengthChange": true,
|
|
|
38 |
"bFilter": true,
|
|
|
39 |
"bInfo": false,
|
|
|
40 |
"bAutoWidth": false
|
|
|
41 |
});
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
table.page('first').draw('page');
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
var firstVisibleRow = $("#suggested-monthly-po tbody tr:visible:first");
|
|
|
48 |
if (firstVisibleRow.length > 0) {
|
|
|
49 |
firstVisibleRow.trigger('click');
|
|
|
50 |
}
|
|
|
51 |
});
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
function getPoDetailOrder(poId, detailContainer) {
|
|
|
56 |
var url = context + "/monthlyPo/orderByPoId?poId=" + poId;
|
|
|
57 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
58 |
$('#' + detailContainer).html(response);
|
|
|
59 |
$("#selected-po").text(poId);
|
|
|
60 |
});
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
$(function () {
|
|
|
64 |
$(document).on('click', "#approveOrderBtn", function () {
|
|
|
65 |
// Show confirmation alert
|
|
|
66 |
var userConfirmed = confirm("Are you sure you want to approve this order?");
|
|
|
67 |
|
|
|
68 |
// Proceed only if the user confirms
|
|
|
69 |
if (userConfirmed) {
|
|
|
70 |
var bulkOrderModels = [];
|
|
|
71 |
$('#suggested-monthly-po-detail tbody tr').each(function (index) {
|
|
|
72 |
var row = $(this);
|
|
|
73 |
|
|
|
74 |
var bulkOrder = {
|
|
|
75 |
rowIndex: index + 1,
|
|
|
76 |
fofoId: fofoId,
|
|
|
77 |
partnerName: retailerName,
|
|
|
78 |
itemId: row.find('td:nth-child(1)').text().trim(),
|
|
|
79 |
description: row.find('td:nth-child(2)').text().trim(),
|
|
|
80 |
quantity: row.find('td:nth-child(3)').text().trim(),
|
|
|
81 |
itemPrice: row.find('td:nth-child(4)').text().trim()
|
|
|
82 |
};
|
|
|
83 |
|
|
|
84 |
bulkOrderModels.push(bulkOrder);
|
|
|
85 |
});
|
|
|
86 |
|
|
|
87 |
console.log("bulk order models", bulkOrderModels);
|
|
|
88 |
|
|
|
89 |
// Send the request only after confirmation
|
|
|
90 |
doPostAjaxRequestWithJsonHandler(context + `/monthlyPo/approve?poId=${detailPoId}`, JSON.stringify(bulkOrderModels), function (response) {
|
|
|
91 |
if (response) {
|
|
|
92 |
getAllOpenPo("main-content");
|
|
|
93 |
}
|
|
|
94 |
});
|
|
|
95 |
} else {
|
|
|
96 |
// User canceled the action, do nothing
|
|
|
97 |
console.log("User canceled the approval.");
|
|
|
98 |
}
|
|
|
99 |
});
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
$(document).on('click', "#cancelOrderBtn", function () {
|
|
|
103 |
var userConfirmed = confirm("Are you sure you want to cancel this order?");
|
|
|
104 |
|
|
|
105 |
// Proceed only if the user confirms
|
|
|
106 |
if (userConfirmed) {
|
|
|
107 |
doPostAjaxRequestHandler(context + `/monthlyPo/cancelPo?poId=${detailPoId}`, function (response) {
|
|
|
108 |
if (response) {
|
|
|
109 |
getAllOpenPo("main-content");
|
|
|
110 |
}
|
|
|
111 |
});
|
|
|
112 |
} else {
|
|
|
113 |
console.log("User canceled the approval.");
|
|
|
114 |
}
|
|
|
115 |
});
|
|
|
116 |
});
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|