effective_products 0.0.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/stamps_controller.rb +9 -0
- data/app/controllers/effective/ring_wizards_controller.rb +10 -0
- data/app/controllers/effective/stamp_wizards_controller.rb +10 -0
- data/app/datatables/admin/effective_rings_datatable.rb +4 -5
- data/app/datatables/admin/effective_stamps_datatable.rb +43 -0
- data/app/datatables/{effective_ring_payments_datatable.rb → effective_ring_wizards_datatable.rb} +5 -5
- data/app/datatables/effective_stamp_wizards_datatable.rb +36 -0
- data/app/helpers/effective_products_helper.rb +0 -1
- data/app/models/concerns/{effective_products_ring_payment.rb → effective_products_ring_wizard.rb} +27 -36
- data/app/models/concerns/effective_products_stamp_wizard.rb +139 -0
- data/app/models/effective/ring.rb +2 -24
- data/app/models/effective/ring_wizard.rb +7 -0
- data/app/models/effective/stamp.rb +69 -0
- data/app/models/effective/stamp_wizard.rb +7 -0
- data/app/views/admin/rings/_ring.html.haml +23 -15
- data/app/views/admin/stamps/_stamp.html.haml +53 -0
- data/app/views/effective/{ring_payments → ring_wizards}/_content.html.haml +0 -0
- data/app/views/effective/ring_wizards/_dashboard.html.haml +27 -0
- data/app/views/effective/{ring_payments → ring_wizards}/_layout.html.haml +0 -0
- data/app/views/effective/ring_wizards/_orders.html.haml +4 -0
- data/app/views/effective/ring_wizards/_ring.html.haml +40 -0
- data/app/views/effective/{rings/_fields.html.haml → ring_wizards/_ring_fields.html.haml} +25 -7
- data/app/views/effective/ring_wizards/_ring_wizard.html.haml +3 -0
- data/app/views/effective/ring_wizards/_summary.html.haml +31 -0
- data/app/views/effective/ring_wizards/billing.html.haml +15 -0
- data/app/views/effective/ring_wizards/checkout.html.haml +6 -0
- data/app/views/effective/{ring_payments → ring_wizards}/ring.html.haml +4 -4
- data/app/views/effective/{ring_payments → ring_wizards}/start.html.haml +1 -1
- data/app/views/effective/ring_wizards/submitted.html.haml +16 -0
- data/app/views/effective/ring_wizards/summary.html.haml +8 -0
- data/app/views/effective/stamp_wizards/_content.html.haml +10 -0
- data/app/views/effective/stamp_wizards/_dashboard.html.haml +27 -0
- data/app/views/effective/stamp_wizards/_layout.html.haml +3 -0
- data/app/views/effective/stamp_wizards/_orders.html.haml +4 -0
- data/app/views/effective/stamp_wizards/_stamp.html.haml +45 -0
- data/app/views/effective/stamp_wizards/_stamp_fields.html.haml +45 -0
- data/app/views/effective/stamp_wizards/_stamp_wizard.html.haml +3 -0
- data/app/views/effective/stamp_wizards/_summary.html.haml +31 -0
- data/app/views/effective/{ring_payments → stamp_wizards}/billing.html.haml +1 -1
- data/app/views/effective/{ring_payments → stamp_wizards}/checkout.html.haml +1 -1
- data/app/views/effective/stamp_wizards/stamp.html.haml +18 -0
- data/app/views/effective/stamp_wizards/start.html.haml +16 -0
- data/app/views/effective/{ring_payments → stamp_wizards}/submitted.html.haml +4 -3
- data/app/views/effective/{ring_payments → stamp_wizards}/summary.html.haml +2 -2
- data/config/effective_products.rb +4 -4
- data/config/routes.rb +11 -3
- data/db/migrate/01_create_effective_products.rb.erb +98 -1
- data/lib/effective_products/engine.rb +2 -1
- data/lib/effective_products/version.rb +1 -1
- data/lib/effective_products.rb +6 -6
- metadata +42 -21
- data/app/controllers/effective/ring_payments_controller.rb +0 -31
- data/app/models/effective/ring_payment.rb +0 -7
- data/app/views/effective/ring_payments/_dashboard.html.haml +0 -27
- data/app/views/effective/ring_payments/_orders.html.haml +0 -4
- data/app/views/effective/ring_payments/_ring.html.haml +0 -29
- data/app/views/effective/ring_payments/_ring_fields.html.haml +0 -4
- data/app/views/effective/ring_payments/_ring_payment.html.haml +0 -8
- data/app/views/effective/ring_payments/_summary.html.haml +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe191a8c318148da7f4d5c91a4e8248ad1e46ed79a226fd8549873fbeeac7e58
|
4
|
+
data.tar.gz: e0481a234925beb15a4bde2656f931cfc98466224d4fdaa7cdf0be3e4a85879e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39a16cb225c1dd2f0c575af9eec56d5b8865f928d2acc2cb0990aec35dfd36b1d9af8acb474a3ac53dee78772224520fd3e35949447bbf1d5079c38a904511bb
|
7
|
+
data.tar.gz: a9f3006715674b41ce72da94d2936a87d456a45f08920cc4765ecc5596d69ffa6502a42aeed557c3ca1dd2061e76214d897bb3e91308e8bb5e2ede6790ec5781
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Effective
|
2
|
+
class RingWizardsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
|
5
|
+
include Effective::WizardController
|
6
|
+
|
7
|
+
resource_scope -> { EffectiveProducts.RingWizard.deep.where(owner: current_user) }
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Effective
|
2
|
+
class StampWizardsController < ApplicationController
|
3
|
+
before_action(:authenticate_user!) if defined?(Devise)
|
4
|
+
|
5
|
+
include Effective::WizardController
|
6
|
+
|
7
|
+
resource_scope -> { EffectiveProducts.StampWizard.deep.where(owner: current_user) }
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
@@ -16,11 +16,10 @@ module Admin
|
|
16
16
|
col :created_at, as: :date
|
17
17
|
col :owner, search: :string
|
18
18
|
|
19
|
-
col
|
20
|
-
col
|
21
|
-
|
22
|
-
col
|
23
|
-
col :phone
|
19
|
+
col(:first_name) { |ring| ring.owner.first_name }
|
20
|
+
col(:last_name) { |ring| ring.owner.last_name }
|
21
|
+
col(:email) { |ring| ring.owner.email }
|
22
|
+
col(:phone) { |ring| ring.owner.phone }
|
24
23
|
|
25
24
|
col :member_number, label: 'Member #' do |ring|
|
26
25
|
ring.owner.try(:membership).try(:number)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Admin
|
2
|
+
class EffectiveStampsDatatable < Effective::Datatable
|
3
|
+
filters do
|
4
|
+
scope :ready_to_issue
|
5
|
+
scope :issued
|
6
|
+
scope :all
|
7
|
+
end
|
8
|
+
|
9
|
+
datatable do
|
10
|
+
order :updated_at
|
11
|
+
|
12
|
+
col :updated_at, visible: false
|
13
|
+
col :created_at, visible: false
|
14
|
+
col :id, visible: false
|
15
|
+
|
16
|
+
col :created_at, as: :date
|
17
|
+
col :owner, search: :string
|
18
|
+
|
19
|
+
col(:first_name) { |stamp| stamp.owner.first_name }
|
20
|
+
col(:last_name) { |stamp| stamp.owner.last_name }
|
21
|
+
col(:email) { |stamp| stamp.owner.email }
|
22
|
+
col(:phone) { |stamp| stamp.owner.phone }
|
23
|
+
|
24
|
+
col :member_number, label: 'Member #' do |stamp|
|
25
|
+
stamp.owner.try(:membership).try(:number)
|
26
|
+
end
|
27
|
+
|
28
|
+
col :category
|
29
|
+
col :name
|
30
|
+
col :name_confirmation
|
31
|
+
|
32
|
+
col :shipping_address, label: 'Address'
|
33
|
+
|
34
|
+
col :issued_at
|
35
|
+
|
36
|
+
actions_col
|
37
|
+
end
|
38
|
+
|
39
|
+
collection do
|
40
|
+
Effective::Stamp.deep.all
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/app/datatables/{effective_ring_payments_datatable.rb → effective_ring_wizards_datatable.rb}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Dashboard Ring Payments
|
2
|
-
class
|
2
|
+
class EffectiveRingWizardsDatatable < Effective::Datatable
|
3
3
|
datatable do
|
4
4
|
order :created_at
|
5
5
|
|
@@ -20,17 +20,17 @@ class EffectiveRingPaymentsDatatable < Effective::Datatable
|
|
20
20
|
|
21
21
|
actions_col(actions: []) do |resource|
|
22
22
|
if resource.draft?
|
23
|
-
dropdown_link_to('Continue', effective_products.
|
24
|
-
dropdown_link_to('Delete', effective_products.
|
23
|
+
dropdown_link_to('Continue', effective_products.ring_wizard_build_path(resource, reource.next_step), 'data-turbolinks' => false)
|
24
|
+
dropdown_link_to('Delete', effective_products.ring_wizard_path(resource), 'data-confirm': "Really delete #{resource}?", 'data-method': :delete)
|
25
25
|
else
|
26
|
-
dropdown_link_to('Show', effective_products.
|
26
|
+
dropdown_link_to('Show', effective_products.ring_wizard_path(resource))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
31
31
|
|
32
32
|
collection do
|
33
|
-
EffectiveProducts.
|
33
|
+
EffectiveProducts.RingWizard.deep.done.where(owner: current_user)
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Dashboard Stamp Payments
|
2
|
+
class EffectiveStampWizardsDatatable < Effective::Datatable
|
3
|
+
datatable do
|
4
|
+
order :created_at
|
5
|
+
|
6
|
+
col :token, visible: false
|
7
|
+
col :created_at, visible: false
|
8
|
+
|
9
|
+
col(:submitted_at, label: 'Submitted on') do |resource|
|
10
|
+
resource.submitted_at&.strftime('%F') || 'Incomplete'
|
11
|
+
end
|
12
|
+
|
13
|
+
col :owner, visible: false, search: :ststamp
|
14
|
+
col :status, visible: false
|
15
|
+
col :orders, action: :show
|
16
|
+
|
17
|
+
col(:issued_at, label: 'Issued on') do |resource|
|
18
|
+
resource.stamp.issued_at&.strftime('%F') || '-'
|
19
|
+
end
|
20
|
+
|
21
|
+
actions_col(actions: []) do |resource|
|
22
|
+
if resource.draft?
|
23
|
+
dropdown_link_to('Continue', effective_products.stamp_wizard_build_path(resource, reource.next_step), 'data-turbolinks' => false)
|
24
|
+
dropdown_link_to('Delete', effective_products.stamp_wizard_path(resource), 'data-confirm': "Really delete #{resource}?", 'data-method': :delete)
|
25
|
+
else
|
26
|
+
dropdown_link_to('Show', effective_products.stamp_wizard_path(resource))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
collection do
|
33
|
+
EffectiveProducts.StampWizard.deep.done.where(owner: current_user)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/app/models/concerns/{effective_products_ring_payment.rb → effective_products_ring_wizard.rb}
RENAMED
@@ -1,28 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# EffectiveProductsRingWizard
|
4
4
|
#
|
5
|
-
# Mark your owner model with
|
5
|
+
# Mark your owner model with effective_products_ring_wizard to get all the includes
|
6
6
|
|
7
|
-
module
|
7
|
+
module EffectiveProductsRingWizard
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
module Base
|
11
|
-
def
|
12
|
-
include ::
|
11
|
+
def effective_products_ring_wizard
|
12
|
+
include ::EffectiveProductsRingWizard
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
-
def
|
18
|
-
|
19
|
-
def all_wizard_steps
|
20
|
-
const_get(:WIZARD_STEPS).keys
|
21
|
-
end
|
22
|
-
|
23
|
-
def required_wizard_steps
|
24
|
-
[:start, :billing, :checkout, :submitted]
|
25
|
-
end
|
17
|
+
def effective_products_ring_wizard?; true; end
|
26
18
|
end
|
27
19
|
|
28
20
|
included do
|
@@ -52,7 +44,7 @@ module EffectiveProductsRingPayment
|
|
52
44
|
accepts_nested_attributes_for :owner
|
53
45
|
|
54
46
|
# Effective Namespace
|
55
|
-
has_many :rings, -> { order(:id) }, class_name: 'Effective::Ring', inverse_of: :
|
47
|
+
has_many :rings, -> { order(:id) }, class_name: 'Effective::Ring', inverse_of: :ring_wizard, dependent: :destroy
|
56
48
|
accepts_nested_attributes_for :rings, reject_if: :all_blank, allow_destroy: true
|
57
49
|
|
58
50
|
has_many :orders, -> { order(:id) }, as: :parent, class_name: 'Effective::Order', dependent: :nullify
|
@@ -83,7 +75,7 @@ module EffectiveProductsRingPayment
|
|
83
75
|
# All Steps validations
|
84
76
|
validates :owner, presence: true
|
85
77
|
|
86
|
-
#
|
78
|
+
# Ring Step
|
87
79
|
validate(if: -> { current_step == :ring }) do
|
88
80
|
self.errors.add(:rings, "can't be blank") unless present_rings.present?
|
89
81
|
end
|
@@ -117,14 +109,7 @@ module EffectiveProductsRingPayment
|
|
117
109
|
end
|
118
110
|
|
119
111
|
def build_ring
|
120
|
-
ring = rings.build(
|
121
|
-
owner: owner,
|
122
|
-
first_name: owner.try(:first_name),
|
123
|
-
last_name: owner.try(:last_name),
|
124
|
-
email: owner.try(:email),
|
125
|
-
phone: owner.try(:phone)
|
126
|
-
)
|
127
|
-
|
112
|
+
ring = rings.build(owner: owner)
|
128
113
|
address = owner.try(:shipping_address) || owner.try(:billing_address)
|
129
114
|
|
130
115
|
if address.present?
|
@@ -135,23 +120,29 @@ module EffectiveProductsRingPayment
|
|
135
120
|
end
|
136
121
|
|
137
122
|
def assign_pricing
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
123
|
+
raise('to be implemented by including class')
|
124
|
+
|
125
|
+
# raise('expected a persisted ring') unless ring&.persisted?
|
126
|
+
|
127
|
+
# price = case ring.metal
|
128
|
+
# when '14k Yellow Gold' then 450_00
|
129
|
+
# when 'Sterling Silver' then 175_00
|
130
|
+
# when 'Titanium' then 50_00
|
131
|
+
# else
|
132
|
+
# raise "unexpected ring metal: #{ring.metal || 'none'}"
|
133
|
+
# end
|
134
|
+
|
135
|
+
# qb_item_name = "Professional Ring"
|
136
|
+
# tax_exempt = false
|
137
|
+
|
138
|
+
# ring.assign_attributes(price: price, qb_item_name: qb_item_name, tax_exempt: tax_exempt)
|
150
139
|
end
|
151
140
|
|
152
141
|
# After the configure Ring step
|
153
142
|
def ring!
|
154
143
|
assign_pricing() if ring.present?
|
144
|
+
raise('expected ring to have a price') if ring.price.blank?
|
145
|
+
|
155
146
|
save!
|
156
147
|
end
|
157
148
|
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# EffectiveProductsStampWizard
|
4
|
+
#
|
5
|
+
# Mark your owner model with effective_products_stamp_wizard to get all the includes
|
6
|
+
|
7
|
+
module EffectiveProductsStampWizard
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module Base
|
11
|
+
def effective_products_stamp_wizard
|
12
|
+
include ::EffectiveProductsStampWizard
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def effective_products_stamp_wizard?; true; end
|
18
|
+
end
|
19
|
+
|
20
|
+
included do
|
21
|
+
acts_as_purchasable_parent
|
22
|
+
acts_as_tokened
|
23
|
+
|
24
|
+
acts_as_statused(
|
25
|
+
:draft, # Just Started
|
26
|
+
:submitted # All done
|
27
|
+
)
|
28
|
+
|
29
|
+
acts_as_wizard(
|
30
|
+
start: 'Start',
|
31
|
+
stamp: 'Select Stamp',
|
32
|
+
summary: 'Review',
|
33
|
+
billing: 'Billing Address',
|
34
|
+
checkout: 'Checkout',
|
35
|
+
submitted: 'Submitted'
|
36
|
+
)
|
37
|
+
|
38
|
+
acts_as_purchasable_wizard
|
39
|
+
|
40
|
+
log_changes(except: :wizard_steps) if respond_to?(:log_changes)
|
41
|
+
|
42
|
+
# Application Namespace
|
43
|
+
belongs_to :owner, polymorphic: true
|
44
|
+
accepts_nested_attributes_for :owner
|
45
|
+
|
46
|
+
# Effective Namespace
|
47
|
+
has_many :stamps, -> { order(:id) }, class_name: 'Effective::Stamp', inverse_of: :stamp_wizard, dependent: :destroy
|
48
|
+
accepts_nested_attributes_for :stamps, reject_if: :all_blank, allow_destroy: true
|
49
|
+
|
50
|
+
has_many :orders, -> { order(:id) }, as: :parent, class_name: 'Effective::Order', dependent: :nullify
|
51
|
+
accepts_nested_attributes_for :orders
|
52
|
+
|
53
|
+
effective_resource do
|
54
|
+
# Acts as Statused
|
55
|
+
status :string, permitted: false
|
56
|
+
status_steps :text, permitted: false
|
57
|
+
|
58
|
+
# Dates
|
59
|
+
submitted_at :datetime
|
60
|
+
|
61
|
+
# Acts as Wizard
|
62
|
+
wizard_steps :text, permitted: false
|
63
|
+
|
64
|
+
timestamps
|
65
|
+
end
|
66
|
+
|
67
|
+
scope :deep, -> { includes(:owner, :orders, :stamps) }
|
68
|
+
scope :sorted, -> { order(:id) }
|
69
|
+
|
70
|
+
scope :in_progress, -> { where.not(status: [:submitted]) }
|
71
|
+
scope :done, -> { where(status: [:submitted]) }
|
72
|
+
|
73
|
+
scope :for, -> (user) { where(owner: user) }
|
74
|
+
|
75
|
+
# All Steps validations
|
76
|
+
validates :owner, presence: true
|
77
|
+
|
78
|
+
# Stamp Step
|
79
|
+
validate(if: -> { current_step == :stamp }) do
|
80
|
+
self.errors.add(:stamps, "can't be blank") unless present_stamps.present?
|
81
|
+
end
|
82
|
+
|
83
|
+
# All Fees and Orders
|
84
|
+
def submit_fees
|
85
|
+
stamps
|
86
|
+
end
|
87
|
+
|
88
|
+
def after_submit_purchased!
|
89
|
+
# Nothing to do yet
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# Instance Methods
|
95
|
+
def to_s
|
96
|
+
'stamp payment'
|
97
|
+
end
|
98
|
+
|
99
|
+
def in_progress?
|
100
|
+
draft?
|
101
|
+
end
|
102
|
+
|
103
|
+
def done?
|
104
|
+
submitted?
|
105
|
+
end
|
106
|
+
|
107
|
+
def stamp
|
108
|
+
stamps.first
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_stamp
|
112
|
+
address = owner.try(:shipping_address) || owner.try(:billing_address)
|
113
|
+
stamps.build(owner: owner, shipping_address: address)
|
114
|
+
end
|
115
|
+
|
116
|
+
def assign_pricing
|
117
|
+
raise('to be implemented by including class')
|
118
|
+
|
119
|
+
# price = (stamp.physical? ? 100_00 : 50_00)
|
120
|
+
# qb_item_name = "Professional Stamp"
|
121
|
+
# tax_exempt = false
|
122
|
+
|
123
|
+
# stamp.assign_attributes(price: price, qb_item_name: qb_item_name, tax_exempt: tax_exempt)
|
124
|
+
end
|
125
|
+
|
126
|
+
# After the configure Stamp step
|
127
|
+
def stamp!
|
128
|
+
assign_pricing() if stamp.present?
|
129
|
+
raise('expected stamp to have a price') if stamp.price.blank?
|
130
|
+
save!
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def present_stamps
|
136
|
+
stamps.reject(&:marked_for_destruction?)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -14,15 +14,10 @@ module Effective
|
|
14
14
|
# This ring is charged to an owner
|
15
15
|
belongs_to :owner, polymorphic: true
|
16
16
|
|
17
|
-
# Through the
|
18
|
-
belongs_to :
|
17
|
+
# Through the ring_wizard
|
18
|
+
belongs_to :ring_wizard, polymorphic: true, optional: true
|
19
19
|
|
20
20
|
effective_resource do
|
21
|
-
first_name :string
|
22
|
-
last_name :string
|
23
|
-
phone :string
|
24
|
-
email :string
|
25
|
-
|
26
21
|
size :integer
|
27
22
|
metal :string
|
28
23
|
|
@@ -40,11 +35,6 @@ module Effective
|
|
40
35
|
scope :ready_to_issue, -> { purchased.where(issued_at: nil) }
|
41
36
|
scope :issued, -> { where.not(issued_at: nil) }
|
42
37
|
|
43
|
-
validates :first_name, presence: true
|
44
|
-
validates :last_name, presence: true
|
45
|
-
validates :phone, presence: true
|
46
|
-
validates :email, presence: true, email: true
|
47
|
-
|
48
38
|
validates :metal, presence: true, inclusion: { in: METALS }
|
49
39
|
|
50
40
|
validates :size, presence: true
|
@@ -63,17 +53,5 @@ module Effective
|
|
63
53
|
issued_at.present?
|
64
54
|
end
|
65
55
|
|
66
|
-
# This is the Admin Save and Mark Paid action
|
67
|
-
def mark_paid!
|
68
|
-
raise('expected a blank ring payment') if ring_payment.present?
|
69
|
-
|
70
|
-
save!
|
71
|
-
|
72
|
-
order = Effective::Order.new(items: self, user: owner)
|
73
|
-
order.purchase!(skip_buyer_validations: true, email: false)
|
74
|
-
|
75
|
-
true
|
76
|
-
end
|
77
|
-
|
78
56
|
end
|
79
57
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Effective
|
4
|
+
class Stamp < ActiveRecord::Base
|
5
|
+
acts_as_purchasable
|
6
|
+
acts_as_addressable :shipping
|
7
|
+
|
8
|
+
#CATEGORIES = ['Physical', 'Digital-only']
|
9
|
+
CATEGORIES = ['Physical']
|
10
|
+
|
11
|
+
log_changes if respond_to?(:log_changes)
|
12
|
+
|
13
|
+
# This ring is charged to an owner
|
14
|
+
belongs_to :owner, polymorphic: true
|
15
|
+
|
16
|
+
# Through the stamp_wizard
|
17
|
+
belongs_to :stamp_wizard, polymorphic: true, optional: true
|
18
|
+
|
19
|
+
effective_resource do
|
20
|
+
name :string
|
21
|
+
name_confirmation :string
|
22
|
+
|
23
|
+
category :string
|
24
|
+
|
25
|
+
# Admin issues stamps
|
26
|
+
issued_at :datetime # Present when issued by an admin
|
27
|
+
|
28
|
+
# Acts as Purchasable
|
29
|
+
price :integer
|
30
|
+
qb_item_name :string
|
31
|
+
tax_exempt :boolean
|
32
|
+
|
33
|
+
timestamps
|
34
|
+
end
|
35
|
+
|
36
|
+
scope :deep, -> { includes(:owner) }
|
37
|
+
scope :ready_to_issue, -> { purchased.where(issued_at: nil) }
|
38
|
+
scope :issued, -> { where.not(issued_at: nil) }
|
39
|
+
|
40
|
+
validates :category, presence: true, inclusion: { in: CATEGORIES }
|
41
|
+
validates :name, presence: true
|
42
|
+
validates :name_confirmation, presence: true
|
43
|
+
|
44
|
+
validate(if: -> { name.present? && name_confirmation.present? }) do
|
45
|
+
self.errors.add(:name_confirmation, "doesn't match name") unless name == name_confirmation
|
46
|
+
end
|
47
|
+
|
48
|
+
validate(if: -> { physical? }) do
|
49
|
+
self.errors.add(:shipping_address, "can't be blank when physical stamp") unless shipping_address.present?
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
['Professional Stamp', *name.presence].join(' ')
|
54
|
+
end
|
55
|
+
|
56
|
+
def mark_as_issued!
|
57
|
+
update!(issued_at: Time.zone.now)
|
58
|
+
end
|
59
|
+
|
60
|
+
def issued?
|
61
|
+
issued_at.present?
|
62
|
+
end
|
63
|
+
|
64
|
+
def physical?
|
65
|
+
category == 'Physical'
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -11,30 +11,38 @@
|
|
11
11
|
%td
|
12
12
|
- if ring.purchased_order.present?
|
13
13
|
= link_to(ring.purchased_order, effective_orders.admin_order_path(ring.purchased_order))
|
14
|
+
|
14
15
|
%tr
|
15
|
-
%th
|
16
|
-
%td
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
%th Contact
|
17
|
+
%td
|
18
|
+
- owner = ring.owner
|
19
|
+
|
20
|
+
= owner.to_s
|
21
|
+
|
22
|
+
- if owner.try(:email).present?
|
23
|
+
%br
|
24
|
+
= mail_to(owner.email)
|
25
|
+
|
26
|
+
- if owner.try(:phone).present?
|
27
|
+
%br
|
28
|
+
= owner.phone
|
29
|
+
|
30
|
+
- if owner.try(:membership).try(:number).present?
|
31
|
+
%br
|
32
|
+
Member Number #{owner.membership.number}
|
33
|
+
|
29
34
|
%tr
|
30
35
|
%th Address
|
31
36
|
%td= ring.shipping_address.to_html
|
37
|
+
|
32
38
|
%tr
|
33
39
|
%th Size
|
34
40
|
%td= ring.size
|
41
|
+
|
35
42
|
%tr
|
36
43
|
%th Metal
|
37
44
|
%td= ring.metal
|
45
|
+
|
38
46
|
%tr
|
39
47
|
%th Issued At
|
40
|
-
%td= ring.issued_at
|
48
|
+
%td= ring.issued_at&.strftime('%F') || 'Not Issued'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
%table.table
|
2
|
+
%tbody
|
3
|
+
%tr
|
4
|
+
%th Owner
|
5
|
+
%td
|
6
|
+
- url = (edit_polymorphic_path(stamp.owner) rescue "/admin/users/#{stamp.owner.to_param}/edit")
|
7
|
+
= link_to(stamp.owner, url)
|
8
|
+
|
9
|
+
%tr
|
10
|
+
%th Purchased Order
|
11
|
+
%td
|
12
|
+
- if stamp.purchased_order.present?
|
13
|
+
= link_to(stamp.purchased_order, effective_orders.admin_order_path(stamp.purchased_order))
|
14
|
+
|
15
|
+
%tr
|
16
|
+
%th Contact
|
17
|
+
%td
|
18
|
+
- owner = stamp.owner
|
19
|
+
|
20
|
+
= owner.to_s
|
21
|
+
|
22
|
+
- if owner.try(:email).present?
|
23
|
+
%br
|
24
|
+
= mail_to(owner.email)
|
25
|
+
|
26
|
+
- if owner.try(:phone).present?
|
27
|
+
%br
|
28
|
+
= owner.phone
|
29
|
+
|
30
|
+
- if owner.try(:membership).try(:number).present?
|
31
|
+
%br
|
32
|
+
Member Number #{owner.membership.number}
|
33
|
+
|
34
|
+
%tr
|
35
|
+
%th
|
36
|
+
%td= stamp.physical? ? 'Physical' : 'Digital Only'
|
37
|
+
|
38
|
+
- if stamp.shipping_address.present?
|
39
|
+
%tr
|
40
|
+
%th Address
|
41
|
+
%td= stamp.shipping_address.to_html
|
42
|
+
|
43
|
+
%tr
|
44
|
+
%th Name on Stamp
|
45
|
+
%td= stamp.name
|
46
|
+
|
47
|
+
%tr
|
48
|
+
%th Name Confirmation
|
49
|
+
%td= stamp.name_confirmation
|
50
|
+
|
51
|
+
%tr
|
52
|
+
%th Issued At
|
53
|
+
%td= stamp.issued_at&.strftime('%F') || 'Not Issued'
|
File without changes
|