Class: PolishInvoicer::Invoice
- Inherits:
-
Object
- Object
- PolishInvoicer::Invoice
- Defined in:
- lib/polish_invoicer/invoice.rb
Constant Summary collapse
- AVAILABLE_PARAMS =
[ :number, # numer faktury (string) :ksef_number, # numer faktury w KSeF (string) :ksef_qr_code_url, # adres URL kodu QR dla faktury w KSeF :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) :price_paid, # kwota częściowego opłacenia faktury w złotych :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) :foreign_buyer, # nabywcą jest firma spoza Polski, domyślnie: false (boolean) :lang, # język na fakturze, domyślnie: zależny od ustawienia foreign_buyer # foreign_buyer = false => lang = 'pl' # foreign_buyer = true => lang = 'pl_en' # możliwe wartości: pl | pl_en | en | es :reverse_charge, # faktura z odwrotnym obciążeniem VAT :vat_cash_accounting, # faktura z metodą kasową :prepayment_invoice, # faktura zaliczkowa :currency, # waluta rozliczeniowa, domyślnie: PLN (string) :exchange_rate # kurs waluty rozliczeniowej, domyślnie: 1.0000 (float) ].freeze
Instance Method Summary collapse
- #errors ⇒ Object
- #exchanged_tax ⇒ Object
-
#gross_value ⇒ Object
cena/wartość brutto.
-
#initialize(params = {}) ⇒ Invoice
constructor
A new instance of Invoice.
-
#net_value ⇒ Object
cena/wartość netto.
- #paid_value ⇒ Object
- #qr_code_data_url ⇒ Object
- #save_to_html(path) ⇒ Object
- #save_to_pdf(path) ⇒ Object
- #template_file ⇒ Object
- #template_lang ⇒ Object
-
#to_hash ⇒ Object
Wszystkie dane w postaci hash-a.
- #to_pay_value ⇒ Object
- #total_to_pay_value ⇒ Object
- #valid? ⇒ Boolean
-
#vat_value ⇒ Object
kwota VAT.
Constructor Details
#initialize(params = {}) ⇒ Invoice
Returns a new instance of Invoice.
43 44 45 46 47 48 49 50 51 |
# File 'lib/polish_invoicer/invoice.rb', line 43 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 Method Details
#errors ⇒ Object
53 54 55 |
# File 'lib/polish_invoicer/invoice.rb', line 53 def errors @validator.errors end |
#exchanged_tax ⇒ Object
95 96 97 |
# File 'lib/polish_invoicer/invoice.rb', line 95 def exchanged_tax (vat_value * exchange_rate) end |
#gross_value ⇒ Object
cena/wartość brutto
74 75 76 77 78 |
# File 'lib/polish_invoicer/invoice.rb', line 74 def gross_value return price if gross_price price + (price * Vat.to_i(vat) / 100.0) end |
#net_value ⇒ Object
cena/wartość netto
62 63 64 65 66 |
# File 'lib/polish_invoicer/invoice.rb', line 62 def net_value return price unless gross_price price / (1 + (Vat.to_i(vat) / 100.0)) end |
#paid_value ⇒ Object
103 104 105 |
# File 'lib/polish_invoicer/invoice.rb', line 103 def paid_value paid ? total_to_pay_value : price_paid.to_f end |
#qr_code_data_url ⇒ Object
119 120 121 122 123 |
# File 'lib/polish_invoicer/invoice.rb', line 119 def qr_code_data_url return unless ksef_qr_code_url RQRCode::QRCode.new(ksef_qr_code_url).as_png(size: 220).to_data_url end |
#save_to_html(path) ⇒ Object
80 81 82 83 |
# File 'lib/polish_invoicer/invoice.rb', line 80 def save_to_html(path) validate! Writer.new(self).save_to_html(path) end |
#save_to_pdf(path) ⇒ Object
85 86 87 88 |
# File 'lib/polish_invoicer/invoice.rb', line 85 def save_to_pdf(path) validate! Writer.new(self).save_to_pdf(path) end |
#template_file ⇒ Object
115 116 117 |
# File 'lib/polish_invoicer/invoice.rb', line 115 def template_file proforma ? "proforma-#{template_lang}.slim" : "invoice-#{template_lang}.slim" end |
#template_lang ⇒ Object
111 112 113 |
# File 'lib/polish_invoicer/invoice.rb', line 111 def template_lang lang || (foreign_buyer ? 'pl_en' : 'pl') end |
#to_hash ⇒ Object
Wszystkie dane w postaci hash-a
91 92 93 |
# File 'lib/polish_invoicer/invoice.rb', line 91 def to_hash Presenter.new(self).data end |
#to_pay_value ⇒ Object
107 108 109 |
# File 'lib/polish_invoicer/invoice.rb', line 107 def to_pay_value paid ? 0 : (total_to_pay_value - price_paid.to_f) end |
#total_to_pay_value ⇒ Object
99 100 101 |
# File 'lib/polish_invoicer/invoice.rb', line 99 def total_to_pay_value reverse_charge ? net_value : gross_value end |
#valid? ⇒ Boolean
57 58 59 |
# File 'lib/polish_invoicer/invoice.rb', line 57 def valid? @validator.valid? end |