This commit is contained in:
Sewer Aplikacji 2016-10-10 11:52:43 +02:00
commit 36efe9425d
9 changed files with 89 additions and 54 deletions

View File

@ -36,7 +36,7 @@ gem 'jbuilder', '~> 2.5'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
gem 'wicked_pdf' gem 'wicked_pdf'
gem 'wkhtmltopdf-binary', '0.9.9' #gem 'wkhtmltopdf-binary'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri gem 'byebug', platform: :mri

BIN
app/assets/images/pdf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
app/assets/images/pdf48.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -6,8 +6,9 @@ class InvoicesController < ApplicationController
def show def show
@invoice = Invoice.find(params[:id]) @invoice = Invoice.find(params[:id])
respond_to do |format| respond_to do |format|
format.html format.html {@inv_format = 'html'}
format.pdf do format.pdf do
render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension. render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension.
disposition: 'attachment', disposition: 'attachment',
@ -26,6 +27,7 @@ class InvoicesController < ApplicationController
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 @invoice.number = new_nr
end end
@invoice.invoice_products.build
@user_firms = current_user.user_firms @user_firms = current_user.user_firms
@customers = current_user.customers @customers = current_user.customers
end end
@ -67,6 +69,6 @@ class InvoicesController < ApplicationController
private private
def invoice_params 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
end end

View File

@ -2,7 +2,8 @@ class Invoice < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :user_firm belongs_to :user_firm
belongs_to :customer 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 def netto_amount
0.0 0.0

View File

@ -1,4 +1,5 @@
class InvoiceProduct < ApplicationRecord class InvoiceProduct < ApplicationRecord
belongs_to :invoice belongs_to :invoice, inverse_of: :invoice_products
belongs_to :product belongs_to :product
validates_presence_of :invoice
end end

View File

@ -3,47 +3,70 @@
<% if @invoice.errors.any? %> <% if @invoice.errors.any? %>
<%= raw errors_to_html(@invoice.errors) %> <%= raw errors_to_html(@invoice.errors) %>
<% end %> <% end %>
<div class="form-group"> <fieldset>
<div class="col-sm-3"></div> <legend>Dane do faktury</legend>
<%= f.label :number, class: "col-sm-2 control-label" %> <div class="form-group">
<div class="col-sm-4"> <div class="col-sm-3"></div>
<%= f.text_field :number, class: "form-control", placeholder: 'Numer faktury' %> <%= f.label :number, class: "col-sm-2 control-label" %>
<div class="col-sm-4">
<%= f.text_field :number, class: "form-control", placeholder: 'Numer faktury' %>
</div>
<div class="col-sm-3"></div>
</div> </div>
<div class="col-sm-3"></div> <div class="form-group">
</div> <%= f.label :user_firm, class: "col-sm-2 control-label" %>
<div class="form-group"> <div class="col-sm-4">
<%= 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"} %>
<div class="col-sm-4"> </div>
<%= 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" %>
</div> <div class="col-sm-4">
<%= 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"} %>
<div class="col-sm-4">
<%= f.select :customer_id, @customers.collect {|c| [ c.name, c.id ] }, {include_blank: true}, {class: "form-control"} %>
</div>
</div>
<div class="form-group">
<%= f.label :date, class: "col-sm-2 control-label" %>
<div class="col-sm-4">
<div class="input-group date">
<%= f.text_field :date, class: "form-control datepicker", placeholder: 'Data wystawienia' %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">
</span>
</span>
</div> </div>
</div> </div>
<%= f.label :date_of_payment, class: "col-sm-2 control-label" %> <div class="form-group">
<div class="col-sm-4"> <%= f.label :date, class: "col-sm-2 control-label" %>
<div class="input-group date"> <div class="col-sm-4">
<%= f.text_field :date_of_payment, class: "form-control datepicker", placeholder: 'Data wystawienia' %> <div class="input-group date">
<span class="input-group-addon"> <%= f.text_field :date, class: "form-control datepicker", placeholder: 'Data wystawienia' %>
<span class="glyphicon glyphicon-calendar"> <span class="input-group-addon">
</span> <span class="glyphicon glyphicon-calendar">
</span> </span>
</span>
</div>
</div>
<%= f.label :date_of_payment, class: "col-sm-2 control-label" %>
<div class="col-sm-4">
<div class="input-group date">
<%= f.text_field :date_of_payment, class: "form-control datepicker", placeholder: 'Data wystawienia' %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">
</span>
</span>
</div>
</div> </div>
</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="form-group">
<div class="col-sm-offset-2 col-sm-10"> <div class="col-sm-offset-2 col-sm-10">
<%= f.submit 'Zapisz', class: "btn btn-primary" %> <%= f.submit 'Zapisz', class: "btn btn-primary" %>

View File

@ -1,7 +1,13 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="content-box-large"> <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="panel-body">
<div class="row"> <div class="row">
<div class="col-md-7"></div> <div class="col-md-7"></div>
@ -21,7 +27,7 @@
<div class="col-md-12"><h1>&nbsp;</h1></div> <div class="col-md-12"><h1>&nbsp;</h1></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12 text-center"><h1>Faktura VAT nr <%= @invoice.number %></h1></div> <div class="col-md-12 text-center"><span style="font-size:32px;">Faktura VAT nr <%= @invoice.number %></span><br/><span style="font-size:14px;">ORYGINAŁ / KOPIA</span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-12"><h1>&nbsp;</h1></div> <div class="col-md-12"><h1>&nbsp;</h1></div>
@ -80,7 +86,7 @@
<th>PKWiU</th> <th>PKWiU</th>
<th>Ilość</th> <th>Ilość</th>
<th>j.m.</th> <th>j.m.</th>
<th>Cena netto</th> <th>Cena jed. netto</th>
<th>%VAT</th> <th>%VAT</th>
<th>Wartość netto</th> <th>Wartość netto</th>
<th>Kwota VAT</th> <th>Kwota VAT</th>
@ -88,18 +94,21 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<%= @invoice.invoice_products.each_with_index do |invoice_product, index| %>
<tr> <tr>
<td>1</td> <td><%= index + 1 %></td>
<td>Usługa transportowa</td> <td><%= invoice_product.product.name %></td>
<td></td> <td></td>
<td class="text-right">1</td> <td class="text-right"><%= number_with_delimiter(invoice_product.qty, delimiter: " ", separator: ",") %></td>
<td class="text-right">szt.</td> <td class="text-right"><%= invoice_product.product.qnt_name %></td>
<td class="text-right">10 000,00</td> <td class="text-right"><%= number_with_precision(invoice_product.netto_price, delimiter: " ", separator: ",", precision: 2) %></td>
<td class="text-right">23%</td> <td class="text-right"><%= invoice_product.product.vat.name %></td>
<td class="text-right">10 000,00</td> <td class="text-right"><%= number_with_precision(invoice_product.netto_price * invoice_product.qty, delimiter: " ", separator: ",", precision: 2) %></td>
<td class="text-right">2 300,00</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">12 300,00</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> </tr>
<% end %>
<tr> <tr>
<td>2</td> <td>2</td>
<td>Usługa informatyczna</td> <td>Usługa informatyczna</td>

View File

@ -3,7 +3,6 @@
<div class="panel-title">Faktura: <%= @invoice.number %></div> <div class="panel-title">Faktura: <%= @invoice.number %></div>
<div class="panel-options"> <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 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> </div>
<div class="content-box-large box-with-header" style="background:#dddddd"> <div class="content-box-large box-with-header" style="background:#dddddd">