mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Added Invoice Support
This commit is contained in:
@@ -70,6 +70,7 @@ class QboController < ApplicationController
|
||||
QboItem.update_all
|
||||
QboEmployee.update_all
|
||||
QboEstimate.update_all
|
||||
QboInvoice.update_all
|
||||
end
|
||||
|
||||
redirect_to qbo_path(:redmine_qbo), :flash => { :notice => "Successfully synced to Quickbooks" }
|
||||
@@ -84,4 +85,13 @@ class QboController < ApplicationController
|
||||
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
|
||||
|
||||
38
app/models/qbo_invoice.rb
Normal file
38
app/models/qbo_invoice.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
#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 QboInvoice < ActiveRecord::Base
|
||||
unloadable
|
||||
has_many :issues
|
||||
attr_accessible :doc_number
|
||||
validates_presence_of :id, :doc_number
|
||||
|
||||
def self.get_base
|
||||
Qbo.get_base(:invoice)
|
||||
end
|
||||
|
||||
def self.update_all
|
||||
# Update the item table
|
||||
get_base.service.all.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!
|
||||
}
|
||||
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!
|
||||
end
|
||||
end
|
||||
@@ -14,3 +14,4 @@ en:
|
||||
field_qbo_customer: "Customer"
|
||||
field_qbo_item: "Item"
|
||||
field_qbo_employee: "Employee"
|
||||
field_qbo_invoice: "Invoice"
|
||||
@@ -16,3 +16,4 @@ 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
|
||||
18
db/migrate/011_create_qbo_invoices.rb
Normal file
18
db/migrate/011_create_qbo_invoices.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
#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 CreateQboInvoices < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :qbo_invoices, id: false do |t|
|
||||
t.integer :id, :options => 'PRIMARY KEY'
|
||||
t.string :doc_number
|
||||
end
|
||||
end
|
||||
end
|
||||
15
db/migrate/012_update_issues_with_invoices.rb
Normal file
15
db/migrate/012_update_issues_with_invoices.rb
Normal 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 UpdateIssuesWithInvoices< ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :issues, :qbo_invoice, index: true
|
||||
end
|
||||
end
|
||||
1
init.rb
1
init.rb
@@ -32,6 +32,7 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
Issue.safe_attributes 'qbo_customer_id'
|
||||
Issue.safe_attributes 'qbo_item_id'
|
||||
Issue.safe_attributes 'qbo_estimate_id'
|
||||
Issue.safe_attributes 'qbo_invoice_id'
|
||||
User.safe_attributes 'qbo_employee_id'
|
||||
TimeEntry.safe_attributes 'qbo_billed'
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ module IssuePatch
|
||||
belongs_to :qbo_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
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,18 +16,22 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
# Update the customer and item database
|
||||
QboCustomer.update_all
|
||||
QboItem.update_all
|
||||
QboInvoice.update_all
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
if context[:issue].qbo_customer && context[:issue].qbo_item
|
||||
@selected_customer = context[:issue].qbo_customer.id
|
||||
@selected_item = context[:issue].qbo_item.id
|
||||
end
|
||||
@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
|
||||
|
||||
# Generate the drop down list of quickbooks contacts
|
||||
# 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
|
||||
|
||||
# Generate the drop down list of quickbooks contacts
|
||||
@select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id).reverse, :selected => @selected_item, include_blank: true
|
||||
return "<p>#{@select_customer}</p> <p>#{@select_item}</p>"
|
||||
# Generate the drop down list of quickbooks items
|
||||
@select_item = context[:form].select :qbo_item_id, QboItem.all.pluck(:name, :id), :selected => @selected_item, include_blank: true
|
||||
|
||||
# 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>"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,14 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
if issue.qbo_estimate
|
||||
QboEstimate.update(issue.qbo_estimate.id)
|
||||
@estimate = issue.qbo_estimate.doc_number
|
||||
@link = link_to @estimate, qbo_estimate_pdf_path(issue.qbo_estimate.id)
|
||||
@estimate_link = link_to @estimate, qbo_estimate_pdf_path(issue.qbo_estimate.id)
|
||||
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)
|
||||
end
|
||||
|
||||
return "<div class=\"attributes\">
|
||||
@@ -46,7 +53,12 @@ class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
<div class=\"qbo_estimate_id attribute\">
|
||||
<div class=\"label\"><span>Estimate</span>:</div>
|
||||
<div class=\"value\">#{@link}</div>
|
||||
<div class=\"value\">#{@estimate_link}</div>
|
||||
</div>
|
||||
|
||||
<div class=\"qbo_invoice_id attribute\">
|
||||
<div class=\"label\"><span>Invoice</span>:</div>
|
||||
<div class=\"value\">#{@invoice_link}</div>
|
||||
</div>
|
||||
</div>"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user