67 if (!isset($conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER) || trim($conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER) ==
'') {
68 $conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER =
'411';
70 if (!isset($conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER) || trim($conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER) ==
'') {
71 $conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER =
'401';
73 $this->prefixcustomeraccountancycode = $conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER;
74 $this->prefixsupplieraccountancycode = $conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER;
76 if (!isset($conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER) || trim($conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER) ==
'') {
77 $conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER =
'5';
79 if (!isset($conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER) || trim($conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER) ==
'') {
80 $conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER =
'5';
82 $this->customeraccountancycodecharacternumber = $conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER;
83 $this->supplieraccountancycodecharacternumber = $conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER;
92 public function info($langs)
97 $texte =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
98 $texte .=
'<input type="hidden" name="token" value="'.newToken().
'">';
99 $texte .=
'<input type="hidden" name="page_y" value="">';
100 $texte .=
'<input type="hidden" name="action" value="setModuleOptions">';
101 $texte .=
'<input type="hidden" name="param1" value="COMPANY_DIGITARIA_MASK_SUPPLIER">';
102 $texte .=
'<input type="hidden" name="param2" value="COMPANY_DIGITARIA_MASK_CUSTOMER">';
103 $texte .=
'<input type="hidden" name="param3" value="COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER">';
104 $texte .=
'<input type="hidden" name="param4" value="COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER">';
105 $texte .=
'<input type="hidden" name="param5" value="COMPANY_DIGITARIA_CLEAN_WORDS">';
106 $texte .=
'<table class="nobordernopadding centpercent">';
107 $s1 = $form->textwithpicto(
'<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER.
'">', $tooltip, 1, 1);
108 $s2 = $form->textwithpicto(
'<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER.
'">', $tooltip, 1, 1);
109 $s3 = $form->textwithpicto(
'<input type="text" class="flat" size="2" name="value3" value="'.$conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER.
'">', $tooltip, 1, 1);
110 $s4 = $form->textwithpicto(
'<input type="text" class="flat" size="2" name="value4" value="'.$conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER.
'">', $tooltip, 1, 1);
111 $texte .=
'<tr><td>';
113 $texte .= $langs->trans(
"ModuleCompanyCodeCustomer".$this->
name,
'{s2}',
'{s4}').
"<br>\n";
114 $texte .= $langs->trans(
"ModuleCompanyCodeSupplier".$this->
name,
'{s1}',
'{s3}').
"<br>\n";
115 $texte = str_replace(array(
'{s1}',
'{s2}',
'{s3}',
'{s4}'), array($s1, $s2, $s3, $s4), $texte);
118 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL) || !empty($conf->global->$conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
119 $texte .= $langs->trans(
'RemoveSpecialChars').
' = '.
yn(1).
"<br>\n";
122 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_REGEX)) {
123 $texte .= $langs->trans(
'COMPANY_DIGITARIA_CLEAN_REGEX').
' = '.$conf->global->COMPANY_DIGITARIA_CLEAN_REGEX.
"<br>\n";
126 if (!isset($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE) || !empty($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE)) {
127 $texte .= $langs->trans(
'COMPANY_DIGITARIA_UNIQUE_CODE').
' = '.
yn(1).
"<br>\n";
130 $texte .=
'<td class="right"><input type="submit" class="button button-edit reposition" name="modify" value="'.$langs->trans(
"Modify").
'"></td>';
133 $texte .=
'<tr><td>';
136 $texthelp = $langs->trans(
"RemoveSpecialWordsHelp");
137 $texttitle = $langs->trans(
"RemoveSpecialWords");
139 $texte .= $form->textwithpicto($texttitle, $texthelp, 1,
'help',
'', 1);
141 $texte .=
'<textarea class="flat" cols="60" name="value5">';
142 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_WORDS)) {
143 $texte .= $conf->global->COMPANY_DIGITARIA_CLEAN_WORDS;
145 $texte .=
'</textarea>';
146 $texte .=
'</tr></table>';
163 global $conf, $mysoc;
165 $s = $langs->trans(
"ThirdPartyName").
": ".$mysoc->name;
168 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
169 $thirdpartylabelexample = preg_replace(
'/([^a-z0-9])/i',
'', $mysoc->name);
172 $s .= $this->prefixcustomeraccountancycode.strtoupper(substr($thirdpartylabelexample, 0, $this->customeraccountancycodecharacternumber));
174 $s .= $this->prefixsupplieraccountancycode.strtoupper(substr($thirdpartylabelexample, 0, $this->supplieraccountancycodecharacternumber));
187 public function get_code($db, $societe, $type =
'')
196 if (is_object($societe)) {
197 dol_syslog(
"mod_codecompta_digitaria::get_code search code for type=".$type.
" & company=".(!empty($societe->name) ? $societe->name :
''));
199 if ($type ==
'supplier') {
200 $codetouse = $societe->name;
201 $prefix = $this->prefixsupplieraccountancycode;
202 $width = $this->supplieraccountancycodecharacternumber;
203 } elseif ($type ==
'customer') {
204 $codetouse = $societe->name;
205 $prefix = $this->prefixcustomeraccountancycode;
206 $width = $this->customeraccountancycodecharacternumber;
208 $this->error =
'Bad value for parameter type';
213 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_WORDS)) {
214 $cleanWords = explode(
";", $conf->global->COMPANY_DIGITARIA_CLEAN_WORDS);
215 $codetouse = str_replace($cleanWords,
"", $codetouse);
218 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL) || !empty($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
219 $codetouse = preg_replace(
'/([^a-z0-9])/i',
'', $codetouse);
222 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_REGEX)) {
223 $codetouse = preg_replace(
'/'.$conf->global->COMPANY_DIGITARIA_CLEAN_REGEX.
'/',
'\1\2\3', $codetouse);
226 $this->code = $prefix.strtoupper(substr($codetouse, 0, $width));
227 dol_syslog(
"mod_codecompta_digitaria::get_code search code proposed=".$this->code, LOG_DEBUG);
230 if (!isset($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE) || !empty($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE)) {
233 while ($disponibility <> 0 && $i < 1000) {
234 $widthsupplier = $this->supplieraccountancycodecharacternumber;
235 $widthcustomer = $this->customeraccountancycodecharacternumber;
240 if ($i >= 10 && $i <= 99) {
243 if ($i >= 100 && $i <= 999) {
247 if ($type ==
'supplier') {
248 $this->code = $prefix.strtoupper(substr($codetouse, 0, $widthsupplier - $a)).$i;
249 } elseif ($type ==
'customer') {
250 $this->code = $prefix.strtoupper(substr($codetouse, 0, $widthcustomer - $a)).$i;
261 if ($disponibility == 0) {
280 if ($type ==
'supplier') {
281 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
282 $typethirdparty =
'accountancy_code_supplier';
284 $typethirdparty =
'code_compta_fournisseur';
286 } elseif ($type ==
'customer') {
287 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
288 $typethirdparty =
'accountancy_code_customer';
290 $typethirdparty =
'code_compta';
293 $this->error =
'Bad value for parameter type';
297 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
298 $sql =
"SELECT " . $typethirdparty .
" FROM " . MAIN_DB_PREFIX .
"societe_perentity";
299 $sql .=
" WHERE " . $typethirdparty .
" = '" . $db->escape($code) .
"'";
301 $sql =
"SELECT " . $typethirdparty .
" FROM " . MAIN_DB_PREFIX .
"societe";
302 $sql .=
" WHERE " . $typethirdparty .
" = '" . $db->escape($code) .
"'";
304 $sql .=
" AND entity IN (".getEntity(
'societe').
")";
306 $resql = $db->query($sql);
308 if ($db->num_rows($resql) == 0) {
309 dol_syslog(
"mod_codecompta_digitaria::checkIfAccountancyCodeIsAlreadyUsed '".$code.
"' available");
312 dol_syslog(
"mod_codecompta_digitaria::checkIfAccountancyCodeIsAlreadyUsed '".$code.
"' not available");
316 $this->error = $db->error().
" sql=".$sql;