Commit 05530124 authored by thejoelinux's avatar thejoelinux

ajout des statistiques de prêts

parent c9268961
......@@ -101,4 +101,21 @@ class Loan extends Record {
$this->is_back = $new_state;
return $GLOBALS["data"]->update($sql);
}
public static function fetch_yearly_stats() {
$datas = "[[";
// SQL SELECT lud_loans
$sql = " SELECT
DATE_FORMAT(start_date, '%Y-%m-15') AS stat_date, COUNT(id) AS loan_count
FROM ".Loan::$table."
WHERE start_date > DATE_SUB(curdate(), interval 13 month)
GROUP BY DATE_FORMAT(start_date, '%Y-%m-15')
ORDER BY start_date";
$GLOBALS["data"]->select($sql, $rset);
do {
$datas .= '["'.$rset->value("stat_date").' 12:00AM", '.$rset->value("loan_count").'],';
} while($rset->nextrow());
return substr($datas, 0, -1)."]]";
}
}
......@@ -16,7 +16,6 @@ class StatisticsController extends AppController {
}
function _list() {
$this->set_val("main_url", "api.php?o=statistics&a=daily_stats");
return "statistics/list";
}
......@@ -30,6 +29,15 @@ class StatisticsController extends AppController {
exit();
}
function _loan_stats() {
try {
echo Loan::fetch_yearly_stats();
} catch(data_exception $e) {
echo "[[]]";
}
exit();
}
function _draw() {
$response = new Record();
$response->draw = intval($_GET["draw"]);
......
/**
* jqPlot
* Pure JavaScript plotting plugin using jQuery
*
* Version: 1.0.0b2_r792
*
* Copyright (c) 2009-2011 Chris Leonello
* jqPlot is currently available for use in all personal or commercial projects
* under both the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL
* version 2.0 (http://www.gnu.org/licenses/gpl-2.0.html) licenses. This means that you can
* choose the license that best suits your project and use it accordingly.
*
* Although not required, the author would appreciate an email letting him
* know of any substantial use of jqPlot. You can reach the author at:
* chris at jqplot dot com or see http://www.jqplot.com/info.php .
*
* If you are feeling kind and generous, consider supporting the project by
* making a donation at: http://www.jqplot.com/donate.php .
*
* sprintf functions contained in jqplot.sprintf.js by Ash Searle:
*
* version 2007.04.27
* author Ash Searle
* http://hexmen.com/blog/2007/03/printf-sprintf/
* http://hexmen.com/js/sprintf.js
* The author (Ash Searle) has placed this code in the public domain:
* "This code is unrestricted: you are free to use it however you like."
*
*/
(function(a){a.jqplot.CanvasAxisTickRenderer=function(b){this.mark="outside";this.showMark=true;this.showGridline=true;this.isMinorTick=false;this.angle=0;this.markSize=4;this.show=true;this.showLabel=true;this.labelPosition="auto";this.label="";this.value=null;this._styles={};this.formatter=a.jqplot.DefaultTickFormatter;this.formatString="";this.prefix="";this.fontFamily='"Trebuchet MS", Arial, Helvetica, sans-serif';this.fontSize="10pt";this.fontWeight="normal";this.fontStretch=1;this.textColor="#666666";this.enableFontSupport=true;this.pt2px=null;this._elem;this._ctx;this._plotWidth;this._plotHeight;this._plotDimensions={height:null,width:null};a.extend(true,this,b);var c={fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily};if(this.pt2px){c.pt2px=this.pt2px}if(this.enableFontSupport){function d(){return !!(document.createElement("canvas").getContext&&typeof document.createElement("canvas").getContext("2d").fillText=="function")}if(d()){this._textRenderer=new a.jqplot.CanvasFontRenderer(c)}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}}else{this._textRenderer=new a.jqplot.CanvasTextRenderer(c)}};a.jqplot.CanvasAxisTickRenderer.prototype.init=function(b){a.extend(true,this,b);this._textRenderer.init({fontSize:this.fontSize,fontWeight:this.fontWeight,fontStretch:this.fontStretch,fillStyle:this.textColor,angle:this.getAngleRad(),fontFamily:this.fontFamily})};a.jqplot.CanvasAxisTickRenderer.prototype.getWidth=function(d){if(this._elem){return this._elem.outerWidth(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.sin(f.angle)*e)+Math.abs(Math.cos(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getHeight=function(d){if(this._elem){return this._elem.outerHeight(true)}else{var f=this._textRenderer;var c=f.getWidth(d);var e=f.getHeight(d);var b=Math.abs(Math.cos(f.angle)*e)+Math.abs(Math.sin(f.angle)*c);return b}};a.jqplot.CanvasAxisTickRenderer.prototype.getAngleRad=function(){var b=this.angle*Math.PI/180;return b};a.jqplot.CanvasAxisTickRenderer.prototype.setTick=function(b,d,c){this.value=b;if(c){this.isMinorTick=true}return this};a.jqplot.CanvasAxisTickRenderer.prototype.draw=function(c,f){if(!this.label){this.label=this.prefix+this.formatter(this.formatString,this.value)}if(this._elem){if(a.jqplot.use_excanvas){window.G_vmlCanvasManager.uninitElement(this._elem.get(0))}this._elem.emptyForce();this._elem=null}var e=f.canvasManager.getCanvas();this._textRenderer.setText(this.label,c);var b=this.getWidth(c);var d=this.getHeight(c);e.width=b;e.height=d;e.style.width=b;e.style.height=d;e.style.textAlign="left";e.style.position="absolute";e=f.canvasManager.initCanvas(e);this._elem=a(e);this._elem.css(this._styles);this._elem.addClass("jqplot-"+this.axis+"-tick");e=null;return this._elem};a.jqplot.CanvasAxisTickRenderer.prototype.pack=function(){this._textRenderer.draw(this._elem.get(0).getContext("2d"),this.label)}})(jQuery);
\ No newline at end of file
This diff is collapsed.
......@@ -13,7 +13,20 @@
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">Nombre d'emprunts (12 derniers mois)</h4>
</div>
<div class="panel-body">
<div id="loan_chart" style="height:200px;width:500px;"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel panel-primary">
......@@ -39,12 +52,13 @@
</div>
</div>
</div>
<script src="js/jquery.jqplot.min.js"></script>
<script src="js/plugins/jqplot.json2.min.js"></script>
<script src="js/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script src="js/plugins/jqplot.barRenderer.min.js"></script>
<script src="js/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script src="js/plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
<script src="js/plugins/jqplot.canvasTextRenderer.min.js"></script>
<script>
$(document).ready(function() {
......@@ -94,7 +108,7 @@ $(document).ready(function() {
};
// The url for our json data
var main_url = "{{ main_url | raw }}";
var main_url = "api.php?o=statistics&a=daily_stats";
var main_plot = $.jqplot('main_chart', main_url, {
axes:{
......@@ -110,6 +124,29 @@ $(document).ready(function() {
dataRenderer: ajaxDataRenderer,
series:[{lineWidth:2}]
});
var loan_url = "api.php?o=statistics&a=loan_stats";
var loan_plot = $.jqplot('loan_chart', loan_url, {
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickInterval:'1 months',
tickOptions: {
angle: -30
}
},
yaxis:{
label:'Emprunts',
min:0
}
},
dataRenderer: ajaxDataRenderer,
series:[{lineWidth:2}]
});
});
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment