mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
Refunds for canceled orders and returned parts (SOP-OPS-014)
A Refund page on the customer: the canceled order's estimate fills in the parts the 30% restocking fee is worked out on. Refunding makes the fee invoice, pays it from the customer's credit, records the rest as a Check (company check) or Expense (card refund on the terminal) with the category Accounts Receivable, applies the credit to it so the balance comes back to $0.00, and optionally marks the estimate Rejected, cancels its work orders with the reason as a note and emails the customer. Each refund has a page with a PDF of it. New permission: Issue refunds. New settings under Billing » Refunds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
16f9441568
commit
9fa199aa98
21 files changed
+1737
No files matched your search
@@ -0,0 +1,108 @@
|
||||
#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.
|
||||
|
||||
# Customer refunds (SOP-OPS-014): the Refund page for a customer with credit, and a refund once it's made
|
||||
class QboRefundsController < ApplicationController
|
||||
before_action :authorize_global
|
||||
|
||||
QBO_ERRORS = QboEstimatesController::QBO_ERRORS
|
||||
|
||||
def new
|
||||
@customer = Customer.find_by(id: params[:customer_id])
|
||||
return render_404 unless @customer
|
||||
|
||||
@form = RedmineQboBilling::RefundForm.new(customer_id: @customer.id.to_s, estimate_id: params[:estimate_id].to_s,
|
||||
txn_date: User.current.today.iso8601, method: 'check',
|
||||
close_estimate: '1', cancel_issues: '1', email_customer: '1')
|
||||
@form.parts_amount = estimate_parts(@form.estimate_id)
|
||||
load_page
|
||||
end
|
||||
|
||||
def create
|
||||
@form = RedmineQboBilling::RefundForm.from_params(params.require(:refund).permit(*RedmineQboBilling::RefundForm::ATTRIBUTES))
|
||||
@customer = Customer.find_by(id: @form.customer_id)
|
||||
return render_404 unless @customer
|
||||
return show_form unless @form.valid?
|
||||
|
||||
refund = RedmineQboBilling::RefundWriter.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_form
|
||||
end
|
||||
|
||||
def show
|
||||
@refund = QboRefund.find_by(id: params[:id])
|
||||
return render_404 unless @refund
|
||||
|
||||
@customer = @refund.customer
|
||||
end
|
||||
|
||||
# The refund as a PDF, shown in the browser to print or save
|
||||
def pdf
|
||||
refund = QboRefund.find_by(id: params[:id])
|
||||
return render_404 unless refund
|
||||
|
||||
document = RedmineQboBilling::RefundPdf.new(refund)
|
||||
send_data document.render, type: 'application/pdf', disposition: 'inline', filename: document.filename
|
||||
end
|
||||
|
||||
# Emails the customer the refund's summary (again, or after fixing their email in QuickBooks)
|
||||
def email
|
||||
refund = QboRefund.find_by(id: params[:id])
|
||||
return render_404 unless refund&.done?
|
||||
|
||||
warning = RedmineQboBilling::RefundWriter.email_customer(refund, refund.customer, QboRefundMailer)
|
||||
if warning
|
||||
flash[:error] = warning
|
||||
else
|
||||
flash[:notice] = l(:notice_refund_emailed, email: refund.emailed_to)
|
||||
end
|
||||
redirect_to qbo_refund_path(refund)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# The estimate's parts (its lines that aren't labor), before tax, for the restocking fee
|
||||
def estimate_parts(estimate_id)
|
||||
return '' if estimate_id.blank?
|
||||
|
||||
estimate = RedmineQboBilling::RefundGateway.new.estimate(estimate_id)
|
||||
estimate ? format('%.2f', RedmineQboBilling::RefundWriter.parts_amount(estimate)) : ''
|
||||
rescue *QBO_ERRORS => e
|
||||
flash.now[:error] = qbo_message(e)
|
||||
''
|
||||
end
|
||||
|
||||
def load_page
|
||||
@estimates = RedmineQboBilling::RefundWriter.estimate_choices(@customer)
|
||||
@preview = RedmineQboBilling::RefundWriter.preview(@customer, parts: @form.parts_value || BigDecimal('0'))
|
||||
@statuses = IssueStatus.sorted.to_a
|
||||
rescue *QBO_ERRORS => e
|
||||
@preview = nil
|
||||
flash.now[:error] = qbo_message(e)
|
||||
end
|
||||
|
||||
def show_form
|
||||
load_page
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
def qbo_message(error)
|
||||
detail = error.respond_to?(:detail) ? error.detail.to_s : ''
|
||||
message = error.message.to_s
|
||||
detail.present? && !message.include?(detail) ? "#{message}: #{detail}" : message
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
#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.
|
||||
|
||||
# Emails a customer the summary of their refund (SOP-OPS-014). It goes out like redmine_qbo_reminders' appointment
|
||||
# reminders when that plugin is installed (its From, Reply-To and SMTP server, e.g. the shop's sales mailbox);
|
||||
# otherwise through Redmine's own email settings, from Redmine's emission address. Not Redmine's Mailer, which only
|
||||
# writes to Redmine users and adds Redmine's headers and footer.
|
||||
class QboRefundMailer < ActionMailer::Base
|
||||
layout false
|
||||
self.raise_delivery_errors = true
|
||||
|
||||
class DeliveryOff < StandardError; end
|
||||
|
||||
def refund_summary(refund, email)
|
||||
@refund = refund
|
||||
@customer = refund.customer
|
||||
reminders = defined?(RedmineQboReminders::Settings) ? RedmineQboReminders::Settings.current : nil
|
||||
@shop_name = reminders&.[]('shop_name').to_s.presence || Setting.app_title
|
||||
delivery = reminders ? reminders.delivery_options : {}
|
||||
if delivery.empty? && !ActionMailer::Base.perform_deliveries
|
||||
raise DeliveryOff, I18n.t(:text_refund_email_off)
|
||||
end
|
||||
|
||||
options = { to: email, from: reminders&.from.presence || Setting.mail_from.to_s,
|
||||
subject: I18n.t(:text_refund_email_subject, shop: @shop_name, amount: RedmineQboBilling::RefundWriter.money(refund.refund_amount)) }
|
||||
options[:reply_to] = reminders.reply_to if reminders&.reply_to
|
||||
message = mail(options.merge(delivery)) do |format|
|
||||
format.text
|
||||
end
|
||||
message.perform_deliveries = true unless delivery.empty?
|
||||
message
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
#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.
|
||||
|
||||
# A customer refund (SOP-OPS-014), as it was made: the restocking fee, the refund, and each step's outcome
|
||||
class QboRefund < ApplicationRecord
|
||||
METHODS = %w[check card].freeze
|
||||
STATUSES = %w[done incomplete].freeze
|
||||
|
||||
belongs_to :customer
|
||||
belongs_to :user, optional: true
|
||||
|
||||
validates :customer_id, presence: true
|
||||
validates :method, inclusion: { in: METHODS }
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
|
||||
scope :recent, -> { order(created_at: :desc, id: :desc) }
|
||||
|
||||
def done?
|
||||
status == 'done'
|
||||
end
|
||||
|
||||
def check?
|
||||
method == 'check'
|
||||
end
|
||||
|
||||
def method_name
|
||||
I18n.t("label_refund_method_#{method}")
|
||||
end
|
||||
|
||||
def canceled_issue_ids
|
||||
Array(JSON.parse(self[:canceled_issue_ids].presence || '[]')).map(&:to_i)
|
||||
rescue JSON::ParserError
|
||||
[]
|
||||
end
|
||||
|
||||
def canceled_issue_ids=(ids)
|
||||
self[:canceled_issue_ids] = Array(ids).map(&:to_i).uniq.to_json
|
||||
end
|
||||
|
||||
# The QuickBooks screen for the refund check or expense
|
||||
def purchase_url
|
||||
return nil if purchase_id.blank?
|
||||
|
||||
page = check? ? 'check' : 'expense'
|
||||
"https://#{RedmineQbo.sandbox_mode? ? 'sandbox' : 'app'}.qbo.intuit.com/app/#{page}?txnId=#{purchase_id}"
|
||||
end
|
||||
end
|
||||
@@ -23,6 +23,9 @@
|
||||
<% 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 %>
|
||||
<% if RedmineQboBilling.refunder? %>
|
||||
<%= link_to sprite_icon('arrow-narrow-left', l(:label_refund)), new_qbo_refund_path(customer_id: @customer.id), class: 'icon icon-arrow-narrow-left' %>
|
||||
<% end %>
|
||||
<% if User.current.allowed_to?(:edit_customers, nil, global: true) %>
|
||||
<%= link_to sprite_icon('edit', l(:button_edit)), edit_customer_path(@customer),
|
||||
class: 'icon icon-edit', accesskey: accesskey(:edit) %>
|
||||
@@ -65,6 +68,27 @@
|
||||
<%= render partial: 'qbo_drafts/list', locals: { drafts: customer_drafts, show_customer: false } %>
|
||||
<% end %>
|
||||
|
||||
<%# Refunds made from Redmine (SOP-OPS-014) %>
|
||||
<% if RedmineQboBilling.refunder? %>
|
||||
<% customer_refunds = QboRefund.where(customer_id: @customer.id).recent.limit(10).to_a %>
|
||||
<% if customer_refunds.any? %>
|
||||
<h4><%= l(:label_refunds) %>:</h4>
|
||||
<table class="list">
|
||||
<tbody>
|
||||
<% 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><%= refund.method_name %></td>
|
||||
<td style="text-align: right"><%= RedmineQboBilling::RefundWriter.money(refund.refund_amount) %></td>
|
||||
<td><%= refund.done? ? '' : l(:label_refund_incomplete) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="splitcontentleft">
|
||||
|
||||
@@ -66,3 +66,40 @@
|
||||
<em class="info"><%= l(:text_default_tracker_info) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<%# Refunds (SOP-OPS-014): the restocking fee, and where the refund check or card refund is recorded %>
|
||||
<% refunds = RedmineQboBilling::RefundWriter %>
|
||||
<% accounts = Account.where(active: true).order(:name).pluck(:name, :id) %>
|
||||
<fieldset class="box tabular">
|
||||
<legend><%= l(:label_refund_settings) %></legend>
|
||||
<p>
|
||||
<label for="settings_restocking_fee_rate"><%= l(:label_restocking_fee_rate) %></label>
|
||||
<%= number_field_tag 'settings[restocking_fee_rate]', refunds.plain(refunds.fee_rate), id: 'settings_restocking_fee_rate',
|
||||
min: 0, max: 100, step: 0.01, style: 'width: 6em' %>%
|
||||
<em class="info"><%= l(:text_restocking_fee_rate) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="settings_restocking_item_id"><%= l(:label_restocking_item) %></label>
|
||||
<%= select_tag 'settings[restocking_item_id]', options_from_collection_for_select(Item.sellable.order(:name), :id, :name, @settings['restocking_item_id']),
|
||||
include_blank: true, id: 'settings_restocking_item_id' %>
|
||||
<em class="info"><%= l(:text_restocking_item) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="settings_refund_check_account_id"><%= l(:label_refund_check_account) %></label>
|
||||
<%= select_tag 'settings[refund_check_account_id]', options_for_select(accounts, @settings['refund_check_account_id'].to_s),
|
||||
include_blank: l(:label_refund_first_bank_account), id: 'settings_refund_check_account_id' %>
|
||||
<em class="info"><%= l(:text_refund_check_account) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="settings_refund_card_account_id"><%= l(:label_refund_card_account) %></label>
|
||||
<%= select_tag 'settings[refund_card_account_id]', options_for_select(accounts, @settings['refund_card_account_id'].to_s),
|
||||
include_blank: l(:label_refund_first_bank_account), id: 'settings_refund_card_account_id' %>
|
||||
<em class="info"><%= l(:text_refund_card_account) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="settings_refund_canceled_status_id"><%= l(:label_refund_canceled_status) %></label>
|
||||
<%= select_tag 'settings[refund_canceled_status_id]', options_from_collection_for_select(IssueStatus.sorted, :id, :name, @settings['refund_canceled_status_id'].to_s),
|
||||
include_blank: refunds.canceled_status ? "#{refunds.canceled_status.name} (#{l(:label_default)})" : true, id: 'settings_refund_canceled_status_id' %>
|
||||
<em class="info"><%= l(:text_refund_canceled_status) %></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
@@ -0,0 +1,15 @@
|
||||
<% 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)) %>
|
||||
|
||||
<% 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) %>
|
||||
<% end -%>
|
||||
<%= t(:label_refund_amount) %>: <%= money.(@refund.refund_amount) %>
|
||||
<%= @refund.check? ? t(:text_refund_email_check, number: @refund.check_number) : t(:text_refund_email_card) %>
|
||||
|
||||
<%= t(:text_refund_email_terms) %>
|
||||
|
||||
<%= @shop_name %>
|
||||
@@ -0,0 +1,122 @@
|
||||
<%# Refund for a canceled order or returned parts (SOP-OPS-014) %>
|
||||
<% html_title l(:label_refund) %>
|
||||
<% money = ->(amount) { RedmineQboBilling::RefundWriter.money(amount) } %>
|
||||
<% preview = @preview %>
|
||||
|
||||
<h2>
|
||||
<%= link_to l(:label_customers), customers_path %> »
|
||||
<%= link_to @customer.name, customer_path(@customer) %> »
|
||||
<%= l(:label_refund) %>
|
||||
</h2>
|
||||
|
||||
<%= error_messages_for @form %>
|
||||
|
||||
<p class="warning"><%= l(:text_refund_final_sale) %></p>
|
||||
|
||||
<% if preview && preview.credits.empty? %>
|
||||
<p class="nodata"><%= l(:text_refund_no_credit) %></p>
|
||||
<% end %>
|
||||
|
||||
<%# Picking the canceled order's estimate reloads the page with its parts filled in %>
|
||||
<%= form_tag new_qbo_refund_path, method: :get, id: 'qbo-refund-estimate' do %>
|
||||
<%= hidden_field_tag 'customer_id', @customer.id, id: nil %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label for="qbo_refund_estimate"><%= l(:label_refund_estimate) %></label>
|
||||
<%= select_tag 'estimate_id', options_for_select(@estimates, @form.estimate_id), include_blank: l(:label_refund_no_estimate),
|
||||
id: 'qbo_refund_estimate', onchange: 'this.form.submit()' %>
|
||||
<noscript><%= submit_tag l(:button_apply), name: nil %></noscript>
|
||||
<em class="info"><%= l(:text_refund_estimate) %></em>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= form_tag qbo_refunds_path, method: :post, id: 'qbo-refund-form' do %>
|
||||
<%= hidden_field_tag 'refund[customer_id]', @customer.id, id: nil %>
|
||||
<%= hidden_field_tag 'refund[estimate_id]', @form.estimate_id, id: nil %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label for="qbo_refund_parts"><%= l(:label_refund_parts) %></label>
|
||||
$<%= text_field_tag 'refund[parts_amount]', @form.parts_amount, id: 'qbo_refund_parts', size: 12, inputmode: 'decimal',
|
||||
autocomplete: 'off', data: { rate: preview&.fee_rate.to_s } %>
|
||||
<em class="info"><%= l(:text_refund_parts, rate: RedmineQboBilling::RefundWriter.plain(preview&.fee_rate || RedmineQboBilling::RefundWriter.fee_rate)) %></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_reason) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= l(:label_refund_also) %></label>
|
||||
<% [[:close_estimate, :label_refund_close_estimate], [:cancel_issues, :label_refund_cancel_issues], [:email_customer, :label_refund_email_customer]].each do |flag, label| %>
|
||||
<% needs_estimate = flag != :email_customer %>
|
||||
<label class="block">
|
||||
<%= hidden_field_tag "refund[#{flag}]", '0', id: nil %>
|
||||
<%= check_box_tag "refund[#{flag}]", '1', @form.send(:"#{flag}?") && (!needs_estimate || @form.estimate_id.present?),
|
||||
id: "qbo_refund_#{flag}", disabled: needs_estimate && @form.estimate_id.blank? %>
|
||||
<%= l(label) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% if @customer.email.blank? %><em class="info"><%= l(:text_refund_no_email) %></em><% end %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<% if preview %>
|
||||
<fieldset class="box" id="qbo-refund-preview">
|
||||
<legend><%= l(:label_refund_summary) %></legend>
|
||||
<table class="list">
|
||||
<thead><tr><th><%= l(:label_refund_credit_from) %></th><th><%= l(:label_payment_reference) %></th><th><%= l(:label_memo) %></th><th><%= l(:label_amount) %></th></tr></thead>
|
||||
<tbody>
|
||||
<% preview.credits.each do |credit| %>
|
||||
<tr>
|
||||
<td><%= link_to format_date(credit.date), qbo_payment_path(credit.payment_id) %></td>
|
||||
<td><%= credit.reference %></td>
|
||||
<td><%= credit.memo %></td>
|
||||
<td style="text-align: right"><%= money.(credit.amount) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr><td colspan="3"><%= l(:label_refund_credit) %></td><td style="text-align: right" id="qbo-refund-credit" data-credit="<%= preview.credit_total.to_s('F') %>"><%= money.(preview.credit_total) %></td></tr>
|
||||
<tr><td colspan="3"><%= l(:label_refund_fee_rate, rate: RedmineQboBilling::RefundWriter.plain(preview.fee_rate)) %></td><td style="text-align: right" id="qbo-refund-fee">-<%= money.(preview.fee) %></td></tr>
|
||||
<tr><td colspan="3"><strong><%= l(:label_refund_amount) %></strong></td><td style="text-align: right"><strong id="qbo-refund-amount"><%= money.(preview.refund) %></strong></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<p><em class="info"><%= l(:text_refund_summary) %></em></p>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
|
||||
<p><%= submit_tag l(:button_refund), data: { confirm: l(:text_refund_confirm) }, disabled: preview.nil? || preview.credits.empty? %></p>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
$(function() {
|
||||
var money = function(n) { return '$' + n.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); };
|
||||
function update() {
|
||||
var parts = parseFloat(($('#qbo_refund_parts').val() || '0').replace(/[$,\s]/g, '')) || 0;
|
||||
var rate = parseFloat($('#qbo_refund_parts').data('rate')) || 0;
|
||||
var credit = parseFloat($('#qbo-refund-credit').data('credit')) || 0;
|
||||
var fee = Math.round(parts * rate) / 100;
|
||||
$('#qbo-refund-fee').text('-' + money(fee));
|
||||
$('#qbo-refund-amount').text(money(Math.max(credit - fee, 0)));
|
||||
}
|
||||
function method() { $('#qbo-refund-check-number').toggle($('#qbo_refund_method_check').is(':checked')); }
|
||||
$('#qbo_refund_parts').on('input', update);
|
||||
$('input[name="refund[method]"]').on('change', method);
|
||||
update(); method();
|
||||
});
|
||||
<% end %>
|
||||
@@ -0,0 +1,64 @@
|
||||
<%# 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? %>
|
||||
<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">
|
||||
<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>
|
||||
<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) %>
|
||||
<% 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.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.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>
|
||||
Reference in new issue
Block a user