Fix numbering for expense report
This commit is contained in:
parent
852c4fc033
commit
d8872a412b
@ -101,6 +101,51 @@ class mod_expensereport_jade extends ModeleNumRefExpenseReport
|
|||||||
{
|
{
|
||||||
global $db,$conf;
|
global $db,$conf;
|
||||||
|
|
||||||
|
// For backward compatibility and restore old behavior to get ref of expense report
|
||||||
|
if ($conf->global->EXPENSEREPORT_USE_OLD_NUMBERING_RULE)
|
||||||
|
{
|
||||||
|
$fuser = null;
|
||||||
|
if ($object->fk_user_author > 0)
|
||||||
|
{
|
||||||
|
$fuser=new User($db);
|
||||||
|
$fuser->fetch($object->fk_user_author);
|
||||||
|
}
|
||||||
|
|
||||||
|
$expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR;
|
||||||
|
$num_car = (empty($conf->global->NDF_NUM_CAR_REF))?"5":$conf->global->NDF_NUM_CAR_REF;
|
||||||
|
|
||||||
|
$sql = 'SELECT MAX(de.ref_number_int) as max';
|
||||||
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport de';
|
||||||
|
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
if($db->num_rows($result) > 0):
|
||||||
|
$objp = $db->fetch_object($result);
|
||||||
|
$newref = $objp->max;
|
||||||
|
$newref++;
|
||||||
|
while(strlen($newref) < $num_car):
|
||||||
|
$newref = "0".$newref;
|
||||||
|
endwhile;
|
||||||
|
else:
|
||||||
|
$newref = 1;
|
||||||
|
while(strlen($newref) < $num_car):
|
||||||
|
$newref = "0".$newref;
|
||||||
|
endwhile;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
$ref_number_int = ($newref+1)-1;
|
||||||
|
$update_number_int = true;
|
||||||
|
|
||||||
|
$user_author_infos = dolGetFirstLastname($fuser->firstname, $fuser->lastname);
|
||||||
|
|
||||||
|
$prefix="ER";
|
||||||
|
if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX;
|
||||||
|
$newref = str_replace(' ','_', $user_author_infos).$expld_car.$prefix.$newref.$expld_car.dol_print_date($object->date_debut,'%y%m%d');
|
||||||
|
|
||||||
|
dol_syslog("mod_expensereport_jade::getNextValue return ".$newref);
|
||||||
|
return $newref;
|
||||||
|
}
|
||||||
|
|
||||||
// D'abord on recupere la valeur max
|
// D'abord on recupere la valeur max
|
||||||
$posindice=8;
|
$posindice=8;
|
||||||
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
|
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
|
||||||
|
|||||||
@ -315,11 +315,16 @@ if (empty($reshook))
|
|||||||
|
|
||||||
if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
|
if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
|
||||||
{
|
{
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
$object = new ExpenseReport($db);
|
$object = new ExpenseReport($db);
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
|
|
||||||
$result = $object->setValidate($user);
|
$result = $object->setValidate($user);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
// Define output language
|
// Define output language
|
||||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||||
@ -338,8 +343,13 @@ if (empty($reshook))
|
|||||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
if ($result > 0 && $object->fk_user_validator > 0)
|
if (! $error && $result > 0 && $object->fk_user_validator > 0)
|
||||||
{
|
{
|
||||||
$langs->load("mails");
|
$langs->load("mails");
|
||||||
|
|
||||||
@ -418,10 +428,15 @@ if (empty($reshook))
|
|||||||
$action='';
|
$action='';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (! $error)
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
{
|
||||||
}
|
$db->commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
|
if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
|
||||||
|
|||||||
@ -1091,7 +1091,7 @@ class ExpenseReport extends CommonObject
|
|||||||
{
|
{
|
||||||
$num = $this->ref;
|
$num = $this->ref;
|
||||||
}
|
}
|
||||||
if (empty($num)) return -1;
|
if (empty($num) || $num < 0) return -1;
|
||||||
|
|
||||||
$this->newref = $num;
|
$this->newref = $num;
|
||||||
|
|
||||||
|
|||||||
@ -74,6 +74,7 @@ EX_CAM_VP=PV maintenance and repair
|
|||||||
DefaultCategoryCar=Default transportation mode
|
DefaultCategoryCar=Default transportation mode
|
||||||
DefaultRangeNumber=Default range number
|
DefaultRangeNumber=Default range number
|
||||||
|
|
||||||
|
Error_EXPENSEREPORT_ADDON_NotDefined=Error, the rule for expense report numbering ref was not defined into setup of module 'Expense Report'
|
||||||
ErrorDoubleDeclaration=You have declared another expense report into a similar date range.
|
ErrorDoubleDeclaration=You have declared another expense report into a similar date range.
|
||||||
AucuneLigne=There is no expense report declared yet
|
AucuneLigne=There is no expense report declared yet
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user