chart.js
1 month ago
chart.min.js
1 month ago
digital-files-chooser.js
1 month ago
fusewp.js
1 month ago
index.php
1 month ago
license.js
1 month ago
login-redirect.js
1 month ago
reports.js
1 month ago
reports.min.js
1 month ago
tax-rate-repeater.js
1 month ago
reports.js
298 lines
| 1 | (function ($) { |
| 2 | |
| 3 | function format_amount(amount) { |
| 4 | return currencySymbol.replace(/[0-9.,]+/, amount); |
| 5 | } |
| 6 | |
| 7 | $(window).on('load', function () { |
| 8 | |
| 9 | if (document.getElementById('ppress-report-revenue')) { |
| 10 | |
| 11 | $('#ppress-mode-filter select').on('change', function () { |
| 12 | $('#ppress-date-filters').toggle(this.value === 'custom'); |
| 13 | }).trigger('change'); |
| 14 | |
| 15 | const revenueConfig = { |
| 16 | type: 'line', |
| 17 | data: { |
| 18 | labels: revenueStat.label, |
| 19 | datasets: revenueStat.dataset |
| 20 | }, |
| 21 | options: { |
| 22 | responsive: true, |
| 23 | interaction: { |
| 24 | mode: 'index', |
| 25 | intersect: false, |
| 26 | }, |
| 27 | stacked: false, |
| 28 | scales: { |
| 29 | y: { |
| 30 | type: 'linear', |
| 31 | display: true, |
| 32 | position: 'left', |
| 33 | // https://www.chartjs.org/docs/latest/samples/scale-options/ticks.html |
| 34 | ticks: { |
| 35 | // Include a dollar sign in the ticks |
| 36 | callback: function (value, index, ticks) { |
| 37 | return format_amount(value); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | }, |
| 42 | plugins: { |
| 43 | tooltip: { |
| 44 | callbacks: { |
| 45 | label: function (context) { |
| 46 | let label = context.dataset.label || ''; |
| 47 | |
| 48 | if (label) { |
| 49 | label += ': '; |
| 50 | } |
| 51 | if (context.parsed.y !== null) { |
| 52 | label += format_amount(context.parsed.y); |
| 53 | } |
| 54 | return label; |
| 55 | } |
| 56 | } |
| 57 | }, |
| 58 | legend: { |
| 59 | display: false |
| 60 | } |
| 61 | } |
| 62 | }, |
| 63 | }; |
| 64 | |
| 65 | const taxesConfig = { |
| 66 | type: 'line', |
| 67 | data: { |
| 68 | labels: taxesStat.label, |
| 69 | datasets: taxesStat.dataset |
| 70 | }, |
| 71 | options: { |
| 72 | responsive: true, |
| 73 | interaction: { |
| 74 | mode: 'index', |
| 75 | intersect: false, |
| 76 | }, |
| 77 | stacked: false, |
| 78 | scales: { |
| 79 | y: { |
| 80 | type: 'linear', |
| 81 | display: true, |
| 82 | position: 'left', |
| 83 | // https://www.chartjs.org/docs/latest/samples/scale-options/ticks.html |
| 84 | ticks: { |
| 85 | // Include a dollar sign in the ticks |
| 86 | callback: function (value, index, ticks) { |
| 87 | return format_amount(value); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | }, |
| 92 | plugins: { |
| 93 | tooltip: { |
| 94 | callbacks: { |
| 95 | label: function (context) { |
| 96 | let label = context.dataset.label || ''; |
| 97 | |
| 98 | if (label) { |
| 99 | label += ': '; |
| 100 | } |
| 101 | if (context.parsed.y !== null) { |
| 102 | label += format_amount(context.parsed.y); |
| 103 | } |
| 104 | return label; |
| 105 | } |
| 106 | } |
| 107 | }, |
| 108 | legend: { |
| 109 | display: false |
| 110 | } |
| 111 | } |
| 112 | }, |
| 113 | }; |
| 114 | |
| 115 | const ordersConfig = { |
| 116 | type: 'line', |
| 117 | data: { |
| 118 | labels: orderStat.label, |
| 119 | datasets: orderStat.dataset |
| 120 | }, |
| 121 | options: { |
| 122 | responsive: true, |
| 123 | interaction: { |
| 124 | mode: 'index', |
| 125 | intersect: false, |
| 126 | }, |
| 127 | stacked: false, |
| 128 | scales: { |
| 129 | y: { |
| 130 | type: 'linear', |
| 131 | position: 'left', |
| 132 | } |
| 133 | } |
| 134 | }, |
| 135 | }; |
| 136 | |
| 137 | const refundConfig = { |
| 138 | type: 'line', |
| 139 | data: { |
| 140 | labels: refundStat.label, |
| 141 | datasets: refundStat.dataset |
| 142 | }, |
| 143 | options: { |
| 144 | responsive: true, |
| 145 | interaction: { |
| 146 | mode: 'index', |
| 147 | intersect: false, |
| 148 | }, |
| 149 | stacked: false, |
| 150 | scales: { |
| 151 | y: { |
| 152 | type: 'linear', |
| 153 | display: true, |
| 154 | position: 'left', |
| 155 | } |
| 156 | }, |
| 157 | plugins: { |
| 158 | legend: { |
| 159 | display: false |
| 160 | } |
| 161 | } |
| 162 | }, |
| 163 | }; |
| 164 | |
| 165 | const topPlanConfig = { |
| 166 | type: 'line', |
| 167 | data: { |
| 168 | labels: topPlansStat.label, |
| 169 | datasets: topPlansStat.dataset |
| 170 | }, |
| 171 | options: { |
| 172 | responsive: true, |
| 173 | interaction: { |
| 174 | mode: 'index', |
| 175 | intersect: false, |
| 176 | }, |
| 177 | stacked: false, |
| 178 | scales: { |
| 179 | y: { |
| 180 | type: 'linear', |
| 181 | stacked: true, |
| 182 | position: 'left', |
| 183 | }, |
| 184 | y1: { |
| 185 | type: 'linear', |
| 186 | position: 'right', |
| 187 | // grid line settings |
| 188 | grid: { |
| 189 | drawOnChartArea: false, // only want the grid lines for one axis to show up |
| 190 | }, |
| 191 | ticks: { |
| 192 | // Include a dollar sign in the ticks |
| 193 | callback: function (value, index, ticks) { |
| 194 | return format_amount(value); |
| 195 | } |
| 196 | } |
| 197 | }, |
| 198 | }, |
| 199 | plugins: { |
| 200 | tooltip: { |
| 201 | callbacks: { |
| 202 | label: function (context) { |
| 203 | let label = context.dataset.label || ''; |
| 204 | |
| 205 | if (label) label += ': '; |
| 206 | |
| 207 | if (context.parsed.y !== null) { |
| 208 | |
| 209 | if (context.dataset.borderColor === 'rgb(255, 99, 132)') { |
| 210 | label += format_amount(context.parsed.y); |
| 211 | } else { |
| 212 | label += context.parsed.y; |
| 213 | } |
| 214 | } |
| 215 | return label; |
| 216 | } |
| 217 | } |
| 218 | }, |
| 219 | legend: { |
| 220 | display: false |
| 221 | } |
| 222 | } |
| 223 | }, |
| 224 | }; |
| 225 | |
| 226 | const paymentMethodsConfig = { |
| 227 | type: 'line', |
| 228 | data: { |
| 229 | labels: paymentMethodsStat.label, |
| 230 | datasets: paymentMethodsStat.dataset |
| 231 | }, |
| 232 | options: { |
| 233 | responsive: true, |
| 234 | interaction: { |
| 235 | mode: 'index', |
| 236 | intersect: false, |
| 237 | }, |
| 238 | stacked: false, |
| 239 | scales: { |
| 240 | y: { |
| 241 | type: 'linear', |
| 242 | stacked: true, |
| 243 | position: 'left', |
| 244 | }, |
| 245 | y1: { |
| 246 | type: 'linear', |
| 247 | position: 'right', |
| 248 | // grid line settings |
| 249 | grid: { |
| 250 | drawOnChartArea: false, // only want the grid lines for one axis to show up |
| 251 | }, |
| 252 | ticks: { |
| 253 | // Include a dollar sign in the ticks |
| 254 | callback: function (value, index, ticks) { |
| 255 | return format_amount(value); |
| 256 | } |
| 257 | } |
| 258 | }, |
| 259 | }, |
| 260 | plugins: { |
| 261 | tooltip: { |
| 262 | callbacks: { |
| 263 | label: function (context) { |
| 264 | let label = context.dataset.label || ''; |
| 265 | |
| 266 | if (label) label += ': '; |
| 267 | |
| 268 | if (context.parsed.y !== null) { |
| 269 | |
| 270 | if (context.dataset.borderColor === 'rgb(255, 99, 132)') { |
| 271 | label += format_amount(context.parsed.y); |
| 272 | } else { |
| 273 | label += context.parsed.y; |
| 274 | } |
| 275 | } |
| 276 | return label; |
| 277 | } |
| 278 | } |
| 279 | }, |
| 280 | legend: { |
| 281 | display: false |
| 282 | } |
| 283 | } |
| 284 | }, |
| 285 | }; |
| 286 | |
| 287 | new Chart(document.getElementById('ppress-report-revenue'), revenueConfig); |
| 288 | new Chart(document.getElementById('ppress-report-orders'), ordersConfig); |
| 289 | if ($('#ppress-report-tax').length > 0) { |
| 290 | new Chart(document.getElementById('ppress-report-tax'), taxesConfig); |
| 291 | } |
| 292 | new Chart(document.getElementById('ppress-report-refunds'), refundConfig); |
| 293 | new Chart(document.getElementById('ppress-report-top-plans'), topPlanConfig); |
| 294 | new Chart(document.getElementById('ppress-report-payment-methods'), paymentMethodsConfig); |
| 295 | } |
| 296 | }); |
| 297 | |
| 298 | })(jQuery); |