Class: Report::CashFlow::CashFlow
- Inherits:
-
Object
- Object
- Report::CashFlow::CashFlow
- Defined in:
- app/services/report/cash_flow/cash_flow.rb
Overview
Service object: cash flow.
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Class Method Details
.balance_data(year, month, company_id, accounts) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/services/report/cash_flow/cash_flow.rb', line 75 def self.balance_data(year, month, company_id, accounts) ViewFinancialAccountBalance .where(year: year) .where("month <= #{month}") .where(company_id: company_id) .where(account_number: accounts) .group(:account_id, :account_number, :account_name, :year, :month) .order(:account_number) .select(:account_id, :account_number, :account_name, :year, :month, 'sum(monthly_amount) as value', 'sum(beginning_balance_amount) as bb_value') .map { |r| r.attributes.symbolize_keys }.map(&:compact) end |
.result_report(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/services/report/cash_flow/cash_flow.rb', line 10 def self.result_report( = {}) bs_accounts = {} var_acc = [] by_month_consolidated = [] bs_accounts[:net_income] = [4999] bs_accounts[:depreciation] = [9220, 9225, 9230, 9235, 9236, 9240] bs_accounts[:amortization] = [9245] bs_accounts[:screapped_inventory] = [6235, 6240] bs_accounts[:return_bad_deb_reserve] = [5360, 5355, 9035, 9040] bs_accounts[:accounts_receivable] = [1210, 1211, 1215, 1216] bs_accounts[:inventory] = [1410, 1411, 1412, 1415, 1455, 1460, 1490] bs_accounts[:prepaid_expenses_and_other] = [1510, 1560, 1610] bs_accounts[:intercompany] = [1291, 1292, 1293, 1294, 1298] bs_accounts[:other_receivable] = [1245, 3320, 3390] bs_accounts[:vendor_prepayment] = [1246] bs_accounts[:loans_to_employees] = [1265] bs_accounts[:personal_income_tax_payments] = [4990] bs_accounts[:security_deposit] = [1240, 3310] bs_accounts[:accounts_payable_trade] = [4110] bs_accounts[:accounts_payable_customer] = [4202] bs_accounts[:accrued_expenses] = [4120, 4121, 4122, 4125, 4126] bs_accounts[:accrued_payroll] = [4410, 4420, 4421, 4422, 4423, 4424, 4425] bs_accounts[:sales_tax] = [4150, 4151, 4155, 4156, 4160, 4161] bs_accounts[:corporate_income_tax] = [4175, 4180, 4185] bs_accounts[:other_liabilities] = [4760] bs_accounts[:automobile] = [2135] bs_accounts[:office_equipment_or_other_equipment] = [2125, 2145] bs_accounts[:computer_equipment] = [2140] bs_accounts[:furniture] = [2130] bs_accounts[:computer_software] = [2310] bs_accounts[:credit_line] = [4515] bs_accounts[:short_term_sba_loan] = [4510, 4725, 4729] bs_accounts[:short_term_capital_leases] = [4511, 4715, 4716, 4719] bs_accounts[:cash_beginning_of_period] = [1111, 1121, 1122, 1123, 1125, 1130, 1135, 1140, 1141] bs_accounts.map { |_k, v| var_acc += v } bs_data = balance_data([:years][0].to_i, [:months][0].to_i, [:company_ids][0].to_i, var_acc) count = 0 bs_accounts.each do |detail_name, accounts| count += 1 bb_value = 0 accounts.each do |acc| bs_data.each do |r| bb_value += r[:bb_value] if r[:account_number] == acc && acc < 4999 end end by_month_consolidated << { detail_number: count, name: detail_name.to_s, 0 => bb_value } (1..12).each do |e| monthly = 0 accounts.each do |acc| bs_data.each do |r| if acc >= 4999 monthly += r[:value] if r[:account_number] == acc && r[:month] == e elsif acc < 4999 monthly += (r[:value] + r[:bb_value]) if r[:account_number] == acc && r[:month] <= e end end by_month_consolidated.map { |r| r[:detail_number] == count ? r[e] = monthly : r } end end end Result.new(success: true, year: [:years][0].to_i, month: [:months][0].to_i, company_id: [:company_ids][0].to_i, by_month: by_month_consolidated) end |