<%= form_with(url: {action: :get_csv_of_send_log}) do %>
  <%= select_tag 'month_for_out', options_for_select(@select_month) %> のログを
  <%= submit_tag "CSV保存" %>
<% end %>

<br>

<%= form_with(url: {action: :send_log}, method: :get) do %>
  <%= select_tag :type, options_for_select([["送信者名", 1], ["送信者メールアドレス", 2],
                       ["受信者名", 3], ["受信者メールアドレス", 4]], @type.to_i ) %>
  <%= text_field_tag :keyward, @keyward %>
  <%= submit_tag "検索" %>
<% end %>

<br>

データ数：<%= @total_data %>
[ <%= render '/layouts/original_paginate', controller: :sys_log, action: :send_log, page: @page, total_page: @total_page, w_in: 4, w_out: 2 %> ]<br>

<table border="1" cellspacing="0" cellpadding="3">
  <tr bordercolor=gray>
  <td nowrap bgcolor="#e5f0fe"><br></td>
  <td nowrap bgcolor="#e5f0fe">登録日</td>
  <td nowrap bgcolor="#e5f0fe">送信ＩＤ</td>
  <td nowrap bgcolor="#e5f0fe">送信者名</td>
  <td nowrap bgcolor="#e5f0fe">送信者メールアドレス</td>
  <td nowrap bgcolor="#e5f0fe">受信者名</td>
  <td nowrap bgcolor="#e5f0fe">受信者メールアドレス</td>
  <td nowrap bgcolor="#e5f0fe">総ファイル数</td>
  <td nowrap bgcolor="#e5f0fe">総ファイルサイズ</td>
  </tr>

  <% count = 0 -%>

  <% @rs.each do | data | -%>
    <tr bordercolor="gray">
      <td nowrap align="center"><%= count + @s_data %></td>
      <td nowrap><%= (Time.parse(data.created_at.to_s)).strftime("%Y/%m/%d %H:%M:%S") %></td>
      <td nowrap>
      <%= link_to data.send_matter_id.to_s, {controller: :sys_log, action: :send_matter_info, id: data.send_matter_id} %>
      </td>
      <td nowrap><%= data.sender_name %></td>
      <td nowrap><%= data.sender_mail_address %></td>
      <td nowrap>
        <%- receiver_count = 0 -%>
        <%- for tmp_receiver in get_receivers(data.send_matter_id, 'name') -%>
          <%- if receiver_count > 0 -%>
           <br/>
          <%- end -%>
          <%= tmp_receiver %>
          <%- receiver_count += 1 -%>
        <%- end -%>
      </td>
      <td nowrap>
        <%- receiver_count = 0 -%>
        <%- for tmp_receiver in get_receivers(data.send_matter_id, 'mail_address') -%>
          <%- if receiver_count > 0 -%>
           <br/>
          <%- end -%>
          <%= tmp_receiver %>
          <%- receiver_count += 1 -%>
        <%- end -%>
      </td>
      <td nowrap><%= data.total_file %></td>
      <%- if data.total_size -%>
        <%- if data.total_size.to_i > 1024 * 1024 -%>
          <%- file_total_size = (data.total_size.to_i / (1024 * 1024)).to_s + ' MB' -%>
        <%- elsif data.total_size.to_i > 1024 -%>
          <%- file_total_size = (data.total_size.to_i / 1024).to_s + ' KB' -%>
        <%- else -%>
          <%- file_total_size = data.total_size.to_s + ' B' -%>
        <%- end -%>
      <%- end -%>
      <td nowrap><%= file_total_size %></td>
    </tr>
    <% count = count + 1 -%>
  <% end -%>

  <% if count == 0 -%>
    <tr><td colspan="9" algin=center>データがありません</td></tr>
  <% end -%>
</table>

