Merge branch 'billable-purchases'

This commit is contained in:
2016-02-25 22:53:46 -05:00
17 changed files with 180 additions and 29 deletions

View File

@@ -0,0 +1,22 @@
#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 EstimateController < ApplicationController
unloadable
#
# Downloads and forwards the estimate pdf
#
def show
base = QboEstimate.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "estimate.pdf", :disposition => 'inline', :type => "application/pdf"
end
end

View File

@@ -0,0 +1,21 @@
#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 InvoiceController < ApplicationController
unloadable
#
# Downloads and forwards the invoice pdf
#
def show
base = QboInvoice.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "invoice.pdf", :disposition => 'inline', :type => "application/pdf"
end
end

View File

@@ -71,27 +71,9 @@ class QboController < ApplicationController
QboEmployee.update_all
QboEstimate.update_all
QboInvoice.update_all
QboPurchase.update_all
end
redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" }
end
#
# Downloads and forwards the estimate pdf
#
def estimate_pdf
base = QboEstimate.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "estimate.pdf", :disposition => 'inline', :type => "application/pdf"
end
#
# Downloads and forwards the invoice pdf
#
def invoice_pdf
base = QboInvoice.get_base.service
@pdf = base.pdf(base.fetch_by_id(params[:id]))
send_data @pdf, filename: "invoice.pdf", :disposition => 'inline', :type => "application/pdf"
end
end
end

View File

@@ -0,0 +1,2 @@
module EstimateHelper
end

View File

@@ -0,0 +1,2 @@
module InvoiceHelper
end

View File

@@ -11,6 +11,7 @@
class QboCustomer < ActiveRecord::Base
unloadable
has_many :issues
has_many :qbo_purchases
attr_accessible :name
validates_presence_of :id, :name

View File

@@ -0,0 +1,47 @@
#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 QboPurchase < ActiveRecord::Base
unloadable
belongs_to :issues
belongs_to :qbo_customer
attr_accessible :description
validates_presence_of :id, :line_id, :description, :qbo_customer_id
def self.get_base
Qbo.get_base(:purchase)
end
def self.get_purchase(id)
get_base.service.find_by_id(id)
end
def self.update_all
QboPurchase.get_base.service.all.each { |purchase|
purchase.line_items.all? { |line_item|
detail = line_item.account_based_expense_line_detail ? line_item.account_based_expense_line_detail : line_item.item_based_expense_line_detail
if detail.billable_status = "Billable"
qbo_purchase = find_or_create_by(id: purchase.id)
qbo_purchase.line_id = line_item.id
qbo_purchase.description = line_item.description
qbo_purchase.qbo_customer_id = detail.customer_ref
#TODO attach to issues
#qbo_purchase.issue_id = Issue.find_by_invoice()
qbo_purchase.save
end
}
}
end
end

View File

@@ -14,4 +14,5 @@ en:
field_qbo_customer: "Customer"
field_qbo_item: "Item"
field_qbo_employee: "Employee"
field_qbo_invoice: "Invoice"
field_qbo_invoice: "Invoice"
field_qbo_estimate: "Estimate"

View File

@@ -15,5 +15,5 @@ get 'qbo', :to=> 'qbo#index'
get 'qbo/authenticate', :to => 'qbo#authenticate'
get 'qbo/oauth_callback', :to => 'qbo#oauth_callback'
get 'qbo/sync', :to => 'qbo#sync'
get 'qbo/estimate/:id', :to => 'qbo#estimate_pdf', :as => :qbo_estimate_pdf
get 'qbo/invoice/:id', :to => 'qbo#invoice_pdf', :as => :qbo_invoice_pdf
get 'qbo/estimate/:id', :to => 'estimate#show', as: :estimate
get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice

View File

@@ -0,0 +1,21 @@
#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 CreateQboPurchases< ActiveRecord::Migration
def change
create_table :qbo_purchases, id: false do |t|
t.integer :id, :options => 'PRIMARY KEY'
t.integer :line_id
t.string :description
t.integer :customer_id
t.integer :issue_id
end
end
end

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 UpdateCustomers < ActiveRecord::Migration
def change
add_reference :qbo_customers, :qbo_purchase, index: true
end
end

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 UpdateQboPurchases < ActiveRecord::Migration
def change
rename_column :qbo_purchases, :customer_id, :qbo_customer_id
end
end

View File

@@ -17,11 +17,13 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
QboCustomer.update_all
QboItem.update_all
QboInvoice.update_all
QboEstimate.update_all
# Check to see if there is a quickbooks user attached to the issue
@selected_customer = context[:issue].qbo_customer.id if context[:issue].qbo_customer
@selected_item = context[:issue].qbo_item.id if context[:issue].qbo_item
@selected_invoice = context[:issue].qbo_invoice.id if context[:issue].qbo_invoice
@selected_estimate = context[:issue].qbo_estimate.id if context[:issue].qbo_estimate
# Generate the drop down list of quickbooks customers
@select_customer = context[:form].select :qbo_customer_id, QboCustomer.all.pluck(:name, :id), :selected => @selected_customer, include_blank: true
@@ -32,6 +34,10 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
# Generate the drop down list of quickbooks invoices
@select_invoice = context[:form].select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_invoice, include_blank: true
return "<p>#{@select_customer}</p> <p>#{@select_item}</p> <p>#{@select_invoice}</p>"
# Generate the drop down list of quickbooks extimates
@select_estimate = context[:form].select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_estimate, include_blank: true
return "<p>#{@select_customer}</p> <p>#{@select_item}</p> <p>#{@select_invoice}</p> <p>#{@select_estimate}</p>"
end
end

View File

@@ -18,7 +18,7 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
if Qbo.first && issue.qbo_customer && issue.qbo_item
# 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
if issue.tracker.name = "Quote" && issue.status.name = "New" && issue.qbo_estimate
# Get QBO Services
item_service = QboItem.get_base.service
@@ -46,8 +46,8 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
estimate.line_items << line_item
# Save the etimate to the issue
issue.qbo_estimate_id = estimate_base.service.create(estimate).id
issue.save!
#issue.qbo_estimate_id = estimate_base.service.create(estimate).id
#issue.save!
end
end
end

View File

@@ -30,14 +30,14 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
if issue.qbo_estimate
QboEstimate.update(issue.qbo_estimate.id)
@estimate = issue.qbo_estimate.doc_number
@estimate_link = link_to @estimate, qbo_estimate_pdf_path(issue.qbo_estimate.id)
@estimate_link = link_to @estimate, "#{Redmine::Utils::relative_url_root }/qbo/estimate/#{issue.qbo_estimate.id}", :target => "_blank"
end
# Invoice Number
if issue.qbo_invoice
QboInvoice.update(issue.qbo_invoice.id)
@invoice = issue.qbo_invoice.doc_number
@invoice_link = link_to @invoice, qbo_invoice_pdf_path(issue.qbo_invoice.id)
@invoice_link = link_to @invoice, "#{Redmine::Utils::relative_url_root }/qbo/invoice/#{issue.qbo_invoice.id}", :target => "_blank"
end
return "<div class=\"attributes\">

View File

@@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
class EstimateControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

View File

@@ -0,0 +1,8 @@
require File.expand_path('../../test_helper', __FILE__)
class InvoiceControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end