Class: PolishInvoicer::Invoice

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#loggerObject

Returns the value of attribute logger.



28
29
30
# File 'lib/polish_invoicer/invoice.rb', line 28

def logger
  @logger
end

#template_pathObject

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_commandObject

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_pathObject

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

#errorsObject



39
40
41
# File 'lib/polish_invoicer/invoice.rb', line 39

def errors
  @validator.errors
end

#gross_valueObject

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_valueObject

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_hashObject

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/polish_invoicer/invoice.rb', line 43

def valid?
  @validator.valid?
end

#vat_valueObject

kwota VAT



54
55
56
# File 'lib/polish_invoicer/invoice.rb', line 54

def vat_value
  (gross_value * Vat.to_i(vat)) / (100.0 + Vat.to_i(vat))
end