diff --git a/htdocs/includes/modules/facture/mercure/mercure.modules.php b/htdocs/includes/modules/facture/mercure/mercure.modules.php
index 22c338f5660..93641e7601a 100644
--- a/htdocs/includes/modules/facture/mercure/mercure.modules.php
+++ b/htdocs/includes/modules/facture/mercure/mercure.modules.php
@@ -28,13 +28,14 @@
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
+
/**
- \class mod_facture_pluton
- \brief Classe du mod�le de num�rotation de r�f�rence de facture Mercure
+ \class mod_facture_mercure
+ \brief Classe du modele de numerotation de reference de facture Mercure
*/
class mod_facture_mercure extends ModeleNumRefFactures
{
- var $version='experimental'; // 'development', 'experimental', 'dolibarr'
+ var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefixinvoice;
var $prefixcreditnote;
var $matrice;
@@ -52,37 +53,38 @@ class mod_facture_mercure extends ModeleNumRefFactures
*/
function info()
{
- global $conf,$langs;
+ global $conf,$langs;
- $langs->load("bills");
-
- $form = new Form($db);
-
- $texte = $langs->trans('MercureNumRefModelDesc1')."
\n";
- $texte.= '
';
+
+ return $texte;
}
/** \brief Renvoi un exemple de numerotation
@@ -101,10 +103,10 @@ class mod_facture_mercure extends ModeleNumRefFactures
return $numExample;
}
- /** \brief Renvoi prochaine valeur attribuee
- * \param objsoc Objet societe
- * \param facture Objet facture
- * \return string Valeur
+ /** \brief Return next value
+ * \param objsoc Object third party
+ * \param facture Object invoice
+ * \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc,$facture)
{
@@ -114,58 +116,102 @@ class mod_facture_mercure extends ModeleNumRefFactures
if ($facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
- if (! $mask) return 'Error format not defined';
+ if (! $mask)
+ {
+ $this->error='ErrorFormatNotDefined';
+ return 0;
+ }
- // Replace all code that ar not {0...0}
- $newmask=$mask;
- $newmask=str_ireplace('{yyyy}','yyyy',$newmask);
- $newmask=str_ireplace('{yy}','yy',$newmask);
- $newmask=str_ireplace('{mm}','mm',$newmask);
- $newmask=str_ireplace('{dd}','dd',$newmask);
- //print "newmask=".$newmask;
+ // Extract value for mask counter, mask raz and mask offset
+ if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
+ $masktri=$reg[1].$reg[2].$reg[3];
+ $maskcounter=$reg[1];
+ $maskraz=-1;
+ $maskoffset=0;
+
+ $maskwithonlyymcode=$mask;
+ $maskwithonlyymcode=eregi_replace('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$maskcounter,$maskwithonlyymcode);
+ $maskwithonlyymcode=eregi_replace('\{dd\}','dd',$maskwithonlyymcode);
+ $maskwithnocode=$maskwithonlyymcode;
+ $maskwithnocode=eregi_replace('\{yyyy\}','yyyy',$maskwithnocode);
+ $maskwithnocode=eregi_replace('\{yy\}','yy',$maskwithnocode);
+ $maskwithnocode=eregi_replace('\{y\}','y',$maskwithnocode);
+ $maskwithnocode=eregi_replace('\{mm\}','mm',$maskwithnocode);
+ //print "maskwithonlyymcode=".$maskwithonlyymcode." maskwithnocode=".$maskwithnocode."\n
";
+
+ // If an offset is asked
+ if (! empty($reg[2]) && eregi('^\+',$reg[2])) $maskoffset=eregi_replace('^\+','',$reg[2]);
+ if (! empty($reg[3]) && eregi('^\+',$reg[3])) $maskoffset=eregi_replace('^\+','',$reg[3]);
+
+ // If a restore to zero after a month is asked we check if there is already a value for this year.
+ if (! empty($reg[2]) && eregi('^@',$reg[2])) $maskraz=eregi_replace('^@','',$reg[2]);
+ if (! empty($reg[3]) && eregi('^@',$reg[3])) $maskraz=eregi_replace('^@','',$reg[3]);
+ if ($maskraz >= 0)
+ {
+ if ($maskraz > 1 && ! eregi('^(.*)\{(y+)\}\{(m+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
+ if ($maskraz <= 1 && ! eregi('^(.*)\{(y+)\}',$maskwithonlyymcode,$reg)) return 'ErrorCantUseRazIfNoYearInMask';
+ //print "x".$maskwithonlyymcode." ".$maskraz;
+
+ // Define $yearcomp and $monthcomp (that will be use de filter request to search max number)
+ $monthcomp=$maskraz;
+ $yearoffset=0;
+ $yearcomp=0;
+ if (date("m") < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
+ 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;
+
+ $sqlwhere='';
+ $sqlwhere.='SUBSTRING(facnumber, '.(strlen($reg[1])+1).', '.strlen($reg[2]).') >= '.$yearcomp;
+ if ($monthcomp > 1) // Test useless if monthcomp = 1 (or 0 is same as 1)
+ {
+ $sqlwhere.=' AND ';
+ $sqlwhere.='SUBSTRING(facnumber, '.(strlen($reg[1])+strlen($reg[2])+1).', '.strlen($reg[3]).') >= '.$monthcomp;
+ }
+ }
+ //print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."
\n";
- $posnumstart=strpos($newmask,'{0'); // Pos of {
- $posnumend =strpos($newmask,'0}')+1; // Pos of }
-
- if ($posnumstart <= 0 || $posnumend <= 1) return 'Error in format';
-
- $sqlstring='SUBSTRING(facnumber, '.($posnumstart+1).', '.($posnumend-$posnumstart-1).')';
+ $posnumstart=strpos($maskwithnocode,$maskcounter); // Pos of counter in final string (from 0 to ...)
+ if ($posnumstart < 0) return 'ErrorBadMask';
+ $sqlstring='SUBSTRING(facnumber, '.($posnumstart+1).', '.strlen($maskcounter).')';
//print "x".$sqlstring;
+ // Get counter in database
$counter=0;
-
$sql = "SELECT MAX(".$sqlstring.") as val";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
$sql.= " WHERE facnumber not like '(%'";
if ($facture->type == 2) $sql.= " AND type = 2";
else $sql.=" AND type != 2";
+ if ($sqlwhere) $sql.=' AND '.$sqlwhere;
+
//print $sql;
+ dolibarr_syslog("mod_facture_mercure::getNextValue sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$obj = $db->fetch_object($resql);
$counter = $obj->val;
}
- if (eregi('[^0-9]',$counter)) $counter=0;
+ else dolibarr_print_error($db);
+ if (empty($counter) || eregi('[^0-9]',$counter)) $counter=$maskoffset;
$counter++;
- $sizeofnum=$posnumend-$posnumstart;
- //print $counter."-".$sizeofnum."-".$posnumstart."-".$posnumend;
-
// Build numFinal
$numFinal = $mask;
// We replace special codes
$numFinal = str_ireplace('{yyyy}',date("Y"),$numFinal);
$numFinal = str_ireplace('{yy}',date("y"),$numFinal);
+ $numFinal = str_ireplace('{y}' ,substr(date("y"),2,1),$numFinal);
$numFinal = str_ireplace('{mm}',date("m"),$numFinal);
$numFinal = str_ireplace('{dd}',date("d"),$numFinal);
// Now we replace the counter
- $nummask='{'.str_pad('',$sizeofnum-1,"0").'}';
- $numcount=str_pad($counter,$sizeofnum-1,"0",STR_PAD_LEFT);
- //print 'x'.$nummask.'-'.$sizeofnum.'y';
- $numFinal = str_ireplace($nummask,$numcount,$numFinal);
+ $maskbefore='{'.$masktri.'}';
+ $maskafter=str_pad($counter,strlen($maskcounter),"0",STR_PAD_LEFT);
+ //print 'x'.$maskbefore.'-'.$maskafter.'y';
+ $numFinal = str_ireplace($maskbefore,$maskafter,$numFinal);
dolibarr_syslog("mod_facture_mercure::getNextValue return ".$numFinal);
return $numFinal;
diff --git a/htdocs/includes/modules/facture/orion/orion.modules.php b/htdocs/includes/modules/facture/orion/orion.modules.php
deleted file mode 100644
index 76c5a223aeb..00000000000
--- a/htdocs/includes/modules/facture/orion/orion.modules.php
+++ /dev/null
@@ -1,154 +0,0 @@
-
- * Copyright (C) 2004-2005 Laurent Destailleur
- * Copyright (C) 2005-2007 Regis Houssin
- *
- * 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/orion/orion.modules.php
- \ingroup facture
- \brief Fichier contenant la classe du modèle de numérotation de référence de facture Orion
- \version $Revision$
-*/
-
-require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
-
-/**
- \class mod_facture_orion
- \brief Classe du modèle de numérotation de référence de facture Orion
-*/
-class mod_facture_orion extends ModeleNumRefFactures
-{
- var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
-
- /** \brief Renvoi la description du modele de numérotation
- * \return string Texte descripif
- */
- function info()
- {
- global $conf,$langs;
-
- $langs->load("bills");
-
- $texte = $langs->trans('OrionNumRefModelDesc1')."
\n";
- $texte.= $langs->trans('OrionNumRefModelDesc2')."
\n";
- $texte.= $langs->trans('OrionNumRefModelDesc3')."
\n";
- $texte.= $langs->trans('OrionNumRefModelDesc4')."
\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 "FA0600001";
- }
-
- /** \brief Renvoi prochaine valeur attribuée
- * \param objsoc Objet société
- * \param facture Objet facture
- * \return string Valeur
- */
- function getNextValue($objsoc,$facture)
- {
- global $db,$conf;
-
- // On défini l'année fiscale
- $prefix='FA';
- $current_month = date("n");
-
- if (is_object($facture) && $facture->date)
- {
- $create_month = strftime("%m",$facture->date);
- }
- else
- {
- $create_month = $current_month;
- }
-
- if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_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é)
- $fayy='';
- $sql = "SELECT MAX(facnumber)";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $resql=$db->query($sql);
- if ($resql)
- {
- $row = $db->fetch_row($resql);
- if ($row) $fayy = substr($row[0],0,4);
- }
-
- // Si au moins un champ respectant le modèle a été trouvée
- if (eregi('FA[0-9][0-9]',$fayy))
- {
- // Recherche rapide car restreint par un like sur champ indexé
- $posindice=5;
- $sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $resql=$db->query($sql);
- if ($resql)
- {
- $row = $db->fetch_row($resql);
- $max = $row[0];
- }
- }
- else
- {
- $max=0;
- }
-
- $num = sprintf("%05s",$max+1);
-
- return "FA$yy$num";
- }
-
-
- /** \brief Renvoie la référence de commande suivante non utilisée
- * \param objsoc Objet société
- * \param facture Objet facture
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0,$facture)
- {
- return $this->getNextValue($objsoc,$facture);
- }
-
-}
-
-?>
diff --git a/htdocs/includes/modules/facture/titan/titan.modules.php b/htdocs/includes/modules/facture/titan/titan.modules.php
deleted file mode 100644
index 29cbf0e71d7..00000000000
--- a/htdocs/includes/modules/facture/titan/titan.modules.php
+++ /dev/null
@@ -1,160 +0,0 @@
-
- * Copyright (C) 2004-2005 Laurent Destailleur
- * Copyright (C) 2005-2007 Regis Houssin
- *
- * 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/titan/titan.modules.php
- \ingroup facture
- \brief Fichier contenant la classe du modèle de numérotation de référence de facture Titan
- \version $Revision$
-*/
-
-require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
-
-/**
- \class mod_facture_titan
- \brief Classe du modèle de numérotation de référence de facture Titan
-*/
-class mod_facture_titan extends ModeleNumRefFactures
-{
- var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
-
-
- /** \brief Renvoi la description du modele de numérotation
- * \return string Texte descripif
- */
- function info()
- {
- global $conf,$langs;
-
- $langs->load("bills");
-
- $texte = $langs->trans('TitanNumRefModelDesc1')."
\n";
- $texte.= $langs->trans('TitanNumRefModelDesc2')."
\n";
- $texte.= $langs->trans('TitanNumRefModelDesc3')."
\n";
- $texte.= $langs->trans('TitanNumRefModelDesc4')."
\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 "FA0600001";
- }
-
- /** \brief Renvoi prochaine valeur attribuée
- * \param objsoc Objet société
- * \param facture Objet facture
- * \return string Valeur
- */
- function getNextValue($objsoc,$facture)
- {
- global $db,$conf;
-
- // On défini l'année fiscale
- $prefix='FA';
- $current_month = date("n");
-
- if (is_object($facture) && $facture->date)
- {
- $create_month = strftime("%m",$facture->date);
- }
- else
- {
- $create_month = $current_month;
- }
-
- if($conf->global->SOCIETE_FISCAL_MONTH_START > 1 && $current_month >= $conf->global->SOCIETE_FISCAL_MONTH_START && $create_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;
- $fayy='';
- $sql = "SELECT MAX(facnumber)";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $sql.= " WHERE facnumber like '${fisc}%'";
- $resql=$db->query($sql);
- if ($resql)
- {
- $row = $db->fetch_row($resql);
- if ($row) $fayy = substr($row[0],0,4);
- }
-
- // Si au moins un champ respectant le modèle a été trouvée
- if (eregi('FA[0-9][0-9]',$fayy))
- {
- // Recherche rapide car restreint par un like sur champ indexé
- $date = strftime("%Y%m", time());
- $posindice=5;
- $sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))";
- $sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $sql.= " WHERE facnumber like '${fayy}%'";
- $resql=$db->query($sql);
- if ($resql)
- {
- $row = $db->fetch_row($resql);
- $max = $row[0];
- }
- }
- else
- {
- $max=0;
- }
-
- $num = sprintf("%05s",$max+1);
-
- return "FA$yy$num";
- }
-
-
- /** \brief Renvoie la référence de commande suivante non utilisée
- * \param objsoc Objet société
- * \param facture Objet facture
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0,$facture)
- {
- return $this->getNextValue($objsoc,$facture);
- }
-
-}
-
-?>