Last active
August 29, 2015 14:08
-
-
Save tinnguyenz/6f35893ba94a08a76adc 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
class Project::FinancialStatementsController < Project::BaseController | |
load_and_authorize_resource | |
include ::Project::PrjProjectsHelper | |
def update | |
@project = Project.find(params[:project_id]) | |
success = true | |
partial_info = {} | |
sheet = nil | |
if params[:target] == "ClientSheet" | |
sheet = @project.client_sheet | |
sheet.on_update_financial_statements = true | |
associations = [] | |
if @project.is_a?(PdtProject) | |
associations = [{:financial_statements => [:client, :orders, :billing_plans]}] | |
else | |
associations = [{:financial_statements => [:task]}] | |
end | |
# Eager load necessary associations. | |
sheet.preload_associations(associations) | |
if sheet.update_attributes(params[:client_sheet]) && sheet.errors.blank? | |
success = true | |
sheet.reload | |
partial_info = { | |
:partial => "project/shared/financial/financial_statements_info", | |
:locals => {:object => sheet} | |
} | |
# Render special form for PRJ Client sheet. | |
if @project.is_a?(PrjProject) | |
partial_info[:partial] = "project/prj_client_sheets/financial_statements_info" | |
end | |
else | |
success = false | |
end | |
elsif params[:target] == "ServiceSheet" | |
sheet = ServiceSheet.includes({:orders => :billing_plans}).find(params[:target_id]) | |
sheet.on_update_financial_statements = true | |
if sheet.update_attributes(params[:service_sheet]) | |
success = true | |
sheet.reload | |
if sheet.financial_statements.blank? | |
# Build a new financial statement to ensure that | |
# the input fields for financial statement will always display. | |
sheet.financial_statements.build | |
end | |
partial_info = { | |
:partial => "project/shared/financial/financial_statements_info", | |
:locals => {:object => sheet} | |
} | |
if @project.is_a?(PrjProject) | |
partial_info[:partial] = "project/prj_service_sheets/financial_statements_info" | |
elsif @project.is_a?(PrsProject) | |
partial_info[:partial] = "project/prs_service_sheets/financial_statements_info" | |
elsif @project.is_a?(PgiProject) | |
partial_info[:partial] = "project/pgi_service_sheets/financial_statements_info" | |
end | |
else | |
success = false | |
end | |
end | |
if success | |
render(:json => {:status => "success", :html => render_to_string(partial_info)}) | |
else | |
# Re-render the financial form to show error messages. | |
render(:json => {:status => "error", :html => render_financial_statement_form(sheet)}) | |
end | |
end | |
def set_current_tab | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment