From 87b8d99c41f447905949679c77ecd233a2c8c2d6 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 26 Mar 2019 12:09:38 -0400 Subject: [PATCH] Working on issue.bill_time --- Gemfile | 1 - lib/issue_patch.rb | 12 ++++++++++-- lib/issues_save_hook_listener.rb | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index a28724a..2acdd86 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,6 @@ gem 'roxml' gem 'nhtsa_vin' gem 'will_paginate' gem 'rails-jquery-autocomplete' -gem 'jquery-rails', '~> 3.1.4' gem 'jquery-ui-rails' group :assets do diff --git a/lib/issue_patch.rb b/lib/issue_patch.rb index 756d0da..db0b6e1 100644 --- a/lib/issue_patch.rb +++ b/lib/issue_patch.rb @@ -42,7 +42,11 @@ module IssuePatch # Create billable time entries 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 unless Qbo.first + return unless customer # Get unbilled time entries spent_time = time_entries.where(qbo_billed: [false, nil]) @@ -55,25 +59,29 @@ module IssuePatch item_service = Qbo.get_base(:item).service 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) spent_time.each do |entry| - # Lets tottal up each activity h[entry.activity.name] += entry.hours # update time entries billed status entry.qbo_billed = true entry.save end + # Now letes upload our totals for each activity as their own billable time entry h.each do |key, val| # Convert float spent time to hours and minutes hours = val.to_i minutesDecimal = (( val - hours) * 60) minutes = minutesDecimal.to_i - + + # Lets match the activity to an qbo item item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first 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?}" # TODO entry.user.qbo_employee.id time_entry.employee_id = assigned_to.qbo_employee_id diff --git a/lib/issues_save_hook_listener.rb b/lib/issues_save_hook_listener.rb index 3647434..ad628bc 100644 --- a/lib/issues_save_hook_listener.rb +++ b/lib/issues_save_hook_listener.rb @@ -51,6 +51,6 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener # Called After Issue Saved def controller_issues_edit_after_save(context={}) issue = context[:issue] - issue.bill_time if Qbo.first && issue.customer && issue.status.is_closed? + issue.bill_time end end