Created
June 30, 2010 18:54
-
-
Save jparker/459069 to your computer and use it in GitHub Desktop.
Initial implementation (FLAWED)
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
| %tr | |
| %td= link_to "Details", billable | |
| %td= h billable.client.name | |
| %td= h billable.booking.date.to_s(:short) | |
| %td= h billable.agency.name | |
| %td= h billable.job_type.name | |
| %td= h truncate(billable.vendor.name) | |
| %td= h truncate(billable.project.name) | |
| %td= number_to_currency billable.base_rate | |
| %td= number_to_currency billable.gross_rate | |
| %td= number_to_currency billable.commission_rate | |
| %td= number_to_currency billable.outstanding |
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
| class Search | |
| def initialize(query) | |
| @query = query | |
| end | |
| def billables | |
| # Billable.search parses the query and returns a named_scope with corresponding conditions | |
| @billables ||= Billable.search(@query) | |
| end | |
| def sum(column) | |
| billables.sum(column) | |
| end | |
| def needs_gross_invoice? | |
| billables.any? { |b| b.needs_gross_invoice? } | |
| end | |
| def needs_commission_invoice? | |
| billables.any? { |b| b.needs_commission_invoice? } | |
| end | |
| 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
| class SearchesController < ActionController::Base | |
| # GET /search[?page=#] | |
| def show | |
| @search = session[:search] | |
| @billables = @search.billables.paginate(:page => params[:page]) | |
| end | |
| # POST /search | |
| def create | |
| session[:search] = Search.new(params[:query]) | |
| redirect_to search_path | |
| end | |
| 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
| = link_to_if @search.needs_gross_invoice?, new_search_gross_invoice_path | |
| | | |
| = link_to_if @search.needs_commission_invoice?, new_search_commission_invoice_path | |
| %table | |
| %thead | |
| / ... | |
| %tfoot | |
| %tr | |
| %td{:colspan => ...} Totals | |
| %td= number_to_currency @search.sum(:base_rate) | |
| %td= number_to_currency @search.sum(:gross_rate) | |
| %td= number_to_currency @search.sum(:commission_rate) | |
| %td= number_to_currency @search.sum(:outstanding) | |
| %tbody | |
| = render @billables | |
| = will_paginate @billables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment