Added QBO Billed Flag to Time Entries

This allows prevents duplicate billing for Time Entries
This commit is contained in:
2016-01-09 08:45:52 -05:00
parent 7abf20f35d
commit def2bf068e
3 changed files with 29 additions and 3 deletions

View File

@@ -0,0 +1,15 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class UpdateTimeEntries < ActiveRecord::Migration
def change
add_column :time_entries, :qbo_billed, :boolean, :default => false
end
end

View File

@@ -27,7 +27,8 @@ Redmine::Plugin.register :redmine_qbo do
Issue.safe_attributes 'qbo_customer_id'
Issue.safe_attributes 'qbo_item_id'
User.safe_attributes 'qbo_employee_id'
TimeEntry.safe_attributes 'qbo_billed'
# We are playing in the sandbox
Quickbooks.sandbox_mode = true

View File

@@ -24,11 +24,21 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
time_entry = Quickbooks::Model::TimeActivity.new
item = item_service.fetch_by_id issue.qbo_item_id
# Get unbilled time entries
spent_time = issue.time_entries.where(qbo_billed: [false, nil])
spent_hours ||= spent_time.sum(:hours) || 0
# Convert float spent time to hours and minutes
hours = issue.spent_hours.to_i
minutesDecimal = (( issue.spent_hours - hours) * 60)
hours = spent_hours.to_i
minutesDecimal = (( spent_hours - hours) * 60)
minutes = minutesDecimal.to_i
# update time entries billed status
spent_time.each do |entry|
entry.qbo_billed = true
entry.save
end
employee_id = User.find_by_id(issue.assigned_to_id).qbo_employee_id
# If the issue is closed, then create a new billable time activty for the customer