我有兩個表salary_structures和payheads。下面是我的表結構:唧唧to same more more more single single single single single single single single single single single more more??
create_table "payheads", :force => true do |t|
t.integer "company_id", :null => false
t.integer "defined_by", :null => false
t.string "payhead_type"
t.string "payhead_name"
t.string "under"
t.string "affect_net_salary"
t.string "name_appear_in_payslip"
t.string "use_of_gratuity"
t.datetime "created_at"
t.datetime "updated_at"
end
和:
create_table "salary_structures", :force => true do |t|
t.integer "company_id", :null => false
t.integer "for_employee"
t.integer "created_by"
t.date "effective_from_date"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "payhead_id"
t.decimal "amount", :precision => 18, :scale => 2, :default => 0.0
end
按我的表結構,我在salary_structures表,並在我的payheads表已經payhead_id我有四個payheads(基本,PF等) 。現在當一個管理員想要定義一個員工的salary_structure時,他必須爲每個支付頭寸確定金額,按照我的設計,我想一次爲一個salary_structure保存一個員工的所有支付頭。但問題出在一個salary_structure id我怎麼能保存多個支付頭。下面是我的看法形式:
<%= form_for(@salary_structure) do |f| %>
<%= render 'shared/form_error', :object => @salary_structure %>
<div class="field">
<%= f.label :for_employee, :class => "required" %><br />
<%= collection_select(:salary_structure, :for_employee, @users, :id, :first_name,:autofocus =>"autofocus", :prompt => true) %>
</div>
<div class="column width3">
<div class="field">
<%= f.label :effective_from_date, :class => "required" %><br />
<%= f.text_field :effective_from_date %>
</div>
</div>
<div class="column width6 first">
<table class=" display stylized full" id="salary_structure_report" style="">
<thead>
<tr>
<th width="80%"><label class="required">Pay Head</label></th>
<th width = "20%"><label class="required">Amount</label></th>
</tr>
</thead>
<tbody>
<% for ph in @payheads %>
<tr>
<td width = "80%">
<%= f.hidden_field "payhead_id", ph.id %>
<%= ph.payhead_name %> </td>
<td width = "20%" ><%= f.text_field :amount %></td>
</tr>
<% end %>
</tbody>
<tfoot>
<tr>
<td class="ta-right" width = "80%">Total</td>
<td class="ta-left" width = "20%"><span class="WebRupee">Rs</span><span id = "total">00.00</span></td>
</tr>
</tfoot>
</table>
</div><br />
<div class = "column width3 first">
<button type="submit" class="btn btn-green big"><img src="/images/add.png" class="icon" /> Save</button>
<%= link_to 'Cancel', salary_structures_path, :class=>"btn btn-gray bg"%>
</div>
</div>
<% end %>
,當我試圖正常保存它,它不保存payhead ID在salary_structures表 ,我應該做的事的模型。任何幫助,都會提前致歉。
嗨,感謝您的解決方案,但我不想在payhead表中保存任何payhead,我想用所有這些payheads保存salary_structure,爲了方便我的金額字段在salary_structure表中不在支付表 – Ravindra 2012-02-27 06:57:43
If你不想在匯款表中保存任何付款頭,那麼你打算在其中存儲什麼? salary_structure.amount是所有payhead.amounts的總和嗎?你如何更新它? – Rahul 2012-02-27 08:07:20
先生,我先前告訴我的支付方式是爲公司所有員工管理員定義的。在薪金結構中,我只爲所有各自的支付人節省了金額,我可以從支付表中取回 – Ravindra 2012-02-27 09:21:30