wco_models 3.1.0.95 → 3.1.0.96
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/assets/javascripts/wco/application.js +6 -4
- data/app/assets/javascripts/wco/invoices.js +33 -0
- data/app/controllers/wco/invoices_controller.rb +159 -0
- data/app/controllers/wco/products_controller.rb +15 -11
- data/app/models/wco/price.rb +4 -6
- data/app/models/wco/product.rb +3 -1
- data/app/views/wco/_alerts_notices.haml +4 -1
- data/app/views/wco/invoices/new_stripe.haml +2 -2
- data/app/views/wco/invoices/show.haml +1 -1
- data/app/views/wco/products/_table.haml +1 -0
- data/app/views/wco/products/new.haml +2 -0
- data/app/views/wco/products/show.jbuilder +16 -0
- metadata +21 -3
- /data/app/models/wco/{premium_item.rb → premium_item.rb-trash} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b8f95ac4445fae28c24950aa08aa7c36cfe21d61a7f5791c0ca688862f2216b
|
4
|
+
data.tar.gz: f37434ed5db0e33d3754b0e91e4cf69c3c90272e358f5229eebc7ca314ec56d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da38057b8f74c5c3ce868398cc6868d253f32f2b3ed4803e52ad40caa3f889507ba92b17d46180bd362e79a9a45fb568654667911b3dbdb38528584358b0d1a5
|
7
|
+
data.tar.gz: 408013e01f428949316aac1ab3866affc50f3efa1ba9ce41147a2451186809c1b053781a67979f381535be23414e138d014e3548d7711e0c2b5cd0d79490ce77
|
@@ -14,11 +14,13 @@
|
|
14
14
|
//
|
15
15
|
// require select2
|
16
16
|
//
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
// require ./alerts-notices
|
18
|
+
// require ./collapse-expand
|
19
|
+
// require ./file_upload
|
20
|
+
// require ./office_action_templates
|
21
|
+
//
|
21
22
|
//= require ./shared
|
23
|
+
//= require_tree .
|
22
24
|
//
|
23
25
|
|
24
26
|
$(function() {
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
const AppRouter = {
|
3
|
+
product_path: (id) => `/wco/products/${id}.json`,
|
4
|
+
}
|
5
|
+
|
6
|
+
$(document).ready(function () {
|
7
|
+
|
8
|
+
// const jwt_token = $("#Config").data('jwt-token')
|
9
|
+
// logg(jwt_token, 'jwt_token')
|
10
|
+
// path = `/api/products/${productId}.json?jwt_token=${jwt_token}`
|
11
|
+
|
12
|
+
if ($(".invoices-new").length) {
|
13
|
+
|
14
|
+
$("select[name='invoice[items][][product_id]']").on('change', function(ev) {
|
15
|
+
var productId = ev.target.value
|
16
|
+
logg(productId, 'productId')
|
17
|
+
|
18
|
+
$.get(AppRouter.product_path(productId), function(_data) {
|
19
|
+
logg(_data, '_data')
|
20
|
+
|
21
|
+
$('select[name="invoice[items][][price_id]"]').empty();
|
22
|
+
// $('select[name="invoice[items][][price_id]"]').append($("<option disabled=true selected=true></option>").attr("value", '').text('Choose a price...')
|
23
|
+
$.each(_data.prices, function(_, item) {
|
24
|
+
$('select[name="invoice[items][][price_id]"]').append($("<option></option>").attr("value", item.id).text(item.name));
|
25
|
+
})
|
26
|
+
})
|
27
|
+
})
|
28
|
+
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
})
|
33
|
+
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
require 'prawn/table'
|
3
|
+
|
4
|
+
class Wco::InvoicesController < Wco::ApplicationController
|
5
|
+
|
6
|
+
before_action :set_lists
|
7
|
+
|
8
|
+
def create_monthly_pdf
|
9
|
+
month_on = DateTime.strptime(params[:month_on], '%Y-%m-%d').strftime('%Y-%m-01')
|
10
|
+
@leadset = Leadset.find params[:leadset_id]
|
11
|
+
authorize! :create_monthly_invoice_pdf, @leadset
|
12
|
+
|
13
|
+
@invoice = Wco::Invoice.where({ leadset_id: @leadset.id, month_on: month_on }).first
|
14
|
+
if @invoice && !params[:replace]
|
15
|
+
flash_alert "Already created this invoice."
|
16
|
+
redirect_to controller: :leadsets, action: :show, id: @leadset.id
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
if !@invoice
|
21
|
+
@invoice = Wco::Invoice.create({
|
22
|
+
leadset_id: @leadset.id,
|
23
|
+
month_on: month_on,
|
24
|
+
number: @leadset.next_invoice_number,
|
25
|
+
})
|
26
|
+
@leadset.update_attributes({ next_invoice_number: @leadset.next_invoice_number + 1 })
|
27
|
+
end
|
28
|
+
|
29
|
+
@pdf = @invoice.generate_monthly_invoice
|
30
|
+
path = "/tmp/#{@invoice.filename}"
|
31
|
+
@pdf.render_file path
|
32
|
+
data = File.read path
|
33
|
+
|
34
|
+
asset = ::Gameui::Asset3d.new invoice: @invoice
|
35
|
+
f = File.new( path )
|
36
|
+
asset.object = f
|
37
|
+
f.close
|
38
|
+
@invoice.asset = asset
|
39
|
+
if asset.save
|
40
|
+
flash_notice "Saved the asset."
|
41
|
+
end
|
42
|
+
if @invoice.save
|
43
|
+
flash_notice "Saved the invoice."
|
44
|
+
end
|
45
|
+
|
46
|
+
File.delete(path) if File.exist?(path)
|
47
|
+
redirect_to controller: :leadsets, action: :show, id: @invoice.leadset_id
|
48
|
+
|
49
|
+
# send_data( data, { :filename => @invoice.filename,
|
50
|
+
# :disposition => params[:disposition] ? params[:disposition] : :attachment,
|
51
|
+
# :type => 'application/pdf'
|
52
|
+
# })
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_stripe
|
56
|
+
@invoice = Wco::Invoice.new params[:invoice].permit!
|
57
|
+
authorize! :create, @invoice
|
58
|
+
|
59
|
+
stripe_invoice = Stripe::Invoice.create({
|
60
|
+
customer: @invoice.leadset.customer_id,
|
61
|
+
collection_method: 'send_invoice',
|
62
|
+
days_until_due: 0,
|
63
|
+
# collection_method: 'charge_automatically',
|
64
|
+
pending_invoice_items_behavior: 'exclude',
|
65
|
+
})
|
66
|
+
params[:invoice][:items].each do |item|
|
67
|
+
stripe_price = Wco::Price.find( item[:price_id] ).price_id
|
68
|
+
puts! stripe_price, 'stripe_price'
|
69
|
+
invoice_item = Stripe::InvoiceItem.create({
|
70
|
+
customer: @invoice.leadset.customer_id,
|
71
|
+
price: stripe_price,
|
72
|
+
invoice: stripe_invoice.id,
|
73
|
+
quantity: item[:quantity],
|
74
|
+
})
|
75
|
+
end
|
76
|
+
Stripe::Invoice.finalize_invoice( stripe_invoice[:id] )
|
77
|
+
if params[:do_send]
|
78
|
+
Stripe::Invoice.send_invoice(stripe_invoice[:id])
|
79
|
+
flash_notice "Scheduled to send the invoice via stripe."
|
80
|
+
end
|
81
|
+
@invoice.update_attributes({ invoice_id: stripe_invoice[:id] })
|
82
|
+
|
83
|
+
if @invoice.save
|
84
|
+
flash_notice "Created the invoice."
|
85
|
+
redirect_to action: :show, id: @invoice.id
|
86
|
+
else
|
87
|
+
flash_alert "Cannot create invoice: #{@invoice.errors.messages}"
|
88
|
+
render :new
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def index
|
93
|
+
authorize! :index, Wco::Invoice
|
94
|
+
@invoices = Wco::Invoice.all
|
95
|
+
if params[:leadset_id]
|
96
|
+
@invoices = @invoices.where( leadset_id: params[:leadset_id] )
|
97
|
+
end
|
98
|
+
@invoices = @invoices.includes( :payments )
|
99
|
+
end
|
100
|
+
|
101
|
+
def new_pdf
|
102
|
+
authorize! :new, @invoice
|
103
|
+
@leadset = Leadset.find params[:leadset_id]
|
104
|
+
@products_list = Wco::Product.list
|
105
|
+
end
|
106
|
+
|
107
|
+
def new_stripe
|
108
|
+
authorize! :new, @invoice
|
109
|
+
@leadset = Wco::Leadset.find params[:leadset_id]
|
110
|
+
@products_list = Wco::Product.list
|
111
|
+
end
|
112
|
+
|
113
|
+
def email_send
|
114
|
+
@invoice = Wco::Invoice.find params[:id]
|
115
|
+
authorize! :send_email, @invoice
|
116
|
+
out = ::IshManager::LeadsetMailer.monthly_invoice( @invoice.id.to_s )
|
117
|
+
Rails.env.production? ? out.deliver_later : out.deliver_now
|
118
|
+
flash_notice "Scheduled to send an email."
|
119
|
+
redirect_to controller: :leadsets, action: :show, id: @invoice.leadset_id
|
120
|
+
end
|
121
|
+
|
122
|
+
def send_stripe
|
123
|
+
@invoice = Wco::Invoice.find params[:id]
|
124
|
+
authorize! :send_stripe, @invoice
|
125
|
+
Stripe::Invoice.send_invoice( @invoice.invoice_id )
|
126
|
+
flash_notice "Scheduled to send the invoice."
|
127
|
+
redirect_to action: :show, id: @invoice.id
|
128
|
+
end
|
129
|
+
|
130
|
+
def show
|
131
|
+
@invoice = Wco::Invoice.find params[:id]
|
132
|
+
authorize! :show, @invoice
|
133
|
+
@stripe_invoice = Stripe::Invoice.retrieve @invoice.invoice_id
|
134
|
+
end
|
135
|
+
|
136
|
+
def update
|
137
|
+
@invoice = Wco::Invoice.find params[:id]
|
138
|
+
authorize! :update, @invoice
|
139
|
+
if @invoice.update_attributes params[:invoice].permit!
|
140
|
+
flash[:notice] = 'Success'
|
141
|
+
redirect_to :action => 'index'
|
142
|
+
else
|
143
|
+
flash[:alert] = "Cannot update invoice: #{@invoice.errors.messages}"
|
144
|
+
end
|
145
|
+
redirect_to :action => 'index'
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# private
|
150
|
+
#
|
151
|
+
private
|
152
|
+
|
153
|
+
def set_lists
|
154
|
+
@invoice_number = Wco::Invoice.order_by( :number => :desc ).first
|
155
|
+
@invoice_number = @invoice_number ? @invoice_number.number + 1 : 1
|
156
|
+
@new_invoice = Wco::Invoice.new :number => @invoice_number
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -23,17 +23,17 @@ class Wco::ProductsController < Wco::ApplicationController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def destroy
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
flag = Stripe::Product.delete(
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
@product = Wco::Product.find params[:id]
|
27
|
+
authorize! :destroy, @product
|
28
|
+
|
29
|
+
# flag = Stripe::Product.delete( @product.product_id ) if @product.product_id.present?
|
30
|
+
# flash_notice "Delete stripe product: #{flag}"
|
31
|
+
|
32
|
+
if @product.destroy
|
33
|
+
flash_notice 'Deleted Wco::Product'
|
34
|
+
else
|
35
|
+
flash_alert "Cannot destroy product: #{@product.errors.fill_messages.join(', ')}."
|
36
|
+
end
|
37
37
|
redirect_to action: :index
|
38
38
|
end
|
39
39
|
|
@@ -82,6 +82,10 @@ class Wco::ProductsController < Wco::ApplicationController
|
|
82
82
|
def show
|
83
83
|
authorize! :show, @product
|
84
84
|
@product = Wco::Product.find params[:id]
|
85
|
+
respond_to do |format|
|
86
|
+
format.html
|
87
|
+
format.json { render 'show.jbuilder', layout: false }
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
def update
|
data/app/models/wco/price.rb
CHANGED
@@ -13,11 +13,6 @@ class Wco::Price
|
|
13
13
|
|
14
14
|
field :amount_cents, type: Integer
|
15
15
|
|
16
|
-
def to_s
|
17
|
-
price = self
|
18
|
-
"$#{ price[:amount_cents].to_f/100 }/#{ price.interval||'onetime' }"
|
19
|
-
end
|
20
|
-
|
21
16
|
INTERVAL_DAY = 'day'
|
22
17
|
INTERVAL_WEEK = 'week'
|
23
18
|
INTERVAL_MONTH = 'month'
|
@@ -27,10 +22,13 @@ class Wco::Price
|
|
27
22
|
|
28
23
|
field :price_id # stripe
|
29
24
|
|
25
|
+
def to_s
|
26
|
+
price = self
|
27
|
+
"$#{ price[:amount_cents].to_f/100 }/#{ price.interval||'onetime' }"
|
28
|
+
end
|
30
29
|
def self.list
|
31
30
|
[[nil,nil]] + all.map { |p| [ "#{p.product.name} :: #{p.amount_cents.to_f/100}/#{p.interval||'onetime'}", p.id ] }
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
35
33
|
|
36
34
|
|
data/app/models/wco/product.rb
CHANGED
@@ -7,13 +7,13 @@
|
|
7
7
|
|
8
8
|
.row
|
9
9
|
.col.s12.col.m6.col-md-offset-3
|
10
|
-
%h5 New Stripe Invoice for `#{link_to @leadset
|
10
|
+
%h5 New Stripe Invoice for `#{link_to @leadset, leadset_path(@leadset)}`:
|
11
11
|
|
12
12
|
= form_for invoice, :as => :invoice, :url => url do |f|
|
13
13
|
= hidden_field_tag 'invoice[leadset_id]', @leadset.id
|
14
14
|
|
15
15
|
.input-field
|
16
|
-
%label Email
|
16
|
+
%label <b>Email:</b>
|
17
17
|
= @leadset.email
|
18
18
|
-# - if @leadset.email
|
19
19
|
-# = f.text_field :email, value: @leadset.email
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wco_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.0.
|
4
|
+
version: 3.1.0.96
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Pudeyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 3.20.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jbuilder
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.11.5
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.11.5
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: haml
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -359,6 +373,7 @@ files:
|
|
359
373
|
- app/assets/javascripts/wco/application.js
|
360
374
|
- app/assets/javascripts/wco/collapse-expand.js
|
361
375
|
- app/assets/javascripts/wco/file_upload.js
|
376
|
+
- app/assets/javascripts/wco/invoices.js
|
362
377
|
- app/assets/javascripts/wco/office_action_templates.js
|
363
378
|
- app/assets/javascripts/wco/shared.js
|
364
379
|
- app/assets/stylesheets/vendor/bootstrap-4.6.2.min.css
|
@@ -373,6 +388,7 @@ files:
|
|
373
388
|
- app/controllers/wco/application_controller.rb
|
374
389
|
- app/controllers/wco/galleries_controller.rb
|
375
390
|
- app/controllers/wco/headlines_controller.rb
|
391
|
+
- app/controllers/wco/invoices_controller.rb
|
376
392
|
- app/controllers/wco/leads_controller.rb
|
377
393
|
- app/controllers/wco/leadsets_controller.rb
|
378
394
|
- app/controllers/wco/logs_controller.rb
|
@@ -405,7 +421,7 @@ files:
|
|
405
421
|
- app/models/wco/office_action_template.rb
|
406
422
|
- app/models/wco/office_action_template_tie.rb
|
407
423
|
- app/models/wco/photo.rb
|
408
|
-
- app/models/wco/premium_item.rb
|
424
|
+
- app/models/wco/premium_item.rb-trash
|
409
425
|
- app/models/wco/price.rb
|
410
426
|
- app/models/wco/product.rb
|
411
427
|
- app/models/wco/profile.rb
|
@@ -526,7 +542,9 @@ files:
|
|
526
542
|
- app/views/wco/products/_table.haml
|
527
543
|
- app/views/wco/products/edit.haml
|
528
544
|
- app/views/wco/products/index.haml
|
545
|
+
- app/views/wco/products/new.haml
|
529
546
|
- app/views/wco/products/show.haml
|
547
|
+
- app/views/wco/products/show.jbuilder
|
530
548
|
- app/views/wco/publishers/_form.haml
|
531
549
|
- app/views/wco/publishers/_header.haml
|
532
550
|
- app/views/wco/publishers/edit.haml
|
File without changes
|