forked from Mostfit/mostfit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisfit.rb
143 lines (122 loc) · 5.67 KB
/
misfit.rb
1
2
3
4
5
6
7
8
9
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
module Misfit
module Config
puts "Setting rights..."
def self.model_names
# Added an ugly patch for making alias of client_groups available
DataMapper::Model.descendants.map{|d| d.to_s.snake_case.to_sym} << :group
end
def self.controller_names
Application.subclasses_list.reject{|c| c.index("::")}.map{|x| x.snake_case.to_sym} + [:data_entry]
end
def self.all_models
{:all => model_names}
end
def self.all_models_except(models)
{:all => (model_names - models)}
end
def self.all_controllers
{:all => controller_names}
end
def self.all_controllers_except(controllers)
{:all => (controller_names - controllers)}
end
def controllers_from_models(role)
@crud_rights[role]
end
@crud_rights = {
:admin => all_models,
:mis_manager => all_models_except([:user, :admin]),
:data_entry => {
:all => [:client, :loan, :payment, :document, :client_group, :group, :insurance_company, :insurance_policy, :cgt, :grt, :staff_member, :center],
},
:staff_member => {
:all => [:center, :client, :loan, :payment, :document, :client_group, :group, :comment, :insurance_company, :staff_member, :location, :branch_diary, :stock_register, :asset_register]
},
:funder => {
:all => []
},
:accountant => {
:all => [:accounts, :journals, :rule_books, :account_types, :accounting_periods]
}
}
@access_rights = {
:admin => all_controllers,
:mis_manager => all_controllers_except([:users, :admin]),
:data_entry => {
:all => [:search, :comments, :documents, :"data_entry/client_groups", :"data_entry/payments", :"data_entry/clients",:"data_entry/loans", :"data_entry/index",
:clients, :loans, :client_groups, :cgts, :grts, :staff_members, :bookmarks]
},
:read_only => {
:all => [:searches, :browse, :branches, :centers, :payments, :clients, :loans, :dashboard, :regions, :reports, :documents, :comments, :insurance_policies, :audit_trails, :info,
:insurance_companies, :areas, :staff_members, :document_types, :occupations, :client_types, :fees, :funders, :attendances, :dashboard, :graph_data,
:locations, :branch_diaries, :stock_registers, :asset_registers],
:index => [:holidays, :loan_products]
},
:staff_member => {
:all => [:documents, :searches, :browse, :branches, :centers, :payments, :clients, :client_groups, :groups, :audit_trails, :comments, :insurance_policies, :bookmarks,
:reports, :"data_entry/centers", :"data_entry/client_groups", :"data_entry/payments", :"data_entry/clients", :staff_members, :audit_items, :locations, :loans,
:"data_entry/loans", :"data_entry/index", :insurance_companies, :info, :dashboard, :graph_data, :branch_diaries, :stock_registers, :asset_registers],
:index => [:holidays, :loan_products]
},
:funder => {
:all => [:searches, :browse, :branches, :centers, :client_groups, :payments, :clients, :loans, :dashboard, :regions, :documents, :comments, :areas, :info, :locations,
:audit_trails, :documents, :attendances, :staff_members, :funders, :portfolios, :funding_lines, :reports, :graph_data, :dashboard, :bookmarks]
},
:accountant => {
:all => [:browse, :branches, :accounts, :journals, :rule_books, :account_types, :accounting_periods, :info, :reports, :reports, :dashboard, :graph_data]
}
}
def self.crud_rights
@crud_rights
end
def self.access_rights
@access_rights
end
module DateFormat
def self.compile(mfi = Mfi.first)
Date.class_eval do
define_method :to_s do
self.display
end
end
Date.instance_eval do
class << self
mfi = Mfi.first
min_allowed_transaction_date = if mfi.min_date_from and mfi.number_of_past_days
(mfi.min_date_from==:today ? Date.today : mfi.in_operation_since) - mfi.number_of_past_days
elsif mfi.in_operation_since
mfi.in_operation_since
else
Date.new(2000, 01, 01)
end
min_allowed_date = if not mfi.in_operation_since.blank?
mfi.in_operation_since
else
Date.new(2000, 01, 01)
end
max_allowed_date = Date.today + mfi.number_of_future_days
max_allowed_transaction_date =
if mfi.number_of_future_days
Date.today + mfi.number_of_future_transaction_days
else
Date.today+1000
end
define_method :min_date do
min_allowed_date
end
define_method :max_date do
max_allowed_date
end
define_method :min_transaction_date do
min_allowed_transaction_date
end
define_method :max_transaction_date do
max_allowed_transaction_date
end
end
end
Merb.logger.info("Date format set to:: #{Mfi.first.date_format} and min date is #{Date.min_date}, max date is #{Date.max_date}, min transaction date is #{Date.min_transaction_date} and max transaction date is #{Date.max_transaction_date}")
end
end
end
end