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 %> -
-
- <%= f.label :number, class: "col-sm-2 control-label" %> -
- <%= f.text_field :number, class: "form-control", placeholder: 'Numer faktury' %> +
+ Dane do faktury +
+
+ <%= 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' %> - - - - +
+ <%= 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_of_payment, class: "col-sm-2 control-label" %> -
-
- <%= f.text_field :date_of_payment, class: "form-control datepicker", placeholder: 'Data wystawienia' %> - - - - +
+ <%= f.label :date, class: "col-sm-2 control-label" %> +
+
+ <%= f.text_field :date, class: "form-control datepicker", placeholder: 'Data wystawienia' %> + + + + +
+
+ <%= f.label :date_of_payment, class: "col-sm-2 control-label" %> +
+
+ <%= f.text_field :date_of_payment, class: "form-control datepicker", placeholder: 'Data wystawienia' %> + + + + +
-
- + +
+ Produkty/Usługi +
+ <%= f.fields_for :invoice_products do |invoice_products_form| %> +
+
+ <%= invoice_products_form.select :product_id, Product.where(user_id: current_user.id).collect {|p| [ p.name, p.id ] }, {include_blank: true}, {class: "form-control"} %> +
+
+ <%= invoice_products_form.text_field :qty, class: "form-control", placeholder: 'Ilość' %> +
+
+ <%= invoice_products_form.text_field :netto_price, class: "form-control", placeholder: 'Wartość netto' %> +
+
+ <%= invoice_products_form.check_box :_destroy%> +
+
+ <% end %> +
+
<%= f.submit 'Zapisz', class: "btn btn-primary" %> diff --git a/app/views/invoices/_show.html.erb b/app/views/invoices/_show.html.erb index 40a177f..e4aebec 100644 --- a/app/views/invoices/_show.html.erb +++ b/app/views/invoices/_show.html.erb @@ -1,7 +1,13 @@
-
+
+ <% unless @inv_format.blank? %> +
+ <%= link_to image_tag("pdf48.png", height: "24") + ' PDF', invoice_path(@invoice, format: :pdf) %> +
+ <% end %> +
@@ -80,7 +86,7 @@ PKWiU Ilość j.m. - Cena netto + Cena jed. netto %VAT Wartość netto Kwota VAT @@ -88,18 +94,21 @@ + + <%= @invoice.invoice_products.each_with_index do |invoice_product, index| %> - 1 - Usługa transportowa + <%= index + 1 %> + <%= invoice_product.product.name %> - 1 - szt. - 10 000,00 - 23% - 10 000,00 - 2 300,00 - 12 300,00 + <%= number_with_delimiter(invoice_product.qty, delimiter: " ", separator: ",") %> + <%= invoice_product.product.qnt_name %> + <%= number_with_precision(invoice_product.netto_price, delimiter: " ", separator: ",", precision: 2) %> + <%= invoice_product.product.vat.name %> + <%= number_with_precision(invoice_product.netto_price * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %> + <%= number_with_precision((invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100)) * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %> + <%= number_with_precision((invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100 + 1)) * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %> + <% end %> 2 Usługa informatyczna diff --git a/app/views/invoices/show.html.erb b/app/views/invoices/show.html.erb index afd1c0a..941e44a 100644 --- a/app/views/invoices/show.html.erb +++ b/app/views/invoices/show.html.erb @@ -3,7 +3,6 @@
Faktura: <%= @invoice.number %>
<%= link_to raw(" " + I18n.t('back')), invoices_path, title: I18n.t('back'), class: "text-primary" %> - <%= link_to 'PDF', invoice_path(@invoice, format: :pdf) %>