diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php new file mode 100644 index 00000000000..e3cc97fc61e --- /dev/null +++ b/htdocs/admin/contract.php @@ -0,0 +1,165 @@ + + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/admin/contract.php + * \ingroup contract + * \brief Setup page of module Contracts + * \version $Id$ + */ + +require("../main.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); +require_once(DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'); + +$langs->load("admin"); +$langs->load("bills"); +$langs->load("other"); +$langs->load("contracts"); + +if (!$user->admin) +accessforbidden(); + +/* + * Actions + */ +if ($_POST["action"] == 'updateMask') +{ + $maskconst=$_POST['maskconstcontract']; + $maskvalue=$_POST['maskcontract']; + if ($maskconst) dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity); +} + +if ($_GET["action"] == 'setmod') +{ + dolibarr_set_const($db, "CONTRACT_ADDON",$_GET["value"],'chaine',0,'',$conf->entity); +} + +// constants of magre model +if ($_POST["action"] == 'updateMatrice') dolibarr_set_const($db, "CONTRACT_NUM_MATRICE",$_POST["matrice"],'chaine',0,'',$conf->entity); +if ($_POST["action"] == 'updatePrefix') dolibarr_set_const($db, "CONTRACT_NUM_PREFIX",$_POST["prefix"],'chaine',0,'',$conf->entity); +if ($_POST["action"] == 'setOffset') dolibarr_set_const($db, "CONTRACT_NUM_DELTA",$_POST["offset"],'chaine',0,'',$conf->entity); +if ($_POST["action"] == 'setNumRestart') dolibarr_set_const($db, "CONTRACT_NUM_RESTART_BEGIN_YEAR",$_POST["numrestart"],'chaine',0,'',$conf->entity); + +/* + * View + */ +llxHeader(); + +$dir=DOL_DOCUMENT_ROOT."/includes/modules/contract/"; +$html=new Form($db); + +$linkback=''.$langs->trans("BackToModuleList").''; +print_fiche_titre($langs->trans("ContractsSetup"),$linkback,'setup'); + +print "
"; + +print_titre($langs->trans("ContractsNumberingModules")); + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$dir = "../includes/modules/contract/"; +$handle = opendir($dir); +if (is_resource($handle)) +{ + $var=true; + + while (($file = readdir($handle))!==false) + { + if (substr($file, 0, 13) == 'mod_contract_' && substr($file, dol_strlen($file)-3, 3) == 'php') + { + $file = substr($file, 0, dol_strlen($file)-4); + + require_once(DOL_DOCUMENT_ROOT ."/includes/modules/contract/".$file.".php"); + + $module = new $file; + + // Show modules according to features level + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; + + if ($module->isEnabled()) + { + $var=!$var; + print '\n"; + print ''; + + // Examples + print '\n"; + + print ''; + + $contract=new Contrat($db); + $contract->initAsSpecimen(); + + // Info + $htmltooltip=''; + $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; + $facture->type=0; + $nextval=$module->getNextValue($mysoc,$contract); + if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval + { + $htmltooltip.=''.$langs->trans("NextValue").': '; + if ($nextval) + { + $htmltooltip.=$nextval.'
'; + } + else + { + $htmltooltip.=$langs->trans($module->error).'
'; + } + } + + print ''; + + print ''; + } + } + } + closedir($handle); +} + +print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("Infos").'
'.$module->nom."'; + print $module->info(); + print ''.$module->getExample()."'; + if ($conf->global->CONTRACT_ADDON == "$file") + { + print img_picto($langs->trans("Activated"),'on'); + } + else + { + print ''; + print img_picto($langs->trans("Disabled"),'off'); + print ''; + } + print ''; + print $html->textwithpicto('',$htmltooltip,1,0); + print '

'; +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/includes/modules/contract/mod_contract_magre.php b/htdocs/includes/modules/contract/mod_contract_magre.php new file mode 100755 index 00000000000..7661a6c9c81 --- /dev/null +++ b/htdocs/includes/modules/contract/mod_contract_magre.php @@ -0,0 +1,131 @@ +< + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/includes/modules/contract/mod_contract_magre.php + * \ingroup contract + * \brief File of class to manage contract numbering rules Magre + * \version $Id$ + */ + +require_once(DOL_DOCUMENT_ROOT ."/includes/modules/contract/modules_contract.php"); + +/** \class mod_commande_magre + * \brief Class to manage contract numbering rules Magre + */ +class mod_contract_magre extends ModelNumRefContracts +{ + var $version='dolibarr'; + var $error = ''; + var $nom = 'Magre'; + + /** + * Return default description of numbering model + * @return string text description + */ + function info() + { + global $conf,$langs; + + $langs->load("bills"); + + $form = new Form($db); + + $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; + $texte.= '
'; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + + $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Contract")); + $tooltip.=$langs->trans("GenericMaskCodes2"); + $tooltip.=$langs->trans("GenericMaskCodes3"); + $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Contract"),$langs->transnoentities("Contract")); + $tooltip.=$langs->trans("GenericMaskCodes5"); + + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= '
'.$langs->trans("Mask").':'.$form->textwithpicto('',$tooltip,1,1).' 
'; + $texte.= '
'; + + return $texte; + } + + /** + * Return numbering example + * @return string Example + */ + function getExample() + { + global $conf,$langs,$mysoc; + + $old_code_client=$mysoc->code_client; + $mysoc->code_client='CCCCCCCCCC'; + $numExample = $this->getNextValue($mysoc,''); + $mysoc->code_client=$old_code_client; + + if (! $numExample) + { + $numExample = $langs->trans('NotConfigured'); + } + return $numExample; + } + + /** + * Return next value + * @param objsoc third party object + * @param contract contract object + * @return string Value if OK, 0 if KO + */ + function getNextValue($objsoc,$contract) + { + global $db,$conf; + + require_once(DOL_DOCUMENT_ROOT ."/lib/functions2.lib.php"); + + $mask=$conf->global->CONTRACT_MAGRE_MASK; + + if (! $mask) + { + $this->error='NotConfigured'; + return 0; + } + + $numFinal=get_next_value($db,$mask,'contrat','ref','',$objsoc->code_client,$contract->date_contrat); + + return $numFinal; + } + + /** + *Return next free value + * @param objsoc Object third party + * @param objforref Object for number to search + * @return string Next free value + */ + function contract_get_num($objsoc,$objforref) + { + return $this->getNextValue($objsoc,$objforref); + } + +} + +?> \ No newline at end of file diff --git a/htdocs/includes/modules/contract/mod_contract_serpis.php b/htdocs/includes/modules/contract/mod_contract_serpis.php new file mode 100755 index 00000000000..e537971ec3c --- /dev/null +++ b/htdocs/includes/modules/contract/mod_contract_serpis.php @@ -0,0 +1,142 @@ + + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/includes/modules/contract/mod_contract_serpis.php + * \ingroup contract + * \brief File of class to manage contract numbering rules Serpis + * \version $Id$ + */ +require_once(DOL_DOCUMENT_ROOT ."/includes/modules/contract/modules_contract.php"); + +/** \class mod_commande_serpis + * \brief Class to manage contract numbering rules Serpis + */ +class mod_contract_serpis extends ModelNumRefContracts +{ + var $version='dolibarr'; + var $prefix='CT'; + var $error=''; + var $nom='Serpis'; + + + /** + * Return default description of numbering model + * @return string text description + */ + function info() + { + global $langs; + return $langs->trans("SimpleNumRefModelDesc",$this->prefix); + } + + + /** + * Return numbering example + * @return string Example + */ + function getExample() + { + return $this->prefix."0501-0001"; + } + + + /** + * Test if existing numbers make problems with numbering + * @return boolean false if conflit, true if ok + */ + function canBeActivated() + { + global $conf,$langs; + + $coyymm=''; $max=''; + + $posindice=8; + $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; + $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; + $sql.= " WHERE ref LIKE '".$this->prefix."____-%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } + } + if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) + { + $langs->load("errors"); + $this->error=$langs->trans('ErrorNumRefModel', $max); + return false; + } + + return true; + } + + /** + * Return next value + * @param objsoc third party object + * @param contract contract object + * @return string Value if OK, 0 if KO + */ + function getNextValue($objsoc,$contract) + { + global $db,$conf; + + $posindice=8; + $sql = "SELECT MAX(SUBSTRING(ref FROM ".$posindice.")) as max"; + $sql.= " FROM ".MAIN_DB_PREFIX."contrat"; + $sql.= " WHERE ref like '".$this->prefix."____-%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $max = intval($obj->max); + else $max=0; + } + else + { + dol_syslog("mod_contract_serpis::getNextValue sql=".$sql); + return -1; + } + + $date=$contract->date_contrat; + $yymm = strftime("%y%m",$date); + $num = sprintf("%04s",$max+1); + + dol_syslog("mod_contract_serpis::getNextValue return ".$this->prefix.$yymm."-".$num); + return $this->prefix.$yymm."-".$num; + } + + + /** + *Return next free value + * @param objsoc Object third party + * @param objforref Object for number to search + * @return string Next free value + */ + function contract_get_num($objsoc,$objforref) + { + return $this->getNextValue($objsoc,$objforref); + } + +} +?> diff --git a/htdocs/includes/modules/contract/modules_contract.php b/htdocs/includes/modules/contract/modules_contract.php new file mode 100755 index 00000000000..08b9956f858 --- /dev/null +++ b/htdocs/includes/modules/contract/modules_contract.php @@ -0,0 +1,101 @@ + + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2011 Juanjo Menent + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/includes/modules/contract/mod_contract.php + * \ingroup contract + * \brief File of class to manage contract numbering + * \version $Id$ + */ + +class ModelNumRefContracts +{ + var $error=''; + + /** + * Return if a module can be used or not + * @return boolean true if module can be used + */ + function isEnabled() + { + return true; + } + + /** + * Return default description of numbering model + * @return string text description + */ + function info() + { + global $langs; + $langs->load("contracts"); + return $langs->trans("NoDescription"); + } + + /** + * Return numbering example + * @return string Example + */ + function getExample() + { + global $langs; + $langs->load("contracts"); + return $langs->trans("NoExample"); + } + + /** + * Test if existing numbers make problems with numbering + * @return boolean false if conflit, true if ok + */ + function canBeActivated() + { + return true; + } + + /** + * Return next value + * @return string Value + */ + function getNextValue() + { + global $langs; + return $langs->trans("NotAvailable"); + } + + /** + * Return numbering version module + * @return string Value + */ + function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == 'development') return $langs->trans("VersionDevelopment"); + if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); + if ($this->version == 'dolibarr') return DOL_VERSION; + return $langs->trans("NotAvailable"); + } +} +?> diff --git a/htdocs/includes/modules/modContrat.class.php b/htdocs/includes/modules/modContrat.class.php index fdf9c7603b9..2921bd919a6 100644 --- a/htdocs/includes/modules/modContrat.class.php +++ b/htdocs/includes/modules/modContrat.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin - * + * Copyright (C) 2011 Juanjo Menent * 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 @@ -68,10 +68,18 @@ class modContrat extends DolibarrModules // Dependances $this->depends = array("modService"); $this->requiredby = array(); + + // Config pages + $this->config_page_url = array("contract.php"); // Constantes $this->const = array(); - + $this->const[0][0] = "CONTRACT_ADDON"; + $this->const[0][1] = "chaine"; + $this->const[0][2] = "mod_contract_magre"; + $this->const[0][3] = 'Nom du gestionnaire de numerotation des contrats'; + $this->const[0][4] = 0; + // Boxes $this->boxes = array(); $this->boxes[0][1] = "box_contracts.php"; @@ -121,9 +129,9 @@ class modContrat extends DolibarrModules { global $conf; - // Nettoyage avant activation + // Nettoyage avant activation $this->remove(); - + return $this->_init($sql); } diff --git a/htdocs/langs/ca_ES/admin.lang b/htdocs/langs/ca_ES/admin.lang index 6618c95f23c..f403bfb4949 100644 --- a/htdocs/langs/ca_ES/admin.lang +++ b/htdocs/langs/ca_ES/admin.lang @@ -916,6 +916,9 @@ FreeLegalTextOnInterventions=Text addicional en les fitxes d'intervenció FicheinterNumberingModules=Mòduls de numeració de les fitxes d'intervenció TemplatePDFInterventions=Model de documents de les fitxes d'intervenció WatermarkOnDraftInterventionCards=Marca d'aigua en fitxes d'intervenció (en cas d'estar buit) +##### Contracts ##### +ContractsSetup=Configuració del mòdul contractes +ContractsNumberingModules=Mòduls de numeració dels contratos ##### Members ##### MembersSetup=Configuració del mòdulo Associacions MemberMainOptions=Opcions principals diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 6501914d8ae..f80a34d4463 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -913,6 +913,9 @@ FreeLegalTextOnInterventions=Free text on intervention documents FicheinterNumberingModules=Intervention numbering modules TemplatePDFInterventions=Intervention card documents models WatermarkOnDraftInterventionCards=Watermark on intervention card documents (any if empty) +##### Contracts ##### +ContractsSetup=Contracts module setup +ContractsNumberingModules=Contracts numbering modules ##### Members ##### MembersSetup=Members module setup MemberMainOptions=Main options diff --git a/htdocs/langs/es_AR/admin.lang b/htdocs/langs/es_AR/admin.lang index 7e2d987756b..8eee92cf97a 100755 --- a/htdocs/langs/es_AR/admin.lang +++ b/htdocs/langs/es_AR/admin.lang @@ -916,6 +916,9 @@ FreeLegalTextOnInterventions=Texto adicional en las fichas de intervención FicheinterNumberingModules=Módulos de numeración de las fichas de intervención TemplatePDFInterventions=Modelo de documentos de las fichas de intervención WatermarkOnDraftInterventionCards=Marca de agua en fichas de intervención (en caso de estar vacío) +##### Contracts ##### +ContractsSetup=Configuración del módulo contratos +ContractsNumberingModules=Módulos de numeración de los contratos ##### Members ##### MembersSetup=Configuración del módulo Asociaciones MemberMainOptions=Opciones principales diff --git a/htdocs/langs/es_ES/admin.lang b/htdocs/langs/es_ES/admin.lang index ab0c33a0074..e8588187f0b 100644 --- a/htdocs/langs/es_ES/admin.lang +++ b/htdocs/langs/es_ES/admin.lang @@ -916,6 +916,9 @@ FreeLegalTextOnInterventions=Texto adicional en las fichas de intervención FicheinterNumberingModules=Módulos de numeración de las fichas de intervención TemplatePDFInterventions=Modelo de documentos de las fichas de intervención WatermarkOnDraftInterventionCards=Marca de agua en fichas de intervención (en caso de estar vacío) +##### Contracts ##### +ContractsSetup=Configuración del módulo contratos +ContractsNumberingModules=Módulos de numeración de los contratos ##### Members ##### MembersSetup=Configuración del módulo Asociaciones MemberMainOptions=Opciones principales diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 4e29884c955..0e16deb661a 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -922,6 +922,9 @@ FreeLegalTextOnInterventions= Mention complémentaire sur les fiches d'intervent FicheinterNumberingModules= Modèles de numérotation des fiches d'intervention TemplatePDFInterventions= Modèle de document des fiches d'intervention WatermarkOnDraftInterventionCards= Filigrane sur les brouillons des fiches d'intervention (aucun si vide) +##### Contracts ##### +ContractsSetup=Configuration du module contrats +ContractsNumberingModules=Modèles de numérotation des contrats ##### Members ##### MembersSetup= Configuration du module Adhérents MemberMainOptions= Options principales