From 8d1891574628396ab56f24eb3533d9254d2646be Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Apr 2019 18:18:04 +0200 Subject: [PATCH] Work on edit link of expense report line and files --- htdocs/expensereport/card.php | 29 +++++++++++++-- .../class/expensereport.class.php | 35 ++++++++++++------- .../tpl/expensereport_linktofile.tpl.php | 6 ++++ htdocs/langs/en_US/trips.lang | 2 +- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 0cbbeb6d240..8f6f7c98c56 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2017 Laurent Destailleur + * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2017 Ferran Marcet @@ -1243,6 +1243,21 @@ if (empty($reshook)) $object = new ExpenseReport($db); $object->fetch($id); + // First save uploaded file + $fk_ecm_files = 0; + if (GETPOSTISSET('attachfile')) + { + $arrayoffiles=GETPOST('attachfile', 'array'); + if (is_array($arrayoffiles) && ! empty($arrayoffiles[0])) + { + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + $relativepath='expensereport/'.$object->ref.'/'.$arrayoffiles[0]; + $ecmfiles=new EcmFiles($db); + $ecmfiles->fetch(0, '', $relativepath); + $fk_ecm_files = $ecmfiles->id; + } + } + $rowid = $_POST['rowid']; $type_fees_id = GETPOST('fk_c_type_fees', 'int'); $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int'); @@ -1284,7 +1299,7 @@ if (empty($reshook)) if (! $error) { // TODO Use update method of ExpenseReportLine - $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat); + $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files); if ($result >= 0) { if ($result > 0) @@ -2249,6 +2264,16 @@ else print ''."\n"; print ''; + $filenamelinked=''; + if ($line->fk_ecm_files > 0) + { + $result = $ecmfilesstatic->fetch($line->fk_ecm_files); + if ($result > 0) + { + $filenamelinked = $ecmfilesstatic->filename; + } + } + $tredited='tredited'; include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 6a4fe0e7616..55a411cf1c7 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1940,7 +1940,7 @@ class ExpenseReport extends CommonObject } /** - * updateline + * Update an expense report line * * @param int $rowid Line to edit * @param int $type_fees_id Type payment @@ -1951,10 +1951,11 @@ class ExpenseReport extends CommonObject * @param double $value_unit Value init * @param int $date Date * @param int $expensereport_id Expense report id - * @param int $fk_c_exp_tax_cat id of category of car + * @param int $fk_c_exp_tax_cat Id of category of car + * @param int $fk_ecm_files Id of ECM file to link to this expensereport line * @return int <0 if KO, >0 if OK */ - public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0) + public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0) { global $user, $mysoc; @@ -2013,6 +2014,8 @@ class ExpenseReport extends CommonObject $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->fk_ecm_files = $fk_ecm_files; + $this->line->rowid = $rowid; $this->line->id = $rowid; @@ -2020,21 +2023,26 @@ class ExpenseReport extends CommonObject $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; $sql.= " WHERE c.id = ".$type_fees_id; - $result = $this->db->query($sql); - $objp_fees = $this->db->fetch_object($result); - $this->line->type_fees_code = $objp_fees->code_type_fees; - $this->line->type_fees_libelle = $objp_fees->libelle_type_fees; + $resql = $this->db->query($sql); + if ($resql) + { + $objp_fees = $this->db->fetch_object($resql); + $this->line->type_fees_code = $objp_fees->code_type_fees; + $this->line->type_fees_libelle = $objp_fees->libelle_type_fees; + $this->db->free($resql); + } // Select des informations du projet $sql = "SELECT p.ref as ref_projet, p.title as title_projet"; $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql.= " WHERE p.rowid = ".$projet_id; - $result = $this->db->query($sql); - if ($result) { - $objp_projet = $this->db->fetch_object($result); + $resql = $this->db->query($sql); + if ($resql) { + $objp_projet = $this->db->fetch_object($resql); + $this->line->projet_ref = $objp_projet->ref_projet; + $this->line->projet_title = $objp_projet->title_projet; + $this->db->free($resql); } - $this->line->projet_ref = $objp_projet->ref_projet; - $this->line->projet_title = $objp_projet->title_projet; $this->applyOffset(); $this->checkRules(); @@ -2727,7 +2735,8 @@ class ExpenseReportLine $sql.= ",vat_src_code='".$this->db->escape($this->vat_src_code)."'"; $sql.= ",rule_warning_message='".$this->db->escape($this->rule_warning_message)."'"; $sql.= ",fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat); - if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); + $sql.= ",fk_ecm_files=".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); + if ($this->fk_c_type_fees) $sql.= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); else $sql.= ",fk_c_type_fees=null"; if ($this->fk_project > 0) $sql.= ",fk_projet=".$this->db->escape($this->fk_project); else $sql.= ",fk_projet=null"; diff --git a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php index ccdbc4ecf12..4ea23418db8 100644 --- a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php +++ b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php @@ -88,6 +88,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) print '
'; $checked=''; //var_dump(GETPOST($file['relativename'])); var_dump($file['relativename']); var_dump($_FILES['userfile']['name']); + // If a file was just uploaded, we check to preselect it foreach($_FILES['userfile']['name'] as $tmpfile) { if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) @@ -100,6 +101,11 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) break; } } + // If we edit a line already linked, then $filenamelinked is defined to the filename (without path) of linked file + if (! empty($filenamelinked) && $filenamelinked == $file['relativename']) + { + $checked=' checked'; + } print '
'.$file['relativename'].'
'; print ''; } diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang index e34078e8fc2..654f14d6bf7 100644 --- a/htdocs/langs/en_US/trips.lang +++ b/htdocs/langs/en_US/trips.lang @@ -148,4 +148,4 @@ nolimitbyEX_EXP=by line (no limitation) CarCategory=Category of car ExpenseRangeOffset=Offset amount: %s RangeIk=Mileage range -AttachTheNewLineToTheDocument=Attach the new line to an existing document +AttachTheNewLineToTheDocument=Attach the line to an uploaded document