From 6ecf896fa2b34509f5d915e4d8a92d957892ac90 Mon Sep 17 00:00:00 2001 From: Steve Pettitt Date: Tue, 10 May 2016 23:04:06 +0100 Subject: [PATCH] HTML order cycle report email, text customisable in translations --- app/assets/stylesheets/mail/email.css.sass | 3 + app/mailers/producer_mailer.rb | 5 ++ .../order_cycle_report.html.haml | 62 +++++++++++++++++++ .../order_cycle_report.text.haml | 4 +- config/locales/en.yml | 3 + spec/mailers/producer_mailer_spec.rb | 1 + 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 app/views/producer_mailer/order_cycle_report.html.haml diff --git a/app/assets/stylesheets/mail/email.css.sass b/app/assets/stylesheets/mail/email.css.sass index 4256357923..e9eabd4edb 100644 --- a/app/assets/stylesheets/mail/email.css.sass +++ b/app/assets/stylesheets/mail/email.css.sass @@ -74,6 +74,9 @@ table.order-summary padding-left: 5px padding-right: 5px +.text-right + text-align: right + .social .soc-btn padding: 3px 7px font-size: 12px diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 52decf5d8a..9f776abc81 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -7,6 +7,7 @@ class ProducerMailer < Spree::BaseMailer @line_items = aggregated_line_items_from(@order_cycle, @producer) @receival_instructions = @order_cycle.receival_instructions_for @producer @total = total_from_line_items(@line_items) + @tax_total = tax_total_from_line_items(@line_items) subject = "[#{Spree::Config.site_name}] Order cycle report for #{producer.name}" @@ -53,4 +54,8 @@ class ProducerMailer < Spree::BaseMailer def total_from_line_items(aggregated_line_items) Spree::Money.new(aggregated_line_items.values.map(&:total).reduce(:+)).to_s end + + def tax_total_from_line_items(aggregated_line_items) + Spree::Money.new(aggregated_line_items.values.map(&:included_tax).reduce(:+)).to_s + end end diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml new file mode 100644 index 0000000000..66276745b5 --- /dev/null +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -0,0 +1,62 @@ +%p Dear #{@producer.name}, +%p + = t :producer_mail_text_before + - if @receival_instructions + %p + Stock pickup/delivery instructions: + = @receival_instructions +%p + Here is a summary of the orders for your products: + %table.order-summary + %thead + %tr + %th + = t :sku + %th + = t :supplier + %th + = t :product + %th.text-right + = t :quantity + %th.text-right + = t :price + %th.text-right + = t :subtotal + %th.text-right + = t :included_tax + %tbody + - @line_items.each_pair do |variant, line_item| + %tr + %td + #{variant.sku} + %td + #{raw(variant.product.supplier.name)} + %td + #{raw(variant.product_and_full_name)} + %td.text-right + #{line_item.quantity} + %td.text-right + #{line_item.single_money} + %td.text-right + #{line_item.display_total} + %td.text-right + #{line_item.display_included_tax} + %tr.total_row + %td + %td + %td + %td + %td + %td.text-right + #{@total} + %td.text-right + #{@tax_total} +%p + = t :producer_mail_text_after + %em + %p + #{@coordinator.name} + %p + #{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} + #{@coordinator.phone} + #{@coordinator.email} diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index ea035391b8..5c94107bd4 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -1,6 +1,6 @@ Dear #{@producer.name}, \ -We now have all the consumer orders for the next food drop. += t :producer_mail_text_before \ - if @receival_instructions Stock pickup/delivery instructions: @@ -18,7 +18,7 @@ Here is a summary of the orders for your products: \ Total: #{@total} \ -Thanks and best wishes, += t :producer_mail_text_after #{@coordinator.name} #{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} #{@coordinator.phone} diff --git a/config/locales/en.yml b/config/locales/en.yml index 7b5f9b168f..4b53aa6e5a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -401,6 +401,9 @@ See the %{link} to find out more about %{sitename}'s features and to start using If you are a producer or food enterprise, we are excited to have you as a part of the network." email_signup_help_html: "We welcome all your questions and feedback; you can use the Send Feedback button on the site or email us at" + producer_mail_text_before: "We now have all the consumer orders for the next food drop." + producer_mail_text_after: "Thanks and best wishes," + shopping_oc_closed: Orders are closed shopping_oc_closed_description: "Please wait until the next cycle opens (or contact us directly to see if we can accept any late orders)" shopping_oc_last_closed: "The last cycle closed %{distance_of_time} ago" diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 4e3fd912d2..e1c91af699 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -63,6 +63,7 @@ describe ProducerMailer do end it "includes the total" do + puts mail.body.encoded mail.body.should include 'Total: $20.00' end