* Copyright (C) 2005 Eric Seigne * Copyright (C) 2006-2011 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see http://www.gnu.org/ */ /** * \file htdocs/includes/modules/societe/mod_codecompta_aquarium.php * \ingroup societe * \brief File of class to manage accountancy code of thirdparties with Panicum rules */ require_once(DOL_DOCUMENT_ROOT."/includes/modules/societe/modules_societe.class.php"); /** * \class mod_codecompta_aquarium * \brief Class to manage accountancy code of thirdparties with Aquarium rules */ class mod_codecompta_aquarium extends ModeleAccountancyCode { var $nom='Aquarium'; var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $prefixcustomeraccountancycode='411'; var $prefixsupplieraccountancycode='401'; /** * Constructor */ function mod_codecompta_aquarium() { global $conf; $this->prefixcustomeraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_CUSTOMER; $this->prefixsupplieraccountancycode=$conf->global->COMPANY_AQUARIUM_MASK_SUPPLIER; } /** Return description of module * * @param $langs Object langs * @return string Description of module */ function info($langs) { global $conf; $langs->load("companies"); $form = new Form($db); $tooltip=''; $texte = '
'; $texte.= ''; $texte.= ''; $texte.= ''; $texte.= ''; $texte.= ''; $s1= $form->textwithpicto('',$tooltip,1,1); $s2= $form->textwithpicto('',$tooltip,1,1); $texte.= ''; $texte.= ''; $texte.= '
'.$langs->trans("ModuleCompanyCode".$this->nom,$s1,$s2)."
\n"; $texte.= '
 
'; $texte.= '
'; return $texte; } /** Return an example of result returned by getNextValue * * @param $langs Object langs * @param $objsoc Object thirdparty * @param $type Type of third party (1:customer, 2:supplier, -1:autodetect) */ function getExample($langs,$objsoc=0,$type=-1) { return $this->prefixsupplieraccountancycode.'SUPPCODE'."
\n".$this->prefixcustomeraccountancycode.'CUSTCODE'; } /** * Set accountancy account code for a third party into this->code * * @param db Database handler * @param societe Third party object * @param type 'customer' or 'supplier' * @return int >=0 if OK, <0 if KO */ function get_code($db, $societe, $type) { $i = 0; $this->db = $db; dol_syslog("mod_codecompta_aquarium::get_code search code for type=".$type." company=".$societe->nom); // Regle gestion compte compta $codetouse=''; if ($type == 'customer') $codetouse = $this->prefixcustomeraccountancycode; if ($type == 'supplier') $codetouse = $this->prefixsupplieraccountancycode; if ($type == 'customer') $codetouse.= ($societe->code_client?$societe->code_client:'CUSTCODE'); if ($type == 'supplier') $codetouse.= ($societe->code_fournisseur?$societe->code_fournisseur:'SUPPCODE'); $codetouse=strtoupper(preg_replace('/([^a-z0-9])/i','',$codetouse)); $is_dispo = $this->verif($db, $codetouse, $societe, $type); if (! $is_dispo) { $this->code=$codetouse; } else { // Pour retour $this->code=$codetouse; } dol_syslog("mod_codecompta_aquarium::get_code found code=".$this->code); return $is_dispo; } /** * Return if a code is available * * @param db Database handler * @param code Code of third party * @param societe Object third party * @param type 'supplier' or 'customer' * @return int 0 if OK but not available, >0 if OK and available, <0 if KO */ function verif($db, $code, $societe, $type) { $sql = "SELECT "; if ($type == 'customer') $sql.= "code_compta"; if ($type == 'supplier') $sql.= "code_compta_fournisseur"; $sql.= " FROM ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE "; if ($type == 'customer') $sql.= "code_compta"; if ($type == 'supplier') $sql.= "code_compta_fournisseur"; $sql.= " = '".$code."'"; $sql.= " AND rowid != ".$societe->id; $resql=$db->query($sql); if ($resql) { if ($db->num_rows($resql) == 0) { dol_syslog("mod_codecompta_aquarium::verif code '".$code."' available"); return 1; // Dispo } else { dol_syslog("mod_codecompta_aquarium::verif code '".$code."' not available"); return 0; // Non dispo } } else { $this->error=$db->error()." sql=".$sql; dol_syslog("mod_codecompta_aquarium::verif error".$this->error, LOG_ERR); return -1; // Erreur } } } ?>