| 30003 |
tejbeer |
1 |
$(function() {
|
|
|
2 |
$(document).on('click', ".partner-brandwise-detail", function() {
|
|
|
3 |
loadDetails("main-content");
|
|
|
4 |
});
|
|
|
5 |
|
| 30047 |
tejbeer |
6 |
$(document).on('change', "#activationType", function() {
|
| 30046 |
tejbeer |
7 |
var row = $(this).closest("tr");
|
| 30047 |
tejbeer |
8 |
var code = $(row).find("td:eq(1)").text();
|
| 34548 |
ranu |
9 |
var activationType = $(row).find("#activationType").val();
|
| 30047 |
tejbeer |
10 |
|
| 30046 |
tejbeer |
11 |
if (confirm("Are you sure ") == true) {
|
| 30047 |
tejbeer |
12 |
doPostAjaxRequestHandler(context + "/changeActivationType?code=" + code + "&activationType=" + activationType,
|
|
|
13 |
function(response) {
|
|
|
14 |
|
|
|
15 |
console.log(response);
|
|
|
16 |
|
|
|
17 |
if (response == true) {
|
|
|
18 |
loadDetails("main-content");
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
});
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
}
|
| 30046 |
tejbeer |
25 |
});
|
| 30003 |
tejbeer |
26 |
});
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
function loadDetails(domId) {
|
|
|
30 |
|
|
|
31 |
doGetAjaxRequestHandler(context + "/getPartnersBrandWiseDetail",
|
|
|
32 |
function(response) {
|
|
|
33 |
$('#' + domId).html(response);
|
|
|
34 |
});
|
|
|
35 |
}
|
|
|
36 |
|
| 30046 |
tejbeer |
37 |
|
| 34437 |
ranu |
38 |
// create suggested po cart related js start here
|
| 30046 |
tejbeer |
39 |
|
| 34437 |
ranu |
40 |
let cart = {};
|
|
|
41 |
|
|
|
42 |
function renderCart() {
|
|
|
43 |
let cartHtml = '';
|
|
|
44 |
let totalAmount = 0;
|
|
|
45 |
|
|
|
46 |
// First loop through cart and calculate totalAmount
|
|
|
47 |
for (const id in cart) {
|
|
|
48 |
const item = cart[id];
|
|
|
49 |
const itemTotal = item.qty * item.price;
|
|
|
50 |
totalAmount += itemTotal;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// Add total at the top
|
|
|
54 |
if (totalAmount > 0) {
|
|
|
55 |
cartHtml += `<div style="text-align:right;font-weight:bold; margin-bottom: 10px;">Total: ₹ ${totalAmount.toFixed(2)}</div><hr style="margin: 4px 0;border-top: 1px solid #000">`;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
// Now loop again to render items
|
|
|
59 |
for (const id in cart) {
|
|
|
60 |
const item = cart[id];
|
|
|
61 |
const itemTotal = item.qty * item.price;
|
|
|
62 |
|
|
|
63 |
cartHtml += `
|
|
|
64 |
<li style="display: flex; align-items: center; justify-content: space-between; padding: 5px 0;">
|
| 34449 |
ranu |
65 |
<div style="flex: 1; min-width: 200px;">${item.model} <br> <span style="color: gray;">- ${item.color}</div>
|
| 34437 |
ranu |
66 |
<div style="display: flex; align-items: center; gap: 5px;">
|
|
|
67 |
<button class="dec-btn" data-id="${id}">-</button>
|
|
|
68 |
<span class="cart-qty">${item.qty}</span>
|
|
|
69 |
<button class="inc-btn" data-id="${id}">+</button>
|
|
|
70 |
<button class="remove-btn btn btn-xs btn-danger" data-id="${id}">x</button>
|
|
|
71 |
</div>
|
|
|
72 |
<span style="width: 80px; text-align: right;">₹ ${itemTotal.toFixed(2)}</span>
|
|
|
73 |
</li>`;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$('#custom-cart-section').html(cartHtml);
|
|
|
77 |
}
|
|
|
78 |
|
| 34449 |
ranu |
79 |
$(document).on('click', '.po-radio-button', function () {
|
|
|
80 |
const selectedRadio = $(this).find('input[type="radio"]');
|
| 34437 |
ranu |
81 |
|
| 34449 |
ranu |
82 |
const itemId = selectedRadio.data('itemid');
|
|
|
83 |
const model = selectedRadio.data('modelnumber');
|
|
|
84 |
const color = selectedRadio.data('color');
|
|
|
85 |
const price = parseFloat(selectedRadio.data('price')) || 0;
|
| 34437 |
ranu |
86 |
|
| 34449 |
ranu |
87 |
const key = itemId;
|
|
|
88 |
|
|
|
89 |
if (cart[key]) {
|
|
|
90 |
cart[key].qty += 1;
|
| 34437 |
ranu |
91 |
} else {
|
| 34449 |
ranu |
92 |
cart[key] = {model, color, qty: 1, price};
|
| 34437 |
ranu |
93 |
}
|
|
|
94 |
|
|
|
95 |
renderCart();
|
|
|
96 |
});
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
$(document).on('click', '.inc-btn', function () {
|
|
|
100 |
const id = $(this).data('id');
|
|
|
101 |
cart[id].qty += 1;
|
|
|
102 |
renderCart();
|
|
|
103 |
});
|
|
|
104 |
|
|
|
105 |
$(document).on('click', '.dec-btn', function () {
|
|
|
106 |
const id = $(this).data('id');
|
|
|
107 |
if (cart[id].qty > 1) {
|
|
|
108 |
cart[id].qty -= 1;
|
|
|
109 |
} else {
|
|
|
110 |
delete cart[id];
|
|
|
111 |
}
|
|
|
112 |
renderCart();
|
|
|
113 |
});
|
|
|
114 |
|
|
|
115 |
$(document).on('click', '.remove-btn', function () {
|
|
|
116 |
const id = $(this).data('id');
|
|
|
117 |
delete cart[id];
|
|
|
118 |
renderCart();
|
|
|
119 |
});
|
|
|
120 |
|
| 34449 |
ranu |
121 |
$(document).on('click', '.add-to-cart-btn', function () {
|
|
|
122 |
var price = $(this).data('price');
|
|
|
123 |
var catalogId = $(this).data('catalogid');
|
|
|
124 |
console.log('price ', price)
|
|
|
125 |
|
|
|
126 |
doGetAjaxRequestHandler(context + "/getPoCatalogsItems?price=" + price + "&catalogId=" + catalogId, function (response) {
|
|
|
127 |
|
|
|
128 |
$('#poItemsDetail .modal-content').html(response);
|
|
|
129 |
|
|
|
130 |
});
|
|
|
131 |
});
|
|
|
132 |
|
| 34490 |
ranu |
133 |
$(document).on('click', '.get-stock-info', function () {
|
|
|
134 |
var $clickedTd = $(this);
|
|
|
135 |
var $clickedTr = $clickedTd.closest('tr');
|
|
|
136 |
|
|
|
137 |
var catalogId = $clickedTd.data('catalogid');
|
|
|
138 |
var fofoId = $clickedTd.data('fofoid');
|
|
|
139 |
|
|
|
140 |
// If already expanded, remove it
|
|
|
141 |
if ($clickedTr.next().hasClass('expanded-row')) {
|
|
|
142 |
$clickedTr.next().remove();
|
|
|
143 |
return;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
doGetAjaxRequestHandler(context + "/getItemsByCatalog?fofoId=" + fofoId + "&catalogId=" + catalogId, function (response) {
|
|
|
147 |
console.log('response', response);
|
|
|
148 |
|
|
|
149 |
// Remove old expanded rows
|
|
|
150 |
$('.expanded-row').remove();
|
|
|
151 |
|
| 34495 |
ranu |
152 |
var expandHtml = '<tr class="expanded-row"><td colspan="10">' + buildStockInfoHtml(response.response) + '</td></tr>';
|
| 34490 |
ranu |
153 |
|
|
|
154 |
$clickedTr.after(expandHtml);
|
|
|
155 |
});
|
|
|
156 |
});
|
|
|
157 |
|
| 34495 |
ranu |
158 |
// function to build HTML when response is a LIST
|
|
|
159 |
function buildStockInfoHtml(responseList) {
|
|
|
160 |
console.log("responseList {}", responseList);
|
|
|
161 |
if (!Array.isArray(responseList) || responseList.length === 0) {
|
| 34490 |
ranu |
162 |
return '<div>No stock info available.</div>';
|
|
|
163 |
}
|
|
|
164 |
|
| 34495 |
ranu |
165 |
var html = '<div style="padding:10px; background:#f9f9f9; border:1px solid #ccc;">';
|
|
|
166 |
html += '<strong>Stock Details:</strong>';
|
|
|
167 |
html += '<table class="table table-bordered" style="margin-top:10px;">';
|
|
|
168 |
html += '<thead><tr><th>Item ID</th><th>Availability</th><th>Description</th></tr></thead>';
|
|
|
169 |
html += '<tbody>';
|
| 34490 |
ranu |
170 |
|
| 34495 |
ranu |
171 |
responseList.forEach(function (item) {
|
|
|
172 |
html += '<tr>';
|
|
|
173 |
html += '<td>' + item.itemId + '</td>';
|
|
|
174 |
html += '<td>' + item.availability + '</td>';
|
|
|
175 |
html += '<td>' + (item.itemDescription && item.itemDescription !== 0 ? item.itemDescription : 'Not Available') + '</td>';
|
|
|
176 |
html += '</tr>';
|
|
|
177 |
});
|
| 34490 |
ranu |
178 |
|
| 34495 |
ranu |
179 |
html += '</tbody></table></div>';
|
| 34490 |
ranu |
180 |
|
|
|
181 |
return html;
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
| 34437 |
ranu |
186 |
$(document).on('click', '#save-po-btn', function () {
|
|
|
187 |
console.log("Save PO button clicked!");
|
|
|
188 |
const fofoId = parseInt($('#fofo-id').val());
|
|
|
189 |
console.log('fofoId:', fofoId);
|
|
|
190 |
saveSuggestedPo(fofoId);
|
|
|
191 |
});
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
function saveSuggestedPo(fofoId) {
|
|
|
195 |
var jsonObject = {};
|
|
|
196 |
jsonObject.poIds = [];
|
|
|
197 |
|
|
|
198 |
// Select <li> directly, not from inside <ul>
|
|
|
199 |
$("#custom-cart-section li").each(function () {
|
| 34449 |
ranu |
200 |
const itemId = $(this).find(".dec-btn").data("id");
|
| 34437 |
ranu |
201 |
const qty = parseInt($(this).find(".cart-qty").text().trim());
|
|
|
202 |
|
| 34449 |
ranu |
203 |
if (!isNaN(itemId) && qty > 0) {
|
| 34437 |
ranu |
204 |
const item = {
|
| 34449 |
ranu |
205 |
itemId: itemId,
|
| 34437 |
ranu |
206 |
qty: qty
|
|
|
207 |
};
|
|
|
208 |
jsonObject.poIds.push(item);
|
|
|
209 |
}
|
|
|
210 |
});
|
|
|
211 |
|
|
|
212 |
if (jsonObject.poIds.length === 0) {
|
|
|
213 |
alert("Cart is empty!");
|
|
|
214 |
return;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
console.log("Sending PO Data:", jsonObject);
|
|
|
218 |
|
|
|
219 |
if (confirm("Are you sure you want to save this Suggested PO?")) {
|
|
|
220 |
doPostAjaxRequestWithJsonHandler(
|
|
|
221 |
context + "/createSuggestedPo?fofoId=" + fofoId,
|
|
|
222 |
JSON.stringify(jsonObject.poIds),
|
|
|
223 |
function (response) {
|
|
|
224 |
if (response === 'true' || response.includes("true")) {
|
|
|
225 |
alert("Suggested PO created successfully!");
|
|
|
226 |
cart = {};
|
|
|
227 |
renderCart();
|
|
|
228 |
} else {
|
|
|
229 |
alert("Failed to create Suggested PO.");
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|