| 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 |
|
| 33715 |
ranu |
63 |
function getPoDetailOrder(poId, detailContainer) {
|
|
|
64 |
var url = context + "/monthlyPo/orderByPoId?poId=" + poId;
|
|
|
65 |
doGetAjaxRequestHandler(url, function (response) {
|
|
|
66 |
|
|
|
67 |
$('#' + detailContainer).html(response);
|
|
|
68 |
|
|
|
69 |
$("#selected-po").text(poId);
|
|
|
70 |
|
|
|
71 |
calculateAndDisplayTotalPrice();
|
|
|
72 |
});
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function calculateAndDisplayTotalPrice() {
|
|
|
76 |
var totalPrice = 0;
|
|
|
77 |
|
|
|
78 |
$('#suggested-monthly-po-detail tbody tr').each(function () {
|
|
|
79 |
var itemPrice = parseFloat($(this).find('td:eq(3)').text());
|
|
|
80 |
var quantity = parseFloat($(this).find('td:eq(2)').text());
|
|
|
81 |
|
|
|
82 |
totalPrice += itemPrice * quantity;
|
|
|
83 |
});
|
|
|
84 |
|
|
|
85 |
$('.totalPoPrice').text('Total PO Price: ' + totalPrice.toFixed(2));
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
|
| 33661 |
ranu |
89 |
$(function () {
|
|
|
90 |
$(document).on('click', "#approveOrderBtn", function () {
|
|
|
91 |
// Show confirmation alert
|
|
|
92 |
var userConfirmed = confirm("Are you sure you want to approve this order?");
|
|
|
93 |
|
|
|
94 |
// Proceed only if the user confirms
|
|
|
95 |
if (userConfirmed) {
|
|
|
96 |
var bulkOrderModels = [];
|
|
|
97 |
$('#suggested-monthly-po-detail tbody tr').each(function (index) {
|
|
|
98 |
var row = $(this);
|
|
|
99 |
|
|
|
100 |
var bulkOrder = {
|
|
|
101 |
rowIndex: index + 1,
|
|
|
102 |
fofoId: fofoId,
|
|
|
103 |
partnerName: retailerName,
|
|
|
104 |
itemId: row.find('td:nth-child(1)').text().trim(),
|
|
|
105 |
description: row.find('td:nth-child(2)').text().trim(),
|
|
|
106 |
quantity: row.find('td:nth-child(3)').text().trim(),
|
|
|
107 |
itemPrice: row.find('td:nth-child(4)').text().trim()
|
|
|
108 |
};
|
|
|
109 |
|
|
|
110 |
bulkOrderModels.push(bulkOrder);
|
|
|
111 |
});
|
|
|
112 |
|
|
|
113 |
console.log("bulk order models", bulkOrderModels);
|
|
|
114 |
|
|
|
115 |
// Send the request only after confirmation
|
|
|
116 |
doPostAjaxRequestWithJsonHandler(context + `/monthlyPo/approve?poId=${detailPoId}`, JSON.stringify(bulkOrderModels), function (response) {
|
|
|
117 |
if (response) {
|
|
|
118 |
getAllOpenPo("main-content");
|
|
|
119 |
}
|
|
|
120 |
});
|
|
|
121 |
} else {
|
|
|
122 |
// User canceled the action, do nothing
|
|
|
123 |
console.log("User canceled the approval.");
|
|
|
124 |
}
|
|
|
125 |
});
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
$(document).on('click', "#cancelOrderBtn", function () {
|
|
|
129 |
var userConfirmed = confirm("Are you sure you want to cancel this order?");
|
|
|
130 |
|
|
|
131 |
// Proceed only if the user confirms
|
|
|
132 |
if (userConfirmed) {
|
|
|
133 |
doPostAjaxRequestHandler(context + `/monthlyPo/cancelPo?poId=${detailPoId}`, function (response) {
|
|
|
134 |
if (response) {
|
|
|
135 |
getAllOpenPo("main-content");
|
|
|
136 |
}
|
|
|
137 |
});
|
|
|
138 |
} else {
|
|
|
139 |
console.log("User canceled the approval.");
|
|
|
140 |
}
|
|
|
141 |
});
|
|
|
142 |
});
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|