effective_orders 2.2.2 → 2.2.3
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 +4 -4
- data/app/controllers/admin/customers_controller.rb +6 -1
- data/app/controllers/admin/order_items_controller.rb +6 -1
- data/app/controllers/admin/orders_controller.rb +6 -1
- data/app/datatables/effective_customers_datatable.rb +38 -0
- data/app/datatables/effective_order_items_datatable.rb +100 -0
- data/app/datatables/effective_orders_datatable.rb +89 -0
- data/app/models/effective/datatables/customers.rb +29 -27
- data/app/models/effective/datatables/order_items.rb +77 -75
- data/lib/effective_orders/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db90e7dfaecba0d3d95887bb7a165d45793210c7
|
4
|
+
data.tar.gz: d4cea5629dbba4dc153a56410912c5540740236f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424ad971b23b9dd732a247dd05c252ed2d10a1aacb7fea47ce6533b79ed69256ad1b49a2c6662b87de858d6258f82f2146485fe2df7c24d9afd246851c35b7cd
|
7
|
+
data.tar.gz: 745f4d71411babbe7bfc97aeadd48647a9dc706b4dc4680f3829ea17296202f30463a888f7f4413c43d3aac99ea0db914c8af8024bd8ba3f5f1052d22a31fd61
|
@@ -5,7 +5,12 @@ module Admin
|
|
5
5
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_customers] : EffectiveOrders.layout)
|
6
6
|
|
7
7
|
def index
|
8
|
-
|
8
|
+
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
9
|
+
@datatable = Effective::Datatables::Customers.new()
|
10
|
+
else
|
11
|
+
@datatable = EffectiveCustomersDatatable.new(self)
|
12
|
+
end
|
13
|
+
|
9
14
|
@page_title = 'Customers'
|
10
15
|
|
11
16
|
EffectiveOrders.authorized?(self, :admin, :effective_orders)
|
@@ -5,7 +5,12 @@ module Admin
|
|
5
5
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_orders] : EffectiveOrders.layout)
|
6
6
|
|
7
7
|
def index
|
8
|
-
|
8
|
+
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
9
|
+
@datatable = Effective::Datatables::OrderItems.new()
|
10
|
+
else
|
11
|
+
@datatable = EffectiveOrderItemsDatatable.new(self)
|
12
|
+
end
|
13
|
+
|
9
14
|
@page_title = 'Order Items'
|
10
15
|
|
11
16
|
EffectiveOrders.authorized?(self, :admin, :effective_orders)
|
@@ -5,7 +5,12 @@ module Admin
|
|
5
5
|
layout (EffectiveOrders.layout.kind_of?(Hash) ? EffectiveOrders.layout[:admin_orders] : EffectiveOrders.layout)
|
6
6
|
|
7
7
|
def index
|
8
|
-
|
8
|
+
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
9
|
+
@datatable = Effective::Datatables::Orders.new()
|
10
|
+
else
|
11
|
+
@datatable = EffectiveOrdersDatatable.new(self)
|
12
|
+
end
|
13
|
+
|
9
14
|
@page_title = 'Orders'
|
10
15
|
|
11
16
|
authorize_effective_order!
|
@@ -0,0 +1,38 @@
|
|
1
|
+
unless Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
+
class EffectiveCustomersDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
order :email
|
5
|
+
|
6
|
+
col :id, visible: false
|
7
|
+
col :email, sql_column: 'users.email' do |user|
|
8
|
+
mail_to user.email, user.email
|
9
|
+
end
|
10
|
+
|
11
|
+
if EffectiveOrders.stripe_enabled
|
12
|
+
col :stripe_customer_id
|
13
|
+
col :stripe_active_card
|
14
|
+
end
|
15
|
+
|
16
|
+
if EffectiveOrders.stripe_connect_enabled
|
17
|
+
col :stripe_connect_access_token
|
18
|
+
end
|
19
|
+
|
20
|
+
col :subscription_types, sql_column: 'subscription_types'
|
21
|
+
|
22
|
+
actions_col partial: 'admin/customers/actions', partial_as: :customer
|
23
|
+
end
|
24
|
+
|
25
|
+
collection do
|
26
|
+
Effective::Customer.customers.uniq
|
27
|
+
.joins(:user, :subscriptions)
|
28
|
+
.select('customers.*, users.email AS email')
|
29
|
+
.select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
|
30
|
+
.group('customers.id, subscriptions.stripe_plan_id, users.email')
|
31
|
+
end
|
32
|
+
|
33
|
+
# def search_column(collection, table_column, search_term)
|
34
|
+
# return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
|
35
|
+
# super
|
36
|
+
# end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
unless Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
+
class EffectiveOrderItemsDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
order :purchased_at, :desc
|
5
|
+
|
6
|
+
col(:purchased_at, sql_column: 'orders.purchased_at') do |order_item|
|
7
|
+
Time.at(order_item[:purchased_at]).in_time_zone if order_item[:purchased_at].present?
|
8
|
+
end
|
9
|
+
|
10
|
+
col :id, visible: false
|
11
|
+
|
12
|
+
col :order
|
13
|
+
# if effectiveorders.obfuscate_order_ids
|
14
|
+
# col(:order, type: :obfuscated_id) do |order_item|
|
15
|
+
# obfuscated_id = effective::order.obfuscate(order_item[:order_id])
|
16
|
+
# link_to(obfuscated_id, (datatables_admin_path? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
17
|
+
# end
|
18
|
+
# else
|
19
|
+
# col(:order) do |order_item|
|
20
|
+
# link_to(order_item.to_param, (datatables_admin_path? ? effective_orders.admin_order_path(order_item.to_param) : effective_orders.order_path(order_item.to_param)))
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
|
24
|
+
unless attributes[:user_id]
|
25
|
+
col :email, sql_column: 'users.email', label: 'Buyer Email', do |order_item|
|
26
|
+
link_to order_item[:email], (edit_admin_user_path(order_item[:user_id]) rescue admin_user_path(order_item[:user_id]) rescue '#')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if EffectiveOrders.require_billing_address && attributes[:user_id].blank?
|
31
|
+
col :buyer_name, sortable: false, label: 'Buyer Name', do |order_item|
|
32
|
+
(order_item[:buyer_name] || '').split('!!SEP!!').find(&:present?)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
col :purchase_state, sql_column: 'orders.purchase_state', filter: { collection: [%w(abandoned abandoned), [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], selected: EffectiveOrders::PURCHASED } do |order_item|
|
37
|
+
order_item[:purchase_state] || 'abandoned'
|
38
|
+
end
|
39
|
+
|
40
|
+
col :title do |order_item|
|
41
|
+
order_item.quantity == 1 ? order_item.title : "#{order_item.title} (#{order_item.quantity} purchased)"
|
42
|
+
end
|
43
|
+
|
44
|
+
col :subtotal, as: :price
|
45
|
+
col :tax, as: :price
|
46
|
+
col :total, as: :price
|
47
|
+
|
48
|
+
col :created_at, visible: false
|
49
|
+
col :updated_at, visible: false
|
50
|
+
end
|
51
|
+
|
52
|
+
collection do
|
53
|
+
collection = Effective::OrderItem.unscoped
|
54
|
+
.joins(order: :user)
|
55
|
+
.select('order_items.*, orders.*, users.email AS email')
|
56
|
+
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
57
|
+
.group('order_items.id, orders.id, users.email')
|
58
|
+
|
59
|
+
if EffectiveOrders.require_billing_address && defined?(EffectiveAddresses)
|
60
|
+
addresses_tbl = EffectiveAddresses.addresses_table_name
|
61
|
+
|
62
|
+
collection = collection
|
63
|
+
.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")
|
64
|
+
.group("#{addresses_tbl}.buyer_name")
|
65
|
+
.select("#{addresses_tbl}.buyer_name AS buyer_name")
|
66
|
+
end
|
67
|
+
|
68
|
+
attributes[:user_id].present? ? collection.where("#{EffectiveOrders.orders_table_name.to_s}.user_id = ?", attributes[:user_id]) : collection
|
69
|
+
end
|
70
|
+
|
71
|
+
def query_subtotal
|
72
|
+
'SUM(price * quantity)'
|
73
|
+
end
|
74
|
+
|
75
|
+
def query_total
|
76
|
+
'SUM((price * quantity) + (CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END))'
|
77
|
+
end
|
78
|
+
|
79
|
+
def query_tax
|
80
|
+
'(CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END)'
|
81
|
+
end
|
82
|
+
|
83
|
+
# def search_column(collection, table_column, search_term)
|
84
|
+
# if table_column[:name] == 'order'
|
85
|
+
# collection.where("#{EffectiveOrders.order_items_table_name.to_s}.order_id = ?", Effective::Order.deobfuscate(search_term))
|
86
|
+
# elsif table_column[:name] == 'purchase_state' && search_term == 'abandoned'
|
87
|
+
# collection.where("#{EffectiveOrders.orders_table_name.to_s}.purchase_state IS NULL")
|
88
|
+
# elsif table_column[:name] == 'subtotal'
|
89
|
+
# collection.having("#{query_subtotal} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
90
|
+
# elsif table_column[:name] == 'tax'
|
91
|
+
# collection.having("#{query_tax} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
92
|
+
# elsif table_column[:name] == 'total'
|
93
|
+
# collection.having("#{query_total} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
94
|
+
# else
|
95
|
+
# super
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
unless Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
+
class EffectiveOrdersDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
order :created_at, :desc
|
5
|
+
|
6
|
+
col :purchased_at
|
7
|
+
|
8
|
+
col :id do |order|
|
9
|
+
link_to order.to_param, effective_orders.admin_order_path(order)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Don't display email or buyer_name column if this is for a specific user
|
13
|
+
if attributes[:user_id].blank?
|
14
|
+
col :email, sql_column: 'users.email', label: 'Buyer Email' do |order|
|
15
|
+
link_to order.user.email, (edit_admin_user_path(order.user) rescue admin_user_path(order.user) rescue '#')
|
16
|
+
end
|
17
|
+
|
18
|
+
if EffectiveOrders.use_address_full_name
|
19
|
+
col :buyer_name, sql_column: 'addresses.full_name' do |order|
|
20
|
+
order.billing_address.try(:full_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
elsif # Not using address full name
|
24
|
+
col :buyer_name, sql_column: 'users.*' do |order|
|
25
|
+
order.user.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if EffectiveOrders.require_billing_address
|
31
|
+
col :billing_address
|
32
|
+
end
|
33
|
+
|
34
|
+
if EffectiveOrders.require_shipping_address
|
35
|
+
col :shipping_address
|
36
|
+
end
|
37
|
+
|
38
|
+
col :purchase_state, label: 'State', search: { collection: purchase_state_filter_values } do |order|
|
39
|
+
order.purchase_state || 'abandoned'
|
40
|
+
end
|
41
|
+
|
42
|
+
col :order_items
|
43
|
+
|
44
|
+
col :subtotal, as: :price
|
45
|
+
col :tax, as: :price
|
46
|
+
|
47
|
+
col :tax_rate, visible: false do |order|
|
48
|
+
tax_rate_to_percentage(order.tax_rate)
|
49
|
+
end
|
50
|
+
|
51
|
+
col :total, as: :price
|
52
|
+
|
53
|
+
col :payment_provider, label: 'Provider', visible: false, search: { collection: ['nil'] + (EffectiveOrders.payment_providers + EffectiveOrders.other_payment_providers).sort }
|
54
|
+
col :payment_card, label: 'Card'
|
55
|
+
|
56
|
+
col :note, visible: false
|
57
|
+
col :note_to_buyer, visible: false
|
58
|
+
col :note_internal, visible: false
|
59
|
+
|
60
|
+
col :created_at, visible: false
|
61
|
+
col :updated_at, visible: false
|
62
|
+
|
63
|
+
actions_col partial: 'admin/orders/actions', partial_as: :order
|
64
|
+
end
|
65
|
+
|
66
|
+
collection do
|
67
|
+
collection = Effective::Order.unscoped
|
68
|
+
.joins(:user)
|
69
|
+
.includes(:addresses)
|
70
|
+
.includes(:user)
|
71
|
+
.includes(:order_items)
|
72
|
+
|
73
|
+
if EffectiveOrders.orders_collection_scope.respond_to?(:call)
|
74
|
+
collection = EffectiveOrders.orders_collection_scope.call(collection)
|
75
|
+
end
|
76
|
+
|
77
|
+
attributes[:user_id].present? ? collection.where(user_id: attributes[:user_id]) : collection
|
78
|
+
end
|
79
|
+
|
80
|
+
def purchase_state_filter_values
|
81
|
+
[
|
82
|
+
%w(abandoned nil),
|
83
|
+
[EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED],
|
84
|
+
[EffectiveOrders::DECLINED, EffectiveOrders::DECLINED],
|
85
|
+
[EffectiveOrders::PENDING, EffectiveOrders::PENDING]
|
86
|
+
]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,37 +1,39 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
+
module Effective
|
3
|
+
module Datatables
|
4
|
+
class Customers < Effective::Datatable
|
5
|
+
datatable do
|
6
|
+
default_order :email, :asc
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
table_column :id, visible: false
|
9
|
+
table_column(:email, column: 'users.email') { |user| mail_to user.email, user.email }
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if EffectiveOrders.stripe_enabled
|
12
|
+
table_column :stripe_customer_id
|
13
|
+
table_column :stripe_active_card
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
if EffectiveOrders.stripe_connect_enabled
|
17
|
+
table_column :stripe_connect_access_token
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
+
table_column :subscription_types, column: 'subscription_types'
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
actions_column partial: 'admin/customers/actions'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
def collection
|
26
|
+
Effective::Customer.customers.uniq
|
27
|
+
.joins(:user, :subscriptions)
|
28
|
+
.select('customers.*, users.email AS email')
|
29
|
+
.select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
|
30
|
+
.group('customers.id, subscriptions.stripe_plan_id, users.email')
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def search_column(collection, table_column, search_term)
|
34
|
+
return collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%") if table_column[:name] == 'subscription_types'
|
35
|
+
super
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,99 +1,101 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0')
|
2
|
+
module Effective
|
3
|
+
module Datatables
|
4
|
+
class OrderItems < Effective::Datatable
|
5
|
+
datatable do
|
6
|
+
default_order :purchased_at, :desc
|
7
|
+
|
8
|
+
table_column(:purchased_at, type: :datetime, column: 'orders.purchased_at') do |order_item|
|
9
|
+
Time.at(order_item[:purchased_at]).in_time_zone if order_item[:purchased_at].present?
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
table_column :id, visible: false
|
13
|
+
|
14
|
+
if EffectiveOrders.obfuscate_order_ids
|
15
|
+
table_column(:order, type: :obfuscated_id, sortable: false) do |order_item|
|
16
|
+
obfuscated_id = Effective::Order.obfuscate(order_item[:order_id])
|
17
|
+
link_to(obfuscated_id, (datatables_admin_path? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
18
|
+
end
|
19
|
+
else
|
20
|
+
table_column(:order, sortable: false) do |order_item|
|
21
|
+
link_to(order_item.to_param, (datatables_admin_path? ? effective_orders.admin_order_path(order_item.to_param) : effective_orders.order_path(order_item.to_param)))
|
22
|
+
end
|
23
|
+
end
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
obfuscated_id = Effective::Order.obfuscate(order_item[:order_id])
|
16
|
-
link_to(obfuscated_id, (datatables_admin_path? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
25
|
+
table_column :email, column: 'users.email', label: 'Buyer Email', if: proc { attributes[:user_id].blank? } do |order_item|
|
26
|
+
link_to order_item[:email], (edit_admin_user_path(order_item[:user_id]) rescue admin_user_path(order_item[:user_id]) rescue '#')
|
17
27
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
28
|
+
|
29
|
+
if EffectiveOrders.require_billing_address
|
30
|
+
table_column :buyer_name, sortable: false, label: 'Buyer Name', if: proc { attributes[:user_id].blank? } do |order_item|
|
31
|
+
(order_item[:buyer_name] || '').split('!!SEP!!').find(&:present?)
|
32
|
+
end
|
21
33
|
end
|
22
|
-
end
|
23
34
|
|
24
|
-
|
25
|
-
|
26
|
-
|
35
|
+
table_column :purchase_state, column: 'orders.purchase_state', filter: { type: :select, values: [%w(abandoned abandoned), [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], selected: EffectiveOrders::PURCHASED } do |order_item|
|
36
|
+
order_item[:purchase_state] || 'abandoned'
|
37
|
+
end
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
(order_item[:buyer_name] || '').split('!!SEP!!').find(&:present?)
|
39
|
+
table_column :title do |order_item|
|
40
|
+
order_item.quantity == 1 ? order_item.title : "#{order_item.title} (#{order_item.quantity} purchased)"
|
31
41
|
end
|
32
|
-
end
|
33
42
|
|
34
|
-
|
35
|
-
order_item[:
|
36
|
-
|
43
|
+
table_column(:subtotal) { |order_item| price_to_currency(order_item[:subtotal].to_i) }
|
44
|
+
table_column(:tax) { |order_item| price_to_currency(order_item[:tax].to_i) }
|
45
|
+
table_column(:total) { |order_item| price_to_currency(order_item[:total].to_i) }
|
37
46
|
|
38
|
-
|
39
|
-
|
47
|
+
table_column :created_at, visible: false
|
48
|
+
table_column :updated_at, visible: false
|
40
49
|
end
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
def collection
|
52
|
+
collection = Effective::OrderItem.unscoped
|
53
|
+
.joins(order: :user)
|
54
|
+
.select('order_items.*, orders.*, users.email AS email')
|
55
|
+
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
56
|
+
.group('order_items.id, orders.id, users.email')
|
45
57
|
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def collection
|
51
|
-
collection = Effective::OrderItem.unscoped
|
52
|
-
.joins(order: :user)
|
53
|
-
.select('order_items.*, orders.*, users.email AS email')
|
54
|
-
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
55
|
-
.group('order_items.id, orders.id, users.email')
|
58
|
+
if EffectiveOrders.require_billing_address && defined?(EffectiveAddresses)
|
59
|
+
addresses_tbl = EffectiveAddresses.addresses_table_name
|
56
60
|
|
57
|
-
|
58
|
-
|
61
|
+
collection = collection
|
62
|
+
.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")
|
63
|
+
.group("#{addresses_tbl}.buyer_name")
|
64
|
+
.select("#{addresses_tbl}.buyer_name AS buyer_name")
|
65
|
+
end
|
59
66
|
|
60
|
-
collection = collection
|
61
|
-
.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")
|
62
|
-
.group("#{addresses_tbl}.buyer_name")
|
63
|
-
.select("#{addresses_tbl}.buyer_name AS buyer_name")
|
67
|
+
attributes[:user_id].present? ? collection.where("#{EffectiveOrders.orders_table_name.to_s}.user_id = ?", attributes[:user_id]) : collection
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def query_subtotal
|
70
|
-
'SUM(price * quantity)'
|
71
|
-
end
|
70
|
+
def query_subtotal
|
71
|
+
'SUM(price * quantity)'
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
def query_total
|
75
|
+
'SUM((price * quantity) + (CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END))'
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def query_tax
|
79
|
+
'(CASE tax_exempt WHEN true THEN 0 ELSE ((price * quantity) * tax_rate) END)'
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
82
|
+
def search_column(collection, table_column, search_term)
|
83
|
+
if table_column[:name] == 'order'
|
84
|
+
collection.where("#{EffectiveOrders.order_items_table_name.to_s}.order_id = ?", Effective::Order.deobfuscate(search_term))
|
85
|
+
elsif table_column[:name] == 'purchase_state' && search_term == 'abandoned'
|
86
|
+
collection.where("#{EffectiveOrders.orders_table_name.to_s}.purchase_state IS NULL")
|
87
|
+
elsif table_column[:name] == 'subtotal'
|
88
|
+
collection.having("#{query_subtotal} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
89
|
+
elsif table_column[:name] == 'tax'
|
90
|
+
collection.having("#{query_tax} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
91
|
+
elsif table_column[:name] == 'total'
|
92
|
+
collection.having("#{query_total} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
93
|
+
else
|
94
|
+
super
|
95
|
+
end
|
94
96
|
end
|
95
|
-
end
|
96
97
|
|
98
|
+
end
|
97
99
|
end
|
98
100
|
end
|
99
101
|
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: 2.2.
|
4
|
+
version: 2.2.3
|
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: 2017-
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -297,6 +297,9 @@ files:
|
|
297
297
|
- app/controllers/effective/providers/stripe_connect.rb
|
298
298
|
- app/controllers/effective/subscriptions_controller.rb
|
299
299
|
- app/controllers/effective/webhooks_controller.rb
|
300
|
+
- app/datatables/effective_customers_datatable.rb
|
301
|
+
- app/datatables/effective_order_items_datatable.rb
|
302
|
+
- app/datatables/effective_orders_datatable.rb
|
300
303
|
- app/helpers/effective_carts_helper.rb
|
301
304
|
- app/helpers/effective_ccbill_helper.rb
|
302
305
|
- app/helpers/effective_orders_helper.rb
|