Updating payment graph
This commit is contained in:
parent
16e5e8d584
commit
5acb3cd272
|
@ -16,6 +16,10 @@ class PaymentsController < ApplicationController
|
||||||
# GET /payments.json
|
# GET /payments.json
|
||||||
def index
|
def index
|
||||||
@payments = @payments.order("date DESC")
|
@payments = @payments.order("date DESC")
|
||||||
|
@graph = { :members => chart("members"),
|
||||||
|
:total => chart("total"),
|
||||||
|
:basic => chart("basic"),
|
||||||
|
:associate => chart("associate")}
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
|
@ -23,8 +27,9 @@ class PaymentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def chart
|
# Private method for index charts
|
||||||
chart_name = params[:name] || "total"
|
def chart name
|
||||||
|
chart_name = name || "total"
|
||||||
if chart_name == "total"
|
if chart_name == "total"
|
||||||
chart_type = [25, 50, 100]
|
chart_type = [25, 50, 100]
|
||||||
elsif chart_name == "members"
|
elsif chart_name == "members"
|
||||||
|
@ -58,10 +63,7 @@ class PaymentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
return @payments_by_month
|
||||||
format.html # index.html.erb
|
|
||||||
format.json { render :json => @payments_by_month }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def amount_or_level p
|
def amount_or_level p
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||||
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
|
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
|
||||||
<script src="highstock/js/highstock.js"></script>
|
<script src="http://code.highcharts.com/highcharts.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
|
@ -14,64 +14,65 @@ $(function() {
|
||||||
$( "#graph" ).dialog( "open" );
|
$( "#graph" ).dialog( "open" );
|
||||||
});
|
});
|
||||||
|
|
||||||
var seriesOptions = [],
|
$('#graph').highcharts({
|
||||||
yAxisOptions = [],
|
|
||||||
seriesCounter = 0,
|
|
||||||
names = ['Members', 'Associate', 'Basic', 'Total'],
|
|
||||||
colors = Highcharts.getOptions().colors;
|
|
||||||
|
|
||||||
$.each(names, function(i, name) {
|
|
||||||
|
|
||||||
$.getJSON('/payments/chart.json?name='+ name.toLowerCase(), function(data) {
|
|
||||||
|
|
||||||
seriesOptions[i] = {
|
|
||||||
name: name,
|
|
||||||
data: data
|
|
||||||
};
|
|
||||||
|
|
||||||
// As we're loading the data asynchronously, we don't know what order it will arrive. So
|
|
||||||
// we keep a counter and create the chart when all the data is loaded.
|
|
||||||
seriesCounter++;
|
|
||||||
|
|
||||||
if (seriesCounter == names.length) {
|
|
||||||
createChart();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// create the chart when all data is loaded
|
|
||||||
function createChart() {
|
|
||||||
$('#graph').highcharts('StockChart', {
|
|
||||||
chart: {
|
chart: {
|
||||||
|
type: 'area'
|
||||||
},
|
},
|
||||||
|
title: null,
|
||||||
rangeSelector: {
|
xAxis: {
|
||||||
selected: 1
|
type: 'datetime'
|
||||||
|
},
|
||||||
|
yAxis : [{ // Primary yAxis
|
||||||
|
title : {
|
||||||
|
text: "Income"
|
||||||
},
|
},
|
||||||
|
|
||||||
yAxis: {
|
|
||||||
labels: {
|
labels: {
|
||||||
formatter: function() {
|
format: '${value}'
|
||||||
return '$' + this.value;
|
|
||||||
}
|
}
|
||||||
|
}, { // Secondary yAxis
|
||||||
|
title : {
|
||||||
|
text: "Members"
|
||||||
},
|
},
|
||||||
plotLines: [{
|
labels: {
|
||||||
value: 0,
|
format: '{value}'
|
||||||
width: 2,
|
|
||||||
color: 'silver'
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
|
opposite: true
|
||||||
|
}],
|
||||||
tooltip: {
|
tooltip: {
|
||||||
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
|
shared: true,
|
||||||
valueDecimals: 0
|
xDateFormat: '%B %Y'
|
||||||
},
|
},
|
||||||
|
plotOptions: {
|
||||||
series: seriesOptions
|
area: {
|
||||||
});
|
stacking: 'normal',
|
||||||
|
lineColor: '#666666',
|
||||||
|
lineWidth: 1,
|
||||||
|
marker: {
|
||||||
|
lineWidth: 1,
|
||||||
|
lineColor: '#666666'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
series: [{
|
||||||
|
name: 'Basic',
|
||||||
|
data: <%= @graph[:basic].to_json %>,
|
||||||
|
tooltip: {
|
||||||
|
valuePrefix: '$'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
name: 'Associate',
|
||||||
|
data: <%= @graph[:associate].to_json %>,
|
||||||
|
tooltip: {
|
||||||
|
valuePrefix: '$'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
yAxis: 1,
|
||||||
|
type: 'spline',
|
||||||
|
name: 'Members',
|
||||||
|
data: <%= @graph[:members].to_json %>
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -7,7 +7,6 @@ Dooraccess::Application.routes.draw do
|
||||||
resources :paypal_csvs
|
resources :paypal_csvs
|
||||||
match 'paypal_csvs/:id/link' => 'paypal_csvs#link', :as => :link_paypal_csv
|
match 'paypal_csvs/:id/link' => 'paypal_csvs#link', :as => :link_paypal_csv
|
||||||
|
|
||||||
match 'payments/chart' => 'payments#chart', :as => :chart_payments
|
|
||||||
resources :payments
|
resources :payments
|
||||||
|
|
||||||
resources :user_certifications
|
resources :user_certifications
|
||||||
|
|
Loading…
Reference in New Issue
Block a user