diff --git a/Gemfile b/Gemfile index 39b8e6d..a999eb7 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,7 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development gem 'wicked_pdf' -gem 'wkhtmltopdf-binary' +#gem 'wkhtmltopdf-binary' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri diff --git a/app/assets/images/pdf.png b/app/assets/images/pdf.png new file mode 100644 index 0000000..1ef1356 Binary files /dev/null and b/app/assets/images/pdf.png differ diff --git a/app/assets/images/pdf48.png b/app/assets/images/pdf48.png new file mode 100644 index 0000000..091b540 Binary files /dev/null and b/app/assets/images/pdf48.png differ diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb index 4b34df0..c08b90f 100644 --- a/app/controllers/invoices_controller.rb +++ b/app/controllers/invoices_controller.rb @@ -6,8 +6,9 @@ class InvoicesController < ApplicationController def show @invoice = Invoice.find(params[:id]) + respond_to do |format| - format.html + format.html {@inv_format = 'html'} format.pdf do render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension. disposition: 'attachment', @@ -26,6 +27,7 @@ class InvoicesController < ApplicationController new_nr = (nr.split("/")[0].to_i + 1).to_s + "/" + nr.split("/")[1] @invoice.number = new_nr end + @invoice.invoice_products.build @user_firms = current_user.user_firms @customers = current_user.customers end @@ -67,6 +69,6 @@ class InvoicesController < ApplicationController private def invoice_params - params.require(:invoice).permit(:number, :user_firm_id, :customer_id, :date, :date_of_payment) + 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 96179e3..e3311da 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -2,7 +2,8 @@ class Invoice < ApplicationRecord belongs_to :user belongs_to :user_firm belongs_to :customer - has_many :invoice_products + has_many :invoice_products, inverse_of: :invoice + accepts_nested_attributes_for :invoice_products, allow_destroy: true def netto_amount 0.0 diff --git a/app/models/invoice_product.rb b/app/models/invoice_product.rb index 3d0b649..0258aef 100644 --- a/app/models/invoice_product.rb +++ b/app/models/invoice_product.rb @@ -1,4 +1,5 @@ class InvoiceProduct < ApplicationRecord - belongs_to :invoice + belongs_to :invoice, inverse_of: :invoice_products belongs_to :product + validates_presence_of :invoice end diff --git a/app/views/invoices/_form.html.erb b/app/views/invoices/_form.html.erb index 8394fd4..2cefb80 100644 --- a/app/views/invoices/_form.html.erb +++ b/app/views/invoices/_form.html.erb @@ -3,47 +3,70 @@ <% if @invoice.errors.any? %> <%= raw errors_to_html(@invoice.errors) %> <% end %> -