dolibarr 24.0.0-beta
mod_codecompta_aquarium.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 * or see https://www.gnu.org/
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
30
31
36{
40 public $name = 'Aquarium';
41
45 public $code;
46
51 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
52
56 public $prefixcustomeraccountancycode;
57
61 public $prefixsupplieraccountancycode;
62
66 public $position = 20;
67
68
72 public function __construct()
73 {
74 global $conf;
75 if (!isset($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) || trim($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) == '') {
76 $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER = '411';
77 }
78 if (!isset($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) == '') {
79 $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER = '401';
80 }
81
82 if (getDolGlobalString('COMPANY_AQUARIUM_NO_PREFIX')) {
83 $this->prefixcustomeraccountancycode = '';
84 $this->prefixsupplieraccountancycode = '';
85 } else {
86 $this->prefixcustomeraccountancycode = getDolGlobalString('COMPANY_AQUARIUM_MASK_CUSTOMER');
87 $this->prefixsupplieraccountancycode = getDolGlobalString('COMPANY_AQUARIUM_MASK_SUPPLIER');
88 }
89 }
90
91
98 public function info($langs)
99 {
100 global $form;
101
102 $langs->load("companies");
103
104 $tooltip = '';
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>';
115 // trans remove html entities
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);
119 $texte .= "<br>\n";
120 if (getDolGlobalInt('COMPANY_AQUARIUM_REMOVE_SPECIAL')) {
121 $texte .= $langs->trans('RemoveSpecialChars').' = '.yn(1)."<br>\n";
122 }
123 if (getDolGlobalString('COMPANY_AQUARIUM_CLEAN_REGEX')) {
124 $texte .= $langs->trans('COMPANY_AQUARIUM_CLEAN_REGEX').' = ' . getDolGlobalString('COMPANY_AQUARIUM_CLEAN_REGEX')."<br>\n";
125 }
126
127 if (getDolGlobalString('COMPANY_AQUARIUM_NO_PREFIX')) {
128 $texte .= $langs->trans('COMPANY_AQUARIUM_NO_PREFIX').' = ' . getDolGlobalString('COMPANY_AQUARIUM_NO_PREFIX')."<br>\n";
129 }
130 $texte .= '</td>';
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>';
133 $texte .= '</form>';
134
135 return $texte;
136 }
137
146 public function getExample($langs = null, $objsoc = '', $type = -1)
147 {
148 $s = '';
149 $s .= $this->prefixcustomeraccountancycode.'CUSTCODE';
150 $s .= "<br>\n";
151 $s .= $this->prefixsupplieraccountancycode.'SUPPCODE';
152 return $s;
153 }
154
155
156 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
165 public function get_code($db, $societe, $type = '')
166 {
167 // phpcs:enable
168 global $conf;
169
170 $i = 0;
171 $this->db = $db;
172
173 dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(!empty($societe->name) ? $societe->name : ''));
174
175 // Regle gestion compte compta
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;
182 } else {
183 $this->error = 'Bad value for parameter type';
184 return -1;
185 }
186
187 //$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
188
189 // Remove special char if COMPANY_AQUARIUM_REMOVE_SPECIAL is set to 1 or not set (default)
190 if (!isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || getDolGlobalString('COMPANY_AQUARIUM_REMOVE_SPECIAL')) {
191 $codetouse = preg_replace('/([^a-z0-9])/i', '', (string) $codetouse);
192 }
193 // Remove special alpha if COMPANY_AQUARIUM_REMOVE_ALPHA is set to 1
194 if (getDolGlobalString('COMPANY_AQUARIUM_REMOVE_ALPHA')) {
195 $codetouse = preg_replace('/([a-z])/i', '', (string) $codetouse);
196 }
197 // Apply a regex replacement pattern on code if COMPANY_AQUARIUM_CLEAN_REGEX is set. Value must be a regex with parenthesis. The part into parenthesis is kept, the rest removed.
198 if (getDolGlobalString('COMPANY_AQUARIUM_CLEAN_REGEX')) { // Example: $conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
199 $codetouse = preg_replace('/' . getDolGlobalString('COMPANY_AQUARIUM_CLEAN_REGEX').'/', '\1\2\3', (string) $codetouse);
200 }
201
202 $codetouse = $prefix.strtoupper((string) $codetouse);
203
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);
207 return $is_dispo;
208 }
209
210
220 public function verif($db, $code, $societe, $type)
221 {
222 $sql = "SELECT ";
223 if ($type == 'customer') {
224 $sql .= "code_compta";
225 } elseif ($type == 'supplier') {
226 $sql .= "code_compta_fournisseur";
227 }
228 $sql .= " FROM ".MAIN_DB_PREFIX."societe";
229 $sql .= " WHERE ";
230 if ($type == 'customer') {
231 $sql .= "code_compta";
232 } elseif ($type == 'supplier') {
233 $sql .= "code_compta_fournisseur";
234 }
235 $sql .= " = '".$db->escape($code)."'";
236 if (!empty($societe->id)) {
237 $sql .= " AND rowid <> ".$societe->id;
238 }
239
240 $resql = $db->query($sql);
241 if ($resql) {
242 if ($db->num_rows($resql) == 0) {
243 dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
244 return 1; // Dispo
245 } else {
246 dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
247 return 0; // Non dispo
248 }
249 } else {
250 $this->error = $db->error()." sql=".$sql;
251 return -1; // Erreur
252 }
253 }
254}
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
Definition repair.php:133