invoices: make duplicate
All checks were successful
Build and Deploy to Production / build (push) Successful in 50s
Build and Deploy to Production / deploy (push) Successful in 26s

This commit is contained in:
Sergei Poljanski 2026-06-09 03:28:42 +03:00
commit cb52388bf1
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
2 changed files with 29 additions and 0 deletions

View file

@ -216,6 +216,32 @@ class AsxpioWeb < Sinatra::Base
erb :'admin/invoices/new'
end
# Start a new invoice prefilled from an existing one ("use as template").
# Reuses the new-invoice form via @form_values. Issue date resets to today and
# the due date keeps the source's payment term (same issued→due gap, anchored
# to today). The snapshotted LTC rate/amount are dropped (stale prices) — the
# address is kept so the operator only re-fetches the live rate.
get '/admin/invoices/:uuid/duplicate' do
src = Invoice[uuid: params[:uuid]] or halt 404
term = (src.due_on - src.issued_on).to_i
@page_title = 'New invoice — admin'
@noindex = true
@form_errors = nil
@form_values = {
client_name: src.client_name,
client_email: src.client_email,
client_address: src.client_address,
currency: src.currency,
gel_rate: src.gel_rate.to_s,
issued_on: Date.today.strftime('%Y-%m-%d'),
due_on: (Date.today + term).strftime('%Y-%m-%d'),
notes: src.notes,
ltc_address: src.ltc_address,
items: src.items_array
}
erb :'admin/invoices/new'
end
post '/admin/invoices' do
@form_values = {
client_name: params[:client_name].to_s.strip,

View file

@ -40,6 +40,9 @@
<% if @invoice.paid? %>Mark unpaid<% else %>Mark paid<% end %>
</button>
</form>
<p style="margin-top: 14px;">
<a href="/admin/invoices/<%= @invoice.uuid %>/duplicate">Use as template for a new invoice →</a>
</p>
</section>
<% unless @invoice.notes.to_s.strip.empty? %>