Subversion Repositories SmartDukaan

Rev

Rev 33997 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33997 ranu 1
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
2
      integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
3
<link rel="stylesheet"
4
      href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-daterangepicker/3.1.0/daterangepicker.min.css"/>
5
 
6
<style>
7
    table th {
8
        text-align: center;
9
    }
10
 
11
    #rbm-arr-table td, #rbm-arr-table th {
12
        padding: 0.35rem;
13
        font-size: 18px;
14
    }
15
 
16
    .text-bold {
17
        font-weight: bold !important;
18
    }
19
 
20
    .text-bold span {
21
        font-weight: bold;
22
    }
23
 
24
    .rb-name {
25
        font-size: 16px;
26
        font-weight: bold;
27
    }
28
 
29
    #rbm-arr-table td {
30
        text-align: center;
31
        background-size: 100% 100%;
32
        background-repeat: no-repeat;
33
        color: #000; /* Ensure text remains visible */
34
        font-weight: 400;
35
    }
36
 
37
</style>
38
 
39
<section class="wrapper">
40
    <div class="row">
41
        <div class="col-lg-12">
42
            <table id="rbm-arr-table" class="table table-border table-condensed table-bordered" style="width:100%">
43
                <tr>
44
                    <th>RBM</th>
45
                    <th>Total (ACH/TGT)</th>
46
                    <th>%</th>
47
                    <th>HID (ACH/TGT)</th>
48
                    <th>%</th>
49
                    <th>FAST (ACH/TGT)</th>
50
                    <th>%</th>
51
                    <th>RUN (ACH/TGT)</th>
52
                    <th>%</th>
34098 ranu 53
                    <th>SLOW (ACH/TGT)</th>
33997 ranu 54
                    <th>%</th>
55
                    <th>Other (ACH/TGT)</th>
56
                    <th>%</th>
57
                </tr>
58
                #foreach($target in $rbmTargetAndAchievementsModels)
59
                    <tr>
60
                        <td>$target.getRbmName()- $target.getWarehouseName()</td>
61
                        <td><span class="achieved-cell">$target.getTotalAchievemnt()</span> / <span
62
                                class="target-cell">$target.getTotalTarget()</span></td>
63
                        <td class="total-percent"></td>
64
                        <td><span class="achieved-cell">$target.getAchievedHid()</span> / <span
65
                                class="target-cell">$target.getHidTarget()</span></td>
66
                        <td class="hid-percent"></td>
34098 ranu 67
 
33997 ranu 68
                        <td><span class="achieved-cell">$target.getAchievedFastMoving()</span> / <span
69
                                class="target-cell">$target.getFastMovingTarget()</span></td>
34098 ranu 70
                        <td class="fast-percent"></td>
71
 
72
                        <td><span class="achieved-cell">$target.getAchievedRunning()</span> / <span
73
                                class="target-cell">$target.getRunningTarget()</span></td>
33997 ranu 74
                        <td class="run-percent"></td>
34098 ranu 75
 
33997 ranu 76
                        <td><span class="achieved-cell">$target.getAchievedSlowMoving()</span> / <span
77
                                class="target-cell">$target.getSlowMovingTarget()</span></td>
78
                        <td class="slow-percent"></td>
34098 ranu 79
 
33997 ranu 80
                        <td><span class="achieved-cell">$target.getAchievedOtherMoving()</span> / <span
81
                                class="target-cell">$target.getOtherMovingTarget()</span></td>
82
                        <td class="other-percent"></td>
83
                    </tr>
84
                #end
85
                <!-- Add a row for totals -->
86
                <tr>
87
                    <td><strong>Total</strong></td>
88
                    <td class="text-bold"><span class="achieved-cell">$totalAchieved </span> / <span
89
                            class="target-cell">$totalTarget</span></td>
90
                    <td class="total-percent text-bold"></td>
91
 
92
                    <td class="text-bold"><span class="achieved-cell">$totalAchievedHid</span> / <span
93
                            class="target-cell">$totalTargetHid</span></td>
94
                    <td class="hid-percent text-bold"></td>
95
 
96
                    <td class="text-bold"><span class="achieved-cell">$totalAchievedFast</span> / <span
97
                            class="target-cell">$totalTargetFast</span></td>
34098 ranu 98
                    <td class="fast-percent text-bold"></td>
99
 
100
                    <td class="text-bold"><span class="achieved-cell">$totalAchievedRunning</span> / <span
101
                            class="target-cell">$totalTargetRunning</span></td>
33997 ranu 102
                    <td class="run-percent text-bold"></td>
103
 
104
                    <td class="text-bold"><span class="achieved-cell">$totalAchievedSlow</span> / <span
105
                            class="target-cell">$totalTargetSlow</span></td>
106
                    <td class="slow-percent text-bold"></td>
107
 
108
                    <td class="text-bold"><span class="achieved-cell">$totalAchievedOther</span> / <span
109
                            class="target-cell">$totalTargetOther</span></td>
110
                    <td class="other-percent text-bold"></td>
111
                </tr>
112
 
113
            </table>
114
        </div>
115
    </div>
116
</section>
117
 
118
<script>
119
    function formatValueInLakh(value) {
120
        return (value / 100000).toFixed(1) + 'L';
121
    }
122
 
123
    function formatTargets() {
124
        const rows = document.querySelectorAll('#rbm-arr-table tbody tr');
125
        let totalAchieved = 0, totalTarget = 0;
126
        let totalAchievedHid = 0, totalTargetHid = 0;
34098 ranu 127
        let totalAchievedFast = 0, totalTargetFast = 0;
128
        let totalAchievedRunning = 0, totalTargetRunning = 0;
33997 ranu 129
        let totalAchievedSlow = 0, totalTargetSlow = 0;
130
        let totalAchievedOther = 0, totalTargetOther = 0;
131
 
132
        rows.forEach(row => {
133
            const cells = row.querySelectorAll('td');
134
            cells.forEach((cell, index) => {
135
                const achievedSpan = cell.querySelector('.achieved-cell');
136
                const targetSpan = cell.querySelector('.target-cell');
137
                if (achievedSpan && targetSpan) {
138
                    const achievedValue = parseFloat(achievedSpan.textContent.replace(/[^\d.-]/g, ''));
139
                    const targetValue = parseFloat(targetSpan.textContent.replace(/[^\d.-]/g, ''));
140
 
141
                    // Add to totals
142
                    if (index === 1) {
143
                        totalAchieved += achievedValue || 0;
144
                        totalTarget += targetValue || 0;
145
                    } else if (index === 3) {
146
                        totalAchievedHid += achievedValue || 0;
147
                        totalTargetHid += targetValue || 0;
148
                    } else if (index === 5) {
34098 ranu 149
                        totalAchievedFast += achievedValue || 0;
150
                        totalTargetFast += targetValue || 0;
33997 ranu 151
                    } else if (index === 7) {
34098 ranu 152
                        totalAchievedRunning += achievedValue || 0;
153
                        totalTargetRunning += targetValue || 0;
154
                    } else if (index === 9) {
33997 ranu 155
                        totalAchievedSlow += achievedValue || 0;
156
                        totalTargetSlow += targetValue || 0;
157
                    } else if (index === 11) {
158
                        totalAchievedOther += achievedValue || 0;
159
                        totalTargetOther += targetValue || 0;
160
                    }
161
 
162
                    // Format values in lakh
163
                    if (!isNaN(achievedValue)) achievedSpan.textContent = formatValueInLakh(achievedValue);
164
                    if (!isNaN(targetValue)) targetSpan.textContent = formatValueInLakh(targetValue);
165
 
166
                    const percentCell = cell.nextElementSibling;
167
                    if (percentCell && targetValue > 0) {
168
                        const percentage = ((achievedValue / targetValue) * 100).toFixed(1);
169
                        percentCell.textContent = percentage + '%';
170
 
171
                        // Determine background color based on percentage
172
                        let color;
173
                        if (percentage <= 1) {
174
                            percentCell.style.color = `red`
175
                        }
176
                        if (percentage <= 40) {
177
                            color = '#F56983FF'; // Orange for <= 40%
178
                        } else if (percentage > 40 && percentage <= 75) {
179
                            color = '#f2c947e8'; // Yellow for 41% - 75%
180
                        } else {
181
                            color = '#82ef8299'; // Green for > 75%
182
                        }
183
 
184
                        // Apply gradient background with the color
185
                        percentCell.style.background = `linear-gradient(to right, ${color} ${percentage}%, transparent ${percentage}%)`;
186
                    } else if (percentCell) {
187
                        percentCell.textContent = "-";
188
                        percentCell.style.background = 'none';
189
                    }
190
                }
191
            });
192
        });
193
 
194
    }
195
 
196
    function groupRowsByRbm() {
197
        const rows = document.querySelectorAll('#rbm-arr-table tbody tr');
198
        let currentRbm = null;
199
        let rbmGroup = [];
200
 
201
        rows.forEach((row, index) => {
202
            const rbmCell = row.cells[0];
203
            if (!rbmCell) return;
204
 
205
            const rbmName = rbmCell.textContent.split('-')[0].trim(); // Extract RBM name
206
 
207
            if (rbmName !== currentRbm) {
208
                // Apply border to the previous group
209
                if (rbmGroup.length > 0) {
210
                    applyBorderToGroup(rbmGroup);
211
                }
212
 
213
                // Reset for new RBM
214
                currentRbm = rbmName;
215
                rbmGroup = [];
216
            }
217
 
218
            // Add the row to the current group
219
            rbmGroup.push(row);
220
 
221
            // Apply border to the last group
222
            if (index === rows.length - 1 && rbmGroup.length > 0) {
223
                applyBorderToGroup(rbmGroup);
224
            }
225
        });
226
    }
227
 
228
    function applyBorderToGroup(group) {
229
        if (group.length === 0) return;
230
 
231
        // Add border styles to the first and last rows in the group
232
        //group[0].style.borderTop = '2px solid #000'; // Black border for start
233
        group[group.length - 1].style.borderBottom = '2px solid #000'; // Black border for end
234
    }
235
 
236
    window.onload = function () {
237
        formatTargets(); // Format targets first
238
        groupRowsByRbm(); // Group rows by RBM
239
    };
240
 
241
 
242
</script>