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 = [],
|
chart: {
|
||||||
seriesCounter = 0,
|
type: 'area'
|
||||||
names = ['Members', 'Associate', 'Basic', 'Total'],
|
},
|
||||||
colors = Highcharts.getOptions().colors;
|
title: null,
|
||||||
|
xAxis: {
|
||||||
$.each(names, function(i, name) {
|
type: 'datetime'
|
||||||
|
},
|
||||||
$.getJSON('/payments/chart.json?name='+ name.toLowerCase(), function(data) {
|
yAxis : [{ // Primary yAxis
|
||||||
|
title : {
|
||||||
seriesOptions[i] = {
|
text: "Income"
|
||||||
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: {
|
|
||||||
},
|
},
|
||||||
|
labels: {
|
||||||
rangeSelector: {
|
format: '${value}'
|
||||||
selected: 1
|
}
|
||||||
|
}, { // Secondary yAxis
|
||||||
|
title : {
|
||||||
|
text: "Members"
|
||||||
},
|
},
|
||||||
|
labels: {
|
||||||
yAxis: {
|
format: '{value}'
|
||||||
labels: {
|
|
||||||
formatter: function() {
|
|
||||||
return '$' + this.value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plotLines: [{
|
|
||||||
value: 0,
|
|
||||||
width: 2,
|
|
||||||
color: 'silver'
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
|
opposite: true
|
||||||
|
}],
|
||||||
|
tooltip: {
|
||||||
|
shared: true,
|
||||||
|
xDateFormat: '%B %Y'
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
area: {
|
||||||
|
stacking: 'normal',
|
||||||
|
lineColor: '#666666',
|
||||||
|
lineWidth: 1,
|
||||||
|
marker: {
|
||||||
|
lineWidth: 1,
|
||||||
|
lineColor: '#666666'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
series: [{
|
||||||
|
name: 'Basic',
|
||||||
|
data: <%= @graph[:basic].to_json %>,
|
||||||
tooltip: {
|
tooltip: {
|
||||||
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
|
valuePrefix: '$'
|
||||||
valueDecimals: 0
|
}
|
||||||
},
|
}, {
|
||||||
|
name: 'Associate',
|
||||||
series: seriesOptions
|
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