mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Compare commits
139 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fee0548899 | |||
| 5ddb45ba24 | |||
| 98c965c607 | |||
| 6e1d23af4e | |||
| 8da45bd348 | |||
| 620c4b395e | |||
| d75208a75a | |||
| 4f08825fb1 | |||
| 865470fc11 | |||
| d827936c85 | |||
| fcc614ff54 | |||
| b7abe2610e | |||
| d916464423 | |||
| 32164157c2 | |||
| ce4b957c8e | |||
| 3735629073 | |||
| d41d618be5 | |||
| d97f3cb2a3 | |||
| dcf31116b4 | |||
| 219141eeee | |||
| 765b5b6024 | |||
| 4efca93d03 | |||
| e2a4908420 | |||
| 183b8d17e6 | |||
| ed2b84c697 | |||
| 59410e6d77 | |||
| a134d1b601 | |||
| 56161f12d0 | |||
| 146dbb137c | |||
| 4f23439dac | |||
| 8b33aa6f6a | |||
| 4f72a8e5ad | |||
| fae4782ef0 | |||
| 37ea01de8c | |||
| 2c53155207 | |||
| dbe585ca2a | |||
| 6434092306 | |||
| 8720176b57 | |||
| 5bdf313fa5 | |||
| 4527e74d29 | |||
| 8e6e543c5b | |||
| dbbd4a2593 | |||
| 6b55f92454 | |||
| fba9645932 | |||
| 0cc867b410 | |||
| 40f738d976 | |||
| 82ecaae156 | |||
| 8d4ac896fa | |||
| 7c6246a539 | |||
| ce88cdd258 | |||
| f179b04af1 | |||
| 0070264d51 | |||
| 22db89a6d9 | |||
| 78dfad9875 | |||
| 6a55138f7c | |||
| f95ee10290 | |||
| adb864c9ca | |||
| f3f92e48e0 | |||
| 87a9d978c2 | |||
| 9981b9ef70 | |||
| 94f10dc9cd | |||
| e3fdc070df | |||
| 4cae63d02b | |||
| d856ceeec7 | |||
| d461570b14 | |||
| 924e0d7bc9 | |||
| 6b3280edaf | |||
| 722d66f130 | |||
| 16083a6f30 | |||
| 1b6fe073dc | |||
| 9f6103ad89 | |||
| 8a67cdf37c | |||
| 9b444d638b | |||
| abab81158f | |||
| 26c0716d35 | |||
| 7f7c724ef1 | |||
| f083e8257a | |||
| 4cb588e992 | |||
| 245d2b49a2 | |||
| e888bd0d38 | |||
| 6cfd56ed01 | |||
| 647af6f87a | |||
| 0e2f9b1031 | |||
| 86ee8908b3 | |||
| a0618b51ba | |||
| 272369ba4c | |||
| 6319c24b5c | |||
| a3180a318c | |||
| aeb890cbed | |||
| 4a94ca1d17 | |||
| 63d845ed97 | |||
| cb67cab974 | |||
| df94564d9b | |||
| 540e008f68 | |||
| c85d3ba8d5 | |||
| 1df335ed16 | |||
| 7ca5076477 | |||
| 6605946e62 | |||
| ba45c776ae | |||
| dcf17052b6 | |||
| 8b9acccb8a | |||
| 2afed176f0 | |||
| 577788110e | |||
| d251ea066f | |||
| 609e65b7cd | |||
| 6c2dd29a57 | |||
| 98896ac0a6 | |||
| 19ba3abade | |||
| 3347490b82 | |||
| d1457b09be | |||
| 1b71439f19 | |||
| 55c09d7e9d | |||
| 8429c29c30 | |||
| 10f8a7e124 | |||
| e8763ea923 | |||
| e5601030b1 | |||
| ad8d15203e | |||
| 3b4e55727c | |||
| 5dc2921d40 | |||
| 0c4ef8abe9 | |||
| 8165523acf | |||
| 7d1e9bb838 | |||
| 0d9140958f | |||
| 16ca8177e9 | |||
| a0e9061a8f | |||
| a56c01fe6d | |||
| 1cb9639f03 | |||
| 7af89db442 | |||
| fae815fd7f | |||
| 1b533d6dd8 | |||
| bc38361348 | |||
| a0a365c10e | |||
| 162c76471b | |||
| 328a50be47 | |||
| 7cc84277c6 | |||
| fbac6b6d77 | |||
| 33b5ac8c87 | |||
| 74f179d64b | |||
| 3cef188ff3 |
1
Gemfile
1
Gemfile
@@ -7,3 +7,4 @@ gem 'oauth'
|
||||
gem 'roxml'
|
||||
gem 'edmunds_vin'
|
||||
gem 'will_paginate', '~> 3.1.0'
|
||||
gem 'rails4-autocomplete'
|
||||
|
||||
47
README.md
47
README.md
@@ -1,20 +1,32 @@
|
||||
#Redmine Quickbooks Online
|
||||
|
||||
A simple plugin for Redmine to connect to Quickbooks Online
|
||||
A plugin for Redmine to connect to Quickbooks Online
|
||||
|
||||
The goal of this project is to allow redmine to connect with Quickbooks Online to create time activity entries for completed work when an issue is closed.
|
||||
The goal of this project is to allow Redmine to connect with Quickbooks Online to create `Time Activity Entries` for completed work when an Issue is closed.
|
||||
|
||||
`Note: This project is under heavy development. Currently the initial functionality goal has been meet, however I am still working on adding other features. Tags should be stable`
|
||||
`Note: Although the core functionality is complete, this project is still under heavy development. I am still working on refining everthing and adding other features. Tags should be stable`
|
||||
|
||||
####How it works
|
||||
* Issues can be assigned to a QBO Customer and QBO Service Item via drop down in issues form
|
||||
- The `QBO Employee` for the issue is assigned via the assigned redmine user
|
||||
- IF an `Issue` has been assined a `QBO Customer`, `QBO Service Item` & `QBO Employee` when an `Issue` is closed the following will happen:
|
||||
- A new `QBO Time Activity` agaist the `QBO Customer` will be created using the total spent hours logged agaist an `Issue`.
|
||||
- The rate will be the set via the `QBO Service Item` price
|
||||
* `Issues` with the Tracker `Quote` will generate an estimate based on the estimated hours and `QBO Service Item` cost.
|
||||
- Needs to have a `QBO Customer` & `QBO Service Item` Assiged
|
||||
* Users will be assigned a `QBO Employee` via a drop down in the user admistration page.
|
||||
####Features
|
||||
* Issues can be assigned to a `Customer` via drop down in the edit Issue form
|
||||
* The `Employee` for the Issue is assigned via the assigned Redmine User
|
||||
- This is set via a drop down in the user admistration page.
|
||||
* IF an `Issue` has been assined a `Customer` when an Issue is closed the following will happen:
|
||||
- A new `Time Activity` will be created for the `Customer` assinged to the issue for each Redmine Time Entery.
|
||||
+ Time Entries will be totalled up by Activity name. This will allow billing for diffrent activities without having to create seperate Issues.
|
||||
+ The Time Activity names are used to lookup `Items` in Quickbooks.
|
||||
+ IF there isn'tany Items that match the Activity name it will be skipped, and will not be billed to the `Customer`
|
||||
- Labor Rates are set by the `Item` in Quickbooks
|
||||
* `Issues` with the Tracker `Quote` will generate an estimate based on the estimated hours and `Item` rates.
|
||||
- Needs to have a `Customer` Assiged
|
||||
* `Payments` Can be created via the Redmine application menu
|
||||
* `Customers` Can be created via the Redmine application menu
|
||||
* `Customers` can be searched
|
||||
* Basic information for the `Customer` can be viewed via the customer page
|
||||
* `Custmoer` information can be update
|
||||
* Webhook Support
|
||||
- `Invoices` are automaticly attached to an Issue if a line item has a hashtag number in a `Line Item`
|
||||
+ `Invoice` Custom Fields are matched Issue Custom Fileds and are automaticly updated in Quickbooks. For example, this is usefull for extracting the Mileage In / Out from the Issue and updating the Invoice with the information.
|
||||
- `Customers` are automaticly updated in local database
|
||||
|
||||
##Prerequisites
|
||||
|
||||
@@ -45,7 +57,7 @@ The goal of this project is to allow redmine to connect with Quickbooks Online t
|
||||
|
||||
## Usage
|
||||
|
||||
To enable automatic `QBO Time Activity` entries for an `Issue` , you need only to assign a `QBO Customer` and `QBO Item` to an `Issue` via drop downs in the creation/update form.
|
||||
To enable automatic `Time Activity` entries for an Issue , you need only to assign a `Customer` to an Issue via drop downs in the issue creation/update form.
|
||||
|
||||

|
||||
|
||||
@@ -53,10 +65,17 @@ Note: After the inital synchronization, this plugin will recieve push notificati
|
||||
|
||||
## TODO
|
||||
* Abiltiy to add line items to a ticket in a dynamic table so they can be added to the invoice upon closing of the issue
|
||||
* Customer ~~Creation~~, ~~Update~~, Deletion
|
||||
* Customer Deletion
|
||||
* Email Customer updates, provding a link that would: bypass the login page, go directly to the issue directing them to, and allow them to view only that issue.
|
||||
* Add a rake file to create required Trackers or statuses required
|
||||
* Add Setting for Sandbox Mode
|
||||
* Refactor Models prefixed with Qbo...
|
||||
* Allow multiple Invoices to be attached to an Issue
|
||||
* Seperate Vehicles into a seperate plugin
|
||||
* Make HTML Pretty
|
||||
* Intergrate Customer Search into Redmine Search
|
||||
* Fix Issue sort by Customer
|
||||
* MORE Stuff...
|
||||
|
||||
##License
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ class PaymentsController < ApplicationController
|
||||
def new
|
||||
@payment = Payment.new
|
||||
|
||||
@customers = Customer.all
|
||||
@customers = Customer.all.sort_by &:name
|
||||
|
||||
@accounts = Qbo.get_base(:account).service.query("SELECT Id, Name FROM Account WHERE AccountType = 'Bank' ")
|
||||
@accounts = Qbo.get_base(:account).service.query("SELECT Id, Name FROM Account WHERE AccountType = 'Bank' Order By Name")
|
||||
|
||||
@payment_methods = Qbo.get_base(:payment_method).service.all
|
||||
end
|
||||
|
||||
@@ -57,12 +57,19 @@ class QboController < ApplicationController
|
||||
qbo.reconnect_token_at = 5.months.from_now.utc
|
||||
qbo.company_id = params['realmId']
|
||||
if qbo.save!
|
||||
redirect_to qbo_path, :flash => { :notice => "Successfully connected to Quickbooks" }
|
||||
redirect_to qbo_sync_path, :flash => { :notice => "Successfully connected to Quickbooks" }
|
||||
else
|
||||
redirect_to plugin_settings_path(:redmine_qbo), :flash => { :error => "Error" }
|
||||
end
|
||||
end
|
||||
|
||||
# Manual Billing
|
||||
def bill
|
||||
i = Issue.find_by_id params[:id]
|
||||
i.bill_time
|
||||
redirect_to i, :flash => { :notice => "Successfully Billed #{i.customer.name}" }
|
||||
end
|
||||
|
||||
# Quickbooks Webhook Callback
|
||||
def qbo_webhook
|
||||
|
||||
@@ -118,15 +125,19 @@ class QboController < ApplicationController
|
||||
# Synchronizes the QboCustomer table with QBO
|
||||
#
|
||||
def sync
|
||||
if Qbo.exists?
|
||||
Customer.sync
|
||||
QboItem.sync
|
||||
QboEmployee.sync
|
||||
QboEstimate.sync
|
||||
QboInvoice.sync
|
||||
|
||||
# Record the last sync time
|
||||
Qbo.update_time_stamp
|
||||
# Update info in background
|
||||
Thread.new do
|
||||
if Qbo.exists?
|
||||
Customer.sync
|
||||
QboItem.sync
|
||||
QboEmployee.sync
|
||||
QboEstimate.sync
|
||||
QboInvoice.sync
|
||||
|
||||
# Record the last sync time
|
||||
Qbo.update_time_stamp
|
||||
end
|
||||
ActiveRecord::Base.connection.close
|
||||
end
|
||||
|
||||
redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" }
|
||||
|
||||
@@ -10,18 +10,17 @@
|
||||
|
||||
class QboInvoice < ActiveRecord::Base
|
||||
unloadable
|
||||
has_many :issues
|
||||
|
||||
has_and_belongs_to_many :issues
|
||||
attr_accessible :doc_number
|
||||
validates_presence_of :id, :doc_number
|
||||
validates_presence_of :doc_number
|
||||
self.primary_key = :id
|
||||
|
||||
def self.get_base
|
||||
Qbo.get_base(:invoice)
|
||||
end
|
||||
|
||||
def self.sync
|
||||
#Pull the invoices from the quickbooks server
|
||||
#invoices = get_base.service.all
|
||||
|
||||
last = Qbo.first.last_sync
|
||||
|
||||
query = "SELECT Id, DocNumber FROM Invoice"
|
||||
@@ -35,41 +34,70 @@ class QboInvoice < ActiveRecord::Base
|
||||
|
||||
# Update the invoice table
|
||||
invoices.each { | invoice |
|
||||
qbo_invoice = find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.save!
|
||||
sync_by_id invoice.id
|
||||
}
|
||||
|
||||
#remove deleted invoices
|
||||
#where.not(invoices.map(&:id)).destroy_all
|
||||
end
|
||||
|
||||
def self.sync_by_id(id)
|
||||
#update the information in the database
|
||||
invoice = get_base.service.fetch_by_id(id)
|
||||
invoice = Qbo.get_base(:invoice).service.fetch_by_id(id)
|
||||
qbo_invoice = find_or_create_by(id: invoice.id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.id = invoice.id
|
||||
qbo_invoice.save!
|
||||
|
||||
is_changed = false
|
||||
|
||||
# Scan the line items for hashtags and attach to the applicable issues
|
||||
invoice.line_items.each { |line|
|
||||
if line.description
|
||||
line.description.scan(/#(\w+)/).flatten.each { |issue|
|
||||
i = Issue.find_by_id(issue.to_i)
|
||||
i.qbo_invoice = QboInvoice.find_by_id(invoice.id.to_i)
|
||||
i.save!
|
||||
begin
|
||||
i.qbo_invoices << QboInvoice.find_by_id(invoice.id.to_i)
|
||||
i.save!
|
||||
rescue
|
||||
# do nothing, the reccord exists
|
||||
end
|
||||
|
||||
# update the invoive custom fields with infomation from the work ticket if available
|
||||
invoice.custom_fields.each { |cf|
|
||||
# VIN
|
||||
begin
|
||||
if cf.name.eql? "VIN"
|
||||
vin = Vehicle.find(i.vehicles_id).vin
|
||||
break if vin.blank?
|
||||
cf.string_value = vin if not cf.string_value.to_s.eql? vin
|
||||
break
|
||||
end
|
||||
rescue
|
||||
#do nothing
|
||||
end
|
||||
|
||||
# Custom Values
|
||||
begin
|
||||
value = i.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
||||
if not value.value.to_s.blank?
|
||||
if not cf.string_value.to_s.eql? value.value.to_s
|
||||
cf.string_value = value.value.to_s
|
||||
is_changed = true
|
||||
end
|
||||
end
|
||||
rescue
|
||||
# Nothing to do here, there is no match
|
||||
end
|
||||
}
|
||||
# Push updates
|
||||
Qbo.get_base(:invoice).service.update(invoice) if is_changed
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def self.update(id)
|
||||
# Update the item table
|
||||
invoice = get_base.service.fetch_by_id(id)
|
||||
qbo_invoice = find_or_create_by(id: id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.save!
|
||||
qbo_invoice = find_or_create_by(id: id)
|
||||
qbo_invoice.doc_number = invoice.doc_number
|
||||
qbo_invoice.save!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
<%= @f.collection_select :vehicle_id, @customer.vehicles.order(:year), :id, :vin, include_blank: true, :selected => @vehicle%>
|
||||
Partial Test
|
||||
@@ -1 +0,0 @@
|
||||
$("#issue_vehicles_id").empty().append("<%= escape_javascript(render(:partial => @vehicles)) %>")
|
||||
4
assets/javascripts/autocomplete.js
Normal file
4
assets/javascripts/autocomplete.js
Normal file
@@ -0,0 +1,4 @@
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require jquery-ui
|
||||
//= require autocomplete-rails
|
||||
@@ -1,16 +0,0 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
|
||||
$ ->
|
||||
$(document).on 'change', '#issue_customer_id', (evt) ->
|
||||
$.ajax 'update_vehicles',
|
||||
type: 'GET'
|
||||
dataType: 'script'
|
||||
data: {
|
||||
customer_id: $("#issue_customer_id option:selected").val()
|
||||
}
|
||||
error: (jqXHR, textStatus, errorThrown) ->
|
||||
console.log("AJAX Error: #{textStatus}")
|
||||
success: (data, textStatus, jqXHR) ->
|
||||
console.log("Dynamic vehicle select OK!")
|
||||
@@ -22,9 +22,10 @@ get 'qbo/sync', :to => 'qbo#sync'
|
||||
get 'qbo/estimate/:id', :to => 'estimate#show', as: :estimate
|
||||
get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice
|
||||
|
||||
#manual billing
|
||||
get 'qbo/bill/:id', :to => 'qbo#bill', as: :bill
|
||||
|
||||
#payments
|
||||
#get 'qbo/payments', :to => 'payments#new'
|
||||
#post 'qbo/payments', :to => 'payments#create'
|
||||
resources :payments
|
||||
|
||||
#webhook
|
||||
|
||||
27
db/migrate/21_add_issues_qbo_invoices.rb
Normal file
27
db/migrate/21_add_issues_qbo_invoices.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
#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 AddIssuesQboInvoices < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :issues_qbo_invoices, :id => false do |t|
|
||||
t.references :issue
|
||||
t.references :qbo_invoice
|
||||
end
|
||||
|
||||
add_index :issues_qbo_invoices, [:issue_id, :qbo_invoice_id], :unique => true
|
||||
|
||||
# Now populate it with a SQL one-liner!
|
||||
execute "insert into issues_qbo_invoices(issue_id, qbo_invoice_id) select id, qbo_invoice_id from issues"
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :issues_qbo_invoices
|
||||
end
|
||||
end
|
||||
7
init.rb
7
init.rb
@@ -15,17 +15,22 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
require_dependency 'issues_save_hook_listener'
|
||||
require_dependency 'issues_show_hook_listener'
|
||||
require_dependency 'users_show_hook_listener'
|
||||
require_dependency 'header_footer_hook_listener.rb'
|
||||
|
||||
# Patches to the Redmine core. Will not work in development mode
|
||||
require_dependency 'issue_patch'
|
||||
require_dependency 'user_patch'
|
||||
require_dependency 'query_patch'
|
||||
require_dependency 'pdf_patch'
|
||||
|
||||
Rails.configuration.to_prepare do
|
||||
Redmine::Search.available_search_types << 'customers'
|
||||
end
|
||||
|
||||
name 'Redmine Quickbooks Online plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'This is a plugin for Redmine to intergrate with Quickbooks Online to allow for seamless intergration CRM and invoicing of completed issues'
|
||||
version '0.3.0'
|
||||
version '0.4.0'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'http://rickbarrette.org'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
#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 HeaderFooterHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
module ActiveSupport::Callbacks::ClassMethods
|
||||
def without_callback(*args, &block)
|
||||
skip_callback(*args)
|
||||
yield
|
||||
set_callback(*args)
|
||||
def view_layouts_base_html_head(context = {})
|
||||
#nothing
|
||||
end
|
||||
|
||||
def view_layouts_base_body_bottom(context = {})
|
||||
return "<div class='footer' align='center'><b>Last Sync: </b> #{Qbo.last_sync}</div>"
|
||||
end
|
||||
end
|
||||
@@ -23,9 +23,10 @@ module IssuePatch
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
belongs_to :customer, primary_key: :id
|
||||
belongs_to :qbo_item, primary_key: :id
|
||||
belongs_to :qbo_estimate, primary_key: :id
|
||||
belongs_to :qbo_invoice, primary_key: :id
|
||||
has_and_belongs_to_many :qbo_invoices
|
||||
#, :association_foreign_key => 'issue_id', :class_name => 'Issue', :join_table => 'issues_qbo_invoices'
|
||||
|
||||
belongs_to :vehicle, primary_key: :id
|
||||
end
|
||||
|
||||
@@ -36,7 +37,57 @@ module IssuePatch
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
# Create billable time entries
|
||||
def bill_time
|
||||
|
||||
# Get unbilled time entries
|
||||
spent_time = time_entries.where(qbo_billed: [false, nil])
|
||||
spent_hours ||= spent_time.sum(:hours) || 0
|
||||
|
||||
if spent_hours > 0 then
|
||||
|
||||
# Prepare to create a new Time Activity
|
||||
time_service = Qbo.get_base(:time_activity).service
|
||||
item_service = Qbo.get_base(:item).service
|
||||
time_entry = Quickbooks::Model::TimeActivity.new
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
|
||||
next if item.nil?
|
||||
|
||||
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial)" if not closed?}"
|
||||
# TODO entry.user.qbo_employee.id
|
||||
time_entry.employee_id = assigned_to.qbo_employee_id
|
||||
time_entry.customer_id = customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = item.id
|
||||
time_entry.start_time = start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
# Load the javascript
|
||||
def view_layouts_base_html_head(context = {})
|
||||
javascript_include_tag 'vehicles', :plugin => 'redmine_qbo'
|
||||
javascript_include_tag 'autocomplete', :plugin => 'redmine_qbo'
|
||||
end
|
||||
|
||||
# Edit Issue Form
|
||||
@@ -22,8 +23,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
selected_customer = context[:issue].customer ? context[:issue].customer.id : nil
|
||||
selected_item = context[:issue].qbo_item ? context[:issue].qbo_item.id : nil
|
||||
selected_invoice = context[:issue].qbo_invoice ? context[:issue].qbo_invoice.id : nil
|
||||
selected_estimate = context[:issue].qbo_estimate ? context[:issue].qbo_estimate.id : nil
|
||||
selected_vehicle = context[:issue].vehicles_id ? context[:issue].vehicles_id : nil
|
||||
|
||||
@@ -31,12 +30,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
customer = Customer.find_by_id(selected_customer) if selected_customer
|
||||
select_customer = f.select :customer_id, Customer.all.pluck(:name, :id).sort, :selected => selected_customer, include_blank: true
|
||||
|
||||
# Generate the drop down list of quickbooks items
|
||||
select_item = f.select :qbo_item_id, QboItem.all.pluck(:name, :id).sort, :selected => selected_item, include_blank: true
|
||||
|
||||
# Generate the drop down list of quickbooks invoices
|
||||
select_invoice = f.select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_invoice, include_blank: true
|
||||
|
||||
# Generate the drop down list of quickbooks extimates
|
||||
select_estimate = f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => selected_estimate, include_blank: true
|
||||
|
||||
@@ -48,6 +41,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
vehicle = f.select :vehicles_id, vehicles, :selected => selected_vehicle, include_blank: true
|
||||
|
||||
return "<p>#{select_customer}</p> <p>#{select_item}</p> <p>#{select_invoice}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
|
||||
return "<p>#{select_customer}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
issue = context[:issue]
|
||||
|
||||
# Check to see if we have registered with QBO
|
||||
if Qbo.first && issue.customer && issue.qbo_item
|
||||
if Qbo.first && issue.customer && issue. qbo_item_id
|
||||
|
||||
# if this is a quote, lets create a new estimate based off estimated hours
|
||||
if issue.tracker.name = "Quote" && issue.status.name = "New" && issue.qbo_estimate
|
||||
@@ -44,10 +44,6 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# Add the line items to the estimate
|
||||
estimate.line_items << line_item
|
||||
|
||||
# Save the etimate to the issue
|
||||
#issue.qbo_estimate_id = estimate_base.service.create(estimate).id
|
||||
#issue.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -55,55 +51,6 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
# Called After Issue Saved
|
||||
def controller_issues_edit_after_save(context={})
|
||||
issue = context[:issue]
|
||||
|
||||
if issue.assigned_to
|
||||
employee_id = issue.assigned_to.qbo_employee_id
|
||||
|
||||
# Check to see if we have registered with QBO and if the issue is closed.
|
||||
# If so then we need to create a new billable time activity for the customer
|
||||
bill_time(issue, employee_id) if Qbo.first && issue.customer && issue.qbo_item && employee_id && issue.status.is_closed?
|
||||
end
|
||||
end
|
||||
|
||||
# Create billable time entries
|
||||
def bill_time(issue, employee_id)
|
||||
|
||||
# Get unbilled time entries
|
||||
spent_time = issue.time_entries.where(qbo_billed: [false, nil])
|
||||
spent_hours ||= spent_time.sum(:hours) || 0
|
||||
|
||||
if spent_hours > 0 then
|
||||
|
||||
# Prepare to create a new Time Activity
|
||||
time_service = Qbo.get_base(:time_activity).service
|
||||
item_service = Qbo.get_base(:item).service
|
||||
time_entry = Quickbooks::Model::TimeActivity.new
|
||||
|
||||
# Convert float spent time to hours and minutes
|
||||
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
|
||||
|
||||
item = item_service.fetch_by_id issue.qbo_item_id
|
||||
time_entry.description = "#{issue.tracker} ##{issue.id}: #{issue.subject}"
|
||||
time_entry.employee_id = employee_id
|
||||
time_entry.customer_id = issue.customer_id
|
||||
time_entry.billable_status = "Billable"
|
||||
time_entry.hours = hours
|
||||
time_entry.minutes = minutes
|
||||
time_entry.name_of = "Employee"
|
||||
time_entry.txn_date = Date.today
|
||||
time_entry.hourly_rate = item.unit_price
|
||||
time_entry.item_id = issue.qbo_item_id
|
||||
time_entry.start_time = issue.start_date
|
||||
time_entry.end_time = Time.now
|
||||
time_service.create(time_entry)
|
||||
end
|
||||
issue.bill_time if Qbo.first && issue.customer && issue.status.is_closed?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,9 +25,6 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
customer = link_to issue.customer.name, "#{Redmine::Utils::relative_url_root}/customers/#{issue.customer.id}"
|
||||
end
|
||||
|
||||
# Check to see if there is a quickbooks item attached to the issue
|
||||
item = issue.qbo_item ? issue.qbo_item.name : nil
|
||||
|
||||
# Estimate Number
|
||||
if issue.qbo_estimate
|
||||
estimate = issue.qbo_estimate.doc_number
|
||||
@@ -35,12 +32,14 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
end
|
||||
|
||||
# Invoice Number
|
||||
if issue.qbo_invoice
|
||||
invoice = issue.qbo_invoice.doc_number
|
||||
invoice_link = link_to invoice, "#{Redmine::Utils::relative_url_root}/qbo/invoice/#{issue.qbo_invoice.id}", :target => "_blank"
|
||||
invoice_link = ""
|
||||
if issue.qbo_invoice_ids
|
||||
issue.qbo_invoice_ids.each do |i|
|
||||
invoice = QboInvoice.find i
|
||||
invoice_link = invoice_link + link_to( invoice.doc_number, "#{Redmine::Utils::relative_url_root}/qbo/invoice/#{i}", :target => "_blank").to_s + " "
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
begin
|
||||
v = Vehicle.find(issue.vehicles_id)
|
||||
vehicle = link_to v.to_s, "#{Redmine::Utils::relative_url_root}/vehicles/#{v.id}"
|
||||
@@ -59,11 +58,6 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
<div class=\"label\"><span>Customer</span>:</div>
|
||||
<div class=\"value\">#{customer}</div>
|
||||
</div>
|
||||
|
||||
<div class=\"qbo_item_id attribute\">
|
||||
<div class=\"label\"><span>Item</span>:</div>
|
||||
<div class=\"value\">#{item}</div>
|
||||
</div>
|
||||
|
||||
<div class=\"qbo_estimate_id attribute\">
|
||||
<div class=\"label\"><span>Estimate</span>:</div>
|
||||
@@ -91,7 +85,11 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
<div class=\"label\"><span>Notes</span>:</div>
|
||||
<div class=\"value\">#{notes}</div>
|
||||
</div>
|
||||
</div>"
|
||||
</div> "
|
||||
end
|
||||
|
||||
def view_issues_show_description_bottom(context={})
|
||||
return "<br/> #{button_to "Bill Time", "#{Redmine::Utils::relative_url_root}/qbo/bill/#{context[:issue].id}", method: :get}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user