ish_models 0.0.33.265 → 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: 1feaa866f501a91b64f3099038f17839932e6fa8f64aa47480da8f619f72382b
4
- data.tar.gz: c23788810130831b83b44bb41b293bfe822f7775585e0496def49976af3c2366
3
+ metadata.gz: 562cb493212497cffadce51e4ff62fdb5cd7986020944767635fb9ba06ec90c8
4
+ data.tar.gz: 7991f49f62f2d2553bc9822adaa4198f19f68a3947a1dfcd9624b928a3eeaed6
5
5
  SHA512:
6
- metadata.gz: a325995f72c871c6a31db6c59862cbc96ff6f5d42faea3dac3f06179469224de2b4258de05c8b9de9b3256a313d7cffe33b6c0313c9cec2a610417e6967bb0cc
7
- data.tar.gz: 16c7fa681f9af5ea0c88a017bcd8c8f7003cd42854b155046cb7ca6de7642edcb1bf52efb7cac96770e34b12cbcb3d3df0094f9cd618c409cba55dff048f0357
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.265
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