-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add columns to transactions snapshot infos
- Loading branch information
Showing
5 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class GetTransactionsSnapshotInfoSummaryJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(snapshot_info, date) | ||
total_summary = date == Date.today ? OriginTransaction.total_summary : snapshot_info.snapshot_records.total_summary(date: snapshot_info.event_date) | ||
total_revenue = total_summary[:total_revenue].to_f | ||
total_cost = total_summary[:total_cost].to_f | ||
total_roi = total_cost == 0 ? 0 : ((total_revenue / total_cost) * 100).round(4) | ||
|
||
snapshot_info.update( | ||
profit_count: total_summary[:profit_count], | ||
profit_amount: total_summary[:profit_amount], | ||
loss_count: total_summary[:loss_count], | ||
loss_amount: total_summary[:loss_amount], | ||
total_cost: total_cost, | ||
total_revenue: total_revenue, | ||
total_roi: total_roi, | ||
max_profit: total_summary[:max_profit], | ||
max_profit_date: total_summary[:max_profit_date], | ||
max_loss: total_summary[:max_loss], | ||
max_loss_date: total_summary[:max_loss_date], | ||
max_revenue: total_summary[:max_revenue], | ||
max_revenue_date: total_summary[:max_revenue_date], | ||
min_revenue: total_summary[:min_revenue], | ||
min_revenue_date: total_summary[:min_revenue_date], | ||
max_roi: total_summary[:max_roi], | ||
max_roi_date: total_summary[:max_roi_date], | ||
max_profit_roi: total_summary[:max_profit_roi], | ||
max_profit_roi_date: total_summary[:max_profit_roi_date], | ||
max_loss_roi: total_summary[:max_loss_roi], | ||
max_loss_roi_date: total_summary[:max_loss_roi_date], | ||
min_roi: total_summary[:min_roi], | ||
min_roi_date: total_summary[:min_roi_date] | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
db/migrate/20231104080315_add_columns_to_transactions_snapshot_infos.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class AddColumnsToTransactionsSnapshotInfos < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :transactions_snapshot_infos, :total_cost, :decimal | ||
add_column :transactions_snapshot_infos, :total_revenue, :decimal | ||
add_column :transactions_snapshot_infos, :total_roi, :decimal | ||
add_column :transactions_snapshot_infos, :profit_count, :integer | ||
add_column :transactions_snapshot_infos, :profit_amount, :decimal | ||
add_column :transactions_snapshot_infos, :loss_count, :integer | ||
add_column :transactions_snapshot_infos, :loss_amount, :decimal | ||
add_column :transactions_snapshot_infos, :max_profit, :decimal | ||
add_column :transactions_snapshot_infos, :max_loss, :decimal | ||
add_column :transactions_snapshot_infos, :max_revenue, :decimal | ||
add_column :transactions_snapshot_infos, :min_revenue, :decimal | ||
add_column :transactions_snapshot_infos, :max_profit_date, :datetime | ||
add_column :transactions_snapshot_infos, :max_loss_date, :datetime | ||
add_column :transactions_snapshot_infos, :max_revenue_date, :datetime | ||
add_column :transactions_snapshot_infos, :min_revenue_date, :datetime | ||
add_column :transactions_snapshot_infos, :max_roi, :decimal | ||
add_column :transactions_snapshot_infos, :max_roi_date, :datetime | ||
add_column :transactions_snapshot_infos, :max_profit_roi, :decimal | ||
add_column :transactions_snapshot_infos, :max_profit_roi_date, :datetime | ||
add_column :transactions_snapshot_infos, :max_loss_roi, :decimal | ||
add_column :transactions_snapshot_infos, :max_loss_roi_date, :datetime | ||
add_column :transactions_snapshot_infos, :min_roi, :decimal | ||
add_column :transactions_snapshot_infos, :min_roi_date, :datetime | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.