effective_orders 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9e77f25b6d0e0a68b65f915274bac55854e97671
         | 
| 4 | 
            +
              data.tar.gz: a7b178984581033d45d4bebacc8be65700b9609b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9049fbc41f9edb0792e992b1376ce845f28c73499d3764972a665abbb1faf94f775d2b7eb763270b96bdf7423e1877d5d013ed8df533887020df3f25700914a9
         | 
| 7 | 
            +
              data.tar.gz: 3f89d86ee7cdc7ef9e479805d08962df11ae7e239058154a1e7baa3f90d847892dc7b04c4f3b47169ad5be3df8df0168a886d12bdf85228dfc723479f291055a
         | 
| @@ -2,43 +2,36 @@ if defined?(EffectiveDatatables) | |
| 2 2 | 
             
              module Effective
         | 
| 3 3 | 
             
                module Datatables
         | 
| 4 4 | 
             
                  class Customers < Effective::Datatable
         | 
| 5 | 
            -
                     | 
| 6 | 
            -
             | 
| 7 | 
            -
                     | 
| 5 | 
            +
                    default_order :email, :asc
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                    table_column :id, visible: false
         | 
| 8 | 
            +
                    table_column(:email, column: 'users.email') { |user| mail_to user.email, user.email }
         | 
| 8 9 |  | 
| 9 10 | 
             
                    if EffectiveOrders.stripe_enabled
         | 
| 10 | 
            -
                      table_column :stripe_customer_id | 
| 11 | 
            +
                      table_column :stripe_customer_id
         | 
| 11 12 | 
             
                      table_column :stripe_active_card
         | 
| 12 13 | 
             
                    end
         | 
| 13 14 |  | 
| 14 15 | 
             
                    if EffectiveOrders.stripe_connect_enabled
         | 
| 15 | 
            -
                      table_column :stripe_connect_access_token | 
| 16 | 
            +
                      table_column :stripe_connect_access_token
         | 
| 16 17 | 
             
                    end
         | 
| 17 18 |  | 
| 18 | 
            -
                    table_column :subscription_types, : | 
| 19 | 
            +
                    table_column :subscription_types, column: 'subscription_types'
         | 
| 19 20 |  | 
| 20 | 
            -
                    table_column :actions, : | 
| 21 | 
            +
                    table_column :actions, sortable: false, filter: false, partial: '/admin/customers/actions'
         | 
| 21 22 |  | 
| 22 23 | 
             
                    def collection
         | 
| 23 24 | 
             
                      Effective::Customer.customers.uniq
         | 
| 24 | 
            -
                        .joins(:user)
         | 
| 25 | 
            -
                        . | 
| 26 | 
            -
                        .select('customers.*')
         | 
| 27 | 
            -
                        .select('users.email AS email')
         | 
| 25 | 
            +
                        .joins(:user, :subscriptions)
         | 
| 26 | 
            +
                        .select('customers.*, users.email AS email')
         | 
| 28 27 | 
             
                        .select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
         | 
| 29 | 
            -
                        .group('customers.id')
         | 
| 30 | 
            -
                        .group('subscriptions.stripe_plan_id')
         | 
| 31 | 
            -
                        .group('users.email')
         | 
| 28 | 
            +
                        .group('customers.id, subscriptions.stripe_plan_id, users.email')
         | 
| 32 29 | 
             
                    end
         | 
| 33 30 |  | 
| 34 31 | 
             
                    def search_column(collection, table_column, search_term)
         | 
| 35 | 
            -
                      if table_column[:name] == 'subscription_types'
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                      else
         | 
| 38 | 
            -
                        super
         | 
| 39 | 
            -
                      end
         | 
| 32 | 
            +
                      return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
         | 
| 33 | 
            +
                      super
         | 
| 40 34 | 
             
                    end
         | 
| 41 | 
            -
             | 
| 42 35 | 
             
                  end
         | 
| 43 36 | 
             
                end
         | 
| 44 37 | 
             
              end
         | 
| @@ -4,80 +4,70 @@ if defined?(EffectiveDatatables) | |
| 4 4 | 
             
                  class Orders < Effective::Datatable
         | 
| 5 5 | 
             
                    default_order :purchased_at, :desc
         | 
| 6 6 |  | 
| 7 | 
            +
                    table_column(:purchased_at) { |order| order.purchased_at.try(:strftime, '%Y-%m-%d %H:%M') }
         | 
| 7 8 | 
             
                    table_column :id
         | 
| 8 9 |  | 
| 9 | 
            -
                    table_column :email, : | 
| 10 | 
            +
                    table_column :email, column: 'users.email', label: 'Buyer Email', if: proc { attributes[:user_id].blank? } do |order|
         | 
| 10 11 | 
             
                      link_to order[:email], (edit_admin_user_path(order.user_id) rescue admin_user_path(order.user_id) rescue '#')
         | 
| 11 12 | 
             
                    end
         | 
| 12 13 |  | 
| 13 14 | 
             
                    if EffectiveOrders.require_billing_address
         | 
| 14 | 
            -
                      table_column :buyer_name, : | 
| 15 | 
            -
                        (order[:buyer_name] || '').split('!!SEP!!').find | 
| 15 | 
            +
                      table_column :buyer_name, sortable: false, label: 'Buyer Name', if: proc { attributes[:user_id].blank? } do |order|
         | 
| 16 | 
            +
                        (order[:buyer_name] || '').split('!!SEP!!').find(&:present?)
         | 
| 16 17 | 
             
                      end
         | 
| 17 18 | 
             
                    end
         | 
| 18 19 |  | 
| 19 | 
            -
                    table_column : | 
| 20 | 
            -
                      content_tag(:ul) do
         | 
| 21 | 
            -
                        (order[:order_items] || '').split('!!SEP!!').map { |oi| content_tag(:li, oi) }.join().html_safe
         | 
| 22 | 
            -
                      end
         | 
| 23 | 
            -
                    end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                    table_column :purchased_at
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                    table_column :purchase_state, :filter => {:type => :select, :values => [['abandoned', 'abandoned'], [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], :selected => EffectiveOrders::PURCHASED} do |order|
         | 
| 20 | 
            +
                    table_column :purchase_state, filter: { type: :select, values: [%w(abandoned abandoned), [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], selected: EffectiveOrders::PURCHASED } do |order|
         | 
| 28 21 | 
             
                      order.purchase_state || 'abandoned'
         | 
| 29 22 | 
             
                    end
         | 
| 30 23 |  | 
| 31 | 
            -
                    table_column : | 
| 32 | 
            -
                       | 
| 24 | 
            +
                    table_column :order_items, sortable: false, column: 'order_items.title' do |order|
         | 
| 25 | 
            +
                      content_tag(:ul) do
         | 
| 26 | 
            +
                        (order[:order_items] || '').split('!!SEP!!').map { |oi| content_tag(:li, oi) }.join.html_safe
         | 
| 27 | 
            +
                      end
         | 
| 33 28 | 
             
                    end
         | 
| 34 29 |  | 
| 35 | 
            -
                    table_column | 
| 30 | 
            +
                    table_column(:total) { |order| price_to_currency(order[:total].to_i) }
         | 
| 31 | 
            +
                    table_column(:created_at, visible: false) { |order| order.updated_at.strftime('%Y-%m-%d %H:%M') }
         | 
| 32 | 
            +
                    table_column(:updated_at, visible: false) { |order| order.updated_at.strftime('%Y-%m-%d %H:%M') }
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    table_column :actions, sortable: false, filter: false do |order|
         | 
| 36 35 | 
             
                      link_to('View', (datatables_admin_path? ? effective_orders.admin_order_path(order) : effective_orders.order_path(order)))
         | 
| 37 36 | 
             
                    end
         | 
| 38 37 |  | 
| 39 38 | 
             
                    def collection
         | 
| 40 39 | 
             
                      collection = Effective::Order.unscoped
         | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
                        .select('orders.*')
         | 
| 47 | 
            -
                        .select("#{query_total} AS total")
         | 
| 48 | 
            -
                        .select("string_agg(order_items.title, '!!SEP!!') AS order_items")
         | 
| 40 | 
            +
                                   .joins(:user, :order_items)
         | 
| 41 | 
            +
                                   .group('users.email, orders.id')
         | 
| 42 | 
            +
                                   .select('orders.*, users.email AS email')
         | 
| 43 | 
            +
                                   .select("#{query_total} AS total")
         | 
| 44 | 
            +
                                   .select("string_agg(order_items.title, '!!SEP!!') AS order_items")
         | 
| 49 45 |  | 
| 50 46 | 
             
                      if EffectiveOrders.require_billing_address && defined?(EffectiveAddresses)
         | 
| 51 | 
            -
                         | 
| 47 | 
            +
                        addresses_tbl = EffectiveAddresses.addresses_table_name
         | 
| 52 48 |  | 
| 53 49 | 
             
                        collection = collection
         | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
                      end
         | 
| 58 | 
            -
             | 
| 59 | 
            -
                      if attributes[:user_id].present?
         | 
| 60 | 
            -
                        collection.where(:user_id => attributes[:user_id])
         | 
| 61 | 
            -
                      else
         | 
| 62 | 
            -
                        collection
         | 
| 50 | 
            +
                                     .joins("LEFT JOIN (SELECT addressable_id, string_agg(#{addresses_tbl}.full_name, '!!SEP!!') AS buyer_name FROM #{addresses_tbl} WHERE #{addresses_tbl}.category = 'billing' AND #{addresses_tbl}.addressable_type = 'Effective::Order' GROUP BY #{addresses_tbl}.addressable_id) #{addresses_tbl} ON orders.id = #{addresses_tbl}.addressable_id")
         | 
| 51 | 
            +
                                     .group("#{addresses_tbl}.buyer_name")
         | 
| 52 | 
            +
                                     .select("#{addresses_tbl}.buyer_name AS buyer_name")
         | 
| 63 53 | 
             
                      end
         | 
| 64 54 |  | 
| 55 | 
            +
                      attributes[:user_id].present? ? collection.where(user_id: attributes[:user_id]) : collection
         | 
| 65 56 | 
             
                    end
         | 
| 66 57 |  | 
| 67 58 | 
             
                    def query_total
         | 
| 68 | 
            -
                       | 
| 59 | 
            +
                      'SUM((order_items.price * order_items.quantity) + (CASE order_items.tax_exempt WHEN true THEN 0 ELSE ((order_items.price * order_items.quantity) * order_items.tax_rate) END))'
         | 
| 69 60 | 
             
                    end
         | 
| 70 61 |  | 
| 71 62 | 
             
                    def search_column(collection, table_column, search_term)
         | 
| 72 63 | 
             
                      if table_column[:name] == 'total'
         | 
| 73 64 | 
             
                        collection.having("#{query_total} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
         | 
| 74 65 | 
             
                      elsif table_column[:name] == 'purchase_state' && search_term == 'abandoned'
         | 
| 75 | 
            -
                        collection.where(: | 
| 66 | 
            +
                        collection.where(purchase_state: nil)
         | 
| 76 67 | 
             
                      else
         | 
| 77 68 | 
             
                        super
         | 
| 78 69 | 
             
                      end
         | 
| 79 70 | 
             
                    end
         | 
| 80 | 
            -
             | 
| 81 71 | 
             
                  end
         | 
| 82 72 | 
             
                end
         | 
| 83 73 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: effective_orders
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.2. | 
| 4 | 
            +
              version: 1.2.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Code and Effect
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-01- | 
| 11 | 
            +
            date: 2015-01-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |