{{define "invoice_form"}}
<h2>Invoice — {{.Assignment.Name}}</h2>
<p class="muted">{{.Company.Name}} · {{money .TotalHours}} hrs logged = {{money .TotalAmount}} DKK before MVG</p>

<form method="post" action="/invoice">
  <input type="hidden" name="company_id" value="{{.CompanyID}}">
  <input type="hidden" name="assignment_id" value="{{.AssignmentID}}">

  <fieldset>
    <legend>Invoice</legend>
    <p><label>Invoice number<br><input name="invoice_number" value="{{.InvoiceNumber}}" required></label></p>
    <p><label>Date<br><input value="{{.Today}}" disabled></label> <span class="muted">(today)</span></p>
    <p><label>Payment terms (days)<br><input name="due_days" type="number" value="{{.DueDays}}"></label></p>
    <p><label>MVG %<br><input name="mvg" type="number" step="0.01" value="{{money .MVGPercent}}"></label></p>
    <p><label>Comment (optional)<br><textarea name="comment" rows="2"></textarea></label></p>
  </fieldset>

  <fieldset>
    <legend>Sender</legend>
    <p><label>Name<br><input name="from_name" value="{{.Cfg.CompanyName}}"></label></p>
    <p><label>Address<br><input name="from_address" value="{{.Cfg.CompanyAddress}}"></label></p>
    <p><label>Phone<br><input name="from_phone" value="{{.Cfg.CompanyPhone}}"></label></p>
    <p><label>Email<br><input name="from_email" value="{{.Cfg.CompanyEmail}}"></label></p>
    <p><label>Web<br><input name="from_web" value="{{.Cfg.CompanyWeb}}"></label></p>
    <p><label>V-tal<br><input name="from_vat" value="{{.Cfg.TaxID}}"></label></p>
    <p><label>Bank info<br><textarea name="bank_info" rows="3">{{.Cfg.BankInfo}}</textarea></label></p>
  </fieldset>

  <fieldset>
    <legend>Extra lines (optional)</legend>
    <div id="extra-lines"></div>
    <button type="button" hx-get="/invoice/line" hx-target="#extra-lines" hx-swap="beforeend">Add line</button>
  </fieldset>

  <p>
    <button type="submit">Generate PDF</button>
    <button type="button"
            hx-get="/main?company_id={{.CompanyID}}&assignment_id={{.AssignmentID}}"
            hx-target="#main">Back</button>
  </p>
</form>
{{end}}

{{define "invoice_line"}}
<div class="line">
  <input name="extra_desc" placeholder="description">
  <input name="extra_qty" type="number" step="0.01" placeholder="qty">
  <select name="extra_unit"><option value="stk">stk</option><option value="tímar">tímar</option></select>
  <input name="extra_price" type="number" step="0.01" placeholder="unit price">
  <button type="button" hx-get="/void" hx-target="closest .line" hx-swap="outerHTML">×</button>
</div>
{{end}}
