modules_societe.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 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@inodbox.com>
  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 3 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 <https://www.gnu.org/licenses/>.
  19. * or see https://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/societe/modules_societe.class.php
  23. * \ingroup societe
  24. * \brief File with parent class of submodules to manage numbering and document generation
  25. */
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
  27. /**
  28. * Parent class for third parties models of doc generators
  29. */
  30. abstract class ModeleThirdPartyDoc extends CommonDocGenerator
  31. {
  32. /**
  33. * @var string Error code (or message)
  34. */
  35. public $error = '';
  36. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  37. /**
  38. * Return list of active generation modules
  39. *
  40. * @param DoliDB $dbs Database handler
  41. * @param integer $maxfilenamelength Max length of value to show
  42. * @return array List of templates
  43. */
  44. public static function liste_modeles($dbs, $maxfilenamelength = 0)
  45. {
  46. // phpcs:enable
  47. $type = 'company';
  48. $list = array();
  49. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  50. $list = getListOfModels($dbs, $type, $maxfilenamelength);
  51. return $list;
  52. }
  53. }
  54. /**
  55. * Parent class for third parties code generators
  56. */
  57. abstract class ModeleThirdPartyCode
  58. {
  59. /**
  60. * @var string Error code (or message)
  61. */
  62. public $error = '';
  63. /**
  64. * @var array Error code (or message) array
  65. */
  66. public $errors;
  67. /** Renvoi la description par defaut du modele de numerotation
  68. *
  69. * @param Translate $langs Object langs
  70. * @return string Texte descripif
  71. */
  72. public function info($langs)
  73. {
  74. $langs->load("bills");
  75. return $langs->trans("NoDescription");
  76. }
  77. /** Return name of module
  78. *
  79. * @param Translate $langs Object langs
  80. * @return string Nom du module
  81. */
  82. public function getNom($langs)
  83. {
  84. return $this->name;
  85. }
  86. /** Return an example of numbering
  87. *
  88. * @param Translate $langs Object langs
  89. * @return string Example
  90. */
  91. public function getExample($langs)
  92. {
  93. $langs->load("bills");
  94. return $langs->trans("NoExample");
  95. }
  96. /**
  97. * Checks if the numbers already in the database do not
  98. * cause conflicts that would prevent this numbering working.
  99. *
  100. * @return boolean false if conflict, true if ok
  101. */
  102. public function canBeActivated()
  103. {
  104. return true;
  105. }
  106. /**
  107. * Return next value available
  108. *
  109. * @param Societe $objsoc Object thirdparty
  110. * @param int $type Type
  111. * @return string Value
  112. */
  113. public function getNextValue($objsoc = 0, $type = -1)
  114. {
  115. global $langs;
  116. return $langs->trans("Function_getNextValue_InModuleNotWorking");
  117. }
  118. /**
  119. * Return version of module
  120. *
  121. * @return string Version
  122. */
  123. public function getVersion()
  124. {
  125. global $langs;
  126. $langs->load("admin");
  127. if ($this->version == 'development') {
  128. return $langs->trans("VersionDevelopment");
  129. } elseif ($this->version == 'experimental') {
  130. return $langs->trans("VersionExperimental");
  131. } elseif ($this->version == 'dolibarr') {
  132. return DOL_VERSION;
  133. } elseif ($this->version) {
  134. return $this->version;
  135. } else {
  136. return $langs->trans("NotAvailable");
  137. }
  138. }
  139. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  140. /**
  141. * Renvoie la liste des modeles de numérotation
  142. *
  143. * @param DoliDB $dbs Database handler
  144. * @param integer $maxfilenamelength Max length of value to show
  145. * @return array|int List of numbers
  146. */
  147. public static function liste_modeles($dbs, $maxfilenamelength = 0)
  148. {
  149. // phpcs:enable
  150. $list = array();
  151. $sql = "";
  152. $resql = $dbs->query($sql);
  153. if ($resql) {
  154. $num = $dbs->num_rows($resql);
  155. $i = 0;
  156. while ($i < $num) {
  157. $row = $dbs->fetch_row($resql);
  158. $list[$row[0]] = $row[1];
  159. $i++;
  160. }
  161. } else {
  162. return -1;
  163. }
  164. return $list;
  165. }
  166. /**
  167. * Return description of module parameters
  168. *
  169. * @param Translate $langs Output language
  170. * @param Societe $soc Third party object
  171. * @param int $type -1=Nothing, 0=Customer, 1=Supplier
  172. * @return string HTML translated description
  173. */
  174. public function getToolTip($langs, $soc, $type)
  175. {
  176. global $conf;
  177. $langs->loadLangs(array("admin", "companies"));
  178. $strikestart = '';
  179. $strikeend = '';
  180. if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  181. $strikestart = '<strike>';
  182. $strikeend = '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
  183. }
  184. $s = '';
  185. if ($type == -1) {
  186. $s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
  187. } elseif ($type == -1) {
  188. $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  189. } elseif ($type == 0) {
  190. $s .= $langs->trans("CustomerCodeDesc").'<br>';
  191. } elseif ($type == 1) {
  192. $s .= $langs->trans("SupplierCodeDesc").'<br>';
  193. }
  194. if ($type != -1) {
  195. $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
  196. }
  197. $s .= '<br>';
  198. $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  199. if ($type == 0) {
  200. $s .= $langs->trans("RequiredIfCustomer").': '.$strikestart;
  201. $s .= yn(!$this->code_null, 1, 2).$strikeend;
  202. $s .= '<br>';
  203. } elseif ($type == 1) {
  204. $s .= $langs->trans("RequiredIfSupplier").': '.$strikestart;
  205. $s .= yn(!$this->code_null, 1, 2).$strikeend;
  206. $s .= '<br>';
  207. } elseif ($type == -1) {
  208. $s .= $langs->trans("Required").': '.$strikestart;
  209. $s .= yn(!$this->code_null, 1, 2).$strikeend;
  210. $s .= '<br>';
  211. }
  212. $s .= $langs->trans("CanBeModifiedIfOk").': ';
  213. $s .= yn($this->code_modifiable, 1, 2);
  214. $s .= '<br>';
  215. $s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>';
  216. $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
  217. $s .= '<br>';
  218. if ($type == 0 || $type == -1) {
  219. $nextval = $this->getNextValue($soc, 0);
  220. if (empty($nextval)) {
  221. $nextval = $langs->trans("Undefined");
  222. }
  223. $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>';
  224. }
  225. if ($type == 1 || $type == -1) {
  226. $nextval = $this->getNextValue($soc, 1);
  227. if (empty($nextval)) {
  228. $nextval = $langs->trans("Undefined");
  229. }
  230. $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>';
  231. }
  232. return $s;
  233. }
  234. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  235. /**
  236. * Check if mask/numbering use prefix
  237. *
  238. * @return int 0=no, 1=yes
  239. */
  240. public function verif_prefixIsUsed()
  241. {
  242. // phpcs:enable
  243. return 0;
  244. }
  245. }
  246. /**
  247. * Parent class for third parties accountancy code generators
  248. */
  249. abstract class ModeleAccountancyCode
  250. {
  251. /**
  252. * @var string Error code (or message)
  253. */
  254. public $error = '';
  255. /**
  256. * Return description of module
  257. *
  258. * @param Translate $langs Object langs
  259. * @return string Description of module
  260. */
  261. public function info($langs)
  262. {
  263. $langs->load("bills");
  264. return $langs->trans("NoDescription");
  265. }
  266. /**
  267. * Return an example of result returned by getNextValue
  268. *
  269. * @param Translate $langs Object langs
  270. * @param societe $objsoc Object thirdparty
  271. * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect)
  272. * @return string Example
  273. */
  274. public function getExample($langs, $objsoc = 0, $type = -1)
  275. {
  276. $langs->load("bills");
  277. return $langs->trans("NoExample");
  278. }
  279. /**
  280. * Checks if the numbers already in the database do not
  281. * cause conflicts that would prevent this numbering working.
  282. *
  283. * @return boolean false if conflict, true if ok
  284. */
  285. public function canBeActivated()
  286. {
  287. return true;
  288. }
  289. /**
  290. * Return version of module
  291. *
  292. * @return string Version
  293. */
  294. public function getVersion()
  295. {
  296. global $langs;
  297. $langs->load("admin");
  298. if ($this->version == 'development') {
  299. return $langs->trans("VersionDevelopment");
  300. } elseif ($this->version == 'experimental') {
  301. return $langs->trans("VersionExperimental");
  302. } elseif ($this->version == 'dolibarr') {
  303. return DOL_VERSION;
  304. } elseif ($this->version) {
  305. return $this->version;
  306. } else {
  307. return $langs->trans("NotAvailable");
  308. }
  309. }
  310. /**
  311. * Return description of module parameters
  312. *
  313. * @param Translate $langs Output language
  314. * @param Societe $soc Third party object
  315. * @param int $type -1=Nothing, 0=Customer, 1=Supplier
  316. * @return string HTML translated description
  317. */
  318. public function getToolTip($langs, $soc, $type)
  319. {
  320. global $conf, $db;
  321. $langs->load("admin");
  322. $s = '';
  323. if ($type == -1) {
  324. $s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
  325. $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  326. }
  327. //$s.='<br>';
  328. //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  329. $s .= '<br>';
  330. if ($type == 0 || $type == -1) {
  331. $result = $this->get_code($db, $soc, 'customer');
  332. $nextval = $this->code;
  333. if (empty($nextval)) {
  334. $nextval = $langs->trans("Undefined");
  335. }
  336. $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>';
  337. }
  338. if ($type == 1 || $type == -1) {
  339. $result = $this->get_code($db, $soc, 'supplier');
  340. $nextval = $this->code;
  341. if (empty($nextval)) {
  342. $nextval = $langs->trans("Undefined");
  343. }
  344. $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>';
  345. }
  346. return $s;
  347. }
  348. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  349. /**
  350. * Set accountancy account code for a third party into this->code
  351. *
  352. * @param DoliDB $db Database handler
  353. * @param Societe $societe Third party object
  354. * @param int $type 'customer' or 'supplier'
  355. * @return int >=0 if OK, <0 if KO
  356. */
  357. public function get_code($db, $societe, $type = '')
  358. {
  359. // phpcs:enable
  360. global $langs;
  361. return $langs->trans("NotAvailable");
  362. }
  363. }