Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4229426621 | ||
|
|
e76bd12b7f | ||
|
|
9501216525 | ||
|
|
73e643a6f9 |
No files matched your search
@@ -28,7 +28,7 @@ Returns, canceled orders and refunded deposits are deducted from the month's sal
|
|||||||
|
|
||||||
Once the month is over, **Approve for payroll** reads QuickBooks one last time. It records the sales, deductions, threshold, rates and payouts, so the month no longer changes with QuickBooks or the settings. **Payroll CSV** downloads each rep's payout. **Reopen** puts an approved month back to being worked out from QuickBooks; the unticked items, adjustments and notes are kept.
|
Once the month is over, **Approve for payroll** reads QuickBooks one last time. It records the sales, deductions, threshold, rates and payouts, so the month no longer changes with QuickBooks or the settings. **Payroll CSV** downloads each rep's payout. **Reopen** puts an approved month back to being worked out from QuickBooks; the unticked items, adjustments and notes are kept.
|
||||||
|
|
||||||
Approvers see each transaction linked to QuickBooks, and the list of months with the month picker.
|
Approvers see each invoice linked to its page in Redmine (or its PDF without the Write invoices permission), each sales receipt, refund receipt and credit memo linked to QuickBooks' PDF of it (opened through Redmine, without signing in to QuickBooks), and the list of months with the month picker.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class SalesCommissionsController < ApplicationController
|
|||||||
menu_item :sales_commissions
|
menu_item :sales_commissions
|
||||||
|
|
||||||
before_action :authorize_global
|
before_action :authorize_global
|
||||||
before_action :find_month, except: [:index, :current]
|
before_action :find_month, except: [:index, :current, :txn_pdf]
|
||||||
before_action :find_open_record, only: [:update, :add_adjustment, :remove_adjustment]
|
before_action :find_open_record, only: [:update, :add_adjustment, :remove_adjustment]
|
||||||
|
|
||||||
helper :sales_commissions
|
helper :sales_commissions
|
||||||
@@ -120,6 +120,19 @@ class SalesCommissionsController < ApplicationController
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# QuickBooks' PDF of a sales receipt, refund receipt or credit memo, shown in the browser
|
||||||
|
def txn_pdf
|
||||||
|
pdf = RedmineQboCommission::Txn.pdf(params[:kind], params[:txn_id])
|
||||||
|
send_data pdf, type: 'application/pdf', disposition: 'inline',
|
||||||
|
filename: "#{params[:kind].to_s.dasherize}-#{params[:txn_id].to_i}.pdf"
|
||||||
|
rescue KeyError
|
||||||
|
render_404
|
||||||
|
rescue StandardError => e
|
||||||
|
Rails.logger.error "[redmine_qbo_commission] PDF of #{params[:kind]} #{params[:txn_id]}: #{e.message}"
|
||||||
|
flash[:error] = l(:error_sales_commission_qbo, error: e.message)
|
||||||
|
redirect_back_or_default sales_commissions_path
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_month
|
def find_month
|
||||||
|
|||||||
@@ -17,10 +17,18 @@ module SalesCommissionsHelper
|
|||||||
RedmineQboCommission.format_rate(rate)
|
RedmineQboCommission.format_rate(rate)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The transaction's number, linked to it in QuickBooks for those who approve
|
# The transaction's number, linked for those who approve: an invoice opens its page in Redmine (or its PDF
|
||||||
|
# without the Write invoices permission); a sales receipt, refund receipt or credit memo, which Redmine has no
|
||||||
|
# page for, opens QuickBooks' PDF of it
|
||||||
def commission_txn_link(txn, can_approve)
|
def commission_txn_link(txn, can_approve)
|
||||||
label = txn.doc_number.present? ? "##{txn.doc_number}" : txn.kind_name
|
label = txn.doc_number.present? ? "##{txn.doc_number}" : txn.kind_name
|
||||||
can_approve ? link_to(label, txn.qbo_url, target: '_blank', rel: 'noopener') : label
|
return label unless can_approve
|
||||||
|
|
||||||
|
if txn.kind == 'invoice'
|
||||||
|
link_to(label, RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(txn.txn_id) : invoice_path(txn.txn_id))
|
||||||
|
else
|
||||||
|
link_to(label, sales_commission_txn_pdf_path(txn.kind, txn.txn_id), target: '_blank', rel: 'noopener')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# "Approved by Jane Smith on 12/03/2026 09:15 AM"
|
# "Approved by Jane Smith on 12/03/2026 09:15 AM"
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ RedmineApp::Application.routes.draw do
|
|||||||
delete 'sales_commission/:month/adjustments/:id', to: 'sales_commissions#remove_adjustment',
|
delete 'sales_commission/:month/adjustments/:id', to: 'sales_commissions#remove_adjustment',
|
||||||
as: :sales_commission_adjustment, constraints: month
|
as: :sales_commission_adjustment, constraints: month
|
||||||
|
|
||||||
|
# QuickBooks' PDF of a sales receipt, refund receipt or credit memo (e.g. /sales_commission/pdf/credit_memo/123)
|
||||||
|
get 'sales_commission/pdf/:kind/:txn_id', to: 'sales_commissions#txn_pdf', as: :sales_commission_txn_pdf,
|
||||||
|
constraints: { kind: /sales_receipt|refund_receipt|credit_memo/, txn_id: /\d+/ }
|
||||||
|
|
||||||
# Administration » Commission reps
|
# Administration » Commission reps
|
||||||
resources :commission_reps, except: [:show]
|
resources :commission_reps, except: [:show]
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ Redmine::Plugin.register :redmine_qbo_commission do
|
|||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'Monthly sales commission (SOP-OPS-013): totals the month\'s paid sales from QuickBooks Online, ' \
|
description 'Monthly sales commission (SOP-OPS-013): totals the month\'s paid sales from QuickBooks Online, ' \
|
||||||
'works out the commission pool, and records each sales rep\'s payout for payroll'
|
'works out the commission pool, and records each sales rep\'s payout for payroll'
|
||||||
version '2026.11.0'
|
version '2026.11.2'
|
||||||
url 'https://gitea.rickbarrette.org/ricky/redmine_qbo_commission'
|
url 'https://gitea.rickbarrette.org/ricky/redmine_qbo_commission'
|
||||||
author_url 'https://barrettefabrication.com'
|
author_url 'https://barrettefabrication.com'
|
||||||
requires_redmine version_or_higher: '7.0.0'
|
requires_redmine version_or_higher: '7.0.0'
|
||||||
@@ -34,7 +34,7 @@ Redmine::Plugin.register :redmine_qbo_commission do
|
|||||||
# The months, adjusting and approving a month for payroll, reopening it, the payroll CSV
|
# The months, adjusting and approving a month for payroll, reopening it, the payroll CSV
|
||||||
permission :approve_sales_commission,
|
permission :approve_sales_commission,
|
||||||
{ sales_commissions: [:index, :current, :show, :update, :refresh, :reopen,
|
{ sales_commissions: [:index, :current, :show, :update, :refresh, :reopen,
|
||||||
:add_adjustment, :remove_adjustment] },
|
:add_adjustment, :remove_adjustment, :txn_pdf] },
|
||||||
global: true
|
global: true
|
||||||
|
|
||||||
menu :top_menu, :sales_commissions, { controller: 'sales_commissions', action: 'current' },
|
menu :top_menu, :sales_commissions, { controller: 'sales_commissions', action: 'current' },
|
||||||
|
|||||||
@@ -50,12 +50,18 @@ module RedmineQboCommission
|
|||||||
I18n.t("label_sales_commission_kind_#{kind}")
|
I18n.t("label_sales_commission_kind_#{kind}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# The transaction's page in QuickBooks
|
# The QuickBooks services that print the transactions Redmine has no page for
|
||||||
def qbo_url
|
PDF_SERVICES = { 'sales_receipt' => 'SalesReceipt', 'refund_receipt' => 'RefundReceipt',
|
||||||
host = defined?(RedmineQbo) && RedmineQbo.respond_to?(:sandbox_mode?) && RedmineQbo.sandbox_mode? ? 'sandbox' : 'app'
|
'credit_memo' => 'CreditMemo' }.freeze
|
||||||
page = { 'invoice' => 'invoice', 'sales_receipt' => 'salesreceipt', 'refund_receipt' => 'refundreceipt',
|
|
||||||
'credit_memo' => 'creditmemo' }[kind]
|
# QuickBooks' PDF of a sales receipt, refund receipt or credit memo (an invoice opens in Redmine instead)
|
||||||
"https://#{host}.qbo.intuit.com/app/#{page}?txnId=#{txn_id}"
|
def self.pdf(kind, txn_id)
|
||||||
|
entity = PDF_SERVICES.fetch(kind.to_s)
|
||||||
|
qbo = QboConnectionService.current!
|
||||||
|
qbo.perform_authenticated_request do |access_token|
|
||||||
|
service = "Quickbooks::Service::#{entity}".constantize.new(company_id: qbo.realm_id, access_token: access_token)
|
||||||
|
service.pdf(Struct.new(:id).new(txn_id.to_s))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -57,6 +57,10 @@ class SalesCommissionsTest < Redmine::IntegrationTest
|
|||||||
assert_select 'input[name=?][value=?][checked]', 'included[]', 'refund_receipt:3'
|
assert_select 'input[name=?][value=?][checked]', 'included[]', 'refund_receipt:3'
|
||||||
assert_select 'input[name=?][value="2"][checked]', 'eligible[]'
|
assert_select 'input[name=?][value="2"][checked]', 'eligible[]'
|
||||||
assert_select 'input[name=approve]'
|
assert_select 'input[name=approve]'
|
||||||
|
# Invoices open in Redmine, the refund receipt (no Redmine page) as QuickBooks' PDF through Redmine
|
||||||
|
assert_select '#sales-commission-sales a[href=?]', '/qbo_invoices/1/edit'
|
||||||
|
assert_select '#sales-commission-deductions a[href=?]', '/sales_commission/pdf/refund_receipt/3'
|
||||||
|
assert_select 'a[href*="qbo.intuit.com"]', count: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_view_only
|
def test_view_only
|
||||||
@@ -177,4 +181,22 @@ class SalesCommissionsTest < Redmine::IntegrationTest
|
|||||||
post '/sales_commission/2026-10/refresh'
|
post '/sales_commission/2026-10/refresh'
|
||||||
assert_redirected_to '/sales_commission/2026-10'
|
assert_redirected_to '/sales_commission/2026-10'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_txn_pdf
|
||||||
|
RedmineQboCommission::Txn.expects(:pdf).with('credit_memo', '123').returns('%PDF-1.4 credit memo')
|
||||||
|
log_user('admin', 'admin')
|
||||||
|
get '/sales_commission/pdf/credit_memo/123'
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'application/pdf', response.media_type
|
||||||
|
assert_equal '%PDF-1.4 credit memo', response.body
|
||||||
|
get '/sales_commission/pdf/invoice/123'
|
||||||
|
assert_response :not_found
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_txn_pdf_needs_approve
|
||||||
|
Role.find(1).add_permission!(:view_sales_commission)
|
||||||
|
log_user('jsmith', 'jsmith')
|
||||||
|
get '/sales_commission/pdf/sales_receipt/5'
|
||||||
|
assert_response :forbidden
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user