Add a more simple project numbering module to have always for each module:

1 simple module with no need to understand masks.
1 generic module with a masks to define.
This commit is contained in:
Laurent Destailleur 2010-02-02 08:44:28 +00:00
parent 0943a28445
commit 1d0a197f85
9 changed files with 235 additions and 117 deletions

View File

@ -30,6 +30,7 @@ require_once(DOL_DOCUMENT_ROOT.'/projet/tasks/task.class.php');
$langs->load("admin"); $langs->load("admin");
$langs->load("other"); $langs->load("other");
$langs->load("projects");
if (!$user->admin) if (!$user->admin)
accessforbidden(); accessforbidden();

View File

@ -0,0 +1,114 @@
<?php
/* Copyright (C) 2010 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/
*/
/**
* \file htdocs/includes/modules/project/mod_project_simple.php
* \ingroup project
* \brief File with class to manage the numbering module Simple for project references
* \version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/project/modules_project.php");
/**
* \class mod_project_simple
* \brief Class to manage the numbering module Simple for project references
*/
class mod_project_simple extends ModeleNumRefProjects
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='PJ';
var $error='';
var $nom = "Simple";
/** \brief Return description of numbering module
* \return string Text with description
*/
function info()
{
global $langs;
return $langs->trans("SimpleNumRefModelDesc");
}
/** \brief Return an example of numbering module values
* \return string Example
*/
function getExample()
{
return $this->prefix."0501-0001";
}
/**
* \brief Return next value
* \param objsoc Object third party
* \param project Object project
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$project='')
{
global $db,$conf;
// D'abord on recupere la valeur max (reponse immediate car champ indexe)
$posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
$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 = $obj->max;
else $max=0;
}
else
{
dol_syslog("mod_project_simple::getNextValue sql=".$sql);
return -1;
}
$date=$project->date_c;
//$yymm = strftime("%y%m",time());
$yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
dol_syslog("mod_project_simple::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}
/** \brief Return next reference not yet used as a reference
* \param objsoc Object third party
* \param project Object project
* \return string Next not used reference
*/
function project_get_num($objsoc=0,$project='')
{
return $this->getNextValue($objsoc,$project);
}
}
?>

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 20010 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -101,7 +101,7 @@ class mod_project_universal extends ModeleNumRefProjects
/** /**
* \brief Return next value * \brief Return next value
* \param objsoc Object third party * \param objsoc Object third party
* \param commande Object project * \param project Object project
* \return string Value if OK, 0 if KO * \return string Value if OK, 0 if KO
*/ */
function getNextValue($objsoc=0,$project='') function getNextValue($objsoc=0,$project='')
@ -119,16 +119,16 @@ class mod_project_universal extends ModeleNumRefProjects
return 0; return 0;
} }
$numFinal=get_next_value($db,$mask,'projet','ref','',$objsoc->code_client,$project->datec); $numFinal=get_next_value($db,$mask,'projet','ref','',$objsoc->code_client,$project->date_c);
return $numFinal; return $numFinal;
} }
/** \brief Renvoie la reference de commande suivante non utilisee /** \brief Return next reference not yet used as a reference
* \param objsoc Object third party * \param objsoc Object third party
* \param commande Object project * \param project Object project
* \return string Texte descripif * \return string Next not used reference
*/ */
function project_get_num($objsoc=0,$project='') function project_get_num($objsoc=0,$project='')
{ {

View File

@ -19,124 +19,123 @@
*/ */
/** /**
\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 modele de numerotation de reference de propale Marbre * \brief Fichier contenant la classe du modele de numerotation de reference de propale Marbre
\version $Id$ * \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_marbre /** \class mod_propale_marbre
\brief Classe du modele de numerotation de reference de propale Marbre * \brief Classe du modele de numerotation de reference de propale Marbre
*/ */
class mod_propale_marbre extends ModeleNumRefPropales class mod_propale_marbre extends ModeleNumRefPropales
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='PR'; var $prefix='PR';
var $error=''; var $error='';
var $nom = "Marbre"; var $nom = "Marbre";
/** \brief Renvoi la description du modele de numerotation /** \brief Return description of numbering module
* \return string Texte descripif * \return string Text with description
*/ */
function info() function info()
{ {
global $langs; global $langs;
return $langs->trans("MarbreNumRefModelDesc"); return $langs->trans("MarbreNumRefModelDesc");
} }
/** \brief Renvoi un exemple de numerotation /** \brief Return an example of numbering module values
* \return string Example * \return string Example
*/ */
function getExample() function getExample()
{ {
return "PR0501-0001"; return $this->prefix."0501-0001";
} }
/** \brief Test si les numeros deje en vigueur dans la base ne provoquent pas de /** \brief Test si les numeros deje en vigueur dans la base ne provoquent pas de
* de conflits qui empechera cette numerotation de fonctionner. * de conflits qui empechera cette numerotation de fonctionner.
* \return boolean false si conflit, true si ok * \return boolean false si conflit, true si ok
*/ */
function canBeActivated() function canBeActivated()
{ {
global $conf; global $conf;
$pryymm=''; $pryymm='';
$sql = "SELECT MAX(ref)"; $sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; $sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE entity = ".$conf->entity; $sql.= " WHERE entity = ".$conf->entity;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$row = $db->fetch_row($resql); $row = $db->fetch_row($resql);
if ($row) $pryymm = substr($row[0],0,6); if ($row) $pryymm = substr($row[0],0,6);
} }
if (! $pryymm || preg_match('/PR[0-9][0-9][0-9][0-9]/i',$pryymm)) if (! $pryymm || preg_match('/PR[0-9][0-9][0-9][0-9]/i',$pryymm))
{ {
return true; return true;
} }
else else
{ {
$this->error='Une propal commencant par $pryymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.'; $this->error='Une propal commencant par $pryymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.';
return false; return false;
} }
} }
/** \brief Return next value /** \brief Return next value
* \param objsoc Object third party * \param objsoc Object third party
* \param propal Object commercial proposal * \param propal Object commercial proposal
* \return string Valeur * \return string Valeur
*/ */
function getNextValue($objsoc,$propal) function getNextValue($objsoc,$propal)
{ {
global $db,$conf; global $db,$conf;
// D'abord on recupere la valeur max (reponse immediate car champ indexe) // D'abord on recupere la valeur max (reponse immediate car champ indexe)
$posindice=8; $posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; $sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref like '".$this->prefix."%'"; $sql.= " WHERE ref like '".$this->prefix."%'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) $max = $obj->max; if ($obj) $max = $obj->max;
else $max=0; else $max=0;
} }
else else
{ {
dol_syslog("mod_propale_marbre::getNextValue sql=".$sql); dol_syslog("mod_propale_marbre::getNextValue sql=".$sql);
return -1; return -1;
} }
$date=$propal->date; $date=$propal->date;
//$yymm = strftime("%y%m",time()); //$yymm = strftime("%y%m",time());
$yymm = strftime("%y%m",$date); $yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1); $num = sprintf("%04s",$max+1);
dol_syslog("mod_propale_marbre::getNextValue return ".$this->prefix.$yymm."-".$num); dol_syslog("mod_propale_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num; return $this->prefix.$yymm."-".$num;
} }
/** \brief Return next free value /** \brief Return next free value
* \param objsoc Object third party * \param objsoc Object third party
* \param objforref Object for number to search * \param objforref Object for number to search
* \return string Next free value * \return string Next free value
*/ */
function getNumRef($objsoc,$objforref) function getNumRef($objsoc,$objforref)
{ {
return $this->getNextValue($objsoc,$objforref); return $this->getNextValue($objsoc,$objforref);
} }
} }

View File

@ -71,3 +71,5 @@ TypeContact_project_task_internal_CONTRIBUTOR=Contributor
TypeContact_project_task_external_CONTRIBUTOR=Contributor TypeContact_project_task_external_CONTRIBUTOR=Contributor
# Documents models # Documents models
DocumentModelBaleine=A complete project's report model (logo...) DocumentModelBaleine=A complete project's report model (logo...)
# NumRef Modules
SimpleNumRefModelDesc=Return the reference number with format PJyymm-nnnn where yy is year, mm is month and nnnn is a sequence without hole and with no reset

View File

@ -85,10 +85,8 @@ ProposalLine=Proposal line
TypeContact_propal_internal_SALESREPFOLL=Representative following-up proposal TypeContact_propal_internal_SALESREPFOLL=Representative following-up proposal
TypeContact_propal_external_BILLING=Customer invoice contact TypeContact_propal_external_BILLING=Customer invoice contact
TypeContact_propal_external_CUSTOMER=Customer contact following-up proposal TypeContact_propal_external_CUSTOMER=Customer contact following-up proposal
# Document models # Document models
DocModelAzurDescription=A complete proposal model (logo...) DocModelAzurDescription=A complete proposal model (logo...)
DocModelJauneDescription=Jaune proposal model DocModelJauneDescription=Jaune proposal model
# NumRef Modules # NumRef Modules
MarbreNumRefModelDesc=Return numero with format %syymm-nnnn for proposals where yy is year, mm is month and nnnn is a sequence with no break and no return to 0 MarbreNumRefModelDesc=Return numero with format %syymm-nnnn for proposals where yy is year, mm is month and nnnn is a sequence with no break and no return to 0

View File

@ -71,3 +71,5 @@ TypeContact_project_task_internal_CONTRIBUTOR=Intervenant
TypeContact_project_task_external_CONTRIBUTOR=Intervenant TypeContact_project_task_external_CONTRIBUTOR=Intervenant
# Documents models # Documents models
DocumentModelBaleine=Modèle de rapport de projet complet (logo...) DocumentModelBaleine=Modèle de rapport de projet complet (logo...)
# NumRef Modules
SimpleNumRefModelDesc=Renvoie le numero sous la forme PJyymm-nnnn où yy est l'annee, mm le mois et nnnn un compteur sequentiel sans rupture et sans remise à 0

View File

@ -85,10 +85,8 @@ ProposalLine=Ligne de proposition
TypeContact_propal_internal_SALESREPFOLL=Commercial suivi propale TypeContact_propal_internal_SALESREPFOLL=Commercial suivi propale
TypeContact_propal_external_BILLING=Contact client facturation propale TypeContact_propal_external_BILLING=Contact client facturation propale
TypeContact_propal_external_CUSTOMER=Contact client suivi propale TypeContact_propal_external_CUSTOMER=Contact client suivi propale
# Documents models # Documents models
DocModelAzurDescription=Modèle de propositions commerciales complet (logo...) DocModelAzurDescription=Modèle de propositions commerciales complet (logo...)
DocModelJauneDescription=Modele de proposition Jaune DocModelJauneDescription=Modele de proposition Jaune
# NumRef Modules # NumRef Modules
MarbreNumRefModelDesc=Renvoie le numero sous la forme PRyymm-nnnn où yy est l'annee, mm le mois et nnnn un compteur sequentiel sans rupture et sans remise à 0 MarbreNumRefModelDesc=Renvoie le numero sous la forme PRyymm-nnnn où yy est l'annee, mm le mois et nnnn un compteur sequentiel sans rupture et sans remise à 0

View File

@ -530,6 +530,8 @@ class Project extends CommonObject
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
$now=mktime();
// Charge tableau des id de societe socids // Charge tableau des id de societe socids
$socids = array(); $socids = array();
@ -580,7 +582,9 @@ class Project extends CommonObject
$this->specimen=1; $this->specimen=1;
$socid = rand(1, $num_socs); $socid = rand(1, $num_socs);
$this->socid = $socids[$socid]; $this->socid = $socids[$socid];
$this->dateo = time(); $this->date_c = $now;
$this->date_m = $now;
$this->date_start = $now;
$this->note_public='SPECIMEN'; $this->note_public='SPECIMEN';
$nbp = rand(1, 9); $nbp = rand(1, 9);
$xnbp = 0; $xnbp = 0;