effective_orders 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e18ac05ae929a3e8cba5f191a3d72cbc834b72b
4
- data.tar.gz: 3fb8c09f1ccab9fa69eb7fc56b93273fa46fd28d
3
+ metadata.gz: 9e77f25b6d0e0a68b65f915274bac55854e97671
4
+ data.tar.gz: a7b178984581033d45d4bebacc8be65700b9609b
5
5
  SHA512:
6
- metadata.gz: cfca6b00e5f4d62f7a156ec33d91daef472091adc30f234aa493aaf0856ac4912089e6a3692ed580f4bc64d2be821a4201c873e1b4a502d5396af5f5b7aa2b99
7
- data.tar.gz: 8cb50d9d1f38a76d715e32840249ed53c0cac14dcea8bdd10c908e071dbec2132d77ffa4069b5df52260c6c97f04e2f2155c3cc71020f43997574c05e65b9bde
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
- table_column :email, :column => 'users.email' do |user|
6
- mail_to user.email, user.email
7
- end
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, :column => 'subscription_types'
19
+ table_column :subscription_types, column: 'subscription_types'
19
20
 
20
- table_column :actions, :sortable => false, :filter => false, :partial => '/admin/customers/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
- .joins(:subscriptions)
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
- collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%")
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, :column => 'users.email', :label => 'Buyer Email', :if => Proc.new { attributes[:user_id].blank? } do |order|
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, :sortable => false, :label => 'Buyer Name', :if => Proc.new { attributes[:user_id].blank? } do |order|
15
- (order[:buyer_name] || '').split('!!SEP!!').find { |name| name.present? }
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 :order_items, :sortable => false, :column => 'order_items.title' do |order|
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 :total do |order|
32
- price_to_currency(order[:total].to_i)
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 :actions, :sortable => false, :filter => false do |order|
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
- .joins(:user)
42
- .joins(:order_items)
43
- .group('users.email')
44
- .group('orders.id')
45
- .select('users.email AS email')
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
- tblAddresses = EffectiveAddresses.addresses_table_name
47
+ addresses_tbl = EffectiveAddresses.addresses_table_name
52
48
 
53
49
  collection = collection
54
- .joins("LEFT JOIN (SELECT addressable_id, string_agg(#{tblAddresses}.full_name, '!!SEP!!') AS buyer_name FROM #{tblAddresses} WHERE #{tblAddresses}.category = 'billing' AND #{tblAddresses}.addressable_type = 'Effective::Order' GROUP BY #{tblAddresses}.addressable_id) #{tblAddresses} ON orders.id = #{tblAddresses}.addressable_id")
55
- .group("#{tblAddresses}.buyer_name")
56
- .select("#{tblAddresses}.buyer_name AS buyer_name")
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
- "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))"
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(:purchase_state => nil)
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '1.2.6'.freeze
2
+ VERSION = '1.2.7'.freeze
3
3
  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.6
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-20 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails