modules_chequereceipts.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/modules/cheque/modules_chequereceipts.php
  24. * \ingroup facture
  25. * \brief File with parent class of check receipt document generators
  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 ModeleNumRefChequeReceipts
  32. * \brief Cheque Receipts numbering references mother class
  33. */
  34. abstract class ModeleNumRefChequeReceipts
  35. {
  36. /**
  37. * @var string Error code (or message)
  38. */
  39. public $error = '';
  40. /**
  41. * Return if a module can be used or not
  42. *
  43. * @return boolean true if module can be used
  44. */
  45. public function isEnabled()
  46. {
  47. return true;
  48. }
  49. /**
  50. * Return the default description of numbering module
  51. *
  52. * @return string Texte descripif
  53. */
  54. public function info()
  55. {
  56. global $langs;
  57. $langs->load("bills");
  58. return $langs->trans("NoDescription");
  59. }
  60. /**
  61. * Return numbering example
  62. *
  63. * @return string Example
  64. */
  65. public function getExample()
  66. {
  67. global $langs;
  68. $langs->load("bills");
  69. return $langs->trans("NoExample");
  70. }
  71. /**
  72. * Checks if the numbers already in the database do not
  73. * cause conflicts that would prevent this numbering working.
  74. *
  75. * @return boolean false if conflict, true if ok
  76. */
  77. public function canBeActivated()
  78. {
  79. return true;
  80. }
  81. /**
  82. * Returns the next value
  83. *
  84. * @param Societe $objsoc Object thirdparty
  85. * @param Object $object Object we need next value for
  86. * @return string Valeur
  87. */
  88. public function getNextValue($objsoc, $object)
  89. {
  90. global $langs;
  91. return $langs->trans("NotAvailable");
  92. }
  93. /**
  94. * Returns the module numbering version
  95. *
  96. * @return string Value
  97. */
  98. public function getVersion()
  99. {
  100. global $langs;
  101. $langs->load("admin");
  102. if ($this->version == 'development') {
  103. return $langs->trans("VersionDevelopment");
  104. }
  105. if ($this->version == 'experimental') {
  106. return $langs->trans("VersionExperimental");
  107. }
  108. if ($this->version == 'dolibarr') {
  109. return DOL_VERSION;
  110. }
  111. if ($this->version) {
  112. return $this->version;
  113. }
  114. return $langs->trans("NotAvailable");
  115. }
  116. }
  117. /**
  118. * Class parent for templates of document generation
  119. */
  120. abstract class ModeleChequeReceipts extends CommonDocGenerator
  121. {
  122. /**
  123. * @var string Error code (or message)
  124. */
  125. public $error = '';
  126. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  127. /**
  128. * Return list of active generation modules
  129. *
  130. * @param DoliDB $db Database handler
  131. * @param integer $maxfilenamelength Max length of value to show
  132. * @return array List of templates
  133. */
  134. public static function liste_modeles($db, $maxfilenamelength = 0)
  135. {
  136. // phpcs:enable
  137. global $conf;
  138. $type = 'chequereceipt';
  139. $list = array();
  140. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  141. $list = getListOfModels($db, $type, $maxfilenamelength);
  142. // TODO Remove this to use getListOfModels only
  143. $list = array('blochet'=>'blochet');
  144. return $list;
  145. }
  146. }
  147. /**
  148. * Cree un bordereau remise de cheque
  149. *
  150. * @param DoliDB $db Database handler
  151. * @param int $id Object invoice (or id of invoice)
  152. * @param string $message Message
  153. * @param string $modele Force le modele a utiliser ('' to not force)
  154. * @param Translate $outputlangs Object lang a utiliser pour traduction
  155. * @return int <0 if KO, >0 if OK
  156. * TODO Use commonDocGenerator
  157. */
  158. function chequereceipt_pdf_create($db, $id, $message, $modele, $outputlangs)
  159. {
  160. global $conf, $langs;
  161. $langs->load("bills");
  162. $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
  163. // Positionne modele sur le nom du modele a utiliser
  164. if (!dol_strlen($modele)) {
  165. if (!empty($conf->global->CHEQUERECEIPT_ADDON_PDF)) {
  166. $modele = $conf->global->CHEQUERECEIPT_ADDON_PDF;
  167. } else {
  168. //print $langs->trans("Error")." ".$langs->trans("Error_FACTURE_ADDON_PDF_NotDefined");
  169. //return 0;
  170. $modele = 'blochet';
  171. }
  172. }
  173. // Charge le modele
  174. $file = "pdf_".$modele.".modules.php";
  175. if (file_exists($dir.$file)) {
  176. $classname = "pdf_".$modele;
  177. require_once $dir.$file;
  178. $obj = new $classname($db);
  179. // We save charset_output to restore it because write_file can change it if needed for
  180. // output format that does not support UTF8.
  181. $sav_charset_output = $outputlangs->charset_output;
  182. if ($obj->write_file($id, $outputlangs) > 0) {
  183. $outputlangs->charset_output = $sav_charset_output;
  184. return 1;
  185. } else {
  186. $outputlangs->charset_output = $sav_charset_output;
  187. dol_print_error($db, "chequereceipt_pdf_create Error: ".$obj->error);
  188. return -1;
  189. }
  190. } else {
  191. dol_print_error('', $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $dir.$file));
  192. return -1;
  193. }
  194. }