diff --git a/app/assets/stylesheets/mail/email.scss b/app/assets/stylesheets/mail/email.scss index dee2738ead..a82ea6c9f9 100644 --- a/app/assets/stylesheets/mail/email.scss +++ b/app/assets/stylesheets/mail/email.scss @@ -1,3 +1,5 @@ +@import '../admin/variables'; + /* ------------------------------------- * GLOBAL *------------------------------------- */ diff --git a/app/assets/stylesheets/mail/payments_list.scss b/app/assets/stylesheets/mail/payments_list.scss new file mode 100644 index 0000000000..406c403e2d --- /dev/null +++ b/app/assets/stylesheets/mail/payments_list.scss @@ -0,0 +1,45 @@ +@import "../admin/variables"; + +// payment list, used in both invoice pdfs and order confirmation emails + +.payments-list { + width: 100%; + border-collapse: separate; + border-spacing: 0; + font-size: 12px; + margin-bottom: 20px; + + td { + padding: 5px; + border-bottom: 1px solid $medium-grey; + + .payment-method-name { + display: block; + font-weight: bold; + } + + .payment-method-description { + display: block; + } + } + + thead th { + border-bottom: 1px solid $medium-grey; + padding: 10px 5px 5px; + text-transform: uppercase; + text-align: left; + } + + .amount { + text-align: right; + padding-right: 15px; + } + + .payment-state { + text-align: right; + } + + .payment-state-value { + text-transform: uppercase; + } +} diff --git a/app/helpers/order_helper.rb b/app/helpers/order_helper.rb index 157ee212bb..c6ab5807bb 100644 --- a/app/helpers/order_helper.rb +++ b/app/helpers/order_helper.rb @@ -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.negative? ? t(:credit_owed) : t(:balance_due) + end end diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index ce9b79874e..844a3fac41 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -5,6 +5,7 @@ module Spree helper HtmlHelper helper ::CheckoutHelper helper SpreeCurrencyHelper + helper Spree::Admin::PaymentsHelper helper OrderHelper include I18nHelper diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 0267e24ef4..18d68cb504 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -2,6 +2,7 @@ class SubscriptionMailer < Spree::BaseMailer helper CheckoutHelper helper ShopMailHelper helper OrderHelper + helper Spree::Admin::PaymentsHelper include I18nHelper def confirmation_email(order) diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index ff4a930e5a..d4c20a02e1 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -70,4 +70,4 @@ %p = @order.distributor.invoice_text -= render 'spree/order_mailer/payment' += render 'spree/shared/payment' diff --git a/app/views/spree/admin/orders/invoice2.html.haml b/app/views/spree/admin/orders/invoice2.html.haml index b9715c2770..7344f7ead5 100644 --- a/app/views/spree/admin/orders/invoice2.html.haml +++ b/app/views/spree/admin/orders/invoice2.html.haml @@ -71,4 +71,4 @@ %p = @order.distributor.invoice_text -= render 'spree/order_mailer/payment' += render 'spree/shared/payment' diff --git a/app/views/spree/admin/payments/index.html.haml b/app/views/spree/admin/payments/index.html.haml index c06a473479..98e00c102d 100644 --- a/app/views/spree/admin/payments/index.html.haml +++ b/app/views/spree/admin/payments/index.html.haml @@ -14,7 +14,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 diff --git a/app/views/spree/order_mailer/_payment.html.haml b/app/views/spree/order_mailer/_payment.html.haml deleted file mode 100644 index 85ad234cda..0000000000 --- a/app/views/spree/order_mailer/_payment.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -%p.callout - %span{:style => "float:right;"} - - if @order.paid? - = t :email_payment_paid - - else - = t :email_payment_not_paid - %strong - = t :email_payment_summary -%h4 - = t :email_payment_method - %strong= last_payment_method(@order)&.name -%p - %em= last_payment_method(@order)&.description -%p   diff --git a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml index cfad3c42b5..13ce27a8ee 100644 --- a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml @@ -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' diff --git a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml index 3a0df14697..90ec5386d1 100644 --- a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml @@ -23,7 +23,7 @@ = @order.bill_address.phone if @order.bill_address.phone = render 'order_summary' -= render 'payment' += render 'spree/shared/payment' = render 'shipping' = render 'special_instructions' diff --git a/app/views/spree/shared/_payment.html.haml b/app/views/spree/shared/_payment.html.haml new file mode 100644 index 0000000000..f13e9b7892 --- /dev/null +++ b/app/views/spree/shared/_payment.html.haml @@ -0,0 +1,15 @@ +%p.callout + %span{:style => "float:right;"} + - if @order.outstanding_balance? + = outstanding_balance_label(@order) + \: + %strong= @order.display_outstanding_balance + - else + - if @order.paid? + = t :email_payment_paid + - else + = t :email_payment_not_paid + %strong + = t :email_payment_summary +- if @order.payments.any? + = render partial: 'spree/shared/payments_list', locals: { payments: @order.payments } diff --git a/app/views/spree/shared/_payments_list.html.haml b/app/views/spree/shared/_payments_list.html.haml new file mode 100644 index 0000000000..ca475aff2b --- /dev/null +++ b/app/views/spree/shared/_payments_list.html.haml @@ -0,0 +1,14 @@ +%table.payments-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.payment-state-value= t(payment.state, scope: :payment_states, default: payment.state.capitalize) + %td.amount= payment.display_amount.to_html diff --git a/app/views/subscription_mailer/confirmation_email.html.haml b/app/views/subscription_mailer/confirmation_email.html.haml index b2adb88f9a..3af1ef2d21 100644 --- a/app/views/subscription_mailer/confirmation_email.html.haml +++ b/app/views/subscription_mailer/confirmation_email.html.haml @@ -17,7 +17,7 @@ = render 'spree/order_mailer/order_summary' -= render 'spree/order_mailer/payment' += render 'spree/shared/payment' = render 'spree/order_mailer/shipping' = render 'spree/order_mailer/special_instructions' diff --git a/app/views/subscription_mailer/placement_email.html.haml b/app/views/subscription_mailer/placement_email.html.haml index 31f13b6513..9acb8aa7a1 100644 --- a/app/views/subscription_mailer/placement_email.html.haml +++ b/app/views/subscription_mailer/placement_email.html.haml @@ -28,7 +28,7 @@ = render 'spree/order_mailer/order_summary' -= render 'spree/order_mailer/payment' += render 'spree/shared/payment' = render 'spree/order_mailer/shipping' = render 'spree/order_mailer/special_instructions' diff --git a/config/locales/en.yml b/config/locales/en.yml index db3866eb5c..996022b994 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3138,6 +3138,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"