Amélioration de la gestion des modules de numérotation.

Ajout du module mod_propale_marbre (PRYYMM-9999)
Ajout du module mod_facture_terre (FAYYMM-9999)
This commit is contained in:
Laurent Destailleur 2005-08-22 19:39:55 +00:00
parent 7b0dad25c9
commit 1b3da4a138
8 changed files with 275 additions and 135 deletions

View File

@ -91,6 +91,11 @@ if ($_GET["action"] == 'delete')
} }
} }
/*
* Affiche page
*/
$dir = "../includes/modules/facture/"; $dir = "../includes/modules/facture/";
@ -109,9 +114,10 @@ print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Name").'</td>'; print '<td>'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>'; print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Example").'</td>'; print '<td nowrap>'.$langs->trans("Example").'</td>';
print '<td align="center" width="60">'.$langs->trans("Default").'</td>'; print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
print "</tr>\n"; print '<td nowrap>'.$langs->trans("NextValue").'</td>';
print '</tr>'."\n";
clearstatcache(); clearstatcache();
@ -120,37 +126,39 @@ $handle=opendir($dir);
$var=True; $var=True;
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') if (is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
{ {
$var = !$var; $var = !$var;
print '<tr '.$bc[$var].'><td width="100">'; print '<tr '.$bc[$var].'><td width="100">';
echo "$file"; echo "$file";
print "</td><td>\n"; print "</td><td>\n";
$filebis = $file."/".$file.".modules.php"; $filebis = $file."/".$file.".modules.php";
// Chargement de la classe de numérotation // Chargement de la classe de numérotation
$classname = "mod_facture_".$file; $classname = "mod_facture_".$file;
require_once($dir.$filebis); require_once($dir.$filebis);
$obj = new $classname($db); $obj = new $classname($db);
print $obj->info(); print $obj->info();
print '</td>'; print '</td>';
// Affiche example // Affiche example
print '<td>'.$obj->getExample().'</td>'; print '<td>'.$obj->getExample().'</td>';
print '<td align="center">'; print '<td align="center">';
if ($facture_addon_var == "$file") if ($facture_addon_var == "$file")
{ {
print img_tick(); print img_tick();
} print "</td><td nowrap>".$obj->getNextValue()."</td>\n";
else }
{ else
print '<a href="facture.php?action=set&amp;value='.$file.'">'.$langs->trans("Default").'</a>'; {
} print '<a href="facture.php?action=set&amp;value='.$file.'">'.$langs->trans("Default").'</a>';
print "</td></tr>\n"; print "</td><td nowrap>&nbsp;</td>\n";
}
print "</td></tr>\n";
} }
} }
closedir($handle); closedir($handle);

View File

@ -23,7 +23,8 @@
* $Source$ * $Source$
*/ */
/** \file htdocs/admin/propale.php /**
\file htdocs/admin/propale.php
\ingroup propale \ingroup propale
\brief Page d'administration/configuration du module Propale \brief Page d'administration/configuration du module Propale
\version $Revision$ \version $Revision$
@ -40,35 +41,30 @@ if (!$user->admin)
if ($_POST["action"] == 'nbprod') if ($_POST["action"] == 'nbprod')
{ {
dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$value); dolibarr_set_const($db, "PROPALE_NEW_FORM_NB_PRODUCT",$value);
Header("Location: propale.php"); Header("Location: propale.php");
} }
llxHeader();
if ($_GET["action"] == 'set') if ($_GET["action"] == 'set')
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_model_pdf (nom) VALUES ('".$_GET["value"]."')"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_model_pdf (nom) VALUES ('".$_GET["value"]."')";
if ($db->query($sql)) if ($db->query($sql))
{ {
} }
} }
if ($_GET["action"] == 'del') if ($_GET["action"] == 'del')
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_model_pdf WHERE nom='".$_GET["value"]."'"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_model_pdf WHERE nom='".$_GET["value"]."'";
if ($db->query($sql)) if ($db->query($sql))
{ {
} }
} }
// positionne la variable pour le test d'affichage de l'icone
$propale_addon_var_pdf = PROPALE_ADDON_PDF; $propale_addon_var_pdf = $conf->global->PROPALE_ADDON_PDF;
if ($_GET["action"] == 'setpdf') if ($_GET["action"] == 'setpdf')
{ {
@ -90,10 +86,15 @@ if ($_GET["action"] == 'setpdf')
} }
} }
$propale_addon_var = PROPALE_ADDON; $propale_addon_var = $conf->global->PROPALE_ADDON;
if ($_GET["action"] == 'setmod') if ($_GET["action"] == 'setmod')
{ {
// \todo Verifier si module numerotation choisi peut etre activé
// par appel methode canBeActivated
if (dolibarr_set_const($db, "PROPALE_ADDON",$_GET["value"])) if (dolibarr_set_const($db, "PROPALE_ADDON",$_GET["value"]))
{ {
// la constante qui a été lue en avant du nouveau set // la constante qui a été lue en avant du nouveau set
@ -103,62 +104,72 @@ if ($_GET["action"] == 'setmod')
} }
/* /*
* Affiche page * Affiche page
*/ */
$dir = "../includes/modules/propale/";
llxHeader('',$langs->trans("PropalSetup"));
print_titre($langs->trans("PropalSetup")); print_titre($langs->trans("PropalSetup"));
print "<br>";
/*
* Module numérotation
*/
print "<br>";
print_titre($langs->trans("ProposalsNumberingModules")); print_titre($langs->trans("ProposalsNumberingModules"));
print "<table class=\"noborder\" width=\"100%\">\n"; print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">\n"; print '<tr class="liste_titre">';
print " <td>".$langs->trans("Name")."</td>\n"; print '<td>'.$langs->trans("Name")."</td>\n";
print " <td>".$langs->trans("Description")."</td>\n"; print '<td>'.$langs->trans("Description")."</td>\n";
print " <td>".$langs->trans("Example")."</td>\n"; print '<td nowrap>'.$langs->trans("Example")."</td>\n";
print " <td align=\"center\">".$langs->trans("Activated")."</td>\n"; print '<td align="center" width="60">'.$langs->trans("Activated")."</td>\n";
print "</tr>\n"; print '<td nowrap>'.$langs->trans("NextValue")."</td>\n";
print '</tr>'."\n";
clearstatcache(); clearstatcache();
$dir = "../includes/modules/propale/";
$handle = opendir($dir); $handle = opendir($dir);
if ($handle) if ($handle)
{ {
$var=true; $var=true;
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php') if (substr($file, 0, 12) == 'mod_propale_' && substr($file, strlen($file)-3, 3) == 'php')
{ {
$file = substr($file, 0, strlen($file)-4); $file = substr($file, 0, strlen($file)-4);
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$file.".php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/".$file.".php");
$modPropale = new $file; $modPropale = new $file;
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].">\n <td width=\"140\">".$file."</td>"; print "<tr ".$bc[$var].">\n <td width=\"140\">".$file."</td>";
print "\n <td>".$modPropale->info()."</td>\n"; print "\n <td>".$modPropale->info()."</td>\n";
print "\n <td>".$modPropale->getExample()."</td>\n"; print "\n <td nowrap>".$modPropale->getExample()."</td>\n";
if ($propale_addon_var == "$file") if ($propale_addon_var == "$file")
{ {
print '<td align="center">'; print '<td align="center">';
print img_tick(); print img_tick();
print '</td>'; print '</td>';
} print "\n <td nowrap>".$modPropale->getNextValue()."</td>\n";
else }
{ else
print "<td align=\"center\"><a href=\"propale.php?action=setmod&amp;value=".$file."\">".$langs->trans("Activate")."</a></td>\n"; {
} print "<td align=\"center\"><a href=\"propale.php?action=setmod&amp;value=".$file."\">".$langs->trans("Activate")."</a></td>\n";
print "\n <td nowrap>&nbsp;</td>\n";
}
print "</tr>\n";
} print "</tr>\n";
}
} }
closedir($handle); closedir($handle);
} }
print "</table><br>\n"; print "</table><br>\n";

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com> * Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
* *
@ -21,10 +21,10 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** \file htdocs/includes/modules/facture/modules_facture.php /**
\file htdocs/includes/modules/facture/modules_facture.php
\ingroup facture \ingroup facture
\brief Fichier contenant la classe mère de generation des factures en PDF \brief Fichier contenant la classe mère de generation des factures en PDF
et la classe mère de numérotation des factures et la classe mère de numérotation des factures
@ -83,14 +83,23 @@ class ModeleNumRefFactures
return $langs->trans("NoExample"); return $langs->trans("NoExample");
} }
/** /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de
\brief Renvoi le dernier message d'erreur de création de facture * de conflits qui empechera cette numérotation de fonctionner.
*/ * \return boolean false si conflit, true si ok
function numreferror() */
function canBeActivated()
{ {
return $this->error; return true;
} }
/** \brief Renvoi prochaine valeur attribuée
* \return string Valeur
*/
function getNextValue()
{
global $langs;
return $langs->trans("NotAvailable");
}
} }
@ -235,8 +244,7 @@ function facture_get_num($soc, $prefixe_additionnel='')
} }
else else
{ {
dolibarr_syslog("Erreur dans facture_get_num"); dolibarr_print_error($db,"modules_facture::facture_get_num ".$obj->error);
dolibarr_print_error($db,$obj->numreferror());
return ""; return "";
} }
} }

View File

@ -0,0 +1,135 @@
<?php
/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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/
*
* $Id$
* $Source$
*/
/**
\file htdocs/includes/modules/facture/terre/terre.modules.php
\ingroup facture
\brief Fichier contenant la classe du modèle de numérotation de référence de facture Terre
\version $Revision$
*/
/** \class mod_facture_terre
\brief Classe du modèle de numérotation de référence de facture Terre
*/
class mod_facture_terre extends ModeleNumRefFactures
{
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
return "Renvoie le numéro sous la forme FAyymm-nnnn où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0";
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "FA0501-0001";
}
/** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de
* de conflits qui empechera cette numérotation de fonctionner.
* \return boolean false si conflit, true si ok
*/
function canBeActivated()
{
$fayymm='';
$sql = "SELECT MAX(facnumber)";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $fayymm = substr($row[0],0,6);
}
if (! $fayymm || eregi('FA[0-9][0-9][0-9][0-9]',$fayymm))
{
return true;
}
else
{
$this->error='Une facture commençant par $fayymm existe en base et est incompatible avec cette numérotation. Supprimer la ou renommer la pour activer ce module.';
return false;
}
}
/** \brief Renvoi prochaine valeur attribuée
* \return string Valeur
*/
function getNextValue()
{
global $db;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
$fayymm='';
$sql = "SELECT MAX(facnumber)";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $fayymm = substr($row[0],0,6);
}
// Si au moins un champ respectant le modèle a été trouvée
if (eregi('FA[0-9][0-9][0-9][0-9]',$fayymm))
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=8;
$sql = "SELECT MAX(0+SUBSTR(facnumber,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber like '${fayymm}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
$yymm = strftime("%y%m",time());
$num = sprintf("%04s",$max+1);
return "FA$yymm-$num";
}
/** \brief Renvoie la référence de facture suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function getNumRef($objsoc=0)
{
return $this->getNextValue();
}
}
?>

View File

@ -86,14 +86,6 @@ class ModeleNumRefFicheinter
return $langs->trans("NoExample"); return $langs->trans("NoExample");
} }
/**
\brief Renvoi le dernier message d'erreur de création de fiche intervention
*/
function numreferror()
{
return $this->error;
}
} }

View File

@ -60,7 +60,20 @@ class mod_propale_ivoire extends ModeleNumRefPropales
*/ */
function getNextValue() function getNextValue()
{ {
return $this->propale_get_num(); global $db;
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal";
if ( $db->query($sql) )
{
$row = $db->fetch_row(0);
$num = $row[0];
}
$y = strftime("%y",time());
return "PR" . "$y" . substr("000".$num, strlen("000".$num)-4,4);
} }
@ -70,21 +83,7 @@ class mod_propale_ivoire extends ModeleNumRefPropales
*/ */
function propale_get_num($objsoc=0) function propale_get_num($objsoc=0)
{ {
global $db; return $this->propale_get_num();
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."propal";
if ( $db->query($sql) )
{
$row = $db->fetch_row(0);
$num = $row[0];
}
$y = strftime("%y",time());
return "PR" . "$y" . substr("000".$num, strlen("000".$num)-4,4);
} }
} }

View File

@ -60,16 +60,6 @@ class mod_propale_jade extends ModeleNumRefPropales
* \return string Valeur * \return string Valeur
*/ */
function getNextValue() function getNextValue()
{
return $this->propale_get_num();
}
/** \brief Renvoie la référence de propale suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function propale_get_num($objsoc=0)
{ {
global $db; global $db;
@ -86,6 +76,16 @@ class mod_propale_jade extends ModeleNumRefPropales
return "PROP" . ($num+1); return "PROP" . ($num+1);
} }
/** \brief Renvoie la référence de propale suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function propale_get_num($objsoc=0)
{
return $this->propale_get_num();
}
} }
?> ?>

View File

@ -131,20 +131,7 @@ class mod_propale_marbre extends ModeleNumRefPropales
*/ */
function propale_get_num($objsoc=0) function propale_get_num($objsoc=0)
{ {
global $db; return $this->getNextValue();
$sql = "SELECT MAX(ref) as nb FROM ".MAIN_DB_PREFIX."propal";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$num = $row[0];
}
$yymm = strftime("%y%m",time());
return "PR$yymm-".$obj->prefix.'-'.substr("000".$num, 0,-4);
} }
} }