diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 094738e..688327d 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -8,7 +8,13 @@ class InvoicesController < ApplicationController end def new - @invoice = Invoice.new(date: Date.today) + @invoice = Invoice.new(date: Date.today, date_of_payment: Date.today + 14.days) + inv = Invoice.where('date > ?', Date.new(Date.today.year,1,1)).last + if !inv.blank? + nr = inv.number + new_nr = (nr.split("/")[0].to_i + 1).to_s + "/" + nr.split("/")[1] + @invoice.number = new_nr + end @user_firms = current_user.user_firms @customers = current_user.customers end @@ -28,7 +34,7 @@ class InvoicesController < ApplicationController def edit @invoice = Invoice.find(params[:id]) @user_firms = current_user.user_firms - @customers = current_user.customers + @customers = current_user.customers end def update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aab0ab5..0b85755 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -25,13 +25,73 @@ module ApplicationHelper def errors_to_html(errors) ret = '
' - ret += I18n.t('activerecord.errors.messages.record_invalid', errors: errors.count) + ret += I18n.t("activerecord.errors.messages.record_invalid", errors: errors.count) ret += '
    ' errors.full_messages.each do |msg| ret += "
  • #{msg}
  • " end - ret += '
' + ret += "" ret end + def decimal_to_word(dec) + singles = ["", " #{I18n.t('numbers.one')}", " #{I18n.t('numbers.two')}", " #{I18n.t('numbers.three')}", " #{I18n.t('numbers.four')}", + " #{I18n.t('numbers.five')}", " #{I18n.t('numbers.six')}", " #{I18n.t('numbers.seven')}", " #{I18n.t('numbers.eight')}", " #{I18n.t('numbers.nine')}"] + teens = ["", " #{I18n.t('numbers.eleven')}", " #{I18n.t('numbers.twelve')}", " #{I18n.t('numbers.thirteen')}", " #{I18n.t('numbers.fourteen')}", + " #{I18n.t('numbers.fifteen')}", " #{I18n.t('numbers.sixteen')}", " #{I18n.t('numbers.seventeen')}", " #{I18n.t('numbers.eighteen')}", " #{I18n.t('numbers.nineteen')}"] + tens = ["", " #{I18n.t('numbers.ten')}", " #{I18n.t('numbers.twenty')}", " #{I18n.t('numbers.thirty')}", " #{I18n.t('numbers.fourty')}", + " #{I18n.t('numbers.fifty')}", " #{I18n.t('numbers.sixty')}", " #{I18n.t('numbers.seventy')}", " #{I18n.t('numbers.eighty')}", " #{I18n.t('numbers.ninety')}"] + hundreds = ["", " #{I18n.t('numbers.hundred')}", " #{I18n.t('numbers.two_hundred')}", " #{I18n.t('numbers.three_hundred')}", " #{I18n.t('numbers.four_hundred')}", + " #{I18n.t('numbers.five_hundred')}", " #{I18n.t('numbers.six_hundred')}", " #{I18n.t('numbers.seven_hudred')}", " #{I18n.t('numbers.eight_hundred')}", " #{I18n.t('numbers.nine_hundred')}"] + groups = Array.new + groups << ["" ,"" ,""] + groups << [" #{I18n.t('numbers.thousand')}" ," #{I18n.t('numbers.thousand1')}" ," #{I18n.t('numbers.thousand2')}"] + groups << [" #{I18n.t('numbers.milion')}" ," #{I18n.t('numbers.milion1')}" ," #{I18n.t('numbers.milion2')}"] + groups << [" #{I18n.t('numbers.miliard')}"," #{I18n.t('numbers.miliard1')}"," #{I18n.t('numbers.miliard2')}"] + groups << [" #{I18n.t('numbers.bilion')}" ," #{I18n.t('numbers.bilion1')}" ," #{I18n.t('numbers.bilion2')}"] + groups << [" #{I18n.t('numbers.biliard')}"," #{I18n.t('numbers.biliard1')}"," #{I18n.t('numbers.biliard2')}"] + groups << [" #{I18n.t('numbers.trylion')}"," #{I18n.t('numbers.trylion1')}"," #{I18n.t('numbers.trylion2')}"] + + ret = "" + number = dec.to_i + rest = (dec * 100) % 100 + if number == 0 + ret = "#{I18n.t('numbers.zero')}" + else + if number < 0 + sign = "#{I18n.t('numbers.minus')}" + number = -number + else + sign = "" + end + g = 0 + while number != 0 + s = (number % 1000) / 100 + d = (number % 100) / 10 + j = (number % 10) + if d == 1 && j > 0 + n = j + d = 0 + j = 0 + else + n = 0 + end + if j == 1 && s+d+n == 0 + k = 0 + elsif j == 2 || j == 3 || j == 4 + k = 1 + else + k = 2 + end + ret = hundreds[s] + tens[d] + teens[n] + singles[j] + groups[g][k] + ret + g = g + 1 + number = number / 1000 + end + end + ret = sign + ret + ret += " PLN #{rest.to_i}/100" + return ret + end + + end diff --git a/app/views/invoices/_form.html.erb b/app/views/invoices/_form.html.erb index 8fb31aa..8394fd4 100644 --- a/app/views/invoices/_form.html.erb +++ b/app/views/invoices/_form.html.erb @@ -4,26 +4,26 @@ <%= raw errors_to_html(@invoice.errors) %> <% end %>
+
<%= f.label :number, class: "col-sm-2 control-label" %> -
+
<%= f.text_field :number, class: "form-control", placeholder: 'Numer faktury' %>
+
<%= f.label :user_firm, class: "col-sm-2 control-label" %> -
+
<%= f.select :user_firm_id, @user_firms.collect {|uf| [ uf.name, uf.id ] }, {}, {class: "form-control"} %>
-
-
<%= f.label :customer, class: "col-sm-2 control-label" %> -
+
<%= f.select :customer_id, @customers.collect {|c| [ c.name, c.id ] }, {include_blank: true}, {class: "form-control"} %>
<%= f.label :date, class: "col-sm-2 control-label" %> -
+
<%= f.text_field :date, class: "form-control datepicker", placeholder: 'Data wystawienia' %> @@ -32,6 +32,16 @@
+ <%= f.label :date_of_payment, class: "col-sm-2 control-label" %> +
+
+ <%= f.text_field :date_of_payment, class: "form-control datepicker", placeholder: 'Data wystawienia' %> + + + + +
+
@@ -43,7 +53,6 @@ $(function() { // Bootstrap DateTimePicker v4 $('.datepicker').datetimepicker({ - useCurrent: true, locale: 'pl', format: 'YYYY-MM-DD' }); diff --git a/app/views/invoices/_show.html.erb b/app/views/invoices/_show.html.erb index b09cef5..946ee9f 100644 --- a/app/views/invoices/_show.html.erb +++ b/app/views/invoices/_show.html.erb @@ -1,15 +1,160 @@
-
-
Faktura VAT
- -
+
- Ut tristique adipiscing mauris, sit amet suscipit metus porta quis. Donec dictum tincidunt erat, eu blandit ligula. Nam sit amet dolor sapien. Quisque velit erat, congue sed suscipit vel, feugiat sit amet enim. Suspendisse interdum enim at mi tempor commodo. Sed tincidunt sed tortor eu scelerisque. Donec luctus malesuada vulputate. Nunc vel auctor metus, vel adipiscing odio. Aliquam aliquet rhoncus libero, at varius nisi pulvinar nec. Aliquam erat volutpat. Donec ut neque mi. Praesent enim nisl, bibendum vitae ante et, placerat pharetra magna. Donec facilisis nisl turpis, eget facilisis turpis semper non. Maecenas luctus ligula tincidunt iasdsd vitae ante et, -

- Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque sed consectetur erat. Maecenas in elementum libero. Sed consequat pellentesque ultricies. Ut laoreet vehicula nisl sed placerat. Duis posuere lectus n, eros et hendrerit pellentesque, ante magna condimentum sapien, eget ultrices eros libero non orci. Etiam varius diam lectus. -

+
+
+
+
+
Miejsce wystawienia
<%= 'Rumia' %>
+
+
+
Data wystawienia
<%= @invoice.date %>
+
+
+
Data sprzedaży
<%= @invoice.date %>
+
+
+
+
+

 

+
+
+

Faktura VAT nr <%= @invoice.number %>

+
+
+

 

+
+
+
+
+

Sprzedawca:

+
+
+

<%= @invoice.user_firm.name %>

+
+
+

<%= @invoice.user_firm.street %>

+
+
+

<%= @invoice.user_firm.postcode %> <%= @invoice.user_firm.city %>

+
+
+

NIP: <%= @invoice.user_firm.nip %>

+
+ +
+
+
+

Nabywca:

+
+
+

<%= @invoice.customer.name %>

+
+
+

<%= @invoice.customer.street %>

+
+
+

<%= @invoice.customer.postcode %> <%= @invoice.user_firm.city %>

+
+
+

NIP: <%= @invoice.customer.nip %>

+
+
+
+
+

 

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LpNazwa towaru/usługiPKWiUIlośćj.m.Cena netto%VATWartość nettoKwota VATWartość brutto
1Usługa transportowa1szt.10 000,0023%10 000,002 300,0012 300,00
2Usługa informatyczna1szt.10 000,0023%10 000,002 300,0012 300,00
3Usługa towarowa1szt.10 000,0023%10 000,002 300,0012 300,00
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
Podsumowanie wg stawki VATWartość nettoKwota VATWartość brutto
Podatek VAT 23%30 000,006 900,0036 900,00
Razem:30 000,006 900,0036 900,00
+
+
diff --git a/app/views/invoices/index.html.erb b/app/views/invoices/index.html.erb index 9ccb0ca..bfb40e2 100644 --- a/app/views/invoices/index.html.erb +++ b/app/views/invoices/index.html.erb @@ -19,7 +19,7 @@ <% @invoices.each do |invoice| %> - <%= invoice.number %> + <%= link_to invoice.number, invoice_path(invoice) %> <%= invoice.customer.name %> <%= number_with_precision(invoice.netto_amount, precision: 2) %> <%= invoice.date %> diff --git a/app/views/invoices/new.html.erb b/app/views/invoices/new.html.erb index 904c62b..931144a 100644 --- a/app/views/invoices/new.html.erb +++ b/app/views/invoices/new.html.erb @@ -1,4 +1,4 @@ -
+
Nowa faktura
diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 10539a4..8f7d1de 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -20,6 +20,8 @@
+ <%= decimal_to_word(127786.9) %>
+ <%= decimal_to_word(599.99) %>
Pellentesque luctus quam quis consequat vulputate. Sed sit amet diam ipsum.
diff --git a/config/locales/pl.yml b/config/locales/pl.yml index de3169f..91422f0 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -252,3 +252,60 @@ pl: long: "%B %d, %Y %H:%M" short: "%d %b %H:%M" pm: po południu + numbers: + minus: 'minus' + zero: 'zero' + one: 'jeden' + two: 'dwa' + three: 'trzy' + four: 'cztery' + five: 'pięć' + six: 'sześć' + seven: 'siedem' + eight: 'osiem' + nine: 'dziewięć' + eleven: 'jedenaście' + twelve: 'dwanaście' + thirteen: 'trzynaście' + fourteen: 'czternaście' + fifteen: 'piętnaście' + sixteen: 'szesnaście' + seventeen: 'siedemnaście' + eighteen: 'osiemnaście' + nineteen: 'dziewiętnaście' + ten: 'dziesięć' + twenty: 'dwadzieścia' + thirty: 'trzydzieści' + fourty: 'czterdzieści' + fifty: 'pięćdziesiąt' + sixty: 'sześćdziesiąt' + seventy: 'siedemdziesiąt' + eighty: 'osiemdziesiąt' + ninety: 'dziewięćdziesiąt' + hundred: 'sto' + two_hudred: 'dwieście' + three_hundred: 'trzysta' + four_hundred: 'czterysta' + five_hundred: 'pięćset' + six_hundred: 'sześćset' + seven_hudred: 'siedemset' + eight_hundred: 'osiemset' + nine_hundred: 'dziewięćset' + thousand: 'tysiąc' + thousand1: 'tysiące' + thousand2: 'tysięcy' + milion: 'milion' + milion1: 'miliony' + milion2: 'milionów' + miliard: 'miliard' + miliard1: 'miliardy' + miliard2: 'miliardów' + bilion: 'bilion' + bilion1: 'biliony' + bilion2: 'bilionów' + biliard: 'biliard' + biliard1: 'biliardy' + biliard2: 'biliardów' + trylion: 'trylion' + trylion1: 'tryliony' + trylion2: 'tryliardów'