mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-19 10:40:36 -05:00
Completed work that's billed and paid in full can be refunded from its invoice (Refund on the invoice, or Paid invoice on the customer's Refund page). It makes a QuickBooks Refund Receipt: the invoice lines refunded (all or part, by quantity or amount) with their products/services and tax codes, the invoice discount's share, and the restocking fee as a negative line when it's ticked: the fee rate of the parts refunded, so labor-only work has none. Paid out of the refund check or card account, with the check number. Each refund records the lines it refunded, so a line can't be refunded for more than it was billed across refunds. Optionally notes the refund on the invoice's work orders and emails the customer. The refund page, PDF and email show the lines, tax and fee. Migration 056 adds the columns to qbo_refunds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
5.5 KiB
ERB
98 lines
5.5 KiB
ERB
<%# A refund as it was made (SOP-OPS-014) %>
|
|
<% html_title l(:label_refund) %>
|
|
<% money = ->(amount) { RedmineQboBilling::RefundWriter.money(amount) } %>
|
|
|
|
<h2>
|
|
<%= link_to l(:label_customers), customers_path %> »
|
|
<% if @customer %><%= link_to @customer.name, customer_path(@customer) %> »<% end %>
|
|
<%= l(:label_refund) %> <%= format_date(@refund.txn_date) %>
|
|
</h2>
|
|
|
|
<div class="contextual">
|
|
<%= link_to sprite_icon('application-pdf', 'PDF'), pdf_qbo_refund_path(@refund), class: 'icon icon-pdf', target: :_blank %>
|
|
<% if @refund.fee_invoice_id.present? %>
|
|
<%= link_to sprite_icon('application-pdf', l(:label_refund_fee_invoice_pdf)), invoice_path(@refund.fee_invoice_id), class: 'icon icon-pdf', target: :_blank %>
|
|
<% end %>
|
|
</div>
|
|
|
|
<% if @refund.done? && @refund.invoice? %>
|
|
<p class="notice flash"><%= l(:text_refund_receipt_made, number: @refund.receipt_number.presence || @refund.purchase_id) %></p>
|
|
<% elsif @refund.done? %>
|
|
<p class="<%= @refund.balance_after.to_d.zero? ? 'notice flash' : 'warning' %>">
|
|
<%= @refund.balance_after.nil? ? l(:text_refund_balance_unknown) : l(:text_refund_balance, balance: money.(@refund.balance_after)) %>
|
|
</p>
|
|
<% else %>
|
|
<p class="conflict"><%= l(:text_refund_incomplete) %></p>
|
|
<% end %>
|
|
<% if @refund.message.present? %>
|
|
<div class="warning"><%= simple_format(h(@refund.message)) %></div>
|
|
<% end %>
|
|
|
|
<div class="box tabular">
|
|
<% if @refund.invoice? %>
|
|
<p><label><%= l(:label_refund_invoice) %></label>
|
|
<%= link_to @refund.document_label, RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(@refund.invoice_id) : invoice_path(@refund.invoice_id) %>
|
|
· <%= l(:label_refund_paid_on_invoice) %> <%= money.(@refund.credit_amount) %></p>
|
|
<p><label><%= l(:label_refund_reason) %></label> <%= @refund.reason %></p>
|
|
<p><label><%= l(:label_refund_lines_amount) %></label> <%= money.(@refund.lines_amount) %></p>
|
|
<% if @refund.refunded_lines.any? %>
|
|
<table class="list" style="max-width: 50em">
|
|
<tbody>
|
|
<% @refund.refunded_lines.each do |line| %>
|
|
<tr>
|
|
<td style="text-align: left"><%= line.description %></td>
|
|
<td><%= l(line.parts ? :label_refund_parts : :label_refund_labor) %></td>
|
|
<td style="text-align: right"><%= RedmineQboBilling::RefundWriter.plain(BigDecimal(line.quantity.to_s)) if line.quantity.present? %></td>
|
|
<td style="text-align: right"><%= money.(line.amount) %></td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
<% end %>
|
|
<% if @refund.discount_amount.to_d.positive? %>
|
|
<p><label><%= l(:label_refund_discount) %></label> -<%= money.(@refund.discount_amount) %></p>
|
|
<% end %>
|
|
<p><label><%= l(:label_refund_tax) %></label> <%= money.(@refund.tax_amount) %></p>
|
|
<% else %>
|
|
<p><label><%= l(:label_refund_estimate) %></label> <%= @refund.estimate_id.present? ? link_to("E#{@refund.estimate_number}", RedmineQboBilling.writer? ? edit_qbo_estimate_path(@refund.estimate_id) : estimate_path(@refund.estimate_id)) : l(:label_refund_no_estimate) %></p>
|
|
<p><label><%= l(:label_refund_reason) %></label> <%= @refund.reason %></p>
|
|
<p><label><%= l(:label_refund_credit) %></label> <%= money.(@refund.credit_amount) %></p>
|
|
<% end %>
|
|
<p><label><%= l(:label_refund_parts) %></label> <%= money.(@refund.parts_amount) %></p>
|
|
<p>
|
|
<label><%= l(:label_refund_fee_rate, rate: RedmineQboBilling::RefundWriter.plain(@refund.fee_rate)) %></label>
|
|
<%= @refund.fee_amount.to_d.positive? ? money.(@refund.fee_amount) : l(:label_refund_no_fee) %>
|
|
<% if @refund.fee_invoice_id.present? %>
|
|
· <%= link_to l(:label_refund_fee_invoice, number: @refund.fee_invoice_number), RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(@refund.fee_invoice_id) : invoice_path(@refund.fee_invoice_id) %>
|
|
<% end %>
|
|
</p>
|
|
<p>
|
|
<label><%= l(:label_refund_amount) %></label>
|
|
<%= money.(@refund.refund_amount) %> · <%= @refund.method_name %><%= " ##{@refund.check_number}" if @refund.check? %>
|
|
<% if @refund.purchase_url %>
|
|
· <%= link_to l(@refund.invoice? ? :label_refund_open_receipt : (@refund.check? ? :label_refund_open_check : :label_refund_open_expense)),
|
|
@refund.purchase_url, target: '_blank', rel: 'noopener' %>
|
|
<% end %>
|
|
</p>
|
|
<% if @refund.estimate_number.present? %>
|
|
<p><label><%= l(:label_refund_close_estimate) %></label> <%= checked_image @refund.estimate_closed? %></p>
|
|
<% end %>
|
|
<% if @refund.noted_issue_ids.any? %>
|
|
<p><label><%= l(:label_refund_note_issues) %></label>
|
|
<%= safe_join(Issue.where(id: @refund.noted_issue_ids).map { |issue| link_to_issue(issue, project: false) }, ', ') %></p>
|
|
<% end %>
|
|
<% if @refund.canceled_issue_ids.any? %>
|
|
<p><label><%= l(:label_refund_cancel_issues) %></label>
|
|
<%= safe_join(Issue.where(id: @refund.canceled_issue_ids).map { |issue| link_to_issue(issue, project: false) }, ', ') %></p>
|
|
<% end %>
|
|
<p>
|
|
<label><%= l(:label_refund_email_customer) %></label> <%= @refund.emailed_to.presence || '—' %>
|
|
<% if @refund.done? %>
|
|
· <%= link_to sprite_icon('email', l(@refund.emailed_to.present? ? :button_refund_email_again : :button_refund_email)),
|
|
email_qbo_refund_path(@refund), method: :post, class: 'icon icon-email',
|
|
data: { confirm: l(:text_refund_email_confirm) } %>
|
|
<% end %>
|
|
</p>
|
|
<p><label><%= l(:field_author) %></label> <%= @refund.user ? link_to_user(@refund.user) : '' %> <%= format_time(@refund.created_at) %></p>
|
|
</div>
|