PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/facture/modules_facture.php

https://github.com/asterix14/dolibarr
PHP | 245 lines | 126 code | 35 blank | 84 comment | 13 complexity | a79fbe97e8fe9c9f16f960160a48457e MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/facture/modules_facture.php
  23. * \ingroup facture
  24. * \brief Fichier contenant la classe mere de generation des factures en PDF
  25. * et la classe mere de numerotation des factures
  26. */
  27. require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
  28. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); // Requis car utilise dans les classes qui heritent
  30. /**
  31. * \class ModelePDFFactures
  32. * \brief Classe mere des modeles de facture
  33. */
  34. abstract class ModelePDFFactures extends CommonDocGenerator
  35. {
  36. var $error='';
  37. /**
  38. * Return list of active generation modules
  39. * @param $db Database handler
  40. */
  41. function liste_modeles($db)
  42. {
  43. global $conf;
  44. $type='invoice';
  45. $liste=array();
  46. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  47. $liste=getListOfModels($db,$type,'');
  48. return $liste;
  49. }
  50. }
  51. /**
  52. * \class ModeleNumRefFactures
  53. * \brief Classe mere des modeles de numerotation des references de facture
  54. */
  55. abstract class ModeleNumRefFactures
  56. {
  57. var $error='';
  58. /** Return if a module can be used or not
  59. * @return boolean true if module can be used
  60. */
  61. function isEnabled()
  62. {
  63. return true;
  64. }
  65. /** Renvoi la description par defaut du modele de numerotation
  66. * @return string Texte descripif
  67. */
  68. function info()
  69. {
  70. global $langs;
  71. $langs->load("bills");
  72. return $langs->trans("NoDescription");
  73. }
  74. /** Renvoi un exemple de numerotation
  75. * @return string Example
  76. */
  77. function getExample()
  78. {
  79. global $langs;
  80. $langs->load("bills");
  81. return $langs->trans("NoExample");
  82. }
  83. /** Test si les numeros deja en vigueur dans la base ne provoquent pas
  84. * de conflits qui empecheraient cette numerotation de fonctionner.
  85. * @return boolean false si conflit, true si ok
  86. */
  87. function canBeActivated()
  88. {
  89. return true;
  90. }
  91. /** Renvoi prochaine valeur attribuee
  92. * @param objsoc Objet societe
  93. * @param facture Objet facture
  94. * @return string Valeur
  95. */
  96. function getNextValue($objsoc,$facture)
  97. {
  98. global $langs;
  99. return $langs->trans("NotAvailable");
  100. }
  101. /** Renvoi version du modele de numerotation
  102. * @return string Valeur
  103. */
  104. function getVersion()
  105. {
  106. global $langs;
  107. $langs->load("admin");
  108. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  109. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  110. if ($this->version == 'dolibarr') return DOL_VERSION;
  111. return $langs->trans("NotAvailable");
  112. }
  113. }
  114. /**
  115. * Create a document onto disk accordign to template module.
  116. *
  117. * @param DoliDB $db Database handler
  118. * @param Object $object Object invoice
  119. * @param string $message message
  120. * @param string $modele Force le modele a utiliser ('' to not force)
  121. * @param Translate $outputlangs objet lang a utiliser pour traduction
  122. * @param int $hidedetails Hide details of lines
  123. * @param int $hidedesc Hide description
  124. * @param int $hideref Hide ref
  125. * @param HookManager $hookmanager Hook manager instance
  126. * @return int <0 if KO, >0 if OK
  127. */
  128. function facture_pdf_create($db, $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
  129. {
  130. global $conf,$user,$langs;
  131. $langs->load("bills");
  132. // Increase limit for PDF build
  133. $err=error_reporting();
  134. error_reporting(0);
  135. @set_time_limit(120);
  136. error_reporting($err);
  137. $dir = "/core/modules/facture/";
  138. $srctemplatepath='';
  139. // Positionne le modele sur le nom du modele a utiliser
  140. if (! dol_strlen($modele))
  141. {
  142. if (! empty($conf->global->FACTURE_ADDON_PDF))
  143. {
  144. $modele = $conf->global->FACTURE_ADDON_PDF;
  145. }
  146. else
  147. {
  148. $modele = 'crabe';
  149. }
  150. }
  151. // If selected modele is a filename template (then $modele="modelname:filename")
  152. $tmp=explode(':',$modele,2);
  153. if (! empty($tmp[1]))
  154. {
  155. $modele=$tmp[0];
  156. $srctemplatepath=$tmp[1];
  157. }
  158. // Search template file
  159. $file=''; $classname=''; $filefound=0;
  160. foreach(array('doc','pdf') as $prefix)
  161. {
  162. $file = $prefix."_".$modele.".modules.php";
  163. // On verifie l'emplacement du modele
  164. $file = dol_buildpath($dir.'doc/'.$file);
  165. if (file_exists($file))
  166. {
  167. $filefound=1;
  168. $classname=$prefix.'_'.$modele;
  169. break;
  170. }
  171. }
  172. // Charge le modele
  173. if ($filefound)
  174. {
  175. require_once($file);
  176. $obj = new $classname($db);
  177. $obj->message = $message;
  178. // We save charset_output to restore it because write_file can change it if needed for
  179. // output format that does not support UTF8.
  180. $sav_charset_output=$outputlangs->charset_output;
  181. if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
  182. {
  183. $outputlangs->charset_output=$sav_charset_output;
  184. // We delete old preview
  185. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  186. dol_delete_preview($object);
  187. // Success in building document. We build meta file.
  188. dol_meta_create($object);
  189. // Appel des triggers
  190. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  191. $interface=new Interfaces($db);
  192. $result=$interface->run_triggers('BILL_BUILDDOC',$object,$user,$langs,$conf);
  193. if ($result < 0) { $error++; $this->errors=$interface->errors; }
  194. // Fin appel triggers
  195. return 1;
  196. }
  197. else
  198. {
  199. $outputlangs->charset_output=$sav_charset_output;
  200. dol_print_error($db,"facture_pdf_create Error: ".$obj->error);
  201. return -1;
  202. }
  203. }
  204. else
  205. {
  206. dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file));
  207. return -1;
  208. }
  209. }
  210. ?>