2011-10-29 10 views
2

1 account.rbレールダブル入力方法

class Account < ActiveRecord::Base 
    belongs_to :transaction 
end 

class Supplier < Account 
end 

class Expense < Account 
end 

2- transaction.rb

class Transaction < ActiveRecord::Base 
    has_many :accounts 
    accepts_nested_attributes_for :accounts 
end 

3マイグレーションスキーマ

create_table "accounts", :force => true do |t| 
    t.string "name" 
    t.decimal "debit" 
    t.decimal "credit" 
    t.decimal "balance" 
    t.string "type" 
    t.integer "transaction_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    create_table "transactions", :force => true do |t| 
    t.string "name" 
    t.decimal "amount" 
    t.date  "date" 
    t.string "document" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 
end 

質問1: サプライヤーと経費をビューに表示するには、どのような方法が最適です(下図参照)?

Question2: どうすれば自動的にexpense_debitとに取引量を記録する方法、およびその逆を実装することができますか? (View screenshot

答えて

1

私は別の設定を提案したいと思います。 1つは、あなたの取引では、どちらが「元」の口座であり、どちらが「先」の口座であるかは記録されません。後でそれを知ることは重要なことです。

複数のアカウントがある可能性があることを認識していますが、デビットとクレジットはアカウントごとに1つの大きな塊ではなく、取引単位で記録する必要があります。たとえば、日付Aと日付Bの間のアカウントの値の変化を表示します(税務申告や四半期売上レポートなどの場合は重要です)。

私は命名についてはわかりませんが、おそらくトランザクションはhas_many口座振替であり、振替は "transaction_id、account_id、amount、direction"です(方向は借方/貸方)。

+1

あなたの答えはTaryn Eastです。私はあなたのソリューションを試してみるつもりです。実際には、トランザクションとアカウントの間のリンクとしてモデルを作成することは考えていませんでした。アカ​​ウント転送モデルがトリックを行うことを願っています。あなたにすぐにフィードバックを与えます。 – blawzoo