NEW Can upload files from the edit page of expense report

This commit is contained in:
Laurent Destailleur 2019-03-07 20:53:03 +01:00
parent 25fa729e4e
commit 0798f7b719
6 changed files with 120 additions and 51 deletions

View File

@ -29,7 +29,7 @@
// Submit file/link
if (GETPOST('sendit', 'alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
if (! empty($_FILES))
if (! empty($_FILES))
{
if (is_array($_FILES['userfile']['tmp_name'])) $userfiles=$_FILES['userfile']['tmp_name'];
else $userfiles=array($_FILES['userfile']['tmp_name']);

View File

@ -77,9 +77,10 @@ class FormFile
* @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM)
* @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*')
* @param string $sectiondir If upload must be done inside a particular directory (is sectiondir defined, sectionid must not be)
* @param int $usewithoutform 0=Default, 1=Disable <form> and style to use in existing area
* @return int <0 if KO, >0 if OK
*/
public function form_attach_new_file($url, $title = '', $addcancel = 0, $sectionid = 0, $perm = 1, $size = 50, $object = '', $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', $sectiondir = '')
public function form_attach_new_file($url, $title = '', $addcancel = 0, $sectionid = 0, $perm = 1, $size = 50, $object = '', $options = '', $useajax = 1, $savingdocmask = '', $linkfiles = 1, $htmlname = 'formuserfile', $accept = '', $sectiondir = '', $usewithoutform = 0)
{
// phpcs:enable
global $conf,$langs, $hookmanager;
@ -114,10 +115,13 @@ class FormFile
if (empty($title)) $title=$langs->trans("AttachANewFile");
if ($title != 'none') $out.=load_fiche_titre($title, null, null);
$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
$out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
if (empty($usewithoutform))
{
$out .= '<form name="'.$htmlname.'" id="'.$htmlname.'" action="'.$url.'" enctype="multipart/form-data" method="POST">';
$out .= '<input type="hidden" id="'.$htmlname.'_section_dir" name="section_dir" value="'.$sectiondir.'">';
$out .= '<input type="hidden" id="'.$htmlname.'_section_id" name="section_id" value="'.$sectionid.'">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
}
$out .= '<table width="100%" class="nobordernopadding">';
$out .= '<tr>';
@ -176,13 +180,7 @@ class FormFile
if ($savingdocmask)
{
//add a global variable for disable the auto renaming on upload
if (! empty($conf->global->MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT))
{
$rename='';
}
else {
$rename='checked';
}
$rename=(empty($conf->global->MAIN_DOC_UPLOAD_NOT_RENAME_BY_DEFAULT)?'checked':'');
$out .= '<tr>';
if (! empty($options)) $out .= '<td>'.$options.'</td>';
@ -194,8 +192,11 @@ class FormFile
$out .= "</table>";
$out .= '</form>';
if (empty($sectionid)) $out .= '<br>';
if (empty($usewithoutform))
{
$out .= '</form>';
if (empty($sectionid)) $out .= '<br>';
}
$out .= "\n<!-- End form attach new file -->\n";
@ -205,12 +206,16 @@ class FormFile
$langs->load('link');
$title = $langs->trans("LinkANewFile");
$out .= load_fiche_titre($title, null, null);
$out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
$out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
$out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$out .= '<div class="valignmiddle" >';
if (empty($usewithoutform))
{
$out .= '<form name="'.$htmlname.'_link" id="'.$htmlname.'_link" action="'.$url.'" method="POST">';
$out .= '<input type="hidden" id="'.$htmlname.'_link_section_dir" name="link_section_dir" value="">';
$out .= '<input type="hidden" id="'.$htmlname.'_link_section_id" name="link_section_id" value="'.$sectionid.'">';
$out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
}
$out .= '<div class="valignmiddle">';
$out .= '<div class="inline-block" style="padding-right: 10px;">';
if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= '<label for="link">'.$langs->trans("URLToLink") . ':</label> ';
$out .= '<input type="text" name="link" class="flat minwidth400imp" id="link" placeholder="'.dol_escape_htmltag($langs->trans("URLToLink")).'">';
@ -227,8 +232,11 @@ class FormFile
$out .= '>';
$out .= '</div>';
$out .= '</div>';
$out .= '<div class="clearboth"></div>';
$out .= '</form><br>';
if (empty($usewithoutform))
{
$out .= '<div class="clearboth"></div>';
$out .= '</form><br>';
}
$out .= "\n<!-- End form link new url -->\n";
}
@ -237,7 +245,7 @@ class FormFile
$res = $hookmanager->executeHooks('formattachOptions', $parameters, $object);
if (empty($res))
{
print '<div class="attacharea attacharea'.$htmlname.'">';
print '<div class="'.($usewithoutform?'inline-block valignmiddle':'attacharea attacharea'.$htmlname).'">';
print $out;
print '</div>';
}

View File

@ -36,6 +36,7 @@ require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php';
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php';
@ -106,6 +107,8 @@ $permissiondellink = $user->rights->expensereport->creer; // Used by the includ
$permissionedit = $user->rights->expensereport->creer; // Used by the include of actions_lineupdown.inc.php
$upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref);
/*
@ -139,6 +142,10 @@ if (empty($reshook))
$fk_c_type_fees=-1;
}
include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
if (GETPOST('sendit', 'alpha')) $action='';
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
@ -216,7 +223,7 @@ if (empty($reshook))
if ($ret < 0) $error++;
}
if (empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin))
if (! $error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin))
{
$error++;
setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors');
@ -672,10 +679,6 @@ if (empty($reshook))
$action='';
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->approve)
{
@ -795,10 +798,6 @@ if (empty($reshook))
$action='';
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
//var_dump($user->id == $object->fk_user_validator);exit;
if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha')=="yes" && $id > 0 && $user->rights->expensereport->creer)
@ -1085,15 +1084,17 @@ if (empty($reshook))
$action='';
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
}
if ($action == "addline" && $user->rights->expensereport->creer)
{
$error = 0;
// First save uploaded file
if (! empty($_FILES))
{
}
// if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
if (empty($vatrate)) $vatrate = "0.000";
$tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate));
@ -1150,7 +1151,8 @@ if (empty($reshook))
// Insert line
$result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_projet, $fk_c_exp_tax_cat, $type);
if ($result > 0) {
if ($result > 0)
{
$ret = $object->fetch($object->id); // Reload to get new records
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
@ -1998,7 +2000,7 @@ else
$actiontouse='updateline';
if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline') $actiontouse='addline';
print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" method="post" >';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="'.$actiontouse.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
@ -2193,8 +2195,62 @@ else
}
// Add a line
if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline' && $user->rights->expensereport->creer)
if (($object->fk_statut == ExpenseReport::STATUS_DRAFT || $object->fk_statut == ExpenseReport::STATUS_REFUSED) && $action != 'editline' && $user->rights->expensereport->creer)
{
$colspan = 10;
if (! empty($conf->global->MAIN_USE_EXPENSE_IK)) $colspan++;
if (! empty($conf->projet->enabled)) $colspan++;
if ($action != 'editline') $colspan++;
print '<tr class="liste_titre">';
print '<td colspan="'.$colspan.'" class="liste_titre">';
print $langs->trans("UploadANewFileNow");
print '</td></tr>';
print '<tr class="oddeven">';
print '<td colspan="'.$colspan.'">';
$modulepart = 'expensereport';
$permission = $user->rights->expensereport->creer;
$formfile=new FormFile($db);
// We define var to enable the feature to add prefix of uploaded files
$savingdocmask='';
if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX))
{
//var_dump($modulepart);
if (in_array($modulepart, array('facture_fournisseur','commande_fournisseur','facture','commande','propal','supplier_proposal','ficheinter','contract','expedition','project','project_task','expensereport','tax', 'produit', 'product_batch')))
{
$savingdocmask=dol_sanitizeFileName($object->ref).'-__file__';
}
/*if (in_array($modulepart,array('member')))
{
$savingdocmask=$object->login.'___file__';
}*/
}
// Show upload form (document and links)
$formfile->form_attach_new_file(
$_SERVER["PHP_SELF"].'?id='.$object->id,
'none',
0,
0,
$permission,
$conf->browser->layout == 'phone' ? 40 : 60,
$object,
'',
1,
$savingdocmask,
0,
'formuserfile',
'accept',
'',
1
);
print '</td></tr>';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
@ -2211,6 +2267,7 @@ else
print '<tr class="oddeven">';
// Line number
print '<td></td>';
// Select date
@ -2226,7 +2283,7 @@ else
print '</td>';
}
if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
if (! empty($conf->global->MAIN_USE_EXPENSE_IK))
{
print '<td class="fk_c_exp_tax_cat">';
$params = array('fk_expense' => $object->id);
@ -2241,7 +2298,7 @@ else
// Add comments
print '<td>';
print '<textarea class="flat_ndf centpercent" name="comments">'.dol_escape_htmltag($comments).'</textarea>';
print '<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.'">'.dol_escape_htmltag($comments).'</textarea>';
print '</td>';
// Select VAT
@ -2275,6 +2332,16 @@ else
print '<td align="center"><input type="submit" value="'.$langs->trans("Add").'" name="bouton" class="button"></td>';
print '</tr>';
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
print '<tr class="oddeven"><td colspan="'.$colspan.'">';
print $langs->trans("AttachTheNewLineToTheDocument");
print '...';
print '</td></tr>';
}
} // Fin si c'est payé/validé
print '</table>';

View File

@ -165,7 +165,7 @@ class ExpenseReport extends CommonObject
*/
public function create($user, $notrigger = 0)
{
global $conf;
global $conf, $langs;
$now = dol_now();
@ -174,7 +174,7 @@ class ExpenseReport extends CommonObject
// Check parameters
if (empty($this->date_debut) || empty($this->date_fin))
{
$this->error='ErrorFieldRequired';
$this->error=$langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Date'));
return -1;
}

View File

@ -73,7 +73,7 @@ $modulepart='trip';
* Actions
*/
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
include DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
/*

View File

@ -73,23 +73,19 @@ EX_PAR_VP=Parking PV
EX_CAM_VP=PV maintenance and repair
DefaultCategoryCar=Default transportation mode
DefaultRangeNumber=Default range number
UploadANewFileNow=Upload a new document now
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.
AucuneLigne=There is no expense report declared yet
ModePaiement=Payment mode
VALIDATOR=User responsible for approval
VALIDOR=Approved by
AUTHOR=Recorded by
AUTHORPAIEMENT=Paid by
REFUSEUR=Denied by
CANCEL_USER=Deleted by
MOTIF_REFUS=Reason
MOTIF_CANCEL=Reason
DATE_REFUS=Deny date
DATE_SAVE=Validation date
DATE_CANCEL=Cancelation date
@ -140,7 +136,6 @@ OnExpense=Expense line
ExpenseReportRuleSave=Expense report rule saved
ExpenseReportRuleErrorOnSave=Error: %s
RangeNum=Range %d
ExpenseReportConstraintViolationError=Constraint violation id [%s]: %s is superior to %s %s
byEX_DAY=by day (limitation to %s)
byEX_MON=by month (limitation to %s)
@ -151,7 +146,6 @@ nolimitbyEX_DAY=by day (no limitation)
nolimitbyEX_MON=by month (no limitation)
nolimitbyEX_YEA=by year (no limitation)
nolimitbyEX_EXP=by line (no limitation)
CarCategory=Category of car
ExpenseRangeOffset=Offset amount: %s
RangeIk=Mileage range