Skip to content

Commit

Permalink
New numbering module for expense report + admin setup
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-maxime committed Aug 27, 2017
1 parent e6ad3f4 commit 61fadfd
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 50 deletions.
52 changes: 27 additions & 25 deletions htdocs/admin/expensereport.php
Expand Up @@ -207,24 +207,26 @@

dol_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');

// Interventions numbering model
/*
print load_fiche_titre($langs->trans("FicheinterNumberingModules"),'','');
* Expense report numbering model
*/

print load_fiche_titre($langs->trans("ExpenseReportNumberingModules"),'','');

print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td width="100">'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Name").'</td>';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Example").'</td>';
print '<td class="nowrap">'.$langs->trans("Example").'</td>';
print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
print "</tr>\n";
print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
print '</tr>'."\n";

clearstatcache();

foreach ($dirmodels as $reldir)
{
$dir = dol_buildpath($reldir."core/modules/fichinter/");
$dir = dol_buildpath($reldir."core/modules/expensereport/");

if (is_dir($dir))
{
Expand All @@ -235,21 +237,20 @@

while (($file = readdir($handle))!==false)
{
if (preg_match('/^(mod_.*)\.php$/i',$file,$reg))
if (substr($file, 0, 18) == 'mod_expensereport_' && substr($file, dol_strlen($file)-3, 3) == 'php')
{
$file = $reg[1];
$classname = substr($file,4);
$file = substr($file, 0, dol_strlen($file)-4);

require_once $dir.$file.'.php';

$module = new $file;
$module = new $file($db);

// Show modules according to features level
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;

if ($module->isEnabled())
{
// Show modules according to features level
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;

print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
print $module->info();
Expand All @@ -264,24 +265,26 @@
print '</td>'."\n";

print '<td align="center">';
if ($conf->global->FICHEINTER_ADDON == $classname)
if ($conf->global->EXPENSEREPORT_ADDON == $file)
{
print img_picto($langs->trans("Activated"),'switch_on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$classname.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a>';
}
print '</td>';

$ficheinter=new Fichinter($db);
$ficheinter->initAsSpecimen();
$exp=new ExpenseReport($db);
$exp->initAsSpecimen();

// Info
$htmltooltip='';
$htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
$nextval=$module->getNextValue($mysoc,$ficheinter);
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
$nextval=$module->getNextValue($exp);
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
$htmltooltip.=''.$langs->trans("NextValue").': ';
if ($nextval) {
if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
Expand All @@ -291,21 +294,20 @@
$htmltooltip.=$langs->trans($module->error).'<br>';
}
}

print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>';

print '</tr>';
print "</tr>\n";
}
}
}
closedir($handle);
}
}
}
print '</table><br>';
*/
print "</table><br>\n";

/*
* Documents models for Interventions
Expand Down
Empty file.
134 changes: 134 additions & 0 deletions htdocs/core/modules/expensereport/mod_expensereport_jade.php
@@ -0,0 +1,134 @@
<?php
/* Copyright (C) 2017 Maxime Kohlhaas <support@atm-consulting.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 3 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, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/

/**
* \file htdocs/core/modules/expensereport/mod_expensereport_jade.php
* \ingroup expensereport
* \brief File of class to manage customer order numbering rules Jade
*/
require_once DOL_DOCUMENT_ROOT .'/core/modules/expensereport/modules_expensereport.php';

/**
* Class to manage customer order numbering rules Jade
*/
class mod_expensereport_jade extends ModeleNumRefExpenseReport
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='ER';
var $error='';
var $nom='Jade';


/**
* Return description of numbering module
*
* @return string Text with description
*/
function info()
{
global $langs;
return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
}


/**
* Renvoi un exemple de numerotation
*
* @return string Example
*/
function getExample()
{
return $this->prefix."0501-0001";
}


/**
* Test si les numeros deje en vigueur dans la base ne provoquent pas de
* de conflits qui empechera cette numerotation de fonctionner.
*
* @return boolean false si conflit, true si ok
*/
function canBeActivated()
{
global $conf,$langs,$db;

$coyymm=''; $max='';

$posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport";
$sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
$sql.= " AND entity = ".$conf->entity;

$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; }
}
if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm))
{
$langs->load("errors");
$this->error=$langs->trans('ErrorNumRefModel', $max);
return false;
}

return true;
}

/**
* Return next free value
*
* @param Object $object Object we need next value for
* @return string Value if KO, <0 if KO
*/
function getNextValue($object)
{
global $db,$conf;

// D'abord on recupere la valeur max
$posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport";
$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 = intval($obj->max);
else $max=0;
}
else
{
dol_syslog("mod_expensereport_jade::getNextValue", LOG_DEBUG);
return -1;
}

//$date=time();
$date=$object->date;
$yymm = strftime("%y%m",$date);

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);

dol_syslog("mod_expensereport_jade::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num;
}
}
126 changes: 126 additions & 0 deletions htdocs/core/modules/expensereport/mod_expensereport_sand.php
@@ -0,0 +1,126 @@
<?php
/* Copyright (C) 2017 Maxime Kohlhaas <support@atm-consulting.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 3 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, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/

/**
* \file htdocs/core/modules/expensereport/mod_expensereport_sand.php
* \ingroup expensereport
* \brief Fichier contenant la classe du modele de numerotation de reference de note de frais Sand
*/

require_once DOL_DOCUMENT_ROOT .'/core/modules/expensereport/modules_expensereport.php';


/**
* Class to manage customer order numbering rules Sand
*/
class mod_expensereport_sand extends ModeleNumRefExpenseReport
{
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $error = '';
var $nom = 'Sand';


/**
* Renvoi la description du modele de numerotation
*
* @return string Texte descripif
*/
function info()
{
global $conf,$langs;

$langs->load("bills");

$form = new Form($this->db);

$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$texte.= '<input type="hidden" name="action" value="updateMask">';
$texte.= '<input type="hidden" name="maskconstorder" value="EXPENSEREPORT_SAND_MASK">';
$texte.= '<table class="nobordernopadding" width="100%">';

$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Order"),$langs->transnoentities("Order"));
$tooltip.=$langs->trans("GenericMaskCodes2");
$tooltip.=$langs->trans("GenericMaskCodes3");
$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Order"),$langs->transnoentities("Order"));
$tooltip.=$langs->trans("GenericMaskCodes5");

// Parametrage du prefix
$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskorder" value="'.$conf->global->EXPENSEREPORT_SAND_MASK.'">',$tooltip,1,1).'</td>';

$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;
}

/**
* Renvoi un exemple de numerotation
*
* @return string Example
*/
function getExample()
{
global $conf,$langs,$mysoc;

$old_code_client=$mysoc->code_client;
$mysoc->code_client='CCCCCCCCCC';
$numExample = $this->getNextValue($mysoc,'');
$mysoc->code_client=$old_code_client;

if (! $numExample)
{
$numExample = $langs->trans('NotConfigured');
}
return $numExample;
}

/**
* 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
*/
function getNextValue($objsoc,$object)
{
global $db,$conf;

require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';

// We get cursor rule
$mask=$conf->global->EXPENSEREPORT_SAND_MASK;

if (! $mask)
{
$this->error='NotConfigured';
return 0;
}

$numFinal=get_next_value($db,$mask,'expensereport','ref','',$objsoc,$object->date);

return $numFinal;
}
}

0 comments on commit 61fadfd

Please sign in to comment.