Work on edit link of expense report line and files
This commit is contained in:
parent
d728af9ced
commit
8d18915746
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
|
||||
* Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
|
||||
@ -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 '</script>'."\n";
|
||||
print '</td></tr>';
|
||||
|
||||
$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';
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -88,6 +88,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
|
||||
print '<br>';
|
||||
$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 '<div class="margintoponly"><input type="radio"'.$checked.' name="attachfile[]" value="'.$file['relativename'].'"> '.$file['relativename'].'</div>';
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user