From debbf9b361cb81c611e5b0abd830f31ea7bfc9bc Mon Sep 17 00:00:00 2001 From: Steve Roberts Date: Tue, 7 Jul 2020 22:05:27 +1000 Subject: [PATCH] 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 --- app/assets/stylesheets/mail/email.scss | 43 ----------------- app/assets/stylesheets/mail/payment_list.scss | 47 +++++++++++++++++++ app/helpers/order_helper.rb | 4 ++ app/mailers/spree/order_mailer.rb | 1 + app/views/spree/admin/orders/_list.html.haml | 16 ------- .../spree/admin/orders/invoice.html.haml | 2 +- .../spree/admin/payments/index.html.haml | 2 +- .../confirm_email_for_customer.html.haml | 2 +- .../_payment.html.haml | 6 +-- .../spree/shared/_payments_list.html.haml | 14 ++++++ config/locales/en.yml | 5 ++ 11 files changed, 76 insertions(+), 66 deletions(-) create mode 100644 app/assets/stylesheets/mail/payment_list.scss delete mode 100644 app/views/spree/admin/orders/_list.html.haml rename app/views/spree/{order_mailer => shared}/_payment.html.haml (59%) create mode 100644 app/views/spree/shared/_payments_list.html.haml diff --git a/app/assets/stylesheets/mail/email.scss b/app/assets/stylesheets/mail/email.scss index 7c632ed913..a82ea6c9f9 100644 --- a/app/assets/stylesheets/mail/email.scss +++ b/app/assets/stylesheets/mail/email.scss @@ -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; } diff --git a/app/assets/stylesheets/mail/payment_list.scss b/app/assets/stylesheets/mail/payment_list.scss new file mode 100644 index 0000000000..7cf6b3ba8e --- /dev/null +++ b/app/assets/stylesheets/mail/payment_list.scss @@ -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; + } + } + \ No newline at end of file diff --git a/app/helpers/order_helper.rb b/app/helpers/order_helper.rb index 157ee212bb..ba47bcdd25 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 < 0 ? 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/views/spree/admin/orders/_list.html.haml b/app/views/spree/admin/orders/_list.html.haml deleted file mode 100644 index 898c3d5288..0000000000 --- a/app/views/spree/admin/orders/_list.html.haml +++ /dev/null @@ -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) \ No newline at end of file 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/payments/index.html.haml b/app/views/spree/admin/payments/index.html.haml index 7fbe76429f..a3df9f1c80 100644 --- a/app/views/spree/admin/payments/index.html.haml +++ b/app/views/spree/admin/payments/index.html.haml @@ -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 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/_payment.html.haml b/app/views/spree/shared/_payment.html.haml similarity index 59% rename from app/views/spree/order_mailer/_payment.html.haml rename to app/views/spree/shared/_payment.html.haml index 1f5ef0375a..8b7b26b074 100644 --- a/app/views/spree/order_mailer/_payment.html.haml +++ b/app/views/spree/shared/_payment.html.haml @@ -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 } 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..32bec2e1b1 --- /dev/null +++ b/app/views/spree/shared/_payments_list.html.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 6177ff03e6..f05dad652b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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"