2006-07-30 01:55:08 +00:00
|
|
|
<?php
|
2008-07-08 23:02:16 +00:00
|
|
|
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
2012-12-30 14:13:49 +00:00
|
|
|
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
|
2013-08-27 07:44:00 +00:00
|
|
|
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
|
2006-07-30 01:55:08 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-07-30 01:55:08 +00:00
|
|
|
* (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
|
2011-07-31 23:24:38 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-07-30 01:55:08 +00:00
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-24 12:11:49 +00:00
|
|
|
* \file htdocs/core/modules/fichinter/mod_pacific.php
|
2011-07-02 15:46:02 +00:00
|
|
|
* \ingroup fiche intervention
|
|
|
|
|
* \brief File with Pacific numbering module for interventions
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT .'/core/modules/fichinter/modules_fichinter.php';
|
2006-07-30 01:55:08 +00:00
|
|
|
|
2007-05-28 14:31:30 +00:00
|
|
|
/**
|
2012-02-16 17:39:22 +00:00
|
|
|
* Class to manage numbering of intervention cards with rule Pacific.
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
2006-07-30 01:55:08 +00:00
|
|
|
class mod_pacific extends ModeleNumRefFicheinter
|
|
|
|
|
{
|
2011-07-02 15:46:02 +00:00
|
|
|
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
|
2006-07-30 01:55:08 +00:00
|
|
|
var $prefix='FI';
|
|
|
|
|
var $error='';
|
2010-06-01 07:31:40 +00:00
|
|
|
var $nom = 'pacific';
|
2010-05-31 19:18:31 +00:00
|
|
|
|
|
|
|
|
|
2012-02-16 17:39:22 +00:00
|
|
|
/**
|
|
|
|
|
* Return description of numbering module
|
2012-03-14 10:49:11 +00:00
|
|
|
*
|
2012-02-16 17:39:22 +00:00
|
|
|
* @return string Text with description
|
2010-06-01 07:31:40 +00:00
|
|
|
*/
|
|
|
|
|
function info()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
|
|
|
|
|
}
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2012-02-16 17:39:22 +00:00
|
|
|
/**
|
|
|
|
|
* Renvoi un exemple de numerotation
|
2012-03-14 10:49:11 +00:00
|
|
|
*
|
2012-02-16 17:39:22 +00:00
|
|
|
* @return string Example
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
|
|
|
|
function getExample()
|
|
|
|
|
{
|
|
|
|
|
return $this->prefix."0501-0001";
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 10:49:11 +00:00
|
|
|
/**
|
2012-02-16 17:39:22 +00:00
|
|
|
* Test si les numeros deja en vigueur dans la base ne provoquent pas de
|
|
|
|
|
* de conflits qui empechera cette numerotation de fonctionner.
|
2012-03-14 10:49:11 +00:00
|
|
|
*
|
2012-02-16 17:39:22 +00:00
|
|
|
* @return boolean false si conflit, true si ok
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
2006-07-30 01:55:08 +00:00
|
|
|
function canBeActivated()
|
|
|
|
|
{
|
2009-05-02 14:26:54 +00:00
|
|
|
global $langs,$conf;
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2006-07-30 01:55:08 +00:00
|
|
|
$langs->load("bills");
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2010-06-01 07:31:40 +00:00
|
|
|
$fayymm=''; $max='';
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2010-06-01 07:31:40 +00:00
|
|
|
$posindice=8;
|
2014-05-21 17:44:53 +00:00
|
|
|
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
|
2006-07-30 01:55:08 +00:00
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
|
2010-05-31 19:18:31 +00:00
|
|
|
$sql.= " WHERE ref like '".$this->prefix."____-%'";
|
2009-05-02 14:26:54 +00:00
|
|
|
$sql.= " WHERE entity = ".$conf->entity;
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2006-07-30 01:55:08 +00:00
|
|
|
$resql=$db->query($sql);
|
|
|
|
|
if ($resql)
|
|
|
|
|
{
|
|
|
|
|
$row = $db->fetch_row($resql);
|
2010-06-01 07:31:40 +00:00
|
|
|
if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; }
|
2006-07-30 01:55:08 +00:00
|
|
|
}
|
2009-10-22 15:09:04 +00:00
|
|
|
if (! $fayymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$fayymm))
|
2006-07-30 01:55:08 +00:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-05-31 19:18:31 +00:00
|
|
|
$langs->load("errors");
|
2010-06-01 07:31:40 +00:00
|
|
|
$this->error=$langs->trans('ErrorNumRefModel',$max);
|
2006-07-30 01:55:08 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 10:49:11 +00:00
|
|
|
/**
|
|
|
|
|
* Return next free value
|
|
|
|
|
*
|
|
|
|
|
* @param Societe $objsoc Object thirdparty
|
|
|
|
|
* @param Object $object Object we need next value for
|
|
|
|
|
* @return string Value if KO, <0 if KO
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
|
|
|
|
function getNextValue($objsoc=0,$object='')
|
2008-07-05 14:20:03 +00:00
|
|
|
{
|
2009-05-02 14:26:54 +00:00
|
|
|
global $db,$conf;
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2010-06-01 07:31:40 +00:00
|
|
|
// D'abord on recupere la valeur max
|
2010-05-31 19:18:31 +00:00
|
|
|
$posindice=8;
|
2014-05-21 17:44:53 +00:00
|
|
|
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
|
2010-05-31 19:18:31 +00:00
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
|
|
|
|
|
$sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
|
2009-05-02 14:26:54 +00:00
|
|
|
$sql.= " AND entity = ".$conf->entity;
|
2010-05-31 19:18:31 +00:00
|
|
|
|
2008-07-08 23:02:16 +00:00
|
|
|
$resql=$db->query($sql);
|
2010-05-31 19:18:31 +00:00
|
|
|
if ($resql)
|
|
|
|
|
{
|
|
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
if ($obj) $max = intval($obj->max);
|
|
|
|
|
else $max=0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//$date=time();
|
2013-08-27 07:44:00 +00:00
|
|
|
$date=$object->datec;
|
2010-05-31 19:18:31 +00:00
|
|
|
$yymm = strftime("%y%m",$date);
|
2014-05-21 17:44:53 +00:00
|
|
|
|
|
|
|
|
if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is
|
|
|
|
|
else $num = sprintf("%04s",$max+1);
|
2010-05-31 19:18:31 +00:00
|
|
|
|
|
|
|
|
return $this->prefix.$yymm."-".$num;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-14 10:49:11 +00:00
|
|
|
/**
|
2012-02-16 17:39:22 +00:00
|
|
|
* Return next free value
|
2012-03-14 10:49:11 +00:00
|
|
|
*
|
2012-02-16 17:39:22 +00:00
|
|
|
* @param Societe $objsoc Object third party
|
|
|
|
|
* @param Object $objforref Object for number to search
|
|
|
|
|
* @return string Next free value
|
2010-05-31 19:18:31 +00:00
|
|
|
*/
|
|
|
|
|
function getNumRef($objsoc,$objforref)
|
|
|
|
|
{
|
|
|
|
|
return $this->getNextValue($objsoc,$objforref);
|
|
|
|
|
}
|
|
|
|
|
|
2006-07-30 01:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|