invoices: make duplicate
This commit is contained in:
parent
7ed1a674aa
commit
cb52388bf1
2 changed files with 29 additions and 0 deletions
26
asxpio.rb
26
asxpio.rb
|
|
@ -216,6 +216,32 @@ class AsxpioWeb < Sinatra::Base
|
||||||
erb :'admin/invoices/new'
|
erb :'admin/invoices/new'
|
||||||
end
|
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
|
post '/admin/invoices' do
|
||||||
@form_values = {
|
@form_values = {
|
||||||
client_name: params[:client_name].to_s.strip,
|
client_name: params[:client_name].to_s.strip,
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,9 @@
|
||||||
<% if @invoice.paid? %>Mark unpaid<% else %>Mark paid<% end %>
|
<% if @invoice.paid? %>Mark unpaid<% else %>Mark paid<% end %>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
<p style="margin-top: 14px;">
|
||||||
|
<a href="/admin/invoices/<%= @invoice.uuid %>/duplicate">Use as template for a new invoice →</a>
|
||||||
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<% unless @invoice.notes.to_s.strip.empty? %>
|
<% unless @invoice.notes.to_s.strip.empty? %>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue