rails_finance 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +20 -0
  4. data/Rakefile +32 -0
  5. data/app/controllers/finance/admin/assessments_controller.rb +55 -0
  6. data/app/controllers/finance/admin/base_controller.rb +4 -0
  7. data/app/controllers/finance/admin/budgets_controller.rb +83 -0
  8. data/app/controllers/finance/admin/expense_members_controller.rb +59 -0
  9. data/app/controllers/finance/admin/expenses_controller.rb +71 -0
  10. data/app/controllers/finance/admin/financial_taxons_controller.rb +67 -0
  11. data/app/controllers/finance/admin/fund_incomes_controller.rb +59 -0
  12. data/app/controllers/finance/admin/funds_controller.rb +58 -0
  13. data/app/controllers/finance/admin/home_controller.rb +8 -0
  14. data/app/controllers/finance/admin/stocks_controller.rb +60 -0
  15. data/app/controllers/finance/me/base_controller.rb +4 -0
  16. data/app/controllers/finance/me/budgets_controller.rb +111 -0
  17. data/app/controllers/finance/me/expense_members_controller.rb +73 -0
  18. data/app/controllers/finance/me/expenses_controller.rb +129 -0
  19. data/app/controllers/finance_controller/me.rb +14 -0
  20. data/app/models/budget/finance/fund_budget.rb +5 -0
  21. data/app/models/budget/finance/stock_budget.rb +5 -0
  22. data/app/models/expense/finance/payable_expense.rb +5 -0
  23. data/app/models/expense/finance/prepay_expense.rb +5 -0
  24. data/app/models/finance/application_record.rb +5 -0
  25. data/app/models/finance/assessment.rb +5 -0
  26. data/app/models/finance/budget.rb +7 -0
  27. data/app/models/finance/expense.rb +7 -0
  28. data/app/models/finance/expense_item.rb +5 -0
  29. data/app/models/finance/expense_member.rb +6 -0
  30. data/app/models/finance/ext/financial.rb +24 -0
  31. data/app/models/finance/ext/member.rb +13 -0
  32. data/app/models/finance/financial_taxon.rb +7 -0
  33. data/app/models/finance/fund.rb +6 -0
  34. data/app/models/finance/fund_income.rb +5 -0
  35. data/app/models/finance/model/assessment.rb +26 -0
  36. data/app/models/finance/model/budget/fund_budget.rb +5 -0
  37. data/app/models/finance/model/budget/stock_budget.rb +10 -0
  38. data/app/models/finance/model/budget.rb +152 -0
  39. data/app/models/finance/model/expense/payable_expense.rb +5 -0
  40. data/app/models/finance/model/expense/prepay_expense.rb +5 -0
  41. data/app/models/finance/model/expense.rb +168 -0
  42. data/app/models/finance/model/expense_item.rb +36 -0
  43. data/app/models/finance/model/expense_member.rb +130 -0
  44. data/app/models/finance/model/financial_taxon.rb +27 -0
  45. data/app/models/finance/model/fund.rb +36 -0
  46. data/app/models/finance/model/fund_income.rb +30 -0
  47. data/app/models/finance/model/stock.rb +33 -0
  48. data/app/models/finance/stock.rb +5 -0
  49. data/app/models/finance.rb +12 -0
  50. data/app/pdfs/borrow_expense_pdf.rb +70 -0
  51. data/app/pdfs/payout_expense_pdf.rb +70 -0
  52. data/app/pdfs/prepay_expense_pdf.rb +70 -0
  53. data/app/records/borrow_expense_record.rb +10 -0
  54. data/app/records/prepay_expense_record.rb +16 -0
  55. data/app/views/admin/_finance_nav.html.erb +14 -0
  56. data/app/views/admin/_nav_expense.html.erb +4 -0
  57. data/app/views/finance/admin/assessments/_edit_form.html.erb +4 -0
  58. data/app/views/finance/admin/assessments/_filter_form.html.erb +9 -0
  59. data/app/views/finance/admin/assessments/_form.html.erb +2 -0
  60. data/app/views/finance/admin/assessments/_index_tbody.html.erb +2 -0
  61. data/app/views/finance/admin/assessments/_index_thead.html.erb +3 -0
  62. data/app/views/finance/admin/assessments/_index_tr.html.erb +19 -0
  63. data/app/views/finance/admin/assessments/_new_form.html.erb +4 -0
  64. data/app/views/finance/admin/assessments/_show_table.html.erb +4 -0
  65. data/app/views/finance/admin/assessments/index.html.erb +5 -0
  66. data/app/views/finance/admin/base/_nav.html.erb +3 -0
  67. data/app/views/finance/admin/budgets/_breadcrumb.html.erb +9 -0
  68. data/app/views/finance/admin/budgets/_edit_form.html.erb +4 -0
  69. data/app/views/finance/admin/budgets/_filter_form.html.erb +10 -0
  70. data/app/views/finance/admin/budgets/_filter_table.html.erb +11 -0
  71. data/app/views/finance/admin/budgets/_form.html.erb +7 -0
  72. data/app/views/finance/admin/budgets/_index_tbody.html.erb +13 -0
  73. data/app/views/finance/admin/budgets/_index_thead.html.erb +6 -0
  74. data/app/views/finance/admin/budgets/_item_form.html.erb +17 -0
  75. data/app/views/finance/admin/budgets/_items.html.erb +16 -0
  76. data/app/views/finance/admin/budgets/_new_form.html.erb +4 -0
  77. data/app/views/finance/admin/budgets/_show/_breadcrumb.html.erb +6 -0
  78. data/app/views/finance/admin/budgets/_show_table.html.erb +62 -0
  79. data/app/views/finance/admin/budgets/index.html.erb +5 -0
  80. data/app/views/finance/admin/budgets/next.turbo_stream.erb +1 -0
  81. data/app/views/finance/admin/budgets/show.htmlx.erb +35 -0
  82. data/app/views/finance/admin/budgets/trigger.js.erb +1 -0
  83. data/app/views/finance/admin/expense_members/_edit_form.html.erb +3 -0
  84. data/app/views/finance/admin/expense_members/_form.html.erb +5 -0
  85. data/app/views/finance/admin/expense_members/_index_tbody.html.erb +53 -0
  86. data/app/views/finance/admin/expense_members/_index_thead.html.erb +12 -0
  87. data/app/views/finance/admin/expense_members/index.html.erb +8 -0
  88. data/app/views/finance/admin/expenses/_breadcrumb.html.erb +9 -0
  89. data/app/views/finance/admin/expenses/_edit_form.html.erb +4 -0
  90. data/app/views/finance/admin/expenses/_filter_form.html.erb +10 -0
  91. data/app/views/finance/admin/expenses/_filter_table.html.erb +11 -0
  92. data/app/views/finance/admin/expenses/_form.html.erb +12 -0
  93. data/app/views/finance/admin/expenses/_index_tbody.html.erb +13 -0
  94. data/app/views/finance/admin/expenses/_index_thead.html.erb +6 -0
  95. data/app/views/finance/admin/expenses/_item_form.html.erb +18 -0
  96. data/app/views/finance/admin/expenses/_items.html.erb +20 -0
  97. data/app/views/finance/admin/expenses/_member_form.html.erb +16 -0
  98. data/app/views/finance/admin/expenses/_new_form.html.erb +4 -0
  99. data/app/views/finance/admin/expenses/index.html.erb +5 -0
  100. data/app/views/finance/admin/expenses/next.turbo_stream.erb +1 -0
  101. data/app/views/finance/admin/expenses/show.html.erb +121 -0
  102. data/app/views/finance/admin/expenses/trigger.turbo_stream.erb +1 -0
  103. data/app/views/finance/admin/financial_taxons/_edit_form.html.erb +4 -0
  104. data/app/views/finance/admin/financial_taxons/_filter_form.html.erb +10 -0
  105. data/app/views/finance/admin/financial_taxons/_form.html.erb +5 -0
  106. data/app/views/finance/admin/financial_taxons/_index_tbody.html.erb +36 -0
  107. data/app/views/finance/admin/financial_taxons/_index_thead.html.erb +5 -0
  108. data/app/views/finance/admin/financial_taxons/_index_tr.html.erb +13 -0
  109. data/app/views/finance/admin/financial_taxons/_new_form.html.erb +4 -0
  110. data/app/views/finance/admin/financial_taxons/index.html.erb +6 -0
  111. data/app/views/finance/admin/fund_incomes/_breadcrumb.html.erb +7 -0
  112. data/app/views/finance/admin/fund_incomes/_edit_form.html.erb +4 -0
  113. data/app/views/finance/admin/fund_incomes/_filter_form.html.erb +9 -0
  114. data/app/views/finance/admin/fund_incomes/_form.html.erb +4 -0
  115. data/app/views/finance/admin/fund_incomes/_index_tbody.html.erb +5 -0
  116. data/app/views/finance/admin/fund_incomes/_index_thead.html.erb +4 -0
  117. data/app/views/finance/admin/fund_incomes/_new_form.html.erb +4 -0
  118. data/app/views/finance/admin/fund_incomes/_show_table.html.erb +12 -0
  119. data/app/views/finance/admin/fund_incomes/index.html.erb +5 -0
  120. data/app/views/finance/admin/funds/_edit_form.html.erb +3 -0
  121. data/app/views/finance/admin/funds/_filter_form.html.erb +9 -0
  122. data/app/views/finance/admin/funds/_form.html.erb +5 -0
  123. data/app/views/finance/admin/funds/_index_tbody.html.erb +14 -0
  124. data/app/views/finance/admin/funds/_index_thead.html.erb +8 -0
  125. data/app/views/finance/admin/funds/_new_form.html.erb +3 -0
  126. data/app/views/finance/admin/funds/_show_table.html.erb +16 -0
  127. data/app/views/finance/admin/funds/index.html.erb +5 -0
  128. data/app/views/finance/admin/home/index.html.erb +6 -0
  129. data/app/views/finance/admin/stocks/_breadcrumb.html.erb +7 -0
  130. data/app/views/finance/admin/stocks/_edit_form.html.erb +4 -0
  131. data/app/views/finance/admin/stocks/_filter_form.html.erb +9 -0
  132. data/app/views/finance/admin/stocks/_form.html.erb +4 -0
  133. data/app/views/finance/admin/stocks/_index_tbody.html.erb +6 -0
  134. data/app/views/finance/admin/stocks/_index_thead.html.erb +7 -0
  135. data/app/views/finance/admin/stocks/_new_form.html.erb +4 -0
  136. data/app/views/finance/admin/stocks/_show_table.html.erb +16 -0
  137. data/app/views/finance/admin/stocks/index.html.erb +5 -0
  138. data/app/views/finance/me/budgets/_breadcrumb.html.erb +6 -0
  139. data/app/views/finance/me/budgets/_filter_form.html.erb +8 -0
  140. data/app/views/finance/me/budgets/_filter_table.html.erb +11 -0
  141. data/app/views/finance/me/budgets/_index_tbody.html.erb +23 -0
  142. data/app/views/finance/me/budgets/_index_thead.html.erb +4 -0
  143. data/app/views/finance/me/budgets/_items.html.erb +22 -0
  144. data/app/views/finance/me/budgets/_show/_breadcrumb.html.erb +6 -0
  145. data/app/views/finance/me/budgets/admin.html.erb +5 -0
  146. data/app/views/finance/me/budgets/financial_taxons.js.erb +7 -0
  147. data/app/views/finance/me/budgets/index.html.erb +5 -0
  148. data/app/views/finance/me/budgets/index.js +45 -0
  149. data/app/views/finance/me/budgets/submit.turbo_stream.erb +1 -0
  150. data/app/views/finance/me/budgets/transfer.turbo_stream.erb +1 -0
  151. data/app/views/finance/me/expense_members/_breadcrumb.html.erb +6 -0
  152. data/app/views/finance/me/expense_members/_button.html.erb +0 -0
  153. data/app/views/finance/me/expense_members/_filter_form.html.erb +10 -0
  154. data/app/views/finance/me/expense_members/_form.html.erb +9 -0
  155. data/app/views/finance/me/expense_members/_index_tbody.html.erb +8 -0
  156. data/app/views/finance/me/expense_members/_index_thead.html.erb +7 -0
  157. data/app/views/finance/me/expense_members/_show_items.html.erb +1 -0
  158. data/app/views/finance/me/expense_members/admin.html.erb +3 -0
  159. data/app/views/finance/me/expense_members/index.html.erb +6 -0
  160. data/app/views/finance/me/expense_members/items.js.erb +1 -0
  161. data/app/views/finance/me/expense_members/show.html.erb +62 -0
  162. data/app/views/finance/me/expenses/_breadcrumb.html.erb +7 -0
  163. data/app/views/finance/me/expenses/_edit_form.html.erb +3 -0
  164. data/app/views/finance/me/expenses/_filter_form.html.erb +8 -0
  165. data/app/views/finance/me/expenses/_filter_table.html.erb +11 -0
  166. data/app/views/finance/me/expenses/_index_tbody.html.erb +16 -0
  167. data/app/views/finance/me/expenses/_index_thead.html.erb +6 -0
  168. data/app/views/finance/me/expenses/_index_tr.html.erb +14 -0
  169. data/app/views/finance/me/expenses/_new_form.html.erb +4 -0
  170. data/app/views/finance/me/expenses/_show/_breadcrumb.html.erb +6 -0
  171. data/app/views/finance/me/expenses/_show_table.html.erb +124 -0
  172. data/app/views/finance/me/expenses/admin.html.erb +5 -0
  173. data/app/views/finance/me/expenses/confirm.html.erb +27 -0
  174. data/app/views/finance/me/expenses/financial_taxons.js.erb +44 -0
  175. data/app/views/finance/me/expenses/index.html.erb +5 -0
  176. data/app/views/finance/me/expenses/index.js +42 -0
  177. data/app/views/finance/me/expenses/show.html.erb +3 -0
  178. data/app/views/me/_finance_nav.html.erb +11 -0
  179. data/config/locales/en.attributes.yml +6 -0
  180. data/config/locales/en.controller.yml +21 -0
  181. data/config/locales/en.enum.yml +18 -0
  182. data/config/locales/zh.attributes.yml +65 -0
  183. data/config/locales/zh.controller.yml +57 -0
  184. data/config/locales/zh.enum.yml +38 -0
  185. data/config/routes.rb +63 -0
  186. data/lib/rails_finance/config.rb +11 -0
  187. data/lib/rails_finance/engine.rb +26 -0
  188. data/lib/rails_finance/version.rb +3 -0
  189. data/lib/rails_finance.rb +2 -0
  190. metadata +259 -0
@@ -0,0 +1,58 @@
1
+ module Finance
2
+ class Admin::FundsController < Admin::BaseController
3
+ before_action :set_fund, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ q_params = {}
7
+ q_params.merge! default_params
8
+
9
+ @funds = Fund.default_where(q_params).order(id: :asc).page(params[:page])
10
+ end
11
+
12
+ def new
13
+ @fund = Fund.new
14
+ end
15
+
16
+ def create
17
+ @fund = Fund.new(fund_params)
18
+
19
+ unless @fund.save
20
+ render :new, locals: { model: @fund }, status: :unprocessable_entity
21
+ end
22
+ end
23
+
24
+ def show
25
+ end
26
+
27
+ def edit
28
+ end
29
+
30
+ def update
31
+ @fund.assign_attributes(fund_params)
32
+
33
+ unless @fund.save
34
+ render :edit, locals: { model: @fund }, status: :unprocessable_entity
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @fund.destroy
40
+ end
41
+
42
+ private
43
+ def set_fund
44
+ @fund = Fund.find(params[:id])
45
+ end
46
+
47
+ def fund_params
48
+ p = params.fetch(:fund, {}).permit(
49
+ :name,
50
+ :budget_amount,
51
+ :amount,
52
+ :note
53
+ )
54
+ p.merge! default_form_params
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ module Finance
2
+ class Admin::HomeController < Admin::BaseController
3
+
4
+ def index
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ module Finance
2
+ class Admin::StocksController < Admin::BaseController
3
+ before_action :set_assessment
4
+ before_action :set_stock, only: [:show, :edit, :update, :destroy]
5
+
6
+ def index
7
+ @stocks = @assessment.stocks.order(id: :asc).page(params[:page])
8
+ end
9
+
10
+ def new
11
+ @stock = @assessment.stocks.build(member: current_member)
12
+ end
13
+
14
+ def create
15
+ @stock = @assessment.stocks.build(stock_params)
16
+ @stock.member = current_member
17
+
18
+ unless @stock.save
19
+ render :new, locals: { model: @stock }, status: :unprocessable_entity
20
+ end
21
+ end
22
+
23
+ def show
24
+ end
25
+
26
+ def edit
27
+ end
28
+
29
+ def update
30
+ @stock.assign_attributes(stock_params)
31
+
32
+ unless @stock.save
33
+ render :edit, locals: { model: @stock }, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @stock.destroy
39
+ end
40
+
41
+ private
42
+ def set_assessment
43
+ @assessment = Assessment.find params[:assessment_id]
44
+ end
45
+
46
+ def set_stock
47
+ @stock = Stock.find(params[:id])
48
+ end
49
+
50
+ def stock_params
51
+ params.fetch(:stock, {}).permit(
52
+ :ratio,
53
+ :amount,
54
+ :expense_amount,
55
+ :note
56
+ )
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,4 @@
1
+ module Finance
2
+ class Me::BaseController < MeController
3
+ end
4
+ end
@@ -0,0 +1,111 @@
1
+ module Finance
2
+ class Me::BudgetsController < Admin::BudgetsController
3
+ include FinanceController::Me
4
+ before_action :set_budget, only: [:show, :edit, :update, :submit, :transfer, :bill, :destroy]
5
+ before_action :prepare_form
6
+ # after_action only: [:create, :update, :destroy] do
7
+ # mark_audits(Purchase, include: [:purchase_items], note: 'record test')
8
+ # end
9
+
10
+ def index
11
+ q_params = {}
12
+ q_params.merge! params.permit(:state)
13
+
14
+ @budgets = current_member.budgets.default_where(q_params).page(params[:page])
15
+ end
16
+
17
+ def admin
18
+ q_params = {
19
+ verifier_id: current_member.id
20
+ }
21
+ q_params.merge! params.permit(:state, :id)
22
+
23
+ @budgets = Budget.default_where(q_params).page(params[:page])
24
+ end
25
+
26
+ def new
27
+ @budget = current_member.budgets.build
28
+ @budget.expense_items.build
29
+
30
+ @taxon_options = []
31
+ end
32
+
33
+ def create
34
+ @budget = current_member.budgets.build(budget_params)
35
+
36
+ unless @budget.save
37
+ render :new, locals: { model: @budget }, status: :unprocessable_entity
38
+ end
39
+ end
40
+
41
+ def financial_taxons
42
+ budget_params.fetch('expense_items_attributes', {}).each do |_, v|
43
+ v.delete('id')
44
+ end
45
+ @budget = current_member.budgets.build(financial_taxon_id: budget_params[:financial_taxon_id])
46
+ @financial_taxons = @budget.financial_taxon.children.map { |i| [i.name, i.id] }
47
+ end
48
+
49
+ def show
50
+ end
51
+
52
+ def edit
53
+ @taxon_options = FinancialTaxon.roots.map { |i| [i.name, i.id] }
54
+ end
55
+
56
+ def update
57
+ @budget.assign_attributes(budget_params)
58
+
59
+ unless @budget.save
60
+ render :edit, locals: { model: @budget }, status: :unprocessable_entity
61
+ end
62
+ end
63
+
64
+ def transfer
65
+ @budget.transfer(params[:type])
66
+ end
67
+
68
+ def submit
69
+ @budget.state = 'verifying' if @budget.init?
70
+ @budget.save
71
+ end
72
+
73
+ def bill
74
+ disposition = params[:disposition] || 'inline'
75
+ @pdf = PayoutExpensePdf.new(@budget.id)
76
+
77
+ respond_to do |format|
78
+ format.html
79
+ format.js
80
+ format.pdf { send_data @pdf.render, filename: 'bill_file', disposition: disposition, type: 'application/pdf' }
81
+ end
82
+ end
83
+
84
+ def destroy
85
+ @budget.destroy
86
+ end
87
+
88
+ private
89
+ def set_budget
90
+ @budget = Budget.find params[:id]
91
+ end
92
+
93
+ def prepare_form
94
+ q_params = {}
95
+ q_params.merge! default_params
96
+
97
+ @financial_taxons = FinancialTaxon.default_where(q_params)
98
+ end
99
+
100
+ def budget_params
101
+ params.fetch(:budget, {}).permit(
102
+ :subject,
103
+ :amount,
104
+ :note,
105
+ :financial_taxon_id,
106
+ expense_items_attributes: {}
107
+ )
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,73 @@
1
+ module Finance
2
+ class Me::ExpenseMembersController < Admin::ExpenseMembersController
3
+ include FinanceController::Me
4
+ skip_before_action :set_expense, only: [:index]
5
+ before_action :set_expense_member, only: [:show, :items, :edit, :update, :bill]
6
+
7
+ def index
8
+ @expense_members = current_member.expense_members.page(params[:page])
9
+ end
10
+
11
+ def admin
12
+ q_params = {
13
+ 'expense_member.verifier_id': current_member.id
14
+ }
15
+ q_params.merge! params.permit(:state, :id)
16
+
17
+ @expense_members = ExpenseMember.default_where(q_params).page(params[:page])
18
+ end
19
+
20
+ def show
21
+ end
22
+
23
+ def bill
24
+ disposition = params[:disposition] || 'inline'
25
+ if params[:type] == 'borrow'
26
+ @pdf = BorrowExpensePdf.new(@expense_member.id)
27
+ elsif params[:type] == 'reimburse'
28
+ @pdf = PrepayExpensePdf.new(@expense_member.id)
29
+ end
30
+ respond_to do |format|
31
+ format.html
32
+ format.js
33
+ format.pdf { send_data @pdf.render, filename: 'bill_file', disposition: disposition, type: 'application/pdf' }
34
+ end
35
+ end
36
+
37
+ def items
38
+ disposition = params[:disposition] || 'inline'
39
+
40
+ respond_to do |format|
41
+ format.html
42
+ format.js
43
+ format.xlsx { send_data @pdf.render, filename: 'bill_file', disposition: disposition, type: 'application/pdf' }
44
+ end
45
+ end
46
+
47
+ def edit
48
+ @payment_methods = current_member.payment_methods
49
+ end
50
+
51
+ def update
52
+ unless @expense_member.update(expense_member_params)
53
+ render :edit, locals: { model: @expense_member }, status: :unprocessable_entity
54
+ end
55
+ end
56
+
57
+ private
58
+ def set_expense_member
59
+ @expense_member = ExpenseMember.find(params[:id])
60
+ end
61
+
62
+ def expense_member_params
63
+ params.fetch(:expense_member, {}).permit(
64
+ :amount,
65
+ :advance,
66
+ :financial_taxon_id,
67
+ :note,
68
+ :payment_method_id
69
+ )
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,129 @@
1
+ module Finance
2
+ class Me::ExpensesController < Admin::ExpensesController
3
+ include FinanceController::Me
4
+ before_action :set_expense, only: [:show, :edit, :update, :submit, :confirm, :bill, :destroy]
5
+ before_action :prepare_form
6
+ # after_action only: [:create, :update, :destroy] do
7
+ # mark_audits(Purchase, include: [:purchase_items], note: 'record test')
8
+ # end
9
+
10
+ def index
11
+ q_params = {}
12
+ q_params.merge! params.permit(:state)
13
+
14
+ @expenses = current_member.created_expenses.default_where(q_params).page(params[:page])
15
+ end
16
+
17
+ def admin
18
+ q_params = {
19
+ verifier_id: current_member.id
20
+ }
21
+ q_params.merge! params.permit(:state, :id)
22
+
23
+ @expenses = Expense.default_where(q_params).page(params[:page])
24
+ end
25
+
26
+ def new
27
+ @expense = current_member.created_expenses.build(type: params[:type])
28
+ @expense.expense_items.build
29
+ @expense.expense_members.build(member_id: current_member.id)
30
+ @taxon_options = []
31
+ end
32
+
33
+ def create
34
+ @expense = current_member.created_expenses.build(expense_params)
35
+
36
+ unless @expense.save
37
+ render :new, locals: { model: @expense }, status: :unprocessable_entity
38
+ end
39
+ end
40
+
41
+ def financial_taxons
42
+ q = expense_params['expense_items_attributes'].each do |_, v|
43
+ v.delete('id')
44
+ end
45
+ q.fetch('expense_members_attributes', {}).each do |_, v|
46
+ v.delete('id')
47
+ end
48
+ @expense = current_member.created_expenses.build(q)
49
+ @taxon_options = @expense.financial_taxon.children.map { |i| [i.name, i.id] }
50
+ end
51
+
52
+ def show
53
+ end
54
+
55
+ def edit
56
+ if @expense.expense_members.count == 0
57
+ @expense.expense_members.build(member_id: current_member.id)
58
+ end
59
+ if current_member.respond_to? :payment_methods
60
+ @payment_methods = current_member.payment_methods.where(myself: true)
61
+ else
62
+ @payment_methods = []
63
+ end
64
+ @taxon_options = FinancialTaxon.roots.map { |i| [i.name, i.id] }
65
+ end
66
+
67
+ def update
68
+ @expense.assign_attributes(expense_params)
69
+
70
+ unless @expense.save
71
+ render :edit, locals: { model: @expense }, status: :unprocessable_entity
72
+ end
73
+ end
74
+
75
+ def confirm
76
+ @payment_methods = Trade::PaymentMethod.where(myself: false)
77
+ if @expense.type == 'Finance::PrepayExpense'
78
+ @expense.expense_members.build(member_id: current_member.id, amount: @expense.amount)
79
+ end
80
+ end
81
+
82
+ def submit
83
+ @expense.state = 'verifying' if @expense.init?
84
+ @expense.save
85
+ end
86
+
87
+ def bill
88
+ disposition = params[:disposition] || 'inline'
89
+ @pdf = PayoutExpensePdf.new(@expense.id)
90
+
91
+ respond_to do |format|
92
+ format.html
93
+ format.js
94
+ format.pdf { send_data @pdf.render, filename: 'bill_file', disposition: disposition, type: 'application/pdf' }
95
+ end
96
+ end
97
+
98
+ def destroy
99
+ @expense.destroy
100
+ end
101
+
102
+ private
103
+ def set_expense
104
+ @expense = Expense.find(params[:id])
105
+ end
106
+
107
+ def prepare_form
108
+ q_params = {}
109
+ q_params.merge! default_params
110
+
111
+ @financial_taxons = FinancialTaxon.default_where(q_params)
112
+ end
113
+
114
+ def expense_params
115
+ params.fetch(:expense, {}).permit(
116
+ :subject,
117
+ :type,
118
+ :amount,
119
+ :note,
120
+ :proof,
121
+ :financial_taxon_id,
122
+ :payment_method_id,
123
+ expense_members_attributes: {},
124
+ expense_items_attributes: {}
125
+ )
126
+ end
127
+
128
+ end
129
+ end