Task #10577: Works with contracts

This commit is contained in:
Juanjo Menent 2011-02-18 17:12:22 +00:00
parent 9cc0956cd5
commit 80a4107c35
10 changed files with 566 additions and 4 deletions

165
htdocs/admin/contract.php Normal file
View File

@ -0,0 +1,165 @@
<?php
/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("ContractsSetup"),$linkback,'setup');
print "<br>";
print_titre($langs->trans("ContractsNumberingModules"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="100">'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Example").'</td>';
print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
print "</tr>\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 '<tr '.$bc[$var].'><td>'.$module->nom."</td>\n";
print '<td>';
print $module->info();
print '</td>';
// Examples
print '<td nowrap="nowrap">'.$module->getExample()."</td>\n";
print '<td align="center">';
if ($conf->global->CONTRACT_ADDON == "$file")
{
print img_picto($langs->trans("Activated"),'on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"),'off');
print '</a>';
}
print '</td>';
$contract=new Contrat($db);
$contract->initAsSpecimen();
// Info
$htmltooltip='';
$htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$facture->type=0;
$nextval=$module->getNextValue($mysoc,$contract);
if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
{
$htmltooltip.=''.$langs->trans("NextValue").': ';
if ($nextval)
{
$htmltooltip.=$nextval.'<br>';
}
else
{
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}
print '<td align="center">';
print $html->textwithpicto('',$htmltooltip,1,0);
print '</td>';
print '</tr>';
}
}
}
closedir($handle);
}
print '</table><br>';
$db->close();
llxFooter('$Date$ - $Revision$');
?>

View File

@ -0,0 +1,131 @@
<<?php
/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstcontract" value="CONTRACT_MAGRE_MASK">';
$texte.= '<table class="nobordernopadding" width="100%">';
$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.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskcontract" value="'.$conf->global->CONTRACT_MAGRE_MASK.'">',$tooltip,1,1).'</td>';
$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '</tr>';
$texte.= '</table>';
$texte.= '</form>';
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);
}
}
?>

View File

@ -0,0 +1,142 @@
<?php
/* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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);
}
}
?>

View File

@ -0,0 +1,101 @@
<?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
*
* 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");
}
}
?>

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
*
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* 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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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