dolibarr  7.0.0-beta
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 {
34  var $nom='Aquarium';
35  var $name='Aquarium';
36  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
37 
38  var $prefixcustomeraccountancycode;
39  var $prefixsupplieraccountancycode;
40 
41 
45  function __construct()
46  {
47  global $conf;
48  if (! isset($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) || trim($conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER) == '') $conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER='411';
49  if (! isset($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) || trim($conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER) == '') $conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER='401';
50  $this->prefixcustomeraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER;
51  $this->prefixsupplieraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER;
52  }
53 
54 
61  function info($langs)
62  {
63  global $conf;
64  global $form;
65 
66  $langs->load("companies");
67 
68  $tooltip='';
69  $texte = '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
70  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
71  $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
72  $texte.= '<input type="hidden" name="param1" value="COMPANY_AQUARIUM_MASK_SUPPLIER">';
73  $texte.= '<input type="hidden" name="param2" value="COMPANY_AQUARIUM_MASK_CUSTOMER">';
74  $texte.= '<table class="nobordernopadding" width="100%">';
75  $s1= $form->textwithpicto('<input type="text" class="flat" size="4" name="value1" value="'.$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER.'">',$tooltip,1,1);
76  $s2= $form->textwithpicto('<input type="text" class="flat" size="4" name="value2" value="'.$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER.'">',$tooltip,1,1);
77  $texte.= '<tr><td>'.$langs->trans("ModuleCompanyCode".$this->name,$s1,$s2)."<br>\n";
78  $texte.= '</td>';
79  $texte.= '<td align="left">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
80  $texte.= '</tr></table>';
81  $texte.= '</form>';
82 
83  return $texte;
84  }
85 
94  function getExample($langs,$objsoc=0,$type=-1)
95  {
96  return $this->prefixsupplieraccountancycode.'SUPPCODE'."<br>\n".$this->prefixcustomeraccountancycode.'CUSTCODE';
97  }
98 
99 
108  function get_code($db, $societe, $type='')
109  {
110  $i = 0;
111  $this->db = $db;
112 
113  dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".(! empty($societe->name)?$societe->name:''));
114 
115  // Regle gestion compte compta
116  $codetouse='';
117  if ($type == 'customer')
118  {
119  $codetouse = $this->prefixcustomeraccountancycode;
120  $codetouse.= (! empty($societe->code_client)?$societe->code_client:'CUSTCODE');
121  }
122  else if ($type == 'supplier')
123  {
124  $codetouse = $this->prefixsupplieraccountancycode;
125  $codetouse.= (! empty($societe->code_fournisseur)?$societe->code_fournisseur:'SUPPCODE');
126  }
127  $codetouse=strtoupper(preg_replace('/([^a-z0-9])/i','',$codetouse));
128 
129  $is_dispo = $this->verif($db, $codetouse, $societe, $type);
130  if (! $is_dispo)
131  {
132  $this->code=$codetouse;
133  }
134  else
135  {
136  // Pour retour
137  $this->code=$codetouse;
138  }
139  dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code);
140  return $is_dispo;
141  }
142 
143 
153  function verif($db, $code, $societe, $type)
154  {
155  $sql = "SELECT ";
156  if ($type == 'customer') $sql.= "code_compta";
157  else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
158  $sql.= " FROM ".MAIN_DB_PREFIX."societe";
159  $sql.= " WHERE ";
160  if ($type == 'customer') $sql.= "code_compta";
161  else if ($type == 'supplier') $sql.= "code_compta_fournisseur";
162  $sql.= " = '".$db->escape($code)."'";
163  if (! empty($societe->id)) $sql.= " AND rowid <> ".$societe->id;
164 
165  $resql=$db->query($sql);
166  if ($resql)
167  {
168  if ($db->num_rows($resql) == 0)
169  {
170  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available");
171  return 1; // Dispo
172  }
173  else
174  {
175  dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available");
176  return 0; // Non dispo
177  }
178  }
179  else
180  {
181  $this->error=$db->error()." sql=".$sql;
182  return -1; // Erreur
183  }
184  }
185 }
186 
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(empty($reshook)) $form
View.
Definition: perms.php:103
Parent class for third parties accountancy code generators.
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.
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:1013