Subversion Repositories SmartDukaan

Rev

Rev 35064 | Rev 35119 | Go to most recent revision | 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>
51
 
52
    <tbody id="monthSalesBody">
53
        #set($start = 1)
54
        #set($end = 6)
55
        #set($range = [$start..$end])
56
        #foreach($i in $range)
57
        <tr class="clickable-row cursor-pointer" data-month="$monthSales.get($i).getMonth()">
58
            <td><b>$monthSales.get($i).getMonth()</b></td>
59
            <td>$monthSales.get($i).getMonthlySales()</td>
60
            <td>$monthSales.get($i).getMtdSales()</td>
61
            <td>$monthSales.get($i).getPartnerType() </td>
62
            <td class="toggle-cell">
63
                <i class="fa fa-angle-down dropdown-icon"
64
                   style="cursor:pointer; font-size: 27px;width: 27px;height: 27px;margin-top: 0px;color: rgba(255, 255, 255, 0.75);line-height: 27px;"></i>
65
            </td>
66
        </tr>
67
 
68
        <tr class="brand-wise-sale-row cursor-pointer" style="display: none;">
69
            <td colspan="6">
35084 aman 70
                <!-- Added table-striped and nested-table-striped classes -->
71
                <table class="table table-striped nested-table-striped brand-wise-table">
35064 aman 72
                    <thead>
73
                    <tr>
74
                        <th>Brand</th>
75
                        <th>LMS</th>
76
                        <th>LMTD</th>
77
                        <th>MTD</th>
78
                        <th>MTDQTY</th>
79
                        <th></th>
80
                    </tr>
81
                    </thead>
82
                    <tbody class="brandWiseBody">
83
                    </tbody>
84
                </table>
85
            </td>
86
        </tr>
87
        <tr class="brand-item-wise-sale-row cursor-pointer" style="display: none;">
88
            <td colspan="6">
35084 aman 89
                <!-- Added table-striped and nested-table-striped classes -->
90
                <table class="table table-striped nested-table-striped brand-wise-table">
35064 aman 91
                    <thead>
92
                    <tr>
93
                        <th>Model</th>
94
                        <th>Quantity</th>
95
                    </tr>
96
                    </thead>
97
                    <tbody class="brandItemWiseBody">
98
                    </tbody>
99
                </table>
100
            </td>
101
        </tr>
102
        #end
103
    </tbody>
104
</table>
105
 
106
<script>
107
    function getCookie(name) {
108
        const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
109
        if (match) {
110
            return decodeURIComponent(match[2]);
111
        }
112
        return null;
113
    }
114
 
115
    document.querySelectorAll('.clickable-row').forEach(function (row) {
116
        row.addEventListener('click', function () {
117
            const brandWiseRow = row.nextElementSibling;
118
            const allBrandWiseRows = document.querySelectorAll('.brand-wise-sale-row');
119
            const fofoId = getCookie("fofoId");
35084 aman 120
 
35064 aman 121
            allBrandWiseRows.forEach(function (otherRow) {
122
                if (otherRow !== brandWiseRow) {
123
                    otherRow.style.display = 'none';
35084 aman 124
                    const brandItemRows = otherRow.parentNode.querySelectorAll('.brand-item-wise-sale-row');
125
                    brandItemRows.forEach(itemRow => itemRow.style.display = 'none');
35064 aman 126
                }
127
            });
128
 
129
            let monthString = row.getAttribute('data-month');
130
            const monthMap = {
131
                'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4,
132
                'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8,
133
                'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12
134
            };
135
 
136
            const monthAbbr = monthString.substring(0, 3);
137
            const monthNumber = monthMap[monthAbbr];
138
 
139
            if (!monthNumber) {
140
                console.error('Invalid month:', monthString);
141
                return;
142
            }
143
 
35084 aman 144
            // Toggle the brand-wise row
35064 aman 145
            if (brandWiseRow.style.display === 'none') {
146
                brandWiseRow.style.display = '';
147
 
148
                doGetAjaxRequestHandler(
35084 aman 149
                        `getBrandwisePartnerSale?month=${monthNumber}`,
35064 aman 150
                        function (response) {
151
                            const brandBody = brandWiseRow.querySelector('.brandWiseBody');
152
                            brandBody.innerHTML = '';
153
 
154
                            response.forEach(function (item) {
155
                                const safe = (val) => (val == null || val === "null" ? 0 : val);
156
                                const brandRow = document.createElement('tr');
157
                                brandRow.classList.add('clickable-brandrow');
35084 aman 158
                                brandRow.setAttribute('data-brand', item.brand);
35064 aman 159
                                brandRow.innerHTML =
160
                                        '<td><b>' + safe(item.brand) + '</b></td>' +
161
                                        '<td>' + safe(item.lms) + '</td>' +
162
                                        '<td>' + safe(item.lmtd) + '</td>' +
163
                                        '<td>' + safe(item.mtd) + '</td>' +
164
                                        '<td>' + safe(item.mtdQty) + '</td>' +
35084 aman 165
                                        '<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>';
166
 
35064 aman 167
                                brandRow.addEventListener('click', function () {
168
                                    const brandName = item.brand;
169
 
170
                                    let brandItemWiseRow = brandRow.nextElementSibling;
171
                                    if (!brandItemWiseRow || !brandItemWiseRow.classList.contains('brand-item-wise-sale-row')) {
172
                                        brandItemWiseRow = document.createElement('tr');
173
                                        brandItemWiseRow.classList.add('brand-item-wise-sale-row');
35084 aman 174
                                        brandItemWiseRow.style.display = 'none';
35064 aman 175
                                        brandItemWiseRow.innerHTML = `
35084 aman 176
                <td colspan="6">
177
                    <table class="table table-striped nested-table-striped brand-wise-table">
178
                        <thead>
179
                            <tr>
180
                                <th>Model</th>
181
                                <th>Quantity</th>
182
                            </tr>
183
                        </thead>
184
                        <tbody class="brandItemWiseBody"></tbody>
185
                    </table>
186
                </td>
187
            `;
35064 aman 188
                                        brandRow.insertAdjacentElement('afterend', brandItemWiseRow);
189
                                    }
190
 
35084 aman 191
                                    // Hide all other brand-item-wise rows
192
                                    const allBrandItemWiseRows = document.querySelectorAll('.brand-item-wise-sale-row');
193
                                    allBrandItemWiseRows.forEach(function (otherRow) {
194
                                        if (otherRow !== brandItemWiseRow) {
195
                                            otherRow.style.display = 'none';
196
                                        }
197
                                    });
35064 aman 198
 
35084 aman 199
                                    // Toggle current row - same logic as month rows
200
                                    if (brandItemWiseRow.style.display === 'none') {
35064 aman 201
                                        brandItemWiseRow.style.display = '';
202
                                        doGetAjaxRequestHandler(
35084 aman 203
                                                'getBrandItemwisePartnerSale?month=' + monthNumber + '&brand=' + encodeURIComponent(brandName) + '&fofoId=' + encodeURIComponent(fofoId),
35064 aman 204
                                                function (response) {
205
                                                    const tbody = brandItemWiseRow.querySelector('.brandItemWiseBody');
206
                                                    tbody.innerHTML = '';
207
                                                    response.forEach(item => {
208
                                                        const tr = document.createElement('tr');
209
                                                        tr.innerHTML =
35084 aman 210
                                                                '<td>' + item.modelName + item.modelNumber + '</td>' +
211
                                                                '<td>' + item.quantity + " pcs" + '</td>';
35064 aman 212
                                                        tbody.appendChild(tr);
213
                                                    });
214
                                                }
215
                                        );
35084 aman 216
                                    } else {
217
                                        brandItemWiseRow.style.display = 'none';
35064 aman 218
                                    }
219
                                });
220
 
221
                                brandBody.appendChild(brandRow);
222
                            });
223
                        }
224
                );
225
            } else {
226
                brandWiseRow.style.display = 'none';
35084 aman 227
                const brandItemRows = brandWiseRow.parentNode.querySelectorAll('.brand-item-wise-sale-row');
228
                brandItemRows.forEach(itemRow => itemRow.style.display = 'none');
35064 aman 229
            }
230
        });
231
    });
35084 aman 232
</script>