Rev 34030 | Rev 34449 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(function() {$(document).on('click', ".partner-brandwise-detail", function() {loadDetails("main-content");});$(document).on('change', "#activationType", function() {var row = $(this).closest("tr");var code = $(row).find("td:eq(1)").text();var activationType = $(row).find("td:eq(24) option:selected").val();if (confirm("Are you sure ") == true) {doPostAjaxRequestHandler(context + "/changeActivationType?code=" + code + "&activationType=" + activationType,function(response) {console.log(response);if (response == true) {loadDetails("main-content");}});}});});function loadDetails(domId) {doGetAjaxRequestHandler(context + "/getPartnersBrandWiseDetail",function(response) {$('#' + domId).html(response);});}// create suggested po cart related js start herelet cart = {};function renderCart() {let cartHtml = '';let totalAmount = 0;// First loop through cart and calculate totalAmountfor (const id in cart) {const item = cart[id];const itemTotal = item.qty * item.price;totalAmount += itemTotal;}// Add total at the topif (totalAmount > 0) {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">`;}// Now loop again to render itemsfor (const id in cart) {const item = cart[id];const itemTotal = item.qty * item.price;cartHtml += `<li style="display: flex; align-items: center; justify-content: space-between; padding: 5px 0;"><div style="flex: 1; min-width: 200px;">${item.model}</div><div style="display: flex; align-items: center; gap: 5px;"><button class="dec-btn" data-id="${id}">-</button><span class="cart-qty">${item.qty}</span><button class="inc-btn" data-id="${id}">+</button><button class="remove-btn btn btn-xs btn-danger" data-id="${id}">x</button></div><span style="width: 80px; text-align: right;">₹ ${itemTotal.toFixed(2)}</span></li>`;}$('#custom-cart-section').html(cartHtml);}$(document).on('click', '.add-to-cart-btn', function () {const catalogId = $(this).data('catalogid');const model = $(this).data('model');const price = parseFloat($(this).data('price')) || 0;if (cart[catalogId]) {cart[catalogId].qty += 1;} else {cart[catalogId] = {model, qty: 1, price};}renderCart();});$(document).on('click', '.inc-btn', function () {const id = $(this).data('id');cart[id].qty += 1;renderCart();});$(document).on('click', '.dec-btn', function () {const id = $(this).data('id');if (cart[id].qty > 1) {cart[id].qty -= 1;} else {delete cart[id];}renderCart();});$(document).on('click', '.remove-btn', function () {const id = $(this).data('id');delete cart[id];renderCart();});$(document).on('click', '#save-po-btn', function () {console.log("Save PO button clicked!");const fofoId = parseInt($('#fofo-id').val());console.log('fofoId:', fofoId);saveSuggestedPo(fofoId);});function saveSuggestedPo(fofoId) {var jsonObject = {};jsonObject.poIds = [];// Select <li> directly, not from inside <ul>$("#custom-cart-section li").each(function () {const catalogId = $(this).find(".dec-btn").data("id");const qty = parseInt($(this).find(".cart-qty").text().trim());if (!isNaN(catalogId) && qty > 0) {const item = {catalogId: catalogId,qty: qty};jsonObject.poIds.push(item);}});if (jsonObject.poIds.length === 0) {alert("Cart is empty!");return;}console.log("Sending PO Data:", jsonObject);if (confirm("Are you sure you want to save this Suggested PO?")) {doPostAjaxRequestWithJsonHandler(context + "/createSuggestedPo?fofoId=" + fofoId,JSON.stringify(jsonObject.poIds),function (response) {if (response === 'true' || response.includes("true")) {alert("Suggested PO created successfully!");cart = {};renderCart();} else {alert("Failed to create Suggested PO.");}});}}