PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

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

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