-
Notifications
You must be signed in to change notification settings - Fork 58
[Ledger] Add filters for merchants #11366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
<div data-tabs-target="tab" id="merchant"> | ||
<p class="italic text-center">Merchants are the company that charges a credit card. Non-card transactions will not be included when this filter is applied.</p> | ||
<%= turbo_frame_tag :merchants_filter, src: event_merchants_filter_path(@event, merchant: @merchant), loading: :lazy, target: "event_#{@event.id}_ledger" %> | ||
</div> | ||
<div data-tabs-target="tab" id="receipts"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for using a Turbo frame!
app/controllers/events_controller.rb
Outdated
def merchants_list | ||
settled_merchants = @event.canonical_transactions.map do |ct| | ||
rst = ct.raw_stripe_transaction | ||
|
||
if rst.present? | ||
merchant_data = rst.stripe_transaction["merchant_data"] | ||
yp_merchant = YellowPages::Merchant.lookup(network_id: merchant_data["network_id"]) | ||
{ id: merchant_data["network_id"], name: yp_merchant.name || merchant_data["name"].titleize } | ||
else | ||
nil | ||
end | ||
end.select(&:present?) | ||
|
||
pending_merchants = @event.canonical_pending_transactions.map do |cpt| | ||
rpst = cpt.raw_pending_stripe_transaction | ||
|
||
if rpst.present? | ||
merchant_data = rpst.stripe_transaction["merchant_data"] | ||
yp_merchant = YellowPages::Merchant.lookup(network_id: merchant_data["network_id"]) | ||
{ id: merchant_data["network_id"], name: yp_merchant.name || merchant_data["name"].titleize } | ||
else | ||
nil | ||
end | ||
end.select(&:present?) | ||
|
||
settled_merchants.concat(pending_merchants) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should belong in the model
ActiveRecord::Base.sanitize_sql_array(["and raw_stripe_transactions.stripe_transaction->'merchant_data'->>'network_id' = ?", @merchant]) | ||
end | ||
|
||
def stripe_joins_for(type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! I like this naming scheme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome work here! only real ask is moving as much of the merchant calculation as possible to the model
Summary of the problem
It'd be useful to be able to filter by merchant for card transactions on the ledger!
Closes #11330
Describe your changes
Modifies both
TransactionGroupingEngine::Transaction::All
andPendingTransactionEngine::PendingTransaction::All
to accept themerchants
filter, which is applied using SQL.Merchants for the current event are loaded lazily with a Turbo frame since some events have very large lists of merchants that they've used.