mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Compare commits
386 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8812d7a11d | |||
| fe1388108c | |||
| b98cdbec8b | |||
| d7f8e51c4a | |||
| 2ce4e8b346 | |||
| dd8bf530c9 | |||
| 1103355cb7 | |||
| e400a7cee3 | |||
| b32df9525c | |||
| 967a727392 | |||
| 79539dd57f | |||
| 9d96c813e9 | |||
| 073447a4ce | |||
| 1a6b6fb321 | |||
| 543841ad64 | |||
| 5ad4b53b30 | |||
| bfec64de54 | |||
| 198e2d5934 | |||
| 95c39fb9c5 | |||
| dc7ee21aad | |||
| 8c8966a859 | |||
| b95aa41b3d | |||
| 2012774ae8 | |||
| be7e9ef2cc | |||
| 5ac1c44e41 | |||
| b1120c3849 | |||
| 847669376f | |||
| c2b62fbf88 | |||
| 21d0d25c78 | |||
| 365a36390b | |||
| 68846f7910 | |||
| 3a64e0d5bd | |||
| 2f5607b8ef | |||
| 2a713d7f13 | |||
| 61f0ee6f81 | |||
| d6a75f8ed0 | |||
| 14d10bd0e6 | |||
| bb9f251e69 | |||
| f2a7c034d0 | |||
| 3589ea8685 | |||
| f71be3f1a5 | |||
| cf3983adc4 | |||
| 55f6666328 | |||
| 933a0bb12d | |||
| 0c5d2195d2 | |||
| 3518f0acfe | |||
| d4bcccf598 | |||
| 3aa2798463 | |||
| 0cb9863000 | |||
| deb648e3d6 | |||
| 384854d701 | |||
| f192fe8d5f | |||
| 8a89af88c3 | |||
| a4944f2a3b | |||
| 0160a58c86 | |||
| f7d809e90a | |||
| 8e80277a15 | |||
| 962e954d6e | |||
| 9d1bfa3951 | |||
| b20a343cd2 | |||
| 593d8e603b | |||
| 5a5a531700 | |||
| f7464e1d47 | |||
| c39c9ab95c | |||
| 5aa32b735f | |||
| 9d4774a31b | |||
| 63c446673f | |||
| 8d1038ac0c | |||
| ae903bede2 | |||
| b82d5091b7 | |||
| 48a2c0cb45 | |||
| 092fa85dd8 | |||
| 5100b111e9 | |||
| 69273b5dc8 | |||
| 52bf4f916d | |||
| 7fa41d6574 | |||
| bbe1b22020 | |||
| 892e57084d | |||
| d6e15f90ef | |||
| 39872107bc | |||
| 1de5712f8c | |||
| 38518fa5e9 | |||
| 46df203e00 | |||
| 642406365d | |||
| ee40dbf5a4 | |||
| 828a59f989 | |||
| 79d05350db | |||
| 12aeb22ac3 | |||
| 09f531ce39 | |||
| 2b4bba7a88 | |||
| 9e2f9f5a7a | |||
| 7a6e35adff | |||
| 5047077b07 | |||
| 5242ed5a94 | |||
| a316c0f8d6 | |||
| 3c6bce713b | |||
| d4b0ac1e38 | |||
| d80df26df1 | |||
| dd9c945fcc | |||
| 43e6fff6d8 | |||
| 1650577d4d | |||
| c2b798e32c | |||
| 1817095d00 | |||
| 27bb6ea4a2 | |||
| ef2aebb7e4 | |||
| bc23dfad56 | |||
| 3be2a73422 | |||
| 4896241df1 | |||
| 75b159bf4e | |||
| 75a651dd3b | |||
| 76e230770b | |||
| 70d7b65741 | |||
| c251dc8407 | |||
| 6464904caf | |||
| 98cf1ed140 | |||
| 0d367245ce | |||
| c053c91a64 | |||
| 8f5467638e | |||
| 723d9024c1 | |||
| 8374f0ae3e | |||
| 4f9a3ed046 | |||
| cd5ed4f3a7 | |||
| 792773b945 | |||
| d09f5e9afe | |||
| f07c90cf90 | |||
| 774ce239c2 | |||
| 3ec2670209 | |||
| 76cbb42309 | |||
| 3e9138f802 | |||
| 1ac799d318 | |||
| 5e4d7c7686 | |||
| 6a6fcf093c | |||
| ab68b1cf89 | |||
| b692abcb64 | |||
| 94fe2f2d05 | |||
| 26f861a493 | |||
| 0f94675ba5 | |||
| 4816229c5e | |||
| 98b2d2078c | |||
| 6cf2a2640b | |||
| 58c9544a22 | |||
| d14b6a1b54 | |||
| ec37439577 | |||
| b5716595e4 | |||
| d968885e1e | |||
| 1231b776b7 | |||
| f8f3870405 | |||
| 723ad5bc53 | |||
| c4c4d6156d | |||
| 28eaecabff | |||
| 6819e2a826 | |||
| 9e1ae8d40b | |||
| 467677d73c | |||
| ee2be0d8c9 | |||
| 0fb358edf3 | |||
| 9972e18632 | |||
| b1c0f965f8 | |||
| d523584ca1 | |||
| de7b534572 | |||
| 24e3c29353 | |||
| 800058a3c0 | |||
| 9c230d6423 | |||
| 497f4661bd | |||
| d5b1187076 | |||
| 0468af9e53 | |||
| 8ac9cfae93 | |||
| c07e4cb427 | |||
| 380315e207 | |||
| 950dfd9af9 | |||
| c4abee7415 | |||
| 27d282f244 | |||
| 610582bce8 | |||
| 655f0c3dcd | |||
| d9ce3981a3 | |||
| 8e6bdc6d38 | |||
| 0a167c33ee | |||
| b8002df5af | |||
| 7356e99981 | |||
| 4eb2718b2b | |||
| 3c849ca5dd | |||
| dd40c045cf | |||
| 6505f8114d | |||
| eeb5e96aae | |||
| 9c61ecd0c0 | |||
| a771085a33 | |||
| 5f1dea77cc | |||
| 9ae11bac49 | |||
| 77239122c0 | |||
| 804b4066ce | |||
| 2cc8c83071 | |||
| a7ba05db29 | |||
| a8c353945d | |||
| f90921fb00 | |||
| 84fd9770c9 | |||
| f7ee1dbcec | |||
| d8d0572a1a | |||
| 1688ebd327 | |||
| 26d4f09f97 | |||
| fe831cf259 | |||
| 35e4c5f9da | |||
| 66779e60f6 | |||
| 1e0e608ca1 | |||
| fbf074e3c3 | |||
| a33a1eeb94 | |||
| 266a3ed921 | |||
| fc0a416175 | |||
| e561b52e9b | |||
| 51586800a0 | |||
| fec1512930 | |||
| 559a846f1e | |||
| f936e61684 | |||
| dfd7dfcf79 | |||
| a409514467 | |||
| 8b44e5b51b | |||
| e350657d89 | |||
| 7fea7042a5 | |||
| 9c57878fd1 | |||
| fd6c70860c | |||
| 48114de428 | |||
| 7267bac43d | |||
| fd92d72ac3 | |||
| 5457ae51c2 | |||
| 6647e533df | |||
| 6d961addbe | |||
| af654ef9d0 | |||
| 3b5f6691fb | |||
| aa770bb1f0 | |||
| 0c2d57c826 | |||
| fa3322d530 | |||
| 3bbc0a16ff | |||
| 2e7c26d90e | |||
| 75fae59bcf | |||
| a1b72a1dd0 | |||
| 4c9b48bd91 | |||
| e3c7047999 | |||
| 07fe12e65b | |||
| 8955053e64 | |||
| b534e94c38 | |||
| 64a7b4fb29 | |||
| a6c88c85c4 | |||
| bbed60c2ca | |||
| 20b31d47be | |||
| b48a21c8fe | |||
| d4930227ba | |||
| ad27e98e48 | |||
| 29fa5ff510 | |||
| b08f3adc39 | |||
| 40f2358c26 | |||
| 952baff6f2 | |||
| 31797585c8 | |||
| 2d50c4c454 | |||
| ae491e0902 | |||
| c205479975 | |||
| ffede26929 | |||
| 8a553c0129 | |||
| d5f9cee2e1 | |||
| 28d5187d40 | |||
| 48709cdceb | |||
| 22a6492e8b | |||
| 82f4ced404 | |||
| 3348173cbe | |||
| 9d83175bd7 | |||
| b6f8304d13 | |||
| cd31ecf1f0 | |||
| 15cd8e756c | |||
| 3caaaa52dd | |||
| 03b12d08ef | |||
| a69ad1cef2 | |||
| eb3d8160a1 | |||
| 9cd5440bc8 | |||
| f10114d43c | |||
| fd8a068f16 | |||
| e115e8fe94 | |||
| b4255135c4 | |||
| 9fc94e93c6 | |||
| 3e50c037e0 | |||
| dc5b8419a4 | |||
| c1002cb93c | |||
| fcaa5f55cf | |||
| 195359ce0b | |||
| b5c8823dda | |||
| d9317e717b | |||
| 9e9c111256 | |||
| c254c78ee5 | |||
| dc1edaa651 | |||
| 028b309a60 | |||
| e0b07764c0 | |||
| 73dc8b3b44 | |||
| 1bc23ab553 | |||
| 5be8d987b6 | |||
| f89cdf8ab2 | |||
| d33eba2b20 | |||
| 39a2e1564f | |||
| 3070192485 | |||
| ed5959d8e0 | |||
| 79d990dd01 | |||
| b1cf8363a9 | |||
| 3d251da80b | |||
| cc9af5dc36 | |||
| 2c3503f4ac | |||
| 5104509106 | |||
| 77be0b9d4c | |||
| 897810b029 | |||
| 37371d2373 | |||
| 95fbad525d | |||
| 9ce8fa4661 | |||
| c6ac6141d9 | |||
| f25fac1190 | |||
| 49f2baed9f | |||
| 9acc33e373 | |||
| 4f6d194615 | |||
| 0308a67a86 | |||
| 7b63e64da0 | |||
| eb8e2fa018 | |||
| 62ac1bf295 | |||
| d044024981 | |||
| 65be0c5f7a | |||
| e9db63ea82 | |||
| c8107c418f | |||
| 2d96f6653b | |||
| b4833d7a5f | |||
| 12cebb1cd1 | |||
| ad4ce232b5 | |||
| 82a273c0c2 | |||
| 88b66c4b41 | |||
| e9038a56c1 | |||
| f2df6b5128 | |||
| b57d51d80a | |||
| 970a2fa681 | |||
| 3d2176c5bd | |||
| baf251e211 | |||
| def5b72aa3 | |||
| 89498c9559 | |||
| b28e9b5a5b | |||
| d529139a9f | |||
| 5155c0bc68 | |||
| 798bfde516 | |||
| d79daa7a28 | |||
| 6bcf210f79 | |||
| 7244455bf2 | |||
| e65d78bb25 | |||
| 0b74f2cf52 | |||
| 98b89e7875 | |||
| b1996aa309 | |||
| f4712ad849 | |||
| a8546934ee | |||
| a7b7db690d | |||
| 0ed61b191f | |||
| 0fb4ec1157 | |||
| d22257e8ab | |||
| e1bb565c59 | |||
| 03e1e7e0b2 | |||
| aa3fefd628 | |||
| 5e635f9e2b | |||
| 2aad7115c4 | |||
| 80ee5287a0 | |||
| 26d8d9d3e9 | |||
| f0c08e155f | |||
| afb3af18d4 | |||
| 20be533a19 | |||
| f07809eacb | |||
| d1653da540 | |||
| d9b1b45f89 | |||
| 2f85d2f56d | |||
| 430579d622 | |||
| 2357b002c6 | |||
| 191cfd5fff | |||
| eb911f195c | |||
| 98cd3d51e9 | |||
| 2365fc2cf8 | |||
| 6556197dd0 | |||
| e19688a525 | |||
| ec1c263347 | |||
| 6f194e37bd | |||
| 135850b74d | |||
| 98e94da39b | |||
| 3a4b3c0646 | |||
| ddb4f40486 | |||
| a10b075ab8 | |||
| 77448e8dc1 | |||
| cf97b341ab | |||
| 7637a6fa28 | |||
| aad4597265 | |||
| f9e271cbcb | |||
| 2ec9e43951 | |||
| c2808c7e8f |
6
Gemfile
6
Gemfile
@@ -1,8 +1,10 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
|
||||
gem 'quickbooks-ruby'#, :git => 'https://github.com/ruckus/quickbooks-ruby.git'
|
||||
gem 'quickbooks-ruby'
|
||||
gem 'quickbooks-ruby-base'
|
||||
gem 'oauth-plugin'#, '~> 0.5.1'
|
||||
gem 'oauth'
|
||||
gem 'roxml'
|
||||
gem 'nokogiri'
|
||||
gem 'edmunds_vin'
|
||||
gem 'will_paginate', '~> 3.1.0'
|
||||
|
||||
20
LICENSE
20
LICENSE
@@ -1,9 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 rick barrette
|
||||
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:
|
||||
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 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.
|
||||
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.
|
||||
|
||||
49
README.md
49
README.md
@@ -4,15 +4,17 @@ A simple 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.
|
||||
|
||||
`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`
|
||||
|
||||
####How it works
|
||||
* A QBO customer and service item can be assigned to a redmine issue.
|
||||
* A QBO employee can be assigned to a redmine user
|
||||
* When a issue is closed, the following things happen:
|
||||
- The plugin checks to see if the user assinged to the issue has a QBO employee assinged to them
|
||||
- The plugin checks to see if the issue has a QBO customer & service item attached
|
||||
- If the above statements are true, then a new QBO Time Activity is created
|
||||
- The total time for the Time Activity will be total spent time.
|
||||
- The rate will be the set be the service item
|
||||
* 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.
|
||||
|
||||
##Prerequisites
|
||||
|
||||
@@ -21,21 +23,40 @@ The goal of this project is to allow redmine to connect with Quickbooks Online t
|
||||
|
||||
##The Install
|
||||
|
||||
1. To install, clone this repo into your plugin folder
|
||||
1. To install, clone this repo into your plugin folder
|
||||
|
||||
' git clone git@github.com:rickbarrette/redmine_qbo.git '
|
||||
`git clone git@github.com:rickbarrette/redmine_qbo.git`
|
||||
|
||||
2. Migrate your database
|
||||
|
||||
' rake redmine:plugins:migrate RAILS_ENV=production '
|
||||
`rake redmine:plugins:migrate RAILS_ENV=production`
|
||||
|
||||
3. Navigate to the plugin configuration page (https://your.redmine.com/settings/plugin/redmine_qbo) and suppy your own OAuth key & secret.
|
||||
3. Navigate to the plugin configuration page and suppy your own OAuth key & secret.
|
||||
|
||||

|
||||
|
||||
4. After saving your key & secret, you need to click on the Authenticate link on the plugin configuration page to authenticate with QBO.
|
||||
|
||||
5. Enjoy
|
||||
5. Assign an Employee to each of your users via the User Administration Page
|
||||
|
||||
Note: Customers, Employees, and Service Items with automaticly update during normal usage of redmine i.e. a page refresh. You can also manualy force redmine to sync its database with QBO clicking the sync link in the Quickbooks top menu page (https://your.redmine.com/redmine/qbo)
|
||||

|
||||
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
Note: Customers, Employees, and Service Items with automaticly update during normal usage of redmine i.e. a page refresh. You can also manualy force redmine to sync its database with QBO clicking the sync link in the Quickbooks top menu page
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
* Add a rake file to create required Trackers or statuses required
|
||||
* Add link Invoice PDF to issue after creation.
|
||||
* Clean up view hook code, possibly use a controller hook and reder partial views
|
||||
* Add Setting for Sandbox Mode
|
||||
|
||||
##License
|
||||
|
||||
|
||||
63
app/controllers/customers_controller.rb
Normal file
63
app/controllers/customers_controller.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
#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.
|
||||
|
||||
# This controller class will handle map management
|
||||
class CustomersController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
|
||||
before_filter :require_user
|
||||
|
||||
# display a list of all customers
|
||||
def index
|
||||
@customers = QboCustomer.paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
end
|
||||
|
||||
# display a specific customer
|
||||
def show
|
||||
@customer = QboCustomer.find_by_id(params[:id])
|
||||
if @customer
|
||||
@vehicles = @customer.vehicles.paginate(:page => params[:page])
|
||||
else
|
||||
flash[:error] = "Customer Not Found"
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
# return an HTML form for editing a customer
|
||||
def edit
|
||||
@customer = QboCustomer.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
# update a specific customer
|
||||
def update
|
||||
@customer = QboCustomer.find_by_id(params[:id])
|
||||
if @customer.update_attributes(params[:customer])
|
||||
flash[:success] = "Customer updated"
|
||||
redirect_to @customer
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -7,23 +7,21 @@
|
||||
#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 QboCustomers < ActiveRecord::Base
|
||||
class EstimateController < ApplicationController
|
||||
unloadable
|
||||
has_many :issues
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
|
||||
def self.update_all
|
||||
qbo = Qbo.first
|
||||
service = Quickbooks::Service::Customer.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
|
||||
# Update the customer table
|
||||
service.all.each { |customer|
|
||||
qbo_customer = QboCustomers.find_or_create_by(id: customer.id)
|
||||
qbo_customer.id = customer.id
|
||||
qbo_customer.name = customer.display_name
|
||||
qbo_customer.save!
|
||||
}
|
||||
|
||||
include AuthHelper
|
||||
|
||||
before_filter :require_user
|
||||
|
||||
#
|
||||
# Downloads and forwards the estimate pdf
|
||||
#
|
||||
def show
|
||||
base = QboEstimate.get_base.service
|
||||
estimate = base.fetch_by_id(params[:id])
|
||||
@pdf = base.pdf(estimate)
|
||||
send_data @pdf, filename: "estimate #{estimate.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||
end
|
||||
|
||||
end
|
||||
26
app/controllers/invoice_controller.rb
Normal file
26
app/controllers/invoice_controller.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
#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
|
||||
|
||||
include AuthHelper
|
||||
|
||||
before_filter :require_user
|
||||
|
||||
#
|
||||
# Downloads and forwards the invoice pdf
|
||||
#
|
||||
def show
|
||||
base = QboInvoice.get_base.service
|
||||
invoice = base.fetch_by_id(params[:id])
|
||||
@pdf = base.pdf(invoice)
|
||||
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||
end
|
||||
end
|
||||
@@ -10,18 +10,21 @@
|
||||
|
||||
class QboController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
|
||||
before_filter :require_user
|
||||
|
||||
#
|
||||
# Called when the QBO Top Menu us shown
|
||||
#
|
||||
def index
|
||||
@qbo = Qbo.first
|
||||
@qbo_customer_count = QboCustomers.count
|
||||
@qbo_customer_count = QboCustomer.count
|
||||
@qbo_item_count = QboItem.count
|
||||
@qbo_employee_count = QboEmployee.count
|
||||
@selected_customer
|
||||
@selected_item
|
||||
@selected_employee
|
||||
@qbo_invoice_count = QboInvoice.count
|
||||
@qbo_estimate_count = QboEstimate.count
|
||||
end
|
||||
|
||||
#
|
||||
@@ -65,10 +68,13 @@ class QboController < ApplicationController
|
||||
# Synchronizes the QboCustomer table with QBO
|
||||
#
|
||||
def sync
|
||||
if Qbo.exists? then
|
||||
QboCustomers.update_all
|
||||
if Qbo.exists?
|
||||
QboCustomer.update_all
|
||||
QboItem.update_all
|
||||
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" }
|
||||
|
||||
76
app/controllers/vehicles_controller.rb
Normal file
76
app/controllers/vehicles_controller.rb
Normal file
@@ -0,0 +1,76 @@
|
||||
#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.
|
||||
|
||||
# This controller class will handle map management
|
||||
class VehiclesController < ApplicationController
|
||||
unloadable
|
||||
|
||||
include AuthHelper
|
||||
|
||||
before_filter :require_user
|
||||
|
||||
# display a list of all vehicles
|
||||
def index
|
||||
@vehicles = Vehicle.paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
# return an HTML form for creating a new vehicle
|
||||
def new
|
||||
@vehicle = Vehicle.new
|
||||
end
|
||||
|
||||
# create a new vehicle
|
||||
def create
|
||||
@vehicle = Vehicle.new(params[:vehicle])
|
||||
@vehicle.save!
|
||||
redirect_to @vehicle
|
||||
end
|
||||
|
||||
# display a specific vehicle
|
||||
def show
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
if @vehicle
|
||||
@customer = @vehicle.qbo_customer.name if @vehicle.qbo_customer
|
||||
else
|
||||
flash[:error] = "Vehicle Not Found"
|
||||
render :index
|
||||
end
|
||||
end
|
||||
|
||||
# return an HTML form for editing a vehicle
|
||||
def edit
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
@customer = @vehicle.qbo_customer.id if @vehicle.qbo_customer
|
||||
end
|
||||
|
||||
# update a specific vehicle
|
||||
def update
|
||||
@vehicle = Vehicle.find_by_id(params[:id])
|
||||
if @vehicle.update_attributes(params[:vehicle])
|
||||
flash[:success] = "Vehicle updated"
|
||||
redirect_to @vehicle
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
# delete a specific vehicle
|
||||
def destroy
|
||||
v = Vehicle.find_by_id(params[:id])
|
||||
if v != nil
|
||||
v.destroy
|
||||
flash.now[:notice] = "Vehicle deleted successfully"
|
||||
else
|
||||
flash.now[:error] = "No Vehicle Found"
|
||||
end
|
||||
redirect_to action: :index
|
||||
end
|
||||
|
||||
end
|
||||
18
app/helpers/auth_helper.rb
Normal file
18
app/helpers/auth_helper.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.
|
||||
|
||||
module AuthHelper
|
||||
|
||||
def require_user
|
||||
if !User.current.logged?
|
||||
render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/estimate_helper.rb
Normal file
2
app/helpers/estimate_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module EstimateHelper
|
||||
end
|
||||
2
app/helpers/invoice_helper.rb
Normal file
2
app/helpers/invoice_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module InvoiceHelper
|
||||
end
|
||||
13
app/helpers/vehicle_helper.rb
Normal file
13
app/helpers/vehicle_helper.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
#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.
|
||||
|
||||
module VehicleHelper
|
||||
|
||||
end
|
||||
@@ -10,11 +10,12 @@
|
||||
|
||||
class Qbo < ActiveRecord::Base
|
||||
unloadable
|
||||
validates_presence_of :token, :secret, :realmId, :token_expires_at, :reconnect_token_at
|
||||
validates_presence_of :qb_token, :qb_secret, :company_id, :token_expires_at, :reconnect_token_at
|
||||
|
||||
QB_KEY = Setting.plugin_redmine_qbo['settingsOAuthConsumerKey']
|
||||
QB_SECRET = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
|
||||
|
||||
# Quickbooks Config Info
|
||||
$qb_oauth_consumer = OAuth::Consumer.new(QB_KEY, QB_SECRET, {
|
||||
:site => "https://oauth.intuit.com",
|
||||
:request_token_path => "/oauth/v1/get_request_token",
|
||||
@@ -22,12 +23,21 @@ class Qbo < ActiveRecord::Base
|
||||
:access_token_path => "/oauth/v1/get_access_token"
|
||||
})
|
||||
|
||||
def self.get_auth_token
|
||||
qbo = first
|
||||
return OAuth::AccessToken.new($qb_oauth_consumer, qbo.token, qbo.secret)
|
||||
end
|
||||
# Configure quickbooks-ruby-base to access our database
|
||||
Quickbooks::Base.configure do |c|
|
||||
c.persistent_token = 'qb_token'
|
||||
c.persistent_secret = 'qb_secret'
|
||||
c.persistent_company_id = 'company_id'
|
||||
end
|
||||
|
||||
def self.get_oauth_consumer
|
||||
return $qb_oauth_consumer
|
||||
# Get a quickbooks base object for type
|
||||
# @params type of base
|
||||
def self.get_base(type)
|
||||
Quickbooks::Base.new(first, type)
|
||||
end
|
||||
|
||||
# Get the QBO account
|
||||
def self.get_account
|
||||
first
|
||||
end
|
||||
end
|
||||
|
||||
128
app/models/qbo_customer.rb
Normal file
128
app/models/qbo_customer.rb
Normal file
@@ -0,0 +1,128 @@
|
||||
#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 QboCustomer < ActiveRecord::Base
|
||||
unloadable
|
||||
|
||||
has_many :issues
|
||||
has_many :qbo_purchases
|
||||
has_many :vehicles
|
||||
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
|
||||
after_initialize :get_details
|
||||
|
||||
self.primary_key = :id
|
||||
|
||||
# returns true if the customer is active
|
||||
def active?
|
||||
return @details.active? if @details
|
||||
end
|
||||
|
||||
# returns a human readable string
|
||||
def to_s
|
||||
return name
|
||||
end
|
||||
|
||||
# returns the customer's email
|
||||
def email
|
||||
begin
|
||||
return @details.email_address.address
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
# returns the customer's primary phone
|
||||
def primary_phone
|
||||
begin
|
||||
return @details.primary_phone.free_form_number
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
# returns the customer's mobile phone
|
||||
def mobile_phone
|
||||
begin
|
||||
return @details.mobile_phone.free_form_number
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
# returns the customer's notes
|
||||
def notes
|
||||
return @details.notes if @details
|
||||
end
|
||||
|
||||
# updates the customer's notes in QBO
|
||||
def notes=(s)
|
||||
customer = get_customer(self.id)
|
||||
customer.notes = s
|
||||
get_base.update(customer)
|
||||
end
|
||||
|
||||
# returns the bases QBO service for customers
|
||||
def get_base
|
||||
Qbo.get_base(:customer)
|
||||
end
|
||||
|
||||
# returns the QBO customer
|
||||
def get_customer (id)
|
||||
get_base.find_by_id(id)
|
||||
end
|
||||
|
||||
# proforms a bruteforce sync operation
|
||||
# This needs to be simplified
|
||||
def update_all
|
||||
customers = get_base.service.all
|
||||
|
||||
transaction do
|
||||
# Update the customer table
|
||||
customers.each { |customer|
|
||||
qbo_customer = QboCustomer.find_or_create_by(id: customer.id)
|
||||
# only update if diffrent
|
||||
if not qbo_customer.name == customer.display_name
|
||||
qbo_customer.name = customer.display_name
|
||||
qbo_customer.id = customer.id
|
||||
qbo_customer.save!
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
# remove deleted customers
|
||||
where.not(customers.map(&:id)).destroy_all
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# init details
|
||||
def get_details
|
||||
if self.id
|
||||
@details = get_customer(self.id)
|
||||
update
|
||||
end
|
||||
end
|
||||
|
||||
# update's the customers name if updated
|
||||
def update
|
||||
begin
|
||||
if not self.name == @detils.display_name
|
||||
self.name = @details.display_name
|
||||
self.save
|
||||
end
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -14,16 +14,24 @@ class QboEmployee < ActiveRecord::Base
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
|
||||
def self.update_all
|
||||
qbo = Qbo.first
|
||||
service = Quickbooks::Service::Employee.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
|
||||
# Update the item table
|
||||
service.all.each { |employee|
|
||||
qbo_employee = QboEmployee.find_or_create_by(id: employee.id)
|
||||
qbo_employee.name = employee.display_name
|
||||
qbo_employee.id = employee.id
|
||||
qbo_employee.save!
|
||||
}
|
||||
def self.get_base
|
||||
Qbo.get_base(:employee)
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_all
|
||||
employees = get_base.service.all
|
||||
|
||||
transaction do
|
||||
# Update the item table
|
||||
employees.each { |employee|
|
||||
qbo_employee = find_or_create_by(id: employee.id)
|
||||
qbo_employee.name = employee.display_name
|
||||
qbo_employee.id = employee.id
|
||||
qbo_employee.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted employees
|
||||
where.not(employees.map(&:id)).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
45
app/models/qbo_estimate.rb
Normal file
45
app/models/qbo_estimate.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
#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 QboEstimate < ActiveRecord::Base
|
||||
unloadable
|
||||
has_many :issues
|
||||
attr_accessible :doc_number
|
||||
validates_presence_of :id, :doc_number
|
||||
|
||||
def self.get_base
|
||||
Qbo.get_base(:estimate)
|
||||
end
|
||||
|
||||
def self.update_all
|
||||
estimates = get_base.service.all
|
||||
|
||||
# Update the item table
|
||||
transaction do
|
||||
estimates.each { |estimate|
|
||||
qbo_estimate = QboEstimate.find_or_create_by(id: estimate.id)
|
||||
qbo_estimate.doc_number = estimate.doc_number
|
||||
qbo_estimate.id = estimate.id
|
||||
qbo_estimate.save!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted estimates
|
||||
where.not(estimates.map(&:id)).destroy_all
|
||||
end
|
||||
|
||||
def self.update(id)
|
||||
# Update the item table
|
||||
estimate = get_base.service.fetch_by_id(id)
|
||||
qbo_estimate = QboEstimate.find_or_create_by(id: id)
|
||||
qbo_estimate.doc_number = estimate.doc_number
|
||||
qbo_estimate.save!
|
||||
end
|
||||
end
|
||||
46
app/models/qbo_invoice.rb
Normal file
46
app/models/qbo_invoice.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
#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
|
||||
#Pull the invoices from the quickbooks server
|
||||
invoices = get_base.service.all
|
||||
|
||||
# Update the invoice table
|
||||
transaction do
|
||||
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!
|
||||
}
|
||||
end
|
||||
|
||||
#remove deleted invoices
|
||||
where.not(invoices.map(&:id)).destroy_all
|
||||
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,16 +14,24 @@ class QboItem < ActiveRecord::Base
|
||||
attr_accessible :name
|
||||
validates_presence_of :id, :name
|
||||
|
||||
def self.get_base
|
||||
Qbo.get_base(:item)
|
||||
end
|
||||
|
||||
def self.update_all
|
||||
qbo = Qbo.first
|
||||
service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
items = get_base.service.find_by(:type, "Service")
|
||||
|
||||
transaction do
|
||||
# Update the item table
|
||||
items.each { |item|
|
||||
qbo_item = QboItem.find_or_create_by(id: item.id)
|
||||
qbo_item.name = item.name
|
||||
qbo_item.id = item.id
|
||||
qbo_item.save!
|
||||
}
|
||||
end
|
||||
|
||||
# Update the item table
|
||||
service.find_by(:type, "Service").each { |item|
|
||||
qbo_item = QboItem.find_or_create_by(id: item.id)
|
||||
qbo_item.name = item.name
|
||||
qbo_item.id = item.id
|
||||
qbo_item.save!
|
||||
}
|
||||
#remove deleted items
|
||||
where.not(items.map(&:id)).destroy_all
|
||||
end
|
||||
end
|
||||
|
||||
47
app/models/qbo_purchase.rb
Normal file
47
app/models/qbo_purchase.rb
Normal 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
|
||||
88
app/models/vehicle.rb
Normal file
88
app/models/vehicle.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
#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 Vehicle < ActiveRecord::Base
|
||||
|
||||
unloadable
|
||||
belongs_to :qbo_customer
|
||||
|
||||
attr_accessible :year, :make, :model, :qbo_customer_id, :notes, :vin
|
||||
validates_presence_of :year, :make, :model, :qbo_customer_id
|
||||
|
||||
before_validation :decode_vin
|
||||
after_initialize :get_details
|
||||
|
||||
# returns a human readable string
|
||||
def to_s
|
||||
return "#{self.year} #{self.make} #{self.model}"
|
||||
end
|
||||
|
||||
# returns the raw JSON details from EMUNDS
|
||||
def details
|
||||
return @details
|
||||
end
|
||||
|
||||
# returns the style of the vehicle
|
||||
def style
|
||||
begin
|
||||
return @details['years'][0]['styles'][0]['name'] if @details
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
# returns the drive of the vehicle i.e. 2 wheel, 4 wheel, ect.
|
||||
def drive
|
||||
return @details['drivenWheels'] if @details
|
||||
end
|
||||
|
||||
# returns the number of doors of the vehicle
|
||||
def doors
|
||||
return @details['numOfDoors'] if @details
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# init method to pull JSON details from Edmunds
|
||||
def get_details
|
||||
if self.vin?
|
||||
@details = JSON.parse get_decoder.full(self.vin)
|
||||
end
|
||||
end
|
||||
|
||||
# returns the Edmunds decoder service
|
||||
def get_decoder
|
||||
#TODO API Code via Settings
|
||||
return decoder = Edmunds::Vin.new('2dheutzvhxs28dzukx5tgu47')
|
||||
end
|
||||
|
||||
# decodes a vin and updates self
|
||||
def decode_vin
|
||||
get_details
|
||||
if self.vin?
|
||||
details
|
||||
self.year = @details['years'][0]['year']
|
||||
self.make = @details['make']['name']
|
||||
self.model = @details['model']['name']
|
||||
end
|
||||
self.name = to_s
|
||||
end
|
||||
|
||||
# makes a squishvin
|
||||
# https://api.edmunds.com/api/vehicle/v2/squishvins/#{vin}/?fmt=json&api_key=#{ENV['edmunds_key']}
|
||||
def vin_squish
|
||||
if not self.vin? or self.vin.size < 11
|
||||
# this is to go ahead and query the API, letting them handle the error. :P
|
||||
return '1000000000A'
|
||||
end
|
||||
v = self.vin[0,11]
|
||||
return v.slice(0,8) + v.slice(9,11)
|
||||
end
|
||||
end
|
||||
35
app/views/customers/_details.html.erb
Normal file
35
app/views/customers/_details.html.erb
Normal file
@@ -0,0 +1,35 @@
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Customer</th>
|
||||
<td><%= @customer.name %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<td><%= @customer.email %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Primary Phone</th>
|
||||
<td><%= @customer.primary_phone %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Mobile Phone</th>
|
||||
<td><%= @customer.mobile_phone %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Notes</th>
|
||||
<td><%= @customer.notes %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td/>
|
||||
<td>
|
||||
<%= button_to "Edit", edit_customer_path(@customer), method: :get%>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
20
app/views/customers/index.html.erb
Normal file
20
app/views/customers/index.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<h1>Customers</h1>
|
||||
<br/>
|
||||
<% @customers.each do |c| %>
|
||||
<div class="row">
|
||||
<div class="span6 columns">
|
||||
<fieldset>
|
||||
<% @customer = c %>
|
||||
<%= render :partial => 'customers/details' %>
|
||||
<%= button_to "Show", customer_path(c.id), method: :get %>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="actions">
|
||||
<%= will_paginate @customers %>
|
||||
<%= button_to "New", new_customer_path, method: :get %>
|
||||
</div>
|
||||
5
app/views/customers/show.html.erb
Normal file
5
app/views/customers/show.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Customer Detail</h1>
|
||||
<br/>
|
||||
<%= render :partial => 'customers/details' %>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/list' %>
|
||||
1
app/views/public/401.html.erb
Normal file
1
app/views/public/401.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= flash.now[:error] = "Not Authorized" %>
|
||||
@@ -16,7 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
<div>
|
||||
<%= f.label "Customer Count:"+@qbo_customer_count.to_s%>
|
||||
<br/>
|
||||
<%= f.select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), :selected => @selected_customer, include_blank: true %>
|
||||
<%= f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, :selected => @selected_customer, include_blank: true %>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
@@ -24,7 +24,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
<div>
|
||||
<%= f.label "Item Count: "+@qbo_item_count.to_s %>
|
||||
<br/>
|
||||
<%= f.select :qbo_item_id, QboItem.all.pluck(:name, :id).reverse, :selected => @selected_item, include_blank: true %>
|
||||
<%= f.select :qbo_item_id, QboItem.all.pluck(:name, :id).sort.reverse, :selected => @selected_item, include_blank: true %>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
@@ -32,11 +32,24 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
<div>
|
||||
<%= f.label "Employee Count: "+@qbo_employee_count.to_s %>
|
||||
<br/>
|
||||
<%= f.select :qbo_employee_id, QboEmployee.all.pluck(:name, :id), :selected => @selected_employee, include_blank: true %>
|
||||
<%= f.select :qbo_employee_id, QboEmployee.all.pluck(:name, :id).sort, :selected => @selected_employee, include_blank: true %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
<p>
|
||||
<%= f.label "Invoice Count: "+@qbo_invoice_count.to_s %>
|
||||
<br/>
|
||||
<%=f.select :qbo_invoice_id, QboInvoice.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_invoice, include_blank: true%>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label "Estimate Count: "+@qbo_estimate_count.to_s %>
|
||||
<br/>
|
||||
<%=f.select :qbo_estimate_id, QboEstimate.all.pluck(:doc_number, :id).sort! {|x, y| y <=> x}, :selected => @selected_estimate, include_blank: true%>
|
||||
</p>
|
||||
|
||||
|
||||
<% end %>
|
||||
<br/>
|
||||
<br/>
|
||||
<%= link_to "Sync", qbo_sync_path %>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
46
app/views/vehicles/_details.html.erb
Normal file
46
app/views/vehicles/_details.html.erb
Normal file
@@ -0,0 +1,46 @@
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Customer</th>
|
||||
<td><%= @customer %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Vehicle</th>
|
||||
<td><%= @vehicle.to_s %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>VIN</th>
|
||||
<td><%= @vehicle.vin %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Style</th>
|
||||
<td><%= @vehicle.style %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Drive</th>
|
||||
<td><%= @vehicle.drive %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Doors</th>
|
||||
<td><%= @vehicle.doors %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Notes</th>
|
||||
<td><%= @vehicle.notes %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td/>
|
||||
<td>
|
||||
<%= button_to "Edit", edit_vehicle_path(@vehicle), method: :get%>
|
||||
<%= button_to "Delete", @vehicle, method: :delete, data: {confirm: "You sure?"} %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
2
app/views/vehicles/_dropdown.html.erb
Normal file
2
app/views/vehicles/_dropdown.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
<%= @f.collection_select :vehicle_id, @customer.vehicles.order(:year), :id, :vin, include_blank: true, :selected => @vehicle%>
|
||||
Partial Test
|
||||
55
app/views/vehicles/_form.html.erb
Normal file
55
app/views/vehicles/_form.html.erb
Normal file
@@ -0,0 +1,55 @@
|
||||
<div class="row">
|
||||
<div class="span6 columns">
|
||||
<fieldset>
|
||||
|
||||
<%= form_for @vehicle do |f| %>
|
||||
<div class="clearfix">
|
||||
Customer:
|
||||
<div class="input">
|
||||
<%= f.collection_select :qbo_customer_id, QboCustomer.order(:name), :id, :name, include_blank: true, :selected => @customer, :required => true%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
Year:
|
||||
<div class="input">
|
||||
<%= f.text_field :year, :required => true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
Make:
|
||||
<div class="input">
|
||||
<%= f.text_field :make, :required => true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
Model:
|
||||
<div class="input">
|
||||
<%= f.text_field :model, :required => true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
VIN:
|
||||
<div class="input">
|
||||
<%= f.text_field :vin %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="clearfix">
|
||||
Notes:
|
||||
<div class="input">
|
||||
<%= f.text_area :notes, :rows => 6, :class => 'wiki-edit', :accesskey => accesskey(:edit), :cols => 60%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
18
app/views/vehicles/_list.html.erb
Normal file
18
app/views/vehicles/_list.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<% @vehicles.each do |vehicle| %>
|
||||
<div class="row">
|
||||
<div class="span6 columns">
|
||||
<fieldset>
|
||||
<% @customer = vehicle.qbo_customer.name if vehicle.qbo_customer %>
|
||||
<% @vehicle = vehicle %>
|
||||
<%= render :partial => 'vehicles/details' %>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="actions">
|
||||
<%= will_paginate @vehicles %>
|
||||
<%= button_to "New", new_vehicle_path, method: :get %>
|
||||
</div>
|
||||
3
app/views/vehicles/edit.html.erb
Normal file
3
app/views/vehicles/edit.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>Edit Customer Vehicle</h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
3
app/views/vehicles/index.html.erb
Normal file
3
app/views/vehicles/index.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>Customer Vehicles</h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/list' %>
|
||||
3
app/views/vehicles/new.html.erb
Normal file
3
app/views/vehicles/new.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>New Customer Vehicle</h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/form' %>
|
||||
3
app/views/vehicles/show.html.erb
Normal file
3
app/views/vehicles/show.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h1>Customer Vehicle</h1>
|
||||
<br/>
|
||||
<%= render :partial => 'vehicles/details' %>
|
||||
3
config/initializers/edmunds.rb
Normal file
3
config/initializers/edmunds.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Edmunds::Api.configure do |config|
|
||||
config.api_key = '2dheutzvhxs28dzukx5tgu47'
|
||||
end
|
||||
@@ -14,3 +14,8 @@ en:
|
||||
field_qbo_customer: "Customer"
|
||||
field_qbo_item: "Item"
|
||||
field_qbo_employee: "Employee"
|
||||
field_qbo_invoice: "Invoice"
|
||||
field_qbo_estimate: "Estimate"
|
||||
field_vehicles: "Vehicle"
|
||||
field_vin: "VIN"
|
||||
field_notes: "Notes"
|
||||
|
||||
@@ -15,4 +15,7 @@ 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 => 'estimate#show', as: :estimate
|
||||
get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice
|
||||
resources :vehicles
|
||||
resources :customers
|
||||
|
||||
18
db/migrate/008_create_qbo_estimates.rb
Normal file
18
db/migrate/008_create_qbo_estimates.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 CreateQboEstimates < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :qbo_estimates, id: false do |t|
|
||||
t.integer :id, :options => 'PRIMARY KEY'
|
||||
t.string :doc_number
|
||||
end
|
||||
end
|
||||
end
|
||||
17
db/migrate/009_update_qbos.rb
Normal file
17
db/migrate/009_update_qbos.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
#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 UpdateQbos < ActiveRecord::Migration
|
||||
def change
|
||||
rename_column :qbos, :token, :qb_token
|
||||
rename_column :qbos, :secret, :qb_secret
|
||||
rename_column :qbos, :realmId, :company_id
|
||||
end
|
||||
end
|
||||
15
db/migrate/010_update_issues_with_estimates.rb
Normal file
15
db/migrate/010_update_issues_with_estimates.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 UpdateIssuesWithEstimates < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :issues, :qbo_estimate, index: true
|
||||
end
|
||||
end
|
||||
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
|
||||
21
db/migrate/013_create_qbo_purchases.rb
Normal file
21
db/migrate/013_create_qbo_purchases.rb
Normal 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
|
||||
15
db/migrate/014_update_customers.rb
Normal file
15
db/migrate/014_update_customers.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 UpdateCustomers < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :qbo_customers, :qbo_purchase, index: true
|
||||
end
|
||||
end
|
||||
15
db/migrate/015_update_qbo_purchases.rb
Normal file
15
db/migrate/015_update_qbo_purchases.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 UpdateQboPurchases < ActiveRecord::Migration
|
||||
def change
|
||||
rename_column :qbo_purchases, :customer_id, :qbo_customer_id
|
||||
end
|
||||
end
|
||||
24
db/migrate/016_create_vehicles.rb
Normal file
24
db/migrate/016_create_vehicles.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
#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 CreateVehicles < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
create_table :vehicles do |t|
|
||||
t.integer :year
|
||||
t.string :make
|
||||
t.string :model
|
||||
t.string :vin
|
||||
t.text :notes
|
||||
end
|
||||
|
||||
add_reference :vehicles, :qbo_customer, index: true
|
||||
end
|
||||
end
|
||||
15
db/migrate/017_update_issues_with_vehicles.rb
Normal file
15
db/migrate/017_update_issues_with_vehicles.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 UpdateIssuesWithVehicles < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :issues, :vehicles, index: true
|
||||
end
|
||||
end
|
||||
15
db/migrate/018_update_vehicles.rb
Normal file
15
db/migrate/018_update_vehicles.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 UpdateVehicles < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :vehicles, :name, :text
|
||||
end
|
||||
end
|
||||
60
init.rb
60
init.rb
@@ -10,29 +10,43 @@
|
||||
|
||||
Redmine::Plugin.register :redmine_qbo do
|
||||
|
||||
require_dependency 'issues_form_hook_listener'
|
||||
require_dependency 'issues_save_hook_listener'
|
||||
require_dependency 'issues_show_hook_listener'
|
||||
require_dependency 'users_show_hook_listener'
|
||||
# View Hook Listeners
|
||||
require_dependency 'issues_form_hook_listener'
|
||||
require_dependency 'issues_save_hook_listener'
|
||||
require_dependency 'issues_show_hook_listener'
|
||||
require_dependency 'users_show_hook_listener'
|
||||
|
||||
# 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'
|
||||
|
||||
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.0.2'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'http://rickbarrette.org'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
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.0.5'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'http://rickbarrette.org'
|
||||
settings :default => {'empty' => true}, :partial => 'qbo/settings'
|
||||
|
||||
# Add safe attributes
|
||||
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
|
||||
# Add safe attributes
|
||||
Issue.safe_attributes 'qbo_customer_id'
|
||||
Issue.safe_attributes 'qbo_item_id'
|
||||
Issue.safe_attributes 'qbo_estimate_id'
|
||||
Issue.safe_attributes 'qbo_invoice_id'
|
||||
Issue.safe_attributes 'vehicles_id'
|
||||
User.safe_attributes 'qbo_employee_id'
|
||||
TimeEntry.safe_attributes 'qbo_billed'
|
||||
|
||||
# We are playing in the sandbox
|
||||
#Quickbooks.sandbox_mode = true
|
||||
|
||||
# set per_page globally
|
||||
WillPaginate.per_page = 10
|
||||
|
||||
# Register QBO top menu item
|
||||
menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks'
|
||||
|
||||
end
|
||||
# Register QBO top menu item
|
||||
menu :top_menu, :qbo, { :controller => :qbo, :action => :index }, :caption => 'Quickbooks', :if => Proc.new { User.current.admin? }
|
||||
menu :top_menu, :vehicles, { :controller => :vehicles, :action => :index }, :caption => 'Vehicles', :if => Proc.new { User.current.logged? }
|
||||
menu :top_menu, :customers, { :controller => :customers, :action => :index }, :caption => 'Customers', :if => Proc.new { User.current.logged? }
|
||||
end
|
||||
|
||||
45
lib/issue_patch.rb
Normal file
45
lib/issue_patch.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
#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.
|
||||
|
||||
require_dependency 'issue'
|
||||
|
||||
# Patches Redmine's Issues dynamically.
|
||||
# Adds a relationships
|
||||
module IssuePatch
|
||||
|
||||
def self.included(base) # :nodoc:
|
||||
base.extend(ClassMethods)
|
||||
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
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
|
||||
belongs_to :vehicle, primary_key: :id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Add module to Issue
|
||||
Issue.send(:include, IssuePatch)
|
||||
@@ -9,27 +9,40 @@
|
||||
#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 IssuesFormHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
|
||||
# Edit Issue Form
|
||||
# Show a dropdown for quickbooks contacts
|
||||
def view_issues_form_details_bottom(context={})
|
||||
selected = ""
|
||||
|
||||
QboCustomers.update_all
|
||||
QboItem.update_all
|
||||
f = context[:form]
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
if not context[:issue].qbo_customer_id.nil? then
|
||||
selected_customer = context[:issue].qbo_customer_id
|
||||
selected_item = context[:issue].qbo_item_id
|
||||
end
|
||||
|
||||
# Generate the drop down list of quickbooks contacts
|
||||
select_customer = context[:form].select :qbo_customer_id, QboCustomers.all.pluck(:name, :id), :selected => selected_customer, include_blank: true
|
||||
selected_customer = context[:issue].qbo_customer ? context[:issue].qbo_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
|
||||
|
||||
customer = QboCustomer.find_by_id(selected_customer) if selected_customer
|
||||
vehicle = context[:issue].vehicles_id
|
||||
|
||||
# Generate the drop down list of quickbooks customers
|
||||
select_customer = f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, :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 = 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
|
||||
|
||||
#@estimates_link = link_to qbo_update_estimates_path
|
||||
|
||||
#render_on :view_issues_form_details_bottom, :partial => 'hooks/redmine_qbo/vehicles/dropdown'
|
||||
vehicles = customer.vehicles.pluck(:name, :id).sort if customer
|
||||
vehicles = Vehicle.all if not vehicles
|
||||
vehicle = f.select :vehicles_id, vehicles, include_blank: true, :selected => vehicle
|
||||
|
||||
return "<p>#{select_customer}</p> <p>#{select_item}</p> <p>#{select_invoice}</p> <p>#{select_estimate}</p> <p>#{vehicle}</p>"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,23 +10,72 @@
|
||||
|
||||
class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# New Issue Saved
|
||||
def controller_issues_edit_after_save(context={})
|
||||
#Before Issue Saved
|
||||
def controller_issues_edit_before_save(context={})
|
||||
issue = context[:issue]
|
||||
qbo = Qbo.first
|
||||
|
||||
# Check to see if we have registered with QBO
|
||||
if not qbo.nil? then
|
||||
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
|
||||
|
||||
# Get QBO Services
|
||||
item_service = QboItem.get_base.service
|
||||
estimate_base = QboEstimate.get_base
|
||||
|
||||
# Create the estimate
|
||||
estimate = estimate_base.qr_model(:estimate)
|
||||
estimate.customer_id = issue.qbo_customer_id
|
||||
estimate.txn_date = Date.today
|
||||
|
||||
# Create the line item for labor
|
||||
item = item_service.fetch_by_id(issue.qbo_item_id)
|
||||
|
||||
line_item = Quickbooks::Model::InvoiceLineItem.new
|
||||
line_item.amount = item.unit_price * issue.estimated_hours
|
||||
line_item.description = issue.subject
|
||||
|
||||
line_item.sales_item! do |detail|
|
||||
detail.unit_price = item.unit_price
|
||||
detail.quantity = issue.estimated_hours
|
||||
detail.item_id = issue.qbo_item_id
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
# Called After Issue Saved
|
||||
def controller_issues_edit_after_save(context={})
|
||||
issue = context[:issue]
|
||||
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.qbo_customer && issue.qbo_item && employee_id && issue.status.is_closed?
|
||||
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 = Quickbooks::Service::TimeActivity.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
item_service = Quickbooks::Service::Item.new(:company_id => qbo.realmId, :access_token => Qbo.get_auth_token)
|
||||
time_service = Qbo.get_base(:time_activity).service
|
||||
item_service = Qbo.get_base(:item).service
|
||||
time_entry = Quickbooks::Model::TimeActivity.new
|
||||
|
||||
# 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 = spent_hours.to_i
|
||||
minutesDecimal = (( spent_hours - hours) * 60)
|
||||
@@ -37,27 +86,21 @@ class IssuesSaveHookListener < Redmine::Hook::ViewListener
|
||||
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
|
||||
# TODO Add configuration settings for employee_id, hourly_rate, item_id
|
||||
if issue.status.is_closed? and not issue.qbo_customer_id.nil? and not issue.qbo_item_id.nil? and not employee_id.nil? and spent_hours > 0 then
|
||||
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.qbo_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
|
||||
|
||||
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.qbo_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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,31 +10,82 @@
|
||||
|
||||
class IssuesShowHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# Additional context fields
|
||||
# :issue => the issue this is edited
|
||||
# :f => the form object to create additional fields
|
||||
#render_on :view_issues_show_details_bottom, :partial => 'hooks/redmine_qbo/_view_issues_show_details_bottom.html.erb'
|
||||
|
||||
# View Issue
|
||||
# Display the quickbooks contact in the issue
|
||||
def view_issues_show_details_bottom(context={})
|
||||
value = ""
|
||||
issue = context[:issue]
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
if not context[:issue].qbo_customer_id.nil? then
|
||||
value = QboCustomers.find_by_id(context[:issue].qbo_customer_id).name
|
||||
end
|
||||
|
||||
output = content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Customer") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_customer_id attribute"), class:"attributes")
|
||||
|
||||
value = ""
|
||||
customer = issue.qbo_customer ? issue.qbo_customer.name : nil
|
||||
|
||||
# Check to see if there is a quickbooks item attached to the issue
|
||||
if not context[:issue].qbo_customer_id.nil? then
|
||||
if not QboItem.find_by_id(context[:issue].qbo_item_id).nil? then
|
||||
value = QboItem.find_by_id(context[:issue].qbo_item_id).name
|
||||
end
|
||||
item = issue.qbo_item ? issue.qbo_item.name : nil
|
||||
|
||||
# Estimate Number
|
||||
if issue.qbo_estimate
|
||||
estimate = issue.qbo_estimate.doc_number
|
||||
estimate_link = link_to estimate, "#{Redmine::Utils::relative_url_root}/qbo/estimate/#{issue.qbo_estimate.id}", :target => "_blank"
|
||||
end
|
||||
|
||||
output << content_tag(:div, content_tag(:div, content_tag(:div, content_tag(:span,"Item") + ":", class:"label") + content_tag(:div, value, class:"value") , class:"qbo_item_id attribute"), class:"attributes")
|
||||
|
||||
# Display the Customers name in the Issue attributes
|
||||
return output
|
||||
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"
|
||||
end
|
||||
|
||||
|
||||
if issue.vehicles_id
|
||||
v = Vehicle.find_by_id(issue.vehicles_id)
|
||||
vehicle = link_to v.to_s, "#{Redmine::Utils::relative_url_root}/vehicles/#{v.id}"
|
||||
vin = v.vin
|
||||
notes = v.notes
|
||||
end
|
||||
|
||||
return "
|
||||
<div class=\"attributes\">
|
||||
|
||||
<div class=\"qbo_customer_id attribute\">
|
||||
<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>
|
||||
|
||||
end
|
||||
<div class=\"qbo_estimate_id attribute\">
|
||||
<div class=\"label\"><span>Estimate</span>:</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>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class=\"vehicle attribute\">
|
||||
<div class=\"label\"><span>Vehicle</span>:</div>
|
||||
<div class=\"value\">#{vehicle}</div>
|
||||
</div>
|
||||
|
||||
<div class=\"vehicle_vin attribute\">
|
||||
<div class=\"label\"><span>VIN</span>:</div>
|
||||
<div class=\"value\">#{vin}</div>
|
||||
</div>
|
||||
|
||||
<div class=\"vehicle_notes attribute\">
|
||||
<div class=\"label\"><span>Notes</span>:</div>
|
||||
<div class=\"value\">#{notes}</div>
|
||||
</div>
|
||||
</div>"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
246
lib/pdf_patch.rb
Normal file
246
lib/pdf_patch.rb
Normal file
@@ -0,0 +1,246 @@
|
||||
require_dependency 'redmine/export/pdf'
|
||||
require_dependency 'redmine/export/pdf/issues_pdf_helper'
|
||||
|
||||
module IssuesPdfHelperPatch
|
||||
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
alias_method_chain :issue_to_pdf, :patch
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def issue_to_pdf_with_patch(issue, assoc={})
|
||||
pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
|
||||
pdf.set_title("#{issue.project} - #{issue.tracker} ##{issue.id}")
|
||||
pdf.alias_nb_pages
|
||||
pdf.footer_date = format_date(Date.today)
|
||||
pdf.add_page
|
||||
pdf.SetFontStyle('B',11)
|
||||
buf = "#{issue.project} - #{issue.tracker} ##{issue.id}"
|
||||
pdf.RDMMultiCell(190, 5, buf)
|
||||
pdf.SetFontStyle('',8)
|
||||
base_x = pdf.get_x
|
||||
i = 1
|
||||
issue.ancestors.visible.each do |ancestor|
|
||||
pdf.set_x(base_x + i)
|
||||
buf = "#{ancestor.tracker} # #{ancestor.id} (#{ancestor.status.to_s}): #{ancestor.subject}"
|
||||
pdf.RDMMultiCell(190 - i, 5, buf)
|
||||
i += 1 if i < 35
|
||||
end
|
||||
pdf.SetFontStyle('B',11)
|
||||
pdf.RDMMultiCell(190 - i, 5, issue.subject.to_s)
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMMultiCell(190, 5, "#{format_time(issue.created_on)} - #{issue.author}")
|
||||
pdf.ln
|
||||
|
||||
left = []
|
||||
left << [l(:field_status), issue.status]
|
||||
left << [l(:field_priority), issue.priority]
|
||||
left << [l(:field_qbo_customer), issue.qbo_customer.name]
|
||||
left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id')
|
||||
#left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id')
|
||||
#left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id')
|
||||
|
||||
v = Vehicle.find_by_id(issue.vehicles_id)
|
||||
vehicle = v ? v.to_s : nil
|
||||
vin = v ? v.vin : nil
|
||||
notes = v ? v.notes : nil
|
||||
left << [l(:field_vehicles), vehicle]
|
||||
left << [l(:field_vin), vin]
|
||||
left << [l(:field_notes), notes]
|
||||
|
||||
right = []
|
||||
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
|
||||
right << [l(:field_due_date), format_date(issue.due_date)] unless issue.disabled_core_fields.include?('due_date')
|
||||
right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio')
|
||||
right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours')
|
||||
right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
|
||||
#right << [l(:field_notes), notes]
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
while left.size < rows
|
||||
left << nil
|
||||
end
|
||||
while right.size < rows
|
||||
right << nil
|
||||
end
|
||||
|
||||
half = (issue.visible_custom_field_values.size / 2.0).ceil
|
||||
issue.visible_custom_field_values.each_with_index do |custom_value, i|
|
||||
(i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false)]
|
||||
end
|
||||
|
||||
if pdf.get_rtl
|
||||
border_first_top = 'RT'
|
||||
border_last_top = 'LT'
|
||||
border_first = 'R'
|
||||
border_last = 'L'
|
||||
else
|
||||
border_first_top = 'LT'
|
||||
border_last_top = 'RT'
|
||||
border_first = 'L'
|
||||
border_last = 'R'
|
||||
end
|
||||
|
||||
rows = left.size > right.size ? left.size : right.size
|
||||
rows.times do |i|
|
||||
heights = []
|
||||
pdf.SetFontStyle('B',9)
|
||||
item = left[i]
|
||||
heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
|
||||
item = right[i]
|
||||
heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
|
||||
pdf.SetFontStyle('',9)
|
||||
item = left[i]
|
||||
heights << pdf.get_string_height(60, item ? item.last.to_s : "")
|
||||
item = right[i]
|
||||
heights << pdf.get_string_height(60, item ? item.last.to_s : "")
|
||||
height = heights.max
|
||||
|
||||
item = left[i]
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", (i == 0 ? border_first_top : border_first), '', 0, 0)
|
||||
pdf.SetFontStyle('',9)
|
||||
pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 0)
|
||||
|
||||
item = right[i]
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", (i == 0 ? border_first_top : border_first), '', 0, 0)
|
||||
pdf.SetFontStyle('',9)
|
||||
pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 2)
|
||||
|
||||
pdf.set_x(base_x)
|
||||
end
|
||||
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
|
||||
pdf.SetFontStyle('',9)
|
||||
|
||||
# Set resize image scale
|
||||
pdf.set_image_scale(1.6)
|
||||
text = textilizable(issue, :description,
|
||||
:only_path => false,
|
||||
:edit_section_links => false,
|
||||
:headings => false,
|
||||
:inline_attachments => false
|
||||
)
|
||||
pdf.RDMwriteFormattedCell(35+155, 5, '', '', text, issue.attachments, "LRB")
|
||||
|
||||
unless issue.leaf?
|
||||
truncate_length = (!is_cjk? ? 90 : 65)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155,5, l(:label_subtask_plural) + ":", "LTR")
|
||||
pdf.ln
|
||||
issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level|
|
||||
buf = "#{child.tracker} # #{child.id}: #{child.subject}".
|
||||
truncate(truncate_length)
|
||||
level = 10 if level >= 10
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMCell(35+135,5, (level >=1 ? " " * level : "") + buf, border_first)
|
||||
pdf.SetFontStyle('B',8)
|
||||
pdf.RDMCell(20,5, child.status.to_s, border_last)
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
relations = issue.relations.select { |r| r.other_issue(issue).visible? }
|
||||
unless relations.empty?
|
||||
truncate_length = (!is_cjk? ? 80 : 60)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(35+155,5, l(:label_related_issues) + ":", "LTR")
|
||||
pdf.ln
|
||||
relations.each do |relation|
|
||||
buf = relation.to_s(issue) {|other|
|
||||
text = ""
|
||||
if Setting.cross_project_issue_relations?
|
||||
text += "#{relation.other_issue(issue).project} - "
|
||||
end
|
||||
text += "#{other.tracker} ##{other.id}: #{other.subject}"
|
||||
text
|
||||
}
|
||||
buf = buf.truncate(truncate_length)
|
||||
pdf.SetFontStyle('', 8)
|
||||
pdf.RDMCell(35+155-60, 5, buf, border_first)
|
||||
pdf.SetFontStyle('B',8)
|
||||
pdf.RDMCell(20,5, relation.other_issue(issue).status.to_s, "")
|
||||
pdf.RDMCell(20,5, format_date(relation.other_issue(issue).start_date), "")
|
||||
pdf.RDMCell(20,5, format_date(relation.other_issue(issue).due_date), border_last)
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
pdf.RDMCell(190,5, "", "T")
|
||||
pdf.ln
|
||||
|
||||
if issue.changesets.any? &&
|
||||
User.current.allowed_to?(:view_changesets, issue.project)
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_associated_revisions), "B")
|
||||
pdf.ln
|
||||
for changeset in issue.changesets
|
||||
pdf.SetFontStyle('B',8)
|
||||
csstr = "#{l(:label_revision)} #{changeset.format_identifier} - "
|
||||
csstr += format_time(changeset.committed_on) + " - " + changeset.author.to_s
|
||||
pdf.RDMCell(190, 5, csstr)
|
||||
pdf.ln
|
||||
unless changeset.comments.blank?
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMwriteHTMLCell(190,5,'','',
|
||||
changeset.comments.to_s, issue.attachments, "")
|
||||
end
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
if assoc[:journals].present?
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_history), "B")
|
||||
pdf.ln
|
||||
assoc[:journals].each do |journal|
|
||||
pdf.SetFontStyle('B',8)
|
||||
title = "##{journal.indice} - #{format_time(journal.created_on)} - #{journal.user}"
|
||||
title << " (#{l(:field_private_notes)})" if journal.private_notes?
|
||||
pdf.RDMCell(190,5, title)
|
||||
pdf.ln
|
||||
pdf.SetFontStyle('I',8)
|
||||
details_to_strings(journal.visible_details, true).each do |string|
|
||||
pdf.RDMMultiCell(190,5, "- " + string)
|
||||
end
|
||||
if journal.notes?
|
||||
pdf.ln unless journal.details.empty?
|
||||
pdf.SetFontStyle('',8)
|
||||
text = textilizable(journal, :notes,
|
||||
:only_path => false,
|
||||
:edit_section_links => false,
|
||||
:headings => false,
|
||||
:inline_attachments => false
|
||||
)
|
||||
pdf.RDMwriteFormattedCell(190,5,'','', text, issue.attachments, "")
|
||||
end
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
|
||||
if issue.attachments.any?
|
||||
pdf.SetFontStyle('B',9)
|
||||
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
|
||||
pdf.ln
|
||||
for attachment in issue.attachments
|
||||
pdf.SetFontStyle('',8)
|
||||
pdf.RDMCell(80,5, attachment.filename)
|
||||
pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
|
||||
pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
|
||||
pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
|
||||
pdf.ln
|
||||
end
|
||||
end
|
||||
pdf.output
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Redmine::Export::PDF::IssuesPdfHelper.send(:include, IssuesPdfHelperPatch)
|
||||
62
lib/query_patch.rb
Normal file
62
lib/query_patch.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
#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.
|
||||
|
||||
require_dependency 'issue_query'
|
||||
|
||||
module QueryPatch
|
||||
|
||||
def self.included(base) # :nodoc:
|
||||
base.extend(ClassMethods)
|
||||
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
|
||||
alias_method_chain :available_columns, :qbo
|
||||
alias_method_chain :available_filters, :qbo
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def available_columns_with_qbo
|
||||
unless @available_columns
|
||||
@available_columns = available_columns_without_qbo
|
||||
@available_columns << QueryColumn.new(:qbo_customer, :sortable => "#{QboCustomer.table_name}.name", :groupable => true, :caption => :field_qbo_customer)
|
||||
end
|
||||
@available_columns
|
||||
end
|
||||
|
||||
def available_filters_with_qbo
|
||||
unless @available_filters
|
||||
@available_filters = available_filters_without_qbo
|
||||
|
||||
qbo_filters = {
|
||||
"customer" => {
|
||||
:name => l(:field_qbo_customer),
|
||||
:type => :text,
|
||||
:order => @available_filters.size + 1},
|
||||
}
|
||||
|
||||
@available_filters.merge!(qbo_filters)
|
||||
end
|
||||
@available_filters
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Add module to Issue
|
||||
IssueQuery.send(:include, QueryPatch)
|
||||
39
lib/user_patch.rb
Normal file
39
lib/user_patch.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
#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.
|
||||
|
||||
require_dependency 'user'
|
||||
|
||||
# Patches Redmine's User dynamically.
|
||||
# Adds a relationships
|
||||
module UserPatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.extend(ClassMethods)
|
||||
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
# Same as typing in the class
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
belongs_to :qbo_employee, primary_key: :id
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Add module to Issue
|
||||
User.send(:include, UserPatch)
|
||||
@@ -12,16 +12,14 @@ class UsersShowHookListener < Redmine::Hook::ViewListener
|
||||
|
||||
# View User
|
||||
def view_users_form(context={})
|
||||
selected = ""
|
||||
|
||||
# Update the users
|
||||
QboEmployee.update_all
|
||||
|
||||
# Check to see if there is a quickbooks user attached to the issue
|
||||
if not context[:user].qbo_employee_id.nil? then
|
||||
selected = context[:user].qbo_employee_id
|
||||
end
|
||||
@selected = context[:user].qbo_employee.id if context[:user].qbo_employee
|
||||
|
||||
# Generate the drop down list of quickbooks contacts
|
||||
return "<p>#{context[:form].select :qbo_employee_id, QboEmployee.all.pluck(:name, :id), :selected => selected, include_blank: true}</p>"
|
||||
return "<p>#{context[:form].select :qbo_employee_id, QboEmployee.all.pluck(:name, :id), :selected => @selected, include_blank: true}</p>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
8
test/functional/estimate_controller_test.rb
Normal file
8
test/functional/estimate_controller_test.rb
Normal 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
|
||||
8
test/functional/invoice_controller_test.rb
Normal file
8
test/functional/invoice_controller_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user