Signed-off-by: Adrian Hinz <ahinz@voicetelecom.pl>
This commit is contained in:
parent
be230631ee
commit
536a0fb168
|
|
@ -17,3 +17,4 @@
|
|||
//= require bootstrap-datetimepicker
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
||||
//= require cocoon
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class InvoicesController < ApplicationController
|
|||
|
||||
def show
|
||||
@invoice = Invoice.find(params[:id])
|
||||
|
||||
@vats = Vat.all
|
||||
respond_to do |format|
|
||||
format.html {@inv_format = 'html'}
|
||||
format.pdf do
|
||||
|
|
|
|||
|
|
@ -9,4 +9,20 @@ class Invoice < ApplicationRecord
|
|||
0.0
|
||||
end
|
||||
|
||||
def products_with_tax(vat_id)
|
||||
self.invoice_products.joins(:product => :vat).where('vats.id = ?',vat_id)
|
||||
end
|
||||
|
||||
def products_with_tax_sum_arr(vat_id)
|
||||
sum = 0.0
|
||||
vat = 0.0
|
||||
total = 0.0
|
||||
for invoice_product in self.invoice_products.joins(:product => :vat).where('vats.id = ?',vat_id)
|
||||
sum += invoice_product.netto_price * invoice_product.qty
|
||||
vat += (invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100)) * invoice_product.qty
|
||||
total += (invoice_product.netto_price * (invoice_product.product.vat.tax_rate/100 + 1)) * invoice_product.qty
|
||||
end
|
||||
return [sum,vat,total]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,23 +48,11 @@
|
|||
</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>
|
||||
<div id="invoice_products" name="invoice_products">
|
||||
<%= f.fields_for :invoice_products do |invoice_products_form| %>
|
||||
<%= render :partial => '/invoices/invoice_product_fields', :locals => {:f => invoice_products_form} %>
|
||||
<% end %>
|
||||
<%= link_to_add_association raw('<i class="fa fa-plus"></i> '+ t('add_position')), f, :invoice_products, {:class => 'btn btn-info btn-xs shiny'} %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<div class="row">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-5">
|
||||
<%= f.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">
|
||||
<%= f.text_field :qty, class: "form-control", placeholder: 'Ilość' %>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<%= f.text_field :netto_price, class: "form-control", placeholder: 'Wartość netto' %>
|
||||
</div>
|
||||
<div class="col-sm-1">
|
||||
<%= f.check_box :_destroy%>
|
||||
<span class="text"><%= t('del_position') %></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -127,17 +127,30 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Podatek VAT 23%</td>
|
||||
<td class="text-right">30 000,00</td>
|
||||
<td class="text-right">6 900,00</td>
|
||||
<td class="text-right">36 900,00</td>
|
||||
</tr>
|
||||
<%
|
||||
total_arr = [0.0,0.0,0.0]
|
||||
for vat in @vats
|
||||
if @invoice.products_with_tax(vat.id)
|
||||
sum_arr = @invoice.products_with_tax_sum_arr(vat.id)
|
||||
total_arr[0] += sum_arr[0]
|
||||
total_arr[1] += sum_arr[1]
|
||||
total_arr[2] += sum_arr[2]
|
||||
%>
|
||||
<tr>
|
||||
<td>Podatek VAT <%= vat.name %></td>
|
||||
<td class="text-right"><%= number_with_precision(sum_arr[0], delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
<td class="text-right"><%= number_with_precision(sum_arr[1], delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
<td class="text-right"><%= number_with_precision(sum_arr[2], delimiter: " ", separator: ",", precision: 2) %></td>
|
||||
</tr>
|
||||
<%
|
||||
end
|
||||
end
|
||||
%>
|
||||
<tr>
|
||||
<td><b>Razem:</b></td>
|
||||
<td class="text-right"><b>30 000,00<b></td>
|
||||
<td class="text-right"><b>6 900,00<b></td>
|
||||
<td class="text-right"><b>36 900,00<b></td>
|
||||
<td class="text-right"><b><%= number_with_precision(total_arr[0], delimiter: " ", separator: ",", precision: 2) %><b></td>
|
||||
<td class="text-right"><b><%= number_with_precision(total_arr[1], delimiter: " ", separator: ",", precision: 2) %><b></td>
|
||||
<td class="text-right"><b><%= number_with_precision(total_arr[2], delimiter: " ", separator: ",", precision: 2) %><b></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -150,10 +163,10 @@
|
|||
<div class="col-md-12">
|
||||
<table>
|
||||
<tr>
|
||||
<td valign="bottom">Kwota do zapłaty: </td><td><span style="font-size:18px"><b>36 900,00 PLN</b></span></td>
|
||||
<td valign="bottom">Kwota do zapłaty: </td><td><span style="font-size:18px"><b><%= number_with_precision(total_arr[2], delimiter: " ", separator: ",", precision: 2) %> PLN</b></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Słownie do zapłaty: </td><td><b><%= decimal_to_word(36900.0) %></b></td>
|
||||
<td>Słownie do zapłaty: </td><td><b><%= decimal_to_word(total_arr[2]) %></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Forma płatności: </td><td><b>Przelew</b></td>
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ require_relative 'application'
|
|||
Rails.application.initialize!
|
||||
|
||||
# haslo_do_API
|
||||
SMS_API_URL = ''
|
||||
SMS_API_PASS_MD5 = '798caa5d3415cb6a74188fe6c5478c85'
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ pl:
|
|||
forgot_your_password: 'Zapmniałeś hasła?'
|
||||
didnt_receive_confirmation_instructions: 'Nie otrzymałeś instrukcji potwierdzenia?'
|
||||
didnt_receive_unlock_instructions: 'Nie otrzymałeś instrukcji odblokowania?'
|
||||
del_position: 'Usuń pozycję'
|
||||
add_position: 'Dodaj pozycję'
|
||||
menu:
|
||||
dashboard: 'Dashboard'
|
||||
customers: 'Klienci'
|
||||
|
|
|
|||
Loading…
Reference in New Issue