Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
27474 tejbeer 1
<style>
35064 aman 2
    .saleTable tr th {
3
        color: #FFFFFF;
4
        padding-bottom: 6px;
5
    }
27474 tejbeer 6
 
35064 aman 7
    .saleTable tr td {
8
        padding-bottom: 6px;
9
    }
27474 tejbeer 10
 
35064 aman 11
    .blue-bg {
12
        box-shadow: 4px 4px 4px grey;
13
        background-image: linear-gradient(#57889c, #B0C4DE);
14
    }
27474 tejbeer 15
 
35064 aman 16
    .brand-wise-table {
17
        width: 100%;
18
        border-collapse: collapse;
19
    }
27474 tejbeer 20
 
35064 aman 21
    .brand-wise-table th, .brand-wise-table td {
22
        border: 1px solid #ddd;
23
        padding: 8px;
24
    }
27474 tejbeer 25
 
35064 aman 26
    .brand-wise-table th {
27
        background-color: #57889c;
28
        color: #fff;
29
    }
35084 aman 30
 
31
    /* Add striped styling for nested tables */
32
    .nested-table-striped tbody tr:nth-of-type(odd) {
33
        background-color: rgba(0, 0, 0, 0.05);
34
    }
35
 
36
    .nested-table-striped tbody tr:hover {
37
        background-color: rgba(0, 0, 0, 0.075);
38
    }
27474 tejbeer 39
</style>
40
 
35064 aman 41
<table class="table table-striped saleTable" style="color:blue;">
42
    <thead>
43
    <tr class="cursor-pointer">
44
        <th></th>
45
        <th>Sales</th>
46
        <th>MTD</th>
47
        <th>Type</th>
48
        <th></th>
49
    </tr>
50
    </thead>
35119 aman 51
    #macro(safe $val)
52
        #if($val && $val != "null")
53
            $val
54
        #else
55
            -
56
        #end
57
    #end
35064 aman 58
 
59
    <tbody id="monthSalesBody">
35284 aman 60
        #set($start = 0)
35064 aman 61
        #set($end = 6)
62
        #set($range = [$start..$end])
63
        #foreach($i in $range)
35284 aman 64
        <tr class="clickable-row cursor-pointer" data-month="$i">
35119 aman 65
            <td><b>#safe($monthSales.get($i).getMonth())</b></td>
66
            <td>#safe($monthSales.get($i).getMonthlySales())</td>
67
            <td>#safe($monthSales.get($i).getMtdSales())</td>
68
            <td>#safe($monthSales.get($i).getPartnerType())</td>
35064 aman 69
            <td class="toggle-cell">
70
                <i class="fa fa-angle-down dropdown-icon"
71
                   style="cursor:pointer; font-size: 27px;width: 27px;height: 27px;margin-top: 0px;color: rgba(255, 255, 255, 0.75);line-height: 27px;"></i>
72
            </td>
73
        </tr>
74
 
35119 aman 75
 
35064 aman 76
        <tr class="brand-wise-sale-row cursor-pointer" style="display: none;">
77
            <td colspan="6">
35084 aman 78
                <!-- Added table-striped and nested-table-striped classes -->
79
                <table class="table table-striped nested-table-striped brand-wise-table">
35064 aman 80
                    <thead>
81
                    <tr>
82
                        <th>Brand</th>
36242 aman 83
                        <th class="lmtdHead">LMTD</th>
35284 aman 84
                        <th class="mtdHead">MTD</th>
35064 aman 85
                        <th>MTDQTY</th>
86
                        <th></th>
87
                    </tr>
88
                    </thead>
89
                    <tbody class="brandWiseBody">
90
                    </tbody>
91
                </table>
92
            </td>
93
        </tr>
94
        <tr class="brand-item-wise-sale-row cursor-pointer" style="display: none;">
95
            <td colspan="6">
35084 aman 96
                <!-- Added table-striped and nested-table-striped classes -->
97
                <table class="table table-striped nested-table-striped brand-wise-table">
35064 aman 98
                    <thead>
99
                    <tr>
100
                        <th>Model</th>
101
                        <th>Quantity</th>
102
                    </tr>
103
                    </thead>
104
                    <tbody class="brandItemWiseBody">
105
                    </tbody>
106
                </table>
107
            </td>
108
        </tr>
109
        #end
110
    </tbody>
111
</table>
112
 
113
<script>
114
    function getCookie(name) {
115
        const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
116
        if (match) {
117
            return decodeURIComponent(match[2]);
118
        }
119
        return null;
120
    }
121
 
122
    document.querySelectorAll('.clickable-row').forEach(function (row) {
123
        row.addEventListener('click', function () {
124
            const brandWiseRow = row.nextElementSibling;
125
            const allBrandWiseRows = document.querySelectorAll('.brand-wise-sale-row');
126
            const fofoId = getCookie("fofoId");
35084 aman 127
 
35064 aman 128
            allBrandWiseRows.forEach(function (otherRow) {
129
                if (otherRow !== brandWiseRow) {
130
                    otherRow.style.display = 'none';
35084 aman 131
                    const brandItemRows = otherRow.parentNode.querySelectorAll('.brand-item-wise-sale-row');
132
                    brandItemRows.forEach(itemRow => itemRow.style.display = 'none');
35064 aman 133
                }
134
            });
135
 
35284 aman 136
            let minusmonth = row.getAttribute('data-month');
35064 aman 137
 
35284 aman 138
            if (!minusmonth) {
139
                console.error('Invalid month:', minusmonth);
35064 aman 140
                return;
141
            }
142
 
35084 aman 143
            // Toggle the brand-wise row
35064 aman 144
            if (brandWiseRow.style.display === 'none') {
145
                brandWiseRow.style.display = '';
146
 
147
                doGetAjaxRequestHandler(
35284 aman 148
                        `getBrandwisePartnerSale?month=${minusmonth}`,
35064 aman 149
                        function (response) {
35284 aman 150
                            let currentDate = new Date();
151
                            let selectedMonth = new Date();
152
                            selectedMonth.setMonth(currentDate.getMonth() - minusmonth);
153
 
154
                            let prevMonth = new Date();
155
                            prevMonth.setMonth(selectedMonth.getMonth() - 1);
156
 
157
                            const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
158
 
36242 aman 159
                            brandWiseRow.querySelector(".lmtdHead").innerText = "LMTD (" + monthNames[prevMonth.getMonth()] + ")";
35284 aman 160
                            brandWiseRow.querySelector(".mtdHead").innerText = "MTD (" + monthNames[selectedMonth.getMonth()] + ")";
161
 
35064 aman 162
                            const brandBody = brandWiseRow.querySelector('.brandWiseBody');
163
                            brandBody.innerHTML = '';
164
 
165
                            response.forEach(function (item) {
166
                                const safe = (val) => (val == null || val === "null" ? 0 : val);
167
                                const brandRow = document.createElement('tr');
168
                                brandRow.classList.add('clickable-brandrow');
35084 aman 169
                                brandRow.setAttribute('data-brand', item.brand);
35064 aman 170
                                brandRow.innerHTML =
171
                                        '<td><b>' + safe(item.brand) + '</b></td>' +
36242 aman 172
                                        '<td>' + safe(item.lmtd) + '</td>' +
35064 aman 173
                                        '<td>' + safe(item.mtd) + '</td>' +
174
                                        '<td>' + safe(item.mtdQty) + '</td>' +
35084 aman 175
                                        '<td class="toggle-cell"><i class="fa fa-angle-down dropdown-icon" style="cursor:pointer; font-size: 27px;width: 27px;height: 27px;margin-top: 0px;color: rgba(255, 255, 255, 0.75);line-height: 27px;"></i></td>';
176
 
35064 aman 177
                                brandRow.addEventListener('click', function () {
178
                                    const brandName = item.brand;
179
 
180
                                    let brandItemWiseRow = brandRow.nextElementSibling;
181
                                    if (!brandItemWiseRow || !brandItemWiseRow.classList.contains('brand-item-wise-sale-row')) {
182
                                        brandItemWiseRow = document.createElement('tr');
183
                                        brandItemWiseRow.classList.add('brand-item-wise-sale-row');
35084 aman 184
                                        brandItemWiseRow.style.display = 'none';
35064 aman 185
                                        brandItemWiseRow.innerHTML = `
35084 aman 186
                <td colspan="6">
187
                    <table class="table table-striped nested-table-striped brand-wise-table">
188
                        <thead>
189
                            <tr>
190
                                <th>Model</th>
191
                                <th>Quantity</th>
192
                            </tr>
193
                        </thead>
194
                        <tbody class="brandItemWiseBody"></tbody>
195
                    </table>
196
                </td>
197
            `;
35064 aman 198
                                        brandRow.insertAdjacentElement('afterend', brandItemWiseRow);
199
                                    }
200
 
35084 aman 201
                                    // Hide all other brand-item-wise rows
202
                                    const allBrandItemWiseRows = document.querySelectorAll('.brand-item-wise-sale-row');
203
                                    allBrandItemWiseRows.forEach(function (otherRow) {
204
                                        if (otherRow !== brandItemWiseRow) {
205
                                            otherRow.style.display = 'none';
206
                                        }
207
                                    });
35064 aman 208
 
35084 aman 209
                                    // Toggle current row - same logic as month rows
210
                                    if (brandItemWiseRow.style.display === 'none') {
35064 aman 211
                                        brandItemWiseRow.style.display = '';
212
                                        doGetAjaxRequestHandler(
35284 aman 213
                                                'getBrandItemwisePartnerSale?month=' + minusmonth + '&brand=' + encodeURIComponent(brandName) + '&fofoId=' + encodeURIComponent(fofoId),
35064 aman 214
                                                function (response) {
215
                                                    const tbody = brandItemWiseRow.querySelector('.brandItemWiseBody');
216
                                                    tbody.innerHTML = '';
217
                                                    response.forEach(item => {
218
                                                        const tr = document.createElement('tr');
219
                                                        tr.innerHTML =
35084 aman 220
                                                                '<td>' + item.modelName + item.modelNumber + '</td>' +
35119 aman 221
                                                                '<td>' + safe(item.quantity) + " pcs" + '</td>';
35064 aman 222
                                                        tbody.appendChild(tr);
223
                                                    });
224
                                                }
225
                                        );
35084 aman 226
                                    } else {
227
                                        brandItemWiseRow.style.display = 'none';
35064 aman 228
                                    }
229
                                });
230
 
231
                                brandBody.appendChild(brandRow);
232
                            });
233
                        }
234
                );
235
            } else {
236
                brandWiseRow.style.display = 'none';
35084 aman 237
                const brandItemRows = brandWiseRow.parentNode.querySelectorAll('.brand-item-wise-sale-row');
238
                brandItemRows.forEach(itemRow => itemRow.style.display = 'none');
35064 aman 239
            }
240
        });
241
    });
35084 aman 242
</script>