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,14 @@
1
+ @font-face {
2
+ font-family: 'PT_Sans-Web';
3
+ src: url('PT_Sans-Web-Regular.eot');
4
+ src: url('PT_Sans-Web-Regular.woff') format('woff'), url('PT_Sans-Web-Regular.ttf') format('truetype'), url('PT_Sans-Web-Regular.svg') format('svg');
5
+ font-weight: normal;
6
+ font-style: normal;
7
+ }
8
+
9
+ @font-face {
10
+ font-family: 'PT_Sans-Web';
11
+ src: url('PT_Sans-Web-Bold.eot');
12
+ src: url('PT_Sans-Web-Bold.woff') format('woff'), url('PT_Sans-Web-Bold.ttf') format('truetype'), url('PT_Sans-Web-Bold.svg') format('svg');
13
+ font-weight: bold;
14
+ }
@@ -0,0 +1,12 @@
1
+ // fieldset.provider_groups {
2
+ // img {
3
+ // padding-right: 5px;
4
+ // }
5
+
6
+ // li.file {
7
+ // display: block !important;
8
+ // label { display: none }
9
+ // float: right;
10
+ // padding: 5px;
11
+ // }
12
+ // }
@@ -0,0 +1,12 @@
1
+ body.active_admin {
2
+ form {
3
+ table.hint {
4
+ width: 76%;
5
+ margin-left: 21%;
6
+
7
+ td {
8
+ width: 50%;
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ body.active_admin {
2
+ .terminal_map {
3
+ margin-top: 8px;
4
+ width: 600px;
5
+ height: 300px;
6
+ background-color: gray;
7
+ text-align: center;
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ rescue_from CanCan::AccessDenied do |exception|
5
+ redirect_to '/'
6
+ end
7
+
8
+ def authenticate_terminal
9
+ @terminal = Terminal.find_by_keyword(params[:terminal])
10
+ render :text => nil, :status => 404 if @terminal.blank?
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CollectionsController < ApplicationController
2
+ before_filter :authenticate_terminal
3
+
4
+ def create
5
+ collection = @terminal.collections.create! params[:collection]
6
+ render :text => collection.id, :status => 200
7
+ rescue ActiveRecord::RecordInvalid
8
+ render :text => nil, :status => 400
9
+ end
10
+ end
@@ -0,0 +1,73 @@
1
+ # coding: utf-8
2
+ class PaymentsController < ApplicationController
3
+ before_filter :authenticate_terminal
4
+
5
+ def limits
6
+ provider = Provider.find_by_keyword params[:provider]
7
+
8
+ render :json => provider.limits.actual.
9
+ by_terminal_profile_and_agent_ids(@terminal.terminal_profile_id, @terminal.agent_id).
10
+ by_payment_type(params[:payment_type]).
11
+ as_json(:only => [:min, :max], :methods => [:weight])
12
+ end
13
+
14
+ def create
15
+ provider = Provider.find_by_keyword params[:provider]
16
+
17
+ if provider.blank?
18
+ Payment.plog :info, :web, "Provider #{params[:provider]} not found",
19
+ :session_id => params[:payment][:session_id],
20
+ :terminal_id => @terminal.id
21
+
22
+ render :text => nil, :status => 404
23
+ return
24
+ end
25
+
26
+ payment = Payment.where(
27
+ :terminal_id => @terminal.id,
28
+ :session_id => params[:payment][:session_id]
29
+ ).first
30
+
31
+ if payment.blank?
32
+ if payment = Payment.build!(@terminal, provider, params[:payment])
33
+ payment.plog :info, :transport, "Created"
34
+
35
+ payment.plog :info, :transport, "Checked" do
36
+ payment.check!
37
+ end
38
+
39
+ render :json => {
40
+ :id => payment.id,
41
+ :state => payment.state,
42
+ :requires_print => provider.requires_print,
43
+ :limits => Limit.for(payment, false).as_json(
44
+ :only => [:min, :max], :methods => [:weight]
45
+ ),
46
+ :commissions => Commission.for(payment, false).as_json(
47
+ :only => [:min, :max, :percent_fee, :static_fee, :payment_type],
48
+ :methods => [:weight]
49
+ ),
50
+ :receipt_template => ProviderReceiptTemplate.for(payment).compile(payment)
51
+ }
52
+ else
53
+ Payment.plog :info, :web, "Payment was not created"
54
+ render :nothing => true, :status => 406
55
+ end
56
+ else
57
+ payment.plog :warn, :transport, "Existing payment found, declining"
58
+ render :nothing => true, :status => 406
59
+ end
60
+ end
61
+
62
+ def pay
63
+ payment = @terminal.payments.find(params[:id])
64
+
65
+ unless payment.queue?
66
+ payment.plog :info, :transport, "Sent to queue" do
67
+ payment.enqueue!(params[:payment])
68
+ end
69
+ end
70
+
71
+ render :text => nil, :status => 200
72
+ end
73
+ end
@@ -0,0 +1,10 @@
1
+ class SystemReceiptTemplatesController < ApplicationController
2
+ before_filter :authenticate_terminal
3
+
4
+ def index
5
+ templates = SystemReceiptTemplate.unscoped
6
+ templates = templates.new_from(params[:date]) unless params[:date].blank?
7
+
8
+ render :json => templates.as_json(:only => [:keyword, :template])
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class TerminalBuildsController < ApplicationController
2
+ def hashes
3
+ render :json => TerminalBuild.find(params[:id]).hashes
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ class TerminalOrdersController < ApplicationController
2
+ before_filter :authenticate_terminal
3
+
4
+ def acknowledge
5
+ order = @terminal.terminal_orders.find_by_id(params[:id])
6
+
7
+ if order.blank?
8
+ render :text => nil, :status => 404
9
+ else
10
+ order.sent!(params[:percent], params[:error])
11
+ render :text => nil, :status => 200
12
+ end
13
+ end
14
+
15
+ def complete
16
+ order = @terminal.terminal_orders.find_by_id(params[:id])
17
+
18
+ if order.blank?
19
+ render :text => nil, :status => 404
20
+ else
21
+ order.complete!
22
+ render :text => nil, :status => 200
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ class TerminalPingsController < ApplicationController
2
+ before_filter :authenticate_terminal
3
+
4
+ def create
5
+ begin
6
+ ping_data = params[:terminal_ping]
7
+ providers = ping_data[:providers]
8
+
9
+ remote_timestamp = providers[:updated_at].blank? ? nil : DateTime.parse(providers[:updated_at])
10
+ local_timestamp = [
11
+ Provider.timestamp.value || DateTime.civil(0, 1, 1),
12
+ ProviderGroup.timestamp.value || DateTime.civil(0, 1, 1),
13
+ TerminalProfilePromotion.timestamp.value || DateTime.civil(0, 1, 1)
14
+ ].max
15
+
16
+ @terminal.ping!(TerminalPing.new ping_data)
17
+
18
+ response = {
19
+ :time => DateTime.now,
20
+ :profile => {
21
+ :support_phone => @terminal.terminal_profile.support_phone,
22
+ :logo => @terminal.terminal_profile.logo.url,
23
+ :modified_at => @terminal.terminal_profile.updated_at
24
+ },
25
+ :orders => @terminal.terminal_orders.unsent.as_json(:only => [:id, :keyword, :args, :created_at]),
26
+ :providers => {}
27
+ }
28
+
29
+ unless providers[:ids].blank?
30
+ response[:providers][:remove] = providers[:ids].map{|x| x.to_s} - Provider.rmap.values
31
+ end
32
+
33
+ if remote_timestamp.blank? || local_timestamp > remote_timestamp
34
+ response[:providers][:update] = @terminal.providers_dump remote_timestamp
35
+ response[:providers][:groups] = @terminal.provider_groups_dump
36
+ response[:providers][:promotions] = @terminal.promotions_dump
37
+ response[:providers][:updated_at] = local_timestamp.strftime('%Y-%m-%dT%H:%M:%S.%9N%z')
38
+ end
39
+
40
+ render :json => response
41
+ rescue ActiveRecord::RecordInvalid
42
+ render :text => nil, :status => 400
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ class WelcomeController < ApplicationController
2
+ def index
3
+ render :status => 403
4
+ end
5
+ end
@@ -0,0 +1,56 @@
1
+ module ActiveAdmin::ReportTemplatesHelper
2
+ def localize_report_fields(data)
3
+ if data.is_a? Array
4
+ data.map do |x|
5
+ localize_report_entry x
6
+ end
7
+ else
8
+ localize_report_entry data
9
+ end
10
+ end
11
+
12
+ def localize_report_entry(entry)
13
+ model, name = entry.split '.'
14
+
15
+ title = I18n.t("activerecord.models.#{model}", :count => 1)
16
+ title += ' / '
17
+ title += I18n.t("activerecord.attributes.#{model}.#{name}")
18
+
19
+ [title, entry]
20
+ end
21
+
22
+ def localize_report_calculations(builder)
23
+ builder.calculations.keys.map do |x|
24
+ title = I18n.t "smartkiosk.reports.data.#{builder.keyword}.calculations.#{x}"
25
+ [title, x]
26
+ end
27
+ end
28
+
29
+ def localize_report_condition_title(builder, field)
30
+ I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.title"
31
+ end
32
+
33
+ def localize_report_condition_value(builder, field, value)
34
+ condition = builder.conditions[field]
35
+ collection = if condition.is_a?(Array)
36
+ I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.values"
37
+ else
38
+ condition.call().with_indifferent_access
39
+ end
40
+
41
+ return value.is_a?(Array) ? value.map{|x| collection[x]}.join(', ') : collection[value]
42
+ end
43
+
44
+ def localize_report_conditions(builder, field)
45
+ condition = builder.conditions[field]
46
+
47
+ if condition.is_a?(Array)
48
+ return condition.map do |x|
49
+ title = I18n.t "smartkiosk.reports.data.#{builder.keyword}.conditions.#{field}.values.#{x}"
50
+ [title, x]
51
+ end
52
+ elsif condition.is_a?(Proc)
53
+ return condition.call().invert
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ module ActiveAdmin::ViewsHelper
2
+ def status_boolean(context, value)
3
+ return "" if value.nil?
4
+ if value
5
+ context.status_tag I18n.t('formtastic.yes'), :ok
6
+ else
7
+ context.status_tag I18n.t('formtastic.no'), :error
8
+ end
9
+ end
10
+
11
+ def currency(value)
12
+ return "" if value.blank?
13
+ "#{value} #{I18n.t('smartkiosk.main_currency')}"
14
+ end
15
+
16
+ def percent(value)
17
+ return "" if value.blank?
18
+ "#{value}%"
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,30 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ if user.root
6
+ can :manage, :all
7
+ else
8
+ user.user_roles.each do |ur|
9
+ model = ur.role.modelize
10
+
11
+ can :read, model if ur.priveleged?(:read)
12
+ can [:new, :create], model if ur.priveleged?(:create)
13
+ can [:edit, :update], model if ur.priveleged?(:edit)
14
+ can :destroy, model if ur.priveleged?(:destroy)
15
+ end
16
+
17
+ Terminal::ORDERS.each do |order|
18
+ can order, Terminal if user.priveleged?(:terminals, order)
19
+ end
20
+ end
21
+
22
+ cannot :destroy, User do |x|
23
+ x == user
24
+ end
25
+
26
+ cannot :destroy, ProviderReceiptTemplate do |x|
27
+ x.system?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ class Agent < ActiveRecord::Base
2
+ include Redis::Objects::RMap
3
+
4
+ has_rmap({:id => lambda{|x| x.to_s}}, :title)
5
+ has_paper_trail
6
+
7
+ #
8
+ # RELATIONS
9
+ #
10
+ scope :root, where(:agent_id => nil)
11
+
12
+ has_many :terminals
13
+ has_many :agents
14
+ has_many :commissions
15
+ has_many :payments, :order => 'id DESC'
16
+
17
+ belongs_to :agent
18
+
19
+ #
20
+ # VALIDATIONS
21
+ #
22
+ validates :title, :presence => true
23
+
24
+ end
@@ -0,0 +1,65 @@
1
+ class Collection < ActiveRecord::Base
2
+ include DateExpander
3
+
4
+ expand_date_from :collected_at
5
+
6
+ has_paper_trail
7
+
8
+ SOURCE_INNER = 0
9
+ SOURCE_IMPORT = 1
10
+
11
+ #
12
+ # RELATIONS
13
+ #
14
+ belongs_to :terminal
15
+ belongs_to :agent
16
+
17
+ #
18
+ # VALIDATIONS
19
+ #
20
+ validates :terminal, :presence => true, :if => lambda{|x| x.source == SOURCE_INNER }
21
+ validates :agent, :presence => true, :if => lambda{|x| x.source == SOURCE_INNER }
22
+ validates :collected_at, :presence => true
23
+
24
+ validate do
25
+ errors.add(:session_ids, :not_an_array) unless session_ids.is_a?(Array)
26
+ errors.add(:banknotes, :not_a_hash) unless banknotes.is_a?(Hash)
27
+ end
28
+
29
+ #
30
+ # MODIFICATIONS
31
+ #
32
+ serialize :banknotes
33
+ serialize :session_ids
34
+
35
+ before_validation do
36
+ self.agent = terminal.agent unless terminal.blank?
37
+ self.session_ids ||= []
38
+ self.banknotes ||= {}
39
+
40
+ return unless session_ids.is_a?(Array)
41
+ return unless banknotes.is_a?(Hash)
42
+
43
+ payments = Payment.where(:session_id => session_ids)
44
+
45
+ self.cash_sum = banknotes.collect{|k,v| k.to_i*v.to_i}.sum
46
+ self.payments_sum = payments.map{|x| x.paid_amount || 0}.sum
47
+ self.payments_count = session_ids.count
48
+ self.approved_payments_sum = payments.select{|x| x.approved?}.map{|x| x.paid_amount || 0}.sum
49
+ self.approved_payments_count = payments.select{|x| x.approved?}.count
50
+ self.cash_payments_count = payments.select{|x| !x.cashless?}.count
51
+ self.cashless_payments_count = payments.select{|x| x.cashless?}.count
52
+ end
53
+
54
+ after_create do
55
+ unless terminal.blank?
56
+ if terminal.collected_at.blank? || self.collected_at > terminal.collected_at
57
+ terminal.update_attribute(:collected_at, self.collected_at)
58
+ end
59
+ end
60
+
61
+ unless session_ids.blank?
62
+ Payment.where(:foreign_id => session_ids).update_all(:collection_id => id)
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,77 @@
1
+ class Commission < ActiveRecord::Base
2
+
3
+ has_paper_trail
4
+
5
+ #
6
+ # RELATIONS
7
+ #
8
+ belongs_to :provider_profile
9
+ has_many :providers, :through => :provider_profile
10
+ has_many :commission_sections, :inverse_of => :commission
11
+
12
+ accepts_nested_attributes_for :commission_sections, :allow_destroy => true
13
+
14
+ default_scope includes(:commission_sections)
15
+
16
+ scope :actual, lambda{
17
+ where(arel_table[:start].lteq Date.today).
18
+ where(arel_table[:finish].gteq Date.today)
19
+ }
20
+
21
+ #
22
+ # VALIDATIONS
23
+ #
24
+ validates :provider_profile, :presence => true
25
+ validates :start, :presence => true
26
+ validates :finish, :presence => true
27
+
28
+ validate do
29
+ return if start.blank? || finish.blank?
30
+
31
+ if start > finish
32
+ errors.add(:start, :too_large)
33
+ return
34
+ end
35
+
36
+ # Conditions intersections
37
+ neighbors = self.class.where(:provider_profile_id => provider_profile_id)
38
+ neighbors = neighbors.where("id != ?", id) unless id.blank?
39
+
40
+ # Ranges intersections
41
+ neighbors = neighbors.to_a
42
+
43
+ neighbors.select! do |x|
44
+ x.start.between?(start, finish) ||
45
+ x.finish.between?(start, finish) ||
46
+ start.between?(x.start, x.finish) ||
47
+ finish.between?(x.start, x.finish)
48
+ end
49
+
50
+ if neighbors.count > 0
51
+ errors[:base] << I18n.t('activerecord.errors.models.commission.conditions_intersect')
52
+ end
53
+ end
54
+
55
+ #
56
+ # METHODS
57
+ #
58
+ def self.for(payment, filter_amount=true)
59
+ commission = payment.provider.commissions.actual.first
60
+ return [] if commission.blank?
61
+
62
+ rates = commission.commission_sections.
63
+ by_terminal_profile_and_agent_ids(payment.terminal.terminal_profile_id, payment.terminal.agent_id).
64
+ by_payment_type(payment.payment_type)
65
+
66
+ rates.select!{|x|
67
+ x.min <= payment.paid_amount &&
68
+ x.max >= payment.paid_amount
69
+ } if filter_amount
70
+
71
+ rates.sort_by(&:weight).reverse
72
+ end
73
+
74
+ def title
75
+ "##{id}"
76
+ end
77
+ end
@@ -0,0 +1,75 @@
1
+ class CommissionSection < ActiveRecord::Base
2
+
3
+ #
4
+ # RELATIONS
5
+ #
6
+ belongs_to :commission, :inverse_of => :commission_sections
7
+ belongs_to :agent
8
+ belongs_to :terminal_profile
9
+
10
+ scope :by_terminal_profile_and_agent_ids, lambda { |p, a|
11
+ conditions = [
12
+ '(terminal_profile_id IS NULL AND agent_id IS NULL)',
13
+ '(agent_id = ? AND terminal_profile_id IS NULL)',
14
+ 'terminal_profile_id = ?'
15
+ ]
16
+ where(
17
+ conditions.join(' OR '),
18
+ a,
19
+ p
20
+ )
21
+ }
22
+ scope :by_payment_type, lambda { |x|
23
+ x.nil? ? scoped : where("payment_type IS NULL OR payment_type = ?", x)
24
+ }
25
+
26
+ #
27
+ # VALIDATIONS
28
+ #
29
+ validates :min, :presence => true
30
+ validates :max, :presence => true
31
+ validates :percent_fee, :presence => true
32
+ validates :static_fee, :presence => true
33
+
34
+ validate do
35
+ return if min.blank? || max.blank?
36
+
37
+ if min > max
38
+ errors.add(:min, :too_large)
39
+ return
40
+ end
41
+
42
+ neighbors = commission.commission_sections.select{|x| x != self}
43
+
44
+ if neighbors.select{|x| x.payment_type.nil? != payment_type.nil?}.count > 0
45
+ errors[:base] << I18n.t('activerecord.errors.models.commission.payment_type_intersects')
46
+ end
47
+
48
+ neighbors.select! do |x|
49
+ x.agent_id == agent_id &&
50
+ x.terminal_profile_id == terminal_profile_id &&
51
+ x.payment_type == payment_type
52
+ end
53
+
54
+ neighbors.select! do |x|
55
+ x.min.between?(min, max) ||
56
+ x.max.between?(min, max) ||
57
+ min.between?(x.min, x.max) ||
58
+ max.between?(x.min, x.max)
59
+ end
60
+
61
+ if neighbors.count > 0
62
+ errors[:base] << I18n.t('activerecord.errors.models.commission.conditions_intersect')
63
+ end
64
+ end
65
+
66
+ def weight
67
+ return 3 unless terminal_profile_id.blank?
68
+ return 2 unless agent_id.blank?
69
+ return 1
70
+ end
71
+
72
+ def fee(amount)
73
+ (self.static_fee||0) + amount*(self.percent_fee||0)/100
74
+ end
75
+ end