PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/societe/modules_societe.class.php

https://github.com/asterix14/dolibarr
PHP | 426 lines | 239 code | 50 blank | 137 comment | 75 complexity | d8d5da044e93fe455b1dcbd69404d338 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-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2007 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/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. * \class ModeleThirdPartyDoc
  29. * \brief Parent class for third parties models of doc generators
  30. */
  31. abstract class ModeleThirdPartyDoc extends CommonDocGenerator
  32. {
  33. var $error='';
  34. /**
  35. * Return list of active generation modules
  36. * @param $db Database handler
  37. * @param $maxfilenamelength Max length of value to show
  38. */
  39. function liste_modeles($db,$maxfilenamelength=0)
  40. {
  41. global $conf;
  42. $type='company';
  43. $liste=array();
  44. include_once(DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php');
  45. $liste=getListOfModels($db,$type,$maxfilenamelength);
  46. return $liste;
  47. }
  48. }
  49. /**
  50. * \class ModeleThirdPartyCode
  51. * \brief Parent class for third parties code generators
  52. */
  53. abstract class ModeleThirdPartyCode
  54. {
  55. var $error='';
  56. /** Renvoi la description par defaut du modele de numerotation
  57. *
  58. * @return string Texte descripif
  59. */
  60. function info($langs)
  61. {
  62. $langs->load("bills");
  63. return $langs->trans("NoDescription");
  64. }
  65. /** Renvoi nom module
  66. *
  67. * @return string Nom du module
  68. */
  69. function getNom($langs)
  70. {
  71. return $this->nom;
  72. }
  73. /** Renvoi un exemple de numerotation
  74. *
  75. * @return string Example
  76. */
  77. function getExample($langs)
  78. {
  79. $langs->load("bills");
  80. return $langs->trans("NoExample");
  81. }
  82. /** Test si les numeros deja en vigueur dans la base ne provoquent pas de
  83. * de conflits qui empechera cette numerotation de fonctionner.
  84. *
  85. * @return boolean false si conflit, true si ok
  86. */
  87. function canBeActivated()
  88. {
  89. return true;
  90. }
  91. /** Return next value available
  92. *
  93. * @return string Value
  94. */
  95. function getNextValue($objsoc=0,$type=-1)
  96. {
  97. global $langs;
  98. return $langs->trans("Function_getNextValue_InModuleNotWorking");
  99. }
  100. /** Return version of module
  101. *
  102. * @return string Version
  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. * Renvoi la liste des modeles de numĂŠroation
  115. *
  116. * @param db Handler de base
  117. */
  118. function liste_modeles($db)
  119. {
  120. $liste=array();
  121. $sql ="";
  122. $resql = $db->query($sql);
  123. if ($resql)
  124. {
  125. $num = $db->num_rows($resql);
  126. $i = 0;
  127. while ($i < $num)
  128. {
  129. $row = $db->fetch_row($resql);
  130. $liste[$row[0]]=$row[1];
  131. $i++;
  132. }
  133. }
  134. else
  135. {
  136. return -1;
  137. }
  138. return $liste;
  139. }
  140. /**
  141. * Return description of module parameters
  142. *
  143. * @param langs Output language
  144. * @param soc Third party object
  145. * @param type -1=Nothing, 0=Customer, 1=Supplier
  146. * @return string HTML translated description
  147. */
  148. function getToolTip($langs,$soc,$type)
  149. {
  150. global $conf;
  151. $langs->load("admin");
  152. $s='';
  153. if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>';
  154. if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  155. if ($type == 0) $s.=$langs->trans("CustomerCodeDesc").'<br>';
  156. if ($type == 1) $s.=$langs->trans("SupplierCodeDesc").'<br>';
  157. if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
  158. $s.='<br>';
  159. $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  160. if ($type == 0)
  161. {
  162. $s.=$langs->trans("RequiredIfCustomer").': ';
  163. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='<strike>';
  164. $s.=yn(!$this->code_null,1,2);
  165. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  166. $s.='<br>';
  167. }
  168. if ($type == 1)
  169. {
  170. $s.=$langs->trans("RequiredIfSupplier").': ';
  171. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='<strike>';
  172. $s.=yn(!$this->code_null,1,2);
  173. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  174. $s.='<br>';
  175. }
  176. if ($type == -1)
  177. {
  178. $s.=$langs->trans("Required").': ';
  179. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='<strike>';
  180. $s.=yn(!$this->code_null,1,2);
  181. if ($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED && !empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  182. $s.='<br>';
  183. }
  184. $s.=$langs->trans("CanBeModifiedIfOk").': ';
  185. $s.=yn($this->code_modifiable,1,2);
  186. $s.='<br>';
  187. $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
  188. $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'<br>';
  189. $s.='<br>';
  190. if ($type == 0 || $type == -1)
  191. {
  192. $nextval=$this->getNextValue($soc,0);
  193. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  194. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>';
  195. }
  196. if ($type == 1 || $type == -1)
  197. {
  198. $nextval=$this->getNextValue($soc,1);
  199. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  200. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>';
  201. }
  202. return $s;
  203. }
  204. /**
  205. * Check if mask/numbering use prefix
  206. *
  207. * @param int 0=no, 1=yes
  208. */
  209. function verif_prefixIsUsed()
  210. {
  211. return 0;
  212. }
  213. }
  214. /**
  215. * \class ModeleAccountancyCode
  216. * \brief Parent class for third parties accountancy code generators
  217. */
  218. abstract class ModeleAccountancyCode
  219. {
  220. var $error='';
  221. /** Return description of module
  222. *
  223. * @param $langs Object langs
  224. * @return string Description of module
  225. */
  226. function info($langs)
  227. {
  228. $langs->load("bills");
  229. return $langs->trans("NoDescription");
  230. }
  231. /** Return an example of result returned by getNextValue
  232. *
  233. * @param $langs Object langs
  234. * @param $objsoc Object thirdparty
  235. * @param $type Type of third party (1:customer, 2:supplier, -1:autodetect)
  236. */
  237. function getExample($langs,$objsoc=0,$type=-1)
  238. {
  239. $langs->load("bills");
  240. return $langs->trans("NoExample");
  241. }
  242. /** Test si les numeros deja en vigueur dans la base ne provoquent pas de
  243. * de conflits qui empechera cette numerotation de fonctionner.
  244. *
  245. * @return boolean false si conflit, true si ok
  246. */
  247. function canBeActivated()
  248. {
  249. return true;
  250. }
  251. /** Return version of module
  252. *
  253. * @return string Version
  254. */
  255. function getVersion()
  256. {
  257. global $langs;
  258. $langs->load("admin");
  259. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  260. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  261. if ($this->version == 'dolibarr') return DOL_VERSION;
  262. return $langs->trans("NotAvailable");
  263. }
  264. /**
  265. * Return description of module parameters
  266. *
  267. * @param langs Output language
  268. * @param soc Third party object
  269. * @param type -1=Nothing, 0=Customer, 1=Supplier
  270. * @return string HTML translated description
  271. */
  272. function getToolTip($langs,$soc,$type)
  273. {
  274. global $conf,$db;
  275. $langs->load("admin");
  276. $s='';
  277. if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>';
  278. if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  279. //$s.='<br>';
  280. //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  281. $s.='<br>';
  282. if ($type == 0 || $type == -1)
  283. {
  284. $result=$this->get_code($db,$soc,'customer');
  285. $nextval=$this->code;
  286. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  287. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>';
  288. }
  289. if ($type == 1 || $type == -1)
  290. {
  291. $result=$this->get_code($db,$soc,'supplier');
  292. $nextval=$this->code;
  293. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  294. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>';
  295. }
  296. return $s;
  297. }
  298. /**
  299. * Set accountancy account code for a third party into this->code
  300. *
  301. * @param db Database handler
  302. * @param societe Third party object
  303. * @param type 'customer' or 'supplier'
  304. * @return int >=0 if OK, <0 if KO
  305. */
  306. function get_code($db, $societe, $type='')
  307. {
  308. return $langs->trans("NotAvailable");
  309. }
  310. }
  311. /**
  312. * Create a document for third party
  313. *
  314. * @param DoliDB $db Database handler
  315. * @param int $id Id of third party to use
  316. * @param string $message Message
  317. * @param string $modele Force model to use ('' to not force). model can be a model name or a template file.
  318. * @param Translate $outputlangs Object lang to use for translation
  319. * @return int <0 if KO, >0 if OK
  320. */
  321. function thirdparty_doc_create($db, $id, $message, $modele, $outputlangs)
  322. {
  323. global $conf,$langs;
  324. $langs->load("bills");
  325. $dir = DOL_DOCUMENT_ROOT . "/core/modules/societe/doc";
  326. $srctemplatepath='';
  327. // Positionne modele sur le nom du modele a utiliser
  328. if (! dol_strlen($modele))
  329. {
  330. if ($conf->global->COMPANY_ADDON_PDF)
  331. {
  332. $modele = $conf->global->COMPANY_ADDON_PDF;
  333. }
  334. else
  335. {
  336. print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
  337. return 0;
  338. }
  339. }
  340. // If selected modele is a filename template (then $modele="modelname:filename")
  341. $tmp=explode(':',$modele,2);
  342. if (! empty($tmp[1]))
  343. {
  344. $modele=$tmp[0];
  345. $srctemplatepath=$tmp[1];
  346. }
  347. // Search template
  348. $file = "doc_".$modele.".modules.php";
  349. if (file_exists($dir.'/'.$file))
  350. {
  351. $classname = "doc_".$modele;
  352. require_once($dir.'/'.$file);
  353. $obj = new $classname($db);
  354. $obj->message = $message;
  355. // We save charset_output to restore it because write_file can change it if needed for
  356. // output format that does not support UTF8.
  357. $sav_charset_output=$outputlangs->charset_output;
  358. if ($obj->write_file($id, $outputlangs, $srctemplatepath) > 0)
  359. {
  360. $outputlangs->charset_output=$sav_charset_output;
  361. return 1;
  362. }
  363. else
  364. {
  365. $outputlangs->charset_output=$sav_charset_output;
  366. dol_print_error($db,"thirdparty_doc_create Error: ".$obj->error);
  367. return -1;
  368. }
  369. }
  370. else
  371. {
  372. dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.'/'.$file));
  373. return -1;
  374. }
  375. }
  376. ?>