Signed-off-by: Adrian Hinz <adhinz@gmail.com>
This commit is contained in:
parent
86d9bcd332
commit
303ae2e174
2
Gemfile
2
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
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
<% if @invoice.errors.any? %>
|
||||
<%= raw errors_to_html(@invoice.errors) %>
|
||||
<% end %>
|
||||
<fieldset>
|
||||
<legend>Dane do faktury</legend>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-3"></div>
|
||||
<%= f.label :number, class: "col-sm-2 control-label" %>
|
||||
|
|
@ -43,7 +45,28 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fildset>
|
||||
<fieldset>
|
||||
<legend>Produkty/Usługi</legend>
|
||||
<div id="inv_products">
|
||||
<%= f.fields_for :invoice_products do |invoice_products_form| %>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-5">
|
||||
<%= 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"} %>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<%= invoice_products_form.text_field :qty, class: "form-control", placeholder: 'Ilość' %>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<%= invoice_products_form.text_field :netto_price, class: "form-control", placeholder: 'Wartość netto' %>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<%= invoice_products_form.check_box :_destroy%>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<%= f.submit 'Zapisz', class: "btn btn-primary" %>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="content-box-large">
|
||||
<div class="panel-heading"></div>
|
||||
<div class="panel-heading">
|
||||
<% unless @inv_format.blank? %>
|
||||
<div class="panel-options">
|
||||
<%= link_to image_tag("pdf48.png", height: "24") + ' PDF', invoice_path(@invoice, format: :pdf) %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-md-7"></div>
|
||||
|
|
@ -80,7 +86,7 @@
|
|||
<th>PKWiU</th>
|
||||
<th>Ilość</th>
|
||||
<th>j.m.</th>
|
||||
<th>Cena netto</th>
|
||||
<th>Cena jed. netto</th>
|
||||
<th>%VAT</th>
|
||||
<th>Wartość netto</th>
|
||||
<th>Kwota VAT</th>
|
||||
|
|
@ -88,18 +94,21 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<%= @invoice.invoice_products.each_with_index do |invoice_product, index| %>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Usługa transportowa</td>
|
||||
<td><%= index + 1 %></td>
|
||||
<td><%= invoice_product.product.name %></td>
|
||||
<td></td>
|
||||
<td class="text-right">1</td>
|
||||
<td class="text-right">szt.</td>
|
||||
<td class="text-right">10 000,00</td>
|
||||
<td class="text-right">23%</td>
|
||||
<td class="text-right">10 000,00</td>
|
||||
<td class="text-right">2 300,00</td>
|
||||
<td class="text-right">12 300,00</td>
|
||||
<td class="text-right"><%= number_with_delimiter(invoice_product.qty, delimiter: " ", separator: ",") %></td>
|
||||
<td class="text-right"><%= invoice_product.product.qnt_name %></td>
|
||||
<td class="text-right"><%= number_with_precision(invoice_product.netto_price, delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
<td class="text-right"><%= invoice_product.product.vat.name %></td>
|
||||
<td class="text-right"><%= number_with_precision(invoice_product.netto_price * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
<td class="text-right"><%= number_with_precision((invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100)) * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
<td class="text-right"><%= number_with_precision((invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100 + 1)) * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Usługa informatyczna</td>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
<div class="panel-title">Faktura: <%= @invoice.number %></div>
|
||||
<div class="panel-options">
|
||||
<%= link_to raw("<i class=\"glyphicon glyphicon-arrow-left text-success\"></i> " + I18n.t('back')), invoices_path, title: I18n.t('back'), class: "text-primary" %>
|
||||
<%= link_to 'PDF', invoice_path(@invoice, format: :pdf) %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-box-large box-with-header" style="background:#dddddd">
|
||||
|
|
|
|||
Loading…
Reference in New Issue