Module: Dorsale::BillingMachine::ApplicationHelper

Included in:
AllHelpers
Defined in:
app/helpers/dorsale/billing_machine/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#billing_machine_invoices_chartObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 36

def billing_machine_invoices_chart
  invoices = policy_scope(::Dorsale::BillingMachine::Invoice)
    .where("date > ?", 1.year.ago.beginning_of_month)

  totals = {}

  (0..12).to_a.reverse.map do |n|
    date  = n.month.ago
    label = l(date, format: "%B %Y").titleize
    totals[label] = 0
    invoices.each do |i|
      next if i.date.year  != date.year
      next if i.date.month != date.month
      totals[label] += i.total_excluding_taxes
    end
  end

  column_chart totals, height: "200px"
end

#billing_machine_payment_status_for_filter_selectObject



18
19
20
21
22
23
24
25
26
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 18

def billing_machine_payment_status_for_filter_select
  {
    ::Dorsale::BillingMachine::Invoice.t("payment_status.all")     => "",
    ::Dorsale::BillingMachine::Invoice.t("payment_status.unpaid")  => "unpaid",
    ::Dorsale::BillingMachine::Invoice.t("payment_status.pending") => "pending",
    ::Dorsale::BillingMachine::Invoice.t("payment_status.late")    => "late",
    ::Dorsale::BillingMachine::Invoice.t("payment_status.paid")    => "paid",
  }
end

#billing_machine_quotation_states_for_filter_selectObject



11
12
13
14
15
16
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 11

def billing_machine_quotation_states_for_filter_select
    [
      [::Dorsale::BillingMachine::Quotation.t("state.all"), ""],
      [::Dorsale::BillingMachine::Quotation.t("state.not_canceled"), "not_canceled"],
    ] + billing_machine_quotation_states_for_select
end

#billing_machine_quotation_states_for_selectObject



2
3
4
5
6
7
8
9
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 2

def billing_machine_quotation_states_for_select
  ::Dorsale::BillingMachine::Quotation::STATES.map do |e|
    [
      ::Dorsale::BillingMachine::Quotation.t("state.#{e}"),
      e,
    ]
  end
end

#bm_currency(n) ⇒ Object



56
57
58
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 56

def bm_currency(n)
  currency(n, ::Dorsale::BillingMachine.default_currency)
end

#quotation_state_classes(quotation) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/dorsale/billing_machine/application_helper.rb', line 28

def quotation_state_classes(quotation)
  if quotation.state == "pending" && quotation.date < 1.month.ago
    return "pending late"
  else
    return quotation.state
  end
end