Subversion Repositories SmartDukaan

Rev

Rev 35838 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<style>

   h5 { text-align: center;
    background-color: lightgray;
    padding: 5px;
    font-size: 16px;
    }

   .mrt-0 {
           margin-top: 0;
   }
    
  #brand-instock tr.hide-table-padding td {
  padding: 0;
}


   .expand-button {
        position: relative;
}

.accordion-toggle .expand-button:after
{
  position: absolute;
  left:.75rem;
  top: 50%;
  transform: translate(0, -50%);
  content: '-';
}
.accordion-toggle.collapsed .expand-button:after
{
  content: '+';
}

   .partner-wallet-view .modelHeaderCustom {
           font-size: 14px !important;
   }

   .partner-wallet-view {
           font-size: 13px;
   }


</style>

<style>
        .well {
                background-color: #f9f9f9;
                border: 1px solid #ddd;
                border-radius: 12px;
                padding: 5px 20px;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }

        .well h4 {
                margin-bottom: 10px;
                font-weight: 500;
                border-bottom: 1px solid #ccc;
                padding-bottom: 6px;
        }

        .well ul li {
                list-style: decimal;
                padding: 4px 0;
                font-weight: 400;
                font-size: 16px;
                border-bottom: 1px dashed #eee;
        }

        .well .currency {
                font-weight: 500
        }

        li.brandFocusedStockDetail a {
                padding: 8px 10px !important;
        }

        .out-of-stock-row a {
                text-decoration: none;
        }

        .out-of-stock-row a:hover {
                text-decoration: underline;
        }

        .oos-toggle-icon {
                display: inline-block;
                width: 16px;
                font-weight: bold;
        }

        .oos-content table {
                background-color: #fff;
        }

        .our-stock-detail-row td {
                border-top: none !important;
        }

        .our-stock-detail-row table {
                margin: 0;
                background-color: #fff;
        }

</style>

 
 
 
 
 <div class="modal-header">
                <button type="button" class="close" style="margin:-10px" data-dismiss="modal">&times;</button>
         <h4 class="modal-title"><b class="fofo-stock-info">Stock Info</b> ($customRetailer.getBusinessName())
                                <input type="hidden" id="fofo-id" value="$customRetailer.getPartnerId()">
                                <a id="mobileAppId" href="${rc.contextPath}/mobileapp?emailId=$customRetailer.getEmail()"
                                   class="btn btn-default" target="_blank">Franchise App</a>

                                <a class="btn btn-default today-fofo-offer" data-fofoid="$sdCreditRequirement.getFofoId()">Today
                                        Offer</a>
         <a class="btn btn-default scheme-imei-history-btn" data-fofoid="$sdCreditRequirement.getFofoId()">IMEI
             Margin</a>
                 <a class="btn btn-default partner-wallet-btn" data-fofoid="$sdCreditRequirement.getFofoId()">Partner
                         Wallet</a>

                        </h4>
       </div>
<div class="modal-body" style="max-height:75vh;overflow:auto;">
        <div class="row">
                <div class="col-md-8 today-fofo-offer-view" style="max-height: 70vh;overflow: auto;display: none;">

        </div>
        <div class="col-md-8 scheme-imei-history-view" style="max-height: 70vh;overflow: auto;display: none;">

                </div>
                <div class="col-md-8 partner-wallet-view" style="max-height: 70vh;overflow: auto;display: none;">

                </div>
                <div class="col-md-8 fofo-summry-view" style="max-height: 70vh;overflow: auto;">
                        <div class="well row" style="margin: 0;">
                                <h4>Summary
                    <a href="#" class="dashboard-view" data-fofoid="$sdCreditRequirement.getFofoId()">More Info</a>
                                </h4>
                                <div class="col-md-4">
                                        <h5>Fund Detail</h5>
                                        <ul>
                                                <li>Total Limit <span class="currency"> $sdCreditRequirement.getLimit()</span></li>
                                                <li>Utilization <span class="currency"> $sdCreditRequirement.getUtilizedAmount()</span></li>
                                                <li>Available Limit <span class="currency"> $sdCreditRequirement.getAvailableLimit()</span></li>
                                                <li>Wallet Amount <span class="currency"> $userWallet.getAmount()</span></li>

                                        </ul>
                                </div>
                                <div class="col-md-4">
                                        <h5>Investment Detail</h5>
                                        <ul>
                                                #if($shortInvest > 0)
                            <li>Short Investment -: <span class="currency"> $shortInvest</span></li>
                                                #end

                                                <li>DRR / Today Purchase <span class="currency"> $purchaseTargetFtd </span> /
                                                        #if($purchasedFtd < $purchaseTargetFtd)
                                                                <span style="color: red;"> <span class="currency"> $purchasedFtd</span> </span>
                                                        #else
                                                                <span style="color: green;"> <span class="currency"> $purchasedFtd</span> </span>
                                                        #end
                                                </li>

                                        </ul>

                                        <h5>Recoverable Amount </h5>
                                        <ul>
                                                <li>Short Invest <span class="currency">$shortInvest</span></li>
                                                <li>Overdue (with intr.) <span class="currency"> $totalDueWithInterest</span></li>
                                                <li>Interest <span class="currency"> $interestDue</span></li>
                                        </ul>

                                </div>

                                <div class="col-md-4">
                                        <h5>Target</h5>
                                        <ul>
                                                <li>Monthly Target -: <span class="currency">$monthlyTarget.purchaseTarget</span></li>
                                                <li>Purchase Mtd -: <span class="currency">$purchaseMtd</span></li>
                                                <li>Sale Mtd -: <span class="currency">$saleMtd</span></li>
                                        </ul>

                                </div>


                        </div>
                        <div class="clearfix"></div>
                        #if($brand != "undefined")
                                <hr style="margin-top:25px; margin-bottom: 10px;">
                                <div class="row">
                                        <div class="col-md-12">
                                                <ul class="nav nav-pills">
                                                        #foreach($bnd in $brands)
                                                                <li class="brandFocusedStockDetail" data-brand="$bnd" data-fofoid="$fofoId">
                                                                        #if(!$brandsWithPartnerStock.contains($bnd))
                                                                                <a style="color: red;" href="#tab_$bnd">$bnd</a>
                                                                        #else
                                                                                <a href="#tab_$bnd">$bnd</a>
                                                                        #end
                                                                </li>
                                                        #end
                                                        <li><a href="#collapse1" data-toggle="collapse"
                                                                   style="background-color: #ccc;color: black;">In Stock </a></li>
                                                        <li><a href="#collapse2" data-toggle="collapse"
                                                                   style="background-color: #ccc;color: black;">Sales </a></li>


                                                </ul>
                                                <div style="margin-top: 10px;">
                                                        <input type="text" id="modelSearchInput" class="form-control"
                                                                   placeholder="Search by Model Number..."
                                                                   style="width: 300px; display: inline-block;">
                                                        <button class="btn btn-default btn-sm" onclick="clearModelSearch()">Clear</button>
                                                </div>
                                                <hr>
                                                <div class="col-md-12 well panel-collapse collapse" id="collapse1">
                                                        <h4>In Stock </h4>
                                                        <div id="itemWiseBrandStockDetail"></div>
                                                </div>
                                                <div id="collapse2" class="panel-collapse collapse col-md-12 well">
                                                        <h4>Seven Days Sales</h4>
                                                        <table class="table table-striped table-advance table-hover" style="width:100%">
                                                                <thead>
                                                                <tr>
                                                                        <th style="width: 25%;">Item</th>
                                                                        <th style="width: 9%;">Brand</th>
                                                                        <th style="width: 15%;">Sold Qty</th>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                        #foreach($catalog in $sevenDayAboveSoldsCatalogs)
                                                                        <tr>
                                                                                <td>$catalog.getModelNumber()</td>
                                                                                <td>$catalog.getBrand()</td>
                                                                                <td>$catalog.getSoldQty()</td>
                                                                        </tr>
                                                                        #end
                                                                </tbody>
                                                        </table>
                                                        <h4>14 Days Sales</h4>
                                                        <table class="table table-striped table-advance table-hover" style="width:100%">
                                                                <thead>
                                                                <tr>
                                                                        <th style="width: 25%;">Item</th>
                                                                        <th style="width: 9%;">Brand</th>
                                                                        <th style="width: 15%;">Sold Qty</th>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                        #foreach($catalog in $fourteenDayAboveSoldsCatalogs)
                                                                        <tr>
                                                                                <td>$catalog.getModelNumber()</td>
                                                                                <td>$catalog.getBrand()</td>
                                                                                <td>$catalog.getSoldQty()</td>
                                                                        </tr>
                                                                        #end
                                                                </tbody>
                                                        </table>
                                                        <h4>21 Days Sales</h4>
                                                        <table class="table table-striped table-advance table-hover" style="width:100%">
                                                                <thead>
                                                                <tr>
                                                                        <th style="width: 25%;">Item</th>
                                                                        <th style="width: 9%;">Brand</th>
                                                                        <th style="width: 15%;">Sold Qty</th>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                        #foreach($catalog in $twentyOneDayAboveSoldsCatalogs)
                                                                        <tr>
                                                                                <td>$catalog.getModelNumber()</td>
                                                                                <td>$catalog.getBrand()</td>
                                                                                <td>$catalog.getSoldQty()</td>
                                                                        </tr>
                                                                        #end
                                                                </tbody>
                                                        </table>
                                                        <h4>28 Days Sales</h4>
                                                        <table class="table table-striped table-advance table-hover" style="width:100%">
                                                                <thead>
                                                                <tr>
                                                                        <th style="width: 25%;">Item</th>
                                                                        <th style="width: 9%;">Brand</th>
                                                                        <th style="width: 15%;">Sold Qty</th>
                                                                </tr>
                                                                </thead>
                                                                <tbody>
                                                                        #foreach($catalog in $twentyEightDayAboveSoldsCatalogs)
                                                                        <tr>
                                                                                <td>$catalog.getModelNumber()</td>
                                                                                <td>$catalog.getBrand()</td>
                                                                                <td>$catalog.getSoldQty()</td>
                                                                        </tr>
                                                                        #end
                                                                </tbody>
                                                        </table>

                                                </div>
                                                <div>
                                                        #foreach($bnd in $brands)
                                                                <div id="tab_$bnd" class="clearfix"></div>
                                                                #set($statusModelMap = $brandStatusWiseStockListMap.get($bnd))
                                                                <h4>$bnd</h4>
                                                                <table class="table table-striped table-advance table-hover" style="width:100%">
                                                                        <thead>
                                                                        <tr>
                                                                                <th style="width: 30%;">Item</th>
                                                                                <th>Status</th>
                                                                                <th>DP</th>
                                                                                <th>Our Stock</th>
                                                                                <th> In-Transit</th>
                                                                                <th>P-Fullfilled</th>
                                                                                <th>P-Shortage</th>
                                                                                <th>P-CurrentQty</th>
                                                                                <th>Indent</th>
                                                                                <th>Aging</th>
                                                                                <th>Action</th>
                                                                        </tr>
                                                                        </thead>
                                                                        <tbody>
                                                                                #foreach($statusKey in $statusModelMap.keySet())
                                                                                        #foreach($stocklist in $statusModelMap.get($statusKey))
                                                                                        <tr>
                                                                                                #if($stocklist.getPartnerCurrentAvailability() < 1)
                                                                                                        <td style="color: red;">$stocklist.getModelNumber()</td>
                                                                                                #else
                                                                                                        <td>$stocklist.getModelNumber()</td>
                                                                                                #end
                                                                                                <td>$stocklist.getStatus()</td>
                                                                                                <td>$tagListingsMap.get($stocklist.getCatalogId()).getSellingPrice()</td>
                                                                                                <td style="color: blue; text-decoration: underline; cursor: pointer;"
                                                                                                        onclick="toggleOurStockRow($stocklist.getCatalogId(), $warehouseId, '$stocklist.getModelNumber()')">
                                                                                                        $stocklist.getNetAvailability()
                                                                                                </td>
                                                                                                #if($catalogWiseQtyMap.get($stocklist.getCatalogId()))
                                                                                                        <td>$catalogWiseQtyMap.get($stocklist.getCatalogId())</td>
                                                                                                #else
                                                                                                        <td>-</td>
                                                                                                #end
                                                                                                <td>$stocklist.getPartnerStockAvailability()</td>
                                                                                                <td>$stocklist.getPartnerShortageStock()</td>
                                                                                                <td style="color: green; text-decoration: underline; cursor: pointer;"
                                                                                                        onclick="togglePartnerStockRow($stocklist.getCatalogId(), $fofoId, '$stocklist.getModelNumber()')">
                                                                                                        $stocklist.getPartnerCurrentAvailability()
                                                                                                </td>
                                                                                                <td>
                                                                                                        #if($pendingIndentsDetailMap.get($stocklist.getCatalogId()).getQty())
                                                                                                                $pendingIndentsDetailMap.get($stocklist.getCatalogId()).getQty()
                                                                                                        #else
                                                                                                                -
                                                                                                        #end
                                                                                                </td>
                                                                                                <td>$stocklist.getExceedDays()</td>
                                                                                                <td>
                                                                                                        <button class="btn btn-sm btn-success add-to-cart-btn"
                                                                                                                        data-toggle="modal"
                                                                                                                        data-target="#poItemsDetail"
                                                                                                                        data-catalogid="$stocklist.getCatalogId()"
                                                                                                                        data-warehouseid="$warehouseId"
                                                                                                                        data-model="$stocklist.getModelNumber()"
                                                                                                                        data-price="$tagListingsMap.get($stocklist.getCatalogId()).getSellingPrice()">
                                                                                                                Add to PO
                                                                                                        </button>
                                                                                                </td>
                                                                                        </tr>
                                                                                        <tr id="our-stock-row-$stocklist.getCatalogId()"
                                                                                                class="our-stock-detail-row"
                                                                                                style="display: none; background-color: #e8f4fd;">
                                                                                                <td colspan="11" style="padding: 10px 20px;">
                                                                                                        <div id="our-stock-content-$stocklist.getCatalogId()">
                                                                                                                <p>Loading...</p>
                                                                                                        </div>
                                                                                                </td>
                                                                                        </tr>
                                                                                        <tr id="partner-stock-row-$stocklist.getCatalogId()"
                                                                                                class="partner-stock-detail-row"
                                                                                                style="display: none; background-color: #d4edda;">
                                                                                                <td colspan="11" style="padding: 10px 20px;">
                                                                                                        <div id="partner-stock-content-$stocklist.getCatalogId()">
                                                                                                                <p>Loading...</p>
                                                                                                        </div>
                                                                                                </td>
                                                                                        </tr>
                                                                                        #end
                                                                                #end
                                                                        <tr class="out-of-stock-row" style="background-color: #f8d7da;">
                                                                                <td colspan="11">
                                                                                        <a href="#" style="color: #c0392b; font-weight: bold;"
                                                                                           onclick="toggleOutOfStock('$bnd', $warehouseId, $fofoId, this); return false;">
                                                                                                <span class="oos-toggle-icon">+</span> Out of Stock Items
                                                                                                (HID/FastMoving/Running)
                                                                                        </a>
                                                                                        <div id="oos-content-$bnd" class="oos-content"
                                                                                                 style="display: none; margin-top: 10px;">
                                                                                                <p>Loading...</p>
                                                                                        </div>
                                                                                </td>
                                                                        </tr>
                                                                        </tbody>
                                                                </table>
                                                        #end
                                                </div>
                                        </div>
                                </div>

                        #end
                </div>
                <div class="col-md-4">
                        <div id="cart-sidebar"
                                 style=" width:100%; background:#f8f9fa; border:1px solid #ccc; padding:5px; border-radius:6px;">
                                <h5 class="mrt-0">Suggested Po Item List</h5>
                                <div id="custom-cart-section" class="well"
                                         style="padding: 4px;max-height: 55vh;overflow-y: auto;"></div>
                                <button id="save-po-btn" class="btn btn-primary btn-block" style="margin-top:10px;">Save PO</button>
                        </div>
                </div>

        </div>


</div>


<div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-default view-close">Close</button>

</div>

<script>
        var ourStockDataLoaded = {};
        var oosDataLoaded = {};
        var partnerStockDataLoaded = {};

        function togglePartnerStockRow(catalogId, fofoId, modelNumber) {
                var row = document.getElementById('partner-stock-row-' + catalogId);
                var contentDiv = document.getElementById('partner-stock-content-' + catalogId);

                if (row.style.display === 'none') {
                        row.style.display = 'table-row';

                        // Load data only if not already loaded
                        if (!partnerStockDataLoaded[catalogId]) {
                                contentDiv.innerHTML = '<p>Loading...</p>';

                                $.ajax({
                                        url: '${rc.contextPath}/getItemsByCatalog',
                                        type: 'GET',
                                        data: {catalogId: catalogId, fofoId: fofoId},
                                        success: function (response) {
                                                partnerStockDataLoaded[catalogId] = true;

                                                var list = response.response;

                                                if (list && list.length > 0) {
                                                        var html = '<strong>Partner Stock: ' + modelNumber + '</strong>';
                                                        html += '<table class="table table-bordered table-sm" style="margin-top:5px; background-color: #fff;">';
                                                        html += '<thead><tr style="background-color: #d4edda;"><th>Item ID</th><th>Description</th><th>Qty</th><th>Status</th></tr></thead><tbody>';

                                                        for (var i = 0; i < list.length; i++) {
                                                                if (list[i].availability > 0) {
                                                                        var stockType = list[i].stockType || 'IN_STOCK';
                                                                        var rowStyle = stockType === 'GRN_PENDING' ? 'background-color: #fff3cd;' : '';
                                                                        var statusLabel = stockType === 'GRN_PENDING' ? '<span style="color: #856404; font-weight: bold;">GRN Pending</span>' : '<span style="color: #155724;">In Stock</span>';
                                                                        html += '<tr style="' + rowStyle + '">';
                                                                        html += '<td>' + list[i].itemId + '</td>';
                                                                        html += '<td>' + (list[i].itemDescription || '-') + '</td>';
                                                                        html += '<td>' + list[i].availability + '</td>';
                                                                        html += '<td>' + statusLabel + '</td>';
                                                                        html += '</tr>';
                                                                }
                                                        }

                                                        html += '</tbody></table>';
                                                        contentDiv.innerHTML = html;
                                                } else {
                                                        contentDiv.innerHTML = '<p>No partner stock details available</p>';
                                                }
                                        },
                                        error: function () {
                                                contentDiv.innerHTML = '<p style="color: red; margin: 0;">Error loading partner stock details</p>';
                                        }
                                });
                        }
                } else {
                        row.style.display = 'none';
                }
        }

        function toggleOurStockRow(catalogId, warehouseId, modelNumber) {
                var row = document.getElementById('our-stock-row-' + catalogId);
                var contentDiv = document.getElementById('our-stock-content-' + catalogId);

                if (row.style.display === 'none') {
                        row.style.display = 'table-row';

                        // Load data only if not already loaded
                        if (!ourStockDataLoaded[catalogId]) {
                                contentDiv.innerHTML = '<p>Loading...</p>';

                                $.ajax({
                                        url: '${rc.contextPath}/indent/getOurStockDetails',
                                        type: 'GET',
                                        data: {catalogId: catalogId, warehouseId: warehouseId},
                                        success: function (response) {


                                                ourStockDataLoaded[catalogId] = true;

                                                var list = response.response;   // 🔥 correct key

                                                if (list && list.length > 0) {
                                                        var html = '<strong>' + modelNumber + '</strong><br>';
                                                        html += '<small style="color:#666;">' + list[0].itemDescription + '</small>';

                                                        html += '<table class="table table-bordered table-sm" style="margin-top:5px">';
                                                        html += '<thead><tr><th>Color</th><th>Qty</th></tr></thead><tbody>';

                                                        for (var i = 0; i < list.length; i++) {
                                                                html += '<tr>';
                                                                html += '<td>' + (list[i].color || '-') + '</td>';
                                                                html += '<td>' + list[i].qty + '</td>';
                                                                html += '</tr>';
                                                        }

                                                        html += '</tbody></table>';
                                                        contentDiv.innerHTML = html;
                                                } else {
                                                        contentDiv.innerHTML = '<p>No color-wise stock details available</p>';
                                                }
                                        },
                                        error: function () {
                                                contentDiv.innerHTML = '<p style="color: red; margin: 0;">Error loading stock details</p>';
                                        }
                                });
                        }
                } else {
                        row.style.display = 'none';
                }
        }

        function toggleOutOfStock(brand, warehouseId, fofoId, linkElement) {
                var contentDiv = document.getElementById('oos-content-' + brand);
                var icon = linkElement.querySelector('.oos-toggle-icon');

                if (contentDiv.style.display === 'none') {
                        contentDiv.style.display = 'block';
                        icon.textContent = '-';

                        // Load data only if not already loaded
                        if (!oosDataLoaded[brand]) {
                                contentDiv.innerHTML = '<p>Loading...</p>';

                                $.ajax({
                                        url: '${rc.contextPath}/indent/getOutOfStockDetails',
                                        type: 'GET',
                                        data: {brand: brand, warehouseId: warehouseId, fofoId: fofoId},
                                        success: function (response) {
                                                console.log("RESPONSE:", response);
                                                oosDataLoaded[brand] = true;

                                                var list = response.response;

                                                if (list && list.length > 0) {
                                                        // Sort items alphabetically by model number (series-wise)
                                                        list.sort(function (a, b) {
                                                                return a.modelNumber.localeCompare(b.modelNumber, undefined, {sensitivity: 'base'});
                                                        });

                                                        var html = '<table class="table table-bordered table-sm" style="margin-bottom: 0;">';
                                                        html += '<thead><tr style="background-color: #f8d7da;"><th>Model Number</th><th>Status</th><th>DP</th><th>Our Stock</th><th>P-CurrentQty</th><th>Action</th></tr></thead><tbody>';

                                                        for (var i = 0; i < list.length; i++) {
                                                                var partnerQty = list[i].partnerCurrentQty || 0;
                                                                var dpPrice = list[i].dp || 0;
                                                                var partnerQtyStyle = partnerQty > 0 ? 'color: green; text-decoration: underline; cursor: pointer;' : 'color: #666;';
                                                                var partnerQtyClick = partnerQty > 0 ? 'onclick="toggleOosPartnerStockRow(' + list[i].catalogId + ', ' + fofoId + ', \'' + list[i].modelNumber + '\')"' : '';

                                                                html += '<tr style="background-color: #f8d7da;">';
                                                                html += '<td>' + list[i].modelNumber + '</td>';
                                                                html += '<td>' + list[i].status + '</td>';
                                                                html += '<td>' + dpPrice + '</td>';
                                                                html += '<td>' + list[i].qty + '</td>';
                                                                html += '<td style="' + partnerQtyStyle + '" ' + partnerQtyClick + '>' + partnerQty + '</td>';
                                                                html += '<td>';
                                                                html += '<button class="btn btn-sm btn-success add-to-cart-btn" data-toggle="modal" data-target="#poItemsDetail" ';
                                                                html += 'data-catalogid="' + list[i].catalogId + '" data-warehouseid="' + warehouseId + '" ';
                                                                html += 'data-model="' + list[i].modelNumber + '" data-price="' + dpPrice + '">Add to PO</button>';
                                                                html += '</td>';
                                                                html += '</tr>';

                                                                // Add hidden row for partner stock details
                                                                html += '<tr id="oos-partner-stock-row-' + list[i].catalogId + '" class="oos-partner-stock-detail-row" style="display: none; background-color: #d4edda;">';
                                                                html += '<td colspan="6" style="padding: 10px 20px;"><div id="oos-partner-stock-content-' + list[i].catalogId + '"><p>Loading...</p></div></td>';
                                                                html += '</tr>';
                                                        }

                                                        html += '</tbody></table>';
                                                        contentDiv.innerHTML = html;
                                                } else {
                                                        contentDiv.innerHTML = '<p style="color: green; margin: 0;">No out of stock items for HID/FastMoving/Running categories.</p>';
                                                }
                                        },
                                        error: function () {
                                                contentDiv.innerHTML = '<p style="color: red; margin: 0;">Error loading out of stock details</p>';
                                        }
                                });
                        }
                } else {
                        contentDiv.style.display = 'none';
                        icon.textContent = '+';
                }
        }

        var oosPartnerStockDataLoaded = {};

        function toggleOosPartnerStockRow(catalogId, fofoId, modelNumber) {
                var row = document.getElementById('oos-partner-stock-row-' + catalogId);
                var contentDiv = document.getElementById('oos-partner-stock-content-' + catalogId);

                if (row.style.display === 'none') {
                        row.style.display = 'table-row';

                        // Load data only if not already loaded
                        if (!oosPartnerStockDataLoaded[catalogId]) {
                                contentDiv.innerHTML = '<p>Loading...</p>';

                                $.ajax({
                                        url: '${rc.contextPath}/getItemsByCatalog',
                                        type: 'GET',
                                        data: {catalogId: catalogId, fofoId: fofoId},
                                        success: function (response) {
                                                oosPartnerStockDataLoaded[catalogId] = true;

                                                var list = response.response;

                                                if (list && list.length > 0) {
                                                        var html = '<strong>Partner Stock: ' + modelNumber + '</strong>';
                                                        html += '<table class="table table-bordered table-sm" style="margin-top:5px; background-color: #fff;">';
                                                        html += '<thead><tr style="background-color: #d4edda;"><th>Item ID</th><th>Description</th><th>Qty</th><th>Status</th></tr></thead><tbody>';

                                                        for (var i = 0; i < list.length; i++) {
                                                                if (list[i].availability > 0) {
                                                                        var stockType = list[i].stockType || 'IN_STOCK';
                                                                        var rowStyle = stockType === 'GRN_PENDING' ? 'background-color: #fff3cd;' : '';
                                                                        var statusLabel = stockType === 'GRN_PENDING' ? '<span style="color: #856404; font-weight: bold;">GRN Pending</span>' : '<span style="color: #155724;">In Stock</span>';
                                                                        html += '<tr style="' + rowStyle + '">';
                                                                        html += '<td>' + list[i].itemId + '</td>';
                                                                        html += '<td>' + (list[i].itemDescription || '-') + '</td>';
                                                                        html += '<td>' + list[i].availability + '</td>';
                                                                        html += '<td>' + statusLabel + '</td>';
                                                                        html += '</tr>';
                                                                }
                                                        }

                                                        html += '</tbody></table>';
                                                        contentDiv.innerHTML = html;
                                                } else {
                                                        contentDiv.innerHTML = '<p>No partner stock details available</p>';
                                                }
                                        },
                                        error: function () {
                                                contentDiv.innerHTML = '<p style="color: red; margin: 0;">Error loading partner stock details</p>';
                                        }
                                });
                        }
                } else {
                        row.style.display = 'none';
                }
        }

        // Model Number Search Filter
        $('#modelSearchInput').on('keyup', function () {
                var searchText = $(this).val().toLowerCase().trim();

                // Filter rows in all brand tables
                $('.fofo-summry-view table tbody tr').each(function () {
                        var $row = $(this);

                        // Skip detail rows (our-stock-detail-row, partner-stock-detail-row, out-of-stock-row, oos-partner-stock-detail-row)
                        if ($row.hasClass('our-stock-detail-row') ||
                                                $row.hasClass('partner-stock-detail-row') ||
                                                $row.hasClass('out-of-stock-row') ||
                                                $row.hasClass('oos-partner-stock-detail-row')) {
                                return;
                        }

                        // Get model number from first column
                        var modelNumber = $row.find('td:first').text().toLowerCase().trim();

                        if (searchText === '' || modelNumber.indexOf(searchText) > -1) {
                                        $row.show();
                        } else {
                                        $row.hide();
                                // Also hide related detail rows
                                var catalogId = $row.find('td:first').text().trim();
                                        $row.next('.our-stock-detail-row').hide();
                                        $row.next().next('.partner-stock-detail-row').hide();
                        }
                });
        });

        function clearModelSearch() {
                $('#modelSearchInput').val('');
                $('.fofo-summry-view table tbody tr').show();
        }
</script>