diff --git a/README.md b/README.md index c9b6cf4..30831df 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ Customer records are automatically updated in the local database when changes oc * With none ticked, the payment is applied to the customer's open invoices **oldest first**, like QuickBooks does; the page shows how it will be split as the amount is typed, and it's worked out again from QuickBooks when saving. Anything more than the open balances stays as a credit. * Tick **Deposit** to keep the whole payment as a credit on the customer's account without paying any invoice (also what happens when there are no open invoices). * The saved payment's page shows where it was applied and has **Print**, QuickBooks' payment PDF. +* **Payments** on the customer page lists all of the customer's payments from QuickBooks, newest first: date, method, reference no., the invoices each was applied to (or Deposit), memo, amount and what's still unapplied, with totals. Each date opens the payment's page and **Print** opens its PDF. ### QuickBooks custom fields @@ -165,7 +166,8 @@ Administration → Items lists the QuickBooks product/service list (synced from * **Write estimates**: create and edit estimates * **Email estimates**: email estimates to customers (Save and send, and the Email link) * **Create issues from estimates**: the Create issues page (was redmine_qbo_calendar's "Create issues from appointment estimates") - * **Receive payments**: the Receive payment page, the payment page and its PDF + * **View payments**: a customer's Payments list, the payment page and its PDF + * **Receive payments**: the Receive payment page, plus everything View payments allows * **Write invoices**: create and edit invoices, and import time and estimates into them * **Email invoices**: email invoices to customers diff --git a/app/controllers/qbo_payments_controller.rb b/app/controllers/qbo_payments_controller.rb index 93dc1d4..c43f760 100644 --- a/app/controllers/qbo_payments_controller.rb +++ b/app/controllers/qbo_payments_controller.rb @@ -9,13 +9,27 @@ #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. # Receives customer payments in QuickBooks: payment type and amount, applied to open invoices oldest first, or -# saved as a deposit. A saved payment can be printed (QuickBooks' payment PDF). +# saved as a deposit. A saved payment can be printed (QuickBooks' payment PDF). A customer's payments are +# listed on their payments page. class QboPaymentsController < ApplicationController before_action :authorize_global QBO_ERRORS = QboEstimatesController::QBO_ERRORS + # The customer's payments, newest first, read from QuickBooks + def index + @customer = Customer.find_by(id: params[:customer_id]) + return render_404 unless @customer + + @payments = RedmineQboBilling::PaymentWriter.customer_payments(@customer) + @totals = RedmineQboBilling::PaymentWriter.payment_totals(@payments) + rescue *QBO_ERRORS => e + @payments = [] + @totals = RedmineQboBilling::PaymentWriter.payment_totals([]) + flash.now[:error] = qbo_message(e) + end + def new customer = Customer.find_by(id: params[:customer_id]) if params[:customer_id].present? @form = RedmineQboBilling::PaymentWriter.new_form(customer: customer, user: User.current) diff --git a/app/views/customers/show.html.erb b/app/views/customers/show.html.erb index 6d44275..3ac91f6 100644 --- a/app/views/customers/show.html.erb +++ b/app/views/customers/show.html.erb @@ -14,6 +14,9 @@ <% if RedmineQboBilling.invoice_writer? %> <%= render partial: 'qbo_invoices/customer_link', locals: { customer: @customer } %> <% end %> + <% if RedmineQboBilling.payment_viewer? %> + <%= link_to sprite_icon('list', l(:label_payments)), qbo_payments_path(customer_id: @customer.id), class: 'icon icon-list' %> + <% end %> <% 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' %> <% else %> diff --git a/app/views/qbo_payments/index.html.erb b/app/views/qbo_payments/index.html.erb new file mode 100644 index 0000000..0759fdc --- /dev/null +++ b/app/views/qbo_payments/index.html.erb @@ -0,0 +1,82 @@ +<% html_title @customer.name, l(:label_payments) %> + +
<%= l(:label_no_payments) %>
+<% else %> +| <%= l(:label_payment_date) %> | +<%= l(:label_payment_method) %> | +<%= l(:label_payment_reference) %> | +<%= l(:label_payment_applies_to) %> | +<%= l(:label_memo) %> | +<%= l(:label_amount) %> | +<%= l(:label_payment_unapplied) %> | ++ |
|---|---|---|---|---|---|---|---|
| <%= link_to format_date(payment.txn_date), qbo_payment_path(payment.id) %> | +<%= RedmineQboBilling::PaymentWriter.payment_method_name(payment) %> | +<%= payment.payment_ref_number %> | +
+ <% if applied.empty? %>
+ <%= l(:label_payment_deposit) %>
+ <% else %>
+ <% applied.each do |invoice_id, number, amount| %>
+
+ <%= link_to "##{number}", RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(invoice_id) : invoice_path(invoice_id) %>
+ <%= number_to_currency(amount) %>
+
+ <% end %>
+ <% end %>
+ |
+ <%= truncate(payment.private_note.to_s, length: 60) %> | +<%= number_to_currency(payment.total) %> | +<%= unapplied > 0 ? number_to_currency(unapplied) : '' %> | ++ <%= link_to sprite_icon('application-pdf', l(:button_print_payment)), pdf_qbo_payment_path(payment.id), + class: 'icon icon-pdf', target: :_blank %> + | +
| <%= l(:label_payment_totals) %> (<%= @payments.size %>) | +<%= number_to_currency(@totals[:received]) %> | +<%= @totals[:unapplied] > 0 ? number_to_currency(@totals[:unapplied]) : '' %> | ++ | ||||