diff --git a/mondumas/models/stats.py b/mondumas/models/stats.py index 58729af..c2ff891 100644 --- a/mondumas/models/stats.py +++ b/mondumas/models/stats.py @@ -62,21 +62,18 @@ def get_ca_groupe_12m(request, societe, datedeb, datefin): 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): +def get_ca_groupe_3y(request, societe, year): - date2 = datedeb + relativedelta(years=-1) - date3 = datedeb + relativedelta(years=-2) - 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-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 + 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 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")}) + results = request.dbsession.execute(query, {'societe': societe, 'year': year}) return results.fetchall() def get_ca_clients_12m(request, societe, datedeb, datefin): @@ -101,21 +98,18 @@ def get_ca_clients_12m(request, societe, datedeb, datefin): 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) +def get_ca_clients_3y(request, societe, year): query = """SELECT LIB, - 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 + 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 JOIN bddevfac.p_type ON bddevfac.facture.typecli = bddevfac.p_type.CODE - WHERE societe=:societe AND typecli <> 'I' 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")}) + WHERE societe=:societe AND year(date) >= :year - 2 AND typecli <> 'I' GROUP BY typecli;""" + results = request.dbsession.execute(query, {'societe': societe, 'year': year}) return results.fetchall() def get_delais_pourcent(request, societe, groupe, datedeb): diff --git a/mondumas/static/css/style.less b/mondumas/static/css/style.less index 4ebd068..b4195fa 100644 --- a/mondumas/static/css/style.less +++ b/mondumas/static/css/style.less @@ -177,19 +177,19 @@ color: black; } -.bg-mar { - background-color: #800000 !important; +.bg-compta { + background-color: SlateBlue !important; color: white; } -.bg-choco { - background-color: #D2691E !important; +.bg-gest { + background-color: Coral !important; color: white; } -.bg-tan { - background-color: #D2B48C !important; - color: black; +.bg-prod { + background-color: SkyBlue !important; + color: white; } .new-page { diff --git a/mondumas/templates/parametres/new_home.pt b/mondumas/templates/parametres/new_home.pt index 85e2e2a..0e6490e 100644 --- a/mondumas/templates/parametres/new_home.pt +++ b/mondumas/templates/parametres/new_home.pt @@ -2,60 +2,11 @@
-
-
-
-
- -
- DEM. DEVIS - A traiter : - ${nb_dd_restants.nb_PE} - ${nb_dd_restants.nb_ME} - ${nb_dd_restants.nb_PL} -
-
-
-
-
- -
- DEVIS - A traiter : - ${nb_de_restants.nb_PE} - ${nb_de_restants.nb_ME} - ${nb_de_restants.nb_PL} -
-
-
-
-
- -
- FACTURES - A traiter : - ${nb_fa_restants.nb_PE} - ${nb_fa_restants.nb_ME} - ${nb_fa_restants.nb_PL} -
-
-
- -

-
+
AGENDA @@ -67,7 +18,7 @@
-
+ -
+
-
-
+ -
- +
+
+
+
+ +
+ DEM. DEVIS + A traiter : + ${nb_dd_restants.nb_PE} + ${nb_dd_restants.nb_ME} + ${nb_dd_restants.nb_PL} +
+
+
+
+
+ +
+ DEVIS + A traiter : + ${nb_de_restants.nb_PE} + ${nb_de_restants.nb_ME} + ${nb_de_restants.nb_PL} +
+
+
+
+
+ +
+ FACTURES + A traiter : + ${nb_fa_restants.nb_PE} + ${nb_fa_restants.nb_ME} + ${nb_fa_restants.nb_PL} +
+
+
+
+
+
-
+
STATS diff --git a/mondumas/templates/stats/ca_clients.pt b/mondumas/templates/stats/ca_clients.pt index 102db24..4477dfc 100644 --- a/mondumas/templates/stats/ca_clients.pt +++ b/mondumas/templates/stats/ca_clients.pt @@ -17,11 +17,13 @@
+

Evolution du CA sur les 12 derniers mois

+

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

diff --git a/mondumas/templates/stats/ca_groupes.pt b/mondumas/templates/stats/ca_groupes.pt index 93cf7f7..3c08efe 100644 --- a/mondumas/templates/stats/ca_groupes.pt +++ b/mondumas/templates/stats/ca_groupes.pt @@ -17,11 +17,13 @@
+

Evolution du CA sur les 12 derniers mois

+

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

diff --git a/mondumas/views/stats.py b/mondumas/views/stats.py index e5aa9dc..58c6258 100644 --- a/mondumas/views/stats.py +++ b/mondumas/views/stats.py @@ -177,21 +177,20 @@ def ca_groupes(request): chart_ca_12m = [] # titre des colonnes chart_ca_12m.append(('Mois', 'AXA', { 'type':'string','role': 'tooltip'}, 'MAIF', { 'type':'string','role': 'tooltip'})) - title = 'CA / MOIS' + title = 'CA sur 12 mois' 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)) + tooltipMAIF = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.MAIF_ca) + ' €\nDossiers: '+str(round(item.MAIF_nb)) + tooltipAXA = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.AXA_ca) + ' €\nDossiers: '+str(round(item.AXA_nb)) # ('+str(item.population)+')/n' - d = (item.mois, float(item.AXA_ca), tooltipAXA, float(item.MAIF_ca), tooltipMAIF) + d = (item.mois[:3], float(item.AXA_ca), tooltipAXA, float(item.MAIF_ca), tooltipMAIF) chart_ca_12m.append(d) # debut = aujourd'hui - 11 mois - datedeb = date.today() - datedeb.replace(month=1,day=1) + thisyear = date.today().year # lire les CA par mois - items = get_ca_groupe_3y(request, societe, datedeb) + items = get_ca_groupe_3y(request, societe, thisyear) chart_ca_3y_1 = [] chart_ca_3y_2 = [] chart_ca_3y_3 = [] @@ -199,9 +198,9 @@ def ca_groupes(request): 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") + 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)) @@ -253,26 +252,25 @@ def ca_clients(request): chart_ca_12m.append(('Mois', 'ASSURANCES', { 'type':'string','role': 'tooltip'}, 'EXPERTS', { 'type':'string','role': 'tooltip'}, 'GROUPEMENT', { 'type':'string','role': 'tooltip'}, 'PARTICULIER', { 'type':'string','role': 'tooltip'}, 'REGIES', { 'type':'string','role': 'tooltip'}, 'SOCIETE', { 'type':'string','role': 'tooltip'})) - title = 'CA / MOIS' + title = 'CA sur 12 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)) - 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)) + tooltipA = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.A_ca) + ' €\nDossiers: '+str(round(item.A_nb)) + tooltipE = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.E_ca) + ' €\nDossiers: '+str(round(item.E_nb)) + tooltipG = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.G_ca) + ' €\nDossiers: '+str(round(item.G_nb)) + tooltipP = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.P_ca) + ' €\nDossiers: '+str(round(item.P_nb)) + tooltipR = item.date[:3] + ' ' + item.date[-4:] + ' \nCA: '+str(item.R_ca) + ' €\nDossiers: '+str(round(item.R_nb)) + tooltipS = item.date[:3] + ' ' + item.date[-4:] + ' \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, + d = (item.mois[:3], float(item.A_ca), tooltipA, float(item.E_ca), tooltipE, float(item.G_ca), tooltipG, 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) + thisyear = date.today().year # lire les CA par mois - items = get_ca_clients_3y(request, societe, datedeb) + items = get_ca_clients_3y(request, societe, thisyear) chart_ca_3y_1 = [] chart_ca_3y_2 = [] chart_ca_3y_3 = [] @@ -280,24 +278,36 @@ def ca_clients(request): 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") + 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.LIB + ' \nCA: '+str(item.Annee1) + ' €\nDossiers: '+str(round(item.Count1)) tooltip_y2 = item.LIB + ' \nCA: '+str(item.Annee2) + ' €\nDossiers: '+str(round(item.Count1)) tooltip_y3 = item.LIB + ' \nCA: '+str(item.Annee3) + ' €\nDossiers: '+str(round(item.Count1)) # ('+str(item.population)+')/n' - d1 = (item.LIB, float(item.Annee1), tooltip_y1) + if item.Annee1 > 0: + ca = float(item.Annee1) + else: + ca = 0 + d1 = (item.LIB, ca, tooltip_y1) chart_ca_3y_1.append(d1) - d2 = (item.LIB, float(item.Annee2), tooltip_y2) + if item.Annee2 > 0: + ca = float(item.Annee2) + else: + ca = 0 + d2 = (item.LIB, ca, tooltip_y2) chart_ca_3y_2.append(d2) - d3 = (item.LIB, float(item.Annee3), tooltip_y3) + if item.Annee3 > 0: + ca = float(item.Annee3) + else: + ca = 0 + d3 = (item.LIB, ca, tooltip_y3) chart_ca_3y_3.append(d3) return { - 'page_title': "CA par clients", + 'page_title': "CA par types de clients", 'url': url, 'chart_ca_12m': json.dumps(chart_ca_12m), 'chart_ca_3y_1': json.dumps(chart_ca_3y_1),