mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-19 18:40:36 -05:00
Refunds of paid invoices: refund receipt with optional restocking fee
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>
This commit is contained in:
1 parent
56859d1794
commit
c851929e02
21 files changed
+1380
-22
No files matched your search
@@ -8,7 +8,8 @@
|
||||
#
|
||||
#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.
|
||||
|
||||
# Customer refunds (SOP-OPS-014): the Refund page for a customer with credit, and a refund once it's made
|
||||
# Customer refunds (SOP-OPS-014): the Refund page for a customer with credit (a canceled order's deposit), the
|
||||
# Refund invoice page for completed work on a paid invoice, and a refund once it's made
|
||||
class QboRefundsController < ApplicationController
|
||||
before_action :authorize_global
|
||||
|
||||
@@ -43,6 +44,40 @@ class QboRefundsController < ApplicationController
|
||||
show_form
|
||||
end
|
||||
|
||||
# Refund of a paid invoice: its lines to pick from, the optional restocking fee, how the money goes back
|
||||
def new_invoice
|
||||
@form = RedmineQboBilling::InvoiceRefundForm.new(invoice_id: params[:invoice_id].to_s, txn_date: User.current.today.iso8601,
|
||||
method: 'check', charge_fee: '1', note_issues: '1', email_customer: '1')
|
||||
return unless load_invoice_page
|
||||
|
||||
@form.customer_id = @customer.id.to_s
|
||||
# Every line with something left to refund is ticked, at what's left of it
|
||||
@lines.select(&:refundable?).each do |line|
|
||||
@form.lines[line.key] = RedmineQboBilling::InvoiceRefundForm::LineChoice.new(
|
||||
refund: '1', quantity: (quantity = RedmineQboBilling::InvoiceRefundWriter.default_quantity(line)) && RedmineQboBilling::RefundWriter.plain(quantity),
|
||||
amount: format('%.2f', line.remaining_amount)
|
||||
)
|
||||
end
|
||||
load_invoice_plan
|
||||
end
|
||||
|
||||
def create_invoice
|
||||
@form = RedmineQboBilling::InvoiceRefundForm.from_params(params.require(:refund).permit(*RedmineQboBilling::InvoiceRefundForm.permitted))
|
||||
return unless load_invoice_page
|
||||
return show_invoice_form unless @form.valid?
|
||||
|
||||
refund = RedmineQboBilling::InvoiceRefundWriter.refund!(@form)
|
||||
if refund.done?
|
||||
flash[:notice] = l(:notice_refund_done, amount: RedmineQboBilling::RefundWriter.money(refund.refund_amount))
|
||||
else
|
||||
flash[:error] = refund.message
|
||||
end
|
||||
redirect_to qbo_refund_path(refund)
|
||||
rescue RedmineQboBilling::RefundWriter::Error, *QBO_ERRORS => e
|
||||
@form.errors.add(:base, qbo_message(e))
|
||||
show_invoice_form
|
||||
end
|
||||
|
||||
def show
|
||||
@refund = QboRefund.find_by(id: params[:id])
|
||||
return render_404 unless @refund
|
||||
@@ -88,6 +123,7 @@ class QboRefundsController < ApplicationController
|
||||
|
||||
def load_page
|
||||
@estimates = RedmineQboBilling::RefundWriter.estimate_choices(@customer)
|
||||
@invoices = RedmineQboBilling::InvoiceRefundWriter.invoice_choices(@customer)
|
||||
@preview = RedmineQboBilling::RefundWriter.preview(@customer, parts: @form.parts_value || BigDecimal('0'))
|
||||
@statuses = IssueStatus.sorted.to_a
|
||||
rescue *QBO_ERRORS => e
|
||||
@@ -100,6 +136,40 @@ class QboRefundsController < ApplicationController
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
# The paid invoice from QuickBooks, its customer and its lines; renders the error and returns false when it
|
||||
# can't be refunded
|
||||
def load_invoice_page
|
||||
gateway = RedmineQboBilling::RefundGateway.new
|
||||
@invoice = gateway.invoice(@form.invoice_id) if @form.invoice_id.present?
|
||||
@customer = Customer.find_by(id: @invoice&.customer_ref&.value)
|
||||
if @invoice.nil? || @customer.nil?
|
||||
render_404
|
||||
return false
|
||||
end
|
||||
unless RedmineQboBilling::InvoiceRefundWriter.paid_in_full?(@invoice)
|
||||
flash[:error] = l(:error_refund_invoice_not_paid)
|
||||
redirect_to edit_qbo_invoice_path(@invoice.id)
|
||||
return false
|
||||
end
|
||||
|
||||
@lines = RedmineQboBilling::InvoiceRefundWriter.lines(@invoice)
|
||||
@refunds = QboRefund.of_invoice(@invoice.id).recent.to_a
|
||||
true
|
||||
rescue *QBO_ERRORS => e
|
||||
flash[:error] = qbo_message(e)
|
||||
redirect_to(@form.customer_id.present? ? customer_path(@form.customer_id) : customers_path)
|
||||
false
|
||||
end
|
||||
|
||||
def load_invoice_plan
|
||||
@plan, = RedmineQboBilling::InvoiceRefundWriter.plan(@invoice, @form, invoice_lines: @lines)
|
||||
end
|
||||
|
||||
def show_invoice_form
|
||||
load_invoice_plan
|
||||
render :new_invoice, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def qbo_message(error)
|
||||
detail = error.respond_to?(:detail) ? error.detail.to_s : ''
|
||||
message = error.message.to_s
|
||||
|
||||
@@ -8,10 +8,16 @@
|
||||
#
|
||||
#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.
|
||||
|
||||
# A customer refund (SOP-OPS-014), as it was made: the restocking fee, the refund, and each step's outcome
|
||||
# A customer refund (SOP-OPS-014), as it was made: the restocking fee, the refund, and each step's outcome.
|
||||
# Two kinds: credit, a canceled order's deposit (RefundWriter), and invoice, completed work on a paid invoice
|
||||
# (InvoiceRefundWriter).
|
||||
class QboRefund < ApplicationRecord
|
||||
METHODS = %w[check card].freeze
|
||||
STATUSES = %w[done incomplete].freeze
|
||||
KINDS = %w[credit invoice].freeze
|
||||
|
||||
# A refunded invoice line, as recorded: its key on the invoice (InvoiceRefundWriter.line_key)
|
||||
RefundedLine = Struct.new(:key, :description, :quantity, :amount, :parts, keyword_init: true)
|
||||
|
||||
belongs_to :customer
|
||||
belongs_to :user, optional: true
|
||||
@@ -19,8 +25,15 @@ class QboRefund < ApplicationRecord
|
||||
validates :customer_id, presence: true
|
||||
validates :method, inclusion: { in: METHODS }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
validates :kind, inclusion: { in: KINDS }
|
||||
|
||||
scope :recent, -> { order(created_at: :desc, id: :desc) }
|
||||
# The invoice's refunds that made a refund receipt in QuickBooks
|
||||
scope :of_invoice, ->(id) { where(kind: 'invoice', invoice_id: id).where.not(purchase_id: [nil, '']) }
|
||||
|
||||
def invoice?
|
||||
kind == 'invoice'
|
||||
end
|
||||
|
||||
def done?
|
||||
status == 'done'
|
||||
@@ -44,11 +57,47 @@ class QboRefund < ApplicationRecord
|
||||
self[:canceled_issue_ids] = Array(ids).map(&:to_i).uniq.to_json
|
||||
end
|
||||
|
||||
# The QuickBooks screen for the refund check or expense
|
||||
def noted_issue_ids
|
||||
Array(JSON.parse(self[:noted_issue_ids].presence || '[]')).map(&:to_i)
|
||||
rescue JSON::ParserError
|
||||
[]
|
||||
end
|
||||
|
||||
def noted_issue_ids=(ids)
|
||||
self[:noted_issue_ids] = Array(ids).map(&:to_i).uniq.to_json
|
||||
end
|
||||
|
||||
def refunded_lines
|
||||
Array(JSON.parse(self[:refunded_lines].presence || '[]')).map do |line|
|
||||
RefundedLine.new(key: line['key'].to_s, description: line['description'].to_s, quantity: line['quantity'],
|
||||
amount: BigDecimal(line['amount'].to_s.presence || '0'), parts: line['parts'] == true)
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
[]
|
||||
end
|
||||
|
||||
def refunded_lines=(lines)
|
||||
self[:refunded_lines] = Array(lines).map do |line|
|
||||
{ key: line.key.to_s, description: line.description.to_s, quantity: line.quantity&.to_s,
|
||||
amount: line.amount.to_d.to_s('F'), parts: line.parts ? true : false }
|
||||
end.to_json
|
||||
end
|
||||
|
||||
# What the order or invoice is called: "E1068", "Invoice #1234", or nil
|
||||
def document_label
|
||||
if invoice? then I18n.t(:label_refund_invoice_number, number: invoice_number)
|
||||
elsif estimate_number.present? then "E#{estimate_number}"
|
||||
end
|
||||
end
|
||||
|
||||
# The QuickBooks screen for the refund receipt, check or expense
|
||||
def purchase_url
|
||||
return nil if purchase_id.blank?
|
||||
|
||||
page = check? ? 'check' : 'expense'
|
||||
page = if invoice? then 'refundreceipt'
|
||||
elsif check? then 'check'
|
||||
else 'expense'
|
||||
end
|
||||
"https://#{RedmineQbo.sandbox_mode? ? 'sandbox' : 'app'}.qbo.intuit.com/app/#{page}?txnId=#{purchase_id}"
|
||||
end
|
||||
end
|
||||
@@ -78,7 +78,13 @@
|
||||
<% customer_refunds.each do |refund| %>
|
||||
<tr>
|
||||
<td><%= link_to format_date(refund.txn_date), qbo_refund_path(refund) %></td>
|
||||
<td><%= refund.estimate_id.present? ? link_to("E#{refund.estimate_number}", RedmineQboBilling.writer? ? edit_qbo_estimate_path(refund.estimate_id) : estimate_path(refund.estimate_id)) : '' %></td>
|
||||
<td>
|
||||
<% if refund.invoice? %>
|
||||
<%= link_to refund.document_label, RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(refund.invoice_id) : invoice_path(refund.invoice_id) %>
|
||||
<% elsif refund.estimate_id.present? %>
|
||||
<%= link_to("E#{refund.estimate_number}", RedmineQboBilling.writer? ? edit_qbo_estimate_path(refund.estimate_id) : estimate_path(refund.estimate_id)) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= refund.method_name %></td>
|
||||
<td style="text-align: right"><%= RedmineQboBilling::RefundWriter.money(refund.refund_amount) %></td>
|
||||
<td><%= refund.done? ? '' : l(:label_refund_incomplete) %></td>
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
<% if RedmineQboBilling.payment_receiver? && @form.balance.to_d > 0 %>
|
||||
<%= link_to sprite_icon('add', l(:button_receive_payment)), new_qbo_payment_path(customer_id: @form.customer_id), class: 'icon icon-add' %>
|
||||
<% end %>
|
||||
<%# Completed work that's paid in full is refunded with a refund receipt %>
|
||||
<% if RedmineQboBilling.refunder? && @form.total.to_d.positive? && @form.balance.to_d <= 0 %>
|
||||
<%= link_to sprite_icon('arrow-narrow-left', l(:label_refund)), new_invoice_qbo_refunds_path(invoice_id: @form.id), class: 'icon icon-arrow-narrow-left' %>
|
||||
<% end %>
|
||||
<%= link_to sprite_icon('application-pdf', l(:label_estimate_pdf)), invoice_path(@form.id), class: 'icon icon-pdf', target: :_blank %>
|
||||
<% if RedmineQboBilling.invoice_sender? && @form.email.present? %>
|
||||
<%= link_to sprite_icon('email', l(:button_email_estimate)), send_email_qbo_invoice_path(@form.id, email: @form.email),
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<% money = ->(amount) { RedmineQboBilling::RefundWriter.money(amount) } -%>
|
||||
<%= t(:text_refund_email_greeting, name: @customer&.name.to_s) %>
|
||||
|
||||
<%= t(:text_refund_email_intro, shop: @shop_name, order: @refund.estimate_number.present? ? "E#{@refund.estimate_number}" : t(:label_refund_your_order)) %>
|
||||
<%= t(:text_refund_email_intro, shop: @shop_name, order: @refund.document_label || t(:label_refund_your_order)) %>
|
||||
|
||||
<% if @refund.invoice? -%>
|
||||
<% @refund.refunded_lines.each do |line| -%>
|
||||
<%= line.description %>: <%= money.(line.amount) %>
|
||||
<% end -%>
|
||||
<%= t(:label_refund_lines_amount) %>: <%= money.(@refund.lines_amount) %>
|
||||
<% if @refund.discount_amount.to_d.positive? -%>
|
||||
<%= t(:label_refund_discount) %>: -<%= money.(@refund.discount_amount) %>
|
||||
<% end -%>
|
||||
<%= t(:label_refund_tax) %>: <%= money.(@refund.tax_amount) %>
|
||||
<% end -%>
|
||||
<% if @refund.fee_amount.to_d.positive? -%>
|
||||
<%= t(:label_refund_parts) %>: <%= money.(@refund.parts_amount) %>
|
||||
<%= t(:label_refund_fee_rate, rate: RedmineQboBilling::RefundWriter.plain(@refund.fee_rate)) %>: <%= money.(@refund.fee_amount) %>
|
||||
@@ -10,6 +20,10 @@
|
||||
<%= t(:label_refund_amount) %>: <%= money.(@refund.refund_amount) %>
|
||||
<%= @refund.check? ? t(:text_refund_email_check, number: @refund.check_number) : t(:text_refund_email_card) %>
|
||||
|
||||
<% if !@refund.invoice? -%>
|
||||
<%= t(:text_refund_email_terms) %>
|
||||
<% elsif @refund.fee_amount.to_d.positive? -%>
|
||||
<%= t(:text_refund_email_terms_invoice) %>
|
||||
<% end -%>
|
||||
|
||||
<%= @shop_name %>
|
||||
@@ -13,6 +13,21 @@
|
||||
|
||||
<p class="warning"><%= l(:text_refund_final_sale) %></p>
|
||||
|
||||
<%# Completed work on a paid invoice is refunded from the invoice (a refund receipt), not from credit %>
|
||||
<% if @invoices.present? %>
|
||||
<%= form_tag new_invoice_qbo_refunds_path, method: :get, id: 'qbo-refund-invoice' do %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label for="qbo_refund_invoice"><%= l(:label_refund_paid_invoice) %></label>
|
||||
<%= select_tag 'invoice_id', options_for_select(@invoices), include_blank: true, id: 'qbo_refund_invoice',
|
||||
onchange: 'if (this.value) this.form.submit()' %>
|
||||
<noscript><%= submit_tag l(:button_apply), name: nil %></noscript>
|
||||
<em class="info"><%= l(:text_refund_paid_invoice) %></em>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if preview && preview.credits.empty? %>
|
||||
<p class="nodata"><%= l(:text_refund_no_credit) %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<%# Refund of completed work on a paid invoice: a QuickBooks Refund Receipt (InvoiceRefundWriter) %>
|
||||
<% html_title "#{l(:label_refund)} #{l(:label_refund_invoice_number, number: @invoice.doc_number)}" %>
|
||||
<% writer = RedmineQboBilling::RefundWriter %>
|
||||
<% money = ->(amount) { writer.money(amount) } %>
|
||||
<% plan = @plan %>
|
||||
<% number = @invoice.doc_number.to_s %>
|
||||
|
||||
<h2>
|
||||
<%= link_to l(:label_customers), customers_path %> »
|
||||
<%= link_to @customer.name, customer_path(@customer) %> »
|
||||
<%= link_to l(:label_refund_invoice_number, number: number), edit_qbo_invoice_path(@invoice.id) %> »
|
||||
<%= l(:label_refund) %>
|
||||
</h2>
|
||||
|
||||
<%= error_messages_for @form %>
|
||||
|
||||
<p class="warning"><%= l(:text_refund_final_sale) %></p>
|
||||
|
||||
<% if @refunds.any? %>
|
||||
<div class="flash warning">
|
||||
<%= l(:text_refund_invoice_earlier) %>
|
||||
<%= safe_join(@refunds.map { |r| link_to("#{format_date(r.txn_date)} · #{money.(r.refund_amount)}", qbo_refund_path(r)) }, ', ') %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_tag create_invoice_qbo_refunds_path, method: :post, id: 'qbo-refund-form' do %>
|
||||
<%= hidden_field_tag 'refund[customer_id]', @customer.id, id: nil %>
|
||||
<%= hidden_field_tag 'refund[invoice_id]', @invoice.id, id: nil %>
|
||||
|
||||
<fieldset class="box" id="qbo-refund-lines">
|
||||
<legend><%= l(:label_refund_invoice_lines, number: number, date: format_date(@invoice.txn_date)) %></legend>
|
||||
<table class="list" data-discount-rate="<%= plan.discount_rate.to_s('F') %>" data-tax-rate="<%= plan.tax_rate.to_s('F') %>"
|
||||
data-fee-rate="<%= plan.fee_rate.to_s('F') %>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: left"><%= l(:label_refund_line) %></th>
|
||||
<th></th>
|
||||
<th style="text-align: right"><%= l(:label_refund_line_billed) %></th>
|
||||
<th style="text-align: right"><%= l(:label_refund_line_refunded) %></th>
|
||||
<th><%= l(:label_refund_line_quantity) %></th>
|
||||
<th><%= l(:label_refund_line_amount) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @lines.each do |line| %>
|
||||
<% choice = @form.line(line.key) %>
|
||||
<% field = "refund[lines][#{line.key}]" %>
|
||||
<% dom = "qbo_refund_line_#{line.key.parameterize(separator: '_')}" %>
|
||||
<tr class="qbo-refund-line<%= ' disabled' unless line.refundable? %>" data-rate="<%= line.rate&.to_s('F') %>"
|
||||
data-parts="<%= line.parts ? 1 : 0 %>" data-taxable="<%= line.taxable ? 1 : 0 %>">
|
||||
<td>
|
||||
<% if line.refundable? %>
|
||||
<%= hidden_field_tag "#{field}[refund]", '0', id: nil %>
|
||||
<%= check_box_tag "#{field}[refund]", '1', choice&.refund?, id: dom, class: 'qbo-refund-pick' %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td style="text-align: left">
|
||||
<label for="<%= dom %>">
|
||||
<% if line.item_name.present? %><strong><%= line.item_name %></strong><br><% end %>
|
||||
<%= line.description %>
|
||||
</label>
|
||||
</td>
|
||||
<td><span class="badge <%= line.parts ? 'badge-status-open' : 'badge-status-closed' %>"><%= l(line.parts ? :label_refund_parts : :label_refund_labor) %></span>
|
||||
<% if line.taxable %><span class="badge"><%= l(:label_refund_taxable) %></span><% end %></td>
|
||||
<td style="text-align: right">
|
||||
<% if line.quantity && line.rate %><%= writer.plain(line.quantity) %> × <%= money.(line.rate) %><br><% end %>
|
||||
<%= money.(line.amount) %>
|
||||
</td>
|
||||
<td style="text-align: right"><%= line.refunded_amount.positive? ? money.(line.refunded_amount) : '' %></td>
|
||||
<% if line.refundable? %>
|
||||
<td style="white-space: nowrap">
|
||||
<% if line.quantity && line.rate %>
|
||||
<%= text_field_tag "#{field}[quantity]", choice&.quantity, size: 5, inputmode: 'decimal', autocomplete: 'off',
|
||||
class: 'qbo-refund-quantity', 'aria-label': l(:label_refund_line_quantity) %>
|
||||
<em class="info">/ <%= writer.plain(line.remaining_quantity) %></em>
|
||||
<% end %>
|
||||
</td>
|
||||
<td style="white-space: nowrap">
|
||||
$<%= text_field_tag "#{field}[amount]", choice&.amount, size: 9, inputmode: 'decimal', autocomplete: 'off',
|
||||
class: 'qbo-refund-line-amount', 'aria-label': l(:label_refund_line_amount),
|
||||
data: { max: line.remaining_amount.to_s('F') } %>
|
||||
</td>
|
||||
<% else %>
|
||||
<td colspan="2"><em class="info"><%= l(:text_refund_line_done) %></em></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><em class="info"><%= l(:text_refund_invoice_lines) %></em></p>
|
||||
</fieldset>
|
||||
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label for="qbo_refund_charge_fee"><%= l(:label_refund_charge_fee) %></label>
|
||||
<%= hidden_field_tag 'refund[charge_fee]', '0', id: nil %>
|
||||
<%= check_box_tag 'refund[charge_fee]', '1', @form.charge_fee?, id: 'qbo_refund_charge_fee' %>
|
||||
<%= l(:label_refund_fee_rate, rate: writer.plain(plan.fee_rate)) %>
|
||||
<em class="info"><%= l(:text_refund_charge_fee) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_refund_method) %><span class="required"> *</span></label>
|
||||
<label class="inline"><%= radio_button_tag 'refund[method]', 'check', @form.method == 'check', id: 'qbo_refund_method_check' %> <%= l(:label_refund_method_check) %></label>
|
||||
<label class="inline"><%= radio_button_tag 'refund[method]', 'card', @form.method == 'card', id: 'qbo_refund_method_card' %> <%= l(:label_refund_method_card) %></label>
|
||||
<em class="info"><%= l(:text_refund_method) %></em>
|
||||
</p>
|
||||
<p id="qbo-refund-check-number">
|
||||
<label for="qbo_refund_check_number"><%= l(:label_refund_check_number) %><span class="required"> *</span></label>
|
||||
<%= text_field_tag 'refund[check_number]', @form.check_number, id: 'qbo_refund_check_number', size: 12, maxlength: 21 %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_refund_date"><%= l(:label_refund_date) %><span class="required"> *</span></label>
|
||||
<%= date_field_tag 'refund[txn_date]', @form.txn_date, id: 'qbo_refund_date' %>
|
||||
</p>
|
||||
<p>
|
||||
<label for="qbo_refund_reason"><%= l(:label_refund_reason) %><span class="required"> *</span></label>
|
||||
<%= text_area_tag 'refund[reason]', @form.reason, id: 'qbo_refund_reason', rows: 3, cols: 60, maxlength: 2000 %>
|
||||
<em class="info"><%= l(:text_refund_invoice_reason) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_refund_also) %></label>
|
||||
<% [[:note_issues, :label_refund_note_issues], [:email_customer, :label_refund_email_customer]].each do |flag, label| %>
|
||||
<label class="block">
|
||||
<%= hidden_field_tag "refund[#{flag}]", '0', id: nil %>
|
||||
<%= check_box_tag "refund[#{flag}]", '1', @form.send(:"#{flag}?"), id: "qbo_refund_#{flag}" %>
|
||||
<%= l(label) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% if @customer.email.blank? %><em class="info"><%= l(:text_refund_no_email) %></em><% end %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<fieldset class="box" id="qbo-refund-preview">
|
||||
<legend><%= l(:label_refund_summary) %></legend>
|
||||
<table class="list">
|
||||
<tbody>
|
||||
<tr><td><%= l(:label_refund_lines_amount) %></td><td style="text-align: right" id="qbo-refund-lines-amount"><%= money.(plan.lines_amount) %></td></tr>
|
||||
<tr id="qbo-refund-discount-row"<%= ' style="display: none"'.html_safe unless plan.discount_rate.positive? %>>
|
||||
<td><%= l(:label_refund_discount) %></td><td style="text-align: right" id="qbo-refund-discount">-<%= money.(plan.discount) %></td>
|
||||
</tr>
|
||||
<tr><td><%= l(:label_refund_tax_estimate) %></td><td style="text-align: right" id="qbo-refund-tax"><%= money.(plan.tax) %></td></tr>
|
||||
<tr><td><%= l(:label_refund_fee_on_parts) %> (<span id="qbo-refund-parts"><%= money.(plan.parts_amount) %></span>)</td>
|
||||
<td style="text-align: right" id="qbo-refund-fee">-<%= money.(plan.fee) %></td></tr>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><td><strong><%= l(:label_refund_amount) %></strong></td><td style="text-align: right"><strong id="qbo-refund-amount"><%= money.(plan.refund) %></strong></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<p><em class="info"><%= l(:text_refund_invoice_summary) %></em></p>
|
||||
</fieldset>
|
||||
|
||||
<p><%= submit_tag l(:button_refund), data: { confirm: l(:text_refund_invoice_confirm) }, disabled: @lines.none?(&:refundable?) %></p>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
$(function() {
|
||||
var table = $('#qbo-refund-lines table');
|
||||
var money = function(n) { return '$' + n.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); };
|
||||
var num = function(v) { return parseFloat(String(v || '').replace(/[$,\s]/g, '')) || 0; };
|
||||
var round = function(n) { return Math.round(n * 100) / 100; };
|
||||
function update() {
|
||||
var lines = 0, parts = 0, taxable = 0;
|
||||
$('tr.qbo-refund-line').each(function() {
|
||||
var row = $(this);
|
||||
if (!row.find('.qbo-refund-pick').is(':checked')) return;
|
||||
var amount = num(row.find('.qbo-refund-line-amount').val());
|
||||
lines += amount;
|
||||
if (row.data('parts') == 1) parts += amount;
|
||||
if (row.data('taxable') == 1) taxable += amount;
|
||||
});
|
||||
var discountRate = num(table.data('discount-rate')), taxRate = num(table.data('tax-rate'));
|
||||
var discount = round(lines * discountRate);
|
||||
var tax = round(taxable * (1 - discountRate) * taxRate);
|
||||
var fee = $('#qbo_refund_charge_fee').is(':checked') ? Math.round(parts * num(table.data('fee-rate'))) / 100 : 0;
|
||||
$('#qbo-refund-lines-amount').text(money(lines));
|
||||
$('#qbo-refund-discount').text('-' + money(discount));
|
||||
$('#qbo-refund-tax').text(money(tax));
|
||||
$('#qbo-refund-parts').text(money(parts));
|
||||
$('#qbo-refund-fee').text('-' + money(fee));
|
||||
$('#qbo-refund-amount').text(money(Math.max(lines - discount + tax - fee, 0)));
|
||||
}
|
||||
// A quantity refunds that many at the line's rate (the amount can still be changed after)
|
||||
$('.qbo-refund-quantity').on('input', function() {
|
||||
var row = $(this).closest('tr'), rate = num(row.data('rate'));
|
||||
if (rate) row.find('.qbo-refund-line-amount').val(round(num($(this).val()) * rate).toFixed(2));
|
||||
row.find('.qbo-refund-pick').prop('checked', num($(this).val()) > 0);
|
||||
update();
|
||||
});
|
||||
$('.qbo-refund-line-amount, #qbo_refund_charge_fee, .qbo-refund-pick').on('input change', update);
|
||||
function method() { $('#qbo-refund-check-number').toggle($('#qbo_refund_method_check').is(':checked')); }
|
||||
$('input[name="refund[method]"]').on('change', method);
|
||||
update(); method();
|
||||
});
|
||||
<% end %>
|
||||
@@ -15,7 +15,9 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @refund.done? %>
|
||||
<% 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>
|
||||
@@ -27,13 +29,39 @@
|
||||
<% end %>
|
||||
|
||||
<div class="box tabular">
|
||||
<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>
|
||||
<% 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>
|
||||
<%= money.(@refund.fee_amount) %>
|
||||
<%= @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 %>
|
||||
@@ -42,12 +70,17 @@
|
||||
<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.check? ? :label_refund_open_check : :label_refund_open_expense), @refund.purchase_url, target: '_blank', rel: 'noopener' %>
|
||||
· <%= 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>
|
||||
|
||||
Reference in new issue
Block a user