Class: PolishInvoicer::Invoice
- Inherits:
-
Object
- Object
- PolishInvoicer::Invoice
- Defined in:
- lib/polish_invoicer/invoice.rb
Constant Summary collapse
- AVAILABLE_PARAMS =
[ :number, # numer faktury (string) :create_date, # data wystawienia faktury (date) :trade_date, # data sprzedaży (date) :seller, # adres sprzedawcy (tablica stringów) :seller_nip, # NIP sprzedawcy (string) :buyer, # adres nabywcy (tablica stringów) :buyer_nip, # NIP nabywcy (string) :recipient, # odbiorca faktury (tablica stringów) :item_name, # nazwa usługi (string) :price, # cena w złotych (float) :gross_price, # znacznik rodzaju ceny (netto/brutto), domyślnie: true (boolean) :vat, # stawka vat, domyślnie: 23 (integer) :pkwiu, # numer PKWiU (string) :payment_type, # rodzaj płatności, domyślnie: 'Przelew' (string) :payment_date, # termin płatności (date) :comments, # uwagi (string lub tablica stringów) :paid, # znacznik opłacenia faktury, domyślnie: true (boolean) :footer, # treść umieszczana w stopce faktury (string) :proforma, # znacznik faktury pro-forma, domyślnie: false (boolean) :no_vat_reason, # podstawa prawna zwolnienia z VAT (string) ].freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
-
#wkhtmltopdf_command ⇒ Object
Returns the value of attribute wkhtmltopdf_command.
-
#wkhtmltopdf_path ⇒ Object
Returns the value of attribute wkhtmltopdf_path.
Instance Method Summary collapse
- #errors ⇒ Object
-
#gross_value ⇒ Object
cena/wartość brutto.
-
#initialize(params = {}) ⇒ Invoice
constructor
A new instance of Invoice.
-
#net_value ⇒ Object
cena/wartość netto.
- #save_to_html(path) ⇒ Object
- #save_to_pdf(path) ⇒ Object
-
#to_hash ⇒ Object
Wszystkie dane w postaci hash-a.
- #valid? ⇒ Boolean
-
#vat_value ⇒ Object
kwota VAT.
Constructor Details
#initialize(params = {}) ⇒ Invoice
Returns a new instance of Invoice.
30 31 32 33 34 35 36 37 |
# File 'lib/polish_invoicer/invoice.rb', line 30 def initialize(params = {}) set_defaults params.each do |k, v| raise "Nierozpoznany parametr #{k}" unless AVAILABLE_PARAMS.include?(k) send("#{k}=", v) end @validator = PolishInvoicer::Validator.new(self) end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
28 29 30 |
# File 'lib/polish_invoicer/invoice.rb', line 28 def logger @logger end |
#template_path ⇒ Object
Returns the value of attribute template_path.
27 28 29 |
# File 'lib/polish_invoicer/invoice.rb', line 27 def template_path @template_path end |
#wkhtmltopdf_command ⇒ Object
Returns the value of attribute wkhtmltopdf_command.
28 29 30 |
# File 'lib/polish_invoicer/invoice.rb', line 28 def wkhtmltopdf_command @wkhtmltopdf_command end |
#wkhtmltopdf_path ⇒ Object
Returns the value of attribute wkhtmltopdf_path.
28 29 30 |
# File 'lib/polish_invoicer/invoice.rb', line 28 def wkhtmltopdf_path @wkhtmltopdf_path end |
Instance Method Details
#errors ⇒ Object
39 40 41 |
# File 'lib/polish_invoicer/invoice.rb', line 39 def errors @validator.errors end |
#gross_value ⇒ Object
cena/wartość brutto
59 60 61 62 |
# File 'lib/polish_invoicer/invoice.rb', line 59 def gross_value return price if gross_price price + price * Vat.to_i(vat) / 100.0 end |
#net_value ⇒ Object
cena/wartość netto
48 49 50 51 |
# File 'lib/polish_invoicer/invoice.rb', line 48 def net_value return price unless gross_price price / (1 + Vat.to_i(vat) / 100.0) end |
#save_to_html(path) ⇒ Object
64 65 66 67 |
# File 'lib/polish_invoicer/invoice.rb', line 64 def save_to_html(path) validate! Writer.new(self).save_to_html(path) end |
#save_to_pdf(path) ⇒ Object
69 70 71 72 |
# File 'lib/polish_invoicer/invoice.rb', line 69 def save_to_pdf(path) validate! Writer.new(self).save_to_pdf(path) end |
#to_hash ⇒ Object
Wszystkie dane w postaci hash-a
75 76 77 |
# File 'lib/polish_invoicer/invoice.rb', line 75 def to_hash Presenter.new(self).data end |
#valid? ⇒ Boolean
43 44 45 |
# File 'lib/polish_invoicer/invoice.rb', line 43 def valid? @validator.valid? end |