dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
18  * or see http://www.gnu.org/
19  */
20 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
27 
28 
33 {
39  public $nom='Aquarium';
40 
44  public $name='Aquarium';
45 
50  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
51 
52  public $prefixcustomeraccountancycode;
53 
54  public $prefixsupplieraccountancycode;
55 
56 
60  function __construct()
61  {
62  global $conf;
63  if (! isset($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) || trim($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) == '') $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER='411';
64  if (! isset($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) == '') $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER='401';
65  $this->prefixcustomeraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER;
66  $this->prefixsupplieraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER;
67  }
68 
69 
76  function info($langs)
77  {
78  global $conf;
79  global $form;
80 
81  $langs->load("companies");
82 
83  $tooltip='';
84  $texte = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
85  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
86  $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
87  $texte.= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
88  $texte.= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
89  $texte.= '<table class="nobordernopadding" width="100%">';
90  $s1= $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER.'">',$tooltip,1,1);
91  $s2= $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER.'">',$tooltip,1,1);
92  $texte.= '<tr><td>';
93  $texte.=$langs->trans("ModuleCompanyCodeCustomer".$this->name,$s2)."<br>\n";
94  $texte.=$langs->trans("ModuleCompanyCodeSupplier".$this->name,$s1)."<br>\n";
95  $texte.="<br>\n";
96  if (! isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || ! empty($conf->global->$conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_SPECIAL').' = '.yn(1)."<br>\n";
97  //if (! empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_ALPHA').' = '.yn($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)."<br>\n";
98  if (! empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) $texte.=$langs->trans('COMPANY_AQUARIUM_CLEAN_REGEX').' = '.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX."<br>\n";
99  $texte.= '</td>';
100  $texte.= '<td align="left">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
101  $texte.= '</tr></table>';
102  $texte.= '</form>';
103 
104  return $texte;
105  }
106 
115  function getExample($langs,$objsoc=0,$type=-1)
116  {
117  $s='';
118  $s.=$this->prefixcustomeraccountancycode.'CUSTCODE';
119  $s.="<br>\n";
120  $s.=$this->prefixsupplieraccountancycode.'SUPPCODE';
121  return $s;
122  }
123 
124 
125  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
134  function get_code($db, $societe, $type='')
135  {
136  // phpcs:enable
137  global $conf;
138 
139  $i = 0;
140  $this->db = $db;
141 
142  dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(! empty($societe->name)?$societe->name:''));
143 
144  // Regle gestion compte compta
145  if ($type == 'customer')
146  {
147  $codetouse=(! empty($societe->code_client)?$societe->code_client:'CUSTCODE');
148  $prefix = $this->prefixcustomeraccountancycode;
149  }
150  else if ($type == 'supplier')
151  {
152  $codetouse=(! empty($societe->code_fournisseur)?$societe->code_fournisseur:'SUPPCODE');
153  $prefix = $this->prefixsupplieraccountancycode;
154  }
155  else
156  {
157  $this->error = 'Bad value for parameter type';
158  return -1;
159  }
160 
161  //$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
162 
163  // Remove special char if COMPANY_AQUARIUM_REMOVE_SPECIAL is set to 1 or not set (default)
164  if (! isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || ! empty($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) $codetouse=preg_replace('/([^a-z0-9])/i','',$codetouse);
165  // Remove special alpha if COMPANY_AQUARIUM_REMOVE_ALPHA is set to 1
166  if (! empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $codetouse=preg_replace('/([a-z])/i','',$codetouse);
167  // 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.
168  if (! empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) // Example: $conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
169  {
170  $codetouse=preg_replace('/'.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX.'/','\1\2\3',$codetouse);
171  }
172 
173  $codetouse=$prefix.strtoupper($codetouse);
174 
175  $is_dispo = $this->verif($db, $codetouse, $societe, $type);
176  if (! $is_dispo)
177  {
178  $this->code=$codetouse;
179  }
180  else
181  {
182  // Pour retour
183  $this->code=$codetouse;
184  }
185  dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code);
186  return $is_dispo;
187  }
188 
189 
199  function verif($db, $code, $societe, $type)
200  {
201  $sql = "SELECT ";
202  if ($type == 'customer') $sql.= "code_compta";
203  else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
204  $sql.= " FROM ".MAIN_DB_PREFIX."societe";
205  $sql.= " WHERE ";
206  if ($type == 'customer') $sql.= "code_compta";
207  else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
208  $sql.= " = '".$db->escape($code)."'";
209  if (! empty($societe->id)) $sql.= " AND rowid <> ".$societe->id;
210 
211  $resql=$db->query($sql);
212  if ($resql)
213  {
214  if ($db->num_rows($resql) == 0)
215  {
216  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
217  return 1; // Dispo
218  }
219  else
220  {
221  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
222  return 0; // Non dispo
223  }
224  }
225  else
226  {
227  $this->error=$db->error()." sql=".$sql;
228  return -1; // Erreur
229  }
230  }
231 }
verif($db, $code, $societe, $type)
Return if a code is available.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
get_code($db, $societe, $type='')
Set accountancy account code for a third party into this->code.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
Parent class for third parties accountancy code generators.
$version
Dolibarr version of the loaded document string.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
info($langs)
Return description of module.
Class to manage accountancy code of thirdparties with Aquarium rules.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.