| 30003 |
tejbeer |
1 |
$(function() {
|
|
|
2 |
$(document).on('click', ".partner-brandwise-detail", function() {
|
|
|
3 |
loadDetails("main-content");
|
|
|
4 |
});
|
|
|
5 |
|
| 30047 |
tejbeer |
6 |
|
|
|
7 |
$(document).on('change', "#activationType", function() {
|
| 30046 |
tejbeer |
8 |
var row = $(this).closest("tr");
|
| 30047 |
tejbeer |
9 |
var code = $(row).find("td:eq(1)").text();
|
| 34030 |
ranu |
10 |
var activationType = $(row).find("td:eq(24) option:selected").val();
|
| 30047 |
tejbeer |
11 |
|
| 30046 |
tejbeer |
12 |
if (confirm("Are you sure ") == true) {
|
| 30047 |
tejbeer |
13 |
doPostAjaxRequestHandler(context + "/changeActivationType?code=" + code + "&activationType=" + activationType,
|
|
|
14 |
function(response) {
|
|
|
15 |
|
|
|
16 |
console.log(response);
|
|
|
17 |
|
|
|
18 |
if (response == true) {
|
|
|
19 |
loadDetails("main-content");
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
});
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
}
|
| 30046 |
tejbeer |
26 |
});
|
| 30003 |
tejbeer |
27 |
});
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
function loadDetails(domId) {
|
|
|
31 |
|
|
|
32 |
doGetAjaxRequestHandler(context + "/getPartnersBrandWiseDetail",
|
|
|
33 |
function(response) {
|
|
|
34 |
$('#' + domId).html(response);
|
|
|
35 |
});
|
|
|
36 |
}
|
|
|
37 |
|
| 30046 |
tejbeer |
38 |
|
| 34437 |
ranu |
39 |
// create suggested po cart related js start here
|
| 30046 |
tejbeer |
40 |
|
| 34437 |
ranu |
41 |
let cart = {};
|
|
|
42 |
|
|
|
43 |
function renderCart() {
|
|
|
44 |
let cartHtml = '';
|
|
|
45 |
let totalAmount = 0;
|
|
|
46 |
|
|
|
47 |
// First loop through cart and calculate totalAmount
|
|
|
48 |
for (const id in cart) {
|
|
|
49 |
const item = cart[id];
|
|
|
50 |
const itemTotal = item.qty * item.price;
|
|
|
51 |
totalAmount += itemTotal;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// Add total at the top
|
|
|
55 |
if (totalAmount > 0) {
|
|
|
56 |
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">`;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Now loop again to render items
|
|
|
60 |
for (const id in cart) {
|
|
|
61 |
const item = cart[id];
|
|
|
62 |
const itemTotal = item.qty * item.price;
|
|
|
63 |
|
|
|
64 |
cartHtml += `
|
|
|
65 |
<li style="display: flex; align-items: center; justify-content: space-between; padding: 5px 0;">
|
| 34449 |
ranu |
66 |
<div style="flex: 1; min-width: 200px;">${item.model} <br> <span style="color: gray;">- ${item.color}</div>
|
| 34437 |
ranu |
67 |
<div style="display: flex; align-items: center; gap: 5px;">
|
|
|
68 |
<button class="dec-btn" data-id="${id}">-</button>
|
|
|
69 |
<span class="cart-qty">${item.qty}</span>
|
|
|
70 |
<button class="inc-btn" data-id="${id}">+</button>
|
|
|
71 |
<button class="remove-btn btn btn-xs btn-danger" data-id="${id}">x</button>
|
|
|
72 |
</div>
|
|
|
73 |
<span style="width: 80px; text-align: right;">₹ ${itemTotal.toFixed(2)}</span>
|
|
|
74 |
</li>`;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$('#custom-cart-section').html(cartHtml);
|
|
|
78 |
}
|
|
|
79 |
|
| 34449 |
ranu |
80 |
$(document).on('click', '.po-radio-button', function () {
|
|
|
81 |
const selectedRadio = $(this).find('input[type="radio"]');
|
| 34437 |
ranu |
82 |
|
| 34449 |
ranu |
83 |
const itemId = selectedRadio.data('itemid');
|
|
|
84 |
const model = selectedRadio.data('modelnumber');
|
|
|
85 |
const color = selectedRadio.data('color');
|
|
|
86 |
const price = parseFloat(selectedRadio.data('price')) || 0;
|
| 34437 |
ranu |
87 |
|
| 34449 |
ranu |
88 |
const key = itemId;
|
|
|
89 |
|
|
|
90 |
if (cart[key]) {
|
|
|
91 |
cart[key].qty += 1;
|
| 34437 |
ranu |
92 |
} else {
|
| 34449 |
ranu |
93 |
cart[key] = {model, color, qty: 1, price};
|
| 34437 |
ranu |
94 |
}
|
|
|
95 |
|
|
|
96 |
renderCart();
|
|
|
97 |
});
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
$(document).on('click', '.inc-btn', function () {
|
|
|
101 |
const id = $(this).data('id');
|
|
|
102 |
cart[id].qty += 1;
|
|
|
103 |
renderCart();
|
|
|
104 |
});
|
|
|
105 |
|
|
|
106 |
$(document).on('click', '.dec-btn', function () {
|
|
|
107 |
const id = $(this).data('id');
|
|
|
108 |
if (cart[id].qty > 1) {
|
|
|
109 |
cart[id].qty -= 1;
|
|
|
110 |
} else {
|
|
|
111 |
delete cart[id];
|
|
|
112 |
}
|
|
|
113 |
renderCart();
|
|
|
114 |
});
|
|
|
115 |
|
|
|
116 |
$(document).on('click', '.remove-btn', function () {
|
|
|
117 |
const id = $(this).data('id');
|
|
|
118 |
delete cart[id];
|
|
|
119 |
renderCart();
|
|
|
120 |
});
|
|
|
121 |
|
| 34449 |
ranu |
122 |
$(document).on('click', '.add-to-cart-btn', function () {
|
|
|
123 |
var price = $(this).data('price');
|
|
|
124 |
var catalogId = $(this).data('catalogid');
|
|
|
125 |
console.log('price ', price)
|
|
|
126 |
|
|
|
127 |
doGetAjaxRequestHandler(context + "/getPoCatalogsItems?price=" + price + "&catalogId=" + catalogId, function (response) {
|
|
|
128 |
|
|
|
129 |
$('#poItemsDetail .modal-content').html(response);
|
|
|
130 |
|
|
|
131 |
});
|
|
|
132 |
});
|
|
|
133 |
|
| 34437 |
ranu |
134 |
$(document).on('click', '#save-po-btn', function () {
|
|
|
135 |
console.log("Save PO button clicked!");
|
|
|
136 |
const fofoId = parseInt($('#fofo-id').val());
|
|
|
137 |
console.log('fofoId:', fofoId);
|
|
|
138 |
saveSuggestedPo(fofoId);
|
|
|
139 |
});
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
function saveSuggestedPo(fofoId) {
|
|
|
143 |
var jsonObject = {};
|
|
|
144 |
jsonObject.poIds = [];
|
|
|
145 |
|
|
|
146 |
// Select <li> directly, not from inside <ul>
|
|
|
147 |
$("#custom-cart-section li").each(function () {
|
| 34449 |
ranu |
148 |
const itemId = $(this).find(".dec-btn").data("id");
|
| 34437 |
ranu |
149 |
const qty = parseInt($(this).find(".cart-qty").text().trim());
|
|
|
150 |
|
| 34449 |
ranu |
151 |
if (!isNaN(itemId) && qty > 0) {
|
| 34437 |
ranu |
152 |
const item = {
|
| 34449 |
ranu |
153 |
itemId: itemId,
|
| 34437 |
ranu |
154 |
qty: qty
|
|
|
155 |
};
|
|
|
156 |
jsonObject.poIds.push(item);
|
|
|
157 |
}
|
|
|
158 |
});
|
|
|
159 |
|
|
|
160 |
if (jsonObject.poIds.length === 0) {
|
|
|
161 |
alert("Cart is empty!");
|
|
|
162 |
return;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
console.log("Sending PO Data:", jsonObject);
|
|
|
166 |
|
|
|
167 |
if (confirm("Are you sure you want to save this Suggested PO?")) {
|
|
|
168 |
doPostAjaxRequestWithJsonHandler(
|
|
|
169 |
context + "/createSuggestedPo?fofoId=" + fofoId,
|
|
|
170 |
JSON.stringify(jsonObject.poIds),
|
|
|
171 |
function (response) {
|
|
|
172 |
if (response === 'true' || response.includes("true")) {
|
|
|
173 |
alert("Suggested PO created successfully!");
|
|
|
174 |
cart = {};
|
|
|
175 |
renderCart();
|
|
|
176 |
} else {
|
|
|
177 |
alert("Failed to create Suggested PO.");
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
);
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|