Class: Invoice
- Inherits:
-
Object
- Object
- Invoice
- Defined in:
- lib/invoice.rb
Instance Method Summary collapse
- #amount_off ⇒ Object
- #as_stripe_invoice ⇒ Object
- #coupon ⇒ Object
- #date(timezone = nil) ⇒ Object
- #discount ⇒ Object
- #discount_is_percentage? ⇒ Boolean
- #download(data) ⇒ Object
- #format_amount(amount) ⇒ Object
- #has_discount ⇒ Object
- #has_starting_balance? ⇒ Boolean
-
#initialize(user, invoice) ⇒ Invoice
constructor
A new instance of Invoice.
- #invoice_items ⇒ Object
- #invoice_items_by_type(type) ⇒ Object
- #pdf(data) ⇒ Object
- #percent_off ⇒ Object
- #raw_starting_balance ⇒ Object
- #raw_total ⇒ Object
- #starting_balance ⇒ Object
- #subscriptions ⇒ Object
- #subtotal ⇒ Object
- #total ⇒ Object
- #view(data) ⇒ Object
Constructor Details
#initialize(user, invoice) ⇒ Invoice
Returns a new instance of Invoice.
2 3 4 5 |
# File 'lib/invoice.rb', line 2 def initialize(user, invoice) @user = user @invoice = invoice end |
Instance Method Details
#amount_off ⇒ Object
61 62 63 64 |
# File 'lib/invoice.rb', line 61 def amount_off amount = invoice.discount.coupon.amount_off || 0 format_amount(amount) end |
#as_stripe_invoice ⇒ Object
108 109 110 |
# File 'lib/invoice.rb', line 108 def as_stripe_invoice invoice end |
#coupon ⇒ Object
45 46 47 |
# File 'lib/invoice.rb', line 45 def coupon invoice.discount.coupon.id if invoice.discount end |
#date(timezone = nil) ⇒ Object
7 8 9 |
# File 'lib/invoice.rb', line 7 def date(timezone = nil) invoice.to_time.in_time_zone(timezone).to_date end |
#discount ⇒ Object
40 41 42 43 |
# File 'lib/invoice.rb', line 40 def discount amount = invoice.subtotal - invoice.total format_amount(amount) end |
#discount_is_percentage? ⇒ Boolean
49 50 51 |
# File 'lib/invoice.rb', line 49 def discount_is_percentage? coupon and invoice.discount.coupon.percent_off end |
#download(data) ⇒ Object
100 101 102 |
# File 'lib/invoice.rb', line 100 def download(data) # Coming Soon end |
#format_amount(amount) ⇒ Object
88 89 90 |
# File 'lib/invoice.rb', line 88 def format_amount(amount) BankTeller::format_amount(amount) end |
#has_discount ⇒ Object
34 35 36 37 38 |
# File 'lib/invoice.rb', line 34 def has_discount invoice.subtotal > 0 and invoice.subtotal != invoice.total and !invoice.discount.nil? end |
#has_starting_balance? ⇒ Boolean
26 27 28 |
# File 'lib/invoice.rb', line 26 def has_starting_balance? raw_starting_balance > 0 end |
#invoice_items ⇒ Object
66 67 68 |
# File 'lib/invoice.rb', line 66 def invoice_items invoice_items_by_type('invoiceitem') end |
#invoice_items_by_type(type) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/invoice.rb', line 74 def invoice_items_by_type(type) line_items = [] if lines.data lines.data.each do |line| if line.type == type line_items << InvoiceItem.new(user, line) end end end line_items end |
#pdf(data) ⇒ Object
96 97 98 |
# File 'lib/invoice.rb', line 96 def pdf(data) # Coming Soon end |
#percent_off ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/invoice.rb', line 53 def percent_off if coupon invoice.discount.coupon.percent_off else 0 end end |
#raw_starting_balance ⇒ Object
104 105 106 |
# File 'lib/invoice.rb', line 104 def raw_starting_balance invoice.starting_balance || 0 end |
#raw_total ⇒ Object
15 16 17 18 |
# File 'lib/invoice.rb', line 15 def raw_total amount = invoice.total - (raw_starting_balance * -1) [0, amount].max end |
#starting_balance ⇒ Object
30 31 32 |
# File 'lib/invoice.rb', line 30 def starting_balance format_amount(raw_starting_balance) end |
#subscriptions ⇒ Object
70 71 72 |
# File 'lib/invoice.rb', line 70 def subscriptions invoice_items_by_type('subscription') end |
#subtotal ⇒ Object
20 21 22 23 24 |
# File 'lib/invoice.rb', line 20 def subtotal amount = invoice.subtotal - raw_starting_balance amount = [0, amount].max format_amount(amount) end |
#total ⇒ Object
11 12 13 |
# File 'lib/invoice.rb', line 11 def total format_amount(raw_total) end |
#view(data) ⇒ Object
92 93 94 |
# File 'lib/invoice.rb', line 92 def view(data) # Coming Soon end |