Compare commits

...

25 Commits

Author SHA1 Message Date
637cfa89b4 Refactored view hooks 2026-02-03 22:52:34 -05:00
c36f4c905b moved issue hooks into issue_patch 2026-02-03 22:42:08 -05:00
83fb20044d updated plugin description 2026-01-31 22:10:23 -05:00
928e632dd3 converted links to buttons 2026-01-31 21:02:22 -05:00
8b9cf5066e only show checkboxes if more then 1 invoices 2026-01-31 20:44:15 -05:00
45bfce87d8 2026.1.9 2026-01-31 13:02:21 -05:00
6f33e9d23d Inverted conditionals in estimates and invoices lists to use 'unless' 2026-01-31 12:54:07 -05:00
92460392b9 Refactor estimates and invoices rendering to use local variables for the abilty for other plugins to display filtered lists 2026-01-31 12:45:47 -05:00
f1bdf59697 Add customer details translation and fix link in appointment action 2026-01-30 23:05:23 -05:00
60e2f1d2b0 2026.1.8 2026-01-30 21:30:28 -05:00
6c9ae82f81 fixed typo 2026-01-30 21:22:08 -05:00
42e4494f6e fixed entity, they need strings 2026-01-30 21:17:17 -05:00
7e0b2c9d09 Removed unused folders 2026-01-30 20:51:09 -05:00
5ca68b01b6 removed unsued tests 2026-01-30 20:46:04 -05:00
ebd4fa7363 Add flash error messages for forbidden access in permission checks 2026-01-30 20:40:57 -05:00
e6818958ae Add I18n support for flash messages and update locale file with new notices 2026-01-30 20:19:12 -05:00
5b31459629 use a symbol for empty 2026-01-30 19:28:33 -05:00
92de2928f6 Merge branch 'master' into symbols 2026-01-30 17:12:11 -05:00
a8af180de2 2026.1.7 2026-01-30 17:09:34 -05:00
e621dc9e3a nil not nill 2026-01-30 17:00:29 -05:00
c3d7c1c867 Use symbols 2026-01-30 16:58:14 -05:00
defeec7f8e 2026.1.6 2026-01-30 07:53:51 -05:00
37c302e274 use symbol keys 2026-01-30 07:53:29 -05:00
006e907b35 need to supply selected id 2026-01-30 07:53:14 -05:00
f1f77a8022 use locale 2026-01-30 07:42:09 -05:00
38 changed files with 149 additions and 280 deletions

View File

@@ -69,7 +69,7 @@ class CustomersController < ApplicationController
def create def create
@customer = Customer.new(allowed_params) @customer = Customer.new(allowed_params)
if @customer.save if @customer.save
flash[:notice] = "New Customer Created" flash[:notice] = t :notice_customer_created
redirect_to @customer redirect_to @customer
else else
flash[:error] = @customer.errors.full_messages.to_sentence flash[:error] = @customer.errors.full_messages.to_sentence
@@ -90,6 +90,7 @@ class CustomersController < ApplicationController
@issues.open.each { |i| @hours+= i.total_spent_hours } @issues.open.each { |i| @hours+= i.total_spent_hours }
@closed_issues.each { |i| @closed_hours+= i.total_spent_hours } @closed_issues.each { |i| @closed_hours+= i.total_spent_hours }
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -99,6 +100,7 @@ class CustomersController < ApplicationController
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -108,13 +110,14 @@ class CustomersController < ApplicationController
begin begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
if @customer.update(allowed_params) if @customer.update(allowed_params)
flash[:notice] = "Customer updated" flash[:notice] = t :notice_customer_updated
redirect_to @customer redirect_to @customer
else else
redirect_to edit_customer_path redirect_to edit_customer_path
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors
end end
rescue rescue
flash[:error] = t :notice_customer_not_found
render_404 render_404
end end
end end
@@ -123,9 +126,10 @@ class CustomersController < ApplicationController
def destroy def destroy
begin begin
Customer.find_by_id(params[:id]).destroy Customer.find_by_id(params[:id]).destroy
flash[:notice] = "Customer deleted successfully" flash[:notice] = t :notice_customer_deleted
redirect_to action: :index redirect_to action: :index
rescue rescue
flash[:error] = t :notice_customer_not_deleted
render_404 render_404
end end
end end
@@ -143,6 +147,7 @@ class CustomersController < ApplicationController
issue = Issue.find_by_id(params[:id]) issue = Issue.find_by_id(params[:id])
redirect_to view_path issue.share_token.token redirect_to view_path issue.share_token.token
rescue rescue
flash[:error] = t :notice_issue_not_found
render_404 render_404
end end
end end
@@ -178,6 +183,7 @@ class CustomersController < ApplicationController
@time_entry = TimeEntry.new(issue: @issue, project: @issue.project) @time_entry = TimeEntry.new(issue: @issue, project: @issue.project)
@relation = IssueRelation.new @relation = IssueRelation.new
rescue rescue
flash[:error] = t :notice_forbidden
render_403 render_403
end end
end end

View File

@@ -36,9 +36,9 @@ class EstimateController < ApplicationController
estimate = get_estimate estimate = get_estimate
begin begin
send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: 'inline', type: "application/pdf" send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf"
rescue rescue
redirect_to :back, flash: { error: "Estimate not found" } redirect_to :back, flash: { error: I18n.t(:notice_estimate_not_found) }
end end
end end
@@ -49,9 +49,9 @@ class EstimateController < ApplicationController
estimate = get_estimate estimate = get_estimate
begin begin
send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: 'inline', type: "application/pdf" send_data estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf"
rescue rescue
redirect_to :back, flash: { error: "Estimate not found" } redirect_to :back, flash: { error: I18n.t(:notice_estimate_not_found) }
end end
end end

View File

@@ -45,10 +45,10 @@ class InvoiceController < ApplicationController
ref = invoice.doc_number ref = invoice.doc_number
end end
send_data @pdf, filename: "invoice #{ref}.pdf", disposition: 'inline', type: "application/pdf" send_data @pdf, filename: "invoice #{ref}.pdf", disposition: :inline, type: "application/pdf"
end end
rescue rescue
redirect_to :back, flash: { error: "Invoice not found" } redirect_to :back, flash: { error: I18n.t(:notice_invoice_not_found) }
end end
end end
end end

View File

@@ -13,6 +13,7 @@ module AuthHelper
def require_user def require_user
return unless session[:token].nil? return unless session[:token].nil?
if !User.current.logged? if !User.current.logged?
flash[:error] = t :notice_forbidden
render_403 render_403
end end
end end
@@ -27,6 +28,7 @@ module AuthHelper
def check_permission(permission) def check_permission(permission)
if !allowed_to?(permission) if !allowed_to?(permission)
flash[:error] = t :notice_forbidden
render_403 render_403
end end
end end
@@ -34,6 +36,7 @@ module AuthHelper
def global_check_permission(permission) def global_check_permission(permission)
if !globaly_allowed_to?(permission) if !globaly_allowed_to?(permission)
flash[:error] = t :notice_forbidden
render_403 render_403
end end
end end

View File

@@ -73,7 +73,7 @@ module QuickbooksOauth
oauth_consumer_secret = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret'] oauth_consumer_secret = Setting.plugin_redmine_qbo['settingsOAuthConsumerSecret']
# Are we are playing in the sandbox? # Are we are playing in the sandbox?
Quickbooks.sandbox_mode = Setting.plugin_redmine_qbo['sandbox'] ? true : false Quickbooks.sandbox_mode = Setting.plugin_redmine_qbo[:sandbox] ? true : false
logger.info "Sandbox mode: #{Quickbooks.sandbox_mode}" logger.info "Sandbox mode: #{Quickbooks.sandbox_mode}"
options = { options = {

View File

@@ -1,9 +1,9 @@
<%= link_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to "Customer Details", "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@customer.primary_phone}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank %> <%= button_to t(:label_appointment), "https://calendar.google.com/calendar/render?action=TEMPLATE&text=#{@customer.name}+-&details=#{ link_to t(:customer_details), "https://#{Setting.host_name}#{customer_path @customer.id}"}%0A#{@customer.primary_phone}&dates=#{Time.now.strftime("%Y%m%d")}T090000/#{Time.now.strftime("%Y%m%d")}T170000", target: :_blank, method: :get %>
<br/> <br/>
<br/> <br/>
<%= link_to t(:label_create_estimate), "https://qbo.intuit.com/app/estimate?nameId=#{@customer.id}", target: :_blank %> <%= button_to t(:label_create_estimate), "https://qbo.intuit.com/app/estimate?nameId=#{@customer.id}", target: :_blank, method: :get %>
<br/> <br/>
<br/> <br/>

View File

@@ -36,7 +36,7 @@
<%=t(:field_notes)%>: <%=t(:field_notes)%>:
<div class="input"> <div class="input">
<p> <p>
<%= content_tag 'span', id: "issue_description_and_toolbar" do %> <%= content_tag :span, id: "issue_description_and_toolbar" do %>
<%= f.text_area :notes, <%= f.text_area :notes,
cols: 60, cols: 60,
rows: 10, rows: 10,
@@ -45,7 +45,7 @@
no_label: true %> no_label: true %>
<% end %> <% end %>
</p> </p>
<%= wikitoolbar_for 'issue_description' %> <%= wikitoolbar_for :issue_description %>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,4 @@
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://#{Setting.plugin_redmine_qbo['sandbox'] ? "sandbox" : "app"}.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2> <h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://#{Setting.plugin_redmine_qbo[:sandbox] ? "sandbox" : "app"}.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}", target: :_blank %> </h2>
<div class="issue"> <div class="issue">
<div class="splitcontent"> <div class="splitcontent">
@@ -27,12 +27,12 @@
<div class="splitcontent"> <div class="splitcontent">
<div class="splitcontentleft"> <div class="splitcontentleft">
<h4><%=t(:estimates)%>:</h4> <h4><%=t(:estimates)%>:</h4>
<%= render partial: 'estimates/list', locals: {customer: @customer} %> <%= render partial: 'estimates/list', locals: {estimates: @customer.estimates} %>
</div> </div>
<div class="splitcontentleft"> <div class="splitcontentleft">
<h4><%=t(:label_invoices)%>:</h4> <h4><%=t(:label_invoices)%>:</h4>
<%= render partial: 'invoices/list', locals: {customer: @customer} %> <%= render partial: 'invoices/list', locals: {invoices: @customer.invoices} %>
</div> </div>
</div> </div>

View File

@@ -19,27 +19,27 @@
<div class="attributes"> <div class="attributes">
<%= issue_fields_rows do |rows| <%= issue_fields_rows do |rows|
rows.left l(:field_status), @issue.status.name, class: 'status' rows.left l(:field_status), @issue.status.name, class: :status
rows.left l(:field_priority), @issue.priority.name, class: 'priority' rows.left l(:field_priority), @issue.priority.name, class: :priority
# unless @issue.disabled_core_fields.include?('assigned_to_id') # unless @issue.disabled_core_fields.include?(:assigned_to_id)
# rows.left l(:field_assigned_to), avatar(@issue.assigned_to, size: "14").to_s.html_safe + (@issue.assigned_to ? @issue.assigned_to : "-"), class: 'assigned-to' # rows.left l(:field_assigned_to), avatar(@issue.assigned_to, size: "14").to_s.html_safe + (@issue.assigned_to ? @issue.assigned_to : "-"), class: 'assigned-to'
# end # end
unless @issue.disabled_core_fields.include?('category_id') || (@issue.category.nil? && @issue.project.issue_categories.none?) unless @issue.disabled_core_fields.include?(:category_id) || (@issue.category.nil? && @issue.project.issue_categories.none?)
rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), class: 'category' rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), class: :category
end end
unless @issue.disabled_core_fields.include?('fixed_version_id') || (@issue.fixed_version.nil? && @issue.assignable_versions.none?) unless @issue.disabled_core_fields.include?(:fixed_version_id) || (@issue.fixed_version.nil? && @issue.assignable_versions.none?)
rows.left l(:field_fixed_version), (@issue.fixed_version ? @issue.fixed_version : "-"), class: 'fixed-version' rows.left l(:field_fixed_version), (@issue.fixed_version ? @issue.fixed_version : "-"), class: 'fixed-version'
end end
unless @issue.disabled_core_fields.include?('start_date') unless @issue.disabled_core_fields.include?(:start_date)
rows.right l(:field_start_date), format_date(@issue.start_date), class: 'start-date' rows.right l(:field_start_date), format_date(@issue.start_date), class: 'start-date'
end end
unless @issue.disabled_core_fields.include?('due_date') unless @issue.disabled_core_fields.include?(:due_date)
rows.right l(:field_due_date), format_date(@issue.due_date), class: 'due-date' rows.right l(:field_due_date), format_date(@issue.due_date), class: 'due-date'
end end
unless @issue.disabled_core_fields.include?('done_ratio') unless @issue.disabled_core_fields.include?(:done_ratio)
rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, legend: "#{@issue.done_ratio}%"), class: 'progress' rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, legend: "#{@issue.done_ratio}%"), class: :progress
end end
unless @issue.disabled_core_fields.include?('estimated_hours') unless @issue.disabled_core_fields.include?(:estimated_hours)
if @issue.estimated_hours.present? || @issue.total_estimated_hours.to_f > 0 if @issue.estimated_hours.present? || @issue.total_estimated_hours.to_f > 0
rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), class: 'estimated-hours' rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), class: 'estimated-hours'
end end
@@ -59,7 +59,7 @@ end %>
<% if @issue.description? %> <% if @issue.description? %>
<div class="description"> <div class="description">
<div class="contextual"> <div class="contextual">
<%= link_to l(:button_quote), quoted_issue_path(@issue), remote: true, method: 'post', class: 'icon icon-comment' if @issue.notes_addable? %> <%= link_to l(:button_quote), quoted_issue_path(@issue), remote: true, method: :post, class: 'icon icon-comment' if @issue.notes_addable? %>
</div> </div>
<p><strong><%=l(:field_description)%></strong></p> <p><strong><%=l(:field_description)%></strong></p>

View File

@@ -1,6 +1,6 @@
<% if @customer.present? %> <% unless estimates.empty? %>
<% @customer.estimates.order(id: :desc).each do |estimate| %> <% estimates.sort.reverse.each do |estimate| %>
<div class="row"> <div class="row">
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %> <b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
</div> </div>

View File

@@ -1,24 +1,23 @@
<% if @customer.present? %> <% unless invoices.empty? %>
<%= form_with(url: invoice_path, method: :get) do |form| %> <%= form_with(url: invoice_path, method: :get) do |form| %>
<% if @customer.invoices.count > 1 %> <% if invoices.count > 1 %>
<div class="form-check"> <div class="form-check">
<%= check_box_tag "select-all-invoices", "1", false, id: "select-all-invoices" %> <%= check_box_tag "select-all-invoices", "1", false, id: "select-all-invoices" %>
<%= label_tag "select-all-invoices", t(:label_select_all) %> <%= label_tag "select-all-invoices", t(:label_select_all) %>
</div> </div>
<hr> <hr>
<% end %> <% end %>
<% @customer.invoices.order(id: :desc).each do |invoice| %> <% invoices.sort.reverse.each do |invoice| %>
<div class="row"> <div class="row">
<%= check_box_tag "invoice_ids[]", invoice.id, false, class: "invoice-checkbox" %> <%= check_box_tag "invoice_ids[]", invoice.id, false, class: "invoice-checkbox" if invoices.count > 1 %>
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %> <b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
</div> </div>
<% end %> <% end %>
<% if @customer.invoices.count > 1 %> <% if invoices.count > 1 %>
<%= form.submit t(:button_bulk_pdf) %> <%= form.submit t(:button_bulk_pdf) %>
<% end %> <% end %>
<% end %> <% end %>

View File

@@ -9,7 +9,7 @@
</tr></thead> </tr></thead>
<tbody> <tbody>
<% for issue in issues %> <% for issue in issues %>
<tr id="issue-<%= h(issue.id) %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %>"> <tr id="issue-<%= h(issue.id) %>" class="hascontextmenu <%= cycle(:odd, :even) %> <%= issue.css_classes %>">
<td class="id"> <td class="id">
<%= check_box_tag("ids[]", issue.id, false, style: 'display:none;', id: nil) %> <%= check_box_tag("ids[]", issue.id, false, style: 'display:none;', id: nil) %>
<%= link_to(issue.id, issue_path(issue)) %> <%= link_to(issue.id, issue_path(issue)) %>

View File

@@ -0,0 +1,3 @@
"<div id='footer' align='center'>
<b><%=I18n.translate(:label_last_sync)%>: </b> <%=Qbo.last_sync if Qbo.exists?%>
</div>"

View File

@@ -60,7 +60,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
<tr> <tr>
<th><%=t(:label_sandbox)%></th> <th><%=t(:label_sandbox)%></th>
<td> <td>
<%= check_box_tag 'settings[sandbox]', @settings['sandbox'], @settings['sandbox'] %> <%= check_box_tag 'settings[sandbox]', @settings[:sandbox], @settings[:sandbox] %>
</td> </td>
</tr> </tr>

View File

View File

@@ -85,4 +85,18 @@ en:
label_syncing: "Syncing Quickbooks" label_syncing: "Syncing Quickbooks"
label_sandbox: "Sandbox" label_sandbox: "Sandbox"
button_bulk_pdf: "Bulk PDF" button_bulk_pdf: "Bulk PDF"
label_select_all: "Select All" label_select_all: "Select All"
notice_customer_created: "Customer created in Quickbooks"
notice_customer_updated: "Customer updated in Quickbooks"
notice_customer_not_found: "Customer not found in Quickbooks"
notice_customer_not_deleted: "Customer could not be deleted in Quickbooks"
notice_customer_deleted: "Customer deleted in Quickbooks"
notice_estimate_created: "Estimate created in Quickbooks"
notice_estimate_updated: "Estimate updated in Quickbooks"
notice_estimate_not_found: "Estimate not found"
notice_invoice_created: "Invoice created in Quickbooks"
notice_invoice_updated: "Invoice updated in Quickbooks"
notice_invoice_not_found: "Invoice not found"
notice_forbidden: "You do not have permission to access this resource"
notice_issue_not_found: "Issue not found"
customer_details: "Customer Details"

18
init.rb
View File

@@ -13,19 +13,19 @@ Redmine::Plugin.register :redmine_qbo do
# About # About
name 'Redmine QBO plugin' name 'Redmine QBO plugin'
author 'Rick Barrette' 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' description 'A pluging for Redmine to connect with QuickBooks Online to create Time Activity Entries for billable hours logged when an Issue is closed'
version '2026.1.5' version '2026.1.9'
url 'https://github.com/rickbarrette/redmine_qbo' url 'https://github.com/rickbarrette/redmine_qbo'
author_url 'https://barrettefabrication.com' author_url 'https://barrettefabrication.com'
settings default: {'empty' => true}, partial: 'qbo/settings' settings default: {empty: true}, partial: 'qbo/settings'
requires_redmine version_or_higher: '6.1.0' requires_redmine version_or_higher: '6.1.0'
# Add safe attributes for core models # Add safe attributes for core models
Issue.safe_attributes 'customer_id' Issue.safe_attributes :customer_id
Issue.safe_attributes 'estimate_id' Issue.safe_attributes :estimate_id
Issue.safe_attributes 'invoice_id' Issue.safe_attributes :invoice_id
User.safe_attributes 'employee_id' User.safe_attributes :employee_id
TimeEntry.safe_attributes 'billed' TimeEntry.safe_attributes :billed
# set per_page globally # set per_page globally
WillPaginate.per_page = 20 WillPaginate.per_page = 20
@@ -35,7 +35,7 @@ Redmine::Plugin.register :redmine_qbo do
permission :add_customers, customers: :new, public: false permission :add_customers, customers: :new, public: false
# Register top menu items # Register top menu items
menu :top_menu, :customers, { controller: :customers, action: :index }, caption: 'Customers', if: Proc.new {User.current.logged?} menu :top_menu, :customers, { controller: :customers, action: :index }, caption: :label_customers, if: Proc.new {User.current.logged?}
end end

View File

@@ -1,19 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 Hooks
class HeaderFooterHookListener < Redmine::Hook::ViewListener
def view_layouts_base_body_bottom(context = {})
return "<div id='footer' align='center'><b>#{I18n.translate(:label_last_sync)}: </b> #{Qbo.last_sync if Qbo.exists?}</div>"
end
end
end

View File

@@ -39,7 +39,7 @@ module Hooks
# Generate the drop down list of quickbooks estimates owned by the selected customer # Generate the drop down list of quickbooks estimates owned by the selected customer
select_estimate = f.select :estimate_id, select_estimate = f.select :estimate_id,
issue.customer ? issue.customer.estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x} : [], issue.customer ? issue.customer.estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x} : [],
selected: issue.estimate, selected: issue.estimate ? issue.estimate.id : nil,
include_blank: true include_blank: true
# Pass all prebuilt form components to our partial # Pass all prebuilt form components to our partial

View File

@@ -1,36 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 Hooks
class IssuesSaveHookListener < Redmine::Hook::ViewListener
# Called Before Issue Saved
def controller_issues_edit_before_save(context={})
return context[:issue].subject = context[:issue].subject.titleize
end
def controller_issues_new_before_save(context={})
return context[:issue].subject = context[:issue].subject.titleize
end
# Called After Issue Saved
def controller_issues_edit_after_save(context={})
issue = context[:issue]
begin
issue.bill_time if issue.status.is_closed?
rescue
# TODO flash[:error] = "Unable to bill, check QBO Auth"
end
end
end
end

View File

@@ -28,7 +28,7 @@ module Hooks
context[:controller].send(:render_to_string, { context[:controller].send(:render_to_string, {
partial: 'issues/show_details', partial: 'issues/show_details',
locals: { locals: {
customer: issue.customer ? link_to(issue.customer): nill, customer: issue.customer ? link_to(issue.customer) : nil,
estimate_link: issue.estimate ? link_to(issue.estimate, issue.estimate, target: :_blank) : nil, estimate_link: issue.estimate ? link_to(issue.estimate, issue.estimate, target: :_blank) : nil,
invoice_link: invoice_link.html_safe, invoice_link: invoice_link.html_safe,
issue: issue issue: issue

View File

@@ -12,8 +12,16 @@ module Hooks
class ViewHookListener < Redmine::Hook::ViewListener class ViewHookListener < Redmine::Hook::ViewListener
# Load the javascript to support the autocomplete forms
def view_layouts_base_html_head(context = {})
js = javascript_include_tag 'application.js', plugin: :redmine_qbo
js += javascript_include_tag 'autocomplete-rails.js', plugin: :redmine_qbo
js += javascript_include_tag 'checkbox_controller.js', plugin: :redmine_qbo
return js
end
render_on :view_layouts_base_sidebar, partial: "qbo/sidebar" render_on :view_layouts_base_sidebar, partial: "qbo/sidebar"
render_on :view_layouts_base_body_bottom, partial: "qbo/footer"
end end
end end

View File

@@ -1,25 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 Hooks
class ViewLayoutsHookListener < Redmine::Hook::ViewListener
# Load the javascript to support the autocomplete forms
def view_layouts_base_html_head(context = {})
js = javascript_include_tag 'application.js', plugin: 'redmine_qbo'
js += javascript_include_tag 'autocomplete-rails.js', plugin: 'redmine_qbo'
js += javascript_include_tag 'checkbox_controller.js', plugin: 'redmine_qbo'
return js
end
end
end

View File

@@ -12,9 +12,9 @@ require_dependency 'issue'
module Patches module Patches
# Patches Redmine's Issues dynamically. # Patches Redmine's Issues dynamically.
# Adds a relationships # Adds relationships for customers, estimates, invoices, customer_tokens
# Adds before and after save hooks
module IssuePatch module IssuePatch
def self.included(base) # :nodoc: def self.included(base) # :nodoc:
@@ -28,6 +28,8 @@ module Patches
belongs_to :customer_token, primary_key: :id belongs_to :customer_token, primary_key: :id
belongs_to :estimate, primary_key: :id belongs_to :estimate, primary_key: :id
has_and_belongs_to_many :invoices has_and_belongs_to_many :invoices
before_save :titlize_subject
after_save :bill_time
end end
end end
@@ -40,61 +42,62 @@ module Patches
# Create billable time entries # Create billable time entries
def bill_time def bill_time
logger.debug "QBO: Billing time for issue ##{id} - #{subject}"
# Check to see if we have everything we need to bill the customer return unless status.is_closed?
return if assigned_to.nil? return if assigned_to.nil?
return unless Qbo.first return unless Qbo.first
return unless customer return unless customer
# Get unbilled time entries Thread.new do
spent_time = time_entries.where(billed: [false, nil]) spent_time = time_entries.where(billed: [false, nil])
spent_hours ||= spent_time.sum(:hours) || 0 spent_hours ||= spent_time.sum(:hours) || 0
if spent_hours > 0 then
# Prepare to create a new Time Activity if spent_hours > 0 then
qbo = Qbo.first
qbo.perform_authenticated_request do |access_token|
time_service = Quickbooks::Service::TimeActivity.new(company_id: qbo.realm_id, access_token: access_token)
item_service = Quickbooks::Service::Item.new(company_id: qbo.realm_id, access_token: access_token)
time_entry = Quickbooks::Model::TimeActivity.new
# Lets total up each activity before billing.
# This will simpify the invoicing with a single billable time entry per time activity
h = Hash.new(0)
spent_time.each do |entry|
h[entry.activity.name] += entry.hours
# update time entries billed status
entry.billed = true
entry.save
end
# Now letes upload our totals for each activity as their own billable time entry # Prepare to create a new Time Activity
h.each do |key, val| qbo = Qbo.first
qbo.perform_authenticated_request do |access_token|
time_service = Quickbooks::Service::TimeActivity.new(company_id: qbo.realm_id, access_token: access_token)
item_service = Quickbooks::Service::Item.new(company_id: qbo.realm_id, access_token: access_token)
time_entry = Quickbooks::Model::TimeActivity.new
# Lets total up each activity before billing.
# This will simpify the invoicing with a single billable time entry per time activity
h = Hash.new(0)
spent_time.each do |entry|
h[entry.activity.name] += entry.hours
# update time entries billed status
entry.billed = true
entry.save
end
# Convert float spent time to hours and minutes # Now letes upload our totals for each activity as their own billable time entry
hours = val.to_i h.each do |key, val|
minutesDecimal = (( val - hours) * 60)
minutes = minutesDecimal.to_i # Convert float spent time to hours and minutes
hours = val.to_i
minutesDecimal = (( val - hours) * 60)
minutes = minutesDecimal.to_i
# Lets match the activity to an qbo item # Lets match the activity to an qbo item
item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first item = item_service.query("SELECT * FROM Item WHERE Name = '#{key}' ").first
next if item.nil? next if item.nil?
# Create the new billable time entry and upload it # Create the new billable time entry and upload it
time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}" time_entry.description = "#{tracker} ##{id}: #{subject} #{"(Partial @ #{done_ratio}%)" if not closed?}"
time_entry.employee_id = assigned_to.employee_id time_entry.employee_id = assigned_to.employee_id
time_entry.customer_id = customer_id time_entry.customer_id = customer_id
time_entry.billable_status = "Billable" time_entry.billable_status = "Billable"
time_entry.hours = hours time_entry.hours = hours
time_entry.minutes = minutes time_entry.minutes = minutes
time_entry.name_of = "Employee" time_entry.name_of = "Employee"
time_entry.txn_date = Date.today time_entry.txn_date = Date.today
time_entry.hourly_rate = item.unit_price time_entry.hourly_rate = item.unit_price
time_entry.item_id = item.id time_entry.item_id = item.id
time_entry.start_time = start_date time_entry.start_time = start_date
time_entry.end_time = Time.now time_entry.end_time = Time.now
time_service.create(time_entry) time_service.create(time_entry)
end
end end
end end
end end
@@ -106,6 +109,11 @@ module Patches
CustomerToken.get_token self CustomerToken.get_token self
end end
# Titleize the subject before save
def titlize_subject
self.subject = self.subject.titleize
end
end end
# Add module to Issue # Add module to Issue

View File

@@ -54,9 +54,9 @@ module Patches
left << [l(:field_status), issue.status] left << [l(:field_status), issue.status]
left << [l(:field_priority), issue.priority] left << [l(:field_priority), issue.priority]
left << [l(:field_customer), customer] left << [l(:field_customer), customer]
left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id') 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_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') #left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?(:fixed_version_id)
logger.debug "Calling :pdf_left hook" logger.debug "Calling :pdf_left hook"
left_hook_output = Redmine::Hook.call_hook :pdf_left, { issue: issue } left_hook_output = Redmine::Hook.call_hook :pdf_left, { issue: issue }
@@ -67,10 +67,10 @@ module Patches
end end
right = [] right = []
right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date') 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_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_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(: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(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
logger.debug "Calling :pdf_right hook" logger.debug "Calling :pdf_right hook"

View File

View File

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

View File

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

View File

@@ -1,18 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 File.expand_path('../../test_helper', __FILE__)
class QboControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

View File

@@ -1,2 +0,0 @@
# Load the Redmine helper
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')

View File

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

View File

@@ -1,19 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 File.expand_path('../../test_helper', __FILE__)
class QboCustomersTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end

View File

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

View File

@@ -1,19 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 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 File.expand_path('../../test_helper', __FILE__)
class QboTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end