41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/controllers/admin/activities_with_prices_controller.rb', line 41
def move_to_invoice
@errors_during_move = []
activity = Activity.find params[:id].to_i
dest_conditions = ['invoices.is_published = ?',false]
dest_conditions[0] += ' AND invoices.id != ?' and dest_conditions << activity.invoice_id if activity
@dest_invoices = Invoice.find_with_totals(
:all,
:conditions => dest_conditions,
:order => 'invoices.issued_on DESC, invoices.id DESC',
:include => [:client]
)
if params.has_key? :move_to_invoice_id
begin
invoice_dest = (params[:move_to_invoice_id].empty?) ?
nil :
Invoice.find(params[:move_to_invoice_id].to_i)
activity.move_to_invoice! invoice_dest
do_list
flash[:warning] = (invoice_dest) ?
('%s successfully moved to "%s"' % [activity.label,invoice_dest.long_name]) :
('The %s was removed from this invoice.' % activity.label)
rescue
@errors_during_move << $!
end
render :action => 'move_to_invoice.js'
else
render :action => 'move_to_invoice.html', :layout => false
end
end
|