Modify payment_list partial to be shared

- Partial is used by both the invoice pdf and the order confirmation email
- separate scss file for new payment list table
- extracted outstanding balance logic (also changed in payments view.. admin/orders/RXXX/payments)
- translations in shared.payments_list and lazy loaded
This commit is contained in:
Steve Roberts
2020-07-07 22:05:27 +10:00
committed by Matt-Yorkley
parent 1f470830c8
commit debbf9b361
11 changed files with 76 additions and 66 deletions

View File

@@ -109,49 +109,6 @@ table.order-summary {
}
}
// put in separate order invoice scss file?
table.payment-list {
width: 100%;
border-collapse: separate;
border-spacing: 0px;
font-size: 12px;
tbody tr td {
padding: 5px;
border-bottom: 1px solid $medium-grey;
.payment-method-name {
display: block;
font-weight: bold;
}
.payment-method-description {
display: block;
}
}
thead tr th {
border-bottom: 1px solid $medium-grey;
padding: 10px 5px 5px;
text-transform: uppercase;
text-align: left;
}
th.amount, td.amount {
text-align: right;
padding-right: 15px;
}
th.payment-state {
text-align: right;
}
td.payment-state {
text-align: right;
text-transform: uppercase;
}
}
.text-right {
text-align: right;
}

View File

@@ -0,0 +1,47 @@
@import '../admin/variables';
// payment list, used in both invoice pdfs and order confirmation emails
table.payment-list {
width: 100%;
border-collapse: separate;
border-spacing: 0px;
font-size: 12px;
margin-bottom: 20px;
tbody tr td {
padding: 5px;
border-bottom: 1px solid $medium-grey;
.payment-method-name {
display: block;
font-weight: bold;
}
.payment-method-description {
display: block;
}
}
thead tr th {
border-bottom: 1px solid $medium-grey;
padding: 10px 5px 5px;
text-transform: uppercase;
text-align: left;
}
th.amount, td.amount {
text-align: right;
padding-right: 15px;
}
th.payment-state {
text-align: right;
}
td.payment-state {
text-align: right;
text-transform: uppercase;
}
}

View File

@@ -4,4 +4,8 @@ module OrderHelper
def last_payment_method(order)
OrderPaymentFinder.new(order).last_payment&.payment_method
end
def outstanding_balance_label(order)
order.outstanding_balance < 0 ? t(:credit_owed) : t(:balance_due)
end
end

View File

@@ -5,6 +5,7 @@ module Spree
helper HtmlHelper
helper ::CheckoutHelper
helper SpreeCurrencyHelper
helper Spree::Admin::PaymentsHelper
helper OrderHelper
include I18nHelper

View File

@@ -1,16 +0,0 @@
%table.payment-list
%thead
%tr
%th= "#{Spree.t('date')}/#{Spree.t('time')}"
%th.amount= t(:amount)
%th= t(:payment_method)
%th.payment-state= t(:payment_state)
%tbody
- payments.each do |payment|
%tr
%td= pretty_time(payment.created_at)
%td.amount= payment.display_amount.to_html
%td
%span.payment-method-name= payment_method_name(payment)
%span.payment-method-description= payment.payment_method.description
%td.payment-state= t(payment.state, scope: :payment_states, default: payment.state.capitalize)

View File

@@ -70,4 +70,4 @@
%p
= @order.distributor.invoice_text
= render 'spree/order_mailer/payment'
= render 'spree/shared/payment'

View File

@@ -13,7 +13,7 @@
- if @order.outstanding_balance?
%h5.outstanding-balance
= @order.outstanding_balance < 0 ? t(:credit_owed) : t(:balance_due)
= outstanding_balance_label(@order)
\:
%strong= @order.display_outstanding_balance

View File

@@ -21,7 +21,7 @@
= t :email_confirm_customer_details_html, distributor: @order.distributor.name
= render 'order_summary'
= render 'payment'
= render 'spree/shared/payment'
= render 'shipping'
= render 'special_instructions'
= render 'signoff'

View File

@@ -4,7 +4,7 @@
= t :email_payment_paid
- else
- if @order.outstanding_balance?
= @order.outstanding_balance < 0 ? t(:credit_owed) : t(:balance_due)
= outstanding_balance_label(@order)
\:
%strong= @order.display_outstanding_balance
- else
@@ -12,6 +12,4 @@
%strong
= t :email_payment_summary
- if @order.payments.any?
= render partial: 'list', locals: { payments: @order.payments }
- else
.alpha.twelve.columns.no-objects-found= t(:order_has_no_payments)
= render partial: 'spree/shared/payments_list', locals: { payments: @order.payments }

View File

@@ -0,0 +1,14 @@
%table.payment-list
%thead
%tr
%th= t('.date_time')
%th= t('.payment_method')
%th.payment-state= t('.payment_state')
%th.amount= t('.amount')
%tbody
- payments.each do |payment|
%tr
%td= l(payment.created_at, format: "%b %d, %Y %H:%M")
%td.payment-method-name= payment_method_name(payment)
%td.payment-state= t(payment.state, scope: :payment_states, default: payment.state.capitalize)
%td.amount= payment.display_amount.to_html

View File

@@ -3134,6 +3134,11 @@ See the %{link} to find out more about %{sitename}'s features and to start using
one: "1 error prohibited this record from being saved:"
other: "%{count} errors prohibited this record from being saved:"
there_were_problems_with_the_following_fields: "There were problems with the following fields"
payments_list:
date_time: "Date/time"
amount: "Amount"
payment_method: "Payment Method"
payment_state: "Payment State"
errors:
messages:
blank: "can't be blank"