From 3d6f908102f60bbd3f087db17408f4a9ac1b3f2b Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Wed, 17 Feb 2016 16:11:01 +0100 Subject: [PATCH] Add created_by to invoice and show it --- app/controllers/finance/invoices_controller.rb | 1 + app/models/invoice.rb | 3 +-- app/views/finance/invoices/_form.html.haml | 5 +++++ app/views/finance/invoices/show.html.haml | 6 ++++++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/nl.yml | 2 ++ .../20160217124256_add_created_by_user_id_to_invoice.rb | 5 +++++ db/schema.rb | 3 ++- 10 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20160217124256_add_created_by_user_id_to_invoice.rb diff --git a/app/controllers/finance/invoices_controller.rb b/app/controllers/finance/invoices_controller.rb index 37cf839f..a38328db 100644 --- a/app/controllers/finance/invoices_controller.rb +++ b/app/controllers/finance/invoices_controller.rb @@ -20,6 +20,7 @@ class Finance::InvoicesController < ApplicationController def create @invoice = Invoice.new(params[:invoice]) + @invoice.created_by = current_user if @invoice.save flash[:notice] = I18n.t('finance.create.notice') diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 6f95cd43..fa8c1a1a 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -3,6 +3,7 @@ class Invoice < ActiveRecord::Base belongs_to :supplier belongs_to :delivery belongs_to :order + belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' validates_presence_of :supplier_id validates_numericality_of :amount, :deposit, :deposit_credit @@ -17,5 +18,3 @@ class Invoice < ActiveRecord::Base amount - deposit + deposit_credit end end - - diff --git a/app/views/finance/invoices/_form.html.haml b/app/views/finance/invoices/_form.html.haml index d2c6d144..7777d92a 100644 --- a/app/views/finance/invoices/_form.html.haml +++ b/app/views/finance/invoices/_form.html.haml @@ -7,6 +7,11 @@ - if @invoice.order %p= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_order'), new_finance_order_path(order_id: @invoice.order.id))).html_safe + - if @invoice.created_at + = f.input :created_at do + = format_time(@invoice.created_at) + = f.input :created_by do + = show_user(@invoice.created_by) = f.association :supplier, hint: false = f.input :number = f.input :date, as: :date_picker diff --git a/app/views/finance/invoices/show.html.haml b/app/views/finance/invoices/show.html.haml index 5f202e3a..97034a04 100644 --- a/app/views/finance/invoices/show.html.haml +++ b/app/views/finance/invoices/show.html.haml @@ -1,5 +1,11 @@ - title t('.title', number: @invoice.number) +%p + %b= heading_helper(Invoice, :created_at) + ':' + = format_time(@invoice.created_at) +%p + %b= heading_helper(Invoice, :created_by) + ':' + = show_user(@invoice.created_by) %p %b= heading_helper(Invoice, :supplier) + ':' = @invoice.supplier.name diff --git a/config/locales/de.yml b/config/locales/de.yml index fc2a849b..0b8661a5 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -54,6 +54,8 @@ de: total_price: Summe invoice: amount: Betrag + created_at: Erstellt am + created_by: Erstellt von date: Rechnungsdatum delivery: Lieferung deposit: Pfand berechnet diff --git a/config/locales/en.yml b/config/locales/en.yml index c0a12abb..46855dc2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -54,6 +54,8 @@ en: total_price: Sum invoice: amount: Amount + created_at: Created at + created_by: Created by date: Billing date delivery: Delivery deposit: Deposit charged diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 89fd14c0..a214ad9a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -54,6 +54,8 @@ fr: total_price: Total invoice: amount: Montant + created_at: Créé le + created_by: "Établi par" date: Date de facturation delivery: Réapprovisionnement deposit: Consigne facturée diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 52d8f21e..304fdbb9 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -54,6 +54,8 @@ nl: total_price: Som invoice: amount: Bedrag + created_at: Gemaakt op + created_by: Gemaakt door date: Factuurdatum delivery: Levering deposit: Statiegeld in rekening gebracht diff --git a/db/migrate/20160217124256_add_created_by_user_id_to_invoice.rb b/db/migrate/20160217124256_add_created_by_user_id_to_invoice.rb new file mode 100644 index 00000000..2329faa6 --- /dev/null +++ b/db/migrate/20160217124256_add_created_by_user_id_to_invoice.rb @@ -0,0 +1,5 @@ +class AddCreatedByUserIdToInvoice < ActiveRecord::Migration + def change + add_column :invoices, :created_by_user_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 3987c4bf..ac1d804c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150923190747) do +ActiveRecord::Schema.define(version: 20160217124256) do create_table "article_categories", force: :cascade do |t| t.string "name", limit: 255, default: "", null: false @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(version: 20150923190747) do t.decimal "deposit_credit", precision: 8, scale: 2, default: 0, null: false t.datetime "created_at" t.datetime "updated_at" + t.integer "created_by_user_id" end add_index "invoices", ["delivery_id"], name: "index_invoices_on_delivery_id", using: :btree