mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Working on issue.bill_time
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -8,7 +8,6 @@ gem 'roxml'
|
|||||||
gem 'nhtsa_vin'
|
gem 'nhtsa_vin'
|
||||||
gem 'will_paginate'
|
gem 'will_paginate'
|
||||||
gem 'rails-jquery-autocomplete'
|
gem 'rails-jquery-autocomplete'
|
||||||
gem 'jquery-rails', '~> 3.1.4'
|
|
||||||
gem 'jquery-ui-rails'
|
gem 'jquery-ui-rails'
|
||||||
|
|
||||||
group :assets do
|
group :assets do
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ module IssuePatch
|
|||||||
# Create billable time entries
|
# Create billable time entries
|
||||||
def bill_time
|
def bill_time
|
||||||
|
|
||||||
|
# Check to see if we have everything we need to bill the customer
|
||||||
|
return unless status.is_closed?
|
||||||
return if assigned_to.nil?
|
return if assigned_to.nil?
|
||||||
|
return unless Qbo.first
|
||||||
|
return unless customer
|
||||||
|
|
||||||
# Get unbilled time entries
|
# Get unbilled time entries
|
||||||
spent_time = time_entries.where(qbo_billed: [false, nil])
|
spent_time = time_entries.where(qbo_billed: [false, nil])
|
||||||
@@ -55,15 +59,17 @@ module IssuePatch
|
|||||||
item_service = Qbo.get_base(:item).service
|
item_service = Qbo.get_base(:item).service
|
||||||
time_entry = Quickbooks::Model::TimeActivity.new
|
time_entry = Quickbooks::Model::TimeActivity.new
|
||||||
|
|
||||||
|
# Lets total up each activity before billing.
|
||||||
|
# This will simpify the invoicing with a single billable time entry per time activity
|
||||||
h = Hash.new(0)
|
h = Hash.new(0)
|
||||||
spent_time.each do |entry|
|
spent_time.each do |entry|
|
||||||
# Lets tottal up each activity
|
|
||||||
h[entry.activity.name] += entry.hours
|
h[entry.activity.name] += entry.hours
|
||||||
# update time entries billed status
|
# update time entries billed status
|
||||||
entry.qbo_billed = true
|
entry.qbo_billed = true
|
||||||
entry.save
|
entry.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Now letes upload our totals for each activity as their own billable time entry
|
||||||
h.each do |key, val|
|
h.each do |key, val|
|
||||||
|
|
||||||
# Convert float spent time to hours and minutes
|
# Convert float spent time to hours and minutes
|
||||||
@@ -71,9 +77,11 @@ module IssuePatch
|
|||||||
minutesDecimal = (( val - hours) * 60)
|
minutesDecimal = (( val - hours) * 60)
|
||||||
minutes = minutesDecimal.to_i
|
minutes = minutesDecimal.to_i
|
||||||
|
|
||||||
|
# Lets match the activity to an qbo item
|
||||||
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
||||||
next if item.nil?
|
next if item.nil?
|
||||||
|
|
||||||
|
# Create the new billable time entry and upload it
|
||||||
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
|
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
|
||||||
# TODO entry.user.qbo_employee.id
|
# TODO entry.user.qbo_employee.id
|
||||||
time_entry.employee_id = assigned_to.qbo_employee_id
|
time_entry.employee_id = assigned_to.qbo_employee_id
|
||||||
|
|||||||
@@ -51,6 +51,6 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
|||||||
# Called After Issue Saved
|
# Called After Issue Saved
|
||||||
def controller_issues_edit_after_save(context={})
|
def controller_issues_edit_after_save(context={})
|
||||||
issue = context[:issue]
|
issue = context[:issue]
|
||||||
issue.bill_time if Qbo.first && issue.customer && issue.status.is_closed?
|
issue.bill_time
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user