29require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
40 public $name =
'Aquarium';
51 public $version =
'dolibarr';
56 public $prefixcustomeraccountancycode;
61 public $prefixsupplieraccountancycode;
66 public $position = 20;
75 if (!isset(
$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) || trim(
$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) ==
'') {
76 $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER =
'411';
78 if (!isset(
$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim(
$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) ==
'') {
79 $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER =
'401';
83 $this->prefixcustomeraccountancycode =
'';
84 $this->prefixsupplieraccountancycode =
'';
86 $this->prefixcustomeraccountancycode =
getDolGlobalString(
'COMPANY_AQUARIUM_MASK_CUSTOMER');
87 $this->prefixsupplieraccountancycode =
getDolGlobalString(
'COMPANY_AQUARIUM_MASK_SUPPLIER');
98 public function info($langs)
102 $langs->load(
"companies");
105 $texte =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
106 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
107 $texte .=
'<input type="hidden" name="page_y" value="">';
108 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
109 $texte .=
'<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
110 $texte .=
'<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
111 $texte .=
'<table class="nobordernopadding" width="100%">';
112 $s1 = $form->textwithpicto(
'<input type="text" class="flat" size="4" name="value1" value="' .
getDolGlobalString(
'COMPANY_AQUARIUM_MASK_SUPPLIER').
'">', $tooltip, 1,
'help',
'valignmiddle', 0, 3, $this->
name);
113 $s2 = $form->textwithpicto(
'<input type="text" class="flat" size="4" name="value2" value="' .
getDolGlobalString(
'COMPANY_AQUARIUM_MASK_CUSTOMER').
'">', $tooltip, 1,
'help',
'valignmiddle', 0, 3, $this->
name);
114 $texte .=
'<tr><td>';
116 $texte .= $langs->trans(
"ModuleCompanyCodeCustomer".$this->
name,
'{s2}').
"<br>\n";
117 $texte .= $langs->trans(
"ModuleCompanyCodeSupplier".$this->
name,
'{s1}').
"<br>\n";
118 $texte = str_replace(array(
'{s1}',
'{s2}'), array($s1, $s2), $texte);
121 $texte .= $langs->trans(
'RemoveSpecialChars').
' = '.
yn(1).
"<br>\n";
124 $texte .= $langs->trans(
'COMPANY_AQUARIUM_CLEAN_REGEX').
' = ' .
getDolGlobalString(
'COMPANY_AQUARIUM_CLEAN_REGEX').
"<br>\n";
128 $texte .= $langs->trans(
'COMPANY_AQUARIUM_NO_PREFIX').
' = ' .
getDolGlobalString(
'COMPANY_AQUARIUM_NO_PREFIX').
"<br>\n";
131 $texte .=
'<td class="right"><input type="submit" class="button button-edit reposition smallpaddingimp" name="modify" value="'.$langs->trans(
"Modify").
'"></td>';
132 $texte .=
'</tr></table>';
146 public function getExample($langs =
null, $objsoc =
'', $type = -1)
149 $s .= $this->prefixcustomeraccountancycode.
'CUSTCODE';
151 $s .= $this->prefixsupplieraccountancycode.
'SUPPCODE';
165 public function get_code($db, $societe, $type =
'')
173 dol_syslog(
"mod_codecompta_aquarium::get_code search code for type=".$type.
" company=".(!empty($societe->name) ? $societe->name :
''));
176 if ($type ==
'customer') {
177 $codetouse = (!empty($societe->code_client) ? $societe->code_client :
'CUSTCODE');
178 $prefix = $this->prefixcustomeraccountancycode;
179 } elseif ($type ==
'supplier') {
180 $codetouse = (!empty($societe->code_fournisseur) ? $societe->code_fournisseur :
'SUPPCODE');
181 $prefix = $this->prefixsupplieraccountancycode;
183 $this->error =
'Bad value for parameter type';
190 if (!isset(
$conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) ||
getDolGlobalString(
'COMPANY_AQUARIUM_REMOVE_SPECIAL')) {
191 $codetouse = preg_replace(
'/([^a-z0-9])/i',
'', (
string) $codetouse);
195 $codetouse = preg_replace(
'/([a-z])/i',
'', (
string) $codetouse);
199 $codetouse = preg_replace(
'/' .
getDolGlobalString(
'COMPANY_AQUARIUM_CLEAN_REGEX').
'/',
'\1\2\3', (
string) $codetouse);
202 $codetouse = $prefix.strtoupper((
string) $codetouse);
204 $is_dispo = $this->
verif($db, $codetouse, $societe, $type);
205 $this->code = $codetouse;
206 dol_syslog(
"mod_codecompta_aquarium::get_code found code=".$this->code);
220 public function verif($db, $code, $societe, $type)
223 if ($type ==
'customer') {
224 $sql .=
"code_compta";
225 } elseif ($type ==
'supplier') {
226 $sql .=
"code_compta_fournisseur";
228 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe";
230 if ($type ==
'customer') {
231 $sql .=
"code_compta";
232 } elseif ($type ==
'supplier') {
233 $sql .=
"code_compta_fournisseur";
235 $sql .=
" = '".$db->escape($code).
"'";
236 if (!empty($societe->id)) {
237 $sql .=
" AND rowid <> ".$societe->id;
240 $resql = $db->query($sql);
242 if ($db->num_rows($resql) == 0) {
243 dol_syslog(
"mod_codecompta_aquarium::verif code '".$code.
"' available");
246 dol_syslog(
"mod_codecompta_aquarium::verif code '".$code.
"' not available");
250 $this->error = $db->error().
" sql=".$sql;
Parent class for third parties accountancy code generators.
Class to manage accountancy code of thirdparties with Aquarium rules.
getExample($langs=null, $objsoc='', $type=-1)
Return an example of result returned by getNextValue.
info($langs)
Return description of module.
verif($db, $code, $societe, $type)
Return if a code is available.
get_code($db, $societe, $type='')
Set accountancy account code for a third party into this->code.
__construct()
Constructor.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.