Browse Source

Created a method generateDocument for several classes
Which are: Commande, Contrat, Livraison, Facture, Projet, Propal, Task, Expedition, CommandeFournisseur, FactureFournisseur and therefore deprecated the following methods supplier_order_pdf_create, supplier_invoice_pdf_create, delivery_order_pdf_create, task_pdf_create, propale_pdf_create, project_pdf_create, facture_pdf_create, expedition_pdf_create, commande_pdf_create

Marcos García de La Fuente 11 years ago
parent
commit
e71dc6bc32

+ 104 - 0
htdocs/comm/propal/class/propal.class.php

@@ -10,6 +10,7 @@
  * Copyright (C) 2010-2011 Philippe Grand			<philippe.grand@atoo-net.com>
  * Copyright (C) 2012-214  Christophe Battarel  	<christophe.battarel@altairis.fr>
  * Copyright (C) 2013      Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2014      Marcos García            <marcosgdf@gmail.com>
  *
  * 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
@@ -2673,6 +2674,109 @@ class Propal extends CommonObject
         }
     }
 
+	/**
+	 *  Create a document onto disk according to template module.
+	 *
+	 * 	@param	    string		$modele			Force model to use ('' to not force)
+	 * 	@param		Translate	$outputlangs	Object langs to use for output
+	 *  @param      int			$hidedetails    Hide details of lines
+	 *  @param      int			$hidedesc       Hide description
+	 *  @param      int			$hideref        Hide ref
+	 * 	@return     int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf,$user,$langs;
+
+		$langs->load("propale");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne le modele sur le nom du modele a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->PROPALE_ADDON_PDF))
+			{
+				$modele = $conf->global->PROPALE_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'azur';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/propale/doc/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+			//$obj->message = $message;
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// We delete old preview
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"propal_pdf_create Error: ".$obj->error);
+				return -1;
+			}
+
+		}
+		else
+		{
+			dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
+			return -1;
+		}
+	}
+
+
 }
 
 

+ 103 - 0
htdocs/commande/class/commande.class.php

@@ -7,6 +7,7 @@
  * Copyright (C) 2011      Jean Heimburger      <jean@tiaris.info>
  * Copyright (C) 2012      Christophe Battarel  <christophe.battarel@altairis.fr>
  * Copyright (C) 2013      Florian Henry		<florian.henry@open-concept.pro>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -3011,6 +3012,108 @@ class Commande extends CommonOrder
         }
     }
 
+	/**
+	 *  Create a document onto disk accordign to template module.
+	 *
+	 *  @param	    string		$modele			Force le mnodele a utiliser ('' to not force)
+	 *  @param		Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @param      int			$hidedetails    Hide details of lines
+	 *  @param      int			$hidedesc       Hide description
+	 *  @param      int			$hideref        Hide ref
+	 *  @return     int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf,$user,$langs,$hookmanager;
+
+		$langs->load("orders");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne le modele sur le nom du modele a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->COMMANDE_ADDON_PDF))
+			{
+				$modele = $conf->global->COMMANDE_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'einstein';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/commande/doc/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+			//$obj->message = $message;
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// We delete old preview
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"order_pdf_create Error: ".$obj->error);
+				return -1;
+			}
+
+		}
+		else
+		{
+			dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
+			return -1;
+		}
+	}
+
 }
 
 

+ 110 - 1
htdocs/compta/facture/class/facture.class.php

@@ -9,7 +9,7 @@
  * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  * Copyright (C) 2010-2014 Juanjo Menent         <jmenent@2byte.es>
  * Copyright (C) 2012      Christophe Battarel   <christophe.battarel@altairis.fr>
- * Copyright (C) 2012      Marcos García         <marcosgdf@gmail.com>
+ * Copyright (C) 2012-2014 Marcos García         <marcosgdf@gmail.com>
  * Copyright (C) 2013      Cedric Gross          <c.gross@kreiz-it.fr>
  * Copyright (C) 2013      Florian Henry		  	<florian.henry@open-concept.pro>
  *
@@ -3222,6 +3222,115 @@ class Facture extends CommonInvoice
 		}
 	}
 
+	/**
+	 *  Create a document onto disk according to template module.
+	 *
+	 *	@param	string		$modele			Force template to use ('' to not force)
+	 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @param  int			$hidedetails    Hide details of lines
+	 *  @param  int			$hidedesc       Hide description
+	 *  @param  int			$hideref        Hide ref
+	 *	@return int        					<0 if KO, >0 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf,$user,$langs;
+
+		$langs->load("bills");
+
+		$error=0;
+
+		// Increase limit for PDF build
+		$err=error_reporting();
+		error_reporting(0);
+		@set_time_limit(120);
+		error_reporting($err);
+
+		$srctemplatepath='';
+
+		// Positionne le modele sur le nom du modele a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->FACTURE_ADDON_PDF))
+			{
+				$modele = $conf->global->FACTURE_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'crabe';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/facture/doc/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// We delete old preview
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"facture_pdf_create Error: ".$obj->error);
+				return -1;
+			}
+
+		}
+		else
+		{
+			dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
+			return -1;
+		}
+	}
+
+
+
 }
 
 

+ 100 - 0
htdocs/contrat/class/contrat.class.php

@@ -7,6 +7,7 @@
  * Copyright (C) 2010-2014	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013       Christophe Battarel  <christophe.battarel@altairis.fr>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2014       Marcos García           <marcosgdf@gmail.com>
  *
  * 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
@@ -2339,6 +2340,105 @@ class ContratLigne extends CommonObject
 		}
 	}
 
+	/**
+	 *  Create a contract document on disk using template defined into CONTRACT_ADDON_PDF
+	 *
+	 *  @param	string		$modele			force le modele a utiliser ('' par defaut)
+	 *  @param	Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @param  int			$hidedetails    Hide details of lines
+	 *  @param  int			$hidedesc       Hide description
+	 *  @param  int			$hideref        Hide ref
+	 *  @return int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf,$langs,$user,$hookmanager;
+
+		$langs->load("contracts");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne modele sur le nom du modele de contrat a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->CONTRACT_ADDON_PDF))
+			{
+				$modele = $conf->global->CONTRACT_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'strato';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/contract/doc/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// We delete old preview
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"contract_pdf_create Error: ".$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			return 0;
+		}
+	}
 }
 
 

+ 4 - 88
htdocs/core/modules/commande/modules_commande.php

@@ -5,6 +5,7 @@
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2012      Juanjo Menent	    <jmenent@2byte.es>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -159,94 +160,9 @@ abstract class ModeleNumRefCommandes
  *  @param      int			$hidedesc       Hide description
  *  @param      int			$hideref        Hide ref
  *  @return     int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Commande class
  */
-function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function commande_pdf_create(DoliDB $db, Commande $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$user,$langs,$hookmanager;
-	$langs->load("orders");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne le modele sur le nom du modele a utiliser
-	if (! dol_strlen($modele))
-	{
-	    if (! empty($conf->global->COMMANDE_ADDON_PDF))
-	    {
-	        $modele = $conf->global->COMMANDE_ADDON_PDF;
-	    }
-	    else
-	    {
-	        $modele = 'einstein';
-	    }
-	}
-
-    // If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/commande/doc/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-		//$obj->message = $message;
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// We delete old preview
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"order_pdf_create Error: ".$obj->error);
-			return -1;
-		}
-
-	}
-	else
-	{
-		dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
-		return -1;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }

+ 4 - 86
htdocs/core/modules/contract/modules_contract.php

@@ -6,6 +6,7 @@
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2011      Juanjo Menent	    <jmenent@2byte.es>
  * Copyright (C) 2013      Philippe Grand	    <philippe.grand@atoo-net.com>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -154,92 +155,9 @@ class ModelNumRefContracts
  *  @param  int			$hidedesc       Hide description
  *  @param  int			$hideref        Hide ref
  *  @return int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Contrat class
  */
-function contract_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function contract_pdf_create(DoliDB $db, Contrat $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$langs,$user,$hookmanager;
-	$langs->load("contracts");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne modele sur le nom du modele de contrat a utiliser
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->CONTRACT_ADDON_PDF))
-		{
-			$modele = $conf->global->CONTRACT_ADDON_PDF;
-		}
-		else
-		{
-			$modele = 'strato';
-		}
-	}
-
-	// If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/contract/doc/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// We delete old preview
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"contract_pdf_create Error: ".$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }

+ 4 - 94
htdocs/core/modules/expedition/modules_expedition.php

@@ -6,6 +6,7 @@
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2011      Juanjo Menent	    <jmenent@2byte.es>
  * Copyright (C) 2011-2013 Philippe Grand       <philippe.grand@atoo-net.com>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -149,100 +150,9 @@ abstract class ModelNumRefExpedition
  * 	@param	string		$modele			Force le modele a utiliser ('' to not force)
  * 	@param	Translate	$outputlangs	Objet lang a utiliser pour traduction
  *  @return int             			<=0 if KO, >0 if OK
+ * @deprecated Use the new function generateDocument of Expedition class
  */
-function expedition_pdf_create($db, $object, $modele, $outputlangs)
+function expedition_pdf_create(DoliDB $db, Expedition $object, $modele, $outputlangs)
 {
-	global $conf,$user,$langs;
-
-	$langs->load("sendings");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Sets the model on the model name to use
-	if (! dol_strlen($modele))
-	{
-	    if (! empty($conf->global->EXPEDITION_ADDON_PDF))
-	    {
-	        $modele = $conf->global->EXPEDITION_ADDON_PDF;
-	    }
-	    else
-	    {
-	        $modele = 'rouget';
-	    }
-	}
-
-	// If selected model is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// We check the model location
-	        $file=dol_buildpath($reldir."core/modules/expedition/doc/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Load the model
-	if ($filefound)
-	{
-	    require_once $file;
-
-		$obj = new $classname($db);
-
-		$result=$object->fetch_origin();
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	//require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			//dol_delete_preview($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_syslog("Erreur dans expedition_pdf_create");
-			dol_print_error($db,$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		if (! $conf->global->EXPEDITION_ADDON_PDF)
-		{
-			print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined");
-		}
-		else
-		{
-			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		}
-		return 0;
-    }
+	return $object->generateDocument($modele, $outputlangs);
 }

+ 4 - 94
htdocs/core/modules/facture/modules_facture.php

@@ -3,6 +3,7 @@
  * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -154,101 +155,10 @@ abstract class ModeleNumRefFactures
  *  @param  int			$hidedesc       Hide description
  *  @param  int			$hideref        Hide ref
  *	@return int        					<0 if KO, >0 if OK
+ * @deprecated Use the new function generateDocument of Facture class
  */
-function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function facture_pdf_create(DoliDB $db, Facture $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$user,$langs;
-
-	$langs->load("bills");
-
-	$error=0;
-
-	// Increase limit for PDF build
-    $err=error_reporting();
-    error_reporting(0);
-    @set_time_limit(120);
-    error_reporting($err);
-
-    $srctemplatepath='';
-
-	// Positionne le modele sur le nom du modele a utiliser
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->FACTURE_ADDON_PDF))
-		{
-			$modele = $conf->global->FACTURE_ADDON_PDF;
-		}
-		else
-		{
-			$modele = 'crabe';
-		}
-	}
-
-    // If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/facture/doc/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// We delete old preview
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"facture_pdf_create Error: ".$obj->error);
-			return -1;
-		}
-
-	}
-	else
-	{
-		dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
-		return -1;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
 

+ 4 - 85
htdocs/core/modules/livraison/modules_livraison.php

@@ -4,6 +4,7 @@
  * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
  * Copyright (C) 2006-2011 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2011-2012 Philippe Grand	    <philippe.grand@atoo-net.com>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -154,92 +155,10 @@ abstract class ModeleNumRefDeliveryOrder
  *	@param	string		$modele			force le modele a utiliser ('' to not force)
  *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
  *  @return int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Livraison class
  */
-function delivery_order_pdf_create($db, $object, $modele, $outputlangs='')
+function delivery_order_pdf_create(DoliDB $db, Livraison $object, $modele, $outputlangs='')
 {
-	global $conf,$user,$langs;
-
-	$langs->load("deliveries");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne modele sur le nom du modele de bon de livraison a utiliser
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->LIVRAISON_ADDON_PDF))
-		{
-			$modele = $conf->global->LIVRAISON_ADDON_PDF;
-		}
-		else
-		{
-			$modele = 'typhon';
-		}
-	}
-
-	// If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/livraison/pdf/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object,$outputlangs) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_syslog("Erreur dans delivery_order_pdf_create");
-			dol_print_error($db,$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs);
 }
 

+ 4 - 86
htdocs/core/modules/project/modules_project.php

@@ -1,5 +1,6 @@
 <?php
 /* Copyright (C) 2010-2014	Regis Houssin	<regis.houssin@capnetworks.com>
+ * Copyright (C) 2014       Marcos García   <marcosgdf@gmail.com>
  *
  * 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
@@ -151,93 +152,10 @@ abstract class ModeleNumRefProjects
  *  @param  int			$hidedesc       Hide description
  *  @param  int			$hideref        Hide ref
  *  @return int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Project class
  */
-function project_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function project_pdf_create(DoliDB $db, Project $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$langs;
-	$langs->load("projects");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne modele sur le nom du modele de projet a utiliser
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->PROJECT_ADDON_PDF))
-		{
-			$modele = $conf->global->PROJECT_ADDON_PDF;
-		}
-		else
-		{
-			$modele='baleine';
-		}
-	}
-
-	// If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/project/pdf/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"project_pdf_create Error: ".$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
 

+ 4 - 85
htdocs/core/modules/project/task/modules_task.php

@@ -1,6 +1,7 @@
 <?php
 /* Copyright (C) 2010 Regis Houssin  <regis.houssin@capnetworks.com>
  * Copyright (C) 2010 Florian Henry  <florian.henry<àopen-concept.pro>
+ * Copyright (C) 2014 Marcos García  <marcosgdf@gmail.com>
  *
  * 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
@@ -152,92 +153,10 @@ abstract class ModeleNumRefTask
  *  @param  int			$hideref        Hide ref
  *  @param  HookManager	$hookmanager	Hook manager instance
  *  @return int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Task class
  */
-function task_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
+function task_pdf_create(DoliDB $db, Task $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
 {
-	global $conf,$langs;
-	$langs->load("projects");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne modele sur le nom du modele de projet a utiliser
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->PROJECT_TASK_ADDON_PDF))
-		{
-			$modele = $conf->global->PROJECT_TASK_ADDON_PDF;
-		}
-		else
-		{
-			$modele='nodefault';
-		}
-	}
-
-	// If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/project/task/pdf/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"task_pdf_create Error: ".$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 }
 

+ 4 - 88
htdocs/core/modules/propale/modules_propale.php

@@ -3,6 +3,7 @@
  * Copyright (C) 2004-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2012      Juanjo Menent		<jmenent@2byte.es>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -155,95 +156,10 @@ abstract class ModeleNumRefPropales
  *  @param      int			$hidedesc       Hide description
  *  @param      int			$hideref        Hide ref
  * 	@return     int         				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of Propal class
  */
-function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function propale_pdf_create(DoliDB $db, Propal $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf,$user,$langs;
-	$langs->load("propale");
-
-	$error=0;
-
-	$srctemplatepath='';
-
-	// Positionne le modele sur le nom du modele a utiliser
-	if (! dol_strlen($modele))
-	{
-	    if (! empty($conf->global->PROPALE_ADDON_PDF))
-	    {
-	        $modele = $conf->global->PROPALE_ADDON_PDF;
-	    }
-	    else
-	    {
-	        $modele = 'azur';
-	    }
-	}
-
-    // If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-    	foreach(array('doc','pdf') as $prefix)
-    	{
-    	    $file = $prefix."_".$modele.".modules.php";
-
-    		// On verifie l'emplacement du modele
-	        $file=dol_buildpath($reldir."core/modules/propale/doc/".$file,0);
-    		if (file_exists($file))
-    		{
-    			$filefound=1;
-    			$classname=$prefix.'_'.$modele;
-    			break;
-    		}
-    	}
-    	if ($filefound) break;
-    }
-
-	// Charge le modele
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db);
-		//$obj->message = $message;
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// We delete old preview
-			require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			// Success in building document. We build meta file.
-			dol_meta_create($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_print_error($db,"propal_pdf_create Error: ".$obj->error);
-			return -1;
-		}
-
-	}
-	else
-	{
-		dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
-		return -1;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
 

+ 3 - 97
htdocs/core/modules/supplier_invoice/modules_facturefournisseur.php

@@ -2,6 +2,7 @@
 /* Copyright (C) 2010	Juanjo Menent	<jmenent@2byte.es>
  * Copyright (C) 2012	Regis Houssin	<regis.houssin@capnetworks.com>
  * Copyright (C) 2013   Philippe Grand  <philippe.grand@atoo-net.com>
+ * Copyright (C) 2014   Marcos García   <marcosgdf@gmail.com>
  *
  * 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
@@ -143,105 +144,10 @@ abstract class ModeleNumRefSuppliersInvoices
  *  @param      int			$hidedesc       Hide description
  *  @param      int			$hideref        Hide ref
  *  @return     int         				0 if KO, 1 if OK
+ *
  */
 function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf, $user, $langs;
-
-	$langs->load("suppliers");
-
-	$error=0;
-
-	// Increase limit for PDF build
-    $err=error_reporting();
-    error_reporting(0);
-    @set_time_limit(120);
-    error_reporting($err);
-
-    $srctemplatepath='';
-
-	// Set the model on the model name to use
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
-		{
-			$modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
-		}
-		else
-		{
-		    $modele = 'canelle';
-		}
-	}
-
-    // If selected modele is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-    if (! empty($tmp[1]))
-    {
-        $modele=$tmp[0];
-        $srctemplatepath=$tmp[1];
-    }
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-		foreach(array('doc','pdf') as $prefix)
-		{
-			$file = $prefix."_".$modele.".modules.php";
-
-			// We checked the location of the model
-			$file=dol_buildpath($reldir."core/modules/supplier_invoice/pdf/".$file,0);
-			if (file_exists($file))
-			{
-				$filefound=1;
-				$classname=$prefix.'_'.$modele;
-				break;
-			}
-		}
-		if ($filefound) break;
-	}
-
-	// Load the model
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db,$object);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_syslog("Erreur dans supplier_invoice_pdf_create");
-			dol_print_error($db,$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		if (! $conf->global->INVOICE_SUPPLIER_ADDON_PDF)
-		{
-			print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined");
-		}
-		else
-		{
-			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		}
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
 

+ 4 - 97
htdocs/core/modules/supplier_order/modules_commandefournisseur.php

@@ -5,6 +5,7 @@
  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  * Copyright (C) 2011-2013 Philippe Grand       <philippe.grand@atoo-net.com>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -149,104 +150,10 @@ abstract class ModeleNumRefSuppliersOrders
  *  @param      int			$hidedesc       Hide description
  *  @param      int			$hideref        Hide ref
  *  @return     int          				0 if KO, 1 if OK
+ * @deprecated Use the new function generateDocument of CommandeFournisseur class
  */
-function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+function supplier_order_pdf_create(DoliDB $db, CommandeFournisseur $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
 {
-	global $conf, $user, $langs;
-	$langs->load("suppliers");
-
-	$error=0;
-
-	// Increase limit for PDF build
-	$err=error_reporting();
-	error_reporting(0);
-	@set_time_limit(120);
-	error_reporting($err);
-
-	$srctemplatepath='';
-
-	// Sets the model on the model name to use
-	if (! dol_strlen($modele))
-	{
-		if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF))
-		{
-			$modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
-		}
-		else
-		{
-			$modele = 'muscadet';
-		}
-	}
-
-	// If selected model is a filename template (then $modele="modelname:filename")
-	$tmp=explode(':',$modele,2);
-	if (! empty($tmp[1]))
-	{
-		$modele=$tmp[0];
-		$srctemplatepath=$tmp[1];
-	}
-
-	// Search template files
-	$file=''; $classname=''; $filefound=0;
-	$dirmodels=array('/');
-	if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
-	foreach($dirmodels as $reldir)
-	{
-		foreach(array('doc','pdf') as $prefix)
-		{
-			$file = $prefix."_".$modele.".modules.php";
-
-			// We check the model location
-			$file=dol_buildpath($reldir."core/modules/supplier_order/pdf/".$file,0);
-			if (file_exists($file))
-			{
-				$filefound=1;
-				$classname=$prefix.'_'.$modele;
-				break;
-			}
-		}
-		if ($filefound) break;
-	}
-
-	// Load the model
-	if ($filefound)
-	{
-		require_once $file;
-
-		$obj = new $classname($db,$object);
-
-		// We save charset_output to restore it because write_file can change it if needed for
-		// output format that does not support UTF8.
-		$sav_charset_output=$outputlangs->charset_output;
-		if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-
-			// we delete preview files
-        	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-			dol_delete_preview($object);
-
-			return 1;
-		}
-		else
-		{
-			$outputlangs->charset_output=$sav_charset_output;
-			dol_syslog("Erreur dans supplier_order_pdf_create");
-			dol_print_error($db,$obj->error);
-			return 0;
-		}
-	}
-	else
-	{
-		if (! $conf->global->COMMANDE_SUPPLIER_ADDON_PDF)
-		{
-			print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_PDF_NotDefined");
-		}
-		else
-		{
-			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
-		}
-		return 0;
-	}
+	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
 }
 

+ 105 - 0
htdocs/expedition/class/expedition.class.php

@@ -6,6 +6,7 @@
  * Copyright (C) 2011-2013	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
  * Copyright (C) 2014		Cedric GROSS			<c.gross@kreiz-it.fr>
+ * Copyright (C) 2014       Marcos García           <marcosgdf@gmail.com>
  *
  * 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
@@ -1532,6 +1533,110 @@ class Expedition extends CommonObject
 		}
 	}
 
+	/**
+	 * 	Cree un bon d'expedition sur disque
+	 *
+	 * 	@param	string		$modele			Force le modele a utiliser ('' to not force)
+	 * 	@param	Translate	$outputlangs	Objet lang a utiliser pour traduction
+	 *  @return int             			<=0 if KO, >0 if OK
+	 */
+	public function generateDocument($modele, $outputlangs)
+	{
+		global $conf,$user,$langs;
+
+		$langs->load("sendings");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Sets the model on the model name to use
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->EXPEDITION_ADDON_PDF))
+			{
+				$modele = $conf->global->EXPEDITION_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'rouget';
+			}
+		}
+
+		// If selected model is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// We check the model location
+				$file=dol_buildpath($reldir."core/modules/expedition/doc/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Load the model
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+
+			$result=$this->fetch_origin();
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				//require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				//dol_delete_preview($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_syslog("Erreur dans expedition_pdf_create");
+				dol_print_error($this->db,$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			if (! $conf->global->EXPEDITION_ADDON_PDF)
+			{
+				print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined");
+			}
+			else
+			{
+				print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			}
+			return 0;
+		}
+	}
+
 }
 
 

+ 113 - 1
htdocs/fourn/class/fournisseur.commande.class.php

@@ -5,7 +5,7 @@
  * Copyright (C) 2007		Franky Van Liedekerke	<franky.van.liedekerke@telenet.be>
  * Copyright (C) 2010-2014	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2010-2014	Philippe Grand			<philippe.grand@atoo-net.com>
- * Copyright (C) 2012       Marcos García           <marcosgdf@gmail.com>
+ * Copyright (C) 2012-2014  Marcos García           <marcosgdf@gmail.com>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
  * Copyright (C) 2013       Cédric Salvador         <csalvador@gpcsolutions.fr>
  *
@@ -2005,6 +2005,118 @@ class CommandeFournisseur extends CommonOrder
 
         return '';
     }
+
+	/**
+	 *  Create a document onto disk according to template model.
+	 *
+	 *  @param	    string		$modele			Force template to use ('' to not force)
+	 *  @param		Translate	$outputlangs	Object lang to use for traduction
+	 *  @param      int			$hidedetails    Hide details of lines
+	 *  @param      int			$hidedesc       Hide description
+	 *  @param      int			$hideref        Hide ref
+	 *  @return     int          				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf, $user, $langs;
+		$langs->load("suppliers");
+
+		$error=0;
+
+		// Increase limit for PDF build
+		$err=error_reporting();
+		error_reporting(0);
+		@set_time_limit(120);
+		error_reporting($err);
+
+		$srctemplatepath='';
+
+		// Sets the model on the model name to use
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF))
+			{
+				$modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'muscadet';
+			}
+		}
+
+		// If selected model is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// We check the model location
+				$file=dol_buildpath($reldir."core/modules/supplier_order/pdf/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Load the model
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db,$this);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_syslog("Erreur dans supplier_order_pdf_create");
+				dol_print_error($this->db,$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			if (! $conf->global->COMMANDE_SUPPLIER_ADDON_PDF)
+			{
+				print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_PDF_NotDefined");
+			}
+			else
+			{
+				print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			}
+			return 0;
+		}
+	}
+
+
 }
 
 

+ 112 - 0
htdocs/fourn/class/fournisseur.facture.class.php

@@ -7,6 +7,7 @@
  * Copyright (C) 2010-2014	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013		Philippe Grand			<philippe.grand@atoo-net.com>
  * Copyright (C) 2013       Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2014       Marcos García           <marcosgdf@gmail.com>
  *
  * 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
@@ -1670,4 +1671,115 @@ class FactureFournisseur extends CommonInvoice
         }
     }
 
+	/**
+	 *	Create a document onto disk according to template model.
+	 *
+	 *	@param	    string		$modele			Force template to use ('' to not force)
+	 *	@param		Translate	$outputlangs	Object lang a utiliser pour traduction
+	 *  @param      int			$hidedetails    Hide details of lines
+	 *  @param      int			$hidedesc       Hide description
+	 *  @param      int			$hideref        Hide ref
+	 *  @return     int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf, $user, $langs;
+
+		$langs->load("suppliers");
+
+		$error=0;
+
+		// Increase limit for PDF build
+		$err=error_reporting();
+		error_reporting(0);
+		@set_time_limit(120);
+		error_reporting($err);
+
+		$srctemplatepath='';
+
+		// Set the model on the model name to use
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
+			{
+				$modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'canelle';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// We checked the location of the model
+				$file=dol_buildpath($reldir."core/modules/supplier_invoice/pdf/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Load the model
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db,$this);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_syslog("Erreur dans supplier_invoice_pdf_create");
+				dol_print_error($this->db,$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			if (! $conf->global->INVOICE_SUPPLIER_ADDON_PDF)
+			{
+				print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined");
+			}
+			else
+			{
+				print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			}
+			return 0;
+		}
+	}
+
 }

+ 98 - 0
htdocs/livraison/class/livraison.class.php

@@ -5,6 +5,7 @@
  * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  * Copyright (C) 2011-2012 Philippe Grand	     <philippe.grand@atoo-net.com>
  * Copyright (C) 2013      Florian Henry		  	<florian.henry@open-concept.pro>
+ * Copyright (C) 2014      Marcos García         <marcosgdf@gmail.com>
  *
  * 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
@@ -926,6 +927,103 @@ class Livraison extends CommonObject
 		}
 	}
 
+	/**
+	 *	Create object on disk
+	 *
+	 *	@param	string		$modele			force le modele a utiliser ('' to not force)
+	 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @return int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs='')
+	{
+		global $conf,$user,$langs;
+
+		$langs->load("deliveries");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne modele sur le nom du modele de bon de livraison a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->LIVRAISON_ADDON_PDF))
+			{
+				$modele = $conf->global->LIVRAISON_ADDON_PDF;
+			}
+			else
+			{
+				$modele = 'typhon';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/livraison/pdf/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this,$outputlangs) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_syslog("Erreur dans delivery_order_pdf_create");
+				dol_print_error($this->db,$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			return 0;
+		}
+	}
+
+
+
 }
 
 

+ 102 - 0
htdocs/projet/class/project.class.php

@@ -3,6 +3,7 @@
  * Copyright (C) 2005-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2010 Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2013	   Florian Henry        <florian.henry@open-concept.pro>
+ * Copyright (C) 2014      Marcos García        <marcosgdf@gmail.com>
  *
  * 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
@@ -1305,5 +1306,106 @@ class Project extends CommonObject
 		}
 
 	}
+
+	/**
+	 *  Create an intervention document on disk using template defined into PROJECT_ADDON_PDF
+	 *
+	 *  @param	string		$modele			force le modele a utiliser ('' par defaut)
+	 *  @param	Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @param  int			$hidedetails    Hide details of lines
+	 *  @param  int			$hidedesc       Hide description
+	 *  @param  int			$hideref        Hide ref
+	 *  @return int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
+	{
+		global $conf,$langs;
+
+		$langs->load("projects");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne modele sur le nom du modele de projet a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->PROJECT_ADDON_PDF))
+			{
+				$modele = $conf->global->PROJECT_ADDON_PDF;
+			}
+			else
+			{
+				$modele='baleine';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/project/pdf/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"project_pdf_create Error: ".$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			return 0;
+		}
+	}
+
 }
 

+ 101 - 0
htdocs/projet/class/task.class.php

@@ -1,6 +1,7 @@
 <?php
 /* Copyright (C) 2008-2012	Laurent Destailleur	<eldy@users.sourceforge.net>
  * Copyright (C) 2010-2012	Regis Houssin		<regis.houssin@capnetworks.com>
+ * Copyright (C) 2014       Marcos García       <marcosgdf@gmail.com>
  *
  * 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
@@ -1312,4 +1313,104 @@ class Task extends CommonObject
 		}
 	}
 
+	/**
+	 *  Create an intervention document on disk using template defined into PROJECT_TASK_ADDON_PDF
+	 *
+	 *  @param	string		$modele			force le modele a utiliser ('' par defaut)
+	 *  @param	Translate	$outputlangs	objet lang a utiliser pour traduction
+	 *  @param  int			$hidedetails    Hide details of lines
+	 *  @param  int			$hidedesc       Hide description
+	 *  @param  int			$hideref        Hide ref
+	 *  @param  HookManager	$hookmanager	Hook manager instance
+	 *  @return int         				0 if KO, 1 if OK
+	 */
+	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
+	{
+		global $conf,$langs;
+		$langs->load("projects");
+
+		$error=0;
+
+		$srctemplatepath='';
+
+		// Positionne modele sur le nom du modele de projet a utiliser
+		if (! dol_strlen($modele))
+		{
+			if (! empty($conf->global->PROJECT_TASK_ADDON_PDF))
+			{
+				$modele = $conf->global->PROJECT_TASK_ADDON_PDF;
+			}
+			else
+			{
+				$modele='nodefault';
+			}
+		}
+
+		// If selected modele is a filename template (then $modele="modelname:filename")
+		$tmp=explode(':',$modele,2);
+		if (! empty($tmp[1]))
+		{
+			$modele=$tmp[0];
+			$srctemplatepath=$tmp[1];
+		}
+
+		// Search template files
+		$file=''; $classname=''; $filefound=0;
+		$dirmodels=array('/');
+		if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
+		foreach($dirmodels as $reldir)
+		{
+			foreach(array('doc','pdf') as $prefix)
+			{
+				$file = $prefix."_".$modele.".modules.php";
+
+				// On verifie l'emplacement du modele
+				$file=dol_buildpath($reldir."core/modules/project/task/pdf/".$file,0);
+				if (file_exists($file))
+				{
+					$filefound=1;
+					$classname=$prefix.'_'.$modele;
+					break;
+				}
+			}
+			if ($filefound) break;
+		}
+
+		// Charge le modele
+		if ($filefound)
+		{
+			require_once $file;
+
+			$obj = new $classname($this->db);
+			// We save charset_output to restore it because write_file can change it if needed for
+			// output format that does not support UTF8.
+			$sav_charset_output=$outputlangs->charset_output;
+			if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+
+				// we delete preview files
+				require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+				dol_delete_preview($this);
+
+				// Success in building document. We build meta file.
+				dol_meta_create($this);
+
+				return 1;
+			}
+			else
+			{
+				$outputlangs->charset_output=$sav_charset_output;
+				dol_print_error($this->db,"task_pdf_create Error: ".$obj->error);
+				return 0;
+			}
+		}
+		else
+		{
+			print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
+			return 0;
+		}
+	}
+
+
 }