Ajout graphes CA par clients
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,4 +4,4 @@
|
||||
*.pyc
|
||||
*.pid
|
||||
*.log
|
||||
|
||||
development.ini
|
||||
|
||||
@@ -59,7 +59,7 @@ def get_ca_groupe_12m(request, societe, datedeb, datefin):
|
||||
SUM(IF(groupe = 'MAIF', 1, 0)) AS MAIF_nb
|
||||
FROM bddevfac.facture
|
||||
WHERE societe=:societe and date >= :datedeb and date <= :datefin GROUP BY yymm;"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'datedeb': datedeb.strftime("%Y%m"), 'datefin': datefin.strftime("%Y%m")})
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'datedeb': datedeb.strftime("%Y-%m"), 'datefin': datefin.strftime("%Y-%m")})
|
||||
return results.fetchall()
|
||||
|
||||
def get_ca_groupe_3y(request, societe, datedeb):
|
||||
@@ -69,10 +69,53 @@ def get_ca_groupe_3y(request, societe, datedeb):
|
||||
|
||||
query = """SELECT groupe,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-2, TOTALHT, 0)) as Annee1,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-2, 1, 0)) as Count1,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-1, TOTALHT, 0)) as Annee2,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n, TOTALHT, 0)) as Annee3
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-1, 1, 0)) as Count2,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n, TOTALHT, 0)) as Annee3,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n, 1, 0)) as Count3
|
||||
FROM bddevfac.facture
|
||||
WHERE societe=:societe GROUP BY groupe;"""
|
||||
WHERE societe=:societe AND groupe <> 'X' GROUP BY groupe;"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'date_n': date3.strftime("%Y"), 'date_n-1': date2.strftime("%Y"), 'date_n': datedeb.strftime("%Y")})
|
||||
return results.fetchall()
|
||||
|
||||
def get_ca_clients_12m(request, societe, datedeb, datefin):
|
||||
|
||||
query = """SELECT DATE_FORMAT(date, "%Y%m") as yymm,
|
||||
DATE_FORMAT(date, "%M") as mois,
|
||||
DATE_FORMAT(date, "%M %Y") as date,
|
||||
SUM(IF(typecli = 'A', totalht, 0)) AS A_ca,
|
||||
SUM(IF(typecli = 'A', 1, 0)) AS A_nb,
|
||||
SUM(IF(typecli = 'E', totalht, 0)) AS E_ca,
|
||||
SUM(IF(typecli = 'E', 1, 0)) AS E_nb,
|
||||
SUM(IF(typecli = 'G', totalht, 0)) AS G_ca,
|
||||
SUM(IF(typecli = 'G', 1, 0)) AS G_nb,
|
||||
SUM(IF(typecli = 'I', totalht, 0)) AS I_ca,
|
||||
SUM(IF(typecli = 'I', 1, 0)) AS I_nb,
|
||||
SUM(IF(typecli = 'P', totalht, 0)) AS P_ca,
|
||||
SUM(IF(typecli = 'P', 1, 0)) AS P_nb,
|
||||
SUM(IF(typecli = 'R', totalht, 0)) AS R_ca,
|
||||
SUM(IF(typecli = 'R', 1, 0)) AS R_nb,
|
||||
SUM(IF(typecli = 'S', totalht, 0)) AS S_ca,
|
||||
SUM(IF(typecli = 'S', 1, 0)) AS S_nb
|
||||
FROM bddevfac.facture
|
||||
WHERE societe=:societe and date >= :datedeb and date <= :datefin GROUP BY yymm;"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'datedeb': datedeb.strftime("%Y-%m"), 'datefin': datefin.strftime("%Y-%m")})
|
||||
return results.fetchall()
|
||||
|
||||
def get_ca_clients_3y(request, societe, datedeb):
|
||||
|
||||
date2 = datedeb + relativedelta(years=-1)
|
||||
date3 = datedeb + relativedelta(years=-2)
|
||||
|
||||
query = """SELECT typecli,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-2, TOTALHT, 0)) as Annee1,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-2, 1, 0)) as Count1,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-1, TOTALHT, 0)) as Annee2,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n-1, 1, 0)) as Count2,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n, TOTALHT, 0)) as Annee3,
|
||||
SUM(IF (date_format(date, '%Y') = :date_n, 1, 0)) as Count3
|
||||
FROM bddevfac.facture
|
||||
WHERE societe=:societe GROUP BY typecli;"""
|
||||
results = request.dbsession.execute(query, {'societe': societe, 'date_n': date3.strftime("%Y"), 'date_n-1': date2.strftime("%Y"), 'date_n': datedeb.strftime("%Y")})
|
||||
return results.fetchall()
|
||||
|
||||
@@ -77,7 +77,9 @@ def includeme(config):
|
||||
config.add_route('stats', '/stats')
|
||||
config.add_route('stats_dossiers', '/stats_dossiers/{societe}')
|
||||
config.add_route('stats_delais', '/stats_delais/{societe}')
|
||||
config.add_route('ca_groupes_12m', '/ca_groupes_12m/{societe}')
|
||||
config.add_route('ca_groupes', '/ca_groupes/{societe}')
|
||||
config.add_route('ca_clients', '/ca_clients/{societe}')
|
||||
|
||||
# utils
|
||||
config.add_route('batch_nuit', '/batch_nuit/{param}')
|
||||
config.add_route('batch_test', '/batch_test/{param}')
|
||||
|
||||
89
mondumas/templates/stats/ca_clients.pt
Normal file
89
mondumas/templates/stats/ca_clients.pt
Normal file
@@ -0,0 +1,89 @@
|
||||
<metal:block use-macro="main_template">
|
||||
<div metal:fill-slot="content">
|
||||
|
||||
<br />
|
||||
<div class="row">
|
||||
<form method="POST" id="frm" class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2">Societe</label>
|
||||
<div class="col-sm-4">
|
||||
<select class="form-control" id="societe" name="societe" onChange="$('#frm').submit()">
|
||||
<tal:block tal:repeat="item societes">
|
||||
<option value="${item}" tal:attributes="selected societe==item and 'selected' or None"> ${item}</option>
|
||||
</tal:block>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Histogramme CA sur 12 mois par clients -->
|
||||
<div id="chart_ca_12m" style="width: 100%; height: 500px;"></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- camembert 1 -->
|
||||
<div class="col-sm-4">
|
||||
<div id="chart_ca_3y_1" style="width: 100%; height: 500px;"></div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div id="chart_ca_3y_2" style="width: 100%; height: 500px;"></div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div id="chart_ca_3y_3" style="width: 100%; height: 500px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||
<script type="text/javascript">
|
||||
google.charts.load("current", {packages:["corechart"]});
|
||||
google.charts.setOnLoadCallback(drawChart);
|
||||
var dataSet_ca_12m = ${chart_ca_12m};
|
||||
|
||||
var dataSet_ca_3y_1 = ${chart_ca_3y_1};
|
||||
var dataSet_ca_3y_2 = ${chart_ca_3y_2};
|
||||
var dataSet_ca_3y_3 = ${chart_ca_3y_3};
|
||||
|
||||
function drawChart() {
|
||||
var data_ca_12m = google.visualization.arrayToDataTable(dataSet_ca_12m);
|
||||
|
||||
var data_ca_3y_1 = google.visualization.arrayToDataTable(dataSet_ca_3y_1);
|
||||
var data_ca_3y_2 = google.visualization.arrayToDataTable(dataSet_ca_3y_2);
|
||||
var data_ca_3y_3 = google.visualization.arrayToDataTable(dataSet_ca_3y_3);
|
||||
|
||||
var options_ca_12m = {
|
||||
title: '${title}',
|
||||
vAxis: {title: "Chiffre d'Affaires en €"},
|
||||
isStacked: true
|
||||
};
|
||||
|
||||
var options_ca_3y_1 = {
|
||||
title: '${title1}',
|
||||
};
|
||||
|
||||
var options_ca_3y_2 = {
|
||||
title: '${title2}',
|
||||
};
|
||||
|
||||
var options_ca_3y_3 = {
|
||||
title: '${title3}',
|
||||
};
|
||||
|
||||
var chart_ca_12m = new google.visualization.SteppedAreaChart(document.getElementById('chart_ca_12m'));
|
||||
chart_ca_12m.draw(data_ca_12m, options_ca_12m);
|
||||
|
||||
var chart_ca_3y_1 = new google.visualization.PieChart(document.getElementById('chart_ca_3y_1'));
|
||||
chart_ca_3y_1.draw(data_ca_3y_1, options_ca_3y_1);
|
||||
var chart_ca_3y_2 = new google.visualization.PieChart(document.getElementById('chart_ca_3y_2'));
|
||||
chart_ca_3y_2.draw(data_ca_3y_2, options_ca_3y_2);
|
||||
var chart_ca_3y_3 = new google.visualization.PieChart(document.getElementById('chart_ca_3y_3'));
|
||||
chart_ca_3y_3.draw(data_ca_3y_3, options_ca_3y_3);
|
||||
}
|
||||
</script>
|
||||
|
||||
</div><!-- content -->
|
||||
</metal:block>
|
||||
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
</div>
|
||||
<div class="row text-center">
|
||||
<div class="col-sm-3">
|
||||
<a href="${request.application_url}/ca_groupes_12m/PE" tal:condition="access > 0">
|
||||
<a href="${request.application_url}/ca_groupes/PE" tal:condition="access > 0">
|
||||
<span class="glyphicon glyphicon-equalizer logo-warning"></span>
|
||||
<h4>CA GROUPES</h4></a>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<a href="${request.application_url}/ca_clients/PE" tal:condition="access > 0">
|
||||
<span class="glyphicon glyphicon-equalizer logo-warning"></span>
|
||||
<h4>CA CLIENTS</h4></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -155,13 +155,14 @@ def stats_delais(request):
|
||||
'groupe': groupe,
|
||||
}
|
||||
|
||||
@view_config(route_name='ca_groupes_12m', renderer='../templates/stats/ca_groupes_12m.pt', permission='view')
|
||||
def ca_groupes_12m(request):
|
||||
@view_config(route_name='ca_groupes', renderer='../templates/stats/ca_groupes.pt', permission='view')
|
||||
def ca_groupes(request):
|
||||
|
||||
societe = request.matchdict['societe']
|
||||
url = request.route_url('stats_delais', societe = societe)
|
||||
url = request.route_url('ca_groupes', societe = societe)
|
||||
|
||||
datefin = date.today()
|
||||
datefin.replace(day=1)
|
||||
# debut = aujourd'hui - 11 mois
|
||||
datedeb = datefin + relativedelta(months=-11)
|
||||
|
||||
@@ -172,6 +173,7 @@ def ca_groupes_12m(request):
|
||||
|
||||
# lire les CA par mois
|
||||
items = get_ca_groupe_12m(request, societe, datedeb, datefin)
|
||||
print(datedeb)
|
||||
chart_ca_12m = []
|
||||
# titre des colonnes
|
||||
chart_ca_12m.append(('Mois', 'AXA', { 'type':'string','role': 'tooltip'}, 'MAIF', { 'type':'string','role': 'tooltip'}))
|
||||
@@ -194,22 +196,105 @@ def ca_groupes_12m(request):
|
||||
chart_ca_3y_2 = []
|
||||
chart_ca_3y_3 = []
|
||||
# titre des colonnes
|
||||
chart_ca_3y_1.append(('Groupe', 'CA'))
|
||||
chart_ca_3y_2.append(('Groupe', 'CA'))
|
||||
chart_ca_3y_3.append(('Groupe', 'CA'))
|
||||
chart_ca_3y_1.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
chart_ca_3y_2.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
chart_ca_3y_3.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
title1 = 'CA ' + (datedeb + relativedelta(years=-2)).strftime("%Y")
|
||||
title2 = 'CA ' + (datedeb + relativedelta(years=-1)).strftime("%Y")
|
||||
title3 = 'CA ' + datedeb.strftime("%Y")
|
||||
for item in items:
|
||||
# construire la liste pour donut cible
|
||||
#tooltipMAIF = item.date + ' \nCA: '+str(item.MAIF_ca) + ' €\nDossiers: '+str(round(item.MAIF_nb))
|
||||
#tooltipAXA = item.date + ' \nCA: '+str(item.AXA_ca) + ' €\nDossiers: '+str(round(item.AXA_nb))
|
||||
tooltip_y1 = item.groupe + ' \nCA: '+str(item.Annee1) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
tooltip_y2 = item.groupe + ' \nCA: '+str(item.Annee2) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
tooltip_y3 = item.groupe + ' \nCA: '+str(item.Annee3) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
# ('+str(item.population)+')/n'
|
||||
d1 = (item.groupe, float(item.Annee1))
|
||||
d1 = (item.groupe, float(item.Annee1), tooltip_y1)
|
||||
chart_ca_3y_1.append(d1)
|
||||
d2 = (item.groupe, float(item.Annee2))
|
||||
d2 = (item.groupe, float(item.Annee2), tooltip_y2)
|
||||
chart_ca_3y_2.append(d2)
|
||||
d3 = (item.groupe, float(item.Annee3))
|
||||
d3 = (item.groupe, float(item.Annee3), tooltip_y3)
|
||||
chart_ca_3y_3.append(d3)
|
||||
|
||||
return {
|
||||
'page_title': "CA par groupe",
|
||||
'url': url,
|
||||
'chart_ca_12m': json.dumps(chart_ca_12m),
|
||||
'chart_ca_3y_1': json.dumps(chart_ca_3y_1),
|
||||
'chart_ca_3y_2': json.dumps(chart_ca_3y_2),
|
||||
'chart_ca_3y_3': json.dumps(chart_ca_3y_3),
|
||||
'title': title,
|
||||
'title1': title1,
|
||||
'title2': title2,
|
||||
'title3': title3,
|
||||
'societes': societes,
|
||||
'societe': societe,
|
||||
}
|
||||
|
||||
@view_config(route_name='ca_clients', renderer='../templates/stats/ca_clients.pt', permission='view')
|
||||
def ca_clients(request):
|
||||
|
||||
societe = request.matchdict['societe']
|
||||
url = request.route_url('ca_clients', societe = societe)
|
||||
|
||||
datefin = date.today()
|
||||
# debut = aujourd'hui - 11 mois
|
||||
datedeb = datefin + relativedelta(months=-11)
|
||||
|
||||
societes = ['PE','ME','PL']
|
||||
# si societe a été changé par le user
|
||||
if 'societe' in request.params:
|
||||
societe = request.params["societe"]
|
||||
|
||||
# lire les CA par mois
|
||||
items = get_ca_clients_12m(request, societe, datedeb, datefin)
|
||||
print(datedeb)
|
||||
chart_ca_12m = []
|
||||
# titre des colonnes
|
||||
chart_ca_12m.append(('Mois', 'A', { 'type':'string','role': 'tooltip'}, 'E', { 'type':'string','role': 'tooltip'},
|
||||
'G', { 'type':'string','role': 'tooltip'}, 'I', { 'type':'string','role': 'tooltip'}, 'P', { 'type':'string','role': 'tooltip'},
|
||||
'R', { 'type':'string','role': 'tooltip'}, 'S', { 'type':'string','role': 'tooltip'}))
|
||||
title = 'CA / MOIS'
|
||||
for item in items:
|
||||
# construire la liste pour donut cible
|
||||
tooltipA = item.date + ' \nCA: '+str(item.A_ca) + ' €\nDossiers: '+str(round(item.A_nb))
|
||||
tooltipE = item.date + ' \nCA: '+str(item.E_ca) + ' €\nDossiers: '+str(round(item.E_nb))
|
||||
tooltipG = item.date + ' \nCA: '+str(item.G_ca) + ' €\nDossiers: '+str(round(item.G_nb))
|
||||
tooltipI = item.date + ' \nCA: '+str(item.I_ca) + ' €\nDossiers: '+str(round(item.I_nb))
|
||||
tooltipP = item.date + ' \nCA: '+str(item.P_ca) + ' €\nDossiers: '+str(round(item.P_nb))
|
||||
tooltipR = item.date + ' \nCA: '+str(item.R_ca) + ' €\nDossiers: '+str(round(item.R_nb))
|
||||
tooltipS = item.date + ' \nCA: '+str(item.S_ca) + ' €\nDossiers: '+str(round(item.S_nb))
|
||||
# ('+str(item.population)+')/n'
|
||||
d = (item.mois, float(item.A_ca), tooltipA, float(item.E_ca), tooltipE, float(item.G_ca), tooltipG,
|
||||
float(item.I_ca), tooltipI, float(item.P_ca), tooltipP, float(item.R_ca), tooltipR, float(item.S_ca), tooltipS)
|
||||
chart_ca_12m.append(d)
|
||||
|
||||
# debut = aujourd'hui - 11 mois
|
||||
datedeb = date.today()
|
||||
datedeb.replace(month=1,day=1)
|
||||
|
||||
# lire les CA par mois
|
||||
items = get_ca_clients_3y(request, societe, datedeb)
|
||||
chart_ca_3y_1 = []
|
||||
chart_ca_3y_2 = []
|
||||
chart_ca_3y_3 = []
|
||||
# titre des colonnes
|
||||
chart_ca_3y_1.append(('Clients', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
chart_ca_3y_2.append(('Clients', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
chart_ca_3y_3.append(('Clients', 'CA', { 'type':'string','role': 'tooltip'}))
|
||||
title1 = 'CA ' + (datedeb + relativedelta(years=-2)).strftime("%Y")
|
||||
title2 = 'CA ' + (datedeb + relativedelta(years=-1)).strftime("%Y")
|
||||
title3 = 'CA ' + datedeb.strftime("%Y")
|
||||
for item in items:
|
||||
# construire la liste pour donut cible
|
||||
tooltip_y1 = item.typecli + ' \nCA: '+str(item.Annee1) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
tooltip_y2 = item.typecli + ' \nCA: '+str(item.Annee2) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
tooltip_y3 = item.typecli + ' \nCA: '+str(item.Annee3) + ' €\nDossiers: '+str(round(item.Count1))
|
||||
# ('+str(item.population)+')/n'
|
||||
d1 = (item.typecli, float(item.Annee1), tooltip_y1)
|
||||
chart_ca_3y_1.append(d1)
|
||||
d2 = (item.typecli, float(item.Annee2), tooltip_y2)
|
||||
chart_ca_3y_2.append(d2)
|
||||
d3 = (item.typecli, float(item.Annee3), tooltip_y3)
|
||||
chart_ca_3y_3.append(d3)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user