diff --git a/public/admin-invoice-form.js b/public/admin-invoice-form.js new file mode 100644 index 0000000..39b2f1c --- /dev/null +++ b/public/admin-invoice-form.js @@ -0,0 +1,28 @@ +(function () { + const tbody = document.querySelector('#items-table tbody'); + const addBtn = document.getElementById('add-row'); + + function reindex() { + Array.from(tbody.querySelectorAll('tr.item-row')).forEach((row, i) => { + row.querySelectorAll('input').forEach((input) => { + input.name = input.name.replace(/items\[\d+\]/, 'items[' + i + ']'); + }); + }); + } + + addBtn.addEventListener('click', function () { + const last = tbody.querySelector('tr.item-row:last-child'); + const clone = last.cloneNode(true); + clone.querySelectorAll('input').forEach((input) => { input.value = ''; }); + tbody.appendChild(clone); + reindex(); + }); + + tbody.addEventListener('click', function (e) { + if (!e.target.matches('.remove-row')) return; + const rows = tbody.querySelectorAll('tr.item-row'); + if (rows.length <= 1) return; + e.target.closest('tr.item-row').remove(); + reindex(); + }); +})(); diff --git a/views/admin/invoices/index.erb b/views/admin/invoices/index.erb new file mode 100644 index 0000000..08241c0 --- /dev/null +++ b/views/admin/invoices/index.erb @@ -0,0 +1,41 @@ +
No invoices yet. Create the first one.
+| Number | +Client | +Issued | +Total | +Status | ++ |
|---|---|---|---|---|---|
| <%= inv.number %> | +<%= inv.client_name %> | +<%= inv.issued_on.strftime('%Y-%m-%d') %> | +<%= inv.currency %> <%= '%.2f' % inv.total %> | ++ <%= inv.status %> + | ++ view + | +
+ Public landing page + · + Download PDF +
+
+ Share this URL with the client:
+ https://asxp.io/i/<%= @invoice.uuid %>
+
<%= @invoice.notes %>
+from IE Sergei Poljanski
++ Download PDF +
+If anything looks wrong, reply to the invoice email or write to ie@asxp.io.
+