diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php
index 629a5152324dfb27974ff054cb76613ad731ae26..88f68bdf6d4782992d96a658e6ab2c319ad2b374 100644
--- a/htdocs/ecm/index.php
+++ b/htdocs/ecm/index.php
@@ -236,7 +236,7 @@ print '<table class="nobordernopadding" width="100%"><tr><td valign="top">';
 
 if (eregi('search',$action))
 {
-	//print_fiche_titre($langs->trans("ECMManualOrg"));
+	//print_fiche_titre($langs->trans("ECMSectionsManual"));
 
 	print '<form method="post" action="'.DOL_URL_ROOT.'/ecm/search.php">';
 	print '<table class="nobordernopadding" width="100%">';
@@ -249,7 +249,7 @@ if (eregi('search',$action))
 	print "</table></form>";
 	//print $langs->trans("ECMManualOrgDesc");
 
-	//print_fiche_titre($langs->trans("ECMAutoOrg"));
+	//print_fiche_titre($langs->trans("ECMSectionAuto"));
 
 	print '<form method="post" action="'.DOL_URL_ROOT.'/ecm/search.php">';
 	print '<table class="noborder" width="100%">';
@@ -279,7 +279,7 @@ if (eregi('search',$action))
 
 	print '<tr '. $bc[false].'><td colspan="4" align="center"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
 	print "</table></form>";
-	//print $langs->trans("ECMAutoOrgDesc");
+	//print $langs->trans("ECMSectionAutoDesc");
 }
 
 
@@ -300,7 +300,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 
 	print '<tr class="liste_titre">';
 	print '<td class="liste_titre" align="left">'.$langs->trans("ECMSections").'</td>';
-	print '<td class="liste_titre" colspan="4" align="right">';
+	print '<td class="liste_titre" colspan="5" align="right">';
 	print '<a href="'.$_SERVER["PHP_SELF"].'?action=refreshmanual'.($section?'&amp;section='.$section:'').'">'.$langs->trans("Refresh").' '.img_picto($langs->trans("Refresh"),'refresh').'</a>';
 	print '</td>';
 	print '</tr>';
@@ -313,13 +313,14 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 		print '<table class="nobordernopadding"><tr class="nobordernopadding">';
 		print '<td align="left" width="24px">';
 		print img_picto_common('','treemenu/base.gif');
-		print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionAuto").')';
+		print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsAuto").')';
 		print '</td>';
 		print '</tr></table>';
 		print '</td>';
 		print '<td align="right">&nbsp;</td>';
 		print '<td align="right">&nbsp;</td>';
 		print '<td align="right">&nbsp;</td>';
+		print '<td align="right">&nbsp;</td>';
 		print '<td align="center">';
 		$htmltooltip=$langs->trans("ECMAreaDesc2");
 		print $form->textwithhelp('',$htmltooltip,1,0);
@@ -343,15 +344,28 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 				print '<td align="left">';
 				print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
 				tree_showpad($sectionauto,$key);
-				print '</td><td valign="top">';
-				print img_picto('','object_dir');
-				print '</td><td valign="middle">&nbsp;';
+				print '</td>';
+				
+				print '<td valign="top">';
+				$n=3;
+				$ref=img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/plustop'.$n.'.gif','',1);
+				$oldref=$ecmdirstatic->ref;
+				$ecmdirstatic->ref=$ref;
+				print $ecmdirstatic->getNomUrl(0,$option);
+				$ecmdirstatic->ref=$oldref;
+				print img_picto('',DOL_URL_ROOT.'/theme/common/treemenu/folder.gif','',1);
+				print '</td>';
+				
+				print '<td valign="middle">';
 				print '<a href="'.DOL_URL_ROOT.'/ecm/docother.php">';
 				print $val['label'];
 				print '</a></td></tr></table>';
 				print "</td>\n";
 					
-				// Nb of doc
+				// Nb of doc in dir
+				print '<td align="right">&nbsp;</td>';
+
+				// Nb of doc in subdir
 				print '<td align="right">&nbsp;</td>';
 
 				// Edit link
@@ -363,7 +377,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 				// Info
 				print '<td align="center">';
 				$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
-				$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMAutoOrg").'<br>';
+				$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionAuto").'<br>';
 				$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$langs->trans("ECMTypeAuto").'<br>';
 				$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['desc'];
 				print $form->textwithhelp('',$htmltooltip,1,0);
@@ -382,7 +396,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 	print '<table class="nobordernopadding"><tr class="nobordernopadding">';
 	print '<td align="left" width="24px">';
 	print img_picto_common('','treemenu/base.gif');
-	print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionManual").')';
+	print '</td><td align="left">'.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionsManual").')';
 	print '</td>';
 	print '</tr></table></td>';
 	print '<td align="right">';
@@ -390,6 +404,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 	print '<td align="right">&nbsp;</td>';
 	//print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docdir.php?action=create">'.img_edit_add().'</a></td>';
 	print '<td align="right">&nbsp;</td>';
+	print '<td align="right">&nbsp;</td>';
 	print '<td align="center">';
 	$htmltooltip=$langs->trans("ECMAreaDesc2");
 	print $form->textwithhelp('',$htmltooltip,1,0);
@@ -488,8 +503,11 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 			print '<table class="nobordernopadding"><tr class="nobordernopadding"><td>';
 			$resarray=tree_showpad($fulltree,$key);
 			$a=$resarray[0];
-			$b=$resarray[1];
+			$nbofsubdir=$resarray[1];
+			$c=$resarray[2];
+			$nboffilesinsubdir=$resarray[3];
 			print '</td>';
+
 			// Show picto
 			print '<td valign="top">';
 			//print $val['fullpath']."(".$showline.")";
@@ -515,8 +533,13 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 			print "</td>\n";
 
 			// Nb of docs
-			print '<td align="right">'.$val['cachenbofdoc'].'</td>';
-				
+			print '<td align="right">';
+			print $val['cachenbofdoc'];
+			print '</td>';
+			print '<td align="left">';
+			if ($nbofsubdir && $nboffilesinsubdir) print '<font color="#AAAAAA">+'.$nboffilesinsubdir.'</font> ';
+			print '</td>';
+			
 			// Edit link
 			print '<td align="right"><a href="'.DOL_URL_ROOT.'/ecm/docmine.php?section='.$val['id'].'">'.img_edit().'</a></td>';
 				
@@ -529,10 +552,13 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $
 			$userstatic->id=$val['fk_user_c'];
 			$userstatic->nom=$val['login_c'];
 			$htmltooltip='<b>'.$langs->trans("ECMSection").'</b>: '.$val['label'].'<br>';
-			$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMManualOrg").'<br>';
+			$htmltooltip='<b>'.$langs->trans("Type").'</b>: '.$langs->trans("ECMSectionManual").'<br>';
 			$htmltooltip.='<b>'.$langs->trans("ECMCreationUser").'</b>: '.$userstatic->getNomUrl(1).'<br>';
 			$htmltooltip.='<b>'.$langs->trans("ECMCreationDate").'</b>: '.dolibarr_print_date($val['date_c'],"dayhour").'<br>';
-			$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'];
+			$htmltooltip.='<b>'.$langs->trans("Description").'</b>: '.$val['description'].'<br>';
+			$htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInDir").'</b>: '.$val['cachenbofdoc'].'<br>';
+			if ($nbofsubdir) $htmltooltip.='<b>'.$langs->trans("ECMNbOfFilesInSubDir").'</b>: '.$nboffilesinsubdir;
+			else $htmltooltip.='<b>'.$langs->trans("ECMNbOfSubDir").'</b>: '.$nbofsubdir.'<br>';
 			print $form->textwithhelp('',$htmltooltip,1,0);
 			print "</td>";
 				
diff --git a/htdocs/langs/HOWTO-Translation.txt b/htdocs/langs/HOWTO-Translation.txt
index 16f9f5fd1d9135aa00b8bf1e82db1739a5d032e6..95fcab85925c9af39791ed0ebfe2aff8142039a6 100644
--- a/htdocs/langs/HOWTO-Translation.txt
+++ b/htdocs/langs/HOWTO-Translation.txt
@@ -1 +1 @@
-See http://dolibarr.com/wikidev/index.php/Documentation_traducteur
+See http://dolibarr.com/wikidev/index.php/Documentation_traducteur
diff --git a/htdocs/langs/en_US/ecm.lang b/htdocs/langs/en_US/ecm.lang
index bbf243d76742b021cdf63b9b64cf99e92998de8f..3560e6c42a0e23080fded99707f093e3bf230b52 100644
--- a/htdocs/langs/en_US/ecm.lang
+++ b/htdocs/langs/en_US/ecm.lang
@@ -13,6 +13,8 @@ ECMNbOfDocsSmall=Nb of doc.
 ECMSection=Directory
 ECMSectionManual=Manual directory
 ECMSectionAuto=Automatic directory
+ECMSectionsManual=Manual directories
+ECMSectionsAuto=Automatic directories
 ECMSections=Directories
 ECMRoot=Root
 ECMNewSection=New directory
@@ -20,6 +22,9 @@ ECMAddSection=Add a manual directory
 ECMNewSection=New manual directory
 ECMNewDocument=New document
 ECMCreationDate=Creation date
+ECMNbOfFilesInDir=Number of files in directory
+ECMNbOfSubDir=Number of sub-directories
+ECMNbOfFilesInSubDir=Nunber of iles in sub-directories
 ECMCreationUser=Creator
 ECMArea=ECM area
 ECMAreaDesc=The ECM (Electronic Content Management) area allows you to save, share and search quickly all kind of documents in Dolibarr.
@@ -37,8 +42,6 @@ ECMDocsByOrders=Documents linked to customers orders
 ECMDocsByContracts=Documents linked to contracts
 ECMDocsByInvoices=Documents linked to customers invoices
 ECMDocsByProducts=Documents linked to products
-ECMManualOrg=Manual directory
-ECMAutoOrg=Automatic directory
 ECMNoDirecotyYet=No directory created
 ShowECMSection=Show directory
 DeleteSection=Remove directory
diff --git a/htdocs/langs/fr_FR/.cvsignore b/htdocs/langs/fr_FR/.cvsignore
index 63f874305ecb9a9a3cf9c18bc0a8f2d5f37d5d57..1fd02e68d65bd6442875caef6f3aec0b5eca4673 100644
--- a/htdocs/langs/fr_FR/.cvsignore
+++ b/htdocs/langs/fr_FR/.cvsignore
@@ -1 +1 @@
-google.lang
+google.lang
diff --git a/htdocs/langs/fr_FR/ecm.lang b/htdocs/langs/fr_FR/ecm.lang
index b2a7fe4e574a57dd5545b714be765783539ba985..560a70b39c1061b9aab771442035997515f7e843 100644
--- a/htdocs/langs/fr_FR/ecm.lang
+++ b/htdocs/langs/fr_FR/ecm.lang
@@ -8,28 +8,33 @@ DocsContracts=Documents contrats
 DocsProposals=Documents propositions
 DocsOrders=Documents commandes
 DocsInvoices=Documents factures
-ECMNbOfDocs=Nb de documents de la rubrique
+ECMNbOfDocs=Nb de documents du r�pertoire
 ECMNbOfDocsSmall=Nb de doc.
-ECMSection=Rubrique
-ECMSectionManual=Rubriques manuelles
-ECMSectionAuto=Rubriques automatiques
-ECMSections=Rubriques
+ECMSection=R�pertoire
+ECMSectionManual=R�pertoire manuel
+ECMSectionAuto=R�pertoire automatique
+ECMSectionsManual=R�pertoires manuels
+ECMSectionsAuto=R�pertoires automatiques
+ECMSections=R�pertoires
 ECMRoot=Racine
-ECMNewSection=Nouvelle rubrique
-ECMAddSection=Ajouter rubrique manuelle
-ECMNewSection=Nouvelle rubrique manuelle
+ECMNewSection=Nouveau r�pertoire
+ECMAddSection=Ajouter r�pertoire manuel
+ECMNewSection=Nouveau r�pertoire manuel
 ECMNewDocument=Nouveau document
 ECMCreationDate=Date cr�ation
+ECMNbOfFilesInDir=Nombre de fichiers dans le r�pertoire
+ECMNbOfSubDir=Nombre de sous-r�pertoires
+ECMNbOfFilesInSubDir=Nombre de fichiers dans les sous-r�pertoires
 ECMCreationUser=Cr�ateur
 ECMArea=Espace GED
 ECMAreaDesc=L'espace GED (Gestion Electronique de Documents) vous permet de stocker dans Dolibarr et retrouver rapidement tout type de documents.
-ECMAreaDesc2=* Les rubriques automatiques sont aliment�es automatiquement lors de l'ajout d'un document depuis une fiche objet (propal, facture...).<br>* Les rubriques manuelles peuvent etre utilis�es pour stocker des documents divers, non li�s � un objet particulier.
-ECMSectionWasRemoved=La rubrique <b>%s</b> a �t� effac�e.
+ECMAreaDesc2=* Les r�pertoires automatiques sont aliment�es automatiquement lors de l'ajout d'un document depuis une fiche objet (propal, facture...).<br>* Les r�pertoires manuels peuvent etre utilis�es pour stocker des documents divers, non li�s � un objet particulier.
+ECMSectionWasRemoved=Le r�pertoire <b>%s</b> a �t� effac�e.
 ECMDocumentsSection=Document de la section
 ECMSearchByKeywords=Recherche par mots cl�s
 ECMSearchByEntity=Recherche par objet
-ECMSectionOfDocuments=Rubriques des documents
-ECMTypeManual=Manuelle
+ECMSectionOfDocuments=R�pertoires des documents
+ECMTypeManual=Manuel
 ECMTypeAuto=Automatique
 ECMDocsByThirdParties=Documents associ�s aux tiers
 ECMDocsByProposals=Documents associ�s aux propositions
@@ -37,13 +42,11 @@ ECMDocsByOrders=Documents associ
 ECMDocsByContracts=Documents associ�s aux contrats
 ECMDocsByInvoices=Documents associ�s aux factures
 ECMDocsByProducts=Documents associ�s aux produits
-ECMManualOrg=Rubrique manuelle
-ECMAutoOrg=Rubrique automatique
-ECMNoDirecotyYet=Aucune rubrique cr��e
-ShowECMSection=Afficher rubrique
-DeleteSection=Suppression rubrique
-ConfirmDeleteSection=Confirmez-vous la suppression de la rubrique <b>%s</b> ?
+ECMNoDirecotyYet=Aucun r�pertoire cr��e
+ShowECMSection=Afficher r�pertoire
+DeleteSection=Suppression r�pertoire
+ConfirmDeleteSection=Confirmez-vous la suppression du r�pertoire <b>%s</b> ?
 ECMDirectoryForFiles=R�pertoire relatif pour les fichiers
 CannotRemoveDirectoryContainsFiles=Suppression impossible car des fichiers sont pr�sents
 ECMFileManager=Gestionnaire fichier
-ECMSelectASection=Selectionner une rubrique sur l'arbre de gauche...
\ No newline at end of file
+ECMSelectASection=Selectionner un r�pertoire sur l'arbre de gauche...
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/html/spam.html b/htdocs/langs/fr_FR/html/spam.html
index 9d6dcccdc56d3b0ae1bec57927984e86e9507624..643e69a3fc0f34d3d29f8eb2595090ae56af6925 100644
--- a/htdocs/langs/fr_FR/html/spam.html
+++ b/htdocs/langs/fr_FR/html/spam.html
@@ -23,4 +23,4 @@ Enfin, la loi pour la confiance dans l'
 
 <P class="bodytext">Ainsi, les entreprises peuvent jusqu'au 22 d�cembre 2004 adresser, � partir de fichiers constitu�s dans le respect des dispositions de la loi Informatique et libert�s du 6 janvier 1978, un courrier �lectronique afin de recueillir le consentement des personnes. L'absence de r�ponse de celles-ci dans la p�riode des 6 mois �quivaudra � un refus d'�tre d�march�.&nbsp; </P>
 <P class="bodytext">Ind�pendamment des r�gles sp�cifiques pr�vues dans le code des postes et des t�l�communications et dans celui de la consommation, les op�rations de prospection par courrier �lectronique, quelque soit leur nature (commerciale, caritative, politique, religieuse ou associative par exemple), sont soumises au respect de la l�gislation relative � la protection des donn�es personnelles, � savoir la <a href="http://www.cnil.fr/index.php?id=301" target="cnil">loi Informatique et Libert�s du 6 janvier 1978</a>. 
-</P>
+</P>
diff --git a/htdocs/lib/.cvsignore b/htdocs/lib/.cvsignore
index 6c8214fdbe20830800b11d5643b7c9c36394c246..60dbf5fcb1a348a218385aa8dc7b29b15e96df35 100644
--- a/htdocs/lib/.cvsignore
+++ b/htdocs/lib/.cvsignore
@@ -1 +1 @@
-htmlMimeMail
+htmlMimeMail
diff --git a/htdocs/lib/bookmark.lib.php b/htdocs/lib/bookmark.lib.php
index 689bfcf611df032830e4b4d36d623cab5003b335..8e0c8b6331d299deffac8555af8ad930420c52e5 100644
--- a/htdocs/lib/bookmark.lib.php
+++ b/htdocs/lib/bookmark.lib.php
@@ -1,69 +1,69 @@
-<?php
-/* Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
- */
-
-/**
-	    \file       htdocs/lib/invoice.lib.php
-		\brief      Ensemble de fonctions de base pour le module factures
-		\version    $Revision$
-
-		Ensemble de fonctions de base de dolibarr sous forme d'include
-*/
-
-function showArrayOfBookmark($fac)
-{
-	$sql = "SELECT s.rowid as socid, s.nom, b.rowid as bid";
-	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
-	$sql .= " WHERE b.fk_soc = s.rowid AND b.fk_user = ".$user->id;
-	$sql .= " ORDER BY lower(s.nom) ASC";
-
-	$resql = $db->query($sql);
-
-	if ( $resql )
-	{
-	  $num = $db->num_rows($resql);
-	  $i = 0;
-	  if ($num)
-	    {
-	      print '<table class="noborder" width="100%">';
-	      print "<tr class=\"liste_titre\"><td colspan=\"2\">".$langs->trans("Bookmarks")."</td></tr>\n";
-	      $var = True;
-	      while ($i < $num)
-		{
-		  $obj = $db->fetch_object($resql);
-		  $var = !$var;
-		  print "<tr $bc[$var]>";
-		  print '<td><a href="fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
-		  print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">'.img_delete().'</a></td>';
-		  print '</tr>';
-		  $i++;
-		}
-	      print '</table>';
-	    }
-	  $db->free($resql);
-	}
-	else
-	{
-	  dolibarr_print_error($db);
-	}
-}
-
+<?php
+/* Copyright (C) 2005 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
+ *
+ * $Id$
+ * $Source$
+ */
+
+/**
+	    \file       htdocs/lib/invoice.lib.php
+		\brief      Ensemble de fonctions de base pour le module factures
+		\version    $Revision$
+
+		Ensemble de fonctions de base de dolibarr sous forme d'include
+*/
+
+function showArrayOfBookmark($fac)
+{
+	$sql = "SELECT s.rowid as socid, s.nom, b.rowid as bid";
+	$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
+	$sql .= " WHERE b.fk_soc = s.rowid AND b.fk_user = ".$user->id;
+	$sql .= " ORDER BY lower(s.nom) ASC";
+
+	$resql = $db->query($sql);
+
+	if ( $resql )
+	{
+	  $num = $db->num_rows($resql);
+	  $i = 0;
+	  if ($num)
+	    {
+	      print '<table class="noborder" width="100%">';
+	      print "<tr class=\"liste_titre\"><td colspan=\"2\">".$langs->trans("Bookmarks")."</td></tr>\n";
+	      $var = True;
+	      while ($i < $num)
+		{
+		  $obj = $db->fetch_object($resql);
+		  $var = !$var;
+		  print "<tr $bc[$var]>";
+		  print '<td><a href="fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td>';
+		  print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">'.img_delete().'</a></td>';
+		  print '</tr>';
+		  $i++;
+		}
+	      print '</table>';
+	    }
+	  $db->free($resql);
+	}
+	else
+	{
+	  dolibarr_print_error($db);
+	}
+}
+
 ?>
\ No newline at end of file
diff --git a/htdocs/lib/contract.lib.php b/htdocs/lib/contract.lib.php
index 974e488e313cd143270297cb3e569279a1b2a1fb..f908c8782ee71305acc6961317fd0f9bd82f639c 100644
--- a/htdocs/lib/contract.lib.php
+++ b/htdocs/lib/contract.lib.php
@@ -1,4 +1,4 @@
-<?php
+<?php
 /* Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -21,41 +21,41 @@
 	    \file       htdocs/lib/contract.lib.php
 		\brief      Ensemble de fonctions de base pour le module contrat
 		\version    $Id$
-*/
-
-function contract_prepare_head($contrat)
-{
-	global $langs, $conf;
-	$h = 0;
-	$head = array();
-	
+*/
+
+function contract_prepare_head($contrat)
+{
+	global $langs, $conf;
+	$h = 0;
+	$head = array();
+	
 	$head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id;
-	$head[$h][1] = $langs->trans("ContractCard");
-	$head[$h][2] = 'card';
+	$head[$h][1] = $langs->trans("ContractCard");
+	$head[$h][2] = 'card';
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id;
 	$head[$h][1] = $langs->trans("ContractContacts");
-	$head[$h][2] = 'contact';
+	$head[$h][2] = 'contact';
 	$h++;
 
 	$head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$contrat->id;
 	$head[$h][1] = $langs->trans("Note");
-	$head[$h][2] = 'note';
+	$head[$h][2] = 'note';
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$contrat->id;
+	$head[$h][1] = $langs->trans("Documents");
+	$head[$h][2] = 'documents';
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id;
+	$head[$h][1] = $langs->trans("Info");
+	$head[$h][2] = 'info';
 	$h++;
-
-	$head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$contrat->id;
-	$head[$h][1] = $langs->trans("Documents");
-	$head[$h][2] = 'documents';
-	$h++;
-
-	$head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id;
-	$head[$h][1] = $langs->trans("Info");
-	$head[$h][2] = 'info';
-	$h++;
-
-
-	return $head;
-}
-
+
+
+	return $head;
+}
+
 ?>
\ No newline at end of file
diff --git a/htdocs/lib/doxygen.php b/htdocs/lib/doxygen.php
index 04e71cd5cd7d09ae0caa675c6f8aeb0ed16fdabe..860ea218870ae12a91eddeeec7f954e7000cb217 100644
--- a/htdocs/lib/doxygen.php
+++ b/htdocs/lib/doxygen.php
@@ -1,27 +1,27 @@
-<?php
-/* Copyright (C) 2008 Laurent Destailleur  <eldy@users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- * or see http://www.gnu.org/
- */
-
-/**
-*		\mainpage	Dolibarr project
-*		
-*		This is source documentation for Dolibarr.<br>
-*		This documentation can be built or updated running the script <b>dolibarr-doxygen-build.pl</b><br>
-*		<br>
-*		Dolibarr official web site: <a href="http://dolibarr.org">dolibarr.org</a><br>
+<?php
+/* Copyright (C) 2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * or see http://www.gnu.org/
+ */
+
+/**
+*		\mainpage	Dolibarr project
+*		
+*		This is source documentation for Dolibarr.<br>
+*		This documentation can be built or updated running the script <b>dolibarr-doxygen-build.pl</b><br>
+*		<br>
+*		Dolibarr official web site: <a href="http://dolibarr.org">dolibarr.org</a><br>
 */
\ No newline at end of file
diff --git a/htdocs/lib/lib_foot.js b/htdocs/lib/lib_foot.js
index 39fedd0fe61ea13406b99ef2cc7cb812f4b16556..5ce21a2c0517ada28ef1eb7d25d58550837f7f22 100644
--- a/htdocs/lib/lib_foot.js
+++ b/htdocs/lib/lib_foot.js
@@ -1,11 +1,11 @@
 // Copyright (C) 2005-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
-//
-// Script javascript mis en bas de page (avant fin de body)
-//
+//
+// Script javascript mis en bas de page (avant fin de body)
+//
 // \file       htdocs/lib/lib_foot.js
 // \brief      File that include javascript functions (included if option use_javascript activated)
 // \version    $Revision$
-
+
 
 /***********************************************
 * Cool DHTML tooltip script- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
@@ -81,4 +81,4 @@ function hidetip()
 
 document.onmousemove=positiontip;
 
-
+
diff --git a/htdocs/lib/tax.lib.php b/htdocs/lib/tax.lib.php
index bcaef4a0d40af55b548f16dbfbbef2e7f462c860..b2ec8c54040245633dafb0b43808a38f3be2e8cd 100644
--- a/htdocs/lib/tax.lib.php
+++ b/htdocs/lib/tax.lib.php
@@ -1,415 +1,415 @@
-<?php
-/* Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
- * Copyright (C) 2006-2007 Yannick Warnier      <ywarnier@beeznest.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-/**
-	    \file       htdocs/lib/tax.lib.php
-        \ingroup    tax
-		\brief      Library for tax module
-		\version    $Id$
-*/
-
-
-/**
- * 	\brief		Look for collectable VAT clients in the chosen year
- *	\param		db			Database handle
- *	\param		y			Year
- *	\param		modetax		0 or 1 (option vat on debit)
- *	\param		direction	'sell' or 'buy'
- *	\return		array		List of customers third parties with vat, -1 if no accountancy module, -2 if not yet developped, -3 if error
- */
-function vat_by_thirdparty($db, $y, $modetax, $direction)
-{
-	global $conf;
-
-   	$list=array();
-	//print "xx".$conf->global->MAIN_MODULE_COMPTABILITEEXPERT;
-	//print "xx".$conf->global->MAIN_MODULE_COMPTABILITE;
-
-	if ($direction == 'sell') 
-	{
-		$invoicetable='facture';
-		$invoicedettable='facturedet';
-		$fk_facture='fk_facture';
-		$total_tva='total_tva';
-	}
-	if ($direction == 'buy') 
-	{
-		$invoicetable='facture_fourn';
-		$invoicedettable='facture_fourn_det';
-		$fk_facture='fk_facture_fourn';
-		$total_tva='tva';
-	}
-
-    // Define sql request
-	$sql='';
-	if ($modetax == 1)
-    {
-        // If vat payed on due invoices (non draft)
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql = 'TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
-			$sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva,";
-			$sql.= " s.tva_assuj as assuj, s.rowid as socid";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicedettable." as fd, ".MAIN_DB_PREFIX."societe as s";
-	        $sql.= " WHERE ";
-	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
-	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
-	        $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
-	        $sql.= " GROUP BY s.rowid";
-		}
-    }
-    else
-    {
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-			// If vat payed on payments
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql = 'TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        // Tva sur factures pay�s (should be on payment)
-/*	        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
-			$sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva,";
-			$sql.= " s.tva_assuj as assuj, s.rowid as socid";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
-	        $sql.= " WHERE ";
-			$sql.= " f.fk_statut in (2)";	// Payed (partially or completely)
-			$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
-	        $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
-			$sql.= " GROUP BY s.rowid";
-*/
-			$sql = 'TODO';
-		}
-    }
-
-	if (! $sql) return -1;
-	if ($sql && $sql=='TODO') return -2;
-	if ($sql && $sql!='TODO')
-	{
-		dolibarr_syslog("Client::vat_by_customer sql=".$sql);
-	    $resql = $db->query($sql);
-	    if ($resql)
-	    {
-	    	while($assoc = $db->fetch_array($resql))
-			{
-	        	$list[] = $assoc;
-	    	}
-			$db->free($resql);
-	    	return $list;
-	    }
-	    else
-	    {
-	        dolibarr_print_error($db);
-			return -3;
-	    }
-	}
-}
-
-
-/**
- * 	\brief		Gets VAT to collect for the given month of the given year
- *				The function gets the VAT in split results, as the VAT declaration asks
- * 				to report the amounts for different VAT rates as different lines.
- * 				This function also accounts recurrent invoices
- * 	\param		db			Database handler object
- * 	\param		y			Year
- *	\param		q			Year quarter (1-4)
- *	\param		modetax		0 or 1 (option vat on debit)
- *	\param		direction	'sell' or 'buy'
- * 	\return		array		List of quarters with vat
- */
-function vat_by_quarter($db, $y, $q, $modetax, $direction)
-{
-	global $conf;
-
-	$list=array();
-
-	if ($direction == 'sell') 
-	{
-		$invoicetable='facture';
-		$invoicedettable='facturedet';
-		$fk_facture='fk_facture';
-		$fk_facture2='fk_facture';
-		$fk_payment='fk_paiement';
-		$total_tva='total_tva';
-		$paymenttable='paiement';
-		$paymentfacturetable='paiement_facture';
-	}
-	if ($direction == 'buy') 
-	{
-		$invoicetable='facture_fourn';
-		$invoicedettable='facture_fourn_det';
-		$fk_facture='fk_facture_fourn';
-		$fk_facture2='fk_facturefourn';
-		$fk_payment='fk_paiementfourn';
-		$total_tva='tva';
-		$paymenttable='paiementfourn';
-		$paymentfacturetable='paiementfourn_facturefourn';
-	}
-	
-    // CAS DES BIENS
-	
-	// Define sql request
-	$sql='';
-	if ($modetax == 1)
-    {
-        // If vat payed on due invoices (non draft)
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql='TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
-			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
-			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
-	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
-	        $sql.= " WHERE ";
-	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
-	        $sql.= " AND f.rowid = d.".$fk_facture;
-	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
-	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
-	        $sql.= " AND d.product_type = 0";		// Limit to products
-	        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
-		}
-    }
-    else
-    {
-        // If vat payed on payments
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql='TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        // Tva sur factures pay�s (should be on payment)
-	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
-			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
-			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
-	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
-	        $sql.= " WHERE ";
-			$sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
-	        $sql.= " AND f.rowid = d.".$fk_facture;
-	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
-	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
-	        $sql.= " AND d.product_type = 0";		// Limit to products
-			$sql.= " ORDER BY d.rowid, d.".$fk_facture;
-		}
-    }
-
-	if (! $sql) return -1;
-	if ($sql && $sql=='TODO') return -2;
-	if ($sql && $sql!='TODO')
-	{
-		dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
-	    $resql = $db->query($sql);
-	    if ($resql)
-	    {
-	    	$rate = -1;
-			$oldrowid='';
-	    	while($assoc = $db->fetch_array($resql))
-	    	{
-	    		if (! isset($list[$assoc['rate']]['totalht']))  $list[$assoc['rate']]['total_ht']=0;
-	    		if (! isset($list[$assoc['rate']]['vat']))      $list[$assoc['rate']]['total_vat']=0;
-
-				if ($assoc['rowid'] != $oldrowid)		// Si rupture sur d.rowid
-				{
-					$oldrowid=$assoc['rowid'];
-					$list[$assoc['rate']]['totalht']  += $assoc['total_ht'];
-					$list[$assoc['rate']]['vat']      += $assoc['total_vat'];
-				}
-				$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
-				$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
-
-				$list[$assoc['rate']]['facid'][] = $assoc['facid'];
-				$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
-				$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
-				$list[$assoc['rate']]['descr'][] = $assoc['descr'];
-
-				$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
-				$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
-
-				$list[$assoc['rate']]['pid'][] = $assoc['pid'];
-				$list[$assoc['rate']]['pref'][] = $assoc['pref'];
-				$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
-
-				$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
-				$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
-				
-	    		$rate = $assoc['rate'];
-	    	}
-	    }
-	    else
-	    {
-	        dolibarr_print_error($db);
-			return -3;
-	    }
-	}
-
-
-	// CAS DES SERVICES
-	
-	// Define sql request
-	$sql='';
-	if ($modetax == 1)	// Option vat on debit
-    {
-        // If vat payed on due invoices (non draft)
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql='TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
-			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
-			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
-	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
-	        $sql.= " WHERE ";
-	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
-	        $sql.= " AND f.rowid = d.".$fk_facture;
-	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
-	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
-	        $sql.= " AND d.product_type = 1";		// Limit to services
-	        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
-		}
-    }
-    else
-    {
-        // If vat payed on payments
-		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
-		{
-	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
-	        // n'est pas stock� dans la table des payments.
-	        // Seul le module compta expert peut r�soudre ce probl�me.
-	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
-	        // detail part tva et part ht).
-			$sql='TODO';
-		}
-		if ($conf->global->MAIN_MODULE_COMPTABILITE)
-		{
-	        // Tva sur factures pay�s (should be on payment)
-	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
-			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
-			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
-			$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount";
-	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
-	        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
-	        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
-	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
-			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
-	        $sql.= " WHERE ";
-			$sql.= " f.fk_statut in (1,2)";	// Payed (partially or completely)
-	        $sql.= " AND f.rowid = d.".$fk_facture;;
-	        $sql.= " AND pf.".$fk_facture2." = f.rowid";
-	        $sql.= " AND pa.rowid = pf.".$fk_payment;
-	        $sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'";
-	        $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
-	        $sql.= " AND d.product_type = 1";		// Limit to services
-			$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
-		}
-    }
-
-	if (! $sql) return -1;
-	if ($sql && $sql=='TODO') return -2;
-	if ($sql && $sql!='TODO')
-	{
-		dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
-	    $resql = $db->query($sql);
-	    if ($resql)
-	    {
-	    	$rate = -1;
-			$oldrowid='';
-	    	while($assoc = $db->fetch_array($resql))
-	    	{
-	    		if (! isset($list[$assoc['rate']]['totalht']))  $list[$assoc['rate']]['total_ht']=0;
-	    		if (! isset($list[$assoc['rate']]['vat']))      $list[$assoc['rate']]['total_vat']=0;
-
-				if ($assoc['rowid'] != $oldrowid)		// Si rupture sur d.rowid
-				{
-					$oldrowid=$assoc['rowid'];
-					$list[$assoc['rate']]['totalht']  += $assoc['total_ht'];
-					$list[$assoc['rate']]['vat']      += $assoc['total_vat'];
-				}
-				$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
-				$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
-				
-				$list[$assoc['rate']]['facid'][] = $assoc['facid'];
-				$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
-				$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
-				$list[$assoc['rate']]['descr'][] = $assoc['descr'];
-
-				$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
-				$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
-
-				$list[$assoc['rate']]['pid'][] = $assoc['pid'];
-				$list[$assoc['rate']]['pref'][] = $assoc['pref'];
-				$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
-
-				$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
-				$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
-
-	    		$rate = $assoc['rate'];
-	    	}
-	    }
-	    else
-	    {
-	        dolibarr_print_error($db);
-			return -3;
-	    }
-	}
-	
-	return $list;
-}
-
+<?php
+/* Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
+ * Copyright (C) 2006-2007 Yannick Warnier      <ywarnier@beeznest.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+	    \file       htdocs/lib/tax.lib.php
+        \ingroup    tax
+		\brief      Library for tax module
+		\version    $Id$
+*/
+
+
+/**
+ * 	\brief		Look for collectable VAT clients in the chosen year
+ *	\param		db			Database handle
+ *	\param		y			Year
+ *	\param		modetax		0 or 1 (option vat on debit)
+ *	\param		direction	'sell' or 'buy'
+ *	\return		array		List of customers third parties with vat, -1 if no accountancy module, -2 if not yet developped, -3 if error
+ */
+function vat_by_thirdparty($db, $y, $modetax, $direction)
+{
+	global $conf;
+
+   	$list=array();
+	//print "xx".$conf->global->MAIN_MODULE_COMPTABILITEEXPERT;
+	//print "xx".$conf->global->MAIN_MODULE_COMPTABILITE;
+
+	if ($direction == 'sell') 
+	{
+		$invoicetable='facture';
+		$invoicedettable='facturedet';
+		$fk_facture='fk_facture';
+		$total_tva='total_tva';
+	}
+	if ($direction == 'buy') 
+	{
+		$invoicetable='facture_fourn';
+		$invoicedettable='facture_fourn_det';
+		$fk_facture='fk_facture_fourn';
+		$total_tva='tva';
+	}
+
+    // Define sql request
+	$sql='';
+	if ($modetax == 1)
+    {
+        // If vat payed on due invoices (non draft)
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql = 'TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
+			$sql.= " sum(fd.total_ht) as amount, sum(fd.".$total_tva.") as tva,";
+			$sql.= " s.tva_assuj as assuj, s.rowid as socid";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicedettable." as fd, ".MAIN_DB_PREFIX."societe as s";
+	        $sql.= " WHERE ";
+	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
+	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
+	        $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
+	        $sql.= " GROUP BY s.rowid";
+		}
+    }
+    else
+    {
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+			// If vat payed on payments
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql = 'TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        // Tva sur factures pay�s (should be on payment)
+/*	        $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
+			$sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva,";
+			$sql.= " s.tva_assuj as assuj, s.rowid as socid";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
+	        $sql.= " WHERE ";
+			$sql.= " f.fk_statut in (2)";	// Payed (partially or completely)
+			$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
+	        $sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
+			$sql.= " GROUP BY s.rowid";
+*/
+			$sql = 'TODO';
+		}
+    }
+
+	if (! $sql) return -1;
+	if ($sql && $sql=='TODO') return -2;
+	if ($sql && $sql!='TODO')
+	{
+		dolibarr_syslog("Client::vat_by_customer sql=".$sql);
+	    $resql = $db->query($sql);
+	    if ($resql)
+	    {
+	    	while($assoc = $db->fetch_array($resql))
+			{
+	        	$list[] = $assoc;
+	    	}
+			$db->free($resql);
+	    	return $list;
+	    }
+	    else
+	    {
+	        dolibarr_print_error($db);
+			return -3;
+	    }
+	}
+}
+
+
+/**
+ * 	\brief		Gets VAT to collect for the given month of the given year
+ *				The function gets the VAT in split results, as the VAT declaration asks
+ * 				to report the amounts for different VAT rates as different lines.
+ * 				This function also accounts recurrent invoices
+ * 	\param		db			Database handler object
+ * 	\param		y			Year
+ *	\param		q			Year quarter (1-4)
+ *	\param		modetax		0 or 1 (option vat on debit)
+ *	\param		direction	'sell' or 'buy'
+ * 	\return		array		List of quarters with vat
+ */
+function vat_by_quarter($db, $y, $q, $modetax, $direction)
+{
+	global $conf;
+
+	$list=array();
+
+	if ($direction == 'sell') 
+	{
+		$invoicetable='facture';
+		$invoicedettable='facturedet';
+		$fk_facture='fk_facture';
+		$fk_facture2='fk_facture';
+		$fk_payment='fk_paiement';
+		$total_tva='total_tva';
+		$paymenttable='paiement';
+		$paymentfacturetable='paiement_facture';
+	}
+	if ($direction == 'buy') 
+	{
+		$invoicetable='facture_fourn';
+		$invoicedettable='facture_fourn_det';
+		$fk_facture='fk_facture_fourn';
+		$fk_facture2='fk_facturefourn';
+		$fk_payment='fk_paiementfourn';
+		$total_tva='tva';
+		$paymenttable='paiementfourn';
+		$paymentfacturetable='paiementfourn_facturefourn';
+	}
+	
+    // CAS DES BIENS
+	
+	// Define sql request
+	$sql='';
+	if ($modetax == 1)
+    {
+        // If vat payed on due invoices (non draft)
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql='TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
+			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
+			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
+	        $sql.= " WHERE ";
+	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
+	        $sql.= " AND f.rowid = d.".$fk_facture;
+	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
+	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
+	        $sql.= " AND d.product_type = 0";		// Limit to products
+	        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
+		}
+    }
+    else
+    {
+        // If vat payed on payments
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql='TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        // Tva sur factures pay�s (should be on payment)
+	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
+			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
+			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
+	        $sql.= " WHERE ";
+			$sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
+	        $sql.= " AND f.rowid = d.".$fk_facture;
+	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
+	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
+	        $sql.= " AND d.product_type = 0";		// Limit to products
+			$sql.= " ORDER BY d.rowid, d.".$fk_facture;
+		}
+    }
+
+	if (! $sql) return -1;
+	if ($sql && $sql=='TODO') return -2;
+	if ($sql && $sql!='TODO')
+	{
+		dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
+	    $resql = $db->query($sql);
+	    if ($resql)
+	    {
+	    	$rate = -1;
+			$oldrowid='';
+	    	while($assoc = $db->fetch_array($resql))
+	    	{
+	    		if (! isset($list[$assoc['rate']]['totalht']))  $list[$assoc['rate']]['total_ht']=0;
+	    		if (! isset($list[$assoc['rate']]['vat']))      $list[$assoc['rate']]['total_vat']=0;
+
+				if ($assoc['rowid'] != $oldrowid)		// Si rupture sur d.rowid
+				{
+					$oldrowid=$assoc['rowid'];
+					$list[$assoc['rate']]['totalht']  += $assoc['total_ht'];
+					$list[$assoc['rate']]['vat']      += $assoc['total_vat'];
+				}
+				$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
+				$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
+
+				$list[$assoc['rate']]['facid'][] = $assoc['facid'];
+				$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
+				$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
+				$list[$assoc['rate']]['descr'][] = $assoc['descr'];
+
+				$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
+				$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
+
+				$list[$assoc['rate']]['pid'][] = $assoc['pid'];
+				$list[$assoc['rate']]['pref'][] = $assoc['pref'];
+				$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
+
+				$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
+				$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
+				
+	    		$rate = $assoc['rate'];
+	    	}
+	    }
+	    else
+	    {
+	        dolibarr_print_error($db);
+			return -3;
+	    }
+	}
+
+
+	// CAS DES SERVICES
+	
+	// Define sql request
+	$sql='';
+	if ($modetax == 1)	// Option vat on debit
+    {
+        // If vat payed on due invoices (non draft)
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql='TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
+			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
+			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
+	        $sql.= " WHERE ";
+	        $sql.= " f.fk_statut in (1,2)";	// Validated or payed (partially or completely)
+	        $sql.= " AND f.rowid = d.".$fk_facture;
+	        $sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
+	        $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
+	        $sql.= " AND d.product_type = 1";		// Limit to services
+	        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
+		}
+    }
+    else
+    {
+        // If vat payed on payments
+		if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
+		{
+	        // \todo a ce jour on se sait pas la compter car le montant tva d'un payment
+	        // n'est pas stock� dans la table des payments.
+	        // Seul le module compta expert peut r�soudre ce probl�me.
+	        // (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
+	        // detail part tva et part ht).
+			$sql='TODO';
+		}
+		if ($conf->global->MAIN_MODULE_COMPTABILITE)
+		{
+	        // Tva sur factures pay�s (should be on payment)
+	        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
+			$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
+			$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
+			$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount";
+	        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
+	        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
+	        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
+	        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
+			$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
+	        $sql.= " WHERE ";
+			$sql.= " f.fk_statut in (1,2)";	// Payed (partially or completely)
+	        $sql.= " AND f.rowid = d.".$fk_facture;;
+	        $sql.= " AND pf.".$fk_facture2." = f.rowid";
+	        $sql.= " AND pa.rowid = pf.".$fk_payment;
+	        $sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'";
+	        $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
+	        $sql.= " AND d.product_type = 1";		// Limit to services
+			$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
+		}
+    }
+
+	if (! $sql) return -1;
+	if ($sql && $sql=='TODO') return -2;
+	if ($sql && $sql!='TODO')
+	{
+		dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
+	    $resql = $db->query($sql);
+	    if ($resql)
+	    {
+	    	$rate = -1;
+			$oldrowid='';
+	    	while($assoc = $db->fetch_array($resql))
+	    	{
+	    		if (! isset($list[$assoc['rate']]['totalht']))  $list[$assoc['rate']]['total_ht']=0;
+	    		if (! isset($list[$assoc['rate']]['vat']))      $list[$assoc['rate']]['total_vat']=0;
+
+				if ($assoc['rowid'] != $oldrowid)		// Si rupture sur d.rowid
+				{
+					$oldrowid=$assoc['rowid'];
+					$list[$assoc['rate']]['totalht']  += $assoc['total_ht'];
+					$list[$assoc['rate']]['vat']      += $assoc['total_vat'];
+				}
+				$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
+				$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
+				
+				$list[$assoc['rate']]['facid'][] = $assoc['facid'];
+				$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
+				$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
+				$list[$assoc['rate']]['descr'][] = $assoc['descr'];
+
+				$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
+				$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
+
+				$list[$assoc['rate']]['pid'][] = $assoc['pid'];
+				$list[$assoc['rate']]['pref'][] = $assoc['pref'];
+				$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
+
+				$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
+				$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
+
+	    		$rate = $assoc['rate'];
+	    	}
+	    }
+	    else
+	    {
+	        dolibarr_print_error($db);
+			return -3;
+	    }
+	}
+	
+	return $list;
+}
+
 ?>
\ No newline at end of file
diff --git a/htdocs/lib/treeview.lib.php b/htdocs/lib/treeview.lib.php
index 35c43b1fc0342ccaf8955da62ca3e603365b7e71..04f682beda34c6a21c89a7e93d95b0d5dd7d2f6e 100644
--- a/htdocs/lib/treeview.lib.php
+++ b/htdocs/lib/treeview.lib.php
@@ -91,6 +91,8 @@ function tree_showpad(&$fulltree,$key,$selected=0)
 
 		$atleastonofthislevelafter=0;
 		$nbofhigherlevelafter=0;
+		$nbofdirinsub=0;
+		$nbofdocinsub=0;
 		$found=0;
 		//print 'x'.$key;
 		foreach($fulltree as $key2 => $val2)
@@ -99,6 +101,8 @@ function tree_showpad(&$fulltree,$key,$selected=0)
 			{
 				if ($fulltree[$key2]['level'] > $pos)
 				{
+					$nbofdirinsub++;
+					$nbofdocinsub+=$fulltree[$key2]['cachenbofdoc'];
 					$nbofhigherlevelafter++;
 				} 
 				if ($fulltree[$key2]['level'] == $pos)
@@ -110,7 +114,10 @@ function tree_showpad(&$fulltree,$key,$selected=0)
 					break;
 				} 
 			}
-			if ($key2 == $key) $found=1;	
+			if ($key2 == $key) 
+			{
+				$found=1;
+			}
 		}
 		//print $atleastonofthislevelafter;
 		
@@ -127,7 +134,7 @@ function tree_showpad(&$fulltree,$key,$selected=0)
 		$pos++;
 	}
 	
-	return array($atleastonofthislevelafter,$nbofhigherlevelafter);
+	return array($atleastonofthislevelafter,$nbofhigherlevelafter,$nbofdirinsub,$nbofdocinsub);
 }