-
Notifications
You must be signed in to change notification settings - Fork 0
/
santerre.js
executable file
·131 lines (121 loc) · 4.27 KB
/
santerre.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
$(function() {
$("button").button();
$("#li_nb_jours_last").hide();
$("#dateRevele").datepicker({
showButtonPanel: true,
defaultDate: 0
});
$("#add-dialog").dialog( {
autoOpen: false,
modal: true,
title: 'Ajouter un relevé',
buttons: {
"Enregistrer" : function () {
var fields = $(":input").serializeArray();
$.ajax({
url: 'save.php',
data: fields,
success: function () {
$( "#add-dialog" ).dialog( "close" );
refresh();
}
});
},
cancel: function () {
$( this ).dialog( "close" );
}
}
});
$("#add").click(function() {
$("#add-dialog").dialog('open');
});
$("#panel-add-submit").click(function() {
$("#add-dialog").dialog('close');
});
function round(val) {
return (typeof(val) == "undefined" || val == null ? " ": $.formatNumber(val,{locale:"fr"}));
}
function nvl(val, newval) {
return (val == null? newval: val);
}
var list_releves = [];
var points_week = [], points_total= [], points_jardinier = [];
function prix() {
$.ajax({
url: 'prix.php',
success: function (data) {
data = data[0];
var v_to_end = (list_releves[0].vafter*1)+list_releves[0].v_par_time*data.toend;;
points_total.push([Date.parseString(nvl(data.end," "),'yyyy-MM-dd').getTime(), v_to_end]);
var gtotal = $("#gtotal");
var plot = $.plot(gtotal, [{label:"Volume",data:points_total}], { xaxis: { mode: "time",
monthNames: months } });
o = plot.pointOffset({ x: Date.parseString(nvl(list_releves[list_releves.length-1].dafter," "),'yyyy-MM-dd').getTime(), y: v_to_end});
gtotal.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Mesuré</div>');
o = plot.pointOffset({ x: Date.parseString(nvl(list_releves[0].dafter," "),'yyyy-MM-dd').getTime(), y: v_to_end});
gtotal.append('<div style="position:absolute;left:' + (o.left + 4) + 'px;top:' + o.top + 'px;color:#666;font-size:smaller">Prévisions</div>');
var ctx = plot.getCanvas().getContext("2d");
ctx.beginPath();
o.left += 4;
ctx.moveTo(o.left, o.top);
ctx.lineTo(o.left, o.top - 10);
ctx.lineTo(o.left + 10, o.top - 5);
ctx.lineTo(o.left, o.top);
ctx.fillStyle = "#000";
ctx.fill();
v_to_end = $.formatNumber(v_to_end,{locale:"fr"});
$("#v_to_end").text( v_to_end);
if (list_releves[0].nb_jours_last<-7) {
$("#nb_jours_last").text(-list_releves[0].nb_jours_last);
$("#li_nb_jours_last").show();
}
}
});
}
var months = ["Jan","Fev","Mar","Avr","Mai","Juin", "Juil", "Aout", "Sept", "Oct", "Nov", "Dec"];
function refresh() {
$.ajax({
url: 'list.php',
success: function (data) {
list_releves = data;
$("#table_content").empty();
for(line in data) {
data[line].ddiff = nvl(data[line].ddiff,0);
data[line].vdiff = nvl(data[line].vdiff,0);
if (data[line].ddiff != 0) {
var v_par_time = data[line].vdiff / data[line].ddiff;
data[line].v_par_time =v_par_time;
}
points_total.unshift([Date.parseString(nvl(data[line].dafter," "),'yyyy-MM-dd').getTime(), Math.round(data[line].vafter)]);
points_week.unshift([Date.parseString(nvl(data[line].dafter," "),'yyyy-MM-dd').getTime(), Math.round(data[line].v_par_time)]);
points_jardinier.unshift([Date.parseString(nvl(data[line].dafter," "),'yyyy-MM-dd').getTime(), Math.round(data[line].v_par_time/46)]);
$("#table_content").append(
"<tr>"+
"<td>"+Date.parseString(nvl(data[line].dafter," "),'yyyy-MM-dd').format('dd/MM/yy')+"</td>"+
"<td class='numeric'>"+round(data[line].vafter)+"</td>"+
"<td class='numeric'>"+round(v_par_time)+"</td>"+
"<td class='numeric'>"+ round(v_par_time/46)+"</td>"+
"<td class='numeric'>"+round(v_par_time/46/4.5)+"</td>"+
"</tr>");
}
$.plot($("#gweek"), [{label:"Consommation",data:points_week}],
{
xaxis: {
mode: "time" ,
monthNames: months,
timeformat: "%d %b"
},
yaxis: {min: 0}
});
$.plot($("#gjardinier"), [{label:"Par co-jardinier",data:points_jardinier}], { xaxis: { mode: "time",
monthNames: months,
timeformat: "%d %b"}, yaxis: {min: 0} });
prix();
}
});
}
$("#refresh").click(function() {
refresh();
});
refresh();
});