Merge branch 'master' of ssh://51.254.143.84:9319/home/git/invoice_keeper

This commit is contained in:
Adrian Hinz 2018-04-17 18:21:35 +02:00
parent 8121f3bb0d
commit 7e95446069
3 changed files with 20 additions and 19 deletions

View File

@ -1,35 +1,32 @@
# encoding: utf-8
class InvoicesController < ApplicationController
def index
@invoices = Invoice.where(user_id: current_user.id)
@invoices = Invoice.where(user_id: current_user.id).order('created_at DESC')
end
def show
@invoice = Invoice.find(params[:id])
@vats = Vat.all
respond_to do |format|
format.html {@inv_format = 'html'}
format.html { @inv_format = 'html' }
format.pdf do
render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension.
disposition: 'attachment',
layout: 'pdf',
encoding: 'UTF-8',
page_size: 'A4',
margin: { top: 8, # default 10 (mm)
bottom: 8,
left: 8,
right: 8 },
viewport_size: '1336x1024'
render pdf: "Faktura_VAT_#{@invoice.id}", # Excluding ".pdf" extension.
disposition: 'attachment',
layout: 'pdf',
encoding: 'UTF-8',
page_size: 'A4',
margin: { top: 8, bottom: 8, left: 8, right: 8 },
viewport_size: '1336x1024'
end
end
end
def new
@invoice = Invoice.new(date: Date.today, date_of_payment: Date.today + 14.days)
inv = Invoice.where('date > ?', Date.new(Date.today.year,1,1)).last
if !inv.blank?
inv = Invoice.where('date > ?', Date.new(Date.today.year, 1, 1)).last
unless inv.blank?
nr = inv.number
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
end
@invoice.invoice_products.build
@ -73,7 +70,11 @@ class InvoicesController < ApplicationController
end
private
def invoice_params
params.require(:invoice).permit(:number, :user_firm_id, :customer_id, :date, :date_of_payment, invoice_products_attributes: [:id, :product_id, :qty, :netto_price, :_destroy])
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

View File

@ -2,11 +2,11 @@ class Invoice < ApplicationRecord
belongs_to :user
belongs_to :user_firm
belongs_to :customer
has_many :invoice_products, inverse_of: :invoice
has_many :invoice_products, inverse_of: :invoice, dependent: :destroy
accepts_nested_attributes_for :invoice_products, allow_destroy: true
def netto_amount
0.0
invoice_products.sum('invoice_products.netto_price * invoice_products.qty')
end
def products_with_tax(vat_id)

View File

@ -166,7 +166,7 @@
<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(total_arr[2]) %></b></td>
<td>Słownie do zapłaty: </td><td><b><%= decimal_to_word(('%.2f' % total_arr[2]).to_f) %></b></td>
</tr>
<tr>
<td>Forma płatności: </td><td><b>Przelew</b></td>