Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New numbering module for expense report + admin setup
- Loading branch information
1 parent
e6ad3f4
commit 61fadfd
Showing
6 changed files
with
411 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
134 changes: 134 additions & 0 deletions
134
htdocs/core/modules/expensereport/mod_expensereport_jade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
126
htdocs/core/modules/expensereport/mod_expensereport_sand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"> <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; | ||
} | ||
} | ||
|
Oops, something went wrong.