Class: Report::AccountsPayableCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
app/services/report/accounts_payable_command.rb

Overview

Service object: accounts payable command.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.company_optionsObject

Company options.

Returns:

  • (Object)


37
38
39
# File 'app/services/report/accounts_payable_command.rb', line 37

def self.company_options
  Company.select_options_sales_companies
end

Instance Method Details

#executeObject

Run the report with the given filters and store the result.

Returns:

  • (Object)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/report/accounts_payable_command.rb', line 9

def execute
  return unless valid?

  @results = VoucherItem
             .joins(joins_sql)
             .select(select_sql)
             .where(
      "V.state in ('unpaid','paid') " \
      "AND (case when payment.amount is null then voucher_items.gross_amount      " \
      "else voucher_items.gross_amount - coalesce(payment.amount) end) <> 0 " \
      "AND V.company_id = :company_id " \
      "AND V.supplier_id <> 295241 " \
      "AND (voucher_items.gl_offset_account_id in (19,20) OR voucher_items.gl_offset_account_id is null) " \
      "AND V.gl_date::date <= :picked_date",
      company_id: company_id.to_i,
      picked_date: start_date
    )
             .order(order_sql.sql_safe)
end

#payee_countObject

Summary totals computed from results



42
43
44
# File 'app/services/report/accounts_payable_command.rb', line 42

def payee_count
  @results&.map { |r| r["payee"] }&.uniq&.count || 0
end

#success?Boolean

Whether the command validated and ran successfully.

Returns:

  • (Boolean)


31
32
33
# File 'app/services/report/accounts_payable_command.rb', line 31

def success?
  valid? && @results.present?
end

#total_currentObject

Total current.

Returns:

  • (Object)


48
49
50
# File 'app/services/report/accounts_payable_command.rb', line 48

def total_current
  @results&.sum { |a| a["current"].to_f } || 0
end

#total_days30Object

Total days30.

Returns:

  • (Object)


54
55
56
# File 'app/services/report/accounts_payable_command.rb', line 54

def total_days30
  @results&.sum { |a| a["days30"].to_f } || 0
end

#total_days60Object

Total days60.

Returns:

  • (Object)


60
61
62
# File 'app/services/report/accounts_payable_command.rb', line 60

def total_days60
  @results&.sum { |a| a["days60"].to_f } || 0
end

#total_openObject

Total open.

Returns:

  • (Object)


78
79
80
# File 'app/services/report/accounts_payable_command.rb', line 78

def total_open
  @results&.sum { |a| a["open_amount"].to_f } || 0
end

#total_originalObject

Total original.

Returns:

  • (Object)


72
73
74
# File 'app/services/report/accounts_payable_command.rb', line 72

def total_original
  @results&.sum { |a| a["original_amount"].to_f } || 0
end

#total_over60Object

Total over60.

Returns:

  • (Object)


66
67
68
# File 'app/services/report/accounts_payable_command.rb', line 66

def total_over60
  @results&.sum { |a| a["over60"].to_f } || 0
end