This commit is contained in:
Mini Robot 2018-04-17 18:26:49 +02:00
commit 7756a98fbc
5 changed files with 24 additions and 19 deletions

2
.gitignore vendored
View File

@ -16,7 +16,7 @@
/tmp/* /tmp/*
!/log/.keep !/log/.keep
!/tmp/.keep !/tmp/.keep
.tags
# Ignore Byebug command history file. # Ignore Byebug command history file.
.byebug_history .byebug_history
Gemfile.lock Gemfile.lock

View File

@ -1,8 +1,7 @@
source 'http://rubygems.org' source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4' gem 'rails', '~> 5.0.0'
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
# gem 'sqlite3' # gem 'sqlite3'
gem 'momentjs-rails', '>= 2.9.0' gem 'momentjs-rails', '>= 2.9.0'
@ -10,7 +9,7 @@ gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
gem 'devise' gem 'devise'
gem 'mysql2' gem 'mysql2'
# Use Puma as the app server # Use Puma as the app server
gem 'puma', '~> 3.7' gem 'puma', '~> 3.0'
# Use SCSS for stylesheets # Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0' gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets # Use Uglifier as compressor for JavaScript assets
@ -31,7 +30,7 @@ gem 'jbuilder', '~> 2.5'
# gem 'redis', '~> 3.0' # gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password # Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7' # gem 'bcrypt', '~> 3.1.7'
gem 'cocoon'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
gem 'wicked_pdf' gem 'wicked_pdf'

View File

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

View File

@ -2,11 +2,11 @@ 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, inverse_of: :invoice has_many :invoice_products, inverse_of: :invoice, dependent: :destroy
accepts_nested_attributes_for :invoice_products, allow_destroy: true accepts_nested_attributes_for :invoice_products, allow_destroy: true
def netto_amount def netto_amount
0.0 invoice_products.sum('invoice_products.netto_price * invoice_products.qty')
end end
def products_with_tax(vat_id) 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> <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>
<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>
<tr> <tr>
<td>Forma płatności: </td><td><b>Przelew</b></td> <td>Forma płatności: </td><td><b>Przelew</b></td>