ish_models 0.0.33.266 → 0.0.33.267

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
  SHA256:
3
- metadata.gz: 8eb5db8ce22c02492c9b4c1b5d2aacf498d7765b0a2076ef913be600f5230ad0
4
- data.tar.gz: 91f0c2b5c1a5b29391cb3989b51ba9f27016561f8287c273e1d17d300b87b9a4
3
+ metadata.gz: 562cb493212497cffadce51e4ff62fdb5cd7986020944767635fb9ba06ec90c8
4
+ data.tar.gz: 7991f49f62f2d2553bc9822adaa4198f19f68a3947a1dfcd9624b928a3eeaed6
5
5
  SHA512:
6
- metadata.gz: f2a4ab8a3310ea17ad92c5fb7274be9abd88c02ae375918509724fc76d482354aa993fa6497a9605427ea680e8c55e37dd657ac948fca249d7477ff8acd6ae9f
7
- data.tar.gz: bfdddadd74b5f5bd12610f91de2863e07761a99aa9101f384bb383bfa10b9079378911a3ad5d9082d02539ad3e4a52b94925ba3f54796314b2cca1aa9132458c
6
+ metadata.gz: 2bc7c42c23d84036beaa7df47fa2c8d4ca8438dcf0dba760f3691e5470fdaed0483eb4f2372ed1fc4090b69ff21d3078b9503cef2f32e414ab77c7153746df86
7
+ data.tar.gz: ff6b3f6331e2d10da1e1a4c82d408000f5555066875f28d5310630d18e230bf2a17e67ab8f3e1b43e0792501a0aac15f6e8f65cdaf6d1c5703264ecc511d145b
data/lib/ish/invoice.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'autoinc'
2
- # require "prawn"
2
+ require 'prawn'
3
+ require 'prawn/table'
3
4
 
4
5
  ##
5
6
  ## Invoice - for wasya.co
@@ -22,27 +23,99 @@ class Ish::Invoice
22
23
  Leadset.find leadset_id
23
24
  end
24
25
 
25
- field :number, type: Integer
26
+ field :number, type: Integer, default: 100
26
27
  increments :number
27
28
 
28
- field :amount_cents, type: Integer
29
+ field :month_on, type: Date
29
30
 
30
- has_many :payments, :class_name => 'Ish::Payment'
31
- field :paid_amount_cents, type: Integer, :default => 0 ## @TODO: unused? _vp_ 2023-08-18
31
+ # field :amount_cents, type: Integer
32
+ # has_many :payments, :class_name => 'Ish::Payment'
33
+ # field :paid_amount_cents, type: Integer, :default => 0 ## @TODO: unused? _vp_ 2023-08-18
34
+ # field :description, type: String
35
+ # field :items, type: Array
32
36
 
33
- field :description, type: String
34
37
 
35
- field :items, type: Array
36
38
 
37
- # def generate_pdf pdf=nil
38
- # pdf ||= Prawn::Document.new
39
- # pdf.text "Job Summary."
40
- # filename = "a-summary.pdf"
41
- # path = Rails.root.join 'tmp', filename
42
- # pdf.render_file path
43
- # data = File.read path
44
- # File.delete(path) if File.exist?(path)
45
- # return data
46
- # end
39
+ ## Prawn/pdf unit of measure is 1/72"
40
+ ## Canvas width: 612, height: 792
41
+ def generate_monthly_invoice month_on
42
+ tree_img_url = "#{Rails.root.join('public')}/tree-1.jpg"
43
+ wasya_co_logo_url = "#{Rails.root.join('public')}/259x66-WasyaCo-logo.png"
44
+
45
+ ## canvas width: 612, height: 792
46
+ pdf = Prawn::Document.new
47
+
48
+ pdf.canvas do
49
+ pdf.image tree_img_url, at: [ 0, 792 ], width: 612
50
+
51
+ pdf.fill_color 'ffffff'
52
+ pdf.transparent( 0.75 ) do
53
+ pdf.fill_rectangle [0, 792], 612, 792
54
+ end
55
+ pdf.fill_color '000000'
56
+
57
+ pdf.image wasya_co_logo_url, at: [252, 720], width: 108 ## 1.5"
58
+
59
+ pdf.bounding_box( [0.75*72, 9.25*72], width: 3.25*72, height: 0.75*72 ) do
60
+ pdf.text "From:"
61
+ pdf.text "Wasya Co"
62
+ pdf.text "victor@wasya.co"
63
+ end
64
+
65
+ pdf.bounding_box( [4.5*72, 9.25*72], width: 3.25*72, height: 0.75*72 ) do
66
+ pdf.text "Stats:"
67
+ pdf.text "Date: #{ Time.now.to_date.to_s }"
68
+ pdf.text "Invoice #: #{ number }"
69
+ end
70
+
71
+ pdf.bounding_box( [0.75*72, 8.25*72], width: 3.25*72, height: 0.75*72 ) do
72
+ pdf.text "To:"
73
+ pdf.text leadset.name
74
+ pdf.text leadset.email
75
+ end
76
+
77
+ pdf.bounding_box( [4.5*72, 8.25*72], width: 3.25*72, height: 0.75*72 ) do
78
+ pdf.text "Notes:"
79
+ pdf.text "Support & various tasks, for the month of #{ month_on }."
80
+ end
81
+
82
+ lineitems_with_header = [
83
+ [ 'Description', 'Per Unit', '# of Units', 'Subtotal' ]
84
+ ]
85
+ total = 0
86
+ leadset.subscriptions.each do |i|
87
+ subtotal = (i.price.amount_cents * i.quantity).to_f/100
88
+ lineitems_with_header.push([ i.price.product.name, i.price.to_s, i.quantity, subtotal ])
89
+ total += subtotal
90
+ end
91
+
92
+
93
+ pdf.move_down 20
94
+ pdf.table(lineitems_with_header, {
95
+ position: :center,
96
+ width: 7.5*72,
97
+ cell_style: {
98
+ inline_format: true,
99
+ borders: [ :bottom ]
100
+ },
101
+ } )
102
+
103
+ pdf.table([
104
+ [ 'Total' ],
105
+ [ total ],
106
+ ], {
107
+ position: 7*72,
108
+ width: 1*72,
109
+ cell_style: {
110
+ inline_format: true,
111
+ borders: [ :bottom ]
112
+ },
113
+ } )
114
+
115
+ pdf.text_box "Thank you!", at: [ 3.25*72, 1.25*72 ], width: 2*72, height: 1*72, align: :center
116
+ end
117
+
118
+ return pdf
119
+ end
47
120
 
48
121
  end
data/lib/ish_models.rb CHANGED
@@ -76,6 +76,7 @@ require 'office/scheduled_email_action'
76
76
 
77
77
  require 'wco/appliance'
78
78
  require 'wco/appliance_tmpl'
79
+ require 'wco/price'
79
80
  require 'wco/product'
80
81
  require 'wco/serverhost'
81
82
  require 'wco/subscription'
data/lib/wco/price.rb ADDED
@@ -0,0 +1,27 @@
1
+
2
+ ##
3
+ ## Not used. _vp_ 2023-09-07
4
+ ## Just replicating the Stripe structure.
5
+ ##
6
+ class Wco::Price
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+
10
+ belongs_to :product, class_name: '::Wco::Product', inverse_of: :prices
11
+
12
+ has_many :subscriptions, class_name: '::Wco::Subscription', inverse_of: :price, foreign_key: :wco_price_id
13
+
14
+ field :amount_cents, type: Integer
15
+
16
+ INTERVALS = [ nil, 'day', 'week', 'month', 'year' ]
17
+ field :interval, type: String
18
+
19
+ field :price_id # stripe
20
+
21
+ def to_s
22
+ "$#{ amount_cents.to_f/100 } / #{interval}"
23
+ end
24
+
25
+ end
26
+
27
+
data/lib/wco/product.rb CHANGED
@@ -6,14 +6,21 @@ class Wco::Product
6
6
  field :name
7
7
 
8
8
  field :product_id # stripe
9
- field :price_id # stripe
10
9
 
11
- field :price_cents, type: Integer
10
+ ## @TODO: remove, interval makes no sense on product! replace with Wco::Price . _vp_ 2023-09-07
11
+ # INTERVALS = [ nil, 'day', 'week', 'month', 'year' ]
12
+ # field :interval, type: String
12
13
 
13
- INTERVALS = [ nil, 'day', 'week', 'month', 'year' ]
14
- field :interval, type: String
14
+ ## @TODO: remove, interval makes no sense on product! replace with Wco::Price . _vp_ 2023-09-07
15
+ # field :price_id # stripe
15
16
 
16
- has_many :subscriptions, class_name: '::Wco::Subscription', inverse_of: :subscription
17
+ ## @TODO: remove, interval makes no sense on product! replace with Wco::Price . _vp_ 2023-09-07
18
+ # field :price_cents, type: Integer
19
+
20
+ ## @TODO: remove, interval makes no sense on product! replace with Wco::Price . _vp_ 2023-09-07
21
+ # has_many :subscriptions, class_name: '::Wco::Subscription', inverse_of: :subscription
22
+
23
+ has_many :prices, class_name: '::Wco::Price', inverse_of: :product
17
24
 
18
25
  def self.list
19
26
  [ [nil,nil] ] + self.all.map { |i| [i.name, i.id] }
@@ -7,11 +7,18 @@ class Wco::Subscription
7
7
  field :price_id, type: :string # stripe
8
8
 
9
9
  field :leadset_id
10
+ def leadset
11
+ Leadset.find leadset_id
12
+ end
10
13
 
11
- belongs_to :product, class_name: '::Wco::Product', inverse_of: :subscriptions
14
+ field :quantity, type: :integer
12
15
 
13
- belongs_to :profile, class_name: '::Ish::UserProfile', optional: true, inverse_of: :subscriptions
16
+ belongs_to :product, class_name: '::Wco::Product', inverse_of: :subscriptions
17
+ belongs_to :price, class_name: '::Wco::Price', inverse_of: :subscriptions, foreign_key: :wco_price_id
14
18
 
19
+ ## This was for ACL on wco dashboard? Should that be the same class?
20
+ ## @TODO: optional ?!
21
+ belongs_to :profile, class_name: '::Ish::UserProfile', inverse_of: :subscriptions, optional: true
15
22
 
16
23
  end
17
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.266
4
+ version: 0.0.33.267
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -187,6 +187,7 @@ files:
187
187
  - lib/video.rb
188
188
  - lib/wco/appliance.rb
189
189
  - lib/wco/appliance_tmpl.rb
190
+ - lib/wco/price.rb
190
191
  - lib/wco/product.rb
191
192
  - lib/wco/serverhost.rb
192
193
  - lib/wco/subscription.rb