From 8a67fef286d3a140846bb55fc412b17e805949ec Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Tue, 17 Apr 2018 17:56:13 +0200 Subject: [PATCH 1/3] t --- Gemfile | 7 +++---- app/controllers/invoices_controller.rb | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 212d05d..51ce931 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,7 @@ source 'https://rubygems.org' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.1.4' +gem 'rails', '~> 5.0.0' # Use sqlite3 as the database for Active Record # gem 'sqlite3' gem 'momentjs-rails', '>= 2.9.0' @@ -11,7 +10,7 @@ gem 'devise' gem 'mysql2' # Use Puma as the app server -gem 'puma', '~> 3.7' +gem 'puma', '~> 3.0' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -32,7 +31,7 @@ gem 'jbuilder', '~> 2.5' # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' - +gem 'cocoon' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development gem 'wicked_pdf' diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 40ba83a..9416980 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -18,8 +18,8 @@ class InvoicesController < ApplicationController margin: { top: 8, # default 10 (mm) bottom: 8, left: 8, - right: 8 }, - viewport_size: '1280x1024' + right: 8 }, + viewport_size: '1336x1024' end end end From f1c1ca6202d6860a7d5333d41c2565105143f686 Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Tue, 17 Apr 2018 17:57:09 +0200 Subject: [PATCH 2/3] e --- .gitignore | 2 +- Gemfile.lock | 190 --------------------------------------------------- 2 files changed, 1 insertion(+), 191 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index ce3a6a4..dbb0e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ /tmp/* !/log/.keep !/tmp/.keep - +.tags # Ignore Byebug command history file. .byebug_history Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 714d3b4..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,190 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.0.0.1) - actionpack (= 5.0.0.1) - nio4r (~> 1.2) - websocket-driver (~> 0.6.1) - actionmailer (5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.0.0.1) - actionview (= 5.0.0.1) - activesupport (= 5.0.0.1) - rack (~> 2.0) - rack-test (~> 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.0.1) - activesupport (= 5.0.0.1) - builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.0.1) - activesupport (= 5.0.0.1) - globalid (>= 0.3.6) - activemodel (5.0.0.1) - activesupport (= 5.0.0.1) - activerecord (5.0.0.1) - activemodel (= 5.0.0.1) - activesupport (= 5.0.0.1) - arel (~> 7.0) - activesupport (5.0.0.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (7.1.2) - bcrypt (3.1.11-x64-mingw32) - bcrypt (3.1.11-x86-mingw32) - bootstrap3-datetimepicker-rails (4.14.30) - momentjs-rails (>= 2.8.1) - builder (3.2.2) - coffee-rails (4.2.1) - coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.8.0) - concurrent-ruby (1.0.2) - debug_inspector (0.0.2) - devise (4.2.0) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.1) - responders - warden (~> 1.2.3) - erubis (2.7.0) - execjs (2.7.0) - globalid (0.3.7) - activesupport (>= 4.1.0) - i18n (0.7.0) - jbuilder (2.6.0) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.2.1) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - loofah (2.0.3) - nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.9.1) - momentjs-rails (2.15.1) - railties (>= 3.1) - multi_json (1.12.1) - mysql2 (0.4.4-x64-mingw32) - mysql2 (0.4.4-x86-mingw32) - nio4r (1.2.1) - nokogiri (1.6.8-x64-mingw32) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - nokogiri (1.6.8-x86-mingw32) - mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) - orm_adapter (0.5.0) - pkg-config (1.1.7) - puma (3.6.0) - rack (2.0.1) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.0.1) - actioncable (= 5.0.0.1) - actionmailer (= 5.0.0.1) - actionpack (= 5.0.0.1) - actionview (= 5.0.0.1) - activejob (= 5.0.0.1) - activemodel (= 5.0.0.1) - activerecord (= 5.0.0.1) - activesupport (= 5.0.0.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.1) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6.0) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.0.1) - actionpack (= 5.0.0.1) - activesupport (= 5.0.0.1) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (11.3.0) - responders (2.3.0) - railties (>= 4.2.0, < 5.1) - sass (3.4.22) - sass-rails (5.0.6) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - sprockets (3.7.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.0) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - thor (0.19.1) - thread_safe (0.3.5) - tilt (2.0.5) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) - tzinfo (1.2.2) - thread_safe (~> 0.1) - tzinfo-data (1.2016.7) - tzinfo (>= 1.0.0) - uglifier (3.0.2) - execjs (>= 0.3.0, < 3) - warden (1.2.6) - rack (>= 1.0) - web-console (3.3.1) - actionview (>= 5.0) - activemodel (>= 5.0) - debug_inspector - railties (>= 5.0) - websocket-driver (0.6.4) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) - wicked_pdf (1.1.0) - -PLATFORMS - x64-mingw32 - x86-mingw32 - -DEPENDENCIES - bootstrap3-datetimepicker-rails (~> 4.14.30) - byebug - coffee-rails (~> 4.2) - coffee-script-source (= 1.8.0) - devise - jbuilder (~> 2.5) - jquery-rails - momentjs-rails (>= 2.9.0) - mysql2 - puma (~> 3.0) - rails (~> 5.0.0, >= 5.0.0.1) - sass-rails (~> 5.0) - turbolinks (~> 5) - tzinfo-data - uglifier (>= 1.3.0) - web-console - wicked_pdf - -BUNDLED WITH - 1.13.2 From 7e9544606953a1a3c8f19c81e0a740ecf39822a9 Mon Sep 17 00:00:00 2001 From: Adrian Hinz Date: Tue, 17 Apr 2018 18:21:35 +0200 Subject: [PATCH 3/3] Merge branch 'master' of ssh://51.254.143.84:9319/home/git/invoice_keeper --- app/controllers/invoices_controller.rb | 33 +++++++++++++------------- app/models/invoice.rb | 4 ++-- app/views/invoices/_show.html.erb | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 9416980..f0df12d 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -1,35 +1,32 @@ # encoding: utf-8 class InvoicesController < ApplicationController def index - @invoices = Invoice.where(user_id: current_user.id) + @invoices = Invoice.where(user_id: current_user.id).order('created_at DESC') end def show @invoice = Invoice.find(params[:id]) @vats = Vat.all respond_to do |format| - format.html {@inv_format = 'html'} + format.html { @inv_format = 'html' } format.pdf do - render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension. - disposition: 'attachment', - layout: 'pdf', - encoding: 'UTF-8', - page_size: 'A4', - margin: { top: 8, # default 10 (mm) - bottom: 8, - left: 8, - right: 8 }, - viewport_size: '1336x1024' + render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension. + disposition: 'attachment', + layout: 'pdf', + encoding: 'UTF-8', + page_size: 'A4', + margin: { top: 8, bottom: 8, left: 8, right: 8 }, + viewport_size: '1336x1024' end end end def new @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? + inv = Invoice.where('date > ?', Date.new(Date.today.year, 1, 1)).last + unless inv.blank? nr = inv.number - new_nr = (nr.split("/")[0].to_i + 1).to_s + "/" + nr.split("/")[1] + new_nr = (nr.split('/')[0].to_i + 1).to_s + '/' + nr.split('/')[1] @invoice.number = new_nr end @invoice.invoice_products.build @@ -73,7 +70,11 @@ class InvoicesController < ApplicationController end private + def invoice_params - params.require(:invoice).permit(:number, :user_firm_id, :customer_id, :date, :date_of_payment, invoice_products_attributes: [:id, :product_id, :qty, :netto_price, :_destroy]) + params.require(:invoice) + .permit(:number, :user_firm_id, :customer_id, :date, + :date_of_payment, + invoice_products_attributes: [:id, :product_id, :qty, :netto_price, :_destroy]) end end diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 19670ef..8d63e5a 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -2,11 +2,11 @@ class Invoice < ApplicationRecord belongs_to :user belongs_to :user_firm belongs_to :customer - has_many :invoice_products, inverse_of: :invoice + has_many :invoice_products, inverse_of: :invoice, dependent: :destroy accepts_nested_attributes_for :invoice_products, allow_destroy: true def netto_amount - 0.0 + invoice_products.sum('invoice_products.netto_price * invoice_products.qty') end def products_with_tax(vat_id) diff --git a/app/views/invoices/_show.html.erb b/app/views/invoices/_show.html.erb index 249d2b7..7904a77 100644 --- a/app/views/invoices/_show.html.erb +++ b/app/views/invoices/_show.html.erb @@ -166,7 +166,7 @@ Kwota do zapłaty: <%= number_with_precision(total_arr[2], delimiter: " ", separator: ",", precision: 2) %> PLN - Słownie do zapłaty: <%= decimal_to_word(total_arr[2]) %> + Słownie do zapłaty: <%= decimal_to_word(('%.2f' % total_arr[2]).to_f) %> Forma płatności: Przelew