Class: PaymentsReport

Inherits:
ReportBuilder::Base show all
Defined in:
app/reports/payments_report.rb

Instance Attribute Summary

Attributes inherited from ReportBuilder::Base

#report, #template

Instance Method Summary collapse

Methods inherited from ReportBuilder::Base

#arelize, #human_calculation_name, #human_calculation_names, #human_condition_name, #human_condition_values, #human_field_name, #human_field_value, #human_groupping_field_names, #human_groupping_names, #initialize, #keyword, #query, requires_dates!, requires_dates?, #requires_dates?

Constructor Details

This class inherits a constructor from ReportBuilder::Base

Instance Method Details

#calculationsObject



179
180
181
182
183
184
185
186
# File 'app/reports/payments_report.rb', line 179

def calculations
  {
    :quantity   => lambda{|q, t| t.groupping.blank? ? q : q.project('COUNT(*) AS "quantity"') },
    :enrolled   => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(enrolled_amount) AS "enrolled"') },
    :paid       => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(paid_amount) AS "paid"') },
    :commission => lambda{|q, t| t.groupping.blank? ? q : q.project('SUM(commission_amount) AS "commission"') }
  }.with_indifferent_access
end

#conditionsObject



188
189
190
191
192
193
194
195
196
197
# File 'app/reports/payments_report.rb', line 188

def conditions
  {
    'payment.state' => proc { I18n.t('smartkiosk.payment_states') },
    'payment.payment_type' => proc { I18n.t('smartkiosk.payment_types') },
    'payment.provider_id' => proc { Provider.rmap.invert },
    'payment.agent_id' => proc { Agent.rmap.invert },
    'payment.terminal_id' => proc { Terminal.rmap.invert },
    'payment.gateway_id' => proc { Gateway.rmap.invert }
  }
end

#context(start, finish) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'app/reports/payments_report.rb', line 16

def context(start, finish)
  context = tables[:payment]

  [:terminal, :agent, :gateway, :provider].each do |x|
    context = context.join(tables[x]).on(tables[:payment][x.to_s + '_id'].eq tables[x][:id])
  end

  context.where(tables[:payment][:created_at].in(start..finish))

  context
end

#field_localizationsObject



173
174
175
176
177
# File 'app/reports/payments_report.rb', line 173

def field_localizations
  {
    'payment.state' => proc{|x| I18n.t("smartkiosk.payment_states.#{x}")}
  }
end

#fieldsObject



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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/reports/payments_report.rb', line 41

def fields
  {
    '' => %w(
        payment.terminal_id
        terminal.keyword
        terminal.address
        terminal.version
        terminal.issues_started_at
        terminal.collected_at
        terminal.printer_error
        terminal.cash_acceptor_error
        terminal.juristic_name
        terminal.sector
        terminal.contact_name
        terminal.contact_phone
        terminal.contact_email
        terminal.schedule
        terminal.juristic_name
        terminal.contract_number
        terminal.manager
        terminal.rent
        terminal.rent_finish_date
        terminal.collection_zone
        terminal.check_phone_number
        payment.agent_id
        agent.title
        agent.juristic_name
        agent.juristic_address_city
        agent.juristic_address_street
        agent.juristic_address_home
        agent.physical_address_city
        agent.physical_address_district
        agent.physical_address_subway
        agent.physical_address_street
        agent.physical_address_home
        agent.contact_name
        agent.contact_info
        agent.director_name
        agent.director_contact_info
        agent.bookkeeper_name
        agent.bookkeeper_contact_info
        agent.inn
        agent.support_phone
        payment.gateway_id
        gateway.title
        payment.provider_id
        provider.title
        provider.keyword
        provider.juristic_name
        provider.inn
        payment.session_id
        payment.foreign_id
        payment.corrected_payment_id
        payment.user_id
        payment.collection_id
        payment.revision_id
        payment.payment_type
        payment.account
        payment.fields
        payment.raw_fields
        payment.meta
        payment.currency
        payment.paid_amount
        payment.commission_amount
        payment.enrolled_amount
        payment.rebate_amount
        payment.state
        payment.gateway_error
        payment.gateway_provider_id
        payment.gateway_payment_id
        payment.source
        payment.receipt_number
        payment.paid_at
        payment.card_number
        payment.card_number_hash
      ),
    'payment.state' => %w(
        payment.state
      ),
    'payment.terminal_id' => %w(
        payment.terminal_id
        terminal.keyword
        terminal.address
        terminal.juristic_name
        terminal.manager
        terminal.rent
        terminal.address
      ),
    'payment.provider_id' => %w(
        payment.provider_id
        provider.title
        provider.keyword
        provider.juristic_name
        provider.inn
      ),
    'payment.agent_id' => %w(
        payment.agent_id
        agent.title
        agent.juristic_name
        agent.juristic_address_city
        agent.juristic_address_street
        agent.juristic_address_home
        agent.physical_address_city
        agent.physical_address_district
        agent.physical_address_subway
        agent.physical_address_street
        agent.physical_address_home
        agent.contact_name
        agent.contact_info
        agent.director_name
        agent.director_contact_info
        agent.bookkeeper_name
        agent.bookkeeper_contact_info
        agent.inn
        agent.support_phone
      ),
    'payment.gateway_id' => %w(
        payment.gateway_id
        gateway.title
      ),
    'payment.hour' => %w(
        payment.hour
      ),
    'payment.month' => %w(
        payment.month
      ),
    'payment.day' => %w(
        payment.day
      )
  }
end

#grouppingObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/reports/payments_report.rb', line 28

def groupping
  %w(
    payment.state
    payment.terminal_id
    payment.provider_id
    payment.agent_id
    payment.gateway_id
    payment.hour
    payment.day
    payment.month
  )
end

#tablesObject



6
7
8
9
10
11
12
13
14
# File 'app/reports/payments_report.rb', line 6

def tables
  @tables ||= {
    :terminal => Arel::Table.new(:terminals),
    :payment  => Arel::Table.new(:payments),
    :agent    => Arel::Table.new(:agents),
    :gateway  => Arel::Table.new(:gateways),
    :provider => Arel::Table.new(:providers)
  }.with_indifferent_access
end