invoicing: admin and public views

Three admin templates:

- index: invoice list with status badge and link to detail.
- new: client + terms fields, dynamic line-item rows backed by
  admin-invoice-form.js (add/remove + re-index of items[N][...] names).
- show: invoice detail, public URL to share, toggle-paid button.

One public template, invoice_public.erb, shown at /i/:uuid: client name,
number, total, status, and a single big download button to /i/:uuid/pdf.

All admin pages are noindex; same for the public landing (it's a
client-specific URL, not search-discoverable content).
This commit is contained in:
Sergei Poljanski 2026-05-26 17:54:40 +03:00
commit 226ccb8192
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
5 changed files with 224 additions and 0 deletions

View file

@ -0,0 +1,41 @@
<div class="header">
<h1>Invoices</h1>
<p class="tagline"><a href="/admin/invoices/new">+ New invoice</a></p>
</div>
<% if @invoices.empty? %>
<section class="section">
<p>No invoices yet. <a href="/admin/invoices/new">Create the first one</a>.</p>
</section>
<% else %>
<section class="section">
<table class="invoice-list">
<thead>
<tr>
<th>Number</th>
<th>Client</th>
<th>Issued</th>
<th class="num">Total</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<% @invoices.each do |inv| %>
<tr>
<td class="mono"><%= inv.number %></td>
<td><%= inv.client_name %></td>
<td class="mono"><%= inv.issued_on.strftime('%Y-%m-%d') %></td>
<td class="num mono"><%= inv.currency %> <%= '%.2f' % inv.total %></td>
<td>
<span class="badge badge-<%= inv.status %>"><%= inv.status %></span>
</td>
<td class="actions">
<a href="/admin/invoices/<%= inv.uuid %>">view</a>
</td>
</tr>
<% end %>
</tbody>
</table>
</section>
<% end %>

View file

@ -0,0 +1,88 @@
<div class="header">
<h1>New invoice</h1>
<p class="tagline"><a href="/admin/invoices">← all invoices</a></p>
</div>
<% if @form_errors && !@form_errors.empty? %>
<div class="form-error-base">
<% @form_errors.each_value do |msg| %>
<div><%= msg %></div>
<% end %>
</div>
<% end %>
<section class="section">
<form class="contact-form invoice-form" method="post" action="/admin/invoices" autocomplete="off">
<input type="hidden" name="authenticity_token" value="<%= csrf_token %>" />
<h2>Client</h2>
<div class="field">
<label for="client_name">Name</label>
<input type="text" id="client_name" name="client_name" value="<%= @form_values[:client_name] %>" required maxlength="200" />
</div>
<div class="field">
<label for="client_email">Email</label>
<input type="email" id="client_email" name="client_email" value="<%= @form_values[:client_email] %>" required maxlength="200" />
</div>
<div class="field">
<label for="client_address">Address <span class="optional">(optional, free text)</span></label>
<textarea id="client_address" name="client_address" rows="3" maxlength="500"><%= @form_values[:client_address] %></textarea>
</div>
<h2>Terms</h2>
<div class="invoice-grid">
<div class="field">
<label for="issued_on">Issued</label>
<input type="date" id="issued_on" name="issued_on" value="<%= @form_values[:issued_on] || Date.today.strftime('%Y-%m-%d') %>" required />
</div>
<div class="field">
<label for="due_on">Due</label>
<input type="date" id="due_on" name="due_on" value="<%= @form_values[:due_on] || (Date.today + 14).strftime('%Y-%m-%d') %>" required />
</div>
<div class="field">
<label for="currency">Currency</label>
<select id="currency" name="currency">
<% Invoice::CURRENCIES.each do |c| %>
<option value="<%= c %>" <%= 'selected' if (@form_values[:currency] || 'EUR') == c %>><%= c %></option>
<% end %>
</select>
</div>
<div class="field">
<label for="gel_rate">GEL rate</label>
<input type="text" id="gel_rate" name="gel_rate" value="<%= @form_values[:gel_rate] %>" placeholder="2.9500" inputmode="decimal" required />
</div>
</div>
<h2>Line items</h2>
<table class="items-table" id="items-table">
<thead>
<tr>
<th>Description</th>
<th class="num">Qty</th>
<th class="num">Unit price</th>
<th></th>
</tr>
</thead>
<tbody>
<% (@form_values[:items] || [{'description' => '', 'qty' => '', 'unit_price' => ''}]).each_with_index do |item, i| %>
<tr class="item-row">
<td><input type="text" name="items[<%= i %>][description]" value="<%= item['description'] %>" placeholder="DevOps engineering — May 2026" maxlength="300" /></td>
<td class="num"><input type="text" name="items[<%= i %>][qty]" value="<%= item['qty'] %>" placeholder="1" inputmode="decimal" /></td>
<td class="num"><input type="text" name="items[<%= i %>][unit_price]" value="<%= item['unit_price'] %>" placeholder="0.00" inputmode="decimal" /></td>
<td class="actions"><button type="button" class="remove-row" aria-label="Remove">×</button></td>
</tr>
<% end %>
</tbody>
</table>
<button type="button" id="add-row" class="link-button">+ add line</button>
<div class="field">
<label for="notes">Notes <span class="optional">(optional)</span></label>
<textarea id="notes" name="notes" rows="3" maxlength="1000"><%= @form_values[:notes] %></textarea>
</div>
<button type="submit">Create invoice</button>
</form>
</section>
<script src="/admin-invoice-form.js"></script>

View file

@ -0,0 +1,43 @@
<div class="header">
<h1><%= @invoice.number %></h1>
<p class="tagline"><a href="/admin/invoices">← all invoices</a></p>
</div>
<section class="section">
<dl class="kv">
<dt>Client</dt><dd><%= @invoice.client_name %> &lt;<%= @invoice.client_email %>&gt;</dd>
<dt>Issued</dt><dd class="mono"><%= @invoice.issued_on.strftime('%Y-%m-%d') %></dd>
<dt>Due</dt><dd class="mono"><%= @invoice.due_on.strftime('%Y-%m-%d') %></dd>
<dt>Total</dt><dd class="mono"><%= @invoice.currency %> <%= '%.2f' % @invoice.total %><% unless @invoice.currency == 'GEL' %> · GEL <%= '%.2f' % @invoice.total_gel %><% end %></dd>
<dt>Status</dt><dd><span class="badge badge-<%= @invoice.status %>"><%= @invoice.status %></span></dd>
<% if @invoice.paid_at %>
<dt>Paid at</dt><dd class="mono"><%= @invoice.paid_at.utc.strftime('%Y-%m-%d %H:%M UTC') %></dd>
<% end %>
</dl>
</section>
<section class="section">
<h2>Actions</h2>
<p>
<a href="/i/<%= @invoice.uuid %>" target="_blank">Public landing page</a>
&nbsp;·&nbsp;
<a href="/i/<%= @invoice.uuid %>/pdf" target="_blank">Download PDF</a>
</p>
<p>
Share this URL with the client:<br />
<code class="mono">https://asxp.io/i/<%= @invoice.uuid %></code>
</p>
<form method="post" action="/admin/invoices/<%= @invoice.uuid %>/paid" style="margin-top: 14px;">
<input type="hidden" name="authenticity_token" value="<%= csrf_token %>" />
<button type="submit">
<% if @invoice.paid? %>Mark unpaid<% else %>Mark paid<% end %>
</button>
</form>
</section>
<% unless @invoice.notes.to_s.strip.empty? %>
<section class="section">
<h2>Notes</h2>
<p style="white-space: pre-wrap;"><%= @invoice.notes %></p>
</section>
<% end %>

24
views/invoice_public.erb Normal file
View file

@ -0,0 +1,24 @@
<div class="header">
<h1>Invoice <%= @invoice.number %></h1>
<p class="tagline">from IE Sergei Poljanski</p>
</div>
<section class="section">
<dl class="kv">
<dt>Billed to</dt><dd><%= @invoice.client_name %></dd>
<dt>Issued</dt><dd class="mono"><%= @invoice.issued_on.strftime('%Y-%m-%d') %></dd>
<dt>Due</dt><dd class="mono"><%= @invoice.due_on.strftime('%Y-%m-%d') %></dd>
<dt>Total</dt><dd class="mono"><%= @invoice.currency %> <%= '%.2f' % @invoice.total %></dd>
<dt>Status</dt><dd><span class="badge badge-<%= @invoice.status %>"><%= @invoice.status %></span></dd>
</dl>
</section>
<section class="section">
<p style="text-align: center;">
<a href="/i/<%= @invoice.uuid %>/pdf" class="download-button">Download PDF</a>
</p>
</section>
<section class="section legal">
<p class="legal-intro">If anything looks wrong, reply to the invoice email or write to <a href="mailto:ie@asxp.io">ie@asxp.io</a>.</p>
</section>