mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
Estimates, invoices and payments written in Redmine, issues from estimates, and the QuickBooks product/service list and accounts are now part of this plugin (the RedmineQboBilling code, its controllers, views, strings and permissions), so there's one plugin and one version instead of two that had to match. - The customer page, estimate and invoice lists and the issue page render the Create Estimate / Create invoice / Receive payment and Edit links directly; the hooks that only existed to let billing add them are gone. Users without the billing permissions still get the links to QuickBooks. - Migrations 043-046 create the items and accounts tables and the estimate line links, skipping whatever an existing database already has (redmine_qbo_lineitems' tables are used as they are), and copy calendar's existing estimate line links in. - The billing settings are a section of this plugin's settings page. - The hooks other plugins use stay: qbo_billing_issue_values, qbo_billing_validate, qbo_billing_issue_defaults, qbo_billing_issues_created and view_qbo_estimate_contextual. - rake redmine_qbo:relate_estimate_issues Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
62 lines
2.8 KiB
Ruby
62 lines
2.8 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.
|
|
|
|
module RedmineQboBilling
|
|
# What the Receive payment page posts: who paid, how, and how much. PaymentWriter turns it into a
|
|
# QuickBooks payment, applied to the customer's oldest open invoices first, or kept as a deposit.
|
|
class PaymentForm
|
|
include ActiveModel::Model
|
|
include ActiveModel::Validations
|
|
|
|
ATTRIBUTES = %i[customer_id customer_name txn_date payment_method_id reference amount deposit memo].freeze
|
|
|
|
attr_accessor(*ATTRIBUTES)
|
|
# Invoices ticked on the page: the payment goes on these (oldest first). None ticked: all open invoices.
|
|
attr_accessor :invoice_ids
|
|
|
|
validate :validate_payment
|
|
|
|
def self.from_params(params)
|
|
params = params.to_h.stringify_keys
|
|
new(ATTRIBUTES.to_h { |attr| [attr, params[attr.to_s].to_s.strip] }).tap do |form|
|
|
form.invoice_ids = Array(params['invoice_ids']).map(&:to_s).reject(&:blank?).uniq
|
|
end
|
|
end
|
|
|
|
def initialize(attributes = {})
|
|
super
|
|
self.invoice_ids ||= []
|
|
end
|
|
|
|
def amount_value
|
|
EstimateForm.decimal(amount)
|
|
end
|
|
|
|
def txn_date_value
|
|
EstimateForm.date(txn_date)
|
|
end
|
|
|
|
# A deposit is kept unapplied (credit on the customer's account) instead of paying invoices
|
|
def deposit?
|
|
deposit == true || deposit.to_s == '1'
|
|
end
|
|
|
|
private
|
|
|
|
def validate_payment
|
|
errors.add(:base, I18n.t(:error_estimate_needs_customer)) if customer_id.blank?
|
|
errors.add(:base, I18n.t(:error_payment_needs_method)) if payment_method_id.blank?
|
|
value = amount_value
|
|
errors.add(:base, I18n.t(:error_payment_amount)) if value.nil? || value <= 0
|
|
errors.add(:base, I18n.t(:error_estimate_field_invalid, field: I18n.t(:label_payment_date))) if txn_date_value.nil?
|
|
end
|
|
end
|
|
end
|