Skip to content

Commit

Permalink
Complete statistics displayed in mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Aug 3, 2015
1 parent c92f39d commit 097e54b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
18 changes: 14 additions & 4 deletions app/mailers/statistics_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
class StatisticsMailer < ActionMailer::Base
default from: EMAIL_ADDRESSES['StatisticsMailer']['mailer_sender']

def last_months_numbers_email(revenue_hash)
@revenue_hash = revenue_hash
@month = I18n.l(1.month.ago, format: '%B')
def last_months_numbers_email(statistics)
@revenue_hash = statistics.revenue_last_month
@new_users = statistics.new_users_last_month
@legal_entities_count = statistics.legal_entities_count
@private_users_count = statistics.private_users_count
@legal_entity_articles_count = statistics.legal_entity_articles_count
@private_user_articles_count = statistics.private_user_articles_count
@sum_article_prices = statistics.sum_article_prices
@sum_article_prices_with_quantity = statistics.sum_article_prices_with_quantity

@month = 1.month.ago
@date = Date.today

mail(to: EMAIL_ADDRESSES['StatisticsMailer']['mailer_recipient'],
subject: "Statistiken für den Fairmondo-Marktplatz vom #{@month}")
subject: "Statistiken für den Fairmondo-Marktplatz vom #{I18n.l @month, format: '%B'}")
end

end
17 changes: 16 additions & 1 deletion app/views/statistics_mailer/last_months_numbers_email.text.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
Dies sind die Statistiken für den Fairmondo-Marktplatz für den <%= @month %>.
Hallo,

hier die aktuellen Zahlen für den Fairmondo-Marktplatz im Monat <%= I18n.l @month, format: '%B' %>:

Umsatz: <%= @revenue_hash[:revenue] / 100.0 %>
Gebühr: <%= @revenue_hash[:fee] / 100.0 %>
Faires Prozent: <%= @revenue_hash[:fair] / 100.0 %>

Neue Nutzer: <%= @new_users %>


Insgesamt haben wir heute, am <%= I18n.l @date %>, auf dem Marktplatz:

Geschäftskunden: <%= @legal_entities_count %>
Privatkunden: <%= @private_users_count %>
Artikel von Geschäftskunden: <%= @legal_entity_articles_count %>
Artikel von Privatkunden: <%= @private_user_articles_count %>
Eingestellter Warenwert (ohne Artikelstückzahlen): <%= @sum_article_prices %> Euro
Eingestellter Warenwert (mit Artikelstückzahlen): <%= @sum_article_prices_with_quantity %> Euro


Viele Grüße
Dein Fairmondo-Technik-Team
4 changes: 2 additions & 2 deletions app/workers/statistics_mailer_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class StatisticsMailerWorker
include Sidetiq::Schedulable

recurrence do
hourly
daily
end

def perform
statistics = Statistic.new
message = StatisticsMailer.last_months_numbers_email(statistics.revenue_last_month)
message = StatisticsMailer.last_months_numbers_email(statistics)
message.deliver!
end
end

0 comments on commit 097e54b

Please sign in to comment.