%# Refund for a canceled order or returned parts (SOP-OPS-014) %> <% html_title l(:label_refund) %> <% money = ->(amount) { RedmineQboBilling::RefundWriter.money(amount) } %> <% preview = @preview %>
<%= l(:text_refund_final_sale) %>
<% if preview && preview.credits.empty? %><%= l(:text_refund_no_credit) %>
<% 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 %><%= 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()' %> <%= l(:text_refund_estimate) %>
$<%= 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 } %> <%= l(:text_refund_parts, rate: RedmineQboBilling::RefundWriter.plain(preview&.fee_rate || RedmineQboBilling::RefundWriter.fee_rate)) %>
<%= l(:text_refund_method) %>
<%= text_field_tag 'refund[check_number]', @form.check_number, id: 'qbo_refund_check_number', size: 12, maxlength: 21 %>
<%= date_field_tag 'refund[txn_date]', @form.txn_date, id: 'qbo_refund_date' %>
<%= text_area_tag 'refund[reason]', @form.reason, id: 'qbo_refund_reason', rows: 3, cols: 60, maxlength: 2000 %> <%= l(:text_refund_reason) %>
<% [[: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 %> <% end %> <% if @customer.email.blank? %><%= l(:text_refund_no_email) %><% end %>
<%= submit_tag l(:button_refund), data: { confirm: l(:text_refund_confirm) }, disabled: preview.nil? || preview.credits.empty? %>
<% 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 %>