Add a customer payments page

Payments on the customer page lists the customer's QuickBooks payments, newest first, with the
invoices each was applied to, memo, amount, unapplied credit and totals; each links to the payment
page and its PDF. A new View payments permission allows the list, payment page and PDF; Receive
payments includes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 00:00:36 -04:00
1 parent 9121e079a0
commit 14f0409395
10 files changed
+133 -7

No files matched your search

+15 -1
View File
@@ -9,13 +9,27 @@
#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.
# Receives customer payments in QuickBooks: payment type and amount, applied to open invoices oldest first, or
# saved as a deposit. A saved payment can be printed (QuickBooks' payment PDF).
# saved as a deposit. A saved payment can be printed (QuickBooks' payment PDF). A customer's payments are
# listed on their payments page.
class QboPaymentsController < ApplicationController
before_action :authorize_global
QBO_ERRORS = QboEstimatesController::QBO_ERRORS
# The customer's payments, newest first, read from QuickBooks
def index
@customer = Customer.find_by(id: params[:customer_id])
return render_404 unless @customer
@payments = RedmineQboBilling::PaymentWriter.customer_payments(@customer)
@totals = RedmineQboBilling::PaymentWriter.payment_totals(@payments)
rescue *QBO_ERRORS => e
@payments = []
@totals = RedmineQboBilling::PaymentWriter.payment_totals([])
flash.now[:error] = qbo_message(e)
end
def new
customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present?
@form = RedmineQboBilling::PaymentWriter.new_form(customer: customer, user: User.current)
+3
View File
@@ -14,6 +14,9 @@
<% if RedmineQboBilling.invoice_writer? %>
<%= render partial: 'qbo_invoices/customer_link', locals: { customer: @customer } %>
<% end %>
<% if RedmineQboBilling.payment_viewer? %>
<%= link_to sprite_icon('list', l(:label_payments)), qbo_payments_path(customer_id: @customer.id), class: 'icon icon-list' %>
<% end %>
<% if RedmineQboBilling.payment_receiver? %>
<%= link_to sprite_icon('add', l(:button_receive_payment)), new_qbo_payment_path(customer_id: @customer.id), class: 'icon icon-add' %>
<% else %>
+82
View File
@@ -0,0 +1,82 @@
<% html_title @customer.name, l(:label_payments) %>
<div class="contextual">
<% if RedmineQboBilling.payment_receiver? %>
<%= link_to sprite_icon('add', l(:button_receive_payment)), new_qbo_payment_path(customer_id: @customer.id), class: 'icon icon-add' %>
<% 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>
<h2>
<%= link_to l(:label_customers), customers_path %> &#187;
<%= link_to @customer.name, customer_path(@customer) %> &#187;
<%= l(:label_payments) %>
</h2>
<% if @payments.empty? %>
<p class="nodata"><%= l(:label_no_payments) %></p>
<% else %>
<div class="autoscroll">
<table class="list qbo-payments">
<thead>
<tr>
<th><%= l(:label_payment_date) %></th>
<th><%= l(:label_payment_method) %></th>
<th><%= l(:label_payment_reference) %></th>
<th class="applied"><%= l(:label_payment_applies_to) %></th>
<th class="memo"><%= l(:label_memo) %></th>
<th class="amount"><%= l(:label_amount) %></th>
<th class="amount"><%= l(:label_payment_unapplied) %></th>
<th></th>
</tr>
</thead>
<tbody>
<% @payments.each do |payment| %>
<% applied = RedmineQboBilling::PaymentWriter.applied_invoices(payment) %>
<% unapplied = BigDecimal(payment.unapplied_amount.to_s.presence || '0') %>
<tr>
<td class="date"><%= link_to format_date(payment.txn_date), qbo_payment_path(payment.id) %></td>
<td><%= RedmineQboBilling::PaymentWriter.payment_method_name(payment) %></td>
<td><%= payment.payment_ref_number %></td>
<td class="applied">
<% if applied.empty? %>
<em><%= l(:label_payment_deposit) %></em>
<% else %>
<% applied.each do |invoice_id, number, amount| %>
<div>
<%= link_to "##{number}", RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(invoice_id) : invoice_path(invoice_id) %>
<%= number_to_currency(amount) %>
</div>
<% end %>
<% end %>
</td>
<td class="memo"><%= truncate(payment.private_note.to_s, length: 60) %></td>
<td class="amount"><%= number_to_currency(payment.total) %></td>
<td class="amount"><%= unapplied > 0 ? number_to_currency(unapplied) : '' %></td>
<td class="buttons">
<%= link_to sprite_icon('application-pdf', l(:button_print_payment)), pdf_qbo_payment_path(payment.id),
class: 'icon icon-pdf', target: :_blank %>
</td>
</tr>
<% end %>
</tbody>
<tfoot>
<tr class="total">
<td colspan="5"><strong><%= l(:label_payment_totals) %></strong> (<%= @payments.size %>)</td>
<td class="amount"><strong><%= number_to_currency(@totals[:received]) %></strong></td>
<td class="amount"><strong><%= @totals[:unapplied] > 0 ? number_to_currency(@totals[:unapplied]) : '' %></strong></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
<% end %>
<style>
table.qbo-payments td { vertical-align: top; }
table.qbo-payments .applied, table.qbo-payments .memo { text-align: left; }
table.qbo-payments .amount { text-align: right; white-space: nowrap; }
table.qbo-payments tfoot td { border-top: 2px solid #ccc; }
</style>
+3 -2
View File
@@ -3,7 +3,7 @@
<div class="contextual">
<%= link_to sprite_icon('application-pdf', l(:button_print_payment)), pdf_qbo_payment_path(@payment.id), class: 'icon icon-pdf', target: :_blank %>
<% if @customer %>
<% if @customer && RedmineQboBilling.payment_receiver? %>
<%= link_to sprite_icon('add', l(:button_receive_payment)), new_qbo_payment_path(customer_id: @customer.id), class: 'icon icon-add' %>
<% end %>
<%= link_to sprite_icon('link', l(:button_open_in_quickbooks)),
@@ -13,7 +13,8 @@
<h2>
<%= link_to l(:label_customers), customers_path %> &#187;
<% if @customer %><%= link_to @customer.name, customer_path(@customer) %> &#187;<% end %>
<% if @customer %><%= link_to @customer.name, customer_path(@customer) %> &#187;
<%= link_to l(:label_payments), qbo_payments_path(customer_id: @customer.id) %> &#187;<% end %>
<%= l(:label_payment) %> <%= number_to_currency(@payment.total) %>
</h2>