dolibarr  13.0.2
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) == '') $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER = '411';
59  if (!isset($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) == '') $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER = '401';
60  $this->prefixcustomeraccountancycode = $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER;
61  $this->prefixsupplieraccountancycode = $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER;
62  }
63 
64 
71  public function info($langs)
72  {
73  global $conf;
74  global $form;
75 
76  $langs->load("companies");
77 
78  $tooltip = '';
79  $texte = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
80  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
81  $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
82  $texte .= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
83  $texte .= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
84  $texte .= '<table class="nobordernopadding" width="100%">';
85  $s1 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER.'">', $tooltip, 1, 1);
86  $s2 = $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER.'">', $tooltip, 1, 1);
87  $texte .= '<tr><td>';
88  // trans remove html entities
89  $texte .= $langs->trans("ModuleCompanyCodeCustomer".$this->name, '{s2}')."<br>\n";
90  $texte .= $langs->trans("ModuleCompanyCodeSupplier".$this->name, '{s1}')."<br>\n";
91  $texte = str_replace(array('{s1}', '{s2}'), array($s1, $s2), $texte);
92  $texte .= "<br>\n";
93  if (!isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || !empty($conf->global->$conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) $texte .= $langs->trans('RemoveSpecialChars').' = '.yn(1)."<br>\n";
94  //if (! empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $texte.=$langs->trans('COMPANY_AQUARIUM_REMOVE_ALPHA').' = '.yn($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)."<br>\n";
95  if (!empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) $texte .= $langs->trans('COMPANY_AQUARIUM_CLEAN_REGEX').' = '.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX."<br>\n";
96  $texte .= '</td>';
97  $texte .= '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
98  $texte .= '</tr></table>';
99  $texte .= '</form>';
100 
101  return $texte;
102  }
103 
112  public function getExample($langs, $objsoc = 0, $type = -1)
113  {
114  $s = '';
115  $s .= $this->prefixcustomeraccountancycode.'CUSTCODE';
116  $s .= "<br>\n";
117  $s .= $this->prefixsupplieraccountancycode.'SUPPCODE';
118  return $s;
119  }
120 
121 
122  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
131  public function get_code($db, $societe, $type = '')
132  {
133  // phpcs:enable
134  global $conf;
135 
136  $i = 0;
137  $this->db = $db;
138 
139  dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(!empty($societe->name) ? $societe->name : ''));
140 
141  // Regle gestion compte compta
142  if ($type == 'customer')
143  {
144  $codetouse = (!empty($societe->code_client) ? $societe->code_client : 'CUSTCODE');
145  $prefix = $this->prefixcustomeraccountancycode;
146  } elseif ($type == 'supplier')
147  {
148  $codetouse = (!empty($societe->code_fournisseur) ? $societe->code_fournisseur : 'SUPPCODE');
149  $prefix = $this->prefixsupplieraccountancycode;
150  } else {
151  $this->error = 'Bad value for parameter type';
152  return -1;
153  }
154 
155  //$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
156 
157  // Remove special char if COMPANY_AQUARIUM_REMOVE_SPECIAL is set to 1 or not set (default)
158  if (!isset($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL) || !empty($conf->global->COMPANY_AQUARIUM_REMOVE_SPECIAL)) $codetouse = preg_replace('/([^a-z0-9])/i', '', $codetouse);
159  // Remove special alpha if COMPANY_AQUARIUM_REMOVE_ALPHA is set to 1
160  if (!empty($conf->global->COMPANY_AQUARIUM_REMOVE_ALPHA)) $codetouse = preg_replace('/([a-z])/i', '', $codetouse);
161  // 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.
162  if (!empty($conf->global->COMPANY_AQUARIUM_CLEAN_REGEX)) // Example: $conf->global->COMPANY_AQUARIUM_CLEAN_REGEX='^..(..)..';
163  {
164  $codetouse = preg_replace('/'.$conf->global->COMPANY_AQUARIUM_CLEAN_REGEX.'/', '\1\2\3', $codetouse);
165  }
166 
167  $codetouse = $prefix.strtoupper($codetouse);
168 
169  $is_dispo = $this->verif($db, $codetouse, $societe, $type);
170  if (!$is_dispo)
171  {
172  $this->code = $codetouse;
173  } else {
174  // Pour retour
175  $this->code = $codetouse;
176  }
177  dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code);
178  return $is_dispo;
179  }
180 
181 
191  public function verif($db, $code, $societe, $type)
192  {
193  $sql = "SELECT ";
194  if ($type == 'customer') $sql .= "code_compta";
195  elseif ($type == 'supplier') $sql .= "code_compta_fournisseur";
196  $sql .= " FROM ".MAIN_DB_PREFIX."societe";
197  $sql .= " WHERE ";
198  if ($type == 'customer') $sql .= "code_compta";
199  elseif ($type == 'supplier') $sql .= "code_compta_fournisseur";
200  $sql .= " = '".$db->escape($code)."'";
201  if (!empty($societe->id)) $sql .= " AND rowid <> ".$societe->id;
202 
203  $resql = $db->query($sql);
204  if ($resql)
205  {
206  if ($db->num_rows($resql) == 0)
207  {
208  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
209  return 1; // Dispo
210  } else {
211  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
212  return 0; // Non dispo
213  }
214  } else {
215  $this->error = $db->error()." sql=".$sql;
216  return -1; // Erreur
217  }
218  }
219 }
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($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
Parent class for third parties accountancy code generators.
info($langs)
Return description of module.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage accountancy code of thirdparties with Aquarium rules.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.
get_code($db, $societe, $type= '')
Set accountancy account code for a third party into this-&gt;code.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232