Subversion Repositories SmartDukaan

Rev

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