Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/controllers/profitable/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
module Profitable
class DashboardController < BaseController
def index
end
@mrr = Profitable.mrr
@mrr_growth_rate = Profitable.mrr_growth_rate
@total_customers = Profitable.total_customers
@all_time_revenue = Profitable.all_time_revenue
@estimated_valuation = Profitable.estimated_valuation
@average_revenue_per_customer = Profitable.average_revenue_per_customer
@lifetime_value = Profitable.lifetime_value

private
@show_milestone = @mrr_growth_rate > 0
@milestone_message = Profitable.time_to_next_mrr_milestone if @show_milestone

def test
end
@monthly_summary = Profitable.monthly_summary(months: 12)
@daily_summary = Profitable.daily_summary(days: 30)

@periods = [24.hours, 7.days, 30.days]
@period_data = @periods.each_with_object({}) do |period, hash|
hash[period] = Profitable.period_data(in_the_last: period)
end
end
end
end
169 changes: 151 additions & 18 deletions app/views/profitable/dashboard/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<style>
main h2.title {
font-size: 1.25rem;
margin: 64px 0 12px 0;
}

.card-grid {
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -32,78 +37,206 @@

<header>
<h1>💸 <%= Rails.application.class.module_parent_name %></h1>
<% if Profitable.mrr_growth_rate > 0 %>
<p><%= Profitable.time_to_next_mrr_milestone %></p>
<% if @show_milestone %>
<p><%= @milestone_message %></p>
<% end %>
</header>

<main>

<div class="card-grid">
<div class="card">
<h2><%= Profitable.total_customers.to_readable %></h2>
<h2><%= @total_customers.to_readable %></h2>
<p>total customers</p>
</div>
<div class="card">
<h2><%= Profitable.mrr.to_readable %></h2>
<h2><%= @mrr.to_readable %></h2>
<p>MRR</p>
</div>
<div class="card">
<h2><%= Profitable.estimated_valuation.to_readable %></h2>
<h2><%= @estimated_valuation.to_readable %></h2>
<p>Valuation at 3x ARR</p>
</div>
<div class="card">
<h2><%= Profitable.mrr_growth_rate.to_readable %></h2>
<h2><%= @mrr_growth_rate.to_readable %></h2>
<p>MRR growth rate</p>
</div>
<div class="card">
<h2><%= Profitable.average_revenue_per_customer.to_readable %></h2>
<h2><%= @average_revenue_per_customer.to_readable %></h2>
<p>ARPC</p>
</div>
<div class="card">
<h2><%= Profitable.lifetime_value.to_readable %></h2>
<h2><%= @lifetime_value.to_readable %></h2>
<p>LTV</p>
</div>
<div class="card">
<h2><%= Profitable.all_time_revenue.to_readable %></h2>
<h2><%= @all_time_revenue.to_readable %></h2>
<p>All-time revenue</p>
</div>
</div>

<% [24.hours, 7.days, 30.days].each do |period| %>
<h2 class="title">Monthly summary</h2>
<small>(last 12 months)</small>

<style>
.summary-table {
width: 100%;
border-collapse: collapse;
margin-top: 16px;
background-color: var(--bg);
border: 1px solid var(--border);
border-radius: var(--standard-border-radius);
overflow: hidden;
}

.summary-table th,
.summary-table td {
padding: 12px 16px;
text-align: left;
border-bottom: 1px solid var(--border);
}

.summary-table th {
font-weight: 600;
background-color: var(--bg);
position: sticky;
top: 0;
}

.summary-table tr:last-child td {
border-bottom: none;
}

.summary-table .positive {
color: #10b981;
}

.summary-table .negative {
color: #ef4444;
}

.summary-table .muted {
color: #6b7280;
font-size: 0.875em;
}

.summary-table tbody tr:hover {
background-color: rgba(0, 0, 0, 0.02);
}
</style>

<table class="summary-table">
<thead>
<tr>
<th>Month</th>
<th>New</th>
<th>Churned</th>
<th>Net</th>
<th>Churn %</th>
</tr>
</thead>
<tbody>
<% @monthly_summary.reverse.each do |month_data| %>
<tr>
<td><strong><%= month_data[:month_date].strftime('%b %Y') %></strong></td>
<td>
<span class="positive">+<%= month_data[:new_subscribers] %></span>
<span class="muted">(~<%= number_to_currency(month_data[:new_mrr] / 100.0, precision: 0) %>)</span>
</td>
<td>
<% if month_data[:churned_subscribers] > 0 %>
<span class="negative">-<%= month_data[:churned_subscribers] %></span>
<span class="muted">(~<%= number_to_currency(month_data[:churned_mrr] / 100.0, precision: 0) %>)</span>
<% else %>
<span>0</span>
<% end %>
</td>
<td>
<% if month_data[:net_subscribers] > 0 %>
<span class="positive">+<%= month_data[:net_subscribers] %></span>
<span class="muted">(~+<%= number_to_currency(month_data[:net_mrr] / 100.0, precision: 0) %>)</span>
<% elsif month_data[:net_subscribers] < 0 %>
<span class="negative"><%= month_data[:net_subscribers] %></span>
<span class="muted">(~<%= number_to_currency(month_data[:net_mrr] / 100.0, precision: 0) %>)</span>
<% else %>
<span>0</span>
<% end %>
</td>
<td><%= month_data[:churn_rate] %>%</td>
</tr>
<% end %>
</tbody>
</table>

<h2 class="title">Daily summary</h2>
<small>(last 30 days)</small>

<table class="summary-table">
<thead>
<tr>
<th>Date</th>
<th>New Subscribers</th>
<th>Churned</th>
</tr>
</thead>
<tbody>
<% @daily_summary.reverse.each do |day_data| %>
<tr>
<td><strong><%= day_data[:date].strftime('%b %-d, %Y') %></strong></td>
<td>
<% if day_data[:new_subscribers] > 0 %>
<span class="positive">+<%= day_data[:new_subscribers] %></span>
<% else %>
<span>0</span>
<% end %>
</td>
<td>
<% if day_data[:churned_subscribers] > 0 %>
<span class="negative">-<%= day_data[:churned_subscribers] %></span>
<% else %>
<span>0</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

<% @periods.each do |period| %>
<% period_short = period.inspect.gsub("days", "d").gsub("hours", "h").gsub(" ", "") %>
<% data = @period_data[period] %>

<h2>Last <%= period.inspect %></h2>
<h2 class="title">Last <%= period.inspect %></h2>

<div class="card-grid">
<div class="card">
<h2><%= Profitable.new_customers(in_the_last: period).to_readable %></h2>
<h2><%= data[:new_customers].to_readable %></h2>
<p>new customers (<%= period_short %>)</p>
</div>
<div class="card">
<h2><%= Profitable.churned_customers(in_the_last: period).to_readable %></h2>
<h2><%= data[:churned_customers].to_readable %></h2>
<p>churned customers (<%= period_short %>)</p>
</div>
<div class="card">
<h2><%= Profitable.churn(in_the_last: period).to_readable %></h2>
<h2><%= data[:churn].to_readable %></h2>
<p>churn (<%= period_short %>)</p>
</div>

<div class="card">
<h2><%= Profitable.new_mrr(in_the_last: period).to_readable %></h2>
<h2><%= data[:new_mrr].to_readable %></h2>
<p>new MRR (<%= period_short %>)</p>
</div>
<div class="card">
<h2><%= Profitable.churned_mrr(in_the_last: period).to_readable %></h2>
<h2><%= data[:churned_mrr].to_readable %></h2>
<p>churned MRR (<%= period_short %>)</p>
</div>
<div class="card">
<h2><%= Profitable.mrr_growth(in_the_last: period).to_readable %></h2>
<h2><%= data[:mrr_growth].to_readable %></h2>
<p>MRR growth (<%= period_short %>)</p>
</div>

<div class="card">
<h2><%= Profitable.revenue_in_period(in_the_last: period).to_readable %></h2>
<h2><%= data[:revenue].to_readable %></h2>
<p>total revenue (<%= period_short %>)</p>
</div>

Expand Down
Loading