Sha256: 19a2ca5c1ef940675e3f2a99b4f0a94c81544fc6266a4411ebc039ad44d98fbc

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

class Spree::PaymentMethodTransactionsReport::PaymentMethodRevenueDistributionChart
  def initialize(result)
    @time_dimension = result.time_dimension
    @grouped_by_payment_method = result.observations.group_by(&:payment_method_name)
    @time_series = []
    if @grouped_by_payment_method.values.first.present?
      @time_series = @grouped_by_payment_method.values.first.collect { |observation| observation.send(@time_dimension) }
    end
  end

  def to_h
    {
      id: 'payment-methods',
      json: {
        chart: { type: 'column' },
        title: {
          useHTML: true,
          text: "<span class='chart-title'>Payment Methods</span><span class='fa fa-question-circle' data-toggle='tooltip' title=' Compare the revenue generated by different Payment methods such as CC, Check etc.'></span>"
        },
        xAxis: { categories: @time_series },
        yAxis: {
          title: { text: 'value($)' }
        },
        tooltip: { valuePrefix: '$' },
        legend: {
          layout: 'vertical',
          align: 'right',
          verticalAlign: 'middle',
          borderWidth: 0
        },
        series: @grouped_by_payment_method.collect { |key, value| { name: key, data: value.map(&:payment_amount) }
        }
      }
    }
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
spree_admin_insights-3.2.0 app/reports/spree/payment_method_transactions_report/payment_method_revenue_distribution_chart.rb
solidus_admin_insights-2.1.1 app/reports/spree/payment_method_transactions_report/payment_method_revenue_distribution_chart.rb
solidus_admin_insights-2.1.0 app/reports/spree/payment_method_transactions_report/payment_method_revenue_distribution_chart.rb