openfoodfoundation/openfoodnetwork

View on GitHub
lib/reporting/reports/packing/customer.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module Reporting
  module Reports
    module Packing
      class Customer < Base
        def table_columns
          Struct.new(:keys).new(
            [:hub, :customer_code, :first_name, :last_name, :phone, :supplier, :product,
             :variant, :weight, :height, :width, :depth, :quantity, :price, :temp_controlled]
          )
        end

        def columns
          # Reorder default columns
          super.slice(*table_columns.keys)
        end

        def rules
          [
            {
              group_by: :hub,
              header: true,
              header_class: "h1 with-background text-center",
            },
            {
              group_by: proc { |_item, row| row_header(row) },
              header: true,
              fields_used_in_header: [:first_name, :last_name, :customer_code, :phone],
              summary_row:,
            }
          ]
        end

        def ordering_fields
          lambda do
            [
              distributor_alias[:name],
              bill_address_alias[:lastname],
              order_table[:id],
              Arel.sql("supplier"),
              Arel.sql("product"),
              Arel.sql("variant"),
            ]
          end
        end
      end
    end
  end
end