-
-
Save jschoolcraft/184225 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ## Error: | |
| undefined method `calculate_state_revenue' for #<Shop:0x105be6490> |
This file contains hidden or 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
| # View Code | |
| <h1>Total sales for the trailing 4 quarters by state</h1> | |
| <h2>Rhode Island</h2> | |
| <p><%= @shop.calculate_state_revenue("RI") %></p> | |
| <h2>New York</h2> | |
| <p><%= @shop.calculate_state_revenue("NY") %></p> | |
| <h2>North Carolina</h2> | |
| <p><%= @shop.calculate_state_revenue("NC") %></p> |
This file contains hidden or 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
| #controller code | |
| def sales_tax_states | |
| @shop = your_shop | |
| end | |
This file contains hidden or 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
| #Model Code | |
| def calculate_state_revenue(state) | |
| @affiliates = select_state(state) # gets all affiliates from the state | |
| @orders_unpaginated = orders | |
| #use inject to add up their order totals. | |
| @state_total = @affiliates.inject {|result, affiilate| | |
| result = @orders_unpaginated.calculate(:sum, "order_total", :conditions => ['affiliate_code = ?', affiliate.affiliate_code]) | |
| result | |
| } | |
| @state_total | |
| end | |
| #select the state, duh! | |
| def select_state(arg) | |
| #find all affiliates by the status state_active, which means they are one of the taxation states. | |
| your_shop.users.find_all_by_status("#{arg}_State_Active") #unless your_shop.users.blank? | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment