From 95a66e7e63cc8a62e7f461beca312b313a69a369 Mon Sep 17 00:00:00 2001
From: florian HENRY <florian.henry@atm-consulting.fr>
Date: Mon, 8 Aug 2016 14:52:19 +0200
Subject: [PATCH] Work on accoutancy PgSQL comptatiblity and other stuff

---
 htdocs/accountancy/customer/index.php |  55 +++++-----
 htdocs/accountancy/customer/list.php  |   1 +
 htdocs/accountancy/supplier/index.php | 141 ++++++++------------------
 htdocs/langs/en_US/accountancy.lang   |   2 +
 4 files changed, 73 insertions(+), 126 deletions(-)

diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php
index fce70e56051..9a4b1d2e2f0 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -43,7 +43,7 @@ if ($user->societe_id > 0)
 	accessforbidden();
 if (! $user->rights->accounting->ventilation->read)
 	accessforbidden();
-	
+
 	// Filter
 $year = $_GET["year"];
 if ($year == 0) {
@@ -57,17 +57,17 @@ if ($year == 0) {
 // Validate History
 $action = GETPOST('action');
 if ($action == 'validatehistory') {
-	
+
 	$error = 0;
 	$db->begin();
-	
+
 	if ($db->type == 'pgsql') {
-		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
-		$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
+		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet";
+		$sql1 .= " SET fk_code_ventilation = accnt.rowid";
 		$sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
-		$sql1 .= " WHERE fd.fk_product = p.rowid  AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
+		$sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid  AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
 		$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
-		$sql1 .= " AND fd.fk_code_ventilation = 0";
+		$sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0";
 	} else {
 		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
 		$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
@@ -75,9 +75,9 @@ if ($action == 'validatehistory') {
 		$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
 		$sql1 .= " AND fd.fk_code_ventilation = 0";
 	}
-	
+
 	dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -90,7 +90,7 @@ if ($action == 'validatehistory') {
 } elseif ($action == 'fixaccountancycode') {
 	$error = 0;
 	$db->begin();
-	
+
 	$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
 	$sql1 .= " SET fd.fk_code_ventilation = 0";
 	$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN ';
@@ -98,9 +98,9 @@ if ($action == 'validatehistory') {
 	$sql1 .= '	FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt';
 	$sql1 .= '	INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
 	$sql1 .= '	ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
-	
+
 	dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -113,15 +113,15 @@ if ($action == 'validatehistory') {
 } elseif ($action == 'cleanaccountancycode') {
 	$error = 0;
 	$db->begin();
-	
+
 	$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd";
 	$sql1 .= " SET fd.fk_code_ventilation = 0";
 	$sql1 .= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f";
 	$sql1 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'";
 	$sql1 .= "  AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "')";
-	
+
 	dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -198,7 +198,7 @@ $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
 	$num = $db->num_rows($resql);
-	
+
 	while ( $i < $num ) {
 		$row = $db->fetch_row($resql);
 		$var = ! $var;
@@ -245,10 +245,10 @@ $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
 	$num = $db->num_rows($resql);
-	
+
 	while ( $i < $num ) {
 		$row = $db->fetch_row($resql);
-		
+
 		print '<tr><td>' . $row[0] . '</td>';
 		for($i = 1; $i <= 12; $i ++) {
 			print '<td align="right">' . price($row[$i]) . '</td>';
@@ -271,37 +271,34 @@ if (! empty($conf->margin->enabled)) {
 		print '<td width="60" align="center">' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '</td>';
 	}
 	print '<td width="60" align="center"><b>' . $langs->trans("Total") . '</b></td></tr>';
-	
-	$sql = "SELECT '" . $langs->trans("Vide") . "' AS 'Marge',";
+
+	$sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,";
 	for($i = 1; $i <= 12; $i ++) {
 		$sql .= "  SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
 	}
-	$sql .= "  SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as 'Total'";
+	$sql .= "  SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total";
 	$sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd";
 	$sql .= "  LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
 	$sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
 	$sql .= "  AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'";
-	
+
 	if (! empty($conf->multicompany->enabled)) {
 		$sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
 	}
-	
+
 	dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql);
 	$resql = $db->query($sql);
 	if ($resql) {
-		$i = 0;
 		$num = $db->num_rows($resql);
-		
-		while ( $i < $num ) {
-			$row = $db->fetch_row($resql);
-			
+
+		while ($row = $db->fetch_row($resql)) {
+
 			print '<tr><td>' . $row[0] . '</td>';
 			for($i = 1; $i <= 12; $i ++) {
 				print '<td align="right">' . price($row[$i]) . '</td>';
 			}
 			print '<td align="right"><b>' . price($row[13]) . '</b></td>';
 			print '</tr>';
-			$i ++;
 		}
 		$db->free($resql);
 	} else {
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 167f558d830..db73fe7e947 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -307,6 +307,7 @@ if ($result) {
 		// Ref Invoice
 		$facture_static->ref = $objp->facnumber;
 		$facture_static->id = $objp->facid;
+		$facture_static->type = $objp->ftype;
 		print '<td>' . $facture_static->getNomUrl(1) . '</td>';
 		// Ref Product
 		$product_static->ref = $objp->product_ref;
diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php
index 5e87985ce61..bbef2a6dcc0 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -41,7 +41,7 @@ if ($user->societe_id > 0)
 	accessforbidden();
 if (! $user->rights->accounting->ventilation->read)
 	accessforbidden();
-	
+
 // Filter
 $year = $_GET["year"];
 if ($year == 0) {
@@ -55,17 +55,17 @@ if ($year == 0) {
 // Validate History
 $action = GETPOST('action');
 if ($action == 'validatehistory') {
-	
+
 	$error = 0;
 	$db->begin();
-	
+
 	if ($db->type == 'pgsql') {
-		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
-		$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
+		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
+		$sql1 .= " SET fk_code_ventilation = accnt.rowid";
 		$sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
-		$sql1 .= " WHERE fd.fk_product = p.rowid  AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
+		$sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid  AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS;
 		$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
-		$sql1 .= " AND fd.fk_code_ventilation = 0";
+		$sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0";
 	} else {
 		$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
 		$sql1 .= " SET fd.fk_code_ventilation = accnt.rowid";
@@ -73,7 +73,7 @@ if ($action == 'validatehistory') {
 		$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
 		$sql1 .= " AND fd.fk_code_ventilation = 0";
 	}
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -86,7 +86,7 @@ if ($action == 'validatehistory') {
 } elseif ($action == 'fixaccountancycode') {
 	$error = 0;
 	$db->begin();
-	
+
 	$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
 	$sql1 .= " SET fd.fk_code_ventilation = 0";
 	$sql1 .= ' WHERE fd.fk_code_ventilation NOT IN ';
@@ -94,9 +94,9 @@ if ($action == 'validatehistory') {
 	$sql1 .= '	FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt';
 	$sql1 .= '	INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst';
 	$sql1 .= '	ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')';
-	
+
 	dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -109,15 +109,15 @@ if ($action == 'validatehistory') {
 } elseif ($action == 'cleanaccountancycode') {
 	$error = 0;
 	$db->begin();
-	
+
 	$sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd";
 	$sql1 .= " SET fd.fk_code_ventilation = 0";
 	$sql1 .= " WHERE fd.fk_facture_fourn IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
 	$sql1 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'";
 	$sql1 .= "  AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "')";
-	
+
 	dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
-	
+
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
 		$error ++;
@@ -154,35 +154,17 @@ $var = true;
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre"><td width="200" align="left">' . $langs->trans("Account") . '</td>';
 print '<td width="200" align="left">' . $langs->trans("Label") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JanuaryMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("FebruaryMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("MarchMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("AprilMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("MayMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JuneMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JulyMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("AugustMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("SeptemberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("OctoberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("NovemberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("DecemberMin") . '</td>';
+for($i = 1; $i <= 12; $i ++) {
+	print '<td width="60" align="center">' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '</td>';
+}
 print '<td width="60" align="center"><b>' . $langs->trans("Total") . '</b></td></tr>';
 
-$sql = "SELECT IF(aa.account_number IS NULL, 'Non pointe', aa.account_number) AS 'code comptable',";
-$sql .= "  IF(aa.label IS NULL, 'Non pointe', aa.label) AS 'Intitulé',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',";
-$sql .= "  ROUND(SUM(ffd.total_ht),2) as 'Total'";
+$sql = "SELECT  ".$db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') ." AS codecomptable,";
+$sql .= "  " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.label') . " AS intitule,";
+for($i = 1; $i <= 12; $i ++) {
+	$sql .= "  SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
+}
+$sql .= "  ROUND(SUM(ffd.total_ht),2) as total";
 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd";
 $sql .= "  LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
 $sql .= "  LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
@@ -194,31 +176,23 @@ if (! empty($conf->multicompany->enabled)) {
 	$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")";
 }
 
-$sql .= " GROUP BY ffd.fk_code_ventilation";
+$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
 
 dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql);
 $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
 	$num = $db->num_rows($resql);
-	
+
 	while ( $i < $num ) {
-		
+
 		$row = $db->fetch_row($resql);
 		$var = ! $var;
 		print '<tr ' . $bc[$var] . '><td>' . length_accountg($row[0]) . '</td>';
 		print '<td align="left">' . $row[1] . '</td>';
-		print '<td align="right">' . price($row[2]) . '</td>';
-		print '<td align="right">' . price($row[3]) . '</td>';
-		print '<td align="right">' . price($row[4]) . '</td>';
-		print '<td align="right">' . price($row[5]) . '</td>';
-		print '<td align="right">' . price($row[6]) . '</td>';
-		print '<td align="right">' . price($row[7]) . '</td>';
-		print '<td align="right">' . price($row[8]) . '</td>';
-		print '<td align="right">' . price($row[9]) . '</td>';
-		print '<td align="right">' . price($row[10]) . '</td>';
-		print '<td align="right">' . price($row[11]) . '</td>';
-		print '<td align="right">' . price($row[12]) . '</td>';
+		for($i = 2; $i <= 12; $i ++) {
+			print '<td align="right">' . price($row[$i]) . '</td>';
+		}
 		print '<td align="right">' . price($row[13]) . '</td>';
 		print '<td align="right"><b>' . price($row[14]) . '</b></td>';
 		print '</tr>';
@@ -233,34 +207,16 @@ print "</table>\n";
 print "<br>\n";
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre"><td width="400" align="left">' . $langs->trans("Total") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JanuaryMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("FebruaryMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("MarchMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("AprilMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("MayMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JuneMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("JulyMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("AugustMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("SeptemberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("OctoberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("NovemberMin") . '</td>';
-print '<td width="60" align="center">' . $langs->trans("DecemberMin") . '</td>';
+for($i = 1; $i <= 12; $i ++) {
+	print '<td width="60" align="center">' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '</td>';
+}
 print '<td width="60" align="center"><b>' . $langs->trans("Total") . '</b></td></tr>';
 
-$sql = "SELECT '" . $langs->trans("CAHTF") . "' AS 'Total',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',";
-$sql .= "  ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',";
-$sql .= "  ROUND(SUM(ffd.total_ht),2) as 'Total'";
+$sql = "SELECT '" . $langs->trans("CAHTF") . "' AS label,";
+for($i = 1; $i <= 12; $i ++) {
+	$sql .= "  SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ",";
+}
+$sql .= "  ROUND(SUM(ffd.total_ht),2) as total";
 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd";
 $sql .= "  LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
 $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'";
@@ -276,29 +232,20 @@ $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
 	$num = $db->num_rows($resql);
-	
+
 	while ( $i < $num ) {
 		$row = $db->fetch_row($resql);
-		
+
 		print '<tr><td>' . $row[0] . '</td>';
-		print '<td align="right">' . $row[1] . '</td>';
-		print '<td align="right">' . price($row[2]) . '</td>';
-		print '<td align="right">' . price($row[3]) . '</td>';
-		print '<td align="right">' . price($row[4]) . '</td>';
-		print '<td align="right">' . price($row[5]) . '</td>';
-		print '<td align="right">' . price($row[6]) . '</td>';
-		print '<td align="right">' . price($row[7]) . '</td>';
-		print '<td align="right">' . price($row[8]) . '</td>';
-		print '<td align="right">' . price($row[9]) . '</td>';
-		print '<td align="right">' . price($row[10]) . '</td>';
-		print '<td align="right">' . price($row[11]) . '</td>';
-		print '<td align="right">' . price($row[12]) . '</td>';
+			for($i = 1; $i <= 12; $i ++) {
+			print '<td align="right">' . price($row[$i]) . '</td>';
+		}
 		print '<td align="right"><b>' . price($row[13]) . '</b></td>';
 		print '</tr>';
-		
+
 		$i ++;
 	}
-	
+
 	$db->free($resql);
 } else {
 	print $db->lasterror(); // Show last sql error
diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang
index a663d683fe3..056466706a1 100644
--- a/htdocs/langs/en_US/accountancy.lang
+++ b/htdocs/langs/en_US/accountancy.lang
@@ -158,6 +158,8 @@ OptionModeProductSell=Mode sales
 OptionModeProductBuy=Mode purchases
 OptionModeProductSellDesc=Show all products with no accounting account defined for sales.
 OptionModeProductBuyDesc=Show all products with no accounting account defined for purchases.
+CleanFixHistory=Remove accountancy code from lines that not exists into charts of account
+CleanHistory=Reset all accountancy for selected year
 
 ## Dictionary
 Range=Range of accounting account
-- 
GitLab