Module: Crm::Reports::BudgetHelper

Defined in:
app/helpers/crm/reports/budget_helper.rb

Instance Method Summary collapse

Instance Method Details

#add_business_unit(q, business_unit_id = nil) ⇒ Object



62
63
64
# File 'app/helpers/crm/reports/budget_helper.rb', line 62

def add_business_unit(q, business_unit_id = nil)
	business_unit_id.nil? ? q : q.where(:business_unit_id => business_unit_id)
end

#build_actual_accumulated(amount_field, ledger_company_account_ids, business_unit_id = nil) ⇒ Object



21
22
23
24
25
# File 'app/helpers/crm/reports/budget_helper.rb', line 21

def build_actual_accumulated(amount_field, , business_unit_id = nil)
	q = @ledger_entries_accumulated.where(:ledger_company_account_id => )
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_actual_accumulated_previous(amount_field, ledger_company_account_ids, business_unit_id = nil) ⇒ Object



33
34
35
36
37
# File 'app/helpers/crm/reports/budget_helper.rb', line 33

def build_actual_accumulated_previous(amount_field, , business_unit_id = nil)
	q = @ledger_entries_accumulated_previous.where(:ledger_company_account_id => )
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_actual_month(amount_field, ledger_company_account_ids, business_unit_id = nil) ⇒ Object



9
10
11
12
13
# File 'app/helpers/crm/reports/budget_helper.rb', line 9

def build_actual_month(amount_field, , business_unit_id = nil)
	q = @ledger_entries_month.where(:ledger_company_account_id => )
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_actual_month_previous(amount_field, ledger_company_account_ids, business_unit_id = nil) ⇒ Object



27
28
29
30
31
# File 'app/helpers/crm/reports/budget_helper.rb', line 27

def build_actual_month_previous(amount_field, , business_unit_id = nil)
	q = @ledger_entries_month_previous.where(:ledger_company_account_id => )
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_budget_accumulated(amount_field, ledger_account_id, company_id, business_unit_id = nil) ⇒ Object



15
16
17
18
19
# File 'app/helpers/crm/reports/budget_helper.rb', line 15

def build_budget_accumulated(amount_field, , company_id, business_unit_id = nil)
	q = @budgets_accumulated.where(:ledger_account_id => , :company_id => company_id)
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_budget_month(amount_field, ledger_account_id, company_id, business_unit_id = nil) ⇒ Object



3
4
5
6
7
# File 'app/helpers/crm/reports/budget_helper.rb', line 3

def build_budget_month(amount_field, , company_id, business_unit_id = nil)
	q = @budgets.where(:ledger_account_id => , :company_id => company_id)
	q = add_business_unit(q, business_unit_id)
	q_sum(q, amount_field)
end

#build_ledger_company_account_ids(budget, company_id) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/crm/reports/budget_helper.rb', line 43

def (budget, company_id)
  ids = case company_id
        when [Company::USA]
          budget.
        when [Company::CAN]
          budget.
        when [Company::NLD]
          budget.
        when [Company::USA, Company::CAN]
          budget. + budget.
        end
  ids.collect { |id| id.to_i }
end

#build_percentage(diff, original) ⇒ Object



39
40
41
# File 'app/helpers/crm/reports/budget_helper.rb', line 39

def build_percentage(diff, original)
	diff.zero? ? 0 : ( original.zero? ? 100 : ((diff / original) * 100))
end

#q_sum(q, amount_field) ⇒ Object



57
58
59
60
# File 'app/helpers/crm/reports/budget_helper.rb', line 57

def q_sum(q, amount_field)
	q = q.sum(amount_field)
	-q.round
end