PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/societe/core/models/mod_codecompta_aquarium.php

https://bitbucket.org/speedealing/speedealing
PHP | 189 lines | 75 code | 20 blank | 94 comment | 9 complexity | ad1f84255c31bfb706dd1b77d877e835 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * or see http://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/models/mod_codecompta_aquarium.php
  22. * \ingroup societe
  23. * \brief File of class to manage accountancy code of thirdparties with Panicum rules
  24. */
  25. require_once DOL_DOCUMENT_ROOT . '/societe/core/models/modules_societe.class.php';
  26. /**
  27. * Class to manage accountancy code of thirdparties with Aquarium rules
  28. */
  29. class mod_codecompta_aquarium extends ModeleAccountancyCode
  30. {
  31. var $nom='Aquarium';
  32. var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
  33. var $prefixcustomeraccountancycode;
  34. var $prefixsupplieraccountancycode;
  35. /**
  36. * Constructor
  37. */
  38. function __construct()
  39. {
  40. global $conf;
  41. if (empty($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER)) $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER='411';
  42. if (empty($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER)) $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER='401';
  43. $this->prefixcustomeraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER;
  44. $this->prefixsupplieraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER;
  45. }
  46. /**
  47. * Return description of module
  48. *
  49. * @param Translate $langs Object langs
  50. * @return string Description of module
  51. */
  52. function info($langs)
  53. {
  54. global $conf;
  55. global $form;
  56. $langs->load("companies");
  57. $tooltip='';
  58. $texte = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  59. $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  60. $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
  61. $texte.= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
  62. $texte.= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
  63. $texte.= '<table class="nobordernopadding" width="100%">';
  64. $s1= $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER.'">',$tooltip,1,1);
  65. $s2= $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER.'">',$tooltip,1,1);
  66. $texte.= '<tr><td>'.$langs->trans("ModuleCompanyCode".$this->nom,$s1,$s2)."<br>\n";
  67. $texte.= '</td>';
  68. $texte.= '<td align="left">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
  69. $texte.= '</tr></table>';
  70. $texte.= '</form>';
  71. return $texte;
  72. }
  73. /**
  74. * Return an example of result returned by getNextValue
  75. *
  76. * @param Translate $langs Object langs
  77. * @param societe $objsoc Object thirdparty
  78. * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect)
  79. * @return string Return string example
  80. */
  81. function getExample($langs,$objsoc=0,$type=-1)
  82. {
  83. return $this->prefixsupplieraccountancycode.'SUPPCODE'."<br>\n".$this->prefixcustomeraccountancycode.'CUSTCODE';
  84. }
  85. /**
  86. * Set accountancy account code for a third party into this->code
  87. *
  88. * @param DoliDB $db Database handler
  89. * @param Societe $societe Third party object
  90. * @param string $type 'customer' or 'supplier'
  91. * @return int >=0 if OK, <0 if KO
  92. */
  93. function get_code($db, $societe, $type)
  94. {
  95. $i = 0;
  96. $this->db = $db;
  97. dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(! empty($societe->nom)?$societe->nom:''));
  98. // Regle gestion compte compta
  99. $codetouse='';
  100. if ($type == 'customer')
  101. {
  102. $codetouse = $this->prefixcustomeraccountancycode;
  103. $codetouse.= (! empty($societe->code_client)?$societe->code_client:'CUSTCODE');
  104. }
  105. else if ($type == 'supplier')
  106. {
  107. $codetouse = $this->prefixsupplieraccountancycode;
  108. $codetouse.= (! empty($societe->code_fournisseur)?$societe->code_fournisseur:'SUPPCODE');
  109. }
  110. $codetouse=strtoupper(preg_replace('/([^a-z0-9])/i','',$codetouse));
  111. $is_dispo = $this->verif($db, $codetouse, $societe, $type);
  112. if (! $is_dispo)
  113. {
  114. $this->code=$codetouse;
  115. }
  116. else
  117. {
  118. // Pour retour
  119. $this->code=$codetouse;
  120. }
  121. dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code);
  122. return $is_dispo;
  123. }
  124. /**
  125. * Return if a code is available
  126. *
  127. * @param DoliDB $db Database handler
  128. * @param string $code Code of third party
  129. * @param Societe $societe Object third party
  130. * @param string $type 'supplier' or 'customer'
  131. * @return int 0 if OK but not available, >0 if OK and available, <0 if KO
  132. */
  133. function verif($db, $code, $societe, $type)
  134. {
  135. /*
  136. $sql = "SELECT ";
  137. if ($type == 'customer') $sql.= "code_compta";
  138. else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
  139. $sql.= " FROM ".MAIN_DB_PREFIX."societe";
  140. $sql.= " WHERE ";
  141. if ($type == 'customer') $sql.= "code_compta";
  142. else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
  143. $sql.= " = '".$this->db->escape($code)."'";
  144. if (! empty($societe->id)) $sql.= " AND rowid <> ".$societe->id;
  145. $resql=$db->query($sql);
  146. if ($resql)
  147. {
  148. if ($db->num_rows($resql) == 0)
  149. {
  150. dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
  151. return 1; // Dispo
  152. }
  153. else
  154. {
  155. dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
  156. return 0; // Non dispo
  157. }
  158. }
  159. else
  160. {
  161. $this->error=$db->error()." sql=".$sql;
  162. dol_syslog("mod_codecompta_aquarium::verif error".$this->error, LOG_ERR);
  163. return -1; // Erreur
  164. }
  165. */
  166. }
  167. }
  168. ?>