Skip to content

Commit

Permalink
🎨 Rounded off instead of using decimals for better cross db support
Browse files Browse the repository at this point in the history
  • Loading branch information
jurrigerretsen committed Feb 22, 2024
1 parent ec26fe6 commit 6d56aaa
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions models/core/revenuecat_subscription_transactions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ renamed as (
when (is_in_intro_offer_period = 'true' or product_duration is null)
then
case
when datediff(day, start_time, expected_end_time) between 0 and 1 then (30 * price_in_usd)
when datediff(day, start_time, expected_end_time) = 3 then (10 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 6 and 8 then (4 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 12 and 16 then (2 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 27 and 33 then (1 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 58 and 62 then (0.5 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 88 and 95 then (0.333333 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 179 and 185 then (0.1666666 * price_in_usd)
when datediff(day, start_time, expected_end_time) between 363 and 375 then (0.08333 * price_in_usd)
else ((28 / (datediff('s', start_time, expected_end_time) / (24 * 3600))) * price_in_usd)
when datediff(day, start_time, expected_end_time) between 0 and 1 then round(30 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) = 3 then round(10 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 6 and 8 then round(4 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 12 and 16 then round(2 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 27 and 33 then round(1 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 58 and 62 then round(0.5 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 88 and 95 then round(0.333333 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 179 and 185 then round(0.1666666 * price_in_usd, 2)
when datediff(day, start_time, expected_end_time) between 363 and 375 then round(0.08333 * price_in_usd, 2)
else round(((28 / (datediff('s', start_time, expected_end_time) / (24 * 3600))) * price_in_usd), 2)
end
/* then handle cases where product_duration can be used */
when product_duration = 'P1D' then (30 * price_in_usd)
when product_duration = 'P3D' then (10 * price_in_usd)
when product_duration = 'P7D' then (4 * price_in_usd)
when product_duration = 'P1W' then (4 * price_in_usd)
when product_duration = 'P2W' then (2 * price_in_usd)
when product_duration = 'P4W' then (1 * price_in_usd)
when product_duration = 'P1M' then (1 * price_in_usd)
when product_duration = 'P2M' then (0.5 * price_in_usd)
when product_duration = 'P3M' then (0.333333 * price_in_usd)
when product_duration = 'P6M' then (0.1666666 * price_in_usd)
when product_duration = 'P12M' then (0.08333 * price_in_usd)
when product_duration = 'P1Y' then (0.08333 * price_in_usd)
else ((28 / (datediff('s', start_time, expected_end_time) / (24 * 3600))) * price_in_usd)
when product_duration = 'P1D' then round(30 * price_in_usd, 2)
when product_duration = 'P3D' then round(10 * price_in_usd, 2)
when product_duration = 'P7D' then round(4 * price_in_usd, 2)
when product_duration = 'P1W' then round(4 * price_in_usd, 2)
when product_duration = 'P2W' then round(2 * price_in_usd, 2)
when product_duration = 'P4W' then round(1 * price_in_usd, 2)
when product_duration = 'P1M' then round(1 * price_in_usd, 2)
when product_duration = 'P2M' then round(0.5 * price_in_usd, 2)
when product_duration = 'P3M' then round(0.333333 * price_in_usd, 2)
when product_duration = 'P6M' then round(0.1666666 * price_in_usd, 2)
when product_duration = 'P12M' then round(0.08333 * price_in_usd, 2)
when product_duration = 'P1Y' then round(0.08333 * price_in_usd, 2)
else round(((28 / (datediff('s', start_time, expected_end_time) / (24 * 3600))) * price_in_usd), 2)
end
end as mrr_in_usd,
takehome_percentage,
Expand Down

0 comments on commit 6d56aaa

Please sign in to comment.