- title "Lagerübersicht: #{StockArticle.available.count} Artikel im Lager"

.menu
  - form_tag do
    %ul
      %li
        Ansichtsoptionen
        %ul
          %li= link_to_function "Nicht verfügbare Artikel zeigen/verstecken", |
            "$$('tr.unavailable').invoke('toggleClassName', 'hidden');", :style => "width:15em" |


%div{:style => "padding:0 0 0.5em 0.7em;margin-bottom:2em"}
  %span{:style => "float:left"}
    - form_tag do
      Neue Lieferung anlegen für:
      = select_tag :new_delivery, |
        options_for_select([[" -- Lieferantin wählen --", ""]] + |
          Supplier.without_deleted.collect {|s| [ s.name, url_for(new_supplier_delivery_path(s))] }), |
        :onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" |

.single_column{:style => 'width:100%; clear:both'}
  .box_title
  .column_content
    #actions
      %b= link_to "Neuen Lagerartikel anlegen", new_stock_article_path
      |
      = link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", {:controller => 'orders', :action => 'new', :supplier_id => 0}
      |
      %b= link_to "Inventur anlegen", new_stock_taking_path
      |
      = link_to "Inventurübersicht", stock_takings_path

    #articles{:style => "clear:both;margin-top:1em"}
      %table.list
        %thead
          %tr
            %th Artikel
            %th im Lager
            %th davon bestellt
            %th verfügbar
            %th Einheit
            %th Preis
            %th MwSt
            %th Lieferantin
            %th Kategorie
            %th
        %tbody
          - for article in @stock_articles
            - class_name = cycle :even, :odd
            - class_name += " unavailable hidden" if article.quantity_available <= 0
            - class_name += " supplier_#{article.supplier.id}"
            %tr{:class => class_name}
              %td=h article.name
              %td= article.quantity
              %td= article.quantity - article.quantity_available
              %th= article.quantity_available
              %td= article.unit
              %td= article.price
              %td= number_to_percentage article.tax
              %td= link_to article.supplier.name, article.supplier
              %td= article.article_category.name
              %td
                = link_to icon(:edit), edit_stock_article_path(article)
                = link_to icon(:delete), article, :method => :delete, :confirm => "Bist Du sicher?"
    %p
      Aktueller Lagerwert:
      = number_to_currency StockArticle.stock_value
      |
      Artikelanzahl:
      = StockArticle.available.count