Hi Everyone,
I have a rails application that uses the FreeagentCentral API to create new projects in FreeagentCentral when a new case is created in my application.
Once the case has been created, I link to the created project in FreeagentCentral using the following link code:
<%= link_to "#{image_tag('/images/icons/freeagent.png')} Freeagent Project", "#{Freeagent::Base.site}#{Freeagent::Project.element_path(@kase.freeagent_id).gsub!(/.xml/,'')}" if @kase.freeagent_id %>
What I would like to do, is show a list of invoices that have been created in FreeagentCentral under the project - in my application. So for example, if I create a case in my app it would then be created as a project in FreeagentCentral. If I then created 3 invoices in FreeagentCentral within that project, the 3 invoices would be listed within the case show view of my app.
I am using a FreeagentCentral API gem made by Aaron Russell:
http://github.com/aaronrussell/freeagent_api
I have done what I understand to be necessary, which is added the following to my kases_controller.rb
file under the show section:
def show
@kase = Kase.find(params[:id])
@invoice = Invoice.find(params[:freeagent_id])
I don't know if that's correct, or if it should in fact be:
def show
@kase = Kase.find(params[:id])
@kase = Invoice.find(params[:freeagent_id])
Also, once the above is correct - how do I list any invoices found within that project in my show view?
<% for invoice in @kases %>
<li><%= link_to ??, kase %></li>
<% end %>
If it helps, this is the code I use from kase.rb
to send the case to FreeagentCentral as a project:
# FreeAgent API Project Create
# Required attribues
# :contact_id
# :name
# :billing_basis # must be 1, 7, 7.5, or 8
# :budget_units # must be Hours, Days, or Monetary
# :status # must be Active or Completed
def create_freeagent_project(current_user)
contact = Freeagent::Contact.find_by_name(company.companyname)
p = Freeagent::Project.create(
:contact_id => contact.id,
:name => "#{jobno} - #{highrisesubject}",
:billing_basis => 1,
:budget_units => 'Hours',
:status => 'Active'
)
user = Freeagent::User.find_by_email(current_user.email)
Freeagent::Timeslip.create(
:project_id => p.id,
:user_id => user.id,
:hours => 1,
:new_task => 'Setup',
:dated_on => Time.now
)
Freeagent::Task.create(:project_id => p.id, :name => 'Telephone Discussions')
Freeagent::Task.create(:project_id => p.id, :name => 'Investigation')
Freeagent::Task.create(:project_id => p.id, :name => 'Travel')
Freeagent::Task.create(:project_id => p.id, :name => 'Survey')
Freeagent::Task.create(:project_id => p.id, :name => 'Correspondence')
Freeagent::Task.create(:project_id => p.id, :name => 'Report')
Freeagent::Task.create(:project_id => p.id, :name => 'Claim Assessment')
self.freeagent_id = p.id
self.save
end
Any help anyone could shed on this would be gratefully received!
Thanks,
Danny