Subversion Repositories SmartDukaan

Rev

Rev 33939 | Rev 33944 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<style>
    table th {
        text-align: center;
    }

    #rbm-arr-table td, #rbm-arr-table th {
        padding: 0.35rem;
        font-size: 20px;
    }

    .rb-name {
        font-size: 17px;
        font-weight: bold;
    }

    #rbm-arr-table td {
        text-align: center;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        color: #000; /* Ensure text remains visible */
        font-weight: 400;
    }

</style>

<section class="wrapper">
    ##    <div class="row">
    ##        <div class="col-lg-12">
    ##            <h3 class="page-header"><i class="icon_document_alt"></i>RBM ARR</h3>
    ##            <ol class="breadcrumb">
    ##                <li><i class="fa fa-home"></i><a href="${rc.contextPath}/dashboard">Home</a></li>
    ##                <li><i class="icon_document_alt"></i>RBM Wise Today's ARR (Basis Product Movement)</li>
    ##            </ol>
    ##        </div>
    ##    </div>

    <div class="row">
        ##        <div class="col-lg-4">
        ##            <table>
        ##                <tr>
        ##                    <td><input type="date" class="form-control arr-start_date" placeholder="select date"></td>
        ##                    <td><button type="button" class="btn btn-info arr-button-mk">Submit</button></td>
        ##                </tr>
        ##            </table>
        ##        </div>
        ##        <div class="clearfix"></div>
        ##        <br>
        <div class="col-lg-12">
            <table id="rbm-arr-table" class="table table-border table-condensed table-bordered" style="width:100%">
                <thead>
                <tr>
                    <th>RBM</th>
                    <th>Total (ACH/TGT)</th>
                    <th>%</th>
                    <th>HID (ACH/TGT)</th>
                    <th>%</th>
                    <th>RUN (ACH/TGT)</th>
                    <th>%</th>
                    <th>SLOW (ACH/TGT)</th>
                    <th>%</th>
                    <th>EOL (ACH/TGT)</th>
                    <th>%</th>
                    <th>Other (ACH/TGT)</th>
                    <th>%</th>
                </tr>
                </thead>
                <tbody>
                    #foreach($target in $rbmArrViewModels)
                    <tr>
                        <td>$target.getRbmName()- $target.getWarehouseName()</td>
                        <td><span class="achieved-cell">$target.getTotalAchievedTarget()</span> / <span
                                class="target-cell">$target.getTodayTarget()</span></td>
                        <td class="total-percent"></td>
                        <td><span class="achieved-cell">$target.getTodayAchievedHidTarget()</span> / <span
                                class="target-cell">$target.getTodayHidTarget()</span></td>
                        <td class="hid-percent"></td>
                        <td><span class="achieved-cell">$target.getTodayAchievedFastMovingTarget()</span> / <span
                                class="target-cell">$target.getTodayFastMovingTarget()</span></td>
                        <td class="run-percent"></td>
                        <td><span class="achieved-cell">$target.getTodayAchievedSlowMovingTarget()</span> / <span
                                class="target-cell">$target.getTodaySlowMovingTarget()</span></td>
                        <td class="slow-percent"></td>
                        <td><span class="achieved-cell">$target.getTodayAchievedEolTarget()</span> / <span
                                class="target-cell">$target.getTodayEolTarget()</span></td>
                        <td class="eol-percent"></td>
                        <td><span class="achieved-cell">$target.getTodayAchievedOtherMovingTarget()</span> / <span
                                class="target-cell">$target.getTodayOtherMovingTarget()</span></td>
                        <td class="other-percent"></td>
                    </tr>
                    #end
                </tbody>
                <tfoot>
                <tr>
                    <td><strong>Total</strong></td>
                    <td><span id="total-achieved"></span> / <span id="total-target"></span></td>
                    <td class="total-percent"></td>
                    <td><span id="total-achieved-hid"></span> / <span id="total-target-hid"></span></td>
                    <td class="hid-percent"></td>
                    <td><span id="total-achieved-run"></span> / <span id="total-target-run"></span></td>
                    <td class="run-percent"></td>
                    <td><span id="total-achieved-slow"></span> / <span id="total-target-slow"></span></td>
                    <td class="slow-percent"></td>
                    <td><span id="total-achieved-eol"></span> / <span id="total-target-eol"></span></td>
                    <td class="eol-percent"></td>
                    <td><span id="total-achieved-other"></span> / <span id="total-target-other"></span></td>
                    <td class="other-percent"></td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</section>

<script>
    function formatValueInLakh(value) {
        return (value / 100000).toFixed(1) + 'L';
    }

    function formatTargets() {
        const rows = document.querySelectorAll('#rbm-arr-table tbody tr');
        let totalAchieved = 0, totalTarget = 0;
        let totalAchievedHid = 0, totalTargetHid = 0;
        let totalAchievedRun = 0, totalTargetRun = 0;
        let totalAchievedSlow = 0, totalTargetSlow = 0;
        let totalAchievedEol = 0, totalTargetEol = 0;
        let totalAchievedOther = 0, totalTargetOther = 0;

        rows.forEach(row => {
            const cells = row.querySelectorAll('td');
            cells.forEach((cell, index) => {
                const achievedSpan = cell.querySelector('.achieved-cell');
                const targetSpan = cell.querySelector('.target-cell');
                if (achievedSpan && targetSpan) {
                    const achievedValue = parseFloat(achievedSpan.textContent.replace(/[^\d.-]/g, ''));
                    const targetValue = parseFloat(targetSpan.textContent.replace(/[^\d.-]/g, ''));

                    // Add to totals
                    if (index === 1) {
                        totalAchieved += achievedValue || 0;
                        totalTarget += targetValue || 0;
                    } else if (index === 3) {
                        totalAchievedHid += achievedValue || 0;
                        totalTargetHid += targetValue || 0;
                    } else if (index === 5) {
                        totalAchievedRun += achievedValue || 0;
                        totalTargetRun += targetValue || 0;
                    } else if (index === 7) {
                        totalAchievedSlow += achievedValue || 0;
                        totalTargetSlow += targetValue || 0;
                    } else if (index === 9) {
                        totalAchievedEol += achievedValue || 0;
                        totalTargetEol += targetValue || 0;
                    } else if (index === 11) {
                        totalAchievedOther += achievedValue || 0;
                        totalTargetOther += targetValue || 0;
                    }

                    // Format values in lakh
                    if (!isNaN(achievedValue)) achievedSpan.textContent = formatValueInLakh(achievedValue);
                    if (!isNaN(targetValue)) targetSpan.textContent = formatValueInLakh(targetValue);

                    const percentCell = cell.nextElementSibling;
                    if (percentCell && targetValue > 0) {
                        const percentage = ((achievedValue / targetValue) * 100).toFixed(1);
                        percentCell.textContent = percentage + '%';

                        // Determine background color based on percentage
                        let color;
                        if (percentage <= 40) {
                            color = '#F56983FF'; // Orange for <= 40%
                        } else if (percentage > 40 && percentage <= 75) {
                            color = '#f2c947e8'; // Yellow for 41% - 75%
                        } else {
                            color = '#82ef8299'; // Green for > 75%
                        }

                        // Apply gradient background with the color
                        percentCell.style.background = `linear-gradient(to right, ${color} ${percentage}%, transparent ${percentage}%)`;
                    } else if (percentCell) {
                        percentCell.textContent = 'N/A';
                        percentCell.style.background = 'none';
                    }
                }
            });
        });

        // Update total row with calculated totals
        document.getElementById('total-achieved').textContent = formatValueInLakh(totalAchieved);
        document.getElementById('total-target').textContent = formatValueInLakh(totalTarget);
        document.getElementById('total-achieved-hid').textContent = formatValueInLakh(totalAchievedHid);
        document.getElementById('total-target-hid').textContent = formatValueInLakh(totalTargetHid);
        document.getElementById('total-achieved-run').textContent = formatValueInLakh(totalAchievedRun);
        document.getElementById('total-target-run').textContent = formatValueInLakh(totalTargetRun);
        document.getElementById('total-achieved-slow').textContent = formatValueInLakh(totalAchievedSlow);
        document.getElementById('total-target-slow').textContent = formatValueInLakh(totalTargetSlow);
        document.getElementById('total-achieved-eol').textContent = formatValueInLakh(totalAchievedEol);
        document.getElementById('total-target-eol').textContent = formatValueInLakh(totalTargetEol);
        document.getElementById('total-achieved-other').textContent = formatValueInLakh(totalAchievedOther);
        document.getElementById('total-target-other').textContent = formatValueInLakh(totalTargetOther);
    }

    window.onload = formatTargets;
</script>