diff --git a/development.ini b/development.ini index 43f1ab5..0af0f28 100644 --- a/development.ini +++ b/development.ini @@ -19,7 +19,7 @@ pyramid.includes = pyramid_tm -sqlalchemy.url = mysql://phuoc:phuoc!@localhost/bddevfac?charset=utf8 +sqlalchemy.url = mysql://root:anan00@localhost/bddevfac?charset=utf8 # sqlalchemy.url = mysql://phuoc:phuoc!@192.168.1.17/bddevfac?charset=utf8 # sqlalchemy.url = mysql://phuoc:phuoc!@192.168.0.31/bddevfac?charset=utf8 diff --git a/mondumas/models/stats.py b/mondumas/models/stats.py index 7833361..64e8937 100644 --- a/mondumas/models/stats.py +++ b/mondumas/models/stats.py @@ -82,6 +82,20 @@ def get_ca_groupe_3y(request, societe, year): results = request.dbsession.execute(query, {'societe': societe, 'year': year}) return results.fetchall() +def get_ca_groupe_3y_with_others(request, societe, year): + + query = """SELECT groupe, + SUM(IF (year(date) = :year - 2, TOTALHT, 0)) as Annee1, + SUM(IF (year(date) = :year - 2, 1, 0)) as Count1, + SUM(IF (year(date) = :year - 1, TOTALHT, 0)) as Annee2, + SUM(IF (year(date) = :year - 1, 1, 0)) as Count2, + SUM(IF (year(date) = :year, TOTALHT, 0)) as Annee3, + SUM(IF (year(date) = :year, 1, 0)) as Count3 + FROM bddevfac.facture + WHERE societe=:societe AND year(date) >= :year - 2 AND typecli <> 'I' GROUP BY groupe;""" + results = request.dbsession.execute(query, {'societe': societe, 'year': year}) + return results.fetchall() + def get_ca_clients_12m(request, societe, datedeb, datefin): query = """SELECT DATE_FORMAT(date, "%Y%m") as yymm, diff --git a/mondumas/templates/stats/ca_groupes.pt b/mondumas/templates/stats/ca_groupes.pt index 068cc16..b72fe3d 100644 --- a/mondumas/templates/stats/ca_groupes.pt +++ b/mondumas/templates/stats/ca_groupes.pt @@ -37,6 +37,20 @@ +

Evolution du CA sur les 3 dernières années (global)

+
+ +
+
+
+
+
+
+
+
+
+
+ diff --git a/mondumas/views/stats.py b/mondumas/views/stats.py index c04f151..c431b46 100644 --- a/mondumas/views/stats.py +++ b/mondumas/views/stats.py @@ -218,6 +218,32 @@ def ca_groupes(request): d3 = (item.groupe, float(item.Annee3), tooltip_y3) chart_ca_3y_3.append(d3) + # lire les CA par mois + items = get_ca_groupe_3y_with_others(request, societe, thisyear) + chart_ca_3y_1_x = [] + chart_ca_3y_2_x = [] + chart_ca_3y_3_x = [] + # titre des colonnes + chart_ca_3y_1_x.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'})) + chart_ca_3y_2_x.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'})) + chart_ca_3y_3_x.append(('Groupe', 'CA', { 'type':'string','role': 'tooltip'})) + title1 = 'CA ' + str(thisyear - 2) + title2 = 'CA ' + str(thisyear - 1) + title3 = 'CA ' + str(thisyear) + for item in items: + # construire la liste pour donut cible + 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_x = (item.groupe, float(item.Annee1), tooltip_y1) + chart_ca_3y_1_x.append(d1_x) + d2_x = (item.groupe, float(item.Annee2), tooltip_y2) + chart_ca_3y_2_x.append(d2_x) + d3_x = (item.groupe, float(item.Annee3), tooltip_y3) + chart_ca_3y_3_x.append(d3_x) + + return { 'page_title': "CA par groupe", 'url': url, @@ -225,6 +251,9 @@ def ca_groupes(request): '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), + 'chart_ca_3y_1_x': json.dumps(chart_ca_3y_1_x), + 'chart_ca_3y_2_x': json.dumps(chart_ca_3y_2_x), + 'chart_ca_3y_3_x': json.dumps(chart_ca_3y_3_x), 'title': title, 'title1': title1, 'title2': title2,