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>
40 lines
3.3 KiB
Ruby
40 lines
3.3 KiB
Ruby
#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.
|
|
|
|
# Refunds of paid invoices (completed, billed and paid-in-full work): a QuickBooks Refund Receipt for the lines
|
|
# refunded, with an optional restocking fee, alongside the refunds of customer credit (canceled orders)
|
|
class AddInvoiceRefunds < ActiveRecord::Migration[7.0]
|
|
def up
|
|
# credit: a canceled order's deposit (fee invoice + check/expense); invoice: a paid invoice (refund receipt)
|
|
add_column :qbo_refunds, :kind, :string, null: false, default: 'credit', limit: 10 unless column_exists?(:qbo_refunds, :kind)
|
|
add_column :qbo_refunds, :invoice_id, :bigint unless column_exists?(:qbo_refunds, :invoice_id)
|
|
add_column :qbo_refunds, :invoice_number, :string unless column_exists?(:qbo_refunds, :invoice_number)
|
|
# The Refund Receipt's number (its id is purchase_id)
|
|
add_column :qbo_refunds, :receipt_number, :string unless column_exists?(:qbo_refunds, :receipt_number)
|
|
# The refunded lines before the discount, fee and tax; the invoice discount's share; the tax refunded
|
|
add_column :qbo_refunds, :lines_amount, :decimal, precision: 15, scale: 2, null: false, default: 0 unless column_exists?(:qbo_refunds, :lines_amount)
|
|
add_column :qbo_refunds, :discount_amount, :decimal, precision: 15, scale: 2, null: false, default: 0 unless column_exists?(:qbo_refunds, :discount_amount)
|
|
add_column :qbo_refunds, :tax_amount, :decimal, precision: 15, scale: 2, null: false, default: 0 unless column_exists?(:qbo_refunds, :tax_amount)
|
|
# The lines refunded (JSON: key, description, quantity, amount, parts), so a line isn't refunded twice
|
|
add_column :qbo_refunds, :refunded_lines, :text unless column_exists?(:qbo_refunds, :refunded_lines)
|
|
# The work orders the refund was noted on (JSON list of issue ids)
|
|
add_column :qbo_refunds, :noted_issue_ids, :text unless column_exists?(:qbo_refunds, :noted_issue_ids)
|
|
add_index :qbo_refunds, :invoice_id unless index_exists?(:qbo_refunds, :invoice_id)
|
|
end
|
|
|
|
def down
|
|
remove_index :qbo_refunds, :invoice_id if index_exists?(:qbo_refunds, :invoice_id)
|
|
%i[kind invoice_id invoice_number receipt_number lines_amount discount_amount tax_amount refunded_lines
|
|
noted_issue_ids].each do |column|
|
|
remove_column :qbo_refunds, column if column_exists?(:qbo_refunds, column)
|
|
end
|
|
end
|
|
end
|