query_report 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/helpers/query_report_filter_helper.rb +0 -8
- data/app/helpers/query_report_link_helper.rb +9 -0
- data/app/views/query_report/_chart.html.erb +10 -0
- data/app/views/query_report/_charts.html.erb +6 -10
- data/app/views/query_report/_links.html.erb +2 -0
- data/app/views/query_report/_records.html.erb +21 -0
- data/app/views/query_report/_search.html.erb +7 -5
- data/app/views/query_report/list.html.erb +3 -32
- data/lib/query_report/filter.rb +44 -26
- data/lib/query_report/helper.rb +6 -6
- data/lib/query_report/version.rb +1 -1
- data/test/dummy/app/controllers/invoices_controller.rb +23 -18
- data/test/dummy/app/models/invoice.rb +2 -1
- data/test/dummy/app/models/user.rb +6 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130622120853_create_users.rb +2 -3
- data/test/dummy/db/migrate/20130630132513_create_invoices.rb +3 -0
- data/test/dummy/db/schema.rb +7 -5
- data/test/dummy/db/seed.rb +14 -3
- data/test/dummy/log/development.log +3848 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_1phunlrkl040xbl9ni38 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_2jj5q0umhfjgdsr3be6r +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_4nme0opawv0cuju7ycln +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_4x4zy2jyybfnrfctzoll +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_501n5dolb96ahn8fsdeb +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_50279rze1q2oyskpd2bx +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_5cx1jmk7clhq7gdqu8fj +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_625nhhhlou6kji64k1v8 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_8papkqyltk3r9vdbiwlx +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_as4xud3puw1vxjzm8ma3 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_cuw96wvyfzku6np7dv6u +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_eml2za25qr6vmokw5tda +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_f1cpnb605srbgp7u5n6l +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_kcb88g8t6jcdbzy4sf40 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_oziigmt85gb8ro89h2uo +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_rkitlcrj5rur9vtb25yr +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_s24xgsm7sihnsifjqne0 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_v4vq4inppiedkn1mxsut +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_wb62iw0f860zfkjkt42d +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_yb4i2uuaxhoz5hst26bj +0 -0
- metadata +46 -76
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_435onnqlkhcky6yip9mj +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_5a5gcp8rj2g7cjlrh11r +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_5awpjfhldzcfjkeiia3p +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_5n9tm06nu8wtqem8jd9s +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_83yh2jf8w7ouqnuqevws +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_9scoumsixeymou0wyqwf +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_9xq47956uczidwr4xqs2 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_a4mj9799k6k4r6jruzj7 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_a7ev5lal7xp2xzjj2n9p +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_azffwngwstpj3o7g7zaj +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_bsifeckwtz6lhx8rqwgz +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_c27pz5f69skbkwfrnlr5 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_c5lzifpf785aic4t3cm8 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_dbth1ye234719bbg3xjq +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ech68w7azvs6whb6s88w +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_etmdhvrbbmdadc7oyw8q +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_gdb6sz9j5g8pyrobpse2 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_gnj8jwxqjl0ocjfopzmt +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_hzjksutah5t2nkoe5gye +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ijm30kq0c4jrpb5coyiz +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ixj6jdcp3o0pc4vzdjoo +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_l2w9vljbeofwmhmxn9lv +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_m0kxxiow6jlfcjulu02t +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_m2ow1xy7c6tw0f4fj2co +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_meafgmjq07s2xlkm4ney +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_mitzsa7y0lvka04il6an +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_mxejnh24sg011tpzlq7l +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_nlvpu6hg03b8cue75kkc +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ns57exo8aheow6jngknj +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_pq8a5s9f7o747x14bip8 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_pvxfsf8tdy3tk7twydyc +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_t5zt24mkmoq4kpcvvlrp +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_tesee62zyykaxw8dbmq1 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ujpdek4jfp8flbqp7fi3 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_wbiyljqrnox89js4m0at +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ywg973w6dqfz9nuj5qio +0 -0
@@ -11,12 +11,4 @@ module QueryReportFilterHelper
|
|
11
11
|
concat(label_tag options[:placeholder])
|
12
12
|
select_tag name, options_for_select([['', ''], ['true', 'true'], ['false', 'false']], value)
|
13
13
|
end
|
14
|
-
|
15
|
-
def link_to_download_report_pdf
|
16
|
-
link_to t('views.links.pdf'), export_report_url_with_format('pdf'), :target => "_blank"
|
17
|
-
end
|
18
|
-
|
19
|
-
def link_to_download_report_csv
|
20
|
-
link_to t('views.links.csv'), export_report_url_with_format('csv'), :target => "_blank"
|
21
|
-
end
|
22
14
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module QueryReportLinkHelper
|
2
|
+
def link_to_download_report_pdf
|
3
|
+
link_to t('views.links.pdf'), export_report_url_with_format('pdf'), :target => "_blank"
|
4
|
+
end
|
5
|
+
|
6
|
+
def link_to_download_report_csv
|
7
|
+
link_to t('views.links.csv'), export_report_url_with_format('csv'), :target => "_blank"
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<div class="row-fluid">
|
2
|
+
<% report.charts.each_with_index do |chart, i| %>
|
3
|
+
<% chart_id = "chart#{i}" %>
|
4
|
+
<div class="span6">
|
5
|
+
<div id="<%= chart_id %>" style="text-align: center;"></div>
|
6
|
+
</div>
|
7
|
+
<%= render_chart(chart.prepare_visualr, chart_id) %>
|
8
|
+
<% end %>
|
9
|
+
<div class="clearfix"></div>
|
10
|
+
</div>
|
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
<%= render_chart(chart.prepare_visualr, chart_id) %>
|
8
|
-
<% end %>
|
9
|
-
<div class="clearfix"></div>
|
10
|
-
</div>
|
1
|
+
<% if report.has_chart? and report.enable_chart? and report.chart_on_web? %>
|
2
|
+
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
3
|
+
<%= render :partial => "query_report/chart", locals: {report: report} %>
|
4
|
+
<% else %>
|
5
|
+
<br/>
|
6
|
+
<% end %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<% if report.records.size > 0 %>
|
2
|
+
<table class="table table-bordered table-striped">
|
3
|
+
<thead>
|
4
|
+
<% report.columns.each do |column| %>
|
5
|
+
<th><%= sort_link(report.search, column.name) %></th>
|
6
|
+
<% end %>
|
7
|
+
</thead>
|
8
|
+
|
9
|
+
<tbody>
|
10
|
+
<% report.records.each do |record| %>
|
11
|
+
<tr>
|
12
|
+
<% report.columns.each do |column| %>
|
13
|
+
<td><%= record[column.humanize] %></td>
|
14
|
+
<% end %>
|
15
|
+
</tr>
|
16
|
+
<% end %>
|
17
|
+
</tbody>
|
18
|
+
</table>
|
19
|
+
<% else %>
|
20
|
+
<p>No record found</p>
|
21
|
+
<% end %>
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
<%
|
4
|
-
|
1
|
+
<% if report.has_filter? %>
|
2
|
+
<%= search_form_for report.search, :url => url_for, :html => {:method => :get, :class => 'form-inline'} do |f| %>
|
3
|
+
<% report.filters.each do |filter| %>
|
4
|
+
<% filter.comparators.each do |comparator| %>
|
5
|
+
<%= query_report_render_filter(filter, comparator) %>
|
6
|
+
<% end %>
|
5
7
|
<% end %>
|
8
|
+
<%= f.submit 'Search', :class => 'btn btn-blue' %>
|
6
9
|
<% end %>
|
7
|
-
<%= f.submit 'Search', :class => 'btn btn-blue' %>
|
8
10
|
<% end %>
|
@@ -1,14 +1,7 @@
|
|
1
1
|
<%= render :partial => "query_report/search", locals: {report: @report} %>
|
2
2
|
<br/>
|
3
|
-
|
4
|
-
<%=
|
5
|
-
<%= link_to_download_report_csv %>
|
6
|
-
|
7
|
-
<% if @report.has_chart? and @report.enable_chart? and @report.chart_on_web? %>
|
8
|
-
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
9
|
-
<%= render :partial => "query_report/charts", locals: {report: @report} %>
|
10
|
-
<% end %>
|
11
|
-
|
3
|
+
<%= render :partial => "query_report/links", locals: {report: @report} %>
|
4
|
+
<%= render :partial => "query_report/charts", locals: {report: @report} %>
|
12
5
|
<br/>
|
13
6
|
<%# if @report.scopes.size > 0 %>
|
14
7
|
<%#= link_to_with_scope('all', @report.current_scope) %>
|
@@ -16,28 +9,6 @@
|
|
16
9
|
<%#= link_to_with_scope(scope, @report.current_scope) %>
|
17
10
|
<%# end %>
|
18
11
|
<%# end %>
|
19
|
-
<br/>
|
20
|
-
|
21
|
-
<% if @report.records.size > 0 %>
|
22
|
-
<table class="table table-bordered table-striped">
|
23
|
-
<thead>
|
24
|
-
<% @report.columns.each do |column| %>
|
25
|
-
<th><%= sort_link(@report.search, column.name) %></th>
|
26
|
-
<% end %>
|
27
|
-
</thead>
|
28
|
-
|
29
|
-
<tbody>
|
30
|
-
<% @report.records.each do |record| %>
|
31
|
-
<tr>
|
32
|
-
<% @report.columns.each do |column| %>
|
33
|
-
<td><%= record[column.humanize] %></td>
|
34
|
-
<% end %>
|
35
|
-
</tr>
|
36
|
-
<% end %>
|
37
|
-
</tbody>
|
38
|
-
</table>
|
39
|
-
<% else %>
|
40
|
-
<p>No record found</p>
|
41
|
-
<% end %>
|
42
12
|
|
13
|
+
<%= render :partial => "query_report/records", locals: {report: @report} %>
|
43
14
|
<%= paginate @report.paginated_query if @report.paginate? %>
|
data/lib/query_report/filter.rb
CHANGED
@@ -19,38 +19,38 @@ module QueryReport
|
|
19
19
|
@filters << Filter.new(@params, column, options, &block)
|
20
20
|
end
|
21
21
|
|
22
|
+
def has_filter?
|
23
|
+
filters.present?
|
24
|
+
end
|
25
|
+
|
22
26
|
def apply_filters(query, http_params)
|
23
27
|
# apply default filter
|
24
28
|
params = load_default_values_in_param(http_params) #need for ransack filter
|
25
|
-
|
26
29
|
@search = query.search(params[:q])
|
27
30
|
query = @search.result
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
else
|
35
|
-
params[:custom_search][key]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
#filter only if there is a given input
|
39
|
-
query = filter.block.call(query, *ordered_custom_param_values) unless ordered_custom_param_values.all? { |p| p.nil? or p == '' }
|
40
|
-
end
|
32
|
+
#apply custom filter
|
33
|
+
@filters.select(&:custom?).each do |filter|
|
34
|
+
ordered_custom_param_values = ordered_param_value_objects(filter)
|
35
|
+
has_no_user_input = ordered_custom_param_values.all? { |p| p.nil? or p == '' }
|
36
|
+
query = filter.block.call(query, *ordered_custom_param_values) unless has_no_user_input
|
41
37
|
end
|
42
38
|
query
|
43
39
|
end
|
44
40
|
|
41
|
+
def ordered_param_value_objects(filter)
|
42
|
+
filter.comparators.collect do |comp|
|
43
|
+
comp.objectified_param_value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
45
47
|
def load_default_values_in_param(http_params)
|
46
48
|
params = http_params.clone
|
47
49
|
params = params.merge(q: {}) unless params[:q]
|
48
50
|
params = params.merge(custom_search: {}) unless params[:custom_search]
|
49
51
|
@filters.each do |filter|
|
50
|
-
|
51
|
-
filter.
|
52
|
-
params[filter.params_key][comparator.search_key] ||= comparator.default.to_s
|
53
|
-
end
|
52
|
+
filter.comparators.each do |comparator|
|
53
|
+
params[filter.params_key][comparator.search_key] ||= comparator.param_value
|
54
54
|
end
|
55
55
|
end
|
56
56
|
params
|
@@ -60,7 +60,7 @@ module QueryReport
|
|
60
60
|
attr_reader :filter, :type, :name, :default
|
61
61
|
|
62
62
|
def initialize(filter, type, name, default=nil)
|
63
|
-
@filter, @type, @name, @default = filter, type, name, default
|
63
|
+
@filter, @type, @name, @default = filter, type, name, default
|
64
64
|
end
|
65
65
|
|
66
66
|
def search_key
|
@@ -72,12 +72,33 @@ module QueryReport
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def param_value
|
75
|
-
@filter.params[@filter.params_key] ? @filter.params[@filter.params_key][search_key] :
|
75
|
+
@filter.params[@filter.params_key] ? @filter.params[@filter.params_key][search_key] : stringified_default
|
76
76
|
end
|
77
77
|
|
78
78
|
def has_default?
|
79
79
|
!@default.nil?
|
80
80
|
end
|
81
|
+
|
82
|
+
def stringified_default
|
83
|
+
@stringified_default ||= case @filter.type
|
84
|
+
when :date
|
85
|
+
@default.kind_of?(String) ? @default : @default.to_s(:db)
|
86
|
+
else
|
87
|
+
@default.to_s
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#convert param value which is a string to object like date and boolean
|
92
|
+
def objectified_param_value
|
93
|
+
@stringified_default ||= case @filter.type
|
94
|
+
when :date
|
95
|
+
@default.to_date
|
96
|
+
when :boolean
|
97
|
+
@default.to_boolean
|
98
|
+
else
|
99
|
+
@default
|
100
|
+
end
|
101
|
+
end
|
81
102
|
end
|
82
103
|
|
83
104
|
class Filter
|
@@ -88,10 +109,7 @@ module QueryReport
|
|
88
109
|
# +params+:: The params from the http request
|
89
110
|
def initialize(params, column, options, &block)
|
90
111
|
@params, @column, @options, @comparators, @block = params, column, options, [], block
|
91
|
-
@type = options
|
92
|
-
if options.kind_of? Hash
|
93
|
-
@type = options[:type]
|
94
|
-
end
|
112
|
+
@type = options.kind_of?(String) ? options : options[:type]
|
95
113
|
generate_comparators
|
96
114
|
end
|
97
115
|
|
@@ -133,10 +151,10 @@ module QueryReport
|
|
133
151
|
end
|
134
152
|
|
135
153
|
if @options[:comp]
|
136
|
-
@options[:comp].each_with_index do |(
|
154
|
+
@options[:comp].each_with_index do |(ransack_search_key, filter_name), i|
|
137
155
|
default = nil
|
138
|
-
default = @options[:default].kind_of?(Array) ? @options[:default][i] : @options[:default]
|
139
|
-
@comparators << Comparator.new(self,
|
156
|
+
default = @options[:default].kind_of?(Array) ? @options[:default][i] : @options[:default] unless @options[:default].nil?
|
157
|
+
@comparators << Comparator.new(self, ransack_search_key, filter_name, default)
|
140
158
|
end
|
141
159
|
end
|
142
160
|
end
|
data/lib/query_report/helper.rb
CHANGED
@@ -13,26 +13,26 @@ module QueryReport
|
|
13
13
|
@report ||= QueryReport::Report.new(params, view_context, options)
|
14
14
|
@report.query = query
|
15
15
|
@report.instance_eval &block
|
16
|
-
render_report
|
16
|
+
render_report(options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def render_report
|
19
|
+
def render_report(options)
|
20
20
|
respond_to do |format|
|
21
21
|
format.js { render 'query_report/list' }
|
22
22
|
format.html { render 'query_report/list' }
|
23
23
|
format.json { render json: @report.all_records }
|
24
24
|
format.csv { send_data generate_csv_for_report(@report.all_records), :disposition => "attachment;" }
|
25
|
-
format.pdf { send_data query_report_pdf_template_class.new(@report).to_pdf.render }
|
25
|
+
format.pdf { send_data query_report_pdf_template_class(options).new(@report).to_pdf.render }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def query_report_pdf_template_class
|
30
|
-
options = QueryReport.config.pdf_options
|
29
|
+
def query_report_pdf_template_class(options)
|
30
|
+
options = QueryReport.config.pdf_options.merge(options)
|
31
31
|
if options[:template_class]
|
32
32
|
@template_class ||= options[:template_class].to_s.constantize
|
33
33
|
return @template_class
|
34
34
|
end
|
35
|
-
|
35
|
+
QueryReport::ReportPdf
|
36
36
|
end
|
37
37
|
|
38
38
|
def generate_csv_for_report(records)
|
data/lib/query_report/version.rb
CHANGED
@@ -9,8 +9,8 @@ class InvoicesController < ApplicationController
|
|
9
9
|
|
10
10
|
reporter(@invoices) do
|
11
11
|
filter :title, type: :text
|
12
|
-
filter :created_at, type: :date, default: [5.months.ago.to_date
|
13
|
-
filter :paid, type: :boolean
|
12
|
+
filter :created_at, type: :date, default: [5.months.ago.to_date, 1.months.from_now.to_date]
|
13
|
+
filter :paid, type: :boolean, default: false
|
14
14
|
|
15
15
|
column :title do |invoice|
|
16
16
|
link_to invoice.title, invoice
|
@@ -18,25 +18,30 @@ class InvoicesController < ApplicationController
|
|
18
18
|
column :total_paid
|
19
19
|
column :total_charged
|
20
20
|
column :paid
|
21
|
-
|
22
|
-
|
23
|
-
add 'Unpaid' do |query|
|
24
|
-
(query.sum('total_charged').to_f - query.sum('total_paid').to_f).to_f
|
25
|
-
end
|
26
|
-
add 'Paid' do |query|
|
27
|
-
query.sum('total_paid').to_f
|
28
|
-
end
|
21
|
+
column :received_by_id do |invoice|
|
22
|
+
invoice.received_by.name
|
29
23
|
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
25
|
+
#column_chart('Unpaid VS Paid') do
|
26
|
+
# add 'Unpaid' do |query|
|
27
|
+
# (query.sum('total_charged').to_f - query.sum('total_paid').to_f).to_f
|
28
|
+
# end
|
29
|
+
# add 'Paid' do |query|
|
30
|
+
# query.sum('total_paid').to_f
|
31
|
+
# end
|
32
|
+
#end
|
33
|
+
#
|
34
|
+
#pie_chart('Unpaid VS Paid') do
|
35
|
+
# add 'Unpaid' do |query|
|
36
|
+
# (query.sum('total_charged').to_f - query.sum('total_paid').to_f).to_f
|
37
|
+
# end
|
38
|
+
# add 'Paid' do |query|
|
39
|
+
# query.sum('total_paid').to_f
|
40
|
+
# end
|
41
|
+
#end
|
39
42
|
end
|
43
|
+
#ap @report.filters.last.comparators.first.default
|
44
|
+
#ap @report.filters.last.comparators.first.param_value
|
40
45
|
end
|
41
46
|
|
42
47
|
# GET /invoices/1
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -18,15 +18,17 @@ ActiveRecord::Schema.define(:version => 20130630132513) do
|
|
18
18
|
t.float "total_paid"
|
19
19
|
t.float "total_charged"
|
20
20
|
t.boolean "paid"
|
21
|
-
t.
|
22
|
-
t.
|
21
|
+
t.integer "received_by_id"
|
22
|
+
t.date "invoiced_on"
|
23
|
+
t.date "paid_on"
|
24
|
+
t.datetime "created_at", :null => false
|
25
|
+
t.datetime "updated_at", :null => false
|
23
26
|
end
|
24
27
|
|
25
28
|
create_table "users", :force => true do |t|
|
26
|
-
t.string "
|
29
|
+
t.string "first_name"
|
30
|
+
t.string "last_name"
|
27
31
|
t.string "email"
|
28
|
-
t.boolean "single"
|
29
|
-
t.date "dob"
|
30
32
|
t.datetime "created_at", :null => false
|
31
33
|
t.datetime "updated_at", :null => false
|
32
34
|
end
|
data/test/dummy/db/seed.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
User.scoped.destroy_all
|
2
|
+
Invoice.scoped.destroy_all
|
3
|
+
|
4
|
+
users = []
|
5
|
+
users << User.create(first_name: 'A.K.M.', last_name: 'Ashrafuzzaman', email: 'ashraf@gmail.com')
|
6
|
+
users << User.create(first_name: 'A.K.M.', last_name: 'Zahiduzzaman', email: 'zahid@gmail.com')
|
7
|
+
users << User.create(first_name: 'Sharmin', last_name: 'Sultana', email: 'sharmin@gmail.com')
|
8
|
+
|
9
|
+
1.upto(200) do |i|
|
10
|
+
total_paid = 100 + Random.rand(100)
|
11
|
+
total_charged = 100 + Random.rand(100)
|
12
|
+
invoiced_on = Random.rand(30).days.ago
|
13
|
+
Invoice.create!(title: "Invoice ##{i}", total_paid: total_paid, total_charged: total_charged, invoiced_on: invoiced_on,
|
14
|
+
paid: total_paid >= total_charged, received_by_id: users[Random.rand(3)].id)
|
4
15
|
end
|