Module: Payday::Invoiceable
- Included in:
- Invoice
- Defined in:
- lib/payday/invoiceable.rb
Instance Method Summary collapse
-
#bill_to ⇒ Object
Who the invoice is being sent to.
-
#each_detail(&block) ⇒ Object
Iterates through the details on this invoiceable.
- #overdue? ⇒ Boolean
- #paid? ⇒ Boolean
- #refunded? ⇒ Boolean
-
#render_pdf ⇒ Object
Renders this invoice to pdf as a string.
-
#render_pdf_to_file(path) ⇒ Object
Renders this invoice to pdf.
-
#shipping ⇒ Object
TODO: Add a per weight unit shipping cost Calculates the shipping.
-
#subtotal ⇒ Object
Calculates the subtotal of this invoice by adding up all of the line items.
-
#tax ⇒ Object
The tax for this invoice, as a BigDecimal.
-
#total ⇒ Object
Calculates the total for this invoice.
Instance Method Details
#bill_to ⇒ Object
Who the invoice is being sent to.
24 25 26 |
# File 'lib/payday/invoiceable.rb', line 24 def bill_to "Goofy McGoofison\nYour Invoice Doesn't\nHave It's Own BillTo Method" end |
#each_detail(&block) ⇒ Object
Iterates through the details on this invoiceable. The block given should accept two parameters, the detail name and the actual detail value.
83 84 85 86 87 88 89 |
# File 'lib/payday/invoiceable.rb', line 83 def each_detail(&block) return if defined?(invoice_details).nil? invoice_details.each do |detail| block.call(detail[0], detail[1]) end end |
#overdue? ⇒ Boolean
57 58 59 60 61 |
# File 'lib/payday/invoiceable.rb', line 57 def overdue? # rubocop:todo Layout/LineLength defined?(due_at) && ((due_at.is_a?(Date) && due_at < Date.today) || (due_at.is_a?(Time) && due_at < Time.now)) && !paid_at # rubocop:enable Layout/LineLength end |
#paid? ⇒ Boolean
67 68 69 |
# File 'lib/payday/invoiceable.rb', line 67 def paid? defined?(paid_at) && !!paid_at end |
#refunded? ⇒ Boolean
63 64 65 |
# File 'lib/payday/invoiceable.rb', line 63 def refunded? defined?(refunded_at) && !!refunded_at end |
#render_pdf ⇒ Object
Renders this invoice to pdf as a string
72 73 74 |
# File 'lib/payday/invoiceable.rb', line 72 def render_pdf Payday::PdfRenderer.render(self) end |
#render_pdf_to_file(path) ⇒ Object
Renders this invoice to pdf
77 78 79 |
# File 'lib/payday/invoiceable.rb', line 77 def render_pdf_to_file(path) Payday::PdfRenderer.render_to_file(self, path) end |
#shipping ⇒ Object
TODO: Add a per weight unit shipping cost Calculates the shipping
44 45 46 47 48 49 50 |
# File 'lib/payday/invoiceable.rb', line 44 def shipping if defined?(shipping_rate) shipping_rate else 0 end end |
#subtotal ⇒ Object
Calculates the subtotal of this invoice by adding up all of the line items
29 30 31 |
# File 'lib/payday/invoiceable.rb', line 29 def subtotal line_items.reduce(BigDecimal('0')) { |result, item| result + item.amount } end |
#tax ⇒ Object
The tax for this invoice, as a BigDecimal
34 35 36 37 38 39 40 |
# File 'lib/payday/invoiceable.rb', line 34 def tax if defined?(tax_rate) subtotal * tax_rate / 100 else 0 end end |
#total ⇒ Object
Calculates the total for this invoice.
53 54 55 |
# File 'lib/payday/invoiceable.rb', line 53 def total subtotal + tax + shipping end |