- title t('.title', number: @invoice.number)

- total = 0

%p
  %b= heading_helper(Invoice, :created_at) + ':'
  = format_time(@invoice.created_at)
%p
  %b= heading_helper(Invoice, :created_by) + ':'
  = show_user(@invoice.created_by)
%p
  %b= heading_helper(Invoice, :supplier) + ':'
  = @invoice.supplier.name

- if @invoice.deliveries.any?
  %p
    %b= heading_helper(Invoice, :deliveries) + ':'
    %span><
      - @invoice.deliveries.order(:delivered_on).each_with_index do |delivery, index|
        - sum = delivery.sum
        - total += sum
        = ', ' if index > 0
        = link_to format_date(delivery.delivered_on), [delivery.supplier,delivery]
        = ' (' + number_to_currency(sum) + ')'
- if @invoice.orders.any?
  %p
    %b= heading_helper(Invoice, :orders) + ':'
    %span><
      - @invoice.orders.order(:ends).each_with_index do |order, index|
        - sum = order.sum
        - total += sum
        = ', ' if index > 0
        = link_to format_date(order.ends), new_finance_order_path(order_id: order)
        = ' (' + number_to_currency(sum) + ')'

%p
  %b= heading_helper(Invoice, :number) + ':'
  = @invoice.number
%p
  %b= heading_helper(Invoice, :date) + ':'
  = @invoice.date
%p
  %b= heading_helper(Invoice, :paid_on) + ':'
  = @invoice.paid_on
%p
  %b= heading_helper(Invoice, :amount) + ':'
  = number_to_currency @invoice.amount
%p
  %b= heading_helper(Invoice, :deposit) + ':'
  = number_to_currency @invoice.deposit
%p
  %b= heading_helper(Invoice, :deposit_credit) + ':'
  = number_to_currency @invoice.deposit_credit
%p
  %b= heading_helper(Invoice, :net_amount) + ':'
  = number_to_currency @invoice.net_amount
- if @invoice.deliveries.any? || @invoice.orders.any?
  %p
    %b= heading_helper(Invoice, :total) + ':'
    = number_to_currency total
%p
  %b= heading_helper(Invoice, :attachment) + ':'
  - if @invoice.attachment_data
    = link_to t('ui.download'), finance_invoice_attachment_path(@invoice)
%p
  %b= heading_helper(Invoice, :note) + ':'
  =h @invoice.note
- if @invoice.financial_link
  %p
    %b= heading_helper(Invoice, :financial_link) + ':'
    = link_to t('ui.show'), finance_link_path(@invoice.financial_link)

- if @invoice.user_can_edit?(current_user)
  = link_to t('ui.edit'), edit_finance_invoice_path(@invoice), class: 'btn'
= link_to t('ui.or_cancel'), finance_invoices_path
