Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added google chart to admin dashboard and ensured barcode generation …

…is unique to each transaction created
  • Loading branch information...
commit 7d988230f6065bd5a9988642b007d5869f6d005c 1 parent 966c80b
@bsodmike authored
View
7 app/models/transaction.rb
@@ -9,7 +9,8 @@ class Transaction < ActiveRecord::Base
attr_accessor :amount
validates_presence_of :customer_id
- validates_presence_of :online_shop_id
+ validates_presence_of :online_shop_id
+ validates :barcode, :uniqueness => true
validates :amount, :numericality => true
def set_due_date
@@ -17,7 +18,9 @@ def set_due_date
end
def generate_barcode
- self.barcode = "%013d" % Random.new.rand((10 ** 12)...(10 ** 13)) # save as string in DB
+ begin
+ self.barcode = "%013d" % Random.new.rand((10 ** 12)...(10 ** 13))
+ end while Transaction.exists?(:barcode => self.barcode)
end
def amount_to_cents
View
23 app/views/admin/dashboard/index.html.erb
@@ -1,3 +1,25 @@
+<% content_for :head do %>
+<script type="text/javascript" src="https://www.google.com/jsapi"></script>
+<script type="text/javascript">
+ google.load("visualization", "1", {packages:["corechart"]});
+ google.setOnLoadCallback(drawChart);
+ function drawChart() {
+ var data = new google.visualization.DataTable();
+ data.addColumn('string', 'Transaction Status');
+ data.addColumn('number', 'Count');
+ data.addRows(3);
+ data.setValue(0, 0, 'Pending');
+ data.setValue(0, 1, <%= Transaction.where(:state => "pending").count %>);
+ data.setValue(1, 0, 'Done');
+ data.setValue(1, 1, <%= Transaction.where(:state => "done").count %>);
+ data.setValue(2, 0, 'Cancelled');
+ data.setValue(2, 1, <%= Transaction.where(:state => "cancelled").count %>);
+
+ var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
+ chart.draw(data, {width: 450, height: 300, title: 'Transactions Overview as Percentage'});
+ }
+</script>
+<% end %>
<h1>Zahlbar Admin Dashboard ~ <%= %w[Willkommen Welcome].sample %>!</h1>
<br/>
@@ -22,4 +44,5 @@
</tbody>
</table>
</div>
+ <div class="span6" id="chart_div"></div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.