extends ../PaperTemplateLayout.pug

block head
  style
    if (isRtl)
      include ../../css/modules/invoice-rtl.css
    else
      include ../../css/modules/invoice.css

block content 
 div.invoice
  div.invoice__header
    div.paper
      h1.title #{__("invoice.paper.invoice")}
      if saleInvoice.invoiceNo
       span.invoiceNo #{saleInvoice.invoiceNo}

    div.organization
      h3.title #{organizationName}
      if organizationEmail
       span.email #{organizationEmail}

  div.invoice__due-amount
    div.label #{__('invoice.paper.invoice_amount')}
    div.amount #{saleInvoice.totalFormatted}

  div.invoice__meta
   div.invoice__meta-item.invoice__meta-item--amount
    span.label #{__('invoice.paper.due_amount')}
    span.value #{saleInvoice.dueAmountFormatted}

   div.invoice__meta-item.invoice__meta-item--billed-to
    span.label #{__("invoice.paper.billed_to")}
    span.value #{saleInvoice.customer.displayName}

   div.invoice__meta-item.invoice__meta-item--invoice-date
    span.label #{__("invoice.paper.invoice_date")}
    span.value #{saleInvoice.invoiceDateFormatted}

   div.invoice__meta-item.invoice__meta-item--due-date
    span.label #{__("invoice.paper.due_date")}
    span.value #{saleInvoice.dueDateFormatted}

  div.invoice__table
   table 
    thead 
     tr
       th.item #{__("item_entry.paper.item_name")}
       th.rate #{__("item_entry.paper.rate")}
       th.quantity #{__("item_entry.paper.quantity")}
       th.total #{__("item_entry.paper.total")}
    tbody
      each entry in saleInvoice.entries
       tr
        td.item
         div.title=entry.item.name
         span.description=entry.description
        td.rate=entry.rate
        td.quantity=entry.quantity
        td.total=entry.amount

  div.invoice__table-after
    div.invoice__table-total
      table 
        tbody
          tr.subtotal
            td #{__('invoice.paper.subtotal')}
            td #{saleInvoice.subtotalFormatted}
          each tax in saleInvoice.taxes
            tr.tax_line 
              td #{tax.name} [#{tax.taxRate}%]
              td #{tax.taxRateAmountFormatted}
          tr.total
            td #{__('invoice.paper.total')}
            td #{saleInvoice.totalFormatted}
          tr.payment-amount
            td #{__('invoice.paper.payment_amount')}
            td #{saleInvoice.paymentAmountFormatted}
          tr.blanace-due
            td #{__('invoice.paper.balance_due')}
            td #{saleInvoice.dueAmountFormatted}

  div.invoice__footer        
    if saleInvoice.termsConditions
     div.invoice__conditions
      h3 #{__("invoice.paper.conditions_title")}
      p #{saleInvoice.termsConditions}

    if saleInvoice.invoiceMessage
     div.invoice__notes
      h3 #{__("invoice.paper.notes_title")}
      p #{saleInvoice.invoiceMessage}