Add button to create a new empty FinacialLink
This commit is contained in:
parent
1656efd845
commit
0e77a0e77c
5 changed files with 15 additions and 1 deletions
|
@ -36,7 +36,7 @@ class Finance::FinancialLinksController < Finance::BaseController
|
|||
end
|
||||
|
||||
def create
|
||||
@financial_link = FinancialLink.new
|
||||
@financial_link = FinancialLink.first_unused_or_create
|
||||
if params[:bank_transaction] then
|
||||
bank_transaction = BankTransaction.find(params[:bank_transaction])
|
||||
bank_transaction.update_attribute :financial_link, @financial_link
|
||||
|
|
|
@ -4,6 +4,12 @@ class FinancialLink < ApplicationRecord
|
|||
has_many :invoices
|
||||
|
||||
scope :incomplete, -> { with_full_sum.where.not('full_sums.full_sum' => 0) }
|
||||
scope :unused, -> {
|
||||
includes(:bank_transactions, :financial_transactions, :invoices)
|
||||
.where(bank_transactions: { financial_link_id: nil })
|
||||
.where(financial_transactions: { financial_link_id: nil })
|
||||
.where(invoices: { financial_link_id: nil})
|
||||
}
|
||||
scope :with_full_sum, -> {
|
||||
select(:id, :note, :full_sum).joins(<<-SQL)
|
||||
LEFT JOIN (
|
||||
|
@ -27,4 +33,8 @@ class FinancialLink < ApplicationRecord
|
|||
) full_sums ON full_sums.id = financial_links.id
|
||||
SQL
|
||||
}
|
||||
|
||||
def self.first_unused_or_create
|
||||
unused.first || create
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
- content_for :actionbar do
|
||||
= link_to t('.show_all'), finance_transactions_path, class: 'btn'
|
||||
= link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn'
|
||||
- if FinancialLink.any?
|
||||
= link_to t('.new_financial_link'), finance_links_path, method: :post, class: 'btn'
|
||||
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
|
||||
|
||||
.well.well-small
|
||||
|
|
|
@ -955,6 +955,7 @@ de:
|
|||
title: Unbezahlte Rechnungen
|
||||
ordergroups:
|
||||
index:
|
||||
new_financial_link: Neuer Finanzlink
|
||||
new_transaction: Neue Überweisungen eingeben
|
||||
show_all: Alle Transaktionen
|
||||
show_foodcoop: Foodcoop Transaktionen
|
||||
|
|
|
@ -956,6 +956,7 @@ en:
|
|||
title: Unpaid invoices
|
||||
ordergroups:
|
||||
index:
|
||||
new_financial_link: New financial link
|
||||
new_transaction: Add new transactions
|
||||
show_all: All transactions
|
||||
show_foodcoop: Foodcoop transaktions
|
||||
|
|
Loading…
Reference in a new issue