27 require_once DOL_DOCUMENT_ROOT.
'/core/modules/societe/modules_societe.class.php';
38 public $name =
'Digitaria';
44 public $version =
'dolibarr';
50 public $prefixcustomeraccountancycode;
56 public $prefixsupplieraccountancycode;
58 public $position = 30;
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 .=
'<table class="nobordernopadding" width="100%">';
106 $s1 =
$form->textwithpicto(
'<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_DIGITARIA_MASK_SUPPLIER.
'">', $tooltip, 1, 1);
107 $s2 =
$form->textwithpicto(
'<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_DIGITARIA_MASK_CUSTOMER.
'">', $tooltip, 1, 1);
108 $s3 =
$form->textwithpicto(
'<input type="text" class="flat" size="2" name="value3" value="'.$conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_SUPPLIER.
'">', $tooltip, 1, 1);
109 $s4 =
$form->textwithpicto(
'<input type="text" class="flat" size="2" name="value4" value="'.$conf->global->COMPANY_DIGITARIA_MASK_NBCHARACTER_CUSTOMER.
'">', $tooltip, 1, 1);
110 $texte .=
'<tr><td>';
112 $texte .= $langs->trans(
"ModuleCompanyCodeCustomer".$this->
name,
'{s2}',
'{s4}').
"<br>\n";
113 $texte .= $langs->trans(
"ModuleCompanyCodeSupplier".$this->
name,
'{s1}',
'{s3}').
"<br>\n";
114 $texte = str_replace(array(
'{s1}',
'{s2}',
'{s3}',
'{s4}'), array($s1, $s2, $s3, $s4), $texte);
117 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL) || !empty($conf->global->$conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
118 $texte .= $langs->trans(
'RemoveSpecialChars').
' = '.
yn(1).
"<br>\n";
121 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_REGEX)) {
122 $texte .= $langs->trans(
'COMPANY_DIGITARIA_CLEAN_REGEX').
' = '.$conf->global->COMPANY_DIGITARIA_CLEAN_REGEX.
"<br>\n";
125 if (!isset($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE) || !empty($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE)) {
126 $texte .= $langs->trans(
'COMPANY_DIGITARIA_UNIQUE_CODE').
' = '.
yn(1).
"<br>\n";
129 $texte .=
'<td class="right"><input type="submit" class="button button-edit reposition" name="modify" value="'.$langs->trans(
"Modify").
'"></td>';
130 $texte .=
'</tr></table>';
146 global $conf, $mysoc;
148 $s = $langs->trans(
"ThirdPartyName").
": ".$mysoc->name;
151 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
152 $thirdpartylabelexample = preg_replace(
'/([^a-z0-9])/i',
'', $mysoc->name);
155 $s .= $this->prefixcustomeraccountancycode.strtoupper(substr($thirdpartylabelexample, 0, $this->customeraccountancycodecharacternumber));
157 $s .= $this->prefixsupplieraccountancycode.strtoupper(substr($thirdpartylabelexample, 0, $this->supplieraccountancycodecharacternumber));
170 public function get_code($db, $societe, $type =
'')
179 if (is_object($societe)) {
180 dol_syslog(
"mod_codecompta_digitaria::get_code search code for type=".$type.
" & company=".(!empty($societe->name) ? $societe->name :
''));
182 if ($type ==
'supplier') {
183 $codetouse = $societe->name;
184 $prefix = $this->prefixsupplieraccountancycode;
185 $width = $this->supplieraccountancycodecharacternumber;
186 } elseif ($type ==
'customer') {
187 $codetouse = $societe->name;
188 $prefix = $this->prefixcustomeraccountancycode;
189 $width = $this->customeraccountancycodecharacternumber;
191 $this->error =
'Bad value for parameter type';
196 if (!isset($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL) || !empty($conf->global->COMPANY_DIGITARIA_REMOVE_SPECIAL)) {
197 $codetouse = preg_replace(
'/([^a-z0-9])/i',
'', $codetouse);
200 if (!empty($conf->global->COMPANY_DIGITARIA_CLEAN_REGEX)) {
201 $codetouse = preg_replace(
'/'.$conf->global->COMPANY_DIGITARIA_CLEAN_REGEX.
'/',
'\1\2\3', $codetouse);
204 $this->
code = $prefix.strtoupper(substr($codetouse, 0, $width));
205 dol_syslog(
"mod_codecompta_digitaria::get_code search code proposed=".$this->
code);
208 if (!isset($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE) || !empty($conf->global->COMPANY_DIGITARIA_UNIQUE_CODE)) {
211 while ($disponibility <> 0 && $i < 1000) {
212 $widthsupplier = $this->supplieraccountancycodecharacternumber;
213 $widthcustomer = $this->customeraccountancycodecharacternumber;
218 if ($i >= 10 && $i <= 99) {
221 if ($i >= 100 && $i <= 999) {
225 if ($type ==
'supplier') {
226 $this->
code = $prefix.strtoupper(substr($codetouse, 0, $widthsupplier - $a)).$i;
227 } elseif ($type ==
'customer') {
228 $this->
code = $prefix.strtoupper(substr($codetouse, 0, $widthcustomer - $a)).$i;
239 if ($disponibility == 0) {
258 if ($type ==
'supplier') {
259 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
260 $typethirdparty =
'accountancy_code_supplier';
262 $typethirdparty =
'code_compta_fournisseur';
264 } elseif ($type ==
'customer') {
265 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
266 $typethirdparty =
'accountancy_code_customer';
268 $typethirdparty =
'code_compta';
271 $this->error =
'Bad value for parameter type';
275 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
276 $sql =
"SELECT " . $typethirdparty .
" FROM " . MAIN_DB_PREFIX .
"societe_perentity";
277 $sql .=
" WHERE " . $typethirdparty .
" = '" . $db->escape($code) .
"'";
279 $sql =
"SELECT " . $typethirdparty .
" FROM " . MAIN_DB_PREFIX .
"societe";
280 $sql .=
" WHERE " . $typethirdparty .
" = '" . $db->escape($code) .
"'";
283 $resql = $db->query($sql);
285 if ($db->num_rows(
$resql) == 0) {
286 dol_syslog(
"mod_codecompta_digitaria::checkIfAccountancyCodeIsAlreadyUsed '".$code.
"' available");
289 dol_syslog(
"mod_codecompta_digitaria::checkIfAccountancyCodeIsAlreadyUsed '".$code.
"' not available");
293 $this->error = $db->error().
" sql=".$sql;