New: A generic propal numbering module (depreciate all others)

This commit is contained in:
Laurent Destailleur 2008-03-05 22:05:11 +00:00
parent b9d36ccdc6
commit f7d61cac0c
7 changed files with 146 additions and 1033 deletions

View File

@ -1,173 +0,0 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
* 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/propale/mod_propale_diamant.php
\ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Diamant
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/** \class mod_propale_diamant
\brief Classe du modèle de numérotation de référence de propale Diamant
*/
class mod_propale_diamant extends ModeleNumRefPropales
{
/** \brief Constructeur
*/
function mod_propale_diamant()
{
$this->nom = "Diamant";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
$texte = "Renvoie le numéro sous la forme numérique PRYYNNNNN où YY représente l'année et NNNNN Le numéro d'incrément. Ce dernier n'est PAS remis à zéro en début d'année.<br>\n";
$texte.= "Si la constante PROPALE_DIAMANT_DELTA est définie, un offset est appliqué sur le compteur";
if (defined("PROPALE_DIAMANT_DELTA"))
{
$texte .= " (Définie et vaut: ".PROPALE_DIAMANT_DELTA.")";
}
else
{
$texte .= " (N'est pas définie)";
}
return $texte;
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
$y = strftime("%y",time());
if (defined("PROPALE_DIAMANT_DELTA"))
{
$num = sprintf("%02d",PROPALE_DIAMANT_DELTA);
return "PR".$y.substr("0000".$num, strlen("0000".$num)-5,5);
}
else
{
return "PR".$y."00001";
}
}
/** \brief Renvoi prochaine valeur attribuée
* \param objsoc Objet société
* \return string Valeur
*/
function getNextValue($objsoc=0)
{
global $db, $conf;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
$prefix='PR';
$current_year = strftime("%y",time());
$last_year = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")-1));
$pryy = $prefix.$current_year;
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${pryy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$pryy='';
if ($row[0]!='')
{
$pryy = substr($row[0],0,4);
}
else
{
$pryy = $prefix.$last_year;
}
}
//on vérifie si il y a une année précédente
//sinon le delta sera appliqué de nouveau sur la nouvelle année
$lastyy = $prefix.$last_year;
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${lastyy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$lastyy='';
if ($row) $lastyy = substr($row[0],0,4);
}
// Si au moins un champ respectant le modèle a été trouvée
if (eregi('PR[0-9][0-9]',$pryy))
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=5;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${pryy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else if (!eregi('PR[0-9][0-9]',$lastyy))
{
$max=$conf->global->PROPALE_DIAMANT_DELTA?$conf->global->PROPALE_DIAMANT_DELTA:0;
}
$num = sprintf("%05s",$max+1);
$yy = strftime("%y",time());
return "PR$yy$num";
}
/** \brief Renvoie la référence de propale suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function getNumRef($objsoc=0)
{
return $this->getNextValue();
}
}
?>

View File

@ -1,144 +0,0 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
* 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/propale/mod_propale_emeraude.php
\ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Emeraude
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/** \class mod_propale_emeraude
\brief Classe du modèle de numérotation de référence de propale Emeraude
*/
class mod_propale_emeraude extends ModeleNumRefPropales
{
/** \brief Constructeur
*/
function mod_propale_emeraude()
{
$this->nom = "Emeraude";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
global $conf,$langs;
$langs->load("propal");
$texte = $langs->trans('EmeraudeNumRefModelDesc1')."<br>\n";
$texte.= $langs->trans('EmeraudeNumRefModelDesc2')."<br>\n";
$texte.= $langs->trans('EmeraudeNumRefModelDesc3')."<br>\n";
$texte.= $langs->trans('EmeraudeNumRefModelDesc4')."<br>\n";
if ($conf->global->SOCIETE_FISCAL_MONTH_START)
{
$texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).')';
}
else
{
$texte.= ' ('.$langs->trans('IsNotDefined').')';
}
return $texte;
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "PR0500001";
}
/** \brief Renvoi prochaine valeur attribuée
* \return string Valeur
*/
function getNextValue($objsoc=0)
{
global $db,$conf;
// D'abord on défini l'année fiscale
$prefix='PR';
$current_month = date("n");
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
{
$yy = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1));
}
else
{
$yy = strftime("%y",time());
}
// On récupère la valeur max (réponse immédiate car champ indéxé)
$fisc=$prefix.$yy;
$pryy='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${fisc}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $pryy = substr($row[0],0,4);
}
// Si au moins un champ respectant le modèle a été trouvé
if (eregi('PR[0-9][0-9]',$pryy))
{
// Recherche rapide car restreint par un like sur champ indexé
$date = strftime("%Y%m", time());
$posindice=5;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${pryy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
$num = sprintf("%05s",$max+1);
return "PR$yy$num";
}
}
?>

View File

@ -1,138 +0,0 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
* 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/propale/mod_propale_ivoire.php
\ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Ivoire
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/** \class mod_propale_ivoire
\brief Classe du modèle de numérotation de référence de propale Ivoire
*/
class mod_propale_ivoire extends ModeleNumRefPropales
{
/** \brief Constructeur
*/
function mod_propale_ivoire()
{
$this->nom = "Ivoire";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
return "Renvoie le numéro sous la forme PRyynnnn où yy est l'année et nnnn un compteur sans remise à 0";
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "PR050001";
}
/** \brief Renvoi prochaine valeur attribuée
* \param objsoc Objet société
* \return string Valeur
*/
function getNextValue($objsoc=0)
{
global $db;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
$prefix='PR';
$current_year = strftime("%y",time());
$last_year = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")-1));
$pryy = $prefix.$current_year;
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${pryy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$pryy='';
if ($row[0]!='')
{
$pryy = substr($row[0],0,4);
}
else
{
$pryy = $prefix.$last_year;
}
}
// Si au moins un champ respectant le modèle a été trouvée
if (eregi('PR[0-9][0-9]',$pryy))
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=5;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '${pryy}%'";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
$num = sprintf("%04s",$max+1);
$yy = strftime("%y",time());
return "PR$yy$num";
}
/** \brief Renvoie la référence de propale suivante non utilisée
* \param objsoc Objet société
* \return string Texte descripif
*/
function getNumRef($objsoc=0)
{
return $this->getNextValue();
}
}
?>

View File

@ -1,102 +0,0 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr>
*
* 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/propale/mod_propale_jade.php
\ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Jade
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/**
\class mod_propale_jade
\brief Classe du modèle de numérotation de référence de propale Jade
*/
class mod_propale_jade extends ModeleNumRefPropales
{
/** \brief Constructeur
*/
function mod_propale_jade()
{
$this->nom = "Jade";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
return "Renvoie le numéro sous la forme PROPn ou n est un compteur continue sans remise à 0";
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "PROP1";
}
/** \brief Renvoi prochaine valeur attribuée
* \param objsoc Objet société
* \return string Valeur
*/
function getNextValue($objsoc=0)
{
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 "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 getNumRef($objsoc=0)
{
return $this->getNextValue();
}
}
?>

View File

@ -16,16 +16,13 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/includes/modules/propale/mod_propale_marbre.php \file htdocs/includes/modules/propale/mod_propale_marbre.php
\ingroup propale \ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Marbre \brief Fichier contenant la classe du modèle de numérotation de référence de propale Marbre
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
@ -37,16 +34,12 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php")
class mod_propale_marbre extends ModeleNumRefPropales class mod_propale_marbre extends ModeleNumRefPropales
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='PR'; var $prefix='PR';
var $error=''; var $error='';
var $nom = "Marbre";
/** \brief Constructeur
*/
function mod_propale_marbre()
{
$this->nom = "Marbre";
}
/** \brief Renvoi la description du modele de numérotation /** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif * \return string Texte descripif
*/ */

View File

@ -1,140 +0,0 @@
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
*
* 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/propale/mod_propale_rubis.php
\ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Rubis
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/** \class mod_propale_rubis
\brief Classe du modèle de numérotation de référence de propale Rubis
*/
class mod_propale_rubis extends ModeleNumRefPropales
{
/** \brief Constructeur
*/
function mod_propale_rubis()
{
$this->nom = "Rubis";
}
/** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif
*/
function info()
{
global $conf,$langs;
$langs->load("propal");
$texte = $langs->trans('RubisNumRefModelDesc1')."<br>\n";
$texte.= $langs->trans('RubisNumRefModelDesc2')."<br>\n";
$texte.= $langs->trans('RubisNumRefModelDesc3')."<br>\n";
$texte.= $langs->trans('RubisNumRefModelDesc4')."<br>\n";
if ($conf->global->SOCIETE_FISCAL_MONTH_START)
{
$texte.= ' ('.$langs->trans('DefinedAndHasThisValue').' : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).')';
}
else
{
$texte.= ' ('.$langs->trans('IsNotDefined').')';
}
return $texte;
}
/** \brief Renvoi un exemple de numérotation
* \return string Example
*/
function getExample()
{
return "PR0600001";
}
/** \brief Renvoi prochaine valeur attribuée
* \return string Valeur
*/
function getNextValue($objsoc=0)
{
global $db,$conf;
// D'abord on défini l'année fiscale
$prefix='PR';
$current_month = date("n");
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
{
$yy = strftime("%y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1));
}
else
{
$yy = strftime("%y",time());
}
// On récupère la valeur max (réponse immédiate car champ indéxé)
$pryy='';
$sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) $pryy = substr($row[0],0,4);
}
// Si au moins un champ respectant le modèle a été trouvée
if (eregi('PR[0-9][0-9]',$pryy))
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=5;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
$max = $row[0];
}
}
else
{
$max=0;
}
$num = sprintf("%05s",$max+1);
return "PR$yy$num";
}
}
?>

View File

@ -17,103 +17,58 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/ * or see http://www.gnu.org/
*
* $Id$
* $Source$
*
*/ */
/** /**
\file htdocs/includes/modules/propale/mod_propale_saphir.php \file htdocs/includes/modules/propale/mod_propale_saphir.php
\ingroup propale \ingroup propale
\brief Fichier contenant la classe du modèle de numérotation de référence de propale Saphir \brief Fichier contenant la classe du modèle de numérotation de référence de propale Saphir
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php");
/** /**
\class mod_propale_saphir \class mod_propale_saphir
\brief Classe du modèle de numérotation de référence de propale Saphir \brief Classe du modèle de numérotation de référence de propale Saphir
*/ */
class mod_propale_saphir extends ModeleNumRefPropales class mod_propale_saphir extends ModeleNumRefPropales
{ {
var $prefix; var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $matrice;
var $numMatrice = Array();
var $yy;
var $mm;
var $numbitcounter;
var $searchLast;
var $searchLastWithNoYear;
var $searchLastWithPreviousYear;
var $error = ''; var $error = '';
var $nom = 'Saphir';
/** \brief Constructeur
*/
function mod_propale_saphir()
{
$this->nom = "Saphir";
}
/** \brief Renvoi la description du modele de numérotation /** \brief Renvoi la description du modele de numérotation
* \return string Texte descripif * \return string Texte descripif
*/ */
function info() function info()
{ {
global $conf,$langs; global $conf,$langs;
$langs->load("bills"); $langs->load("bills");
$form = new Form($db); $form = new Form($db);
$texte = $langs->trans('SaphirNumRefModelDesc1')."<br>\n"; $texte = $langs->trans('SaphirNumRefModelDesc1')."<br>\n";
$texte.= '<table class="nobordernopadding" width="100%">'; $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
// Paramétrage de la matrice $texte.= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
$texte.= '<tr><td>Matrice de disposition des objets (prefix,mois,année,compteur...)</td>'; $texte.= '<table class="nobordernopadding" width="100%">';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updateMatrice">'; // Parametrage du prefix des factures
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="matrice" value="'.$conf->global->PROPALE_NUM_MATRICE.'"></td>'; $texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; $texte.= '<td align="right">'.$form->textwithhelp('<input type="text" class="flat" size="24" name="maskpropal" value="'.$conf->global->PROPALE_SAPHIR_MASK.'">',$langs->trans("GenericMaskCodes",$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal"),$langs->transnoentities("Proposal")),1,1).'</td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("MatriceProposalDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// Paramétrage du prefix des commandes
$texte.= '<tr><td>Préfix des propositions commerciales</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="updatePrefix">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="prefix" value="'.$conf->global->PROPALE_NUM_PREFIX.'"></td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("PrefixProposalDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// On détermine un offset sur le compteur
$texte.= '<tr><td>Appliquer un offset sur le compteur</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="setOffset">';
$texte.= '<td align="right"><input type="text" class="flat" size="30" name="offset" value="'.$conf->global->PROPALE_NUM_DELTA.'"></td>';
$texte.= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("OffsetDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// On défini si le compteur se remet à zero en debut d'année
$texte.= '<tr><td>Le compteur se remet à zéro en début d\'année</td>';
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="action" value="setNumRestart">';
$texte.= '<td align="right">';
$texte.= $form->selectyesno('numrestart',$conf->global->PROPALE_NUM_RESTART_BEGIN_YEAR,1);
$texte.= '</td><td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
$texte.= '<td aligne="center">'.$form->textwithhelp('',$langs->trans("NumRestartDesc"),1,1).'</td>';
$texte.= '</tr></form>';
// On affiche le debut d'année fiscale
$texte.= '<tr><td>Début d\'année fiscale : '.monthArrayOrSelected($conf->global->SOCIETE_FISCAL_MONTH_START).'</td>';
$texte.= '</tr>';
$texte.= '</table><br>';
return $texte; $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;
} }
/** \brief Renvoi un exemple de numérotation /** \brief Renvoi un exemple de numérotation
@ -121,268 +76,130 @@ function info()
*/ */
function getExample() function getExample()
{ {
global $conf,$langs; global $conf,$langs,$mysoc;
$numExample = ''; $numExample = $this->getNextValue($mysoc,$propalspecimen);
$buildResult = $this->buildMatrice();
if ($buildResult == 1) if (! $numExample)
{ {
// On récupère le nombre de chiffres du compteur $numExample = $langs->trans('NotConfigured');
$arg = '%0'.$this->numbitcounter.'s'; }
$num = sprintf($arg,$conf->global->PROPALE_NUM_DELTA?$conf->global->PROPALE_NUM_DELTA:1); return $numExample;
//On construit le numéro à partir de la matrice
foreach($this->numMatrice as $objetMatrice)
{
if ($objetMatrice == '-') $numExample .= $objetMatrice;
if ($objetMatrice == '$prefix') $numExample .= $this->prefix;
if ($objetMatrice == '$yy') $numExample .= $this->yy;
if ($objetMatrice == '$mm') $numExample .= $this->mm;
if ($objetMatrice == '$num') $numExample .= $num;
}
}
else
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
} }
/** \brief Renvoi prochaine valeur attribuée /** \brief Return next value
* \param objsoc Objet société * \param objsoc Object third party
* \param propale Objet propale * \param facture Object invoice
* \return string Valeur * \return string Value if OK, 0 if KO
*/ */
function getNextValue($objsoc=0,$propale='') function getNextValue($objsoc,$facture)
{ {
global $db,$conf; global $db,$conf;
$buildResult = $this->buildMatrice($objsoc,$propale);
if ($buildResult == 1)
{
// On récupère la valeur max (réponse immédiate car champ indéxé) // On défini critere recherche compteur
$posindice = $this->numbitcounter; $mask=$conf->global->PROPALE_SAPHIR_MASK;
$searchyy='';
$sql = "SELECT MAX(ref)"; if (! $mask)
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; {
if ($conf->global->PROPALE_NUM_RESTART_BEGIN_YEAR) $sql.= " WHERE ref REGEXP '^".$this->searchLast."'"; $this->error='NotConfigured';
$resql=$db->query($sql); return 0;
if ($resql) }
{
$row = $db->fetch_row($resql);
if ($row) $searchyy = substr($row[0],0,-$posindice);
}
if ($conf->global->PROPALE_NUM_DELTA != '') // Extract value for mask counter, mask raz and mask offset
{ if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
//on vérifie si il y a une année précédente $masktri=$reg[1].$reg[2].$reg[3];
//pour éviter que le delta soit appliqué de nouveau sur la nouvelle année $maskcounter=$reg[1];
$previousyy=''; $maskraz=-1;
$sql = "SELECT MAX(ref)"; $maskoffset=0;
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; if (strlen($maskcounter) < 3) return 'CounterMustHaveMoreThan3Digits';
$sql.= " WHERE ref REGEXP '^".$this->searchLastWithPreviousYear."'";
$resql=$db->query($sql); $maskwithonlyymcode=$mask;
if ($resql) $maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
{ $maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
$row = $db->fetch_row($resql); $maskwithnocode=$maskwithonlyymcode;
if ($row) $previousyy = substr($row[0],0,-$posindice); $maskwithnocode=eregi_replace('\{yyyy\}','yyyy',$maskwithnocode);
} $maskwithnocode=eregi_replace('\{yy\}','yy',$maskwithnocode);
} $maskwithnocode=eregi_replace('\{y\}','y',$maskwithnocode);
$maskwithnocode=eregi_replace('\{mm\}','mm',$maskwithnocode);
// Si au moins un champ respectant le modèle a été trouvée //print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n<br>";
if (eregi('^'.$this->searchLastWithNoYear.'',$searchyy))
{ // If an offset is asked
// Recherche rapide car restreint par un like sur champ indexé if (! empty($reg[2]) && eregi('^\+',$reg[2])) $maskoffset=eregi_replace('^\+','',$reg[2]);
$sql = "SELECT MAX(0+SUBSTRING(ref,-".$posindice."))"; if (! empty($reg[3]) && eregi('^\+',$reg[3])) $maskoffset=eregi_replace('^\+','',$reg[3]);
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref REGEXP '^".$searchyy."'"; // If a restore to zero after a month is asked we check if there is already a value for this year.
$resql=$db->query($sql); if (! empty($reg[2]) && eregi('^@',$reg[2])) $maskraz=eregi_replace('^@','',$reg[2]);
if ($resql) if (! empty($reg[3]) && eregi('^@',$reg[3])) $maskraz=eregi_replace('^@','',$reg[3]);
{ if ($maskraz >= 0)
$row = $db->fetch_row($resql); {
$max = $row[0]; if ($maskraz > 12) return 'ErrorBadMask';
} if ($maskraz > 1 && ! eregi('^(.*)\{(y+)\}\{(m+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
} if ($maskraz <= 1 && ! eregi('^(.*)\{(y+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
else if ($conf->global->PROPALE_NUM_DELTA != '' && !eregi('^'.$this->searchLastWithPreviousYear.'',$previousyy)) //print "x".$maskwithonlyymcode." ".$maskraz;
{
// on applique le delta une seule fois // Define $yearcomp and $monthcomp (that will be use de filter request to search max number)
$max=$conf->global->PROPALE_NUM_DELTA?$conf->global->PROPALE_NUM_DELTA-1:0; $monthcomp=$maskraz;
} $yearoffset=0;
else $yearcomp=0;
{ if (date("m") < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
$max=0; if (strlen($reg[2]) == 4) $yearcomp=sprintf("%04d",date("Y")+$yearoffset);
} if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y")+$yearoffset);
if (strlen($reg[2]) == 1) $yearcomp=substr(date("y"),2,1)+$yearoffset;
// On applique le nombre de chiffres du compteur
$arg = '%0'.$this->numbitcounter.'s'; $sqlwhere='';
$num = sprintf($arg,$max+1); $sqlwhere.='SUBSTRING(facnumber, '.(strlen($reg[1])+1).', '.strlen($reg[2]).') >= '.$yearcomp;
$numFinal = ''; if ($monthcomp > 1) // Test useless if monthcomp = 1 (or 0 is same as 1)
{
foreach($this->numMatrice as $objetMatrice) $sqlwhere.=' AND SUBSTRING(facnumber, '.(strlen($reg[1])+strlen($reg[2])+1).', '.strlen($reg[3]).') >= '.$monthcomp;
{ }
if ($objetMatrice == '-') $numFinal .= $objetMatrice; }
if ($objetMatrice == '$prefix') $numFinal .= $this->prefix; //print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."<br>\n";
if ($objetMatrice == '$yy') $numFinal .= $this->yy;
if ($objetMatrice == '$mm') $numFinal .= $this->mm; $posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
if ($objetMatrice == '$num') $numFinal .= $num; if ($posnumstart < 0) return 'ErrorBadMask';
} $sqlstring='SUBSTRING(facnumber, '.($posnumstart+1).', '.strlen($maskcounter).')';
//print "x".$sqlstring;
dolibarr_syslog("mod_propale_saphir::getNextValue return ".$numFinal);
return $numFinal; // Get counter in database
} $counter=0;
} $sql = "SELECT MAX(".$sqlstring.") as val";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
/** \brief Construction de la matrice de numérotation $sql.= " WHERE facnumber not like '(%'";
* \param objsoc Objet société if ($facture->type == 2) $sql.= " AND type = 2";
* \return string Valeur else $sql.=" AND type != 2";
*/ if ($sqlwhere) $sql.=' AND '.$sqlwhere;
function buildMatrice($objsoc=0,$propale='')
{ //print $sql;
global $conf; dolibarr_syslog("mod_facture_mercure::getNextValue sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
$this->prefix = $conf->global->PROPALE_NUM_PREFIX; if ($resql)
$this->matrice = $conf->global->PROPALE_NUM_MATRICE; {
$this->searchLast = ''; $obj = $db->fetch_object($resql);
$this->searchLastWithNoYear = ''; $counter = $obj->val;
$this->searchLastWithPreviousYear = ''; }
else dolibarr_print_error($db);
if ($this->matrice != '') if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
{ $counter++;
$resultatMatrice = Array();
// Build numFinal
$matricePrefix = "PREF|COM"; // PREF : prefix libre (ex: PR pour propale), COM : prefix du client $numFinal = $mask;
$matriceYear = "[A]{2,4}"; // l'année est sur 2 ou 4 chiffres
$matriceMonth = "[M]{2}"; // le mois est sur 2 chiffres // We replace special codes
$matriceCounter = "[C]{1,}"; //le compteur a un nombre de chiffres libre $numFinal = str_ireplace('{yyyy}',date("Y"),$numFinal);
$matriceTiret = "[-]{1}"; // on recherche si il y a des tirets de séparation $numFinal = str_ireplace('{yy}',date("y"),$numFinal);
$numFinal = str_ireplace('{y}' ,substr(date("y"),2,1),$numFinal);
$matriceSearch = Array('prefix'=>$matricePrefix, $numFinal = str_ireplace('{mm}',date("m"),$numFinal);
'year'=>$matriceYear, $numFinal = str_ireplace('{dd}',date("d"),$numFinal);
'month'=>$matriceMonth,
'counter'=>$matriceCounter // Now we replace the counter
); $maskbefore='{'.$masktri.'}';
$maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
// on détermine l'emplacement des tirets //print 'x'.$maskbefore.'-'.$maskafter.'y';
$resultTiret = preg_split('/'.$matriceTiret.'/',$this->matrice, -1, PREG_SPLIT_OFFSET_CAPTURE); $numFinal = str_ireplace($maskbefore,$maskafter,$numFinal);
$j = 0; dolibarr_syslog("mod_propale_saphir::getNextValue return ".$numFinal);
$k = 0; return $numFinal;
}
// on détermine les objets de la matrice
for ($i = 0; $i < count($resultTiret); $i++)
{
foreach($resultTiret[$i] as $idResultTiret => $valueResultTiret)
{
// Ajout des tirets
if ($j != $resultTiret[$i][1])
{
$this->numMatrice[$k] = '-';
$this->searchLast .= '-';
$this->searchLastWithNoYear .= '-';
$this->searchLastWithPreviousYear .= '-';
$j = $resultTiret[$i][1];
$k++;
}
foreach($matriceSearch as $idMatrice => $valueMatrice)
{
$resultCount = eregi(''.$valueMatrice.'',$valueResultTiret,$resultatMatrice);
if ($resultCount)
{
// On récupère le préfix utilisé
if ($idMatrice == 'prefix')
{
if ($resultatMatrice[0] == 'COM')
{
if ($objsoc->prefix_comm)
{
$this->prefix = $objsoc->prefix_comm;
}
else
{
$this->prefix = 'COM';
}
$this->numMatrice[$k] = '$prefix';
$this->searchLast .= $this->prefix;
$this->searchLastWithNoYear .= $this->prefix;
$this->searchLastWithPreviousYear .= $this->prefix;
$k++;
}
else if ($resultatMatrice[0] == 'PREF')
{
$this->numMatrice[$k] = '$prefix';
$this->searchLast .= $this->prefix;
$this->searchLastWithNoYear .= $this->prefix;
$this->searchLastWithPreviousYear .= $this->prefix;
$k++;
}
}
else if ($idMatrice == 'year')
{
// On récupère le nombre de chiffres pour l'année
$numbityear = $resultCount;
// On défini le mois du début d'année fiscale
$current_month = date("n");
if (is_object($propale) && $propale->date)
{
$create_month = strftime("%m",$propale->date);
}
else
{
$create_month = $current_month;
}
// On change d'année fiscal si besoin
if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_month >= $conf->global->SOCIETE_FISCAL_MONTH_START)
{
$this->yy = substr(strftime("%Y",dolibarr_mktime(0,0,0,date("m"),date("d"),date("Y")+1)),$numbityear);
}
else
{
$this->yy = substr(strftime("%Y",time()),$numbityear);
}
$this->numMatrice[$k] = '$yy';
$this->searchLast .= $this->yy;
for ($l = 1; $l <= $numbityear; $l++)
{
$this->searchLastWithNoYear .= '[0-9]';
}
$previousYear = substr(strftime("%Y",mktime(0,0,0,date("m"),date("d"),date("Y")-1)),$numbityear);
$this->searchLastWithPreviousYear .= $previousYear;
$k++;
}
else if ($idMatrice == 'month')
{
// On récupère le mois si besoin
$this->mm = strftime("%m",time());
$this->numMatrice[$k] = '$mm';
$this->searchLast .= '[0-9][0-9]';
$this->searchLastWithNoYear .= '[0-9][0-9]';
$this->searchLastWithPreviousYear .= '[0-9][0-9]';
$k++;
}
else if ($idMatrice == 'counter')
{
// On récupère le nombre de chiffres pour le compteur
$this->numbitcounter = $resultCount;
$this->numMatrice[$k] = '$num';
$k++;
}
}
}
}
}
return 1;
}
else
{
return -3;
}
}
} }
?> ?>