dolibarr  19.0.0-dev
mod_codecompta_aquarium.php
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
27 
28 
33 {
37  public $name = 'Aquarium';
38 
43  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
44 
45  public $prefixcustomeraccountancycode;
46 
47  public $prefixsupplieraccountancycode;
48 
49  public $position = 20;
50 
51 
55  public function __construct()
56  {
57  global $conf;
58  if (!isset($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) || trim($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) == '') {
59  $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER = '411';
60  }
61  if (!isset($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) == '') {
62  $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER = '401';
63  }
64 
65  if (!empty($conf->global->COMPANY_AQUARIUM_NO_PREFIX)) {
66  $this->prefixcustomeraccountancycode = '';
67  $this->prefixsupplieraccountancycode = '';
68  } else {
69  $this->prefixcustomeraccountancycode = $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER;
70  $this->prefixsupplieraccountancycode = $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER;
71  }
72  }
73 
74 
81  public function info($langs)
82  {
83  global $conf;
84  global $form;
85 
86  $langs->load("companies");
87 
88  $tooltip = '';
89  $texte = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
90  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
91  $texte .= '<input type="hidden" name="page_y" value="">';
92  $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
93  $texte .= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
94  $texte .= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
95  $texte .= '<table class="nobordernopadding" width="100%">';
96  $s1 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER.'">', $tooltip, 1, 1);
97  $s2 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER.'">', $tooltip, 1, 1);
98  $texte .= '<tr><td>';
99  // trans remove html entities
100  $texte .= $langs->trans("ModuleCompanyCodeCustomer".$this->name, '{s2}')."<br>\n";
101  $texte .= $langs->trans("ModuleCompanyCodeSupplier".$this->name, '{s1}')."<br>\n";
102  $texte = str_replace(array('{s1}', '{s2}'), array($s1, $s2), $texte);
103  $texte .= "<br>\n";
104  if (!isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || !empty($conf->global->$conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) {
105  $texte .= $langs->trans('RemoveSpecialChars').' = '.yn(1)."<br>\n";
106  }
107  //if (!empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_ALPHA').' = '.yn($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)."<br>\n";
108  if (!empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) {
109  $texte .= $langs->trans('COMPANY_AQUARIUM_CLEAN_REGEX').' = '.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX."<br>\n";
110  }
111 
112  if (!empty($conf->global->COMPANY_AQUARIUM_NO_PREFIX)) {
113  $texte .= $langs->trans('COMPANY_AQUARIUM_NO_PREFIX').' = '.$conf->global->COMPANY_AQUARIUM_NO_PREFIX."<br>\n";
114  }
115  $texte .= '</td>';
116  $texte .= '<td class="right"><input type="submit" class="button button-edit reposition" name="modify" value="'.$langs->trans("Modify").'"></td>';
117  $texte .= '</tr></table>';
118  $texte .= '</form>';
119 
120  return $texte;
121  }
122 
131  public function getExample($langs, $objsoc = 0, $type = -1)
132  {
133  $s = '';
134  $s .= $this->prefixcustomeraccountancycode.'CUSTCODE';
135  $s .= "<br>\n";
136  $s .= $this->prefixsupplieraccountancycode.'SUPPCODE';
137  return $s;
138  }
139 
140 
141  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
150  public function get_code($db, $societe, $type = '')
151  {
152  // phpcs:enable
153  global $conf;
154 
155  $i = 0;
156  $this->db = $db;
157 
158  dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(!empty($societe->name) ? $societe->name : ''));
159 
160  // Regle gestion compte compta
161  if ($type == 'customer') {
162  $codetouse = (!empty($societe->code_client) ? $societe->code_client : 'CUSTCODE');
163  $prefix = $this->prefixcustomeraccountancycode;
164  } elseif ($type == 'supplier') {
165  $codetouse = (!empty($societe->code_fournisseur) ? $societe->code_fournisseur : 'SUPPCODE');
166  $prefix = $this->prefixsupplieraccountancycode;
167  } else {
168  $this->error = 'Bad value for parameter type';
169  return -1;
170  }
171 
172  //$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
173 
174  // Remove special char if COMPANY_AQUARIUM_REMOVE_SPECIAL is set to 1 or not set (default)
175  if (!isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || !empty($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) {
176  $codetouse = preg_replace('/([^a-z0-9])/i', '', $codetouse);
177  }
178  // Remove special alpha if COMPANY_AQUARIUM_REMOVE_ALPHA is set to 1
179  if (!empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) {
180  $codetouse = preg_replace('/([a-z])/i', '', $codetouse);
181  }
182  // 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.
183  if (!empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) { // Example: $conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
184  $codetouse = preg_replace('/'.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX.'/', '\1\2\3', $codetouse);
185  }
186 
187  $codetouse = $prefix.strtoupper($codetouse);
188 
189  $is_dispo = $this->verif($db, $codetouse, $societe, $type);
190  if (!$is_dispo) {
191  $this->code = $codetouse;
192  } else {
193  // Pour retour
194  $this->code = $codetouse;
195  }
196  dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code);
197  return $is_dispo;
198  }
199 
200 
210  public function verif($db, $code, $societe, $type)
211  {
212  $sql = "SELECT ";
213  if ($type == 'customer') {
214  $sql .= "code_compta";
215  } elseif ($type == 'supplier') {
216  $sql .= "code_compta_fournisseur";
217  }
218  $sql .= " FROM ".MAIN_DB_PREFIX."societe";
219  $sql .= " WHERE ";
220  if ($type == 'customer') {
221  $sql .= "code_compta";
222  } elseif ($type == 'supplier') {
223  $sql .= "code_compta_fournisseur";
224  }
225  $sql .= " = '".$db->escape($code)."'";
226  if (!empty($societe->id)) {
227  $sql .= " AND rowid <> ".$societe->id;
228  }
229 
230  $resql = $db->query($sql);
231  if ($resql) {
232  if ($db->num_rows($resql) == 0) {
233  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
234  return 1; // Dispo
235  } else {
236  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
237  return 0; // Non dispo
238  }
239  } else {
240  $this->error = $db->error()." sql=".$sql;
241  return -1; // Erreur
242  }
243  }
244 }
Parent class for third parties accountancy code generators.
Class to manage accountancy code of thirdparties with Aquarium rules.
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.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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:123
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...