modules_commande.php 6.9 KB

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