diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php
index a93f5c3c608..61688e18515 100644
--- a/htdocs/admin/expensereport.php
+++ b/htdocs/admin/expensereport.php
@@ -37,7 +37,9 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
// Load translation files required by the page
$langs->loadLangs(array('admin', 'errors', 'trips', 'other'));
-if (!$user->admin) accessforbidden();
+if (!$user->admin) {
+ accessforbidden();
+}
$action = GETPOST('action', 'aZ09');
$value = GETPOST('value', 'alpha');
@@ -52,51 +54,47 @@ $type = 'expensereport';
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
-if ($action == 'updateMask')
-{
+if ($action == 'updateMask') {
$maskconst = GETPOST('maskconst', 'alpha');
$maskvalue = GETPOST('maskvalue', 'alpha');
- if ($maskconst) $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
+ if ($maskconst) {
+ $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
+ }
- if (!$res > 0) $error++;
+ if (!$res > 0) {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
setEventMessages($langs->trans("Error"), null, 'errors');
}
-} elseif ($action == 'specimen') // For fiche inter
-{
+} elseif ($action == 'specimen') { // For fiche expensereport
$modele = GETPOST('module', 'alpha');
- $inter = new ExpenseReport($db);
- $inter->initAsSpecimen();
- $inter->status = 0; // Force statut draft to show watermark
- $inter->fk_statut = 0; // Force statut draft to show watermark
+ $expensespecimen = new ExpenseReport($db);
+ $expensespecimen->initAsSpecimen();
+ $expensespecimen->status = 0; // Force statut draft to show watermark
// Search template files
$file = ''; $classname = ''; $filefound = 0;
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
- foreach ($dirmodels as $reldir)
- {
+ foreach ($dirmodels as $reldir) {
$file = dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php", 0);
- if (file_exists($file))
- {
+ if (file_exists($file)) {
$filefound = 1;
$classname = "pdf_".$modele;
break;
}
}
- if ($filefound)
- {
+ if ($filefound) {
require_once $file;
$module = new $classname($db);
- if ($module->write_file($inter, $langs) > 0)
- {
+ if ($module->write_file($expensespecimen, $langs) > 0) {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
return;
} else {
@@ -107,30 +105,22 @@ if ($action == 'updateMask')
setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
}
-}
-
-// Activate a model
-elseif ($action == 'set')
-{
+} elseif ($action == 'set') {
+ // Activate a model
$ret = addDocumentModel($value, $type, $label, $scandir);
- if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF))
- {
+ if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF)) {
dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value, 'chaine', 0, '', $conf->entity);
}
-} elseif ($action == 'del')
-{
+} elseif ($action == 'del') {
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
- if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF', $conf->entity);
+ if ($ret > 0) {
+ if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") {
+ dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF', $conf->entity);
+ }
}
-}
-
-// Set default model
-elseif ($action == 'setdoc')
-{
- if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
- {
+} elseif ($action == 'setdoc') {
+ // Set default model
+ if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
// La constante qui a ete lue en avant du nouveau set
// on passe donc par une variable pour avoir un affichage coherent
$conf->global->EXPENSEREPORT_ADDON_PDF = $value;
@@ -138,18 +128,15 @@ elseif ($action == 'setdoc')
// On active le modele
$ret = delDocumentModel($value, $type);
- if ($ret > 0)
- {
+ if ($ret > 0) {
$ret = addDocumentModel($value, $type, $label, $scandir);
}
-} elseif ($action == 'setmod')
-{
+} elseif ($action == 'setmod') {
// TODO Verifier si module numerotation choisi peut etre active
// par appel methode canBeActivated
dolibarr_set_const($db, "EXPENSEREPORT_ADDON", $value, 'chaine', 0, '', $conf->entity);
-} elseif ($action == 'setoptions')
-{
+} elseif ($action == 'setoptions') {
$db->begin();
$freetext = GETPOST('EXPENSEREPORT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
@@ -158,10 +145,11 @@ elseif ($action == 'setdoc')
$draft = GETPOST('EXPENSEREPORT_DRAFT_WATERMARK', 'alpha');
$res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
- if (!$res1 > 0 || !$res2 > 0) $error++;
+ if (!$res1 > 0 || !$res2 > 0) {
+ $error++;
+ }
- if (!$error)
- {
+ if (!$error) {
$db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else {
@@ -206,19 +194,14 @@ print ''."\n";
clearstatcache();
-foreach ($dirmodels as $reldir)
-{
+foreach ($dirmodels as $reldir) {
$dir = dol_buildpath($reldir."core/modules/expensereport/");
- if (is_dir($dir))
- {
+ if (is_dir($dir)) {
$handle = opendir($dir);
- if (is_resource($handle))
- {
- while (($file = readdir($handle)) !== false)
- {
- if (substr($file, 0, 18) == 'mod_expensereport_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
- {
+ if (is_resource($handle)) {
+ while (($file = readdir($handle)) !== false) {
+ if (substr($file, 0, 18) == 'mod_expensereport_' && substr($file, dol_strlen($file) - 3, 3) == 'php') {
$file = substr($file, 0, dol_strlen($file) - 4);
require_once $dir.$file.'.php';
@@ -226,11 +209,14 @@ foreach ($dirmodels as $reldir)
$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->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
+ continue;
+ }
+ if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
+ continue;
+ }
- if ($module->isEnabled())
- {
+ if ($module->isEnabled()) {
print '
| '.$module->nom." | \n";
print $module->info();
print ' | ';
@@ -241,13 +227,15 @@ foreach ($dirmodels as $reldir)
if (preg_match('/^Error/', $tmp)) {
$langs->load("errors");
print ''.$langs->trans($tmp).'
';
- } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
- else print $tmp;
+ } elseif ($tmp == 'NotConfigured') {
+ print $langs->trans($tmp);
+ } else {
+ print $tmp;
+ }
print ''."\n";
print '';
- if ($conf->global->EXPENSEREPORT_ADDON == $file)
- {
+ if ($conf->global->EXPENSEREPORT_ADDON == $file) {
print img_picto($langs->trans("Activated"), 'switch_on');
} else {
print '';
@@ -266,8 +254,9 @@ foreach ($dirmodels as $reldir)
if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
$htmltooltip .= ''.$langs->trans("NextValue").': ';
if ($nextval) {
- if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
+ if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
$nextval = $langs->trans($nextval);
+ }
$htmltooltip .= $nextval.' ';
} else {
$htmltooltip .= $langs->trans($module->error).' ';
@@ -289,7 +278,7 @@ foreach ($dirmodels as $reldir)
print " \n";
/*
- * Documents models for Interventions
+ * Documents models for ExpenseReport
*/
print load_fiche_titre($langs->trans("TemplatePDFExpenseReports"), '', '');
@@ -302,12 +291,10 @@ $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
$sql .= " WHERE type = '".$db->escape($type)."'";
$sql .= " AND entity = ".$conf->entity;
$resql = $db->query($sql);
-if ($resql)
-{
+if ($resql) {
$i = 0;
$num_rows = $db->num_rows($resql);
- while ($i < $num_rows)
- {
+ while ($i < $num_rows) {
$array = $db->fetch_array($resql);
array_push($def, $array[0]);
$i++;
@@ -328,28 +315,21 @@ print " |
\n";
clearstatcache();
-foreach ($dirmodels as $reldir)
-{
+foreach ($dirmodels as $reldir) {
$dir = dol_buildpath($reldir."core/modules/expensereport/doc");
- if (is_dir($dir))
- {
+ if (is_dir($dir)) {
$handle = opendir($dir);
- if (is_resource($handle))
- {
- while (($file = readdir($handle)) !== false)
- {
+ if (is_resource($handle)) {
+ while (($file = readdir($handle)) !== false) {
$filelist[] = $file;
}
closedir($handle);
arsort($filelist);
- foreach ($filelist as $file)
- {
- if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
- {
- if (file_exists($dir.'/'.$file))
- {
+ foreach ($filelist as $file) {
+ if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) {
+ if (file_exists($dir.'/'.$file)) {
$name = substr($file, 4, dol_strlen($file) - 16);
$classname = substr($file, 0, dol_strlen($file) - 12);
@@ -357,21 +337,26 @@ foreach ($dirmodels as $reldir)
$module = new $classname($db);
$modulequalified = 1;
- if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
- if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
+ if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
+ $modulequalified = 0;
+ }
+ if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
+ $modulequalified = 0;
+ }
- if ($modulequalified)
- {
+ if ($modulequalified) {
print '| ';
print (empty($module->name) ? $name : $module->name);
print " | \n";
- if (method_exists($module, 'info')) print $module->info($langs);
- else print $module->description;
+ if (method_exists($module, 'info')) {
+ print $module->info($langs);
+ } else {
+ print $module->description;
+ }
print ' | ';
// Active
- if (in_array($name, $def))
- {
+ if (in_array($name, $def)) {
print ''."\n";
print 'scandir.'&label='.urlencode($module->name).'">';
print img_picto($langs->trans("Enabled"), 'switch_on');
@@ -385,8 +370,7 @@ foreach ($dirmodels as $reldir)
// Default
print ' | ';
- if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name")
- {
+ if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name") {
print img_picto($langs->trans("Default"), 'on');
} else {
print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
@@ -409,8 +393,7 @@ foreach ($dirmodels as $reldir)
// Preview
print ' | ';
- if ($module->type == 'pdf')
- {
+ if ($module->type == 'pdf') {
print ''.img_object($langs->trans("Preview"), 'pdf').'';
} else {
print img_object($langs->trans("PreviewNotAvailable"), 'generic');
@@ -451,14 +434,15 @@ print " |
\n";
$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
$htmltext = ''.$langs->trans("AvailableVariables").':
';
-foreach ($substitutionarray as $key => $val) $htmltext .= $key.'
';
+foreach ($substitutionarray as $key => $val) {
+ $htmltext .= $key.'
';
+}
$htmltext .= '';
print '';
print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'
'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').' ';
$variablename = 'EXPENSEREPORT_FREE_TEXT';
-if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
-{
+if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
print '';
} else {
include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
diff --git a/htdocs/admin/expensereport_rules.php b/htdocs/admin/expensereport_rules.php
index 9b56ac5901b..050c2b9455c 100644
--- a/htdocs/admin/expensereport_rules.php
+++ b/htdocs/admin/expensereport_rules.php
@@ -20,7 +20,7 @@
/**
- * \file htdocs/admin/expensereport_ik.php
+ * \file htdocs/admin/expensereport_rules.php
* \ingroup expensereport
* \brief Page to display expense tax ik
*/
@@ -34,7 +34,9 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_rule.class.ph
// Load translation files required by the page
$langs->loadLangs(array("admin", "other", "trips", "errors", "dict"));
-if (!$user->admin) accessforbidden();
+if (!$user->admin) {
+ accessforbidden();
+}
//Init error
$error = false;
@@ -55,15 +57,15 @@ $amount = GETPOST('amount');
$restrictive = GETPOST('restrictive');
$object = new ExpenseReportRule($db);
-if (!empty($id))
-{
+if (!empty($id)) {
$result = $object->fetch($id);
- if ($result < 0) dol_print_error('', $object->error, $object->errors);
+ if ($result < 0) {
+ dol_print_error('', $object->error, $object->errors);
+ }
}
// TODO do action
-if ($action == 'save')
-{
+if ($action == 'save') {
$error = 0;
// check parameters
@@ -92,8 +94,7 @@ if ($action == 'save')
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ExpenseReportLimitAmount")), null, 'errors');
}
- if (empty($error))
- {
+ if (empty($error)) {
$object->setValues($_POST);
if ($apply_to == 'U') {
@@ -116,18 +117,22 @@ if ($action == 'save')
$object->entity = $conf->entity;
$res = $object->create($user);
- if ($res > 0) setEventMessages($langs->trans('ExpenseReportRuleSave'), null);
- else dol_print_error($object->db);
+ if ($res > 0) {
+ setEventMessages($langs->trans('ExpenseReportRuleSave'), null);
+ } else {
+ dol_print_error($object->db);
+ }
header('Location: '.$_SERVER['PHP_SELF']);
exit;
}
-} elseif ($action == 'delete')
-{
+} elseif ($action == 'delete') {
// TODO add confirm
$res = $object->delete($user);
- if ($res < 0) dol_print_error($object->db);
+ if ($res < 0) {
+ dol_print_error($object->db);
+ }
header('Location: '.$_SERVER['PHP_SELF']);
exit;
@@ -135,8 +140,17 @@ if ($action == 'save')
$rules = ExpenseReportRule::getAllRule();
-$tab_apply = array('A' => $langs->trans('All'), 'G' => $langs->trans('Group'), 'U' => $langs->trans('User'));
-$tab_rules_type = array('EX_DAY' => $langs->trans('Day'), 'EX_MON' => $langs->trans('Month'), 'EX_YEA' => $langs->trans('Year'), 'EX_EXP' => $langs->trans('OnExpense'));
+$tab_apply = array(
+ 'A' => $langs->trans('All'),
+ 'G' => $langs->trans('Group'),
+ 'U' => $langs->trans('User')
+);
+$tab_rules_type = array(
+ 'EX_DAY' => $langs->trans('Day'),
+ 'EX_MON' => $langs->trans('Month'),
+ 'EX_YEA' => $langs->trans('Year'),
+ 'EX_EXP' => $langs->trans('OnExpense')
+);
/*
@@ -156,8 +170,7 @@ print dol_get_fiche_head($head, 'expenserules', $langs->trans("ExpenseReportsRul
echo ''.$langs->trans('ExpenseReportRulesDesc').'';
print '
';
-if ($action != 'edit')
-{
+if ($action != 'edit') {
echo ' |
';
-foreach ($rules as $rule)
-{
+foreach ($rules as $rule) {
echo '';
echo '| ';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
$selected = ($object->is_for_all > 0) ? 'A' : ($object->fk_usergroup > 0 ? 'G' : 'U');
echo ' '.$form->selectarray('apply_to', $tab_apply, $selected, 0).' ';
echo ''.$form->select_dolusers($object->fk_user, 'fk_user').' ';
echo ''.$form->select_dolgroups($object->fk_usergroup, 'fk_usergroup').' ';
} else {
- if ($rule->is_for_all > 0) echo $tab_apply['A'];
- elseif ($rule->fk_usergroup > 0) echo $tab_apply['G'].' ('.$rule->getGroupLabel().')';
- elseif ($rule->fk_user > 0) echo $tab_apply['U'].' ('.$rule->getUserName().')';
- }
- echo ' | ';
-
-
- echo '';
- if ($action == 'edit' && $object->id == $rule->id)
- {
- echo $form->selectExpense($object->fk_c_type_fees, 'fk_c_type_fees', 0, 1, 1);
- } else {
- if ($rule->fk_c_type_fees == -1) echo $langs->trans('AllExpenseReport');
- else {
- $key = getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'code', $rule->fk_c_type_fees, false, 'id');
- if ($key != $langs->trans($key)) echo $langs->trans($key);
- else echo $langs->trans(getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'label', $rule->fk_c_type_fees, false, 'id')); // TODO check to return trans of 'code'
+ if ($rule->is_for_all > 0) {
+ echo $tab_apply['A'];
+ } elseif ($rule->fk_usergroup > 0) {
+ echo $tab_apply['G'].' ('.$rule->getGroupLabel().')';
+ } elseif ($rule->fk_user > 0) {
+ echo $tab_apply['U'].' ('.$rule->getUserName().')';
}
}
echo ' | ';
echo '';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
+ echo $form->selectExpense($object->fk_c_type_fees, 'fk_c_type_fees', 0, 1, 1);
+ } else {
+ if ($rule->fk_c_type_fees == -1) {
+ echo $langs->trans('AllExpenseReport');
+ } else {
+ $key = getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'code', $rule->fk_c_type_fees, false, 'id');
+ if ($key != $langs->trans($key)) {
+ echo $langs->trans($key);
+ } else {
+ echo $langs->trans(getDictvalue(MAIN_DB_PREFIX.'c_type_fees', 'label', $rule->fk_c_type_fees, false, 'id')); // TODO check to return trans of 'code'
+ }
+ }
+ }
+ echo ' | ';
+
+
+ echo '';
+ if ($action == 'edit' && $object->id == $rule->id) {
echo $form->selectarray('code_expense_rules_type', $tab_rules_type, $object->code_expense_rules_type, 0);
} else {
echo $tab_rules_type[$rule->code_expense_rules_type];
@@ -263,8 +279,7 @@ foreach ($rules as $rule)
echo ' | ';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
print $form->selectDate(strtotime(date('Y-m-d', $object->dates)), 'start', '', '', 0, '', 1, 0);
} else {
echo dol_print_date($rule->dates, 'day');
@@ -273,8 +288,7 @@ foreach ($rules as $rule)
echo ' | ';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
print $form->selectDate(strtotime(date('Y-m-d', $object->datee)), 'end', '', '', 0, '', 1, 0);
} else {
echo dol_print_date($rule->datee, 'day');
@@ -283,8 +297,7 @@ foreach ($rules as $rule)
echo ' | ';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
echo ''.$conf->currency;
} else {
echo price($rule->amount, 0, $langs, 1, -1, -1, $conf->currency);
@@ -293,8 +306,7 @@ foreach ($rules as $rule)
echo ' | ';
- if ($action == 'edit' && $object->id == $rule->id)
- {
+ if ($action == 'edit' && $object->id == $rule->id) {
echo $form->selectyesno('restrictive', $object->restrictive, 1);
} else {
echo yn($rule->restrictive, 1, 1);
@@ -303,8 +315,7 @@ foreach ($rules as $rule)
echo ' | ';
- if ($object->id != $rule->id)
- {
+ if ($object->id != $rule->id) {
echo ''.img_edit().' ';
echo ''.img_delete().'';
} else {
|