Skip to content

Commit eeea797

Browse files
committed
Adjust scale for sales
1 parent 718a7c0 commit eeea797

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

fullstack/lib/fullstack/financial.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ defmodule Fullstack.Financial do
9393
## end
9494

9595
def set_transactions_total_amount(transactions) do
96-
Enum.reduce(transactions, 0, fn trx, acc -> trx.amount + acc end)
96+
sum =
97+
transactions
98+
|> Enum.reduce(0.0, fn trx, acc -> trx.amount + acc end)
99+
|> :erlang.float_to_binary(decimals: 2)
100+
101+
"$ #{sum}"
97102
end
98103

99104
def set_biggest_transactions(transactions) do

fullstack/lib/fullstack/financial/transactions.ex

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ defmodule Fullstack.Financial.Transactions do
4242
|> with_amount_range(params)
4343
|> from_customer(params)
4444
|> from_pos(params)
45+
|> maybe_select_fields(params)
4546
|> Repo.all()
4647
end
4748

fullstack/lib/fullstack/utils/charts/dates.ex fullstack/lib/fullstack/utils/charts/charts_dates.ex

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ defmodule Fullstack.Utils.Charts.ChartsDates do
3636

3737
Map.put(acc, key, values)
3838
end)
39-
|> Enum.map(fn {[_, m], %{count: count, amount: amount}} ->
39+
|> Enum.map(fn {[y, m], %{count: count, amount: amount}} ->
40+
month = if y == "2025", do: String.to_integer(m) + 12, else: String.to_integer(m)
41+
4042
[
41-
String.to_integer(m),
43+
month,
4244
count,
43-
Float.ceil(amount / 100_000, 2)
45+
Float.ceil(amount / 10_000, 2)
4446
]
4547
end)
4648
end

fullstack/lib/fullstack_web/live/public/public_transactions.ex

+8-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
9797
end
9898

9999
defp make_point_plot(data, bar_options, selected_bar) do
100-
series_cols = ["Count", "Amount"]
100+
series_cols = ["Count", "$ k"]
101101
test_data = Dataset.new(data, ["Day" | series_cols])
102102

103103
options = [
@@ -125,7 +125,7 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
125125
defp make_red_plot(data) do
126126
Sparkline.new(data)
127127
|> Sparkline.colours("#fad48e", "#ff9838")
128-
|> Map.update!(:height, fn _ -> 60 end)
128+
|> Map.update!(:height, fn _ -> 30 end)
129129
|> Map.update!(:width, fn _ -> 150 end)
130130
|> Sparkline.draw()
131131
end
@@ -145,9 +145,14 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
145145
def format_trx_period(value) do
146146
value
147147
|> round()
148+
|> fix_over_year()
148149
|> Timex.month_name()
149150
end
150151

152+
defp fix_over_year(value) do
153+
if value > 12, do: value - 12, else: value
154+
end
155+
151156
def build_pointplot(dataset, chart_options) do
152157
module =
153158
case chart_options.type do
@@ -233,7 +238,7 @@ defmodule FullstackWeb.Public.TransactionsLive.PublicTransactions do
233238

234239
data = socket.assigns.info.monthly_data
235240

236-
series_cols = ["Count", "Amount"]
241+
series_cols = ["Count", "$ *100"]
237242

238243
test_data =
239244
case needs_update do

fullstack/lib/fullstack_web/live/public/public_transactions.html.heex

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<dt class="order-last text-lg font-medium text-gray-500">Total Sales</dt>
2222

2323
<dd class="text-xl font-extrabold text-blue-600 md:text-2xl">
24-
$ <%= @info.total_amount %>
24+
<%= @info.total_amount %>
2525
</dd>
2626
</div>
2727
</dl>

0 commit comments

Comments
 (0)