<%= render :partial => "submenu" %>

<div id="main"><!-- メイン -->

<h2>受注管理</h2>

<%=h flash[:notice] %>
<%=h flash[:error] %>
<%= render :partial => "search" %>

<% if @order_deliveries %>
  <% form_for :search, :url => {:action => 'csv_download'} do | f | %>
    <%- @search.attributes.reject{|_,v|v.blank?}.each do | k, v | -%>
      <%= f.hidden_field k %>
    <%- end -%>
    <%- [:payment_id, :sex].each do |name| -%>
      <%- params[name] and params[name].each do |value| -%>
        <%= hidden_field_tag '%s[]' % name, value %>
      <%- end -%>
    <%- end -%>
    <br />
    <p>&gt;&gt;検索結果一覧&nbsp;<%=@order_deliveries.total_entries %>件&nbsp;が該当しました</p>
    <div class="btn_box space20_bottom">
      <%= submit_tag 'CSV DOWNLOAD', :class=>"btn" %>
      <%= image_tag("btn_side.gif", :width => "6", :height => "34", :class => "btn_side") %>
    </div>
  <% end %>
  <table class="data2 clear" cellspacing="1">
   <tr>
    <th>受注日</th>
    <th>受注番号</th>
    <th>顧客名</th>
    <th>支払方法</th>
    <th>購入金額(円)</th>
    <th>全商品発送日</th>
    <th>対応状況</th>
    <th>編集</th>
    <th>メール</th>
    <th>削除</th>
   </tr>
   <% @order_deliveries.each do | order_delivery | %>
     <tr>
      <td><%= date(order_delivery.received_at) %></td>
      <td><%= order_delivery.order_code %></td>
      <td><%=h order_delivery.family_name %> <%=h order_delivery.first_name %></td>
      <td><%= order_delivery.payment && order_delivery.payment.name %></td>
      <td><%= number_with_delimiter(order_delivery.total) %></td>
      <td><%= date(order_delivery.shipped_at) || '未発送' %></td>
      <td><%= order_delivery.status_view %></td>
      <td><%= link_to "編集", edit_admin_order_path(order_delivery.order_id) %></td>
<%-
 name = '%s %s 様' % [order_delivery.family_name, order_delivery.first_name]
 body = "%s\r\n\r\n受注番号: %s" % [name, order_delivery.order_code]
 mailto = 'mailto:%s?body=%s' % [order_delivery.email, URI.encode(body)]
 -%>
      <td><%= link_to '作成', mailto %></td>
      <td><%= link_to "削除", { :action => "destroy", :id => order_delivery.id }, :confirm => "本当に削除しますか？", :method=>"delete" %></td>
     </tr>
   <% end %>
  </table>
  <%= will_paginate @order_deliveries, :params => params %>
<% end %>

</div><!-- /メイン -->
