私はもう2日近く頭を骨折していて、解決策を見つけることができません。
請求書番号、合計、支払額、および残高を含む請求書を一覧表示するテーブルがあります。そしてそれはうまくいきます。次に、すべてのラインアイテムをテーブルに追加する必要があります。
請求書テーブルには、of_lax、air_rate_customer、pssの列があるので、簡単にできるので、そこに値があるかどうかを確認する必要があります。
トリッキーな部分はfcl_variable_cost_1_amount
属性です。そのうちの8つ(fcl_variable_cost_1_amount、fcl_variable_cost_2_amountなど)を取得しました。
にはfcl_variable_cost_1_amount
、Chargeテーブルにリンクする対応するfcl_variable_cost_1_charge_idがあります。
したがって、1つの請求書でfcl_variable_cost_1_idは34で、金額は$ 100になる可能性があります(id 34は「ISF」に対応します)。
別の請求書では、fcl_variable_cost_1_idは12で、金額は$ 50です(id 12は「検査料」に対応します)。
では、変数名の広告申込情報を本来の列に表示するにはどうすればよいですか?
これは私のコードです。スクリーンショットもあります。
<% headings = Hash.new %>
<% @shipments.each do |shipment| %>
<% unless shipment.invoice.nil? %>
<% unless shipment.invoice.of_customer_amount_for_customer_inv.nil? %>
<% headings['of_customer_amount_for_customer_inv'] = "Ocean Freight (FCL)" %>
<% end %>
<% unless shipment.invoice.of_lax.nil? %>
<% headings['of_lax'] = "Ocean Freight (LCL)" %>
<% end %>
<% unless shipment.invoice.air_rate_customer.nil? %>
<% headings['air_rate_customer'] = "Air Freight" %>
<% end %>
<% unless shipment.invoice.pss.nil? %>
<% headings['pss'] = "PSS" %>
<% end %>
<% unless shipment.invoice.hc_lax.nil? %>
<% headings['hc_lax'] = "HC LAX" %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_1_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_1_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_1_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_2_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_2_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_2_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_3_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_3_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_3_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_4_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_4_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_4_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_5_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_5_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_5_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_6_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_6_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_6_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_7_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_7_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_7_charge_id).name %>
<% end %>
<% unless shipment.invoice.fcl_variable_cost_8_amount.nil? %>
<% headings[(Charge.find(shipment.invoice.fcl_variable_cost_8_charge_id)).name] = Charge.find(shipment.invoice.fcl_variable_cost_8_charge_id).name %>
<% end %>
<% end %>
<% end %>
<table>
<tr>
<th colspan="9">Customer AR Statement for <%= @customer.company_name %></th>
</tr>
<tr>
<th style="text-align:center;">MTY</th>
<th>Shipper</th>
<th>HBL</th>
<th>Container</th>
<th>Status</th>
<th>Age</th>
<th>Delivered Customer</th>
<th>Invoice Date</th>
<% headings.each_pair do |k,v|%>
<th><%= v %></th>
<% end %>
<th>Invoice Total</th>
<th>Amount Paid</th>
<th>Balance</th>
</tr>
<% @shipments.each do |shipment| %>
<tr>
<td style="text-align:center;"><%= shipment.file_number %></td>
<td><%= shipment.shipper.company_name %></td>
<td><%= shipment.hbl %></td>
<td><%= shipment.container %></td>
<td><%= shipment.status %></td>
<td><%= shipment.age %></td>
<td><%= shipment.invoice.delivered_customer ? "Yes" : "No" %></td>
<td><%= shipment.invoice.read_issued_at unless shipment.invoice.nil? %></td>
<% if shipment.invoice.nil? %>
<td colspan="<%= headings.count %>"></td>
<% else %>
<% headings.each_pair do |k,v| %>
<% if k == "of_lax" and !shipment.invoice.of_lax.nil? %>
<td><%= number_to_currency shipment.invoice.lcl_of_customer_total %>
<% elsif k == "of_customer_amount_for_customer_inv" and !shipment.invoice.of_customer_amount_for_customer_inv.nil? %>
<td><%= number_to_currency shipment.invoice.of_customer_amount_for_customer_inv %></td>
<% elsif k == "air_rate_customer" and !shipment.invoice.air_rate_customer.nil? %>
<td><%= number_to_currency (shipment.volweight * shipment.invoice.air_rate_customer.to_s.to_d) %></td>
<% elsif k == "pss" and !shipment.invoice.pss.nil? %>
<td><%= number_to_currency (shipment.invoice.pss.to_s.to_d * shipment.volweight) %></td>
<% elsif k == "hc_lax" and !shipment.invoice.hc_lax.nil? %>
<td><%= number_to_currency (shipment.invoice.hc_lax.to_s.to_d * shipment.volweight) %></td>
<% else %>
<td></td>
<% end %>
<% end %>
<% end %>
<td style="text-align:right;"><%= number_to_currency shipment.invoice.customer_total unless shipment.invoice.nil? %></td>
<td style="text-align:right;"><%= number_to_currency shipment.invoice.customer_amount_paid unless shipment.invoice.nil? %></td>
<td style="text-align:right;"><%= number_to_currency shipment.invoice.customer_open_balance unless shipment.invoice.nil? %></td>
</tr>
<% end %>
<tr>
<td colspan="<%= 7 + (headings.count) %>"></td>
<th>Totals</th>
<td style="text-align:right;"><%= number_to_currency @totals[:overall] %></td>
<td style="text-align:right;"><%= number_to_currency @totals[:paid] %></td>
<td style="text-align:right;"><%= number_to_currency @totals[:balance] %></td>
</tr>
</table>