mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-19 10:40:36 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88160a985d | ||
|
|
e2a871b1e8 | ||
|
|
489edd97fa | ||
|
|
64e4a149ab | ||
|
|
6a638fe7bb | ||
|
|
51159d5034 | ||
|
|
8f2cef2bc8 | ||
|
|
bd29ec2978 | ||
|
|
b1ad2d5b40 | ||
|
|
03af3457ab | ||
|
|
0d35cffb83 |
No files matched your search
@@ -3,7 +3,6 @@ source 'https://rubygems.org'
|
|||||||
gem 'quickbooks-ruby'
|
gem 'quickbooks-ruby'
|
||||||
gem 'oauth2'
|
gem 'oauth2'
|
||||||
gem 'roxml'
|
gem 'roxml'
|
||||||
gem 'will_paginate'
|
|
||||||
gem 'rexml'
|
gem 'rexml'
|
||||||
gem 'combine_pdf'
|
gem 'combine_pdf'
|
||||||
|
|
||||||
|
|||||||
@@ -69,8 +69,10 @@ This ensures Time Activities are recorded under the correct employee in QuickBoo
|
|||||||
The plugin provides basic Customer management:
|
The plugin provides basic Customer management:
|
||||||
|
|
||||||
* Create Customers directly from Redmine
|
* Create Customers directly from Redmine
|
||||||
|
|
||||||
|
* Browse every Customer on the **Customers** page: a Redmine list with phone numbers, issue counts and last update, sortable by column and paged with Redmine's own pagination (and its per-page choices)
|
||||||
|
|
||||||
* Search Customers by **name or phone number**
|
* Search Customers by **name or phone number**: the best matches come first (click a column to sort them instead), and a single match opens that Customer
|
||||||
|
|
||||||
* View and edit Customer information
|
* View and edit Customer information
|
||||||
|
|
||||||
@@ -101,7 +103,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
## Billing: Estimates, Invoices and Payments
|
## Billing: Estimates, Invoices and Payments
|
||||||
|
|
||||||
* **New estimate** from the customer page: Create Estimate opens the Redmine editor. The customer page no longer links to QuickBooks' estimate or payment screens; the customer's name still opens their QuickBooks account page as a fallback.
|
* **New estimate** from the customer page: Create Estimate opens the Redmine editor. The customer page no longer links to QuickBooks' estimate or payment screens; **Open in QuickBooks** opens their QuickBooks account page as a fallback.
|
||||||
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
* **Edit** any estimate from the Edit link next to it on the customer page or the issue page.
|
||||||
* **Keyboard entry**: in a line's product box, Tab picks the product the text points to (an exact name, the only match, or the only name starting with it, e.g. "lab" → Labor) and fills the line. Tabbing into the description, quantity or rate selects it, so typing replaces it. The quantity, rate and amount boxes take simple math (e.g. `33*1.3`, `(120+15)/2`; `+ - * /`, `x` for times, parentheses), worked out when you leave the box; math in the rate or amount is rounded to the nearest penny, and an amount sets the rate from the quantity. Typing `sub`, `subtotal` or `=` in a product box, then Tab or Enter, adds a subtotal there (an empty line becomes the subtotal; a line with a description keeps it and gets the subtotal after it) and moves on to the next line.
|
* **Keyboard entry**: in a line's product box, Tab picks the product the text points to (an exact name, the only match, or the only name starting with it, e.g. "lab" → Labor) and fills the line. Tabbing into the description, quantity or rate selects it, so typing replaces it. The quantity, rate and amount boxes take simple math (e.g. `33*1.3`, `(120+15)/2`; `+ - * /`, `x` for times, parentheses), worked out when you leave the box; math in the rate or amount is rounded to the nearest penny, and an amount sets the rate from the quantity. Typing `sub`, `subtotal` or `=` in a product box, then Tab or Enter, adds a subtotal there (an empty line becomes the subtotal; a line with a description keeps it and gets the subtotal after it) and moves on to the next line.
|
||||||
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, custom fields and messages, dated today, with the current user as sales person.
|
* **Duplicate** an estimate to start a similar one: same customer, lines, subtotals, custom fields and messages, dated today, with the current user as sales person.
|
||||||
@@ -119,13 +121,14 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, custom fields), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
* **Create invoice** on an estimate's page makes an invoice from it (customer, lines, subtotals, custom fields), like QuickBooks' "Create invoice". **Create invoice** on the customer page starts a blank one, and the Edit link next to each invoice on the customer page opens it.
|
||||||
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
* **Import time & estimates** lists the customer's billable QuickBooks time (the time activities redmine_qbo makes from an issue's time entries) and their open estimates (e.g. the ones redmine_qbo_lineitems makes for parts that weren't quoted).
|
||||||
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). Only lines with one of the **labor products/services** from the plugin settings are offered there. The time goes where the first ticked line was and the ticked lines are removed, so the invoice reads in the same order.
|
* Tick the time to bill and, under **Replace these lines**, the lines it replaces (e.g. the estimate's labor lines). Only lines with one of the **labor products/services** from the plugin settings are offered there. Each time entry takes the place of one ticked line: the one whose description is its issue's subject (issues created from an estimate are named after the line, so "Install #134: Install Lift Kit" replaces the "Install Lift Kit" line), then any others in order. Extra time goes after the last replaced line and extra ticked lines are removed, so the invoice keeps the estimate's order and subtotals.
|
||||||
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
* Ticked estimates go right after the time for the same issue: a redmine_qbo_lineitems estimate starting "Added from: Install #116: …" lands after the time for #116, without that note line, since the time line already names the issue. Estimates with no matching time keep the note and go at the end.
|
||||||
* **Undo import** puts the lines back until the invoice is saved.
|
* **Undo import** puts the lines back until the invoice is saved.
|
||||||
* **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save.
|
* **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save.
|
||||||
* Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved.
|
* Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved.
|
||||||
* **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed.
|
* **Custom fields from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. Plugins can fill custom fields from them when they're imported, and block a save (e.g. redmine_qbo_vehicles fills the VIN and mileage and allows one vehicle per invoice). On its own, redmine_qbo leaves the boxes as typed.
|
||||||
* **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice.
|
* **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice.
|
||||||
|
* Invoices show their status, worked out from the balance and due date like QuickBooks' invoice list: **Paid**, **Partially paid**, **Overdue**, **Open** or **Voided** (a zero total), on the customer page's invoice list and the invoice page.
|
||||||
* Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message.
|
* Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message.
|
||||||
|
|
||||||
### Payments
|
### Payments
|
||||||
@@ -139,11 +142,13 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
|
|||||||
|
|
||||||
### Business report
|
### Business report
|
||||||
|
|
||||||
**Business report** in the top menu compares, for a period (this or last month, quarter or year, or custom dates):
|
**Business report** in the top menu compares, for a period (this or last week, month, quarter or year, or custom dates; weeks start on the day set in Redmine's *Start calendars on* setting, Monday when it follows the language):
|
||||||
|
|
||||||
* **Sales**: estimates written, invoices written and payments received (totals and counts), invoiced vs. estimated, collected vs. invoiced, and what's still owed on those invoices.
|
* **Sales**: estimates written, invoices written and payments received (totals and counts), invoiced vs. estimated, collected vs. invoiced, and what's still owed on those invoices.
|
||||||
* **Hours**: estimated hours on estimates, issues' estimated time, invoiced hours on invoices and time spent, with invoiced vs. spent and spent vs. estimated.
|
* **Hours**: estimated hours on estimates, issues' estimated time, invoiced hours on invoices and time spent, with spent vs. estimated, and the **cost performance index** (CPI = invoiced hours ÷ spent hours): green at 1.00 or more, yellow below 1, red below 0.80. Each month shows its CPI too.
|
||||||
|
* **Charts**: above each set of bars, a line chart of the same figures in the same colors (Chart.js 4.5.1, MIT licensed, bundled with the plugin in assets/javascripts so it doesn't clash with other plugins' copies such as redmine_indicator's Chart.js 2), with a point per day for a week, per week for up to about three months, and per month beyond. Hovering a point shows its figures. **Compare with last year** adds last year's lines, dashed and faded, without reloading: days and weeks go back 52 weeks so weekdays line up, months go back to the same month. Clicking a figure in the legend hides it (and its last-year line); clicking *last year* stops comparing. Today's line stops at today.
|
||||||
* **By month**: every figure month by month, with totals.
|
* **By month**: every figure month by month, with totals.
|
||||||
|
* **Projects**: pick one or more open projects (Ctrl/Cmd-click; closed and archived projects aren't listed) to count only their issues' estimated time and spent time, in the totals, charts and months; none picked counts every project. Estimates, invoices and payments have no project in QuickBooks, so they always cover the whole business (as do the CPI's invoiced hours). **Remember these projects** saves the choice in your Redmine preferences, and the report opens with it until you save another (saving none goes back to every project).
|
||||||
|
|
||||||
Estimates, invoices and payments count by their QuickBooks date. Issues' estimated time counts issues created in the period, leaving out parents so subtasks aren't counted twice. Spent time counts time logged in the period. While estimates, invoices or payments are syncing, the report says so (with how many have been read) and refreshes every 30 seconds; the settings page's Synchronization table shows the same per type. Estimates and invoices synced before these figures were added have no total or hours until a full sync (the report says how many); run one again after changing the labor products/services.
|
Estimates, invoices and payments count by their QuickBooks date. Issues' estimated time counts issues created in the period, leaving out parents so subtasks aren't counted twice. Spent time counts time logged in the period. While estimates, invoices or payments are syncing, the report says so (with how many have been read) and refreshes every 30 seconds; the settings page's Synchronization table shows the same per type. Estimates and invoices synced before these figures were added have no total or hours until a full sync (the report says how many); run one again after changing the labor products/services.
|
||||||
|
|
||||||
@@ -213,7 +218,7 @@ Available hooks:
|
|||||||
|
|
||||||
|Type|Hook|Note
|
|Type|Hook|Note
|
||||||
|--|--|--|
|
|--|--|--|
|
||||||
View Hook|:view_customers_show_contextual, { customer: @customer } | Used to add action links to the customer page's top-right action area (return links styled like Redmine's, e.g. `link_to sprite_icon('add', 'Label'), path, class: 'icon icon-add'`). Replaces `customer_actions_top` / `customer_actions_bottom`
|
View Hook|:view_customers_show_contextual, { customer: @customer } | Used to add action links to the customer page's action area, under the title (return links styled like Redmine's, e.g. `link_to sprite_icon('add', 'Label'), path, class: 'icon icon-add'`). Replaces `customer_actions_top` / `customer_actions_bottom`
|
||||||
View Hook|:pdf_left, { issue: issue } | Used to add text to left side of PDF
|
View Hook|:pdf_left, { issue: issue } | Used to add text to left side of PDF
|
||||||
View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF
|
View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF
|
||||||
View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view
|
View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view
|
||||||
|
|||||||
@@ -117,13 +117,33 @@ class CustomersController < ApplicationController
|
|||||||
@filtered_invoices = Invoice.all.where(customer_id: params[:selected_customer])
|
@filtered_invoices = Invoice.all.where(customer_id: params[:selected_customer])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Most matches a search lists (best first)
|
||||||
|
SEARCH_LIMIT = 200
|
||||||
|
|
||||||
|
# Every customer, sortable and paged like Redmine's lists; a search narrows it to the best matches (a single
|
||||||
|
# match opens that customer). Sorting a search's results by a column replaces the best-first order.
|
||||||
def index
|
def index
|
||||||
if params[:search]
|
sort_init 'name', 'asc'
|
||||||
@customers = CustomerSearchService.call(name: params[:search], limit: 200).paginate(page: params[:page])
|
sort_update 'name' => "#{Customer.table_name}.name",
|
||||||
if only_one_non_zero?(@customers)
|
'phone' => "#{Customer.table_name}.phone_number",
|
||||||
redirect_to @customers.first
|
'mobile' => "#{Customer.table_name}.mobile_phone_number",
|
||||||
end
|
'updated' => "#{Customer.table_name}.updated_at"
|
||||||
|
|
||||||
|
@search = params[:search].to_s.strip
|
||||||
|
if @search.present?
|
||||||
|
scope = CustomerSearchService.call(name: @search, limit: SEARCH_LIMIT)
|
||||||
|
@best_first = params[:sort].blank?
|
||||||
|
else
|
||||||
|
scope = Customer.all
|
||||||
end
|
end
|
||||||
|
scope = scope.reorder(sort_clause).order(:id) unless @best_first
|
||||||
|
|
||||||
|
@customer_count = scope.count
|
||||||
|
return redirect_to(scope.first) if @search.present? && @customer_count == 1
|
||||||
|
|
||||||
|
@customer_pages = Paginator.new @customer_count, per_page_option, params['page']
|
||||||
|
@customers = scope.limit(@customer_pages.per_page).offset(@customer_pages.offset).to_a
|
||||||
|
@issue_counts = Issue.where(customer_id: @customers.map(&:id)).group(:customer_id).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_issue_data
|
def load_issue_data
|
||||||
@@ -157,17 +177,6 @@ class CustomersController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def only_one_non_zero?(array)
|
|
||||||
found_non_zero = false
|
|
||||||
array.each do |val|
|
|
||||||
if val != 0
|
|
||||||
return false if found_non_zero
|
|
||||||
found_non_zero = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
found_non_zero
|
|
||||||
end
|
|
||||||
|
|
||||||
def share
|
def share
|
||||||
issue = Issue.visible.find(params[:id])
|
issue = Issue.visible.find(params[:id])
|
||||||
token = issue.share_token
|
token = issue.share_token
|
||||||
|
|||||||
@@ -15,10 +15,48 @@ class QboReportsController < ApplicationController
|
|||||||
|
|
||||||
before_action :authorize_global
|
before_action :authorize_global
|
||||||
|
|
||||||
|
# The user's preference holding the projects the report opens with
|
||||||
|
PROJECTS_PREF = :qbo_report_project_ids
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
# Projects for the issues and spent time: the projects picker can choose some of the open ones
|
||||||
|
@projects = Project.visible.active.to_a
|
||||||
|
@project_ids = report_project_ids
|
||||||
@report = RedmineQboBilling::BusinessReport.new(period: params[:period].presence || 'this_year',
|
@report = RedmineQboBilling::BusinessReport.new(period: params[:period].presence || 'this_year',
|
||||||
from: params[:from], to: params[:to], today: User.current.today)
|
from: params[:from], to: params[:to], today: User.current.today,
|
||||||
|
week_start: RedmineQboBilling::BusinessReport.week_start_from_setting(Setting.start_of_week),
|
||||||
|
project_ids: @project_ids)
|
||||||
|
# Last year's lines on the charts
|
||||||
|
@compare = params[:compare] == '1'
|
||||||
# Syncs still running for what the report counts: its figures are incomplete until they finish
|
# Syncs still running for what the report counts: its figures are incomplete until they finish
|
||||||
@syncing = QboSyncStatus.by_entity(%w[Estimate Invoice Payment]).values.sort_by(&:entity)
|
@syncing = QboSyncStatus.by_entity(%w[Estimate Invoice Payment]).values.sort_by(&:entity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# The form's projects (none picked is every project), or the user's saved ones when the address has none.
|
||||||
|
# "Remember these projects" saves the form's choice. Only open projects the user can see are kept.
|
||||||
|
def report_project_ids
|
||||||
|
visible = @projects.map(&:id)
|
||||||
|
if params.key?(:project_ids)
|
||||||
|
ids = Array(params[:project_ids]).map(&:to_i) & visible
|
||||||
|
save_project_ids(ids) if params[:save_projects] == '1'
|
||||||
|
else
|
||||||
|
ids = saved_project_ids & visible
|
||||||
|
end
|
||||||
|
@saved_project_ids = saved_project_ids & visible
|
||||||
|
ids
|
||||||
|
end
|
||||||
|
|
||||||
|
def saved_project_ids
|
||||||
|
return [] unless User.current.logged?
|
||||||
|
Array(User.current.pref[PROJECTS_PREF]).map(&:to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_project_ids(ids)
|
||||||
|
return unless User.current.logged?
|
||||||
|
pref = User.current.pref
|
||||||
|
pref[PROJECTS_PREF] = ids
|
||||||
|
pref.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -22,4 +22,11 @@ class Invoice < QboBaseModel
|
|||||||
doc_number
|
doc_number
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Paid, partially paid, overdue, open or voided, from the cached total, balance and due date
|
||||||
|
# (RedmineQboBilling::InvoiceStatus); nil when the balance isn't cached
|
||||||
|
def status(today: User.current.today)
|
||||||
|
RedmineQboBilling::InvoiceStatus.status(total: self[:total_amount], balance: self[:balance],
|
||||||
|
due_date: self[:due_date], today: today)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,24 +1,66 @@
|
|||||||
<h2><%=t(:field_customers)%> <span style="float:right"> <%= render partial: 'customers/search' %> </span> </h2>
|
<% html_title l(:label_customers) %>
|
||||||
<% if @customers.present? %>
|
<% phone = ->(digits) { digits.present? ? number_to_phone(digits.gsub(/\D/, '').to_i, area_code: true) : '' } %>
|
||||||
<br/>
|
|
||||||
<% @customers.each do |c| %>
|
<div class="contextual">
|
||||||
<div class="row">
|
<% if User.current.allowed_to?(:add_customers, nil, global: true) %>
|
||||||
<div class="span6 columns">
|
<%= link_to sprite_icon('add', l(:label_new_customer)), new_customer_path, class: 'icon icon-add' %>
|
||||||
<%= link_to c, customer_path(c.id) %>
|
<% end %>
|
||||||
</div>
|
<% if User.current.admin? %>
|
||||||
</div>
|
<%= link_to sprite_icon('reload', l(:label_sync)), qbo_sync_path, class: 'icon icon-reload' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%=t(:label_matching)%> <%= @customers.count %> <%=t(:field_customers)%> </p>
|
|
||||||
|
|
||||||
<div class="actions">
|
|
||||||
<%= will_paginate @customers %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% else %>
|
<h2><%= l(:label_customers) %></h2>
|
||||||
<p><%=t(:label_no_customers)%> <%= params[:search] %>.</p>
|
|
||||||
|
<%= form_tag(customers_path, method: :get, id: 'customer-search-form') do %>
|
||||||
|
<p class="qbo-customer-search">
|
||||||
|
<%= text_field_tag :search, @search, class: 'customer-name', size: 40, placeholder: t(:label_search_customers),
|
||||||
|
autocomplete: 'off', data: { autocomplete_url: '/customers/autocomplete' } %>
|
||||||
|
<%= submit_tag l(:label_search), name: nil %>
|
||||||
|
<% if @search.present? %>
|
||||||
|
<%= link_to sprite_icon('reload', l(:button_clear)), customers_path, class: 'icon icon-reload' %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div>
|
<% if @customers.empty? %>
|
||||||
<%= render partial: 'qbo/stats' %>
|
<p class="nodata"><%= @search.present? ? l(:label_no_customers, search: @search) : l(:label_no_data) %></p>
|
||||||
</div>
|
<% else %>
|
||||||
|
<% if @best_first %>
|
||||||
|
<p class="info"><%= l(:text_customers_best_match, count: @customer_count) %></p>
|
||||||
|
<% end %>
|
||||||
|
<div class="autoscroll">
|
||||||
|
<table class="list customers odd-even">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<%= sort_header_tag('name', caption: l(:field_name)) %>
|
||||||
|
<%= sort_header_tag('phone', caption: l(:label_primary_phone)) %>
|
||||||
|
<%= sort_header_tag('mobile', caption: l(:label_mobile_phone)) %>
|
||||||
|
<th><%= l(:label_issue_plural) %></th>
|
||||||
|
<%= sort_header_tag('updated', caption: l(:field_updated_on), default_order: 'desc') %>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @customers.each do |customer| %>
|
||||||
|
<tr class="<%= cycle('odd', 'even') %>">
|
||||||
|
<td class="name"><%= link_to customer.name, customer_path(customer.id) %></td>
|
||||||
|
<td class="phone"><%= phone.call(customer.phone_number) %></td>
|
||||||
|
<td class="phone"><%= phone.call(customer.mobile_phone_number) %></td>
|
||||||
|
<td class="issues"><%= @issue_counts[customer.id] || 0 %></td>
|
||||||
|
<td class="updated_on"><%= format_time(customer.updated_at) if customer.updated_at %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<span class="pagination"><%= pagination_links_full @customer_pages, @customer_count %></span>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p class="qbo-customer-stats"><%= render partial: 'qbo/stats' %></p>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
table.customers td.name { text-align: left; }
|
||||||
|
table.customers td.phone, table.customers td.updated_on { white-space: nowrap; }
|
||||||
|
table.customers td.issues { width: 1%; text-align: center; }
|
||||||
|
.qbo-customer-search input { vertical-align: middle; }
|
||||||
|
</style>
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
<div class="contextual">
|
<% html_title @customer.to_s %>
|
||||||
|
|
||||||
|
<h2><%= link_to l(:label_customers), customers_path %> » <%= @customer.to_s %></h2>
|
||||||
|
|
||||||
|
<%# Under the title rather than beside it, so a long name and the many actions don't crowd each other %>
|
||||||
|
<div class="contextual qbo-under-title">
|
||||||
<%# New issue for this customer; picks up what's ticked on this page (an estimate, other plugins' items) %>
|
<%# New issue for this customer; picks up what's ticked on this page (an estimate, other plugins' items) %>
|
||||||
<%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }),
|
<%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }),
|
||||||
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %>
|
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %>
|
||||||
<%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %>
|
<%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %>
|
||||||
<%= call_hook :view_customers_show_contextual, { customer: @customer } %>
|
<%= call_hook :view_customers_show_contextual, { customer: @customer } %>
|
||||||
<%# Estimates, invoices and payments are handled here, each shown to users with its permission. The customer's
|
<%# Estimates, invoices and payments are handled here, each shown to users with its permission; Open in
|
||||||
name below links to their QuickBooks account page as a fallback. %>
|
QuickBooks goes to their QuickBooks account page for anything else. %>
|
||||||
<% if RedmineQboBilling.writer? %>
|
<% if RedmineQboBilling.writer? %>
|
||||||
<%= render partial: 'qbo_estimates/customer_link', locals: { customer: @customer } %>
|
<%= render partial: 'qbo_estimates/customer_link', locals: { customer: @customer } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -22,9 +27,10 @@
|
|||||||
<%= link_to sprite_icon('edit', l(:button_edit)), edit_customer_path(@customer),
|
<%= link_to sprite_icon('edit', l(:button_edit)), edit_customer_path(@customer),
|
||||||
class: 'icon icon-edit', accesskey: accesskey(:edit) %>
|
class: 'icon icon-edit', accesskey: accesskey(:edit) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= link_to sprite_icon('link', l(:button_open_in_quickbooks)),
|
||||||
|
"https://#{RedmineQbo.sandbox_mode? ? 'sandbox' : 'app'}.qbo.intuit.com/app/customerdetail?nameId=#{@customer.id}",
|
||||||
|
class: 'icon icon-link', target: :_blank, rel: 'noopener' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2><%=t(:field_customer)%> #<%= @customer.id %> - <%= link_to @customer.to_s, "https://#{RedmineQbo.sandbox_mode? ? "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">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<% unless invoices.empty? %>
|
<% unless invoices.empty? %>
|
||||||
|
<%= render partial: 'qbo_estimates/status_styles' %>
|
||||||
|
|
||||||
<%= form_with(url: invoice_path, method: :get) do |form| %>
|
<%= form_with(url: invoice_path, method: :get) do |form| %>
|
||||||
|
|
||||||
@@ -10,13 +11,19 @@
|
|||||||
<hr>
|
<hr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<div class="qbo-invoice-list">
|
||||||
<% invoices.sort.reverse.each do |invoice| %>
|
<% invoices.sort.reverse.each do |invoice| %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" if invoices.count > 1 %>
|
<%= check_box_tag "invoice_ids[]", invoice.id, false, onchange: "updateLink()", data: { url: invoice_path(invoice), text: "Invoice ##{invoice.to_s}" }, class: "invoice-checkbox appointment" 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 %>
|
||||||
|
<%# Paid / partially paid / overdue / open / voided, from the cached balance and due date %>
|
||||||
|
<% if (status = invoice.status) %>
|
||||||
|
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
|
||||||
|
<% end %>
|
||||||
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
|
<%= render partial: 'qbo_invoices/invoice_actions', locals: { invoice: invoice } if RedmineQboBilling.invoice_writer? %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<% if invoices.count > 1 %>
|
<% if invoices.count > 1 %>
|
||||||
<%= form.submit t(:button_bulk_pdf) %>
|
<%= form.submit t(:button_bulk_pdf) %>
|
||||||
|
|||||||
@@ -15,9 +15,13 @@
|
|||||||
<% if form.sent? %>
|
<% if form.sent? %>
|
||||||
<span class="qbo-estimate-status qbo-estimate-status-sent"><%= l(:label_estimate_sent) %></span>
|
<span class="qbo-estimate-status qbo-estimate-status-sent"><%= l(:label_estimate_sent) %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if invoice && form.locked == :paid %>
|
<% if invoice %>
|
||||||
<% fully_paid = form.balance.to_d.zero? %>
|
<% status = RedmineQboBilling::InvoiceStatus.status(total: form.total, balance: form.balance,
|
||||||
<span class="qbo-estimate-status qbo-estimate-status-<%= fully_paid ? 'closed' : 'accepted' %>"><%= l(fully_paid ? :label_invoice_paid : :label_invoice_partially_paid) %></span>
|
due_date: RedmineQboBilling::EstimateForm.date(form.due_date),
|
||||||
|
today: User.current.today) %>
|
||||||
|
<% if status %>
|
||||||
|
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status) %></span>
|
||||||
|
<% end %>
|
||||||
<% elsif !invoice && form.txn_status.present? %>
|
<% elsif !invoice && form.txn_status.present? %>
|
||||||
<span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span>
|
<span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -548,6 +548,24 @@ $(function () {
|
|||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Pairs imported time with the invoice lines ticked under "Replace these lines": first by description,
|
||||||
|
// since issues created from an estimate take the line's description as their subject and the time names
|
||||||
|
// it ("Install #134: Install Lift Kit" <-> "Install Lift Kit"); what's left is paired in order.
|
||||||
|
// Returns { pairs: [{ time, line }], extraTimes: [...], extraLines: [...] }.
|
||||||
|
var pairTimeWithLines = function (times, lines) {
|
||||||
|
var norm = function (text) { return String(text || '').split('\n')[0].toLowerCase().replace(/\s+/g, ' ').trim(); };
|
||||||
|
var subject = function (activity) { return norm(String(activity.description || '').replace(/^[^\n]*?#\d+:\s*/, '')); };
|
||||||
|
var lineText = function (line) { return norm($(line).find('.qbo-line-description-input').val()); };
|
||||||
|
var freeTimes = times.slice(), freeLines = [], pairs = [];
|
||||||
|
lines.forEach(function (line) {
|
||||||
|
var text = lineText(line);
|
||||||
|
var i = text ? freeTimes.findIndex(function (t) { return subject(t) === text; }) : -1;
|
||||||
|
if (i >= 0) { pairs.push({ time: freeTimes[i], line: line }); freeTimes.splice(i, 1); } else { freeLines.push(line); }
|
||||||
|
});
|
||||||
|
while (freeTimes.length && freeLines.length) pairs.push({ time: freeTimes.shift(), line: freeLines.shift() });
|
||||||
|
return { pairs: pairs, extraTimes: freeTimes, extraLines: freeLines };
|
||||||
|
};
|
||||||
|
|
||||||
// Rows go after the last filled line, above the spare empty rows
|
// Rows go after the last filled line, above the spare empty rows
|
||||||
var insertAfterFilled = function ($rows) {
|
var insertAfterFilled = function ($rows) {
|
||||||
var $filled = rows().filter(function () { return !rowIsBlank($(this)); });
|
var $filled = rows().filter(function () { return !rowIsBlank($(this)); });
|
||||||
@@ -642,15 +660,24 @@ $(function () {
|
|||||||
// Kept so the import can be undone before saving (clones keep what was typed)
|
// Kept so the import can be undone before saving (clones keep what was typed)
|
||||||
undoState = { rows: rows().clone(), linked: $('#qbo-linked-estimates').children().clone() };
|
undoState = { rows: rows().clone(), linked: $('#qbo-linked-estimates').children().clone() };
|
||||||
|
|
||||||
// Time goes where the first ticked line was; the ticked lines are removed
|
// Each time entry replaces one ticked line, in that line's place (see pairTimeWithLines). Time left over
|
||||||
|
// goes after the last replaced line; ticked lines left over are removed (ticked means replace).
|
||||||
if (times.length) {
|
if (times.length) {
|
||||||
var $timeRows = $(times.map(function (activity) {
|
var ticked = $('#qbo-import-replace input:checked').map(function () { return $(this).data('row')[0]; }).get();
|
||||||
return makeRow($.extend({}, activity, { time_activity_id: activity.id }))[0];
|
ticked = rows().get().filter(function (row) { return ticked.indexOf(row) >= 0; }); // table order
|
||||||
}));
|
var pairing = pairTimeWithLines(times, ticked);
|
||||||
var $replaced = $('#qbo-import-replace input:checked').map(function () { return $(this).data('row')[0]; });
|
var timeRow = function (activity) { return makeRow($.extend({}, activity, { time_activity_id: activity.id })); };
|
||||||
var $anchor = rows().filter(function () { return $replaced.index(this) >= 0; }).first();
|
var $last = $();
|
||||||
if ($anchor.length) { $anchor.before($timeRows); } else { insertAfterFilled($timeRows); }
|
pairing.pairs.forEach(function (pair) {
|
||||||
$replaced.remove();
|
var $row = timeRow(pair.time);
|
||||||
|
$(pair.line).replaceWith($row);
|
||||||
|
if (!$last.length || $row.index() > $last.index()) $last = $row;
|
||||||
|
});
|
||||||
|
pairing.extraLines.forEach(function (line) { $(line).remove(); });
|
||||||
|
if (pairing.extraTimes.length) {
|
||||||
|
var $extra = $(pairing.extraTimes.map(function (activity) { return timeRow(activity)[0]; }));
|
||||||
|
if ($last.length) { $last.after($extra); } else { insertAfterFilled($extra); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each estimate's lines go right after the time for the same issue (e.g. lineitems' "Added from:
|
// Each estimate's lines go right after the time for the same issue (e.g. lineitems' "Added from:
|
||||||
|
|||||||
@@ -7,4 +7,11 @@
|
|||||||
.qbo-estimate-status-closed, .qbo-estimate-status-converted { background: #e8eefa; color: #0d47a1; }
|
.qbo-estimate-status-closed, .qbo-estimate-status-converted { background: #e8eefa; color: #0d47a1; }
|
||||||
.qbo-estimate-status-rejected { background: #fdecea; color: #b71c1c; }
|
.qbo-estimate-status-rejected { background: #fdecea; color: #b71c1c; }
|
||||||
.qbo-estimate-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
|
.qbo-estimate-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
|
||||||
|
/* Invoices (RedmineQboBilling::InvoiceStatus) */
|
||||||
|
.qbo-invoice-status-paid { background: #e6f4e4; color: #108000; }
|
||||||
|
.qbo-invoice-status-partial { background: #fff4d6; color: #8a6100; }
|
||||||
|
.qbo-invoice-status-overdue { background: #fdecea; color: #b71c1c; }
|
||||||
|
.qbo-invoice-status-open { background: #e8eefa; color: #0d47a1; }
|
||||||
|
.qbo-invoice-status-voided { background: #eceef1; color: #6b6c72; text-decoration: line-through; }
|
||||||
|
.qbo-invoice-list .qbo-estimate-status { font-size: .8em; padding: 1px 7px; margin-left: 4px; }
|
||||||
</style>
|
</style>
|
||||||
@@ -7,6 +7,44 @@
|
|||||||
<% bar = ->(value, max) { max > 0 ? (value.to_f / max * 100).round(1) : 0 } %>
|
<% bar = ->(value, max) { max > 0 ? (value.to_f / max * 100).round(1) : 0 } %>
|
||||||
<% fmt_hours = ->(h) { format('%.1f', h.to_f) } %>
|
<% fmt_hours = ->(h) { format('%.1f', h.to_f) } %>
|
||||||
<% pct = ->(v) { v.nil? ? '–' : "#{v}%" } %>
|
<% pct = ->(v) { v.nil? ? '–' : "#{v}%" } %>
|
||||||
|
<%# Line charts: a label and a tooltip title per point, from the chart's granularity %>
|
||||||
|
<% chart = @report.chart %>
|
||||||
|
<% months_abbr = ::I18n.t('date.abbr_month_names') %>
|
||||||
|
<% days_abbr = ::I18n.t('date.abbr_day_names') %>
|
||||||
|
<% one_year = @report.from.year == @report.to.year %>
|
||||||
|
<% point_label = lambda do |date|
|
||||||
|
case chart[:granularity]
|
||||||
|
when :day then "#{days_abbr[date.wday]} #{date.day}"
|
||||||
|
when :week then "#{months_abbr[date.month]} #{date.day}"
|
||||||
|
else one_year ? months_abbr[date.month] : "#{months_abbr[date.month]} #{date.year}"
|
||||||
|
end
|
||||||
|
end %>
|
||||||
|
<% point_title = lambda do |first, last|
|
||||||
|
case chart[:granularity]
|
||||||
|
when :day then format_date(first)
|
||||||
|
when :week then "#{format_date(first)} – #{format_date(last)}"
|
||||||
|
else "#{::I18n.t('date.month_names')[first.month]} #{first.year}"
|
||||||
|
end
|
||||||
|
end %>
|
||||||
|
<% previous_ends = chart[:previous_points].each_with_index.map { |p, i| Date.parse(p) + (Date.parse(chart[:ends][i]) - Date.parse(chart[:points][i])) } %>
|
||||||
|
<% chart_points = {
|
||||||
|
labels: chart[:points].map { |p| point_label.call(Date.parse(p)) },
|
||||||
|
titles: chart[:points].each_with_index.map { |p, i| point_title.call(Date.parse(p), Date.parse(chart[:ends][i])) },
|
||||||
|
previous_titles: chart[:previous_points].each_with_index.map { |p, i| point_title.call(Date.parse(p), previous_ends[i]) },
|
||||||
|
last_year: l(:label_report_last_year)
|
||||||
|
} %>
|
||||||
|
<% chart_series = lambda do |keys|
|
||||||
|
keys.map do |key, label, color|
|
||||||
|
{ label: label, color: color, current: chart[:current][key], previous: chart[:previous][key] }
|
||||||
|
end
|
||||||
|
end %>
|
||||||
|
<% sales_series = chart_series.call([[:estimates, l(:label_report_estimates_written), '#628db6'],
|
||||||
|
[:invoices, l(:label_report_invoices_written), '#e8a33d'],
|
||||||
|
[:payments, l(:label_report_payments_received), '#5aa05a']]) %>
|
||||||
|
<% hours_series = chart_series.call([[:estimate_hours, l(:label_report_estimate_hours), '#628db6'],
|
||||||
|
[:issue_hours, l(:label_report_issue_hours), '#9b7fc0'],
|
||||||
|
[:invoice_hours, l(:label_report_invoice_hours), '#e8a33d'],
|
||||||
|
[:spent_hours, l(:label_report_spent_hours), '#5aa05a']]) %>
|
||||||
|
|
||||||
<h2><%= l(:label_business_report) %></h2>
|
<h2><%= l(:label_business_report) %></h2>
|
||||||
|
|
||||||
@@ -22,10 +60,40 @@
|
|||||||
<%= date_field_tag 'to', @report.to.iso8601, id: 'qbo-report-to' %>
|
<%= date_field_tag 'to', @report.to.iso8601, id: 'qbo-report-to' %>
|
||||||
</span>
|
</span>
|
||||||
<%= submit_tag l(:button_apply), name: nil %>
|
<%= submit_tag l(:button_apply), name: nil %>
|
||||||
|
<label class="qbo-report-compare">
|
||||||
|
<%= check_box_tag 'compare', '1', @compare, id: 'qbo-report-compare' %>
|
||||||
|
<%= l(:label_report_compare_last_year) %>
|
||||||
|
</label>
|
||||||
|
<%# Projects for the issues and spent time; the blank value sends project_ids when none are picked (every project) %>
|
||||||
|
<div class="qbo-report-projects">
|
||||||
|
<label for="qbo-report-project-ids"><%= l(:label_project_plural) %></label>
|
||||||
|
<%= hidden_field_tag 'project_ids[]', '', id: nil %>
|
||||||
|
<%= select_tag 'project_ids[]',
|
||||||
|
project_tree_options_for_select(@projects, selected: @projects.select { |p| @project_ids.include?(p.id) }),
|
||||||
|
multiple: true, size: [[@projects.size, 3].max, 8].min, id: 'qbo-report-project-ids' %>
|
||||||
|
<span class="qbo-report-projects-options">
|
||||||
|
<em class="info"><%= l(:text_report_projects) %></em>
|
||||||
|
<label>
|
||||||
|
<%= check_box_tag 'save_projects', '1', false, id: 'qbo-report-save-projects' %>
|
||||||
|
<%= l(:label_report_remember_projects) %>
|
||||||
|
</label>
|
||||||
|
<% if @saved_project_ids.any? %>
|
||||||
|
<em class="info"><%= l(:text_report_saved_projects, projects: @projects.select { |p| @saved_project_ids.include?(p.id) }.map(&:name).join(', ')) %></em>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p class="qbo-report-range"><%= format_date(@report.from) %> – <%= format_date(@report.to) %></p>
|
<p class="qbo-report-range">
|
||||||
|
<%= format_date(@report.from) %> – <%= format_date(@report.to) %>
|
||||||
|
<% if @report.projects_filtered? %>
|
||||||
|
· <%= l(:label_project_plural) %>: <%= @projects.select { |p| @project_ids.include?(p.id) }.map(&:name).join(', ') %>
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
<% if @report.projects_filtered? %>
|
||||||
|
<p class="info qbo-report-projects-note"><%= l(:text_report_projects_filtered) %></p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if Array(@syncing).any? %>
|
<% if Array(@syncing).any? %>
|
||||||
<% sync_labels = { 'Estimate' => l(:label_estimates), 'Invoice' => l(:label_invoices), 'Payment' => l(:label_payments) } %>
|
<% sync_labels = { 'Estimate' => l(:label_estimates), 'Invoice' => l(:label_invoices), 'Payment' => l(:label_payments) } %>
|
||||||
@@ -58,6 +126,9 @@
|
|||||||
<div class="splitcontent">
|
<div class="splitcontent">
|
||||||
<div class="splitcontentleft">
|
<div class="splitcontentleft">
|
||||||
<h3><%= l(:label_report_money) %></h3>
|
<h3><%= l(:label_report_money) %></h3>
|
||||||
|
<div class="qbo-report-chart">
|
||||||
|
<canvas id="qbo-chart-sales" data-kind="money" data-series="<%= sales_series.to_json %>"></canvas>
|
||||||
|
</div>
|
||||||
<table class="list qbo-report">
|
<table class="list qbo-report">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% [[:estimates, l(:label_report_estimates_written)], [:invoices, l(:label_report_invoices_written)],
|
<% [[:estimates, l(:label_report_estimates_written)], [:invoices, l(:label_report_invoices_written)],
|
||||||
@@ -79,6 +150,9 @@
|
|||||||
|
|
||||||
<div class="splitcontentright">
|
<div class="splitcontentright">
|
||||||
<h3><%= l(:label_report_hours) %></h3>
|
<h3><%= l(:label_report_hours) %></h3>
|
||||||
|
<div class="qbo-report-chart">
|
||||||
|
<canvas id="qbo-chart-hours" data-kind="hours" data-series="<%= hours_series.to_json %>"></canvas>
|
||||||
|
</div>
|
||||||
<table class="list qbo-report">
|
<table class="list qbo-report">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% [[:estimate_hours, l(:label_report_estimate_hours)], [:issue_hours, l(:label_report_issue_hours)],
|
<% [[:estimate_hours, l(:label_report_estimate_hours)], [:issue_hours, l(:label_report_issue_hours)],
|
||||||
@@ -91,8 +165,16 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<% cpi_badge = lambda do |cpi|
|
||||||
|
level = RedmineQboBilling::BusinessReport.cpi_level(cpi)
|
||||||
|
content_tag(:span, cpi.nil? ? '–' : format('%.2f', cpi), class: "qbo-cpi qbo-cpi-#{level || 'none'}")
|
||||||
|
end %>
|
||||||
|
<p class="qbo-report-cpi">
|
||||||
|
<span class="qbo-cpi-label" title="<%= l(:text_report_cpi) %>"><%= l(:label_report_cpi) %></span>
|
||||||
|
<%= cpi_badge.call(@report.cpi) %>
|
||||||
|
<em class="info"><%= l(:text_report_cpi) %></em>
|
||||||
|
</p>
|
||||||
<p class="qbo-report-ratios">
|
<p class="qbo-report-ratios">
|
||||||
<%= l(:label_report_invoiced_of_spent) %>: <strong><%= pct.call(ratios[:invoiced_of_spent]) %></strong><br />
|
|
||||||
<%= l(:label_report_spent_of_estimated) %>: <strong><%= pct.call(ratios[:spent_of_estimated]) %></strong>
|
<%= l(:label_report_spent_of_estimated) %>: <strong><%= pct.call(ratios[:spent_of_estimated]) %></strong>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -111,6 +193,7 @@
|
|||||||
<th><%= l(:label_report_issue_hours) %></th>
|
<th><%= l(:label_report_issue_hours) %></th>
|
||||||
<th><%= l(:label_report_invoice_hours) %></th>
|
<th><%= l(:label_report_invoice_hours) %></th>
|
||||||
<th><%= l(:label_report_spent_hours) %></th>
|
<th><%= l(:label_report_spent_hours) %></th>
|
||||||
|
<th class="cpi"><%= l(:label_report_cpi_short) %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -124,6 +207,7 @@
|
|||||||
<td><%= fmt_hours.call(row[:issue_hours]) %></td>
|
<td><%= fmt_hours.call(row[:issue_hours]) %></td>
|
||||||
<td><%= fmt_hours.call(row[:invoice_hours]) %></td>
|
<td><%= fmt_hours.call(row[:invoice_hours]) %></td>
|
||||||
<td><%= fmt_hours.call(row[:spent_hours]) %></td>
|
<td><%= fmt_hours.call(row[:spent_hours]) %></td>
|
||||||
|
<td class="cpi"><%= cpi_badge.call(RedmineQboBilling::BusinessReport.cpi(row[:invoice_hours], row[:spent_hours])) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -137,6 +221,7 @@
|
|||||||
<td><strong><%= fmt_hours.call(hours[:issue_hours]) %></strong></td>
|
<td><strong><%= fmt_hours.call(hours[:issue_hours]) %></strong></td>
|
||||||
<td><strong><%= fmt_hours.call(hours[:invoice_hours]) %></strong></td>
|
<td><strong><%= fmt_hours.call(hours[:invoice_hours]) %></strong></td>
|
||||||
<td><strong><%= fmt_hours.call(hours[:spent_hours]) %></strong></td>
|
<td><strong><%= fmt_hours.call(hours[:spent_hours]) %></strong></td>
|
||||||
|
<td class="cpi"><%= cpi_badge.call(@report.cpi) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
@@ -154,6 +239,15 @@
|
|||||||
.qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; }
|
.qbo-bar-payments, .qbo-bar-spent_hours { background: #5aa05a; }
|
||||||
.qbo-bar-issue_hours { background: #9b7fc0; }
|
.qbo-bar-issue_hours { background: #9b7fc0; }
|
||||||
.qbo-report-ratios { margin: 8px 4px; line-height: 1.7; }
|
.qbo-report-ratios { margin: 8px 4px; line-height: 1.7; }
|
||||||
|
.qbo-report-cpi { margin: 10px 4px 4px; }
|
||||||
|
.qbo-report-cpi .qbo-cpi-label { font-weight: 600; margin-right: 6px; }
|
||||||
|
.qbo-report-cpi .qbo-cpi { font-size: 1.3em; padding: 3px 12px; }
|
||||||
|
.qbo-report-cpi em.info { display: block; margin-top: 4px; }
|
||||||
|
.qbo-cpi { display: inline-block; font-weight: 700; padding: 1px 8px; border-radius: 10px; background: #eceef1; color: #393a3d; }
|
||||||
|
.qbo-cpi-poor { background: #fdecea; color: #b71c1c; }
|
||||||
|
.qbo-cpi-under { background: #fff4d6; color: #8a6100; }
|
||||||
|
.qbo-cpi-good { background: #e6f4e4; color: #108000; }
|
||||||
|
table.qbo-report-months td.cpi, table.qbo-report-months th.cpi { text-align: center; }
|
||||||
.qbo-report-range { color: #666; margin: 4px 0 10px; }
|
.qbo-report-range { color: #666; margin: 4px 0 10px; }
|
||||||
.qbo-report-syncing ul { display: inline-block; text-align: left; margin: 6px 0 0; }
|
.qbo-report-syncing ul { display: inline-block; text-align: left; margin: 6px 0 0; }
|
||||||
table.qbo-report-months td, table.qbo-report-months th { text-align: right; white-space: nowrap; }
|
table.qbo-report-months td, table.qbo-report-months th { text-align: right; white-space: nowrap; }
|
||||||
@@ -161,6 +255,12 @@
|
|||||||
table.qbo-report-months .hours-start { border-left: 2px solid #ddd; }
|
table.qbo-report-months .hours-start { border-left: 2px solid #ddd; }
|
||||||
table.qbo-report-months tfoot td { border-top: 2px solid #ccc; }
|
table.qbo-report-months tfoot td { border-top: 2px solid #ccc; }
|
||||||
#qbo-report-form select, #qbo-report-form input { vertical-align: middle; }
|
#qbo-report-form select, #qbo-report-form input { vertical-align: middle; }
|
||||||
|
#qbo-report-form .qbo-report-compare { margin-left: 12px; white-space: nowrap; }
|
||||||
|
#qbo-report-form .qbo-report-projects { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px 10px; margin-top: 8px; }
|
||||||
|
#qbo-report-form .qbo-report-projects select { min-width: 220px; max-width: 100%; }
|
||||||
|
#qbo-report-form .qbo-report-projects-options { display: flex; flex-direction: column; gap: 4px; }
|
||||||
|
#qbo-report-form .qbo-report-projects-options label { white-space: nowrap; }
|
||||||
|
.qbo-report-chart { position: relative; height: 260px; margin: 4px 4px 16px; }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<%= javascript_tag do %>
|
<%= javascript_tag do %>
|
||||||
@@ -170,4 +270,142 @@
|
|||||||
$dates.on('change', function() { $period.val('custom'); });
|
$dates.on('change', function() { $period.val('custom'); });
|
||||||
$period.on('change', function() { if ($period.val() !== 'custom') { $('#qbo-report-form').submit(); } });
|
$period.on('change', function() { if ($period.val() !== 'custom') { $('#qbo-report-form').submit(); } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Line charts (Chart.js 4): the same figures and colors as the bars, a point per day,
|
||||||
|
// week or month. "Compare with last year" adds last year's lines, dashed and faded, without reloading.
|
||||||
|
(function() {
|
||||||
|
var points = <%= raw chart_points.to_json %>;
|
||||||
|
// The currency layout the tables use, e.g. "$%n"
|
||||||
|
var currencyFormat = <%= raw number_to_currency(0, precision: 0).to_s.sub('0', '%n').to_json %>;
|
||||||
|
var charts = [];
|
||||||
|
|
||||||
|
function money(v, decimals) {
|
||||||
|
var n = Number(v || 0).toLocaleString(undefined, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });
|
||||||
|
return currencyFormat.replace('%n', n);
|
||||||
|
}
|
||||||
|
function hours(v) { return Number(v || 0).toFixed(1); }
|
||||||
|
function faded(hex) {
|
||||||
|
var n = parseInt(hex.slice(1), 16);
|
||||||
|
return 'rgba(' + (n >> 16 & 255) + ',' + (n >> 8 & 255) + ',' + (n & 255) + ',0.45)';
|
||||||
|
}
|
||||||
|
|
||||||
|
function draw(Chart, canvas, compare) {
|
||||||
|
var series = JSON.parse(canvas.getAttribute('data-series'));
|
||||||
|
var isMoney = canvas.getAttribute('data-kind') === 'money';
|
||||||
|
var datasets = [];
|
||||||
|
series.forEach(function(s) {
|
||||||
|
datasets.push({ label: s.label, data: s.current, borderColor: s.color, backgroundColor: s.color,
|
||||||
|
fill: false, cubicInterpolationMode: 'monotone', pointRadius: 3, pointHoverRadius: 5, spanGaps: false, order: 1 });
|
||||||
|
});
|
||||||
|
series.forEach(function(s) {
|
||||||
|
datasets.push({ label: s.label + ' (' + points.last_year + ')', data: s.previous, previous: true,
|
||||||
|
borderColor: faded(s.color), backgroundColor: faded(s.color), borderDash: [6, 4],
|
||||||
|
borderWidth: 2, fill: false, cubicInterpolationMode: 'monotone', pointRadius: 2, pointHoverRadius: 4,
|
||||||
|
hidden: !compare, order: 2 });
|
||||||
|
});
|
||||||
|
return new Chart(canvas, {
|
||||||
|
type: 'line',
|
||||||
|
data: { labels: points.labels, datasets: datasets },
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
interaction: { mode: 'index', intersect: false },
|
||||||
|
plugins: {
|
||||||
|
// One entry per figure (clicking it hides this year's and last year's line), plus a single
|
||||||
|
// dashed "last year" entry while comparing (clicking it turns comparing off)
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
labels: {
|
||||||
|
boxWidth: 12,
|
||||||
|
generateLabels: function(chart) {
|
||||||
|
var items = Chart.defaults.plugins.legend.labels.generateLabels(chart).filter(function(item) {
|
||||||
|
return !chart.data.datasets[item.datasetIndex].previous;
|
||||||
|
});
|
||||||
|
if (chart.data.datasets.some(function(ds) { return ds.previous && !ds.hidden; })) {
|
||||||
|
items.push({ text: points.last_year, fillStyle: 'rgba(0,0,0,0)', strokeStyle: '#999', lineWidth: 2,
|
||||||
|
lineDash: [4, 3], hidden: false, datasetIndex: -1 });
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClick: function(e, item, legend) {
|
||||||
|
var chart = legend.chart;
|
||||||
|
if (item.datasetIndex === -1) { $('#qbo-report-compare').prop('checked', false).trigger('change'); return; }
|
||||||
|
var visible = !chart.isDatasetVisible(item.datasetIndex);
|
||||||
|
chart.setDatasetVisibility(item.datasetIndex, visible);
|
||||||
|
// last year's line follows (shown only while comparing)
|
||||||
|
chart.getDatasetMeta(item.datasetIndex + series.length).hidden = visible ? null : true;
|
||||||
|
chart.update();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
callbacks: {
|
||||||
|
title: function(items) {
|
||||||
|
if (!items.length) { return ''; }
|
||||||
|
var i = items[0].dataIndex, lines = [points.titles[i]];
|
||||||
|
if (items.some(function(it) { return it.dataset.previous; })) {
|
||||||
|
lines.push(points.last_year + ': ' + points.previous_titles[i]);
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
},
|
||||||
|
label: function(item) {
|
||||||
|
return item.dataset.label + ': ' + (isMoney ? money(item.raw, 2) : hours(item.raw));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
y: { beginAtZero: true, ticks: { precision: isMoney ? 0 : 1, callback: function(v) { return isMoney ? money(v, 0) : v; } } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chart.js from the module: its default export or a named one. Chart.js 2 has no register() and is skipped.
|
||||||
|
function chartClass(mod) {
|
||||||
|
var found = [mod && mod.default, mod && mod.Chart, mod && mod.default && mod.default.Chart];
|
||||||
|
for (var i = 0; i < found.length; i++) {
|
||||||
|
if (typeof found[i] === 'function' && typeof found[i].register === 'function') { return found[i]; }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCompare(on) {
|
||||||
|
charts.forEach(function(chart) {
|
||||||
|
var n = chart.data.datasets.length / 2;
|
||||||
|
for (var j = 0; j < n; j++) {
|
||||||
|
chart.data.datasets[j + n].hidden = !on;
|
||||||
|
// a figure hidden from the legend keeps last year's line hidden too
|
||||||
|
chart.getDatasetMeta(j + n).hidden = chart.isDatasetVisible(j) ? null : true;
|
||||||
|
}
|
||||||
|
chart.update();
|
||||||
|
});
|
||||||
|
// Keep the choice in the address, so reloading or changing the period keeps it
|
||||||
|
if (window.history && history.replaceState) {
|
||||||
|
var url = new URL(window.location.href);
|
||||||
|
if (on) { url.searchParams.set('compare', '1'); } else { url.searchParams.delete('compare'); }
|
||||||
|
history.replaceState(null, '', url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
var $compare = $('#qbo-report-compare');
|
||||||
|
// Chart.js 4 ships with this plugin (assets/javascripts), so the charts don't depend on how Redmine or
|
||||||
|
// other plugins provide it (redmine_indicator puts Chart.js 2 on every page)
|
||||||
|
import(<%= raw asset_path('plugin_assets/redmine_qbo/chart-4.5.1.min.js').to_json %>).then(function(mod) {
|
||||||
|
var Chart = chartClass(mod);
|
||||||
|
if (!Chart) {
|
||||||
|
console.warn('Business report: Chart.js did not load', Object.keys(mod || {}));
|
||||||
|
$('.qbo-report-chart').hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$('.qbo-report-chart canvas').each(function() { charts.push(draw(Chart, this, $compare.is(':checked'))); });
|
||||||
|
window.qboReportCharts = charts;
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.warn('Business report: Chart.js did not load', error);
|
||||||
|
$('.qbo-report-chart').hide();
|
||||||
|
});
|
||||||
|
$compare.on('change', function() { setCompare(this.checked); });
|
||||||
|
});
|
||||||
|
})();
|
||||||
<% end %>
|
<% end %>
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
/*!
|
||||||
|
* Chart.js v4.5.1
|
||||||
|
* https://www.chartjs.org
|
||||||
|
* (c) 2025 Chart.js Contributors
|
||||||
|
* Released under the MIT License
|
||||||
|
*/
|
||||||
|
function t(){}const e=(()=>{let t=0;return()=>t++})();function i(t){return null==t}function s(t){if(Array.isArray&&Array.isArray(t))return!0;const e=Object.prototype.toString.call(t);return"[object"===e.slice(0,7)&&"Array]"===e.slice(-6)}function n(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function o(t){return("number"==typeof t||t instanceof Number)&&isFinite(+t)}function a(t,e){return o(t)?t:e}function r(t,e){return void 0===t?e:t}const l=(t,e)=>"string"==typeof t&&t.endsWith("%")?parseFloat(t)/100*e:+t;function h(t,e,i){if(t&&"function"==typeof t.call)return t.apply(i,e)}function c(t,e,i,o){let a,r,l;if(s(t))if(r=t.length,o)for(a=r-1;a>=0;a--)e.call(i,t[a],a);else for(a=0;a<r;a++)e.call(i,t[a],a);else if(n(t))for(l=Object.keys(t),r=l.length,a=0;a<r;a++)e.call(i,t[l[a]],l[a])}function d(t,e){let i,s,n,o;if(!t||!e||t.length!==e.length)return!1;for(i=0,s=t.length;i<s;++i)if(n=t[i],o=e[i],n.datasetIndex!==o.datasetIndex||n.index!==o.index)return!1;return!0}function u(t){if(s(t))return t.map(u);if(n(t)){const e=Object.create(null),i=Object.keys(t),s=i.length;let n=0;for(;n<s;++n)e[i[n]]=u(t[i[n]]);return e}return t}function f(t){return-1===["__proto__","prototype","constructor"].indexOf(t)}function g(t,e,i,s){if(!f(t))return;const o=e[t],a=i[t];n(o)&&n(a)?p(o,a,s):e[t]=u(a)}function p(t,e,i){const o=s(e)?e:[e],a=o.length;if(!n(t))return t;const r=(i=i||{}).merger||g;let l;for(let e=0;e<a;++e){if(l=o[e],!n(l))continue;const s=Object.keys(l);for(let e=0,n=s.length;e<n;++e)r(s[e],t,l,i)}return t}function m(t,e){return p(t,e,{merger:x})}function x(t,e,i){if(!f(t))return;const s=e[t],o=i[t];n(s)&&n(o)?m(s,o):Object.prototype.hasOwnProperty.call(e,t)||(e[t]=u(o))}const b={"":t=>t,x:t=>t.x,y:t=>t.y};function _(t,e){const i=b[e]||(b[e]=function(t){const e=function(t){const e=t.split("."),i=[];let s="";for(const t of e)s+=t,s.endsWith("\\")?s=s.slice(0,-1)+".":(i.push(s),s="");return i}(t);return t=>{for(const i of e){if(""===i)break;t=t&&t[i]}return t}}(e));return i(t)}function y(t){return t.charAt(0).toUpperCase()+t.slice(1)}const v=t=>void 0!==t,M=t=>"function"==typeof t,w=(t,e)=>{if(t.size!==e.size)return!1;for(const i of t)if(!e.has(i))return!1;return!0};const k=Math.PI,S=2*k,P=S+k,D=Number.POSITIVE_INFINITY,O=k/180,C=k/2,A=k/4,T=2*k/3,L=Math.log10,E=Math.sign;function R(t,e,i){return Math.abs(t-e)<i}function I(t){const e=Math.round(t);t=R(t,e,t/1e3)?e:t;const i=Math.pow(10,Math.floor(L(t))),s=t/i;return(s<=1?1:s<=2?2:s<=5?5:10)*i}function F(t){return!function(t){return"symbol"==typeof t||"object"==typeof t&&null!==t&&!(Symbol.toPrimitive in t||"toString"in t||"valueOf"in t)}(t)&&!isNaN(parseFloat(t))&&isFinite(t)}function z(t,e,i){let s,n,o;for(s=0,n=t.length;s<n;s++)o=t[s][i],isNaN(o)||(e.min=Math.min(e.min,o),e.max=Math.max(e.max,o))}function V(t){return t*(k/180)}function B(t){return t*(180/k)}function W(t){if(!o(t))return;let e=1,i=0;for(;Math.round(t*e)/e!==t;)e*=10,i++;return i}function N(t,e){const i=e.x-t.x,s=e.y-t.y,n=Math.sqrt(i*i+s*s);let o=Math.atan2(s,i);return o<-.5*k&&(o+=S),{angle:o,distance:n}}function H(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function j(t,e){return(t-e+P)%S-k}function $(t){return(t%S+S)%S}function Y(t,e,i,s){const n=$(t),o=$(e),a=$(i),r=$(o-n),l=$(a-n),h=$(n-o),c=$(n-a);return n===o||n===a||s&&o===a||r>l&&h<c}function U(t,e,i){return Math.max(e,Math.min(i,t))}function X(t,e,i,s=1e-6){return t>=Math.min(e,i)-s&&t<=Math.max(e,i)+s}function q(t,e,i){i=i||(i=>t[i]<e);let s,n=t.length-1,o=0;for(;n-o>1;)s=o+n>>1,i(s)?o=s:n=s;return{lo:o,hi:n}}const K=(t,e,i,s)=>q(t,i,s?s=>{const n=t[s][e];return n<i||n===i&&t[s+1][e]===i}:s=>t[s][e]<i),G=(t,e,i)=>q(t,i,(s=>t[s][e]>=i));const J=["push","pop","shift","splice","unshift"];function Z(t,e){const i=t._chartjs;if(!i)return;const s=i.listeners,n=s.indexOf(e);-1!==n&&s.splice(n,1),s.length>0||(J.forEach((e=>{delete t[e]})),delete t._chartjs)}function Q(t){const e=new Set(t);return e.size===t.length?t:Array.from(e)}const tt="undefined"==typeof window?function(t){return t()}:window.requestAnimationFrame;function et(t,e){let i=[],s=!1;return function(...n){i=n,s||(s=!0,tt.call(window,(()=>{s=!1,t.apply(e,i)})))}}const it=t=>"start"===t?"left":"end"===t?"right":"center",st=(t,e,i)=>"start"===t?e:"end"===t?i:(e+i)/2;function nt(t,e,s){const n=e.length;let o=0,a=n;if(t._sorted){const{iScale:r,vScale:l,_parsed:h}=t,c=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null,d=r.axis,{min:u,max:f,minDefined:g,maxDefined:p}=r.getUserBounds();if(g){if(o=Math.min(K(h,d,u).lo,s?n:K(e,d,r.getPixelForValue(u)).lo),c){const t=h.slice(0,o+1).reverse().findIndex((t=>!i(t[l.axis])));o-=Math.max(0,t)}o=U(o,0,n-1)}if(p){let t=Math.max(K(h,r.axis,f,!0).hi+1,s?0:K(e,d,r.getPixelForValue(f),!0).hi+1);if(c){const e=h.slice(t-1).findIndex((t=>!i(t[l.axis])));t+=Math.max(0,e)}a=U(t,o,n)-o}else a=n-o}return{start:o,count:a}}function ot(t){const{xScale:e,yScale:i,_scaleRanges:s}=t,n={xmin:e.min,xmax:e.max,ymin:i.Line truncated
|
||||||
|
/*!
|
||||||
|
* @kurkle/color v0.3.2
|
||||||
|
* https://github.com/kurkle/color#readme
|
||||||
|
* (c) 2023 Jukka Kurkela
|
||||||
|
* Released under the MIT License
|
||||||
|
*/
|
||||||
|
function ut(t){return t+.5|0}const ft=(t,e,i)=>Math.max(Math.min(t,i),e);function gt(t){return ft(ut(2.55*t),0,255)}function pt(t){return ft(ut(255*t),0,255)}function mt(t){return ft(ut(t/2.55)/100,0,1)}function xt(t){return ft(ut(100*t),0,100)}const bt={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},_t=[..."0123456789ABCDEF"],yt=t=>_t[15&t],vt=t=>_t[(240&t)>>4]+_t[15&t],Mt=t=>(240&t)>>4==(15&t);function wt(t){var e=(t=>Mt(t.r)&&Mt(t.g)&&Mt(t.b)&&Mt(t.a))(t)?yt:vt;return t?"#"+e(t.r)+e(t.g)+e(t.b)+((t,e)=>t<255?e(t):"")(t.a,e):void 0}const kt=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function St(t,e,i){const s=e*Math.min(i,1-i),n=(e,n=(e+t/30)%12)=>i-s*Math.max(Math.min(n-3,9-n,1),-1);return[n(0),n(8),n(4)]}function Pt(t,e,i){const s=(s,n=(s+t/60)%6)=>i-i*e*Math.max(Math.min(n,4-n,1),0);return[s(5),s(3),s(1)]}function Dt(t,e,i){const s=St(t,1,.5);let n;for(e+i>1&&(n=1/(e+i),e*=n,i*=n),n=0;n<3;n++)s[n]*=1-e-i,s[n]+=e;return s}function Ot(t){const e=t.r/255,i=t.g/255,s=t.b/255,n=Math.max(e,i,s),o=Math.min(e,i,s),a=(n+o)/2;let r,l,h;return n!==o&&(h=n-o,l=a>.5?h/(2-n-o):h/(n+o),r=function(t,e,i,s,n){return t===n?(e-i)/s+(e<i?6:0):e===n?(i-t)/s+2:(t-e)/s+4}(e,i,s,h,n),r=60*r+.5),[0|r,l||0,a]}function Ct(t,e,i,s){return(Array.isArray(e)?t(e[0],e[1],e[2]):t(e,i,s)).map(pt)}function At(t,e,i){return Ct(St,t,e,i)}function Tt(t){return(t%360+360)%360}function Lt(t){const e=kt.exec(t);let i,s=255;if(!e)return;e[5]!==i&&(s=e[6]?gt(+e[5]):pt(+e[5]));const n=Tt(+e[2]),o=+e[3]/100,a=+e[4]/100;return i="hwb"===e[1]?function(t,e,i){return Ct(Dt,t,e,i)}(n,o,a):"hsv"===e[1]?function(t,e,i){return Ct(Pt,t,e,i)}(n,o,a):At(n,o,a),{r:i[0],g:i[1],b:i[2],a:s}}const Et={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},Rt={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};let It;function Ft(t){It||(It=function(){const t={},e=Object.keys(Rt),i=Object.keys(Et);let s,n,o,a,r;for(s=0;s<e.length;s++){for(a=r=e[s],n=0;n<i.length;n++)o=i[n],r=r.replace(o,Et[o]);o=parseInt(Rt[a],16),t[r]=[o>>16&255,o>>8&255,255&o]}return t}(),It.transparent=[0,0,0,0]);const e=It[t.toLowerCase()];return e&&{r:e[0],g:e[1],b:e[2],a:4===e.length?e[3]:255}}const zt=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;const Vt=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,Bt=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4);function Wt(t,e,i){if(t){let s=Ot(t);s[e]=Math.max(0,Math.min(s[e]+s[e]*i,0===e?360:1)),s=ALine truncated
|
||||||
@@ -2,4 +2,13 @@
|
|||||||
.ui-autocomplete .autocomplete-meta {
|
.ui-autocomplete .autocomplete-meta {
|
||||||
color: #888;
|
color: #888;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
}
|
}
|
||||||
|
/* Contextual links on their own line under the page title (customer and vehicle pages), where a long title and
|
||||||
|
many links would otherwise crowd each other */
|
||||||
|
#content .contextual.qbo-under-title {
|
||||||
|
float: none;
|
||||||
|
text-align: right;
|
||||||
|
white-space: normal;
|
||||||
|
margin: -4px 0 10px;
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
+19
-5
@@ -65,7 +65,8 @@ en:
|
|||||||
label_new_customer: "New Customer"
|
label_new_customer: "New Customer"
|
||||||
label_new_issue: "New Issue"
|
label_new_issue: "New Issue"
|
||||||
label_qbo_never_synced: "Never Synced"
|
label_qbo_never_synced: "Never Synced"
|
||||||
label_no_customers: "There are no customers matching the search term(s)."
|
label_no_customers: "No customers match \"%{search}\"."
|
||||||
|
text_customers_best_match: "%{count} best matches, closest first. Click a column to sort them by it instead."
|
||||||
label_no_estimates: "No Estimates"
|
label_no_estimates: "No Estimates"
|
||||||
label_no_invoices: "No Invoices"
|
label_no_invoices: "No Invoices"
|
||||||
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
label_oauth2_refresh_token_expires_at: "Refresh Token Expires At"
|
||||||
@@ -240,8 +241,11 @@ en:
|
|||||||
label_invoice_balance: "Balance due %{balance}"
|
label_invoice_balance: "Balance due %{balance}"
|
||||||
label_invoice_date: "Invoice date"
|
label_invoice_date: "Invoice date"
|
||||||
label_invoice_no: "Invoice no."
|
label_invoice_no: "Invoice no."
|
||||||
label_invoice_paid: "Paid"
|
label_invoice_status_paid: "Paid"
|
||||||
label_invoice_partially_paid: "Partially paid"
|
label_invoice_status_partial: "Partially paid"
|
||||||
|
label_invoice_status_overdue: "Overdue"
|
||||||
|
label_invoice_status_open: "Open"
|
||||||
|
label_invoice_status_voided: "Voided"
|
||||||
label_message_on_invoice: "Message displayed on invoice"
|
label_message_on_invoice: "Message displayed on invoice"
|
||||||
label_new_invoice: "New invoice"
|
label_new_invoice: "New invoice"
|
||||||
label_open_estimates: "Open estimates"
|
label_open_estimates: "Open estimates"
|
||||||
@@ -253,7 +257,7 @@ en:
|
|||||||
text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?"
|
text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?"
|
||||||
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
|
||||||
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
|
||||||
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). The time goes where the first ticked line is."
|
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). Each time entry takes the place of the line with its issue's description (e.g. Install Lift Kit), then any others in order."
|
||||||
|
|
||||||
# Issues from estimates (moved from redmine_qbo_calendar)
|
# Issues from estimates (moved from redmine_qbo_calendar)
|
||||||
button_create_estimate_issues_submit: "Create issues"
|
button_create_estimate_issues_submit: "Create issues"
|
||||||
@@ -306,6 +310,8 @@ en:
|
|||||||
permission_view_business_reports: "View business reports"
|
permission_view_business_reports: "View business reports"
|
||||||
label_business_report: "Business report"
|
label_business_report: "Business report"
|
||||||
label_report_period: "Period"
|
label_report_period: "Period"
|
||||||
|
label_report_period_this_week: "This week"
|
||||||
|
label_report_period_last_week: "Last week"
|
||||||
label_report_period_this_month: "This month"
|
label_report_period_this_month: "This month"
|
||||||
label_report_period_last_month: "Last month"
|
label_report_period_last_month: "Last month"
|
||||||
label_report_period_this_quarter: "This quarter"
|
label_report_period_this_quarter: "This quarter"
|
||||||
@@ -316,6 +322,8 @@ en:
|
|||||||
label_report_money: "Sales"
|
label_report_money: "Sales"
|
||||||
label_report_hours: "Hours"
|
label_report_hours: "Hours"
|
||||||
label_report_by_month: "By month"
|
label_report_by_month: "By month"
|
||||||
|
label_report_compare_last_year: "Compare with last year"
|
||||||
|
label_report_last_year: "last year"
|
||||||
label_report_estimates_written: "Estimates written"
|
label_report_estimates_written: "Estimates written"
|
||||||
label_report_invoices_written: "Invoices written"
|
label_report_invoices_written: "Invoices written"
|
||||||
label_report_payments_received: "Payments received"
|
label_report_payments_received: "Payments received"
|
||||||
@@ -326,7 +334,9 @@ en:
|
|||||||
label_report_invoiced_of_estimated: "Invoiced vs. estimated"
|
label_report_invoiced_of_estimated: "Invoiced vs. estimated"
|
||||||
label_report_collected_of_invoiced: "Collected vs. invoiced"
|
label_report_collected_of_invoiced: "Collected vs. invoiced"
|
||||||
label_report_open_balance: "Still owed on these invoices"
|
label_report_open_balance: "Still owed on these invoices"
|
||||||
label_report_invoiced_of_spent: "Invoiced vs. spent hours"
|
label_report_cpi: "Cost performance index (CPI)"
|
||||||
|
label_report_cpi_short: "CPI"
|
||||||
|
text_report_cpi: "Invoiced hours ÷ spent hours. 1.00 or more (green): every hour worked was billed; below 1 (yellow): some time wasn't billed; below 0.80 (red): a fifth or more wasn't."
|
||||||
label_report_spent_of_estimated: "Spent vs. issues' estimated hours"
|
label_report_spent_of_estimated: "Spent vs. issues' estimated hours"
|
||||||
text_report_syncing: "QuickBooks is still syncing, so these figures are incomplete until it finishes. This page refreshes every 30 seconds."
|
text_report_syncing: "QuickBooks is still syncing, so these figures are incomplete until it finishes. This page refreshes every 30 seconds."
|
||||||
text_qbo_sync_running: "syncing, %{count} read so far (started %{time})"
|
text_qbo_sync_running: "syncing, %{count} read so far (started %{time})"
|
||||||
@@ -334,6 +344,10 @@ en:
|
|||||||
text_qbo_sync_queued: "waiting to sync"
|
text_qbo_sync_queued: "waiting to sync"
|
||||||
text_report_needs_sync: "%{count} estimates or invoices in this period don't have their total or hours yet. Run a full sync from QuickBooks to fill them in."
|
text_report_needs_sync: "%{count} estimates or invoices in this period don't have their total or hours yet. Run a full sync from QuickBooks to fill them in."
|
||||||
text_report_notes: "Estimates, invoices and payments count by their QuickBooks date; their hours are the quantities of the labor products/services. Issues' estimated time counts issues created in the period, without subtasks. Spent time counts time logged in the period."
|
text_report_notes: "Estimates, invoices and payments count by their QuickBooks date; their hours are the quantities of the labor products/services. Issues' estimated time counts issues created in the period, without subtasks. Spent time counts time logged in the period."
|
||||||
|
label_report_remember_projects: "Remember these projects"
|
||||||
|
text_report_projects: "For issues' estimated time and spent time. None picked: every project. Ctrl/Cmd-click to pick several."
|
||||||
|
text_report_saved_projects: "Opens with: %{projects}"
|
||||||
|
text_report_projects_filtered: "Only issues' estimated time and spent time are limited to these projects. Estimates, invoices and payments come from QuickBooks, which has no projects, so they cover the whole business (and so does the CPI's invoiced hours)."
|
||||||
notice_payment_not_found: "Payment not found in QuickBooks"
|
notice_payment_not_found: "Payment not found in QuickBooks"
|
||||||
notice_payment_saved: "Payment of %{amount} saved in QuickBooks"
|
notice_payment_saved: "Payment of %{amount} saved in QuickBooks"
|
||||||
text_no_payment_methods: "QuickBooks' payment methods couldn't be read. Check the QuickBooks connection."
|
text_no_payment_methods: "QuickBooks' payment methods couldn't be read. Check the QuickBooks connection."
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
name 'Redmine QBO plugin'
|
name 'Redmine QBO plugin'
|
||||||
author 'Rick Barrette'
|
author 'Rick Barrette'
|
||||||
description 'A pluging for Redmine to connect with QuickBooks Online: customers, time activities for billable hours when an issue is closed, and estimates, invoices and payments written in Redmine'
|
description 'A pluging for Redmine to connect with QuickBooks Online: customers, time activities for billable hours when an issue is closed, and estimates, invoices and payments written in Redmine'
|
||||||
version '2026.11.3'
|
version '2026.11.6'
|
||||||
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'
|
||||||
@@ -27,9 +27,6 @@ Redmine::Plugin.register :redmine_qbo do
|
|||||||
User.safe_attributes :employee_id
|
User.safe_attributes :employee_id
|
||||||
TimeEntry.safe_attributes :billed
|
TimeEntry.safe_attributes :billed
|
||||||
|
|
||||||
# set per_page globally
|
|
||||||
WillPaginate.per_page = 20
|
|
||||||
|
|
||||||
# Global Permissions
|
# Global Permissions
|
||||||
# autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms
|
# autocomplete and the filter_* actions feed the customer, estimate and invoice pickers on issue forms
|
||||||
permission :view_customers, { customers: [:index, :show, :autocomplete,
|
permission :view_customers, { customers: [:index, :show, :autocomplete,
|
||||||
|
|||||||
@@ -16,17 +16,24 @@ module RedmineQboBilling
|
|||||||
# hours: man-hours on estimates, issues' estimated time, man-hours invoiced, time spent
|
# hours: man-hours on estimates, issues' estimated time, man-hours invoiced, time spent
|
||||||
# with a month-by-month breakdown. Estimates, invoices and payments count by their QuickBooks date, issues by
|
# with a month-by-month breakdown. Estimates, invoices and payments count by their QuickBooks date, issues by
|
||||||
# the day they were created (only issues without subtasks, so parents' totals aren't counted twice), and
|
# the day they were created (only issues without subtasks, so parents' totals aren't counted twice), and
|
||||||
# spent time by the day it was spent.
|
# spent time by the day it was spent. project_ids limits the issues and spent time to those projects; the
|
||||||
|
# QuickBooks figures have no project, so they always cover the whole business.
|
||||||
class BusinessReport
|
class BusinessReport
|
||||||
PERIODS = %w[this_month last_month this_quarter last_quarter this_year last_year custom].freeze
|
PERIODS = %w[this_week last_week this_month last_month this_quarter last_quarter this_year last_year custom].freeze
|
||||||
|
WEEK_DAYS = { 1 => :monday, 6 => :saturday, 7 => :sunday }.freeze
|
||||||
|
# Chart points: a day each for up to two weeks, a week each up to about three months, else a month each
|
||||||
|
DAILY_UP_TO = 14
|
||||||
|
WEEKLY_UP_TO = 93
|
||||||
MONEY = %i[estimates invoices payments].freeze
|
MONEY = %i[estimates invoices payments].freeze
|
||||||
HOURS = %i[estimate_hours issue_hours invoice_hours spent_hours].freeze
|
HOURS = %i[estimate_hours issue_hours invoice_hours spent_hours].freeze
|
||||||
|
|
||||||
attr_reader :from, :to, :period
|
attr_reader :from, :to, :period, :project_ids
|
||||||
|
|
||||||
# The dates for a period, from today: [from, to]. "custom" uses the given dates (either can be blank).
|
# The dates for a period, from today: [from, to]. "custom" uses the given dates (either can be blank).
|
||||||
def self.range_for(period, today: Date.current, from: nil, to: nil)
|
def self.range_for(period, today: Date.current, from: nil, to: nil, week_start: :monday)
|
||||||
case period.to_s
|
case period.to_s
|
||||||
|
when 'this_week' then [today.beginning_of_week(week_start), today.end_of_week(week_start)]
|
||||||
|
when 'last_week' then w = today - 7; [w.beginning_of_week(week_start), w.end_of_week(week_start)]
|
||||||
when 'this_month' then [today.beginning_of_month, today.end_of_month]
|
when 'this_month' then [today.beginning_of_month, today.end_of_month]
|
||||||
when 'last_month' then m = today.prev_month; [m.beginning_of_month, m.end_of_month]
|
when 'last_month' then m = today.prev_month; [m.beginning_of_month, m.end_of_month]
|
||||||
when 'this_quarter' then [today.beginning_of_quarter, today.end_of_quarter]
|
when 'this_quarter' then [today.beginning_of_quarter, today.end_of_quarter]
|
||||||
@@ -49,11 +56,94 @@ module RedmineQboBilling
|
|||||||
|
|
||||||
# data (for tests): { estimates: [[date, total, hours]], invoices: [[date, total, hours, balance]],
|
# data (for tests): { estimates: [[date, total, hours]], invoices: [[date, total, hours, balance]],
|
||||||
# payments: [[date, total]], issues: [[date, estimated_hours]], time_entries: [[date, hours]] }
|
# payments: [[date, total]], issues: [[date, estimated_hours]], time_entries: [[date, hours]] }
|
||||||
def initialize(period: 'this_year', from: nil, to: nil, today: Date.current, data: nil)
|
# week_start: the first day of a week (:monday, :saturday or :sunday); see week_start_from_setting.
|
||||||
|
# previous_data (for tests): last year's data, like data.
|
||||||
|
# project_ids: the projects whose issues and spent time count; blank for every project.
|
||||||
|
def initialize(period: 'this_year', from: nil, to: nil, today: Date.current, data: nil, week_start: :monday,
|
||||||
|
previous_data: nil, project_ids: nil)
|
||||||
@period = PERIODS.include?(period.to_s) ? period.to_s : 'this_year'
|
@period = PERIODS.include?(period.to_s) ? period.to_s : 'this_year'
|
||||||
@from, @to = self.class.range_for(@period, today: today, from: from, to: to)
|
@week_start = week_start
|
||||||
|
@from, @to = self.class.range_for(@period, today: today, from: from, to: to, week_start: week_start)
|
||||||
@today = today
|
@today = today
|
||||||
@data = data
|
@data = data
|
||||||
|
@previous_data = previous_data
|
||||||
|
@project_ids = Array(project_ids).map(&:to_i).select(&:positive?).uniq
|
||||||
|
end
|
||||||
|
|
||||||
|
# Whether the issues and spent time are limited to some projects
|
||||||
|
def projects_filtered?
|
||||||
|
project_ids.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Redmine's "Start calendars on" setting (1 Monday, 6 Saturday, 7 Sunday); Monday when it follows the language
|
||||||
|
def self.week_start_from_setting(value)
|
||||||
|
WEEK_DAYS[value.to_i] || :monday
|
||||||
|
end
|
||||||
|
|
||||||
|
# ---- charts ----
|
||||||
|
|
||||||
|
# :day, :week or :month, from the length of the period
|
||||||
|
def granularity
|
||||||
|
days = (to - from).to_i + 1
|
||||||
|
return :day if days <= DAILY_UP_TO
|
||||||
|
days <= WEEKLY_UP_TO ? :week : :month
|
||||||
|
end
|
||||||
|
|
||||||
|
# The chart's points as [first day, last day] pairs covering the period
|
||||||
|
def buckets
|
||||||
|
@buckets ||= begin
|
||||||
|
list = []
|
||||||
|
case granularity
|
||||||
|
when :day
|
||||||
|
(from..to).each { |day| list << [day, day] }
|
||||||
|
when :week
|
||||||
|
start = from.beginning_of_week(@week_start)
|
||||||
|
while start <= to
|
||||||
|
list << [[start, from].max, [start + 6, to].min]
|
||||||
|
start += 7
|
||||||
|
end
|
||||||
|
else
|
||||||
|
start = from.beginning_of_month
|
||||||
|
while start <= to
|
||||||
|
list << [[start, from].max, [start.end_of_month, to].min]
|
||||||
|
start = start.next_month
|
||||||
|
end
|
||||||
|
end
|
||||||
|
list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# The same points a year earlier. Days and weeks go back 52 weeks, so a Monday lines up with a Monday;
|
||||||
|
# months go back to the same month.
|
||||||
|
def previous_buckets
|
||||||
|
@previous_buckets ||= if granularity == :month
|
||||||
|
buckets.map { |a, b| [a.prev_year, b.prev_year] }
|
||||||
|
else
|
||||||
|
buckets.map { |a, b| [a - 364, b - 364] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Everything the line charts need: the points' start dates, this period's figures per point (nil after
|
||||||
|
# today, so the line stops there), and last year's for the same points (the toggle shows them).
|
||||||
|
# { granularity:, points: ["2026-10-26", ...],
|
||||||
|
# current: { estimates: [...], invoices:, payments:, estimate_hours:, issue_hours:, invoice_hours:, spent_hours: },
|
||||||
|
# previous: { same keys } }
|
||||||
|
def chart
|
||||||
|
current = sums_by_bucket(data, buckets)
|
||||||
|
current.each_value { |values| buckets.each_with_index { |(a, _), i| values[i] = nil if a > @today } }
|
||||||
|
{
|
||||||
|
granularity: granularity,
|
||||||
|
points: buckets.map { |a, _| a.iso8601 },
|
||||||
|
ends: buckets.map { |_, b| b.iso8601 },
|
||||||
|
previous_points: previous_buckets.map { |a, _| a.iso8601 },
|
||||||
|
current: current,
|
||||||
|
previous: sums_by_bucket(previous_data, previous_buckets)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Last year's data for the chart's points
|
||||||
|
def previous_data
|
||||||
|
@previous_data ||= load_data(previous_buckets.first[0], previous_buckets.last[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@@ -79,6 +169,26 @@ module RedmineQboBilling
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Cost performance index: invoiced hours / spent hours (e.g. 0.85), or nil without spent time. Below
|
||||||
|
# CPI_WARNING (0.8) is poor, below 1 is under, 1 or more is on or over (more billed than worked).
|
||||||
|
CPI_WARNING = 0.8
|
||||||
|
|
||||||
|
def self.cpi(invoice_hours, spent_hours)
|
||||||
|
spent = spent_hours.to_f
|
||||||
|
spent.positive? ? (invoice_hours.to_f / spent).round(2) : nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# :poor (below 0.8), :under (below 1) or :good (1 or more); nil without a CPI
|
||||||
|
def self.cpi_level(cpi)
|
||||||
|
return nil if cpi.nil?
|
||||||
|
return :poor if cpi < CPI_WARNING
|
||||||
|
cpi < 1 ? :under : :good
|
||||||
|
end
|
||||||
|
|
||||||
|
def cpi
|
||||||
|
self.class.cpi(hours[:invoice_hours], hours[:spent_hours])
|
||||||
|
end
|
||||||
|
|
||||||
# Percentages comparing the figures (nil when there's nothing to compare against)
|
# Percentages comparing the figures (nil when there's nothing to compare against)
|
||||||
def ratios
|
def ratios
|
||||||
{
|
{
|
||||||
@@ -126,17 +236,41 @@ module RedmineQboBilling
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def load_data
|
# { money key or hours key => [sum per bucket] } for the data, in buckets ([first day, last day] pairs)
|
||||||
|
def sums_by_bucket(rows, bucket_list)
|
||||||
|
sums = (MONEY + HOURS).index_with { |_| Array.new(bucket_list.size, 0.0) }
|
||||||
|
find = lambda do |date|
|
||||||
|
bucket_list.index { |a, b| date >= a && date <= b }
|
||||||
|
end
|
||||||
|
columns = {
|
||||||
|
estimates: [:estimates, 1], invoices: [:invoices, 1], payments: [:payments, 1],
|
||||||
|
estimate_hours: [:estimates, 2], issue_hours: [:issues, 1], invoice_hours: [:invoices, 2], spent_hours: [:time_entries, 1]
|
||||||
|
}
|
||||||
|
columns.each do |key, (source, col)|
|
||||||
|
Array(rows[source]).each do |row|
|
||||||
|
i = find.call(row[0]) or next
|
||||||
|
sums[key][i] += MONEY.include?(key) ? to_d(row[col]).to_f : row[col].to_f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sums.transform_values { |values| values.map { |v| v.round(2) } }
|
||||||
|
end
|
||||||
|
|
||||||
|
def load_data(from = self.from, to = self.to)
|
||||||
dates = from..to
|
dates = from..to
|
||||||
times = from.in_time_zone.beginning_of_day..to.in_time_zone.end_of_day
|
times = from.in_time_zone.beginning_of_day..to.in_time_zone.end_of_day
|
||||||
leaf = "#{Issue.table_name}.rgt IS NULL OR #{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"
|
leaf = "#{Issue.table_name}.rgt IS NULL OR #{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"
|
||||||
|
issues = Issue.where(created_on: times).where(leaf).where.not(estimated_hours: nil)
|
||||||
|
time_entries = TimeEntry.where(spent_on: dates)
|
||||||
|
if projects_filtered?
|
||||||
|
issues = issues.where(project_id: project_ids)
|
||||||
|
time_entries = time_entries.where(project_id: project_ids)
|
||||||
|
end
|
||||||
{
|
{
|
||||||
estimates: Estimate.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours),
|
estimates: Estimate.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours),
|
||||||
invoices: Invoice.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours, :balance),
|
invoices: Invoice.where(txn_date: dates).pluck(:txn_date, :total_amount, :hours, :balance),
|
||||||
payments: Payment.where(txn_date: dates).pluck(:txn_date, :total_amount),
|
payments: Payment.where(txn_date: dates).pluck(:txn_date, :total_amount),
|
||||||
issues: Issue.where(created_on: times).where(leaf).where.not(estimated_hours: nil)
|
issues: issues.pluck(:created_on, :estimated_hours).map { |t, h| [t.in_time_zone.to_date, h] },
|
||||||
.pluck(:created_on, :estimated_hours).map { |t, h| [t.in_time_zone.to_date, h] },
|
time_entries: time_entries.pluck(:spent_on, :hours)
|
||||||
time_entries: TimeEntry.where(spent_on: dates).pluck(:spent_on, :hours)
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#The MIT License (MIT)
|
||||||
|
#
|
||||||
|
#Copyright (c) 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 RedmineQboBilling
|
||||||
|
# An invoice's status, worked out from its total, balance and due date the way QuickBooks' invoice list
|
||||||
|
# shows it (QuickBooks keeps no status field on invoices):
|
||||||
|
# :voided - nothing to pay at all (a voided invoice has a zero total)
|
||||||
|
# :paid - nothing left owing
|
||||||
|
# :partial - some of it paid
|
||||||
|
# :overdue - money owing and past the due date
|
||||||
|
# :open - money owing, not yet due
|
||||||
|
# nil when the balance isn't known (e.g. an invoice synced before balances were kept).
|
||||||
|
module InvoiceStatus
|
||||||
|
STATUSES = %i[voided paid partial overdue open].freeze
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def status(total:, balance:, due_date: nil, today: Date.current)
|
||||||
|
return nil if balance.nil? || balance.to_s.strip.empty?
|
||||||
|
|
||||||
|
total = to_d(total)
|
||||||
|
balance = to_d(balance)
|
||||||
|
return :voided if total.zero? && balance.zero?
|
||||||
|
return :paid if balance <= 0
|
||||||
|
return :overdue if due_date && due_date < today
|
||||||
|
balance < total ? :partial : :open
|
||||||
|
end
|
||||||
|
|
||||||
|
def label(status)
|
||||||
|
status ? I18n.t("label_invoice_status_#{status}") : ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_d(value)
|
||||||
|
BigDecimal(value.to_s.presence || '0')
|
||||||
|
rescue ArgumentError
|
||||||
|
BigDecimal('0')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user