Added invoices subview for customers, improved invoice forms.
This commit is contained in:
parent
95de3d4dc3
commit
f0c7f59529
159
stoptime.rb
159
stoptime.rb
|
@ -27,7 +27,7 @@ unless defined? PUBLIC_DIR
|
||||||
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
|
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
|
||||||
:default => "%Y-%m-%d %H:%M",
|
:default => "%Y-%m-%d %H:%M",
|
||||||
:month_and_year => "%B %Y",
|
:month_and_year => "%B %Y",
|
||||||
:month_code => "%Y%m",
|
:date_only => "%Y-%m-%d",
|
||||||
:day_code => "%Y%m%d")
|
:day_code => "%Y%m%d")
|
||||||
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
|
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
|
||||||
:default => "%Y-%m-%d",
|
:default => "%Y-%m-%d",
|
||||||
|
@ -308,9 +308,11 @@ module StopTime::Controllers
|
||||||
class CustomersN
|
class CustomersN
|
||||||
def get(customer_id)
|
def get(customer_id)
|
||||||
@customer = Customer.find(customer_id)
|
@customer = Customer.find(customer_id)
|
||||||
@edit_task = true
|
@invoices = @customer.invoices
|
||||||
@target = [CustomersN, @customer.id]
|
|
||||||
@input = @customer.attributes
|
@input = @customer.attributes
|
||||||
|
|
||||||
|
@target = [CustomersN, @customer.id]
|
||||||
|
@edit_task = true
|
||||||
render :customer_form
|
render :customer_form
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -489,6 +491,7 @@ module StopTime::Controllers
|
||||||
@period = @invoice.period
|
@period = @invoice.period
|
||||||
|
|
||||||
if @format == "html"
|
if @format == "html"
|
||||||
|
@input = @invoice.attributes
|
||||||
render :invoice
|
render :invoice
|
||||||
elsif @format == "pdf"
|
elsif @format == "pdf"
|
||||||
pdf_file = PUBLIC_DIR + "#{@number}.pdf"
|
pdf_file = PUBLIC_DIR + "#{@number}.pdf"
|
||||||
|
@ -499,6 +502,14 @@ module StopTime::Controllers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post(customer_id, invoice_number)
|
||||||
|
invoice = Invoice.find_by_number(invoice_number)
|
||||||
|
invoice.payed = @input.has_key? "payed"
|
||||||
|
invoice.save
|
||||||
|
|
||||||
|
redirect R(CustomersNInvoicesX, customer_id, invoice_number)
|
||||||
|
end
|
||||||
|
|
||||||
def _generate_invoice_pdf(number)
|
def _generate_invoice_pdf(number)
|
||||||
template = TEMPLATE_DIR + "invoice.tex.erb"
|
template = TEMPLATE_DIR + "invoice.tex.erb"
|
||||||
tex_file = PUBLIC_DIR + "#{number}.tex"
|
tex_file = PUBLIC_DIR + "#{number}.tex"
|
||||||
|
@ -815,10 +826,48 @@ module StopTime::Views
|
||||||
end
|
end
|
||||||
a "Add a new project/task", :href => R(CustomersNTasksNew, @customer.id)
|
a "Add a new project/task", :href => R(CustomersNTasksNew, @customer.id)
|
||||||
|
|
||||||
|
|
||||||
|
h2 "Invoices"
|
||||||
|
_invoice_list(@invoices)
|
||||||
a "Create a new invoice", :href => R(CustomersNInvoicesNew, @customer.id)
|
a "Create a new invoice", :href => R(CustomersNInvoicesNew, @customer.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _invoice_list(invoices)
|
||||||
|
if invoices.empty?
|
||||||
|
p "None!"
|
||||||
|
else
|
||||||
|
table do
|
||||||
|
tr do
|
||||||
|
th "Number"
|
||||||
|
th "Date"
|
||||||
|
th "Period"
|
||||||
|
th "Payed"
|
||||||
|
end
|
||||||
|
invoices.each do |invoice|
|
||||||
|
tr do
|
||||||
|
td do
|
||||||
|
a invoice.number,
|
||||||
|
:href => R(CustomersNInvoicesX, @customer.id, invoice.number)
|
||||||
|
end
|
||||||
|
td { invoice.updated_at }
|
||||||
|
td { _format_period(invoice.period) }
|
||||||
|
# FIXME: really retrieve the payed flag.
|
||||||
|
td { _form_input_checkbox("payed_#{invoice.number}") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def _format_period(period)
|
||||||
|
period = period.map { |m| m.to_formatted_s(:month_and_year) }.uniq
|
||||||
|
case period.length
|
||||||
|
when 1: period.first
|
||||||
|
when 2: period.join("–")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def task_form
|
def task_form
|
||||||
form :action => R(*@target), :method => :post do
|
form :action => R(*@target), :method => :post do
|
||||||
ul do
|
ul do
|
||||||
|
@ -849,7 +898,35 @@ module StopTime::Views
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoice
|
def invoice
|
||||||
h2 { "Invoice for #{@customer.name}, period N/A" }
|
h2 do
|
||||||
|
span "Invoice for "
|
||||||
|
a @customer.name, :href => R(CustomersN, @customer.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
form :action => R(CustomersNInvoicesX, @customer.id, @invoice.number),
|
||||||
|
:method => :post do
|
||||||
|
table do
|
||||||
|
tr do
|
||||||
|
td { b "Number" }
|
||||||
|
td { @invoice.number }
|
||||||
|
end
|
||||||
|
tr do
|
||||||
|
td { b "Date" }
|
||||||
|
td { @invoice.updated_at.to_formatted_s(:date_only) }
|
||||||
|
end
|
||||||
|
tr do
|
||||||
|
td { b "Period" }
|
||||||
|
td { _format_period(@invoice.period) }
|
||||||
|
end
|
||||||
|
tr do
|
||||||
|
td { b "Payed" }
|
||||||
|
td do
|
||||||
|
_form_input_checkbox("payed")
|
||||||
|
input :type => :submit, :name => "update", :value => "Update"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table do
|
table do
|
||||||
tr do
|
tr do
|
||||||
|
@ -901,54 +978,58 @@ module StopTime::Views
|
||||||
|
|
||||||
def invoice_select_form
|
def invoice_select_form
|
||||||
form :action => R(CustomersNInvoices, @customer.id), :method => :post do
|
form :action => R(CustomersNInvoices, @customer.id), :method => :post do
|
||||||
h2 "Registered time"
|
unless @hourly_rate_tasks.empty?
|
||||||
table do
|
h2 "Registered time"
|
||||||
tr do
|
table do
|
||||||
th ""
|
|
||||||
th "Start"
|
|
||||||
th "End"
|
|
||||||
th "Comment"
|
|
||||||
th "Total"
|
|
||||||
th "Amount"
|
|
||||||
end
|
|
||||||
@hourly_rate_tasks.keys.each do |task|
|
|
||||||
tr do
|
tr do
|
||||||
td { _form_input_checkbox("tasks[]", task.id) }
|
th ""
|
||||||
td task.name, :colspan => 5
|
th "Start"
|
||||||
|
th "End"
|
||||||
|
th "Comment"
|
||||||
|
th "Total"
|
||||||
|
th "Amount"
|
||||||
end
|
end
|
||||||
@hourly_rate_tasks[task].each do |entry|
|
@hourly_rate_tasks.keys.each do |task|
|
||||||
tr do
|
tr.task do
|
||||||
td { _form_input_checkbox("time_entries[]", entry.id) }
|
td { _form_input_checkbox("tasks[]", task.id) }
|
||||||
td { label entry.start, :for => "time_entries[]_#{entry.id}" }
|
td task.name, :colspan => 5
|
||||||
td { entry.end }
|
end
|
||||||
td { entry.comment }
|
@hourly_rate_tasks[task].each do |entry|
|
||||||
td { entry.total }
|
tr do
|
||||||
td { entry.total * entry.task.hourly_rate }
|
td { _form_input_checkbox("time_entries[]", entry.id) }
|
||||||
|
td { label entry.start, :for => "time_entries[]_#{entry.id}" }
|
||||||
|
td { entry.end }
|
||||||
|
td { entry.comment }
|
||||||
|
td { "%.2fh" % entry.hours_total }
|
||||||
|
td { "€ %.2f" % (entry.hours_total * entry.task.hourly_rate) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
h2 "Fixed cost tasks"
|
unless @fixed_cost_tasks.empty?
|
||||||
table do
|
h2 "Fixed cost tasks"
|
||||||
tr do
|
table do
|
||||||
th ""
|
|
||||||
th "Task"
|
|
||||||
th "Registered time"
|
|
||||||
th "Amount"
|
|
||||||
end
|
|
||||||
@fixed_cost_tasks.keys.each do |task|
|
|
||||||
tr do
|
tr do
|
||||||
td { _form_input_checkbox("tasks[]", task.id) }
|
th ""
|
||||||
td { label task.name, :for => "tasks[]_#{task.id}" }
|
th "Task"
|
||||||
td { "%.2fh" % @fixed_cost_tasks[task] }
|
th "Registered time"
|
||||||
td { task.fixed_cost }
|
th "Amount"
|
||||||
|
end
|
||||||
|
@fixed_cost_tasks.keys.each do |task|
|
||||||
|
tr do
|
||||||
|
td { _form_input_checkbox("tasks[]", task.id) }
|
||||||
|
td { label task.name, :for => "tasks[]_#{task.id}" }
|
||||||
|
td { "%.2fh" % @fixed_cost_tasks[task] }
|
||||||
|
td { task.fixed_cost }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
input :type => :submit, :name => "create", :value => "Create invoice"
|
input :type => :submit, :name => "create", :value => "Create invoice"
|
||||||
input :type => "submit", :name => "cancel", :value => "Cancel"
|
input :type => :submit, :name => "cancel", :value => "Cancel"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue