smartkiosk-server 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (254) hide show
  1. data/.gitignore +32 -0
  2. data/.rspec +1 -0
  3. data/Capfile +4 -0
  4. data/Gemfile +71 -0
  5. data/Gemfile.lock +439 -0
  6. data/Guardfile +25 -0
  7. data/LICENSE +287 -0
  8. data/README.md +13 -0
  9. data/Rakefile +5 -0
  10. data/app/acquirers/cards_mkb_acquirer.rb +87 -0
  11. data/app/acquirers/cash_acquirer.rb +22 -0
  12. data/app/admin/agents.rb +108 -0
  13. data/app/admin/collections.rb +62 -0
  14. data/app/admin/commissions.rb +87 -0
  15. data/app/admin/gateways.rb +183 -0
  16. data/app/admin/limits.rb +82 -0
  17. data/app/admin/payments.rb +246 -0
  18. data/app/admin/provider_groups.rb +60 -0
  19. data/app/admin/provider_profiles.rb +11 -0
  20. data/app/admin/provider_receipt_templates.rb +82 -0
  21. data/app/admin/providers.rb +201 -0
  22. data/app/admin/rebates.rb +83 -0
  23. data/app/admin/report_results.rb +66 -0
  24. data/app/admin/report_templates.rb +209 -0
  25. data/app/admin/reports.rb +158 -0
  26. data/app/admin/revisions.rb +120 -0
  27. data/app/admin/system_receipt_templates.rb +76 -0
  28. data/app/admin/terminal_builds.rb +39 -0
  29. data/app/admin/terminal_profiles.rb +123 -0
  30. data/app/admin/terminals.rb +388 -0
  31. data/app/admin/users.rb +117 -0
  32. data/app/admin/versions.rb +131 -0
  33. data/app/admin/welcome.rb +64 -0
  34. data/app/assets/fonts/PT_Sans-Web-Bold.eot +0 -0
  35. data/app/assets/fonts/PT_Sans-Web-Bold.svg +6386 -0
  36. data/app/assets/fonts/PT_Sans-Web-Bold.ttf +0 -0
  37. data/app/assets/fonts/PT_Sans-Web-Bold.woff +0 -0
  38. data/app/assets/fonts/PT_Sans-Web-Regular.eot +0 -0
  39. data/app/assets/fonts/PT_Sans-Web-Regular.svg +5650 -0
  40. data/app/assets/fonts/PT_Sans-Web-Regular.ttf +0 -0
  41. data/app/assets/fonts/PT_Sans-Web-Regular.woff +0 -0
  42. data/app/assets/images/chosen-sprite.png +0 -0
  43. data/app/assets/javascripts/active_admin/chosen.js.erb.coffee +12 -0
  44. data/app/assets/javascripts/active_admin/qtip.js.coffee +22 -0
  45. data/app/assets/javascripts/active_admin/sortable_forms.js.coffee +14 -0
  46. data/app/assets/javascripts/active_admin.js.coffee +9 -0
  47. data/app/assets/javascripts/application.js +15 -0
  48. data/app/assets/javascripts/report_templates.js.coffee +10 -0
  49. data/app/assets/javascripts/terminals.js.coffee +12 -0
  50. data/app/assets/stylesheets/active_admin/PIE.css.scss +18 -0
  51. data/app/assets/stylesheets/active_admin/filter_numeric_range.css.scss +14 -0
  52. data/app/assets/stylesheets/active_admin/selectable_check_boxes.css.scss +12 -0
  53. data/app/assets/stylesheets/active_admin/sortable_forms.css.scss +11 -0
  54. data/app/assets/stylesheets/active_admin.css.scss +705 -0
  55. data/app/assets/stylesheets/fonts.css.scss +14 -0
  56. data/app/assets/stylesheets/provider_groups.css.scss +12 -0
  57. data/app/assets/stylesheets/provider_receipt_templates.css.scss +12 -0
  58. data/app/assets/stylesheets/terminals.css.scss +9 -0
  59. data/app/controllers/application_controller.rb +12 -0
  60. data/app/controllers/collections_controller.rb +10 -0
  61. data/app/controllers/payments_controller.rb +73 -0
  62. data/app/controllers/system_receipt_templates_controller.rb +10 -0
  63. data/app/controllers/terminal_builds_controller.rb +5 -0
  64. data/app/controllers/terminal_orders_controller.rb +25 -0
  65. data/app/controllers/terminal_pings_controller.rb +45 -0
  66. data/app/controllers/welcome_controller.rb +5 -0
  67. data/app/helpers/active_admin/report_templates_helper.rb +56 -0
  68. data/app/helpers/active_admin/views_helper.rb +20 -0
  69. data/app/helpers/application_helper.rb +2 -0
  70. data/app/mailers/.gitkeep +0 -0
  71. data/app/models/.gitkeep +0 -0
  72. data/app/models/ability.rb +30 -0
  73. data/app/models/agent.rb +24 -0
  74. data/app/models/collection.rb +65 -0
  75. data/app/models/commission.rb +77 -0
  76. data/app/models/commission_section.rb +75 -0
  77. data/app/models/gateway.rb +99 -0
  78. data/app/models/gateway_attachment.rb +9 -0
  79. data/app/models/gateway_setting.rb +7 -0
  80. data/app/models/gateway_switch.rb +7 -0
  81. data/app/models/limit.rb +77 -0
  82. data/app/models/limit_section.rb +58 -0
  83. data/app/models/payment.rb +322 -0
  84. data/app/models/provider.rb +59 -0
  85. data/app/models/provider_field.rb +7 -0
  86. data/app/models/provider_gateway.rb +47 -0
  87. data/app/models/provider_group.rb +45 -0
  88. data/app/models/provider_profile.rb +9 -0
  89. data/app/models/provider_rebate.rb +69 -0
  90. data/app/models/provider_receipt_template.rb +85 -0
  91. data/app/models/rebate.rb +84 -0
  92. data/app/models/report.rb +71 -0
  93. data/app/models/report_result.rb +11 -0
  94. data/app/models/report_template.rb +56 -0
  95. data/app/models/revision.rb +104 -0
  96. data/app/models/role.rb +48 -0
  97. data/app/models/system_receipt_template.rb +13 -0
  98. data/app/models/terminal.rb +126 -0
  99. data/app/models/terminal_build.rb +62 -0
  100. data/app/models/terminal_order.rb +42 -0
  101. data/app/models/terminal_ping.rb +120 -0
  102. data/app/models/terminal_profile.rb +51 -0
  103. data/app/models/terminal_profile_promotion.rb +18 -0
  104. data/app/models/terminal_profile_provider.rb +11 -0
  105. data/app/models/terminal_profile_provider_group.rb +19 -0
  106. data/app/models/user.rb +38 -0
  107. data/app/models/user_role.rb +45 -0
  108. data/app/reports/agents_report.rb +81 -0
  109. data/app/reports/collections_report.rb +151 -0
  110. data/app/reports/payments_report.rb +189 -0
  111. data/app/reports/terminals_report.rb +123 -0
  112. data/app/uploaders/file_uploader.rb +53 -0
  113. data/app/uploaders/icon_uploader.rb +15 -0
  114. data/app/uploaders/zip_uploader.rb +53 -0
  115. data/app/views/admin/gateways/providers.html.arb +10 -0
  116. data/app/views/admin/revisions/payments.html.arb +28 -0
  117. data/app/views/admin/terminal_profiles/_tree.html.haml +35 -0
  118. data/app/views/admin/terminal_profiles/sort.html.haml +21 -0
  119. data/app/views/admin/terminals/pings.html.arb +55 -0
  120. data/app/views/admin/terminals/upgrade_build.html.arb +30 -0
  121. data/app/views/layouts/application.html.erb +1 -0
  122. data/app/views/welcome/index.html.erb +25 -0
  123. data/app/workers/pay_worker.rb +11 -0
  124. data/app/workers/report_worker.rb +7 -0
  125. data/app/workers/revise_worker.rb +7 -0
  126. data/config/acquiring.yml +13 -0
  127. data/config/application.rb +75 -0
  128. data/config/boot.rb +6 -0
  129. data/config/database.yml +17 -0
  130. data/config/deploy/roundlake-passenger.rb +3 -0
  131. data/config/deploy/roundlake-trinidad.rb +3 -0
  132. data/config/deploy.rb +37 -0
  133. data/config/environment.rb +5 -0
  134. data/config/environments/development.rb +39 -0
  135. data/config/environments/production.rb +67 -0
  136. data/config/environments/test.rb +37 -0
  137. data/config/initializers/active_admin.rb +31 -0
  138. data/config/initializers/backtrace_silencers.rb +7 -0
  139. data/config/initializers/devise.rb +232 -0
  140. data/config/initializers/inflections.rb +15 -0
  141. data/config/initializers/mime_types.rb +5 -0
  142. data/config/initializers/money.rb +6 -0
  143. data/config/initializers/redis.rb +4 -0
  144. data/config/initializers/secret_token.rb +7 -0
  145. data/config/initializers/session_store.rb +8 -0
  146. data/config/initializers/setup_rack.rb +1 -0
  147. data/config/initializers/wrap_parameters.rb +14 -0
  148. data/config/locales/active_admin.ru.yml +71 -0
  149. data/config/locales/activerecord.ru.yml +645 -0
  150. data/config/locales/devise.ru.yml +57 -0
  151. data/config/locales/ru.yml +33 -0
  152. data/config/locales/smartkiosk.gateways.ru.yml +241 -0
  153. data/config/locales/smartkiosk.hardware.ru.yml +38 -0
  154. data/config/locales/smartkiosk.reports.ru.yml +56 -0
  155. data/config/locales/smartkiosk.ru.yml +163 -0
  156. data/config/nginx.conf +9 -0
  157. data/config/redis.yml +9 -0
  158. data/config/routes.rb +48 -0
  159. data/config/schedule.rb +13 -0
  160. data/config/sidekiq.yml +5 -0
  161. data/config/trinidad.yml +6 -0
  162. data/config.ru +4 -0
  163. data/db/migrate/20120825083035_create_terminals.rb +47 -0
  164. data/db/migrate/20120825083305_create_payments.rb +51 -0
  165. data/db/migrate/20120827062618_devise_create_users.rb +50 -0
  166. data/db/migrate/20120827132621_create_admin_notes.rb +17 -0
  167. data/db/migrate/20120827132622_move_admin_notes_to_comments.rb +25 -0
  168. data/db/migrate/20120903193346_create_providers.rb +24 -0
  169. data/db/migrate/20120922075345_create_collections.rb +26 -0
  170. data/db/migrate/20120922080440_create_agents.rb +29 -0
  171. data/db/migrate/20120922081104_create_commissions.rb +10 -0
  172. data/db/migrate/20120927035841_create_gateways.rb +13 -0
  173. data/db/migrate/20120927040626_create_provider_gateways.rb +13 -0
  174. data/db/migrate/20120927091849_create_limits.rb +10 -0
  175. data/db/migrate/20120927164647_create_roles.rb +14 -0
  176. data/db/migrate/20121003131522_create_report_templates.rb +18 -0
  177. data/db/migrate/20121007135652_create_reports.rb +13 -0
  178. data/db/migrate/20121008073905_create_report_results.rb +10 -0
  179. data/db/migrate/20121017114538_create_gateway_settings.rb +12 -0
  180. data/db/migrate/20121017114556_create_gateway_attachments.rb +10 -0
  181. data/db/migrate/20121019132606_create_revisions.rb +19 -0
  182. data/db/migrate/20121023073501_create_gateway_switches.rb +10 -0
  183. data/db/migrate/20121112142743_create_terminal_orders.rb +13 -0
  184. data/db/migrate/20121118191553_create_versions.rb +19 -0
  185. data/db/migrate/20121125093414_create_system_receipt_templates.rb +9 -0
  186. data/db/migrate/20121127192257_create_terminal_builds.rb +10 -0
  187. data/db/migrate/20121212053441_create_rebates.rb +15 -0
  188. data/db/migrate/20121216143855_create_provider_receipt_templates.rb +9 -0
  189. data/db/migrate/20130101091100_create_terminal_profiles.rb +13 -0
  190. data/db/migrate/20130101091734_create_provider_rebates.rb +21 -0
  191. data/db/migrate/20130102164447_create_limit_sections.rb +14 -0
  192. data/db/migrate/20130102164503_create_commission_sections.rb +17 -0
  193. data/db/migrate/20130102171743_create_provider_profiles.rb +10 -0
  194. data/db/migrate/20130103152507_create_provider_fields.rb +17 -0
  195. data/db/migrate/20130103154526_create_provider_groups.rb +10 -0
  196. data/db/migrate/20130104063628_create_terminal_profile_providers.rb +11 -0
  197. data/db/migrate/20130104090957_create_terminal_profile_provider_groups.rb +11 -0
  198. data/db/migrate/20130108091644_create_terminal_profile_promotions.rb +10 -0
  199. data/db/schema.rb +489 -0
  200. data/db/seeds/receipt_templates/payment.txt +19 -0
  201. data/db/seeds/receipt_templates/system/balance.txt +13 -0
  202. data/db/seeds/receipt_templates/system/collection.txt +17 -0
  203. data/db/seeds/receipt_templates/system/touchtest.txt +15 -0
  204. data/db/seeds.rb +18 -0
  205. data/doc/README_FOR_APP +2 -0
  206. data/init.rb +1 -0
  207. data/lib/active_admin/cancan_integration.rb +81 -0
  208. data/lib/active_admin/form_builder_fix.rb +76 -0
  209. data/lib/active_admin/inputs/filter_date_range_input_fix.rb +24 -0
  210. data/lib/active_admin/inputs/filter_multiple_select_input.rb +18 -0
  211. data/lib/active_admin/inputs/filter_numeric_range_input.rb +31 -0
  212. data/lib/active_admin/resource_controller_fix.rb +23 -0
  213. data/lib/active_admin/views/pages/base_fix.rb +13 -0
  214. data/lib/assets/.gitkeep +0 -0
  215. data/lib/blueprints.rb +79 -0
  216. data/lib/date_expander.rb +38 -0
  217. data/lib/dav4rack/build_resource.rb +59 -0
  218. data/lib/formtastic/inputs/selectable_check_boxes.rb +39 -0
  219. data/lib/paper_trail/version_fix.rb +3 -0
  220. data/lib/report_builder.rb +88 -0
  221. data/lib/seeder.rb +103 -0
  222. data/lib/smartkiosk/server/version.rb +5 -0
  223. data/lib/smartkiosk/server.rb +35 -0
  224. data/lib/string_file.rb +12 -0
  225. data/lib/tasks/.gitkeep +0 -0
  226. data/lib/tasks/db.rake +27 -0
  227. data/lib/tasks/dump.rake +53 -0
  228. data/lib/tasks/matrioshka.rake +16 -0
  229. data/log/.gitkeep +0 -0
  230. data/log/gateways/.gitkeep +0 -0
  231. data/public/404.html +26 -0
  232. data/public/422.html +26 -0
  233. data/public/500.html +25 -0
  234. data/public/robots.txt +5 -0
  235. data/script/rails +6 -0
  236. data/smartkiosk-server.gemspec +23 -0
  237. data/spec/controllers/collections_controller_spec.rb +32 -0
  238. data/spec/controllers/payments_controller_spec.rb +123 -0
  239. data/spec/controllers/system_receipt_templates_controller_spec.rb +5 -0
  240. data/spec/controllers/terminal_builds_controller_spec.rb +5 -0
  241. data/spec/controllers/terminal_orders_controller_spec.rb +32 -0
  242. data/spec/controllers/terminal_pings_controller_spec.rb +31 -0
  243. data/spec/spec_helper.rb +66 -0
  244. data/vendor/assets/javascripts/.gitkeep +0 -0
  245. data/vendor/assets/javascripts/chosen.jquery.js +1026 -0
  246. data/vendor/assets/javascripts/datepicker-ru.jquery.js +21 -0
  247. data/vendor/assets/javascripts/nestedSortable.jquery.js +429 -0
  248. data/vendor/assets/javascripts/qtip.jquery.js +3403 -0
  249. data/vendor/assets/stylesheets/.gitkeep +0 -0
  250. data/vendor/assets/stylesheets/chosen.jquery.css +397 -0
  251. data/vendor/assets/stylesheets/modules/PIE.htc +96 -0
  252. data/vendor/assets/stylesheets/qtip.jquery.css.scss +604 -0
  253. data/vendor/plugins/.gitkeep +0 -0
  254. metadata +333 -0
@@ -0,0 +1,201 @@
1
+ ActiveAdmin.register Provider do
2
+
3
+ menu :parent => I18n.t('activerecord.models.provider.other'),
4
+ :label => I18n.t('smartkiosk.admin.menu.manage'),
5
+ :priority => 1,
6
+ :if => proc { can? :index, Provider }
7
+
8
+ controller do
9
+ def scoped_collection
10
+ Provider.includes(:provider_profile)
11
+ end
12
+ end
13
+
14
+ #
15
+ # INDEX
16
+ #
17
+ filter :id
18
+ filter :provider_profile, :as => 'multiple_select', :input_html => { :class => 'chosen' },
19
+ :collection => proc { ProviderProfile.rmap }
20
+ filter :provider_group, :as => 'multiple_select', :input_html => { :class => 'chosen' }
21
+ filter :title
22
+ filter :keyword
23
+ filter :gateway_ids, :as => 'select',
24
+ :collection => proc { Gateway.all },
25
+ :input_html => { :class => 'chosen' }
26
+ filter :created_at
27
+ filter :updated_at
28
+
29
+ index do
30
+ selectable_column
31
+ column :id, :sortable => :id do |x|
32
+ link_to x.id, [:admin, x]
33
+ end
34
+ column :icon do |x|
35
+ image_tag(x.icon.url(:thumb)) unless x.icon.blank?
36
+ end
37
+ column :provider_profile
38
+ column :keyword
39
+ column :title
40
+ column :provider_gateways_count
41
+ column :updated_at
42
+ default_actions
43
+ end
44
+
45
+ #
46
+ # SHOW
47
+ #
48
+ show do |provider|
49
+ attributes_table do
50
+ row :id
51
+ row :provider_profile
52
+ row :provider_group
53
+ row :title
54
+ row :keyword
55
+ row :icon do
56
+ image_tag(provider.icon) unless provider.icon.blank?
57
+ end
58
+ row :provider_gateways_count
59
+ row :juristic_name
60
+ row :inn
61
+ row :support_phone
62
+ row :updated_at
63
+ end
64
+
65
+ panel I18n.t('activerecord.models.gateway.other') do
66
+ table_for(provider.provider_gateways.order("priority DESC"), :i18n => ProviderGateway) do |t|
67
+ t.column :gateway
68
+ t.column :priority
69
+ t.column :gateway_provider_id
70
+ end
71
+ end
72
+
73
+ panel I18n.t('activerecord.models.commission.other') do
74
+ provider.commissions.actual.each do |commission|
75
+ attributes_table_for commission do
76
+ row :start
77
+ row :finish
78
+ end
79
+ table_for(commission.commission_sections, :i18n => CommissionSection) do |t|
80
+ t.column :agent
81
+ t.column :terminal_profile
82
+ t.column :payment_type
83
+ t.column :min
84
+ t.column :max
85
+ t.column :percent_fee
86
+ t.column :static_fee
87
+ end
88
+ end
89
+ end
90
+
91
+ panel I18n.t('activerecord.models.limit.other') do
92
+ provider.limits.actual.each do |limit|
93
+ attributes_table_for limit do
94
+ row :start
95
+ row :finish
96
+ end
97
+ table_for(limit.limit_sections, :i18n => LimitSection) do |t|
98
+ t.column :agent
99
+ t.column :terminal_profile
100
+ t.column :payment_type
101
+ t.column :min
102
+ t.column :max
103
+ end
104
+ end
105
+ end
106
+
107
+ panel I18n.t('activerecord.models.payment.other') do
108
+ table_for(provider.payments.limit(20), :i18n => Payment) do |t|
109
+ t.column :terminal do |p|
110
+ unless p.terminal.blank?
111
+ link_to p.terminal.keyword, admin_terminal_path(p.terminal)
112
+ end
113
+ end
114
+ t.column :paid_amount
115
+ t.column :provider
116
+ t.column :created_at
117
+ end
118
+ button(
119
+ link_to I18n.t('smartkiosk.full_list'),
120
+ admin_payments_path(:q => {:provider_id_eq => provider.id})
121
+ )
122
+ end
123
+
124
+ active_admin_comments
125
+ end
126
+
127
+ #
128
+ # FORM
129
+ #
130
+ form do |f|
131
+ f.inputs do
132
+ f.input :title
133
+ f.input :provider_profile, :input_html => { :class => 'chosen' },
134
+ :collection => ProviderProfile.rmap
135
+ f.input :provider_group, :input_html => { :class => 'chosen' }
136
+ f.input :keyword
137
+ f.input :icon, :hint => (f.template.image_tag(provider.icon).html_safe unless provider.icon.blank?)
138
+ f.input :juristic_name
139
+ f.input :inn
140
+ f.input :support_phone
141
+ f.input :requires_print, :as => :select, :input_html => { :class => 'chosen' }
142
+ end
143
+ f.inputs do
144
+ f.has_many :provider_fields, :sortable => :priority do |fpf|
145
+ fpf.input :title
146
+ fpf.input :keyword,
147
+ :hint => I18n.t('smartkiosk.admin.messages.provider_fields.keyword_hint')
148
+ fpf.input :kind, :as => :select,
149
+ :input_html => {
150
+ :class => 'chosen',
151
+ :onchange => <<-JS
152
+ element = $(this);
153
+ wrapper = element.closest('ol');
154
+
155
+ wrapper.find('.mask').hide();
156
+ wrapper.find('.values').hide();
157
+
158
+ if (element.val() == 'string' || element.val() == 'number') {
159
+ wrapper.find('.mask').show();
160
+ }
161
+ if (element.val() == 'select') {
162
+ wrapper.find('.values').show();
163
+ }
164
+ JS
165
+ },
166
+ :collection => I18n.t('smartkiosk.provider_field_kinds').invert
167
+ fpf.input :mask, :as => :string,
168
+ :wrapper_html => {
169
+ :class => 'mask',
170
+ :style => ('display:none' unless fpf.object.kind == 'string')
171
+ },
172
+ :hint => I18n.t('smartkiosk.admin.messages.provider_fields.mask_hint')
173
+ fpf.input :regexp
174
+ fpf.input :values, :as => :string,
175
+ :wrapper_html => {
176
+ :class => 'values',
177
+ :style => ('display:none' unless fpf.object.kind == 'select')
178
+ },
179
+ :hint => I18n.t('smartkiosk.admin.messages.provider_fields.values_hint')
180
+ unless fpf.object.new_record?
181
+ fpf.input :_destroy, :as => :boolean, :label => I18n.t('active_admin.delete')
182
+ end
183
+ fpf.input :priority, :as => :hidden
184
+ end
185
+ end
186
+ f.inputs do
187
+ f.has_many :provider_gateways do |fpg|
188
+ fpg.input :gateway, :input_html => { :class => 'chosen' }
189
+ fpg.input :gateway_provider_id
190
+ fpg.input :priority
191
+ fpg.input :account_mapping
192
+ fpg.input :human_fields_mapping, :as => :text, :input_html => {:rows => 4}
193
+ unless fpg.object.new_record?
194
+ fpg.input :_destroy, :as => :boolean, :label => I18n.t('active_admin.delete')
195
+ end
196
+ fpg.form_buffers.last
197
+ end
198
+ end
199
+ f.buttons
200
+ end
201
+ end
@@ -0,0 +1,83 @@
1
+ ActiveAdmin.register Rebate do
2
+ menu :parent => I18n.t('activerecord.models.gateway.other'),
3
+ :if => proc { can? :index, Rebate }
4
+
5
+ #
6
+ # INDEX
7
+ #
8
+ scope I18n.t('active_admin.all'), :all
9
+ scope I18n.t('activerecord.scopes.rebate.active'), :active, :default => true
10
+ scope I18n.t('activerecord.scopes.rebate.outdated'), :outdated
11
+
12
+ filter :id
13
+ filter :gateway, :as => 'multiple_select', :input_html => { :class => 'chosen' }
14
+ filter :created_at
15
+ filter :updated_at
16
+
17
+ index do
18
+ selectable_column
19
+ column :id, :sortable => :id do |x|
20
+ link_to x.id, [:admin, x]
21
+ end
22
+ column :gateway
23
+ column :start
24
+ column :finish
25
+ end
26
+
27
+ #
28
+ # SHOW
29
+ #
30
+ show do |rebate|
31
+ attributes_table do
32
+ row :id
33
+ row :gateway
34
+ row :created_at
35
+ row :updated_at
36
+ end
37
+ end
38
+
39
+ #
40
+ # FORM
41
+ #
42
+ form do |f|
43
+ f.semantic_errors
44
+ f.inputs do
45
+ f.input :gateway, :input_html => {
46
+ :class => 'chosen',
47
+ :onchange => "location.href = '/admin/rebates/new?rebate[gateway_id]='+$(this).val()",
48
+ :disabled => !f.object.new_record?
49
+ }
50
+ if rebate.gateway.blank?
51
+ f.form_buffers.last << content_tag(:li, I18n.t('smartkiosk.admin.messages.rebates.choose_gateway'))
52
+ elsif rebate.gateway.providers.count < 1
53
+ f.form_buffers.last << content_tag(:li, I18n.t('smartkiosk.admin.messages.rebates.no_providers'))
54
+ else
55
+ f.input :period_kind, :as => :select, :collection => I18n.t('smartkiosk.rebate_periods').invert,
56
+ :input_html => { :class => 'chosen' }
57
+ f.input :period_fee
58
+ f.input :start, :as => :datepicker
59
+ f.input :finish, :as => :datepicker
60
+ end
61
+
62
+ f.form_buffers.last
63
+ end
64
+
65
+ unless rebate.gateway.blank?
66
+ f.inputs do
67
+ f.has_many :provider_rebates do |prf|
68
+ prf.semantic_errors
69
+ prf.input :provider, :collection => rebate.gateway.providers, :input_html => { :class => 'chosen' }
70
+ prf.input :payment_type, :as => :select, :input_html => { :class => 'chosen' }, :collection => I18n.t('smartkiosk.payment_types').invert
71
+ prf.input :requires_commission, :as => :select, :input_html => { :class => 'chosen' }
72
+ prf.input :min
73
+ prf.input :max
74
+ prf.input :min_percent_amount
75
+ prf.input :percent_fee
76
+ prf.input :static_fee
77
+ end
78
+ end
79
+ end
80
+
81
+ f.actions
82
+ end
83
+ end
@@ -0,0 +1,66 @@
1
+ ActiveAdmin.register ReportResult do
2
+ actions :show
3
+
4
+ menu false
5
+
6
+ member_action :excel do
7
+ report_result = ReportResult.find(params[:id])
8
+
9
+ report = report_result.report
10
+ result = report_result.data
11
+ fields = result.first.keys
12
+
13
+ package = Axlsx::Package.new do |p|
14
+ p.workbook.add_worksheet(:name => "Report") do |ws|
15
+ bold = ws.styles.add_style :b => true, :alignment=> {:horizontal => :center}
16
+ ws.add_row fields.map{|x| view_context.localize_report_fields(x)[0]}, :style => bold
17
+
18
+ result.each do |r|
19
+ row = []
20
+ fields.each{|f| row << r[f]}
21
+ ws.add_row row
22
+ end
23
+ end
24
+ end
25
+
26
+ package.use_shared_strings = true
27
+ send_data package.to_stream.read, :filename => 'report.xlsx',
28
+ :type => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
29
+ end
30
+
31
+ #
32
+ # SHOW
33
+ #
34
+ action_item :only => [:show] do
35
+ link_to I18n.t('smartkiosk.admin.actions.report_results.excel'),
36
+ excel_admin_report_result_path(report_result)
37
+ end
38
+
39
+ show do
40
+ attributes_table do
41
+ row :rows
42
+ row :report
43
+ row :created_at
44
+ end
45
+
46
+ panel I18n.t('smartkiosk.admin.panels.report_results.data') do
47
+ report = report_result.report
48
+ result = report_result.data
49
+ fields = result.first.try(:keys) || []
50
+ table do
51
+ tr do
52
+ fields.each do |field|
53
+ th localize_report_fields(field)[0]
54
+ end
55
+ end
56
+ result.each do |row|
57
+ tr do
58
+ fields.each do |field|
59
+ td row[field]
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,209 @@
1
+ ActiveAdmin.register ReportTemplate do
2
+
3
+ menu :parent => I18n.t('activerecord.models.report.other'),
4
+ :label => I18n.t('activerecord.models.report_template.other'),
5
+ :priority => 2,
6
+ :if => proc { can? :index, ReportTemplate }
7
+
8
+ controller do
9
+ def scoped_collection
10
+ scope = ReportTemplate
11
+
12
+ unless current_user.root
13
+ t = ReportTemplate.arel_table
14
+
15
+ scope = scope.where(t[:open].eq(true).or t[:user_id].eq(current_user.id))
16
+ end
17
+
18
+ scope
19
+ end
20
+
21
+ def edit
22
+ @report_template = ReportTemplate.find(params[:id])
23
+ @report_template.kind = params[:report_template][:kind] unless params[:report_template].try(:[], :kind).blank?
24
+ end
25
+ end
26
+
27
+ #
28
+ # INDEX
29
+ #
30
+ filter :kind, :as => 'multiple_select', :input_html => { :class => 'chosen' },
31
+ :collection => proc { I18n.t('smartkiosk.reports.kinds').invert }
32
+ filter :title
33
+ filter :created_at
34
+
35
+ index do
36
+ column :kind do |report_template|
37
+ I18n.t "smartkiosk.reports.kinds.#{report_template.kind}"
38
+ end
39
+ column :open do |x|
40
+ status_boolean(self, x.open?)
41
+ end
42
+ column :title
43
+ column :user
44
+ column :created_at
45
+ default_actions
46
+ end
47
+
48
+ #
49
+ # SHOW
50
+ #
51
+ action_item :only => [:show] do
52
+ link_to I18n.t('smartkiosk.admin.actions.report_templates.report'),
53
+ new_admin_report_path('report[report_template_id]' => report_template.id)
54
+ end
55
+
56
+ show do |report_template|
57
+ attributes_table do
58
+ row :kind do
59
+ I18n.t "smartkiosk.reports.kinds.#{report_template.kind}"
60
+ end
61
+ row :title
62
+ row :open do |x|
63
+ status_boolean(self, x.open?)
64
+ end
65
+ row :groupping do
66
+ localize_report_fields(report_template.groupping)[0] unless report_template.groupping.blank?
67
+ end
68
+ row :fields do
69
+ unless report_template.fields.blank?
70
+ report_template.fields.select{|x| !x.blank?}.map do |x|
71
+ localize_report_fields(x)[0]
72
+ end.join ', '
73
+ end
74
+ end
75
+ row :sorting do
76
+ localize_report_fields(report_template.sorting)[0] unless report_template.sorting.blank?
77
+ end
78
+ row :sort_desc do |x|
79
+ status_boolean(self, x.sort_desc?)
80
+ end
81
+ row :email
82
+ row :user
83
+ row :created_at
84
+ row :updated_at
85
+ end
86
+
87
+ panel I18n.t('smartkiosk.admin.panels.report_templates.conditions') do
88
+ div(:class => 'attributes_table') do
89
+ table do
90
+ report_template.report_builder.conditions.each do |condition, values|
91
+ tr do
92
+ th do
93
+ localize_report_condition_title(report_template.report_builder, condition)
94
+ end
95
+ td do
96
+ unless report_template.conditions[condition].blank?
97
+ localize_report_condition_value(report_template.report_builder, condition, report_template.conditions[condition])
98
+ else
99
+ span(I18n.t('active_admin.empty'), :class => 'empty')
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ panel I18n.t('smartkiosk.admin.panels.report_templates.recent') do
109
+ table_for(
110
+ report_template.reports.where(:state => 'done').order('id DESC'),:i18n => Report
111
+ ) do |t|
112
+ t.column :created_at do |r|
113
+ link_to I18n.l(r.created_at, :format => :long), admin_report_path(r)
114
+ end
115
+ t.column :start
116
+ t.column :finish
117
+ end
118
+ end
119
+
120
+ active_admin_comments
121
+ end
122
+
123
+ #
124
+ # FORM
125
+ #
126
+ form do |f|
127
+ f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.basic') do
128
+ f.input :kind, :as => :select,
129
+ :collection => I18n.t('smartkiosk.reports.kinds').invert,
130
+ :input_html => {
131
+ :class => 'chosen',
132
+ :onchange => "location.href = '?report_template[kind]='+$(this).val()"
133
+ }
134
+ f.input :title
135
+ f.input :open, :as => :select, :input_html => { :class => 'chosen' }
136
+ f.input :email
137
+ f.input :user, :input_html => { :class => 'chosen' }
138
+ end
139
+
140
+ if f.object.report_builder
141
+ f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.select') do
142
+ f.input :groupping, :as => :select,
143
+ :collection => localize_report_fields(f.object.report_builder.groupping),
144
+ :input_html => {
145
+ :class => 'chosen',
146
+ :onchange => "reportChangeGroupping($(this).val())"
147
+ }
148
+
149
+ ([''] + f.object.report_builder.groupping).each do |g|
150
+ f.input :fields, :as => :selectable_check_boxes,
151
+ :collection => localize_report_fields(f.object.report_builder.fields[g]),
152
+ :wrapper_html => {
153
+ :class => "groupping groupping-#{g.gsub '.', '-'}",
154
+ :style => ('display: none' unless f.object.groupping == g)
155
+ }
156
+ end
157
+
158
+ f.input :calculations, :as => :selectable_check_boxes,
159
+ :collection => localize_report_calculations(f.object.report_builder)
160
+
161
+ ([''] + f.object.report_builder.groupping).each do |g|
162
+ f.input :sorting, :as => :select,
163
+ :collection => localize_report_fields(f.object.report_builder.fields[g]),
164
+ :input_html => {
165
+ :id => "report_template_sorting_#{g.gsub '.', '-'}",
166
+ :style => 'min-width: 50%',
167
+ :disabled => ("disabled" unless f.object.groupping == g),
168
+ :class => ('chosen' if f.object.groupping == g)
169
+ },
170
+ :wrapper_html => {
171
+ :class => "sorting sorting-#{g.gsub '.', '-'}",
172
+ :style => ('display: none' unless f.object.groupping == g)
173
+ }
174
+ end
175
+
176
+ f.input :sort_desc
177
+
178
+ f.form_buffers.last
179
+ end
180
+
181
+ f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.conditions') do
182
+ f.object.report_builder.conditions.each do |condition, values|
183
+ f.input "condition_#{condition}", :as => :select,
184
+ :label => localize_report_condition_title(f.object.report_builder, condition),
185
+ :collection => localize_report_conditions(f.object.report_builder, condition),
186
+ :input_html => {
187
+ :class => 'chosen',
188
+ :multiple => true,
189
+ :'data-placeholder' => I18n.t('active_admin.filters.multiple_select.placeholder')
190
+ }
191
+ end
192
+
193
+ f.form_buffers.last
194
+ end
195
+ else
196
+ f.inputs I18n.t('smartkiosk.admin.panels.report_templates.form.more') do
197
+ f.form_buffers.last << content_tag(:li,
198
+ I18n.t('smartkiosk.admin.messages.report_templates.choose_report_type'
199
+ ))
200
+ end
201
+ end
202
+
203
+ if f.object.report_builder
204
+ f.actions
205
+ end
206
+
207
+ f.form_buffers.last
208
+ end
209
+ end