Module: Crm::Reports::LeadReportHelper
- Defined in:
- app/helpers/crm/reports/lead_report_helper.rb
Overview
View helpers for the CRM lead report: tab URLs, variance/trend indicators,
comparison bars, period legends, and Highcharts configuration hashes.
Instance Method Summary collapse
-
#lead_bar_chart_config(current_value:, previous_value:, height: 100) ⇒ Hash
Builds a Highcharts horizontal bar comparison chart config.
-
#lead_comparison_bars(current_value, previous_value) ⇒ ActiveSupport::SafeBuffer
Renders a CSS progress-bar comparison of two values (replaces the Highcharts bar chart).
-
#lead_dual_axis_chart_config(categories:, column_data:, column_name:, spline_data:, spline_name:, value_prefix: "$", height: 280) ⇒ Hash
Builds a dual-axis column+spline chart (e.g. won opps count + amount on same timeline).
-
#lead_multi_series_chart_config(categories:, series:, title: "", y_axis_title: "", height: 240) ⇒ Hash
Builds a multi-series areaspline stacked chart (e.g. website traffic sources).
-
#lead_period_legend(start_date, end_date, compare_start_date, compare_end_date) ⇒ ActiveSupport::SafeBuffer
Renders the period legend bar used at the top of each tab.
-
#lead_report_tab_options ⇒ Hash{Symbol => Hash}
Builds the tab navigation options for the lead report, preserving the current
params[:command]filter in each tab's remote URL. -
#lead_spline_chart_config(categories:, labels_current:, labels_previous:, current_data:, previous_data:, height: 325) ⇒ Hash
Builds a Highcharts spline chart configuration as a Ruby hash (for JSON serialization).
-
#lead_trend_icon(value, inverse: false) ⇒ String
Renders a trend icon (up/down/flat) for KPI header labels.
-
#lead_trend_icon_lg(value, inverse: false) ⇒ String
Large variant of lead_trend_icon for standalone display above KPI labels.
-
#lead_variance_badge(value, inverse: false) ⇒ ActiveSupport::SafeBuffer
Renders a styled variance badge with percentage and icon.
-
#lead_variance_icon(value, inverse: false, size: "sm") ⇒ String
Renders a Font Awesome variance indicator icon based on a numeric value.
Instance Method Details
#lead_bar_chart_config(current_value:, previous_value:, height: 100) ⇒ Hash
Builds a Highcharts horizontal bar comparison chart config.
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 302 def (current_value:, previous_value:, height: 100) { chart: { type: "bar", backgroundColor: "transparent", style: { fontFamily: "inherit" }, height: height }, title: { text: "" }, subtitle: { text: "" }, xAxis: { categories: [""], visible: false }, yAxis: { visible: false }, plotOptions: { bar: { dataLabels: { enabled: true, style: { fontWeight: "600" } }, borderRadius: 4 } }, legend: { align: "center", verticalAlign: "bottom", floating: true, y: -5, itemStyle: { fontSize: "11px", fontWeight: "normal" } }, exporting: { enabled: false }, credits: { enabled: false }, series: [ { name: "Previous", color: "#fd7e14", data: [previous_value] }, { name: "Current", color: "#0d6efd", data: [current_value] } ] } end |
#lead_comparison_bars(current_value, previous_value) ⇒ ActiveSupport::SafeBuffer
Renders a CSS progress-bar comparison of two values (replaces the Highcharts bar chart).
Shows current vs previous as horizontal bars with labels.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 138 def (current_value, previous_value) current = current_value.to_f previous = previous_value.to_f max_val = [current, previous, 1].max # avoid division by zero current_pct = (current / max_val * 100).round(1) previous_pct = (previous / max_val * 100).round(1) content_tag(:div, class: "lead-comparison-bars") do = content_tag(:div, class: "lead-comparison-row mb-2") do content_tag(:div, class: "d-flex align-items-center gap-2") do content_tag(:span, "Current", class: "lead-comparison-label") + content_tag(:div, class: "flex-grow-1") do content_tag(:div, class: "progress", style: "height: 22px;") do content_tag(:div, values_format_without_symbol(current_value), class: "progress-bar", style: "width: #{current_pct}%; background-color: #0d6efd;", role: "progressbar") end end end end = content_tag(:div, class: "lead-comparison-row") do content_tag(:div, class: "d-flex align-items-center gap-2") do content_tag(:span, "Previous", class: "lead-comparison-label") + content_tag(:div, class: "flex-grow-1") do content_tag(:div, class: "progress", style: "height: 22px;") do content_tag(:div, values_format_without_symbol(previous_value), class: "progress-bar", style: "width: #{previous_pct}%; background-color: #fd7e14;", role: "progressbar") end end end end safe_join([, ]) end end |
#lead_dual_axis_chart_config(categories:, column_data:, column_name:, spline_data:, spline_name:, value_prefix: "$", height: 280) ⇒ Hash
Builds a dual-axis column+spline chart (e.g. won opps count + amount on same timeline).
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 408 def lead_dual_axis_chart_config(categories:, column_data:, column_name:, spline_data:, spline_name:, value_prefix: "$", height: 280) { chart: { zoomType: "xy", backgroundColor: "transparent", style: { fontFamily: "inherit" }, height: height }, title: { text: "" }, subtitle: { text: "" }, xAxis: [{ categories: categories, crosshair: true, labels: { rotation: -45, style: { fontSize: "10px", color: "#6c757d" } }, tickInterval: categories.length > 20 ? 2 : 1 }], yAxis: [ { title: { text: "Amount (#{value_prefix})", style: { fontSize: "11px", color: "#6c757d" } }, gridLineColor: "#e9ecef", labels: { style: { color: "#6c757d" } } }, { title: { text: column_name, style: { fontSize: "11px", color: "#6c757d" } }, opposite: true, gridLineColor: "#e9ecef", labels: { style: { color: "#6c757d" } } } ], tooltip: { shared: true, backgroundColor: "rgba(255,255,255,0.96)", borderColor: "#dee2e6", borderRadius: 8, shadow: true, style: { fontSize: "12px" } }, legend: { layout: "horizontal", align: "left", verticalAlign: "top", itemStyle: { fontWeight: "normal", color: "#495057" } }, credits: { enabled: false }, plotOptions: { column: { borderRadius: 4 }, series: { animation: { duration: 600 } } }, series: [ { name: column_name, type: "column", color: "#0d6efd", yAxis: 1, data: column_data }, { name: spline_name, type: "spline", dashStyle: "ShortDash", color: "#212529", lineWidth: 2, data: spline_data, tooltip: { valuePrefix: value_prefix } } ] } end |
#lead_multi_series_chart_config(categories:, series:, title: "", y_axis_title: "", height: 240) ⇒ Hash
Builds a multi-series areaspline stacked chart (e.g. website traffic sources).
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 344 def lead_multi_series_chart_config(categories:, series:, title: "", y_axis_title: "", height: 240) { chart: { type: "areaspline", backgroundColor: "transparent", style: { fontFamily: "inherit" }, height: height }, title: { text: title, style: { fontSize: "14px", fontWeight: "600", color: "#212529" } }, xAxis: { categories: categories, crosshair: true, labels: { rotation: -45, style: { fontSize: "10px", color: "#6c757d" } }, tickInterval: categories.length > 20 ? 2 : 1 }, yAxis: { title: { text: y_axis_title, style: { fontSize: "11px", color: "#6c757d" } }, gridLineColor: "#e9ecef", labels: { style: { fontSize: "11px", color: "#6c757d" } } }, legend: { align: "center", verticalAlign: "bottom", itemStyle: { fontSize: "11px", fontWeight: "normal" } }, tooltip: { shared: true, backgroundColor: "rgba(255,255,255,0.96)", borderColor: "#dee2e6", borderRadius: 8, shadow: true, style: { fontSize: "12px" } }, plotOptions: { areaspline: { fillOpacity: 0.15, lineWidth: 2, marker: { radius: 2.5 } }, series: { animation: { duration: 600 } } }, series: series, credits: { enabled: false }, responsive: { rules: [{ condition: { maxWidth: 500 }, chartOptions: { legend: { layout: "horizontal", align: "center", verticalAlign: "bottom" } } }] } } end |
#lead_period_legend(start_date, end_date, compare_start_date, compare_end_date) ⇒ ActiveSupport::SafeBuffer
Renders the period legend bar used at the top of each tab.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 186 def lead_period_legend(start_date, end_date, compare_start_date, compare_end_date) content_tag(:div, class: "lead-report-period-legend d-flex flex-wrap gap-4 p-3 mb-4 bg-light rounded-3 border") do current_label = content_tag(:div, class: "d-flex align-items-center gap-2") do content_tag(:span, "", class: "lead-report-dot lead-report-dot--current") + content_tag(:span, class: "text-body-secondary") do safe_join([ "Current: ", content_tag(:strong, "#{start_date.strftime('%b %d, %Y')} — #{end_date.strftime('%b %d, %Y')}") ]) end end compare_label = content_tag(:div, class: "d-flex align-items-center gap-2") do content_tag(:span, "", class: "lead-report-dot lead-report-dot--previous") + content_tag(:span, class: "text-body-secondary") do safe_join([ "Previous: ", content_tag(:strong, "#{compare_start_date.strftime('%b %d, %Y')} — #{compare_end_date.strftime('%b %d, %Y')}") ]) end end safe_join([current_label, compare_label]) end end |
#lead_report_tab_options ⇒ Hash{Symbol => Hash}
Builds the tab navigation options for the lead report, preserving the
current params[:command] filter in each tab's remote URL.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 12 def params[:command] ||= {} hsh = {} tabs = { customers_created: :reports_lead_report_tab_customers_created, opportunities: :reports_lead_report_tab_opportunities, orders: :reports_lead_report_tab_orders, services: :reports_lead_report_tab_services, rooms_created: :reports_lead_report_tab_rooms_created, calls_in_out: :reports_lead_report_tab_calls_in_out, communications: :reports_lead_report_tab_communications, sms: :reports_lead_report_tab_sms, website_visits: :reports_lead_report_tab_website_visits } tabs.each do |tab_id, route_name| hsh[tab_id] = { remote_href: send("#{route_name}_path", command: params[:command]) } end hsh end |
#lead_spline_chart_config(categories:, labels_current:, labels_previous:, current_data:, previous_data:, height: 325) ⇒ Hash
Builds a Highcharts spline chart configuration as a Ruby hash (for JSON serialization).
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 221 def lead_spline_chart_config(categories:, labels_current:, labels_previous:, current_data:, previous_data:, height: 325) # rubocop:disable Lint/UnusedMethodArgument { chart: { type: "spline", backgroundColor: "transparent", style: { fontFamily: "inherit" }, height: height }, title: { text: "" }, subtitle: { text: "" }, xAxis: { categories: categories, crosshair: true, labels: { rotation: -45, style: { fontSize: "10px", color: "#6c757d" } }, tickInterval: categories.length > 20 ? 2 : 1 }, yAxis: { title: { text: "" }, gridLineColor: "#e9ecef", labels: { style: { color: "#6c757d" } } }, legend: { layout: "horizontal", align: "right", verticalAlign: "top", itemStyle: { fontWeight: "normal", color: "#495057" } }, tooltip: { shared: true, backgroundColor: "rgba(255,255,255,0.96)", borderColor: "#dee2e6", borderRadius: 8, shadow: true, style: { fontSize: "12px" }, useHTML: true }, plotOptions: { series: { animation: { duration: 600 } } }, series: [ { name: "Current", color: "#0d6efd", type: "areaspline", fillOpacity: 0.12, lineWidth: 2, marker: { radius: 3, symbol: "circle" }, data: current_data }, { name: "Previous", color: "#fd7e14", lineWidth: 2, dashStyle: "ShortDash", marker: { radius: 3, symbol: "circle" }, data: previous_data } ], credits: { enabled: false }, responsive: { rules: [{ condition: { maxWidth: 500 }, chartOptions: { legend: { layout: "horizontal", align: "center", verticalAlign: "bottom" } } }] } } end |
#lead_trend_icon(value, inverse: false) ⇒ String
Renders a trend icon (up/down/flat) for KPI header labels.
Uses fa-arrow-trend-up / fa-arrow-trend-down for a visual-friendly look.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 67 def lead_trend_icon(value, inverse: false) return "" unless value rounded = value.respond_to?(:round) ? value.round(2) : value.to_f.round(2) if rounded.positive? css = inverse ? "text-danger" : "text-success" fa_icon("arrow-trend-up", family: :solid, class: "#{css} opacity-50 me-1") elsif rounded.zero? fa_icon("minus", family: :solid, class: "text-warning opacity-50 me-1") else css = inverse ? "text-success" : "text-danger" fa_icon("arrow-trend-down", family: :solid, class: "#{css} opacity-50 me-1") end end |
#lead_trend_icon_lg(value, inverse: false) ⇒ String
Large variant of lead_trend_icon for standalone display above KPI labels.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 89 def lead_trend_icon_lg(value, inverse: false) return "" unless value rounded = value.respond_to?(:round) ? value.round(2) : value.to_f.round(2) if rounded.positive? css = inverse ? "text-danger" : "text-success" fa_icon("arrow-trend-up", family: :solid, class: "#{css} opacity-50 fa-2x") elsif rounded.zero? fa_icon("minus", family: :solid, class: "text-warning opacity-50 fa-2x") else css = inverse ? "text-success" : "text-danger" fa_icon("arrow-trend-down", family: :solid, class: "#{css} opacity-50 fa-2x") end end |
#lead_variance_badge(value, inverse: false) ⇒ ActiveSupport::SafeBuffer
Renders a styled variance badge with percentage and icon.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 111 def lead_variance_badge(value, inverse: false) return content_tag(:span, "--", class: "text-body-secondary") unless value rounded = value.respond_to?(:round) ? value.round(1) : value.to_f.round(1) css = if rounded.positive? inverse ? "text-danger" : "text-success" elsif rounded.negative? inverse ? "text-success" : "text-danger" else "text-body-secondary" end content_tag(:span, class: "fw-semibold #{css}") do safe_join([ content_tag(:span, "#{rounded}%"), " ", lead_variance_icon(rounded, inverse: inverse) ]) end end |
#lead_variance_icon(value, inverse: false, size: "sm") ⇒ String
Renders a Font Awesome variance indicator icon based on a numeric value.
Positive = green arrow up, Zero = yellow dash, Negative = red arrow down.
Pass inverse: true for metrics where decrease is good (e.g. time to convert, lost opps).
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/crm/reports/lead_report_helper.rb', line 40 def lead_variance_icon(value, inverse: false, size: "sm") return "" unless value rounded = value.respond_to?(:round) ? value.round(2) : value.to_f.round(2) icon_size = size == "lg" ? "fa-lg" : "" if rounded.positive? if inverse fa_icon("arrow-up", family: :solid, class: "text-danger #{icon_size}") else fa_icon("arrow-up", family: :solid, class: "text-success #{icon_size}") end elsif rounded.zero? fa_icon("minus", family: :solid, class: "text-warning #{icon_size}") elsif inverse fa_icon("arrow-down", family: :solid, class: "text-success #{icon_size}") else fa_icon("arrow-down", family: :solid, class: "text-danger #{icon_size}") end end |