costagent 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/costagent.rb +15 -4
  2. metadata +3 -3
data/lib/costagent.rb CHANGED
@@ -7,8 +7,8 @@ require "open-uri"
7
7
  # This exposes additional billable tracking functionality around the Freeagent API
8
8
  class CostAgent
9
9
  Project = Struct.new(:id, :name, :currency, :hourly_billing_rate, :daily_billing_rate, :hours_per_day)
10
- Timeslip = Struct.new(:id, :project, :hours, :date, :cost, :comment, :status)
11
- Task = Struct.new(:id, :name, :project)
10
+ Timeslip = Struct.new(:id, :project, :task, :hours, :date, :cost, :comment, :status)
11
+ Task = Struct.new(:id, :name, :project, :hourly_billing_rate, :daily_billing_rate, :billable)
12
12
  Invoice = Struct.new(:id, :project_id, :description, :reference, :amount, :status, :date, :due, :items)
13
13
  InvoiceItem = Struct.new(:id, :invoice_id, :project_id, :item_type, :description, :price, :quantity, :cost)
14
14
 
@@ -53,13 +53,16 @@ class CostAgent
53
53
  # Find the project and hours for this timeslip
54
54
  project = self.project((timeslip/"project-id").text.to_i)
55
55
  if project
56
+ task = self.tasks(project.id).detect { |t| t.id == (timeslip/"task-id").text.to_i }
56
57
  hours = (timeslip/"hours").text.to_f
58
+ cost = (task.nil? ? project : task).hourly_billing_rate * hours
57
59
  # Build the timeslip out using the timeslip data and the project it's tied to
58
60
  Timeslip.new((timeslip/"id").text.to_i,
59
61
  project,
62
+ task,
60
63
  hours,
61
64
  DateTime.parse((timeslip/"dated-on").text),
62
- project.hourly_billing_rate * hours,
65
+ cost,
63
66
  (timeslip/"comment").text,
64
67
  (timeslip/"status").text)
65
68
  else
@@ -73,10 +76,18 @@ class CostAgent
73
76
  (self.api("projects/#{project_id}/tasks")/"task").collect do |task|
74
77
  # Find the project for this task
75
78
  project = self.project((task/"project-id").text.to_i)
79
+ # Calculate rates
80
+ billing_rate = (task/"billing-rate").text.to_f
81
+ billing_period = (task/"billing-period").text
82
+ hourly_rate = (billing_period == "hour" ? billing_rate : billing_rate / project.hours_per_day)
83
+ daily_rate = (billing_period == "hour" ? billing_rate * project.hours_per_day : billing_rate)
76
84
  # Build the task out using the task data and the project it's tied to
77
85
  Task.new((task/"id").text.to_i,
78
86
  (task/"name").text,
79
- project)
87
+ project,
88
+ hourly_rate,
89
+ daily_rate,
90
+ (task/"is-billable").text == "true")
80
91
  end
81
92
  end
82
93
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Elliott Draper
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-10 00:00:00 +01:00
17
+ date: 2010-10-11 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency