code syntax expensereport directory

This commit is contained in:
Frédéric FRANCE 2021-02-25 22:45:02 +01:00
parent f7c119e48c
commit 8a69fa0d35
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
20 changed files with 1703 additions and 1634 deletions

View File

@ -22,12 +22,24 @@
* \brief File to return Ajax response on third parties request * \brief File to return Ajax response on third parties request
*/ */
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal if (!defined('NOTOKENRENEWAL')) {
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); define('NOTOKENRENEWAL', 1); // Disables token renewal
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); }
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); if (!defined('NOREQUIREMENU')) {
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); define('NOREQUIREMENU', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); }
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
$res = 0; $res = 0;
require '../../main.inc.php'; require '../../main.inc.php';
@ -50,20 +62,25 @@ $fk_expense = GETPOST('fk_expense');
$fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat'); $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
if (empty($fk_expense) || $fk_expense < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense'))); if (empty($fk_expense) || $fk_expense < 0) {
elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat'))); echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense')));
else { } elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat')));
} else {
// @see ndfp.class.php:3576 (method: compute_total_km) // @see ndfp.class.php:3576 (method: compute_total_km)
$expense = new ExpenseReport($db); $expense = new ExpenseReport($db);
if ($expense->fetch($fk_expense) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense)); if ($expense->fetch($fk_expense) <= 0) {
else { echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
} else {
$userauthor = new User($db); $userauthor = new User($db);
if ($userauthor->fetch($expense->fk_user_author) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author)); if ($userauthor->fetch($expense->fk_user_author) <= 0) {
else { echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author));
} else {
$range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat); $range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat);
if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range)); if (empty($range)) {
else { echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
} else {
$ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency); $ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency);
echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline')); echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline'));
} }

View File

@ -24,12 +24,24 @@
* \brief File to return Ajax response on third parties request * \brief File to return Ajax response on third parties request
*/ */
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal if (!defined('NOTOKENRENEWAL')) {
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); define('NOTOKENRENEWAL', 1); // Disables token renewal
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); }
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); if (!defined('NOREQUIREMENU')) {
if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); define('NOREQUIREMENU', '1');
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); }
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
$res = 0; $res = 0;
require '../../main.inc.php'; require '../../main.inc.php';
@ -52,21 +64,20 @@ dol_syslog(join(',', $_GET));
// Generation liste des projets // Generation liste des projets
if (GETPOST('fk_projet') != '') if (GETPOST('fk_projet') != '') {
{
$return_arr = array(); $return_arr = array();
$sql = "SELECT p.rowid, p.ref, p.title, s.nom"; $sql = "SELECT p.rowid, p.ref, p.title, s.nom";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
if (!empty($_GET["fk_projet"])) $sql .= " WHERE p.ref LIKE '%".$db->escape($_GET["fk_projet"])."%' OR p.title LIKE '%".$db->escape($_GET["fk_projet"])."%' OR s.nom LIKE '%".$db->escape($_GET["fk_projet"])."%'"; // Add other filters if (!empty($_GET["fk_projet"])) {
$sql .= " WHERE p.ref LIKE '%".$db->escape($_GET["fk_projet"])."%' OR p.title LIKE '%".$db->escape($_GET["fk_projet"])."%' OR s.nom LIKE '%".$db->escape($_GET["fk_projet"])."%'"; // Add other filters
}
$sql .= " ORDER BY p.ref ASC"; $sql .= " ORDER BY p.ref ASC";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{ while ($row = $db->fetch_array($resql)) {
while ($row = $db->fetch_array($resql))
{
$label = $row['ref'].' - '.$row['title']; $label = $row['ref'].' - '.$row['title'];
$row_array['label'] = $label; $row_array['label'] = $label;
$row_array['value'] = $label; $row_array['value'] = $label;

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ class ExpenseReports extends DolibarrApi
/** /**
* @var array $FIELDS Mandatory fields, checked when create and update object * @var array $FIELDS Mandatory fields, checked when create and update object
*/ */
static $FIELDS = array( public static $FIELDS = array(
'fk_user_author' 'fk_user_author'
); );
@ -107,11 +107,12 @@ class ExpenseReports extends DolibarrApi
$sql = "SELECT t.rowid"; $sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t";
$sql .= ' WHERE t.entity IN ('.getEntity('expensereport').')'; $sql .= ' WHERE t.entity IN ('.getEntity('expensereport').')';
if ($user_ids) $sql .= " AND t.fk_user_author IN (".$user_ids.")"; if ($user_ids) {
$sql .= " AND t.fk_user_author IN (".$user_ids.")";
}
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters) {
{
if (!DolibarrApi::_checkFilters($sqlfilters)) { if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
} }
@ -131,13 +132,11 @@ class ExpenseReports extends DolibarrApi
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit)); $min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0; $i = 0;
while ($i < $min) while ($i < $min) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$expensereport_static = new ExpenseReport($this->db); $expensereport_static = new ExpenseReport($this->db);
if ($expensereport_static->fetch($obj->rowid)) { if ($expensereport_static->fetch($obj->rowid)) {
@ -172,12 +171,12 @@ class ExpenseReports extends DolibarrApi
$this->expensereport->$field = $value; $this->expensereport->$field = $value;
} }
/*if (isset($request_data["lines"])) { /*if (isset($request_data["lines"])) {
$lines = array(); $lines = array();
foreach ($request_data["lines"] as $line) { foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line); array_push($lines, (object) $line);
} }
$this->expensereport->lines = $lines; $this->expensereport->lines = $lines;
}*/ }*/
if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) { if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors)); throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
} }
@ -195,28 +194,28 @@ class ExpenseReports extends DolibarrApi
* @return int * @return int
*/ */
/* /*
public function getLines($id) public function getLines($id)
{ {
if(! DolibarrApiAccess::$user->rights->expensereport->lire) { if(! DolibarrApiAccess::$user->rights->expensereport->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->expensereport->fetch($id); $result = $this->expensereport->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'expensereport not found'); throw new RestException(404, 'expensereport not found');
} }
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$this->expensereport->getLinesArray(); $this->expensereport->getLinesArray();
$result = array(); $result = array();
foreach ($this->expensereport->lines as $line) { foreach ($this->expensereport->lines as $line) {
array_push($result,$this->_cleanObjectDatas($line)); array_push($result,$this->_cleanObjectDatas($line));
} }
return $result; return $result;
} }
*/ */
/** /**
* Add a line to given Expense Report * Add a line to given Expense Report
@ -229,56 +228,56 @@ class ExpenseReports extends DolibarrApi
* @return int * @return int
*/ */
/* /*
public function postLine($id, $request_data = null) public function postLine($id, $request_data = null)
{ {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) { if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->expensereport->fetch($id); $result = $this->expensereport->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'expensereport not found'); throw new RestException(404, 'expensereport not found');
} }
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data; $request_data = (object) $request_data;
$updateRes = $this->expensereport->addline( $updateRes = $this->expensereport->addline(
$request_data->desc, $request_data->desc,
$request_data->subprice, $request_data->subprice,
$request_data->qty, $request_data->qty,
$request_data->tva_tx, $request_data->tva_tx,
$request_data->localtax1_tx, $request_data->localtax1_tx,
$request_data->localtax2_tx, $request_data->localtax2_tx,
$request_data->fk_product, $request_data->fk_product,
$request_data->remise_percent, $request_data->remise_percent,
$request_data->info_bits, $request_data->info_bits,
$request_data->fk_remise_except, $request_data->fk_remise_except,
'HT', 'HT',
0, 0,
$request_data->date_start, $request_data->date_start,
$request_data->date_end, $request_data->date_end,
$request_data->product_type, $request_data->product_type,
$request_data->rang, $request_data->rang,
$request_data->special_code, $request_data->special_code,
$fk_parent_line, $fk_parent_line,
$request_data->fk_fournprice, $request_data->fk_fournprice,
$request_data->pa_ht, $request_data->pa_ht,
$request_data->label, $request_data->label,
$request_data->array_options, $request_data->array_options,
$request_data->fk_unit, $request_data->fk_unit,
$this->element, $this->element,
$request_data->id $request_data->id
); );
if ($updateRes > 0) { if ($updateRes > 0) {
return $updateRes; return $updateRes;
} }
return false; return false;
} }
*/ */
/** /**
* Update a line to given Expense Report * Update a line to given Expense Report
@ -292,53 +291,53 @@ class ExpenseReports extends DolibarrApi
* @return object * @return object
*/ */
/* /*
public function putLine($id, $lineid, $request_data = null) public function putLine($id, $lineid, $request_data = null)
{ {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) { if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->expensereport->fetch($id); $result = $this->expensereport->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'expensereport not found'); throw new RestException(404, 'expensereport not found');
} }
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data; $request_data = (object) $request_data;
$updateRes = $this->expensereport->updateline( $updateRes = $this->expensereport->updateline(
$lineid, $lineid,
$request_data->desc, $request_data->desc,
$request_data->subprice, $request_data->subprice,
$request_data->qty, $request_data->qty,
$request_data->remise_percent, $request_data->remise_percent,
$request_data->tva_tx, $request_data->tva_tx,
$request_data->localtax1_tx, $request_data->localtax1_tx,
$request_data->localtax2_tx, $request_data->localtax2_tx,
'HT', 'HT',
$request_data->info_bits, $request_data->info_bits,
$request_data->date_start, $request_data->date_start,
$request_data->date_end, $request_data->date_end,
$request_data->product_type, $request_data->product_type,
$request_data->fk_parent_line, $request_data->fk_parent_line,
0, 0,
$request_data->fk_fournprice, $request_data->fk_fournprice,
$request_data->pa_ht, $request_data->pa_ht,
$request_data->label, $request_data->label,
$request_data->special_code, $request_data->special_code,
$request_data->array_options, $request_data->array_options,
$request_data->fk_unit $request_data->fk_unit
); );
if ($updateRes > 0) { if ($updateRes > 0) {
$result = $this->get($id); $result = $this->get($id);
unset($result->line); unset($result->line);
return $this->_cleanObjectDatas($result); return $this->_cleanObjectDatas($result);
} }
return false; return false;
} }
*/ */
/** /**
* Delete a line of given Expense Report * Delete a line of given Expense Report
@ -351,30 +350,30 @@ class ExpenseReports extends DolibarrApi
* @return int * @return int
*/ */
/* /*
public function deleteLine($id, $lineid) public function deleteLine($id, $lineid)
{ {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) { if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->expensereport->fetch($id); $result = $this->expensereport->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'expensereport not found'); throw new RestException(404, 'expensereport not found');
} }
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
// TODO Check the lineid $lineid is a line of ojbect // TODO Check the lineid $lineid is a line of ojbect
$updateRes = $this->expensereport->deleteline($lineid); $updateRes = $this->expensereport->deleteline($lineid);
if ($updateRes == 1) { if ($updateRes == 1) {
return $this->get($id); return $this->get($id);
} }
return false; return false;
} }
*/ */
/** /**
* Update Expense Report general fields (won't touch lines of expensereport) * Update Expense Report general fields (won't touch lines of expensereport)
@ -403,12 +402,13 @@ class ExpenseReports extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
foreach ($request_data as $field => $value) { foreach ($request_data as $field => $value) {
if ($field == 'id') continue; if ($field == 'id') {
continue;
}
$this->expensereport->$field = $value; $this->expensereport->$field = $value;
} }
if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
{
return $this->get($id); return $this->get($id);
} else { } else {
throw new RestException(500, $this->expensereport->error); throw new RestException(500, $this->expensereport->error);
@ -464,31 +464,31 @@ class ExpenseReports extends DolibarrApi
* } * }
*/ */
/* /*
public function validate($id, $idwarehouse=0) public function validate($id, $idwarehouse=0)
{ {
if(! DolibarrApiAccess::$user->rights->expensereport->creer) { if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->expensereport->fetch($id); $result = $this->expensereport->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'expensereport not found'); throw new RestException(404, 'expensereport not found');
} }
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) { if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) {
throw new RestException(500, 'Error when validate expensereport'); throw new RestException(500, 'Error when validate expensereport');
} }
return array( return array(
'success' => array( 'success' => array(
'code' => 200, 'code' => 200,
'message' => 'expensereport validated' 'message' => 'expensereport validated'
) )
); );
}*/ }*/
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/** /**
@ -555,8 +555,9 @@ class ExpenseReports extends DolibarrApi
{ {
$expensereport = array(); $expensereport = array();
foreach (ExpenseReports::$FIELDS as $field) { foreach (ExpenseReports::$FIELDS as $field) {
if (!isset($data[$field])) if (!isset($data[$field])) {
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
}
$expensereport[$field] = $data[$field]; $expensereport[$field] = $data[$field];
} }
return $expensereport; return $expensereport;

File diff suppressed because it is too large Load Diff

View File

@ -111,15 +111,16 @@ class ExpenseReportIk extends CoreObject
$sql = 'SELECT rowid, label, entity, active'; $sql = 'SELECT rowid, label, entity, active';
$sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat'; $sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat';
$sql .= ' WHERE entity IN ('.getEntity('c_exp_tax_cat').')'; $sql .= ' WHERE entity IN ('.getEntity('c_exp_tax_cat').')';
if ($mode == 1) $sql .= ' AND active = 1'; if ($mode == 1) {
elseif ($mode == 2) $sql .= 'AND active = 0'; $sql .= ' AND active = 1';
} elseif ($mode == 2) {
$sql .= 'AND active = 0';
}
dol_syslog(get_called_class().'::getTaxCategories sql='.$sql, LOG_DEBUG); dol_syslog(get_called_class().'::getTaxCategories sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{ while ($obj = $db->fetch_object($resql)) {
while ($obj = $db->fetch_object($resql))
{
$categories[$obj->rowid] = $obj; $categories[$obj->rowid] = $obj;
} }
} else { } else {
@ -142,8 +143,11 @@ class ExpenseReportIk extends CoreObject
$ranges = self::getRangesByCategory($fk_c_exp_tax_cat); $ranges = self::getRangesByCategory($fk_c_exp_tax_cat);
// substract 1 because array start from 0 // substract 1 because array start from 0
if (empty($ranges) || !isset($ranges[$default_range - 1])) return false; if (empty($ranges) || !isset($ranges[$default_range - 1])) {
else return $ranges[$default_range - 1]; return false;
} else {
return $ranges[$default_range - 1];
}
} }
/** /**
@ -160,20 +164,21 @@ class ExpenseReportIk extends CoreObject
$ranges = array(); $ranges = array();
$sql = 'SELECT r.rowid FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r'; $sql = 'SELECT r.rowid FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
if ($active) $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)'; if ($active) {
$sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)';
}
$sql .= ' WHERE r.fk_c_exp_tax_cat = '.$fk_c_exp_tax_cat; $sql .= ' WHERE r.fk_c_exp_tax_cat = '.$fk_c_exp_tax_cat;
if ($active) $sql .= ' AND r.active = 1 AND c.active = 1'; if ($active) {
$sql .= ' AND r.active = 1 AND c.active = 1';
}
$sql .= ' ORDER BY r.range_ik'; $sql .= ' ORDER BY r.range_ik';
dol_syslog(get_called_class().'::getRangesByCategory sql='.$sql, LOG_DEBUG); dol_syslog(get_called_class().'::getRangesByCategory sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num > 0) if ($num > 0) {
{ while ($obj = $db->fetch_object($resql)) {
while ($obj = $db->fetch_object($resql))
{
$object = new ExpenseReportIk($db); $object = new ExpenseReportIk($db);
$object->fetch($obj->rowid); $object->fetch($obj->rowid);
@ -207,15 +212,17 @@ class ExpenseReportIk extends CoreObject
dol_syslog(get_called_class().'::getAllRanges sql='.$sql, LOG_DEBUG); dol_syslog(get_called_class().'::getAllRanges sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{ while ($obj = $db->fetch_object($resql)) {
while ($obj = $db->fetch_object($resql))
{
$ik = new ExpenseReportIk($db); $ik = new ExpenseReportIk($db);
if ($obj->fk_expense_ik > 0) $ik->fetch($obj->fk_expense_ik); if ($obj->fk_expense_ik > 0) {
$ik->fetch($obj->fk_expense_ik);
}
$obj->ik = $ik; $obj->ik = $ik;
if (!isset($ranges[$obj->fk_c_exp_tax_cat])) $ranges[$obj->fk_c_exp_tax_cat] = array('label' => $obj->label, 'active' => $obj->cat_active, 'ranges' => array()); if (!isset($ranges[$obj->fk_c_exp_tax_cat])) {
$ranges[$obj->fk_c_exp_tax_cat] = array('label' => $obj->label, 'active' => $obj->cat_active, 'ranges' => array());
}
$ranges[$obj->fk_c_exp_tax_cat]['ranges'][] = $obj; $ranges[$obj->fk_c_exp_tax_cat]['ranges'][] = $obj;
} }
} else { } else {
@ -239,14 +246,15 @@ class ExpenseReportIk extends CoreObject
$sql .= ' SELECT COUNT(*) as counted'; $sql .= ' SELECT COUNT(*) as counted';
$sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r'; $sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
$sql .= ' WHERE r.entity IN (0, '.$conf->entity.')'; $sql .= ' WHERE r.entity IN (0, '.$conf->entity.')';
if ($default_c_exp_tax_cat > 0) $sql .= ' AND r.fk_c_exp_tax_cat = '.$default_c_exp_tax_cat; if ($default_c_exp_tax_cat > 0) {
$sql .= ' AND r.fk_c_exp_tax_cat = '.$default_c_exp_tax_cat;
}
$sql .= ' GROUP BY r.fk_c_exp_tax_cat'; $sql .= ' GROUP BY r.fk_c_exp_tax_cat';
$sql .= ') as counts'; $sql .= ') as counts';
dol_syslog(get_called_class().'::getMaxRangeNumber sql='.$sql, LOG_DEBUG); dol_syslog(get_called_class().'::getMaxRangeNumber sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
return $obj->nbRange; return $obj->nbRange;
} else { } else {

View File

@ -156,18 +156,15 @@ class ExpenseReportRule extends CoreObject
$sql = 'SELECT er.rowid'; $sql = 'SELECT er.rowid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_rules er'; $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_rules er';
$sql .= ' WHERE er.entity IN (0,'.getEntity('').')'; $sql .= ' WHERE er.entity IN (0,'.getEntity('').')';
if (!empty($fk_c_type_fees)) if (!empty($fk_c_type_fees)) {
{
$sql .= ' AND er.fk_c_type_fees IN (-1, '.$fk_c_type_fees.')'; $sql .= ' AND er.fk_c_type_fees IN (-1, '.$fk_c_type_fees.')';
} }
if (!empty($date)) if (!empty($date)) {
{
$date = dol_print_date($date, '%Y-%m-%d'); $date = dol_print_date($date, '%Y-%m-%d');
$sql .= ' AND er.dates <= \''.$date.'\''; $sql .= ' AND er.dates <= \''.$date.'\'';
$sql .= ' AND er.datee >= \''.$date.'\''; $sql .= ' AND er.datee >= \''.$date.'\'';
} }
if ($fk_user > 0) if ($fk_user > 0) {
{
$sql .= ' AND (er.is_for_all = 1'; $sql .= ' AND (er.is_for_all = 1';
$sql .= ' OR er.fk_user = '.$fk_user; $sql .= ' OR er.fk_user = '.$fk_user;
$sql .= ' OR er.fk_usergroup IN (SELECT ugu.fk_usergroup FROM '.MAIN_DB_PREFIX.'usergroup_user ugu WHERE ugu.fk_user = '.$fk_user.') )'; $sql .= ' OR er.fk_usergroup IN (SELECT ugu.fk_usergroup FROM '.MAIN_DB_PREFIX.'usergroup_user ugu WHERE ugu.fk_user = '.$fk_user.') )';
@ -177,13 +174,14 @@ class ExpenseReportRule extends CoreObject
dol_syslog("ExpenseReportRule::getAllRule sql=".$sql); dol_syslog("ExpenseReportRule::getAllRule sql=".$sql);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{ while ($obj = $db->fetch_object($resql)) {
while ($obj = $db->fetch_object($resql))
{
$rule = new ExpenseReportRule($db); $rule = new ExpenseReportRule($db);
if ($rule->fetch($obj->rowid) > 0) $rules[$rule->id] = $rule; if ($rule->fetch($obj->rowid) > 0) {
else dol_print_error($db); $rules[$rule->id] = $rule;
} else {
dol_print_error($db);
}
} }
} else { } else {
dol_print_error($db); dol_print_error($db);
@ -201,11 +199,9 @@ class ExpenseReportRule extends CoreObject
{ {
include_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; include_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
if ($this->fk_usergroup > 0) if ($this->fk_usergroup > 0) {
{
$group = new UserGroup($this->db); $group = new UserGroup($this->db);
if ($group->fetch($this->fk_usergroup) > 0) if ($group->fetch($this->fk_usergroup) > 0) {
{
return $group->nom; return $group->nom;
} else { } else {
$this->error = $group->error; $this->error = $group->error;
@ -225,11 +221,9 @@ class ExpenseReportRule extends CoreObject
{ {
include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
if ($this->fk_user > 0) if ($this->fk_user > 0) {
{
$u = new User($this->db); $u = new User($this->db);
if ($u->fetch($this->fk_user) > 0) if ($u->fetch($this->fk_user) > 0) {
{
return dolGetFirstLastname($u->firstname, $u->lastname); return dolGetFirstLastname($u->firstname, $u->lastname);
} else { } else {
$this->error = $u->error; $this->error = $u->error;

View File

@ -70,20 +70,20 @@ class ExpenseReportStats extends Stats
$this->where .= ' e.entity IN ('.getEntity('expensereport').')'; $this->where .= ' e.entity IN ('.getEntity('expensereport').')';
//$this->where.= " AND entity = ".$conf->entity; //$this->where.= " AND entity = ".$conf->entity;
if ($this->socid) if ($this->socid) {
{
$this->where .= " AND e.fk_soc = ".$this->socid; $this->where .= " AND e.fk_soc = ".$this->socid;
} }
// Only me and subordinates // Only me and subordinates
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
{
$childids = $user->getAllChildIds(); $childids = $user->getAllChildIds();
$childids[] = $user->id; $childids[] = $user->id;
$this->where .= " AND e.fk_user_author IN (".(join(',', $childids)).")"; $this->where .= " AND e.fk_user_author IN (".(join(',', $childids)).")";
} }
if ($this->userid > 0) $this->where .= ' AND e.fk_user_author = '.$this->userid; if ($this->userid > 0) {
$this->where .= ' AND e.fk_user_author = '.$this->userid;
}
} }

View File

@ -119,19 +119,36 @@ class PaymentExpenseReport extends CommonObject
} }
// Clean parameters // Clean parameters
if (isset($this->fk_expensereport)) $this->fk_expensereport = trim($this->fk_expensereport); if (isset($this->fk_expensereport)) {
if (isset($this->amount)) $this->amount = trim($this->amount); $this->fk_expensereport = trim($this->fk_expensereport);
if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); }
if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); if (isset($this->amount)) {
if (isset($this->note)) $this->note = trim($this->note); $this->amount = trim($this->amount);
if (isset($this->note_public)) $this->note_public = trim($this->note_public); }
if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); if (isset($this->fk_typepayment)) {
if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); $this->fk_typepayment = trim($this->fk_typepayment);
if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); }
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
if (isset($this->note)) {
$this->note = trim($this->note);
}
if (isset($this->note_public)) {
$this->note_public = trim($this->note_public);
}
if (isset($this->fk_bank)) {
$this->fk_bank = trim($this->fk_bank);
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = trim($this->fk_user_creat);
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = trim($this->fk_user_modif);
}
$totalamount = 0; $totalamount = 0;
foreach ($this->amounts as $key => $value) // How payment is dispatch foreach ($this->amounts as $key => $value) { // How payment is dispatch
{
$newvalue = price2num($value, 'MT'); $newvalue = price2num($value, 'MT');
$this->amounts[$key] = $newvalue; $this->amounts[$key] = $newvalue;
$totalamount += $newvalue; $totalamount += $newvalue;
@ -139,13 +156,14 @@ class PaymentExpenseReport extends CommonObject
$totalamount = price2num($totalamount); $totalamount = price2num($totalamount);
// Check parameters // Check parameters
if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null if ($totalamount == 0) {
return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
}
$this->db->begin(); $this->db->begin();
if ($totalamount != 0) if ($totalamount != 0) {
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,";
$sql .= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; $sql .= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
$sql .= " VALUES ($this->fk_expensereport, '".$this->db->idate($now)."',"; $sql .= " VALUES ($this->fk_expensereport, '".$this->db->idate($now)."',";
@ -156,16 +174,14 @@ class PaymentExpenseReport extends CommonObject
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_expensereport"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_expensereport");
} else { } else {
$error++; $error++;
} }
} }
if ($totalamount != 0 && !$error) if ($totalamount != 0 && !$error) {
{
$this->amount = $totalamount; $this->amount = $totalamount;
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
@ -206,10 +222,8 @@ class PaymentExpenseReport extends CommonObject
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
@ -258,14 +272,30 @@ class PaymentExpenseReport extends CommonObject
// Clean parameters // Clean parameters
if (isset($this->fk_expensereport)) $this->fk_expensereport = trim($this->fk_expensereport); if (isset($this->fk_expensereport)) {
if (isset($this->amount)) $this->amount = trim($this->amount); $this->fk_expensereport = trim($this->fk_expensereport);
if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); }
if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); if (isset($this->amount)) {
if (isset($this->note)) $this->note = trim($this->note); $this->amount = trim($this->amount);
if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); }
if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); if (isset($this->fk_typepayment)) {
if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); $this->fk_typepayment = trim($this->fk_typepayment);
}
if (isset($this->num_payment)) {
$this->num_payment = trim($this->num_payment);
}
if (isset($this->note)) {
$this->note = trim($this->note);
}
if (isset($this->fk_bank)) {
$this->fk_bank = trim($this->fk_bank);
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = trim($this->fk_user_creat);
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = trim($this->fk_user_modif);
}
// Check parameters // Check parameters
@ -293,13 +323,13 @@ class PaymentExpenseReport extends CommonObject
dol_syslog(get_class($this)."::update", LOG_DEBUG); dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -327,18 +357,18 @@ class PaymentExpenseReport extends CommonObject
$this->db->begin(); $this->db->begin();
if (!$error) if (!$error) {
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
$sql .= " WHERE type='payment_expensereport' AND url_id=".$this->id; $sql .= " WHERE type='payment_expensereport' AND url_id=".$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
} }
if (!$error) if (!$error) {
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_expensereport"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_expensereport";
$sql .= " WHERE rowid=".$this->id; $sql .= " WHERE rowid=".$this->id;
@ -351,10 +381,8 @@ class PaymentExpenseReport extends CommonObject
} }
// Commit or rollback // Commit or rollback
if ($error) if ($error) {
{ foreach ($this->errors as $errmsg) {
foreach ($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg); $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
} }
@ -396,8 +424,7 @@ class PaymentExpenseReport extends CommonObject
$result = $object->create($user); $result = $object->create($user);
// Other options // Other options
if ($result < 0) if ($result < 0) {
{
$this->error = $object->error; $this->error = $object->error;
$error++; $error++;
} }
@ -405,8 +432,7 @@ class PaymentExpenseReport extends CommonObject
unset($object->context['createfromclone']); unset($object->context['createfromclone']);
// End // End
if (!$error) if (!$error) {
{
$this->db->commit(); $this->db->commit();
return $object->id; return $object->id;
} else { } else {
@ -487,8 +513,7 @@ class PaymentExpenseReport extends CommonObject
$error = 0; $error = 0;
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{
include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$acc = new Account($this->db); $acc = new Account($this->db);
@ -497,7 +522,9 @@ class PaymentExpenseReport extends CommonObject
//Fix me field //Fix me field
$total = $this->amount; $total = $this->amount;
if ($mode == 'payment_expensereport') $amount = $total; if ($mode == 'payment_expensereport') {
$amount = $total;
}
// Insert payment into llx_bank // Insert payment into llx_bank
$bank_line_id = $acc->addline( $bank_line_id = $acc->addline(
@ -514,35 +541,30 @@ class PaymentExpenseReport extends CommonObject
// Update fk_bank in llx_paiement. // Update fk_bank in llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire // On connait ainsi le paiement qui a genere l'ecriture bancaire
if ($bank_line_id > 0) if ($bank_line_id > 0) {
{
$result = $this->update_fk_bank($bank_line_id); $result = $this->update_fk_bank($bank_line_id);
if ($result <= 0) if ($result <= 0) {
{
$error++; $error++;
dol_print_error($this->db); dol_print_error($this->db);
} }
// Add link 'payment', 'payment_supplier', 'payment_expensereport' in bank_url between payment and bank transaction // Add link 'payment', 'payment_supplier', 'payment_expensereport' in bank_url between payment and bank transaction
$url = ''; $url = '';
if ($mode == 'payment_expensereport') $url = DOL_URL_ROOT.'/expensereport/payment/card.php?rowid='; if ($mode == 'payment_expensereport') {
if ($url) $url = DOL_URL_ROOT.'/expensereport/payment/card.php?rowid=';
{ }
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
if ($result <= 0) if ($result <= 0) {
{
$error++; $error++;
dol_print_error($this->db); dol_print_error($this->db);
} }
} }
// Add link 'user' in bank_url between user and bank transaction // Add link 'user' in bank_url between user and bank transaction
if (!$error) if (!$error) {
{ foreach ($this->amounts as $key => $value) { // We should have always same user but we loop in case of.
foreach ($this->amounts as $key => $value) // We should have always same user but we loop in case of. if ($mode == 'payment_expensereport') {
{
if ($mode == 'payment_expensereport')
{
$fuser = new User($this->db); $fuser = new User($this->db);
$fuser->fetch($key); $fuser->fetch($key);
@ -553,8 +575,7 @@ class PaymentExpenseReport extends CommonObject
$fuser->getFullName($langs), $fuser->getFullName($langs),
'user' 'user'
); );
if ($result <= 0) if ($result <= 0) {
{
$this->error = $this->db->lasterror(); $this->error = $this->db->lasterror();
dol_syslog(get_class($this).'::addPaymentToBank '.$this->error); dol_syslog(get_class($this).'::addPaymentToBank '.$this->error);
$error++; $error++;
@ -568,8 +589,7 @@ class PaymentExpenseReport extends CommonObject
} }
} }
if (!$error) if (!$error) {
{
return 1; return 1;
} else { } else {
return -1; return -1;
@ -591,8 +611,7 @@ class PaymentExpenseReport extends CommonObject
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
return 1; return 1;
} else { } else {
$this->error = $this->db->error(); $this->error = $this->db->error();
@ -613,17 +632,24 @@ class PaymentExpenseReport extends CommonObject
$result = ''; $result = '';
if (empty($this->ref)) $this->ref = $this->label; if (empty($this->ref)) {
$this->ref = $this->label;
}
$label = $langs->trans("ShowPayment").': '.$this->ref; $label = $langs->trans("ShowPayment").': '.$this->ref;
if (!empty($this->id)) if (!empty($this->id)) {
{
$link = '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $link = '<a href="'.DOL_URL_ROOT.'/expensereport/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>'; $linkend = '</a>';
if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); if ($withpicto) {
if ($withpicto && $withpicto != 2) $result .= ' '; $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; }
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
if ($withpicto != 2) {
$result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
}
} }
return $result; return $result;
@ -644,20 +670,16 @@ class PaymentExpenseReport extends CommonObject
dol_syslog(get_class($this).'::info', LOG_DEBUG); dol_syslog(get_class($this).'::info', LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{ if ($this->db->num_rows($result)) {
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$this->id = $obj->rowid; $this->id = $obj->rowid;
if ($obj->fk_user_creat) if ($obj->fk_user_creat) {
{
$cuser = new User($this->db); $cuser = new User($this->db);
$cuser->fetch($obj->fk_user_creat); $cuser->fetch($obj->fk_user_creat);
$this->user_creation = $cuser; $this->user_creation = $cuser;
} }
if ($obj->fk_user_modif) if ($obj->fk_user_modif) {
{
$muser = new User($this->db); $muser = new User($this->db);
$muser->fetch($obj->fk_user_modif); $muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser; $this->user_modification = $muser;

View File

@ -45,7 +45,9 @@ $confirm = GETPOST('confirm', 'alpha');
$childids = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $result = restrictedArea($user, 'expensereport', $id, 'expensereport');
@ -54,17 +56,22 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "ASC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "position_name"; $sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "position_name";
}
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
if (!$object->fetch($id, $ref) > 0) if (!$object->fetch($id, $ref) > 0) {
{
dol_print_error($db); dol_print_error($db);
} }
@ -74,14 +81,16 @@ $modulepart = 'trip';
// Load object // Load object
//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($object->id > 0) if ($object->id > 0) {
{
// Check current user can read this expense report // Check current user can read this expense report
$canread = 0; $canread = 0;
if (!empty($user->rights->expensereport->readall)) $canread = 1; if (!empty($user->rights->expensereport->readall)) {
if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; $canread = 1;
if (!$canread) }
{ if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -104,8 +113,7 @@ $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Documents");
$helpurl = "EN:Module_Expense_Reports"; $helpurl = "EN:Module_Expense_Reports";
llxHeader("", $title, $helpurl); llxHeader("", $title, $helpurl);
if ($object->id) if ($object->id) {
{
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$head = expensereport_prepare_head($object); $head = expensereport_prepare_head($object);
@ -124,8 +132,7 @@ if ($object->id)
// Build file list // Build file list
$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
$totalsize = 0; $totalsize = 0;
foreach ($filearray as $key => $file) foreach ($filearray as $key => $file) {
{
$totalsize += $file['size']; $totalsize += $file['size'];
} }

View File

@ -42,19 +42,27 @@ $langs->loadLangs(array('companies', 'users', 'trips'));
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', '', ''); $result = restrictedArea($user, 'expensereport', '', '');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha'); $sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "d.date_create"; $sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.date_create";
}
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
@ -80,8 +88,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensere
$sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id"; $sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id";
// RESTRICT RIGHTS // RESTRICT RIGHTS
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
&& (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
{
$childids = $user->getAllChildIds(); $childids = $user->getAllChildIds();
$childids[] = $user->id; $childids[] = $user->id;
$sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
@ -90,12 +97,10 @@ if (empty($user->rights->expensereport->readall) && empty($user->rights->expense
$sql .= " GROUP BY tf.code, tf.label"; $sql .= " GROUP BY tf.code, tf.label";
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$num = $db->num_rows($result); $num = $db->num_rows($result);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num) {
{
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$somme[$objp->code] = $objp->km; $somme[$objp->code] = $objp->km;
@ -123,13 +128,11 @@ print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
print "</tr>\n"; print "</tr>\n";
$listoftype = $tripandexpense_static->listOfTypes(); $listoftype = $tripandexpense_static->listOfTypes();
foreach ($listoftype as $code => $label) foreach ($listoftype as $code => $label) {
{
$dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0));
} }
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax) {
{
print '<tr><td class="center" colspan="4">'; print '<tr><td class="center" colspan="4">';
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
@ -168,25 +171,29 @@ $langs->load("boxes");
$sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,"; $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,";
$sql .= " d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as status"; $sql .= " d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as status";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u";
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->socid) {
$sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
}
$sql .= " WHERE u.rowid = d.fk_user_author"; $sql .= " WHERE u.rowid = d.fk_user_author";
// RESTRICT RIGHTS // RESTRICT RIGHTS
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
&& (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
{
$childids = $user->getAllChildIds(); $childids = $user->getAllChildIds();
$childids[] = $user->id; $childids[] = $user->id;
$sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
} }
$sql .= ' AND d.entity IN ('.getEntity('expensereport').')'; $sql .= ' AND d.entity IN ('.getEntity('expensereport').')';
if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; if (!$user->rights->societe->client->voir && !$user->socid) {
if ($socid) $sql .= " AND d.fk_user_author = ".$socid; $sql .= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
}
if ($socid) {
$sql .= " AND d.fk_user_author = ".$socid;
}
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($max, 0); $sql .= $db->plimit($max, 0);
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result) {
{
$var = false; $var = false;
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -201,14 +208,12 @@ if ($result)
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>'; print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th>&nbsp;</th>'; print '<th>&nbsp;</th>';
print '</tr>'; print '</tr>';
if ($num) if ($num) {
{
$total_ttc = $totalam = $total = 0; $total_ttc = $totalam = $total = 0;
$expensereportstatic = new ExpenseReport($db); $expensereportstatic = new ExpenseReport($db);
$userstatic = new User($db); $userstatic = new User($db);
while ($i < $num && $i < $max) while ($i < $num && $i < $max) {
{
$obj = $db->fetch_object($result); $obj = $db->fetch_object($result);
$expensereportstatic->id = $obj->rowid; $expensereportstatic->id = $obj->rowid;
@ -241,7 +246,9 @@ if ($result)
print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>'; print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
} }
print '</table></div><br>'; print '</table></div><br>';
} else dol_print_error($db); } else {
dol_print_error($db);
}
print '</div></div></div>'; print '</div></div></div>';

View File

@ -37,23 +37,26 @@ $ref = GETPOST('ref', 'alpha');
$childids = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $result = restrictedArea($user, 'expensereport', $id, 'expensereport');
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
if (!$object->fetch($id, $ref) > 0) if (!$object->fetch($id, $ref) > 0) {
{
dol_print_error($db); dol_print_error($db);
} }
if ($object->id > 0) if ($object->id > 0) {
{
// Check current user can read this expense report // Check current user can read this expense report
$canread = 0; $canread = 0;
if (!empty($user->rights->expensereport->readall)) $canread = 1; if (!empty($user->rights->expensereport->readall)) {
if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; $canread = 1;
if (!$canread) }
{ if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -69,8 +72,7 @@ $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Info");
$helpurl = "EN:Module_Expense_Reports"; $helpurl = "EN:Module_Expense_Reports";
llxHeader("", $title, $helpurl); llxHeader("", $title, $helpurl);
if ($id > 0 || !empty($ref)) if ($id > 0 || !empty($ref)) {
{
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
$object->fetch($id, $ref); $object->fetch($id, $ref);
$object->info($object->id); $object->info($object->id);

View File

@ -54,18 +54,24 @@ $childids = $user->getAllChildIds(1);
// Security check // Security check
$socid = GETPOST('socid', 'int'); $socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', '', ''); $result = restrictedArea($user, 'expensereport', '', '');
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
// If we are on the view of a specific user // If we are on the view of a specific user
if ($id > 0) if ($id > 0) {
{
$canread = 0; $canread = 0;
if ($id == $user->id) $canread = 1; if ($id == $user->id) {
if (!empty($user->rights->expensereport->readall)) $canread = 1; $canread = 1;
if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) $canread = 1; }
if (!$canread) if (!empty($user->rights->expensereport->readall)) {
{ $canread = 1;
}
if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -78,12 +84,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma'); $sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page; $offset = $limit * $page;
$pageprev = $page - 1; $pageprev = $page - 1;
$pagenext = $page + 1; $pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC"; if (!$sortorder) {
if (!$sortfield) $sortfield = "d.date_debut"; $sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.date_debut";
}
$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
@ -101,8 +113,12 @@ $month_end = GETPOST("month_end", "int");
$year_end = GETPOST("year_end", "int"); $year_end = GETPOST("year_end", "int");
$optioncss = GETPOST('optioncss', 'alpha'); $optioncss = GETPOST('optioncss', 'alpha');
if ($search_status == '') $search_status = -1; if ($search_status == '') {
if ($search_user == '') $search_user = -1; $search_status = -1;
}
if ($search_user == '') {
$search_user = -1;
}
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
@ -123,7 +139,9 @@ $fieldstosearchall = array(
'u.firstname'=>"Firstname", 'u.firstname'=>"Firstname",
'u.login'=>"Login", 'u.login'=>"Login",
); );
if (empty($user->socid)) $fieldstosearchall["d.note_private"] = "NotePrivate"; if (empty($user->socid)) {
$fieldstosearchall["d.note_private"] = "NotePrivate";
}
$arrayfields = array( $arrayfields = array(
'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
@ -151,21 +169,25 @@ $objectuser = new User($db);
* Actions * Actions
*/ */
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } if (GETPOST('cancel', 'alpha')) {
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } $action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid'=>$socid); $parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
if (empty($reshook)) if (empty($reshook)) {
{
// Selection of new fields // Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
{
$search_ref = ""; $search_ref = "";
$search_user = ""; $search_user = "";
$search_amount_ht = ""; $search_amount_ht = "";
@ -181,8 +203,7 @@ if (empty($reshook))
$search_array_options = array(); $search_array_options = array();
} }
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
{
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
} }
@ -216,8 +237,7 @@ $min_year = 10;
// Get current user id // Get current user id
$user_id = $user->id; $user_id = $user->id;
if ($id > 0) if ($id > 0) {
{
// Charge utilisateur edite // Charge utilisateur edite
$fuser->fetch($id, '', '', 1); $fuser->fetch($id, '', '', 1);
$fuser->getrights(); $fuser->getrights();
@ -231,35 +251,50 @@ $sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_v
$sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo"; $sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo";
// Add fields from extrafields // Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) { if (!empty($extrafields->attributes[$object->table_element]['label'])) {
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
}
} }
// Add fields from hooks // Add fields from hooks
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint; $sql .= $hookmanager->resPrint;
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d";
if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)"; if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
}
$sql .= ", ".MAIN_DB_PREFIX."user as u"; $sql .= ", ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")"; $sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
// Search all // Search all
if (!empty($sall)) $sql .= natural_search(array_keys($fieldstosearchall), $sall); if (!empty($sall)) {
$sql .= natural_search(array_keys($fieldstosearchall), $sall);
}
// Ref // Ref
if (!empty($search_ref)) $sql .= natural_search('d.ref', $search_ref); if (!empty($search_ref)) {
$sql .= natural_search('d.ref', $search_ref);
}
// Date Start // Date Start
$sql .= dolSqlDateFilter("d.date_debut", $day_start, $month_start, $year_start); $sql .= dolSqlDateFilter("d.date_debut", $day_start, $month_start, $year_start);
// Date End // Date End
$sql .= dolSqlDateFilter("d.date_fin", $day_end, $month_end, $year_end); $sql .= dolSqlDateFilter("d.date_fin", $day_end, $month_end, $year_end);
if ($search_amount_ht != '') $sql .= natural_search('d.total_ht', $search_amount_ht, 1); if ($search_amount_ht != '') {
if ($search_amount_ttc != '') $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1); $sql .= natural_search('d.total_ht', $search_amount_ht, 1);
}
if ($search_amount_ttc != '') {
$sql .= natural_search('d.total_ttc', $search_amount_ttc, 1);
}
// User // User
if ($search_user != '' && $search_user >= 0) $sql .= " AND u.rowid = '".$db->escape($search_user)."'"; if ($search_user != '' && $search_user >= 0) {
$sql .= " AND u.rowid = '".$db->escape($search_user)."'";
}
// Status // Status
if ($search_status != '' && $search_status >= 0) $sql .= " AND d.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; if ($search_status != '' && $search_status >= 0) {
$sql .= " AND d.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
}
// RESTRICT RIGHTS // RESTRICT RIGHTS
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
&& (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) {
{
$sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
} }
// Add where from extra fields // Add where from extra fields
@ -273,12 +308,10 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records // Count total nb of records
$nbtotalofrecords = ''; $nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
{
$result = $db->query($sql); $result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result); $nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
{
$page = 0; $page = 0;
$offset = 0; $offset = 0;
} }
@ -288,22 +321,39 @@ $sql .= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$arrayofselected = is_array($toselect) ? $toselect : array(); $arrayofselected = is_array($toselect) ? $toselect : array();
$param = ''; $param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); $param .= '&contextpage='.urlencode($contextpage);
if ($sall) $param .= "&sall=".urlencode($sall); }
if ($search_ref) $param .= "&search_ref=".urlencode($search_ref); if ($limit > 0 && $limit != $conf->liste_limit) {
if ($search_user) $param .= "&search_user=".urlencode($search_user); $param .= '&limit='.urlencode($limit);
if ($search_amount_ht) $param .= "&search_amount_ht=".urlencode($search_amount_ht); }
if ($search_amount_ttc) $param .= "&search_amount_ttc=".urlencode($search_amount_ttc); if ($sall) {
if ($search_status >= 0) $param .= "&search_status=".urlencode($search_status); $param .= "&sall=".urlencode($sall);
if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); }
if ($search_ref) {
$param .= "&search_ref=".urlencode($search_ref);
}
if ($search_user) {
$param .= "&search_user=".urlencode($search_user);
}
if ($search_amount_ht) {
$param .= "&search_amount_ht=".urlencode($search_amount_ht);
}
if ($search_amount_ttc) {
$param .= "&search_amount_ttc=".urlencode($search_amount_ttc);
}
if ($search_status >= 0) {
$param .= "&search_status=".urlencode($search_status);
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
}
// Add $param from extra fields // Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@ -313,23 +363,30 @@ if ($resql)
'builddoc'=>$langs->trans("PDFMerge"), 'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"), 'presend'=>$langs->trans("SendByMail"),
); );
if ($user->rights->expensereport->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete"); if ($user->rights->expensereport->supprimer) {
if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
}
if (in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
// Lines of title fields // Lines of title fields
print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n"; print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">'; print '<input type="hidden" name="action" value="'.($action == 'edit' ? 'update' : 'list').'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">'; if ($id > 0) {
print '<input type="hidden" name="id" value="'.$id.'">';
}
if ($id > 0) // For user tab if ($id > 0) { // For user tab
{
$title = $langs->trans("User"); $title = $langs->trans("User");
$linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$head = user_prepare_head($fuser); $head = user_prepare_head($fuser);
@ -340,8 +397,7 @@ if ($resql)
print dol_get_fiche_end(); print dol_get_fiche_end();
if ($action != 'edit') if ($action != 'edit') {
{
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$childids = $user->getAllChildIds(1); $childids = $user->getAllChildIds(1);
@ -366,7 +422,9 @@ if ($resql)
$title = $langs->trans("ListTripsAndExpenses"); $title = $langs->trans("ListTripsAndExpenses");
$url = DOL_URL_ROOT.'/expensereport/card.php?action=create'; $url = DOL_URL_ROOT.'/expensereport/card.php?action=create';
if (!empty($socid)) $url .= '&socid='.$socid; if (!empty($socid)) {
$url .= '&socid='.$socid;
}
$newcardbutton = dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->rights->expensereport->creer); $newcardbutton = dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->rights->expensereport->creer);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1);
@ -378,9 +436,10 @@ if ($resql)
$trackid = 'exp'.$object->id; $trackid = 'exp'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($sall) if ($sall) {
{ foreach ($fieldstosearchall as $key => $val) {
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); $fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>'; print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
} }
@ -388,11 +447,13 @@ if ($resql)
$parameters = array(); $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; if (empty($reshook)) {
else $moreforfilter = $hookmanager->resPrint; $moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if (!empty($moreforfilter)) if (!empty($moreforfilter)) {
{
print '<div class="liste_titre liste_titre_bydiv centpercent">'; print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter; print $moreforfilter;
print '</div>'; print '</div>';
@ -407,17 +468,14 @@ if ($resql)
// Filters // Filters
print '<tr class="liste_titre_filter">'; print '<tr class="liste_titre_filter">';
if (!empty($arrayfields['d.ref']['checked'])) if (!empty($arrayfields['d.ref']['checked'])) {
{
print '<td class="liste_titre" align="left">'; print '<td class="liste_titre" align="left">';
print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">'; print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
print '</td>'; print '</td>';
} }
// User // User
if (!empty($arrayfields['user']['checked'])) if (!empty($arrayfields['user']['checked'])) {
{ if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) {
if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous)
{
print '<td class="liste_titre maxwidthonspartphone" align="left">'; print '<td class="liste_titre maxwidthonspartphone" align="left">';
print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
print '</td>'; print '</td>';
@ -426,8 +484,7 @@ if ($resql)
} }
} }
// Date start // Date start
if (!empty($arrayfields['d.date_debut']['checked'])) if (!empty($arrayfields['d.date_debut']['checked'])) {
{
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat width25" type="text" maxlength="2" name="day_start" value="'.dol_escape_htmltag($day_start).'">'; print '<input class="flat width25" type="text" maxlength="2" name="day_start" value="'.dol_escape_htmltag($day_start).'">';
@ -438,8 +495,7 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Date end // Date end
if (!empty($arrayfields['d.date_fin']['checked'])) if (!empty($arrayfields['d.date_fin']['checked'])) {
{
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
print '<input class="flat width25" type="text" maxlength="2" name="day_end" value="'.dol_escape_htmltag($day_end).'">'; print '<input class="flat width25" type="text" maxlength="2" name="day_end" value="'.dol_escape_htmltag($day_end).'">';
@ -449,33 +505,28 @@ if ($resql)
print '</td>'; print '</td>';
} }
// Date valid // Date valid
if (!empty($arrayfields['d.date_valid']['checked'])) if (!empty($arrayfields['d.date_valid']['checked'])) {
{
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
//print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">'; //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
//$formother->select_year($year_end,'year_end',1, $min_year, $max_year); //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
print '</td>'; print '</td>';
} }
// Date approve // Date approve
if (!empty($arrayfields['d.date_approve']['checked'])) if (!empty($arrayfields['d.date_approve']['checked'])) {
{
print '<td class="liste_titre" align="center">'; print '<td class="liste_titre" align="center">';
//print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">'; //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
//$formother->select_year($year_end,'year_end',1, $min_year, $max_year); //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
print '</td>'; print '</td>';
} }
// Amount with no tax // Amount with no tax
if (!empty($arrayfields['d.total_ht']['checked'])) if (!empty($arrayfields['d.total_ht']['checked'])) {
{
print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>'; print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
} }
if (!empty($arrayfields['d.total_vat']['checked'])) if (!empty($arrayfields['d.total_vat']['checked'])) {
{
print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>'; print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>';
} }
// Amount with all taxes // Amount with all taxes
if (!empty($arrayfields['d.total_ttc']['checked'])) if (!empty($arrayfields['d.total_ttc']['checked'])) {
{
print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>'; print '<td class="liste_titre right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
} }
// Extra fields // Extra fields
@ -486,20 +537,17 @@ if ($resql)
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Date creation // Date creation
if (!empty($arrayfields['d.date_create']['checked'])) if (!empty($arrayfields['d.date_create']['checked'])) {
{
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '</td>'; print '</td>';
} }
// Date modification // Date modification
if (!empty($arrayfields['d.tms']['checked'])) if (!empty($arrayfields['d.tms']['checked'])) {
{
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '</td>'; print '</td>';
} }
// Status // Status
if (!empty($arrayfields['d.fk_statut']['checked'])) if (!empty($arrayfields['d.fk_statut']['checked'])) {
{
print '<td class="liste_titre right">'; print '<td class="liste_titre right">';
$formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1); $formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1);
print '</td>'; print '</td>';
@ -513,24 +561,48 @@ if ($resql)
print "</tr>\n"; print "</tr>\n";
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
if (!empty($arrayfields['d.ref']['checked'])) print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['d.ref']['checked'])) {
if (!empty($arrayfields['user']['checked'])) print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder); print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['d.date_debut']['checked'])) print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, 'align="center"', $sortfield, $sortorder); }
if (!empty($arrayfields['d.date_fin']['checked'])) print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, 'align="center"', $sortfield, $sortorder); if (!empty($arrayfields['user']['checked'])) {
if (!empty($arrayfields['d.date_valid']['checked'])) print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder);
if (!empty($arrayfields['d.date_approve']['checked'])) print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, 'align="center"', $sortfield, $sortorder); }
if (!empty($arrayfields['d.total_ht']['checked'])) print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); if (!empty($arrayfields['d.date_debut']['checked'])) {
if (!empty($arrayfields['d.total_vat']['checked'])) print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, 'align="center"', $sortfield, $sortorder);
if (!empty($arrayfields['d.total_ttc']['checked'])) print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, 'align="right"', $sortfield, $sortorder); }
if (!empty($arrayfields['d.date_fin']['checked'])) {
print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.date_valid']['checked'])) {
print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.date_approve']['checked'])) {
print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, 'align="center"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.total_ht']['checked'])) {
print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.total_vat']['checked'])) {
print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, 'align="right"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.total_ttc']['checked'])) {
print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, 'align="right"', $sortfield, $sortorder);
}
// Extra fields // Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields // Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint; print $hookmanager->resPrint;
if (!empty($arrayfields['d.date_create']['checked'])) print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); if (!empty($arrayfields['d.date_create']['checked'])) {
if (!empty($arrayfields['d.tms']['checked'])) print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
if (!empty($arrayfields['d.fk_statut']['checked'])) print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder); }
if (!empty($arrayfields['d.tms']['checked'])) {
print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
}
if (!empty($arrayfields['d.fk_statut']['checked'])) {
print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder);
}
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
@ -541,12 +613,10 @@ if ($resql)
$expensereportstatic = new ExpenseReport($db); $expensereportstatic = new ExpenseReport($db);
$usertmp = new User($db); $usertmp = new User($db);
if ($num > 0) if ($num > 0) {
{
$i = 0; $i = 0;
$totalarray = array(); $totalarray = array();
while ($i < min($num, $limit)) while ($i < min($num, $limit)) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$expensereportstatic->id = $obj->rowid; $expensereportstatic->id = $obj->rowid;
@ -572,10 +642,13 @@ if ($resql)
print '</td>'; print '</td>';
// Warning late icon and note // Warning late icon and note
print '<td class="nobordernopadding nowrap">'; print '<td class="nobordernopadding nowrap">';
if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) print img_warning($langs->trans("Late")); if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) {
if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) print img_warning($langs->trans("Late")); print img_warning($langs->trans("Late"));
if (!empty($obj->note_private) || !empty($obj->note_public)) }
{ if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) {
print img_warning($langs->trans("Late"));
}
if (!empty($obj->note_private) || !empty($obj->note_public)) {
print ' <span class="note">'; print ' <span class="note">';
print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>'; print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
print '</span>'; print '</span>';
@ -589,7 +662,9 @@ if ($resql)
print '</td>'; print '</td>';
print '</tr></table>'; print '</tr></table>';
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// User // User
if (!empty($arrayfields['user']['checked'])) { if (!empty($arrayfields['user']['checked'])) {
@ -603,50 +678,69 @@ if ($resql)
$usertmp->email = $obj->email; $usertmp->email = $obj->email;
print $usertmp->getNomUrl(-1); print $usertmp->getNomUrl(-1);
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Start date // Start date
if (!empty($arrayfields['d.date_debut']['checked'])) { if (!empty($arrayfields['d.date_debut']['checked'])) {
print '<td class="center">'.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').'</td>'; print '<td class="center">'.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// End date // End date
if (!empty($arrayfields['d.date_fin']['checked'])) { if (!empty($arrayfields['d.date_fin']['checked'])) {
print '<td class="center">'.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').'</td>'; print '<td class="center">'.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Date validation // Date validation
if (!empty($arrayfields['d.date_valid']['checked'])) { if (!empty($arrayfields['d.date_valid']['checked'])) {
print '<td class="center">'.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').'</td>'; print '<td class="center">'.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Date approval // Date approval
if (!empty($arrayfields['d.date_approve']['checked'])) { if (!empty($arrayfields['d.date_approve']['checked'])) {
print '<td class="center">'.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').'</td>'; print '<td class="center">'.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Amount HT // Amount HT
if (!empty($arrayfields['d.total_ht']['checked'])) if (!empty($arrayfields['d.total_ht']['checked'])) {
{
print '<td class="right">'.price($obj->total_ht)."</td>\n"; print '<td class="right">'.price($obj->total_ht)."</td>\n";
if (!$i) $totalarray['nbfield']++; if (!$i) {
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht'; $totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht';
}
$totalarray['val']['d.total_ht'] += $obj->total_ht; $totalarray['val']['d.total_ht'] += $obj->total_ht;
} }
// Amount VAT // Amount VAT
if (!empty($arrayfields['d.total_vat']['checked'])) if (!empty($arrayfields['d.total_vat']['checked'])) {
{
print '<td class="right">'.price($obj->total_tva)."</td>\n"; print '<td class="right">'.price($obj->total_tva)."</td>\n";
if (!$i) $totalarray['nbfield']++; if (!$i) {
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva'; $totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva';
}
$totalarray['val']['d.total_tva'] += $obj->total_tva; $totalarray['val']['d.total_tva'] += $obj->total_tva;
} }
// Amount TTC // Amount TTC
if (!empty($arrayfields['d.total_ttc']['checked'])) if (!empty($arrayfields['d.total_ttc']['checked'])) {
{
print '<td class="right">'.price($obj->total_ttc)."</td>\n"; print '<td class="right">'.price($obj->total_ttc)."</td>\n";
if (!$i) $totalarray['nbfield']++; if (!$i) {
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc'; $totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc';
}
$totalarray['val']['d.total_ttc'] += $obj->total_ttc; $totalarray['val']['d.total_ttc'] += $obj->total_ttc;
} }
@ -658,37 +752,43 @@ if ($resql)
print $hookmanager->resPrint; print $hookmanager->resPrint;
// Date creation // Date creation
if (!empty($arrayfields['d.date_create']['checked'])) if (!empty($arrayfields['d.date_create']['checked'])) {
{
print '<td class="nowrap center">'; print '<td class="nowrap center">';
print dol_print_date($db->jdate($obj->date_create), 'dayhour'); print dol_print_date($db->jdate($obj->date_create), 'dayhour');
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Date modification // Date modification
if (!empty($arrayfields['d.tms']['checked'])) if (!empty($arrayfields['d.tms']['checked'])) {
{
print '<td class="nowrap center">'; print '<td class="nowrap center">';
print dol_print_date($db->jdate($obj->date_modif), 'dayhour'); print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Status // Status
if (!empty($arrayfields['d.fk_statut']['checked'])) if (!empty($arrayfields['d.fk_statut']['checked'])) {
{
print '<td class="nowrap right">'.$expensereportstatic->getLibStatut(5).'</td>'; print '<td class="nowrap right">'.$expensereportstatic->getLibStatut(5).'</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
} }
// Action column // Action column
print '<td class="nowrap center">'; print '<td class="nowrap center">';
if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
{
$selected = 0; $selected = 0;
if (in_array($obj->rowid, $arrayofselected)) $selected = 1; if (in_array($obj->rowid, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>'; print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
} }
print '</td>'; print '</td>';
if (!$i) $totalarray['nbfield']++; if (!$i) {
$totalarray['nbfield']++;
}
print "</tr>\n"; print "</tr>\n";
@ -700,7 +800,11 @@ if ($resql)
} }
} else { } else {
$colspan = 1; $colspan = 1;
foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>'; print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
} }
@ -718,10 +822,11 @@ if ($resql)
print '</form>'."\n"; print '</form>'."\n";
if (empty($id)) if (empty($id)) {
{
$hidegeneratedfilelistifempty = 1; $hidegeneratedfilelistifempty = 1;
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
$hidegeneratedfilelistifempty = 0;
}
// Show list of available documents // Show list of available documents
$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;

View File

@ -41,26 +41,29 @@ $childids = $user->getAllChildIds(1);
// Security check // Security check
$socid = 0; $socid = 0;
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $result = restrictedArea($user, 'expensereport', $id, 'expensereport');
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
if (!$object->fetch($id, $ref) > 0) if (!$object->fetch($id, $ref) > 0) {
{
dol_print_error($db); dol_print_error($db);
} }
$permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php
if ($object->id > 0) if ($object->id > 0) {
{
// Check current user can read this expense report // Check current user can read this expense report
$canread = 0; $canread = 0;
if (!empty($user->rights->expensereport->readall)) $canread = 1; if (!empty($user->rights->expensereport->readall)) {
if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; $canread = 1;
if (!$canread) }
{ if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden(); accessforbidden();
} }
} }
@ -82,8 +85,7 @@ llxHeader("", $title, $helpurl);
$form = new Form($db); $form = new Form($db);
if ($id > 0 || !empty($ref)) if ($id > 0 || !empty($ref)) {
{
$object = new ExpenseReport($db); $object = new ExpenseReport($db);
$object->fetch($id, $ref); $object->fetch($id, $ref);
$object->info($object->id); $object->info($object->id);

View File

@ -26,7 +26,9 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; if (!empty($conf->banque->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
}
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('bills', 'banks', 'companies', 'trips')); $langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
@ -36,16 +38,19 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm'); $confirm = GETPOST('confirm');
// Security check // Security check
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
// TODO Add rule to restrict access payment // TODO Add rule to restrict access payment
//$result = restrictedArea($user, 'facture', $id,''); //$result = restrictedArea($user, 'facture', $id,'');
$object = new PaymentExpenseReport($db); $object = new PaymentExpenseReport($db);
if ($id > 0) if ($id > 0) {
{
$result = $object->fetch($id); $result = $object->fetch($id);
if (!$result) dol_print_error($db, 'Failed to get payment id '.$id); if (!$result) {
dol_print_error($db, 'Failed to get payment id '.$id);
}
} }
@ -54,13 +59,11 @@ if ($id > 0)
*/ */
// Delete payment // Delete payment
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) {
{
$db->begin(); $db->begin();
$result = $object->delete($user); $result = $object->delete($user);
if ($result > 0) if ($result > 0) {
{
$db->commit(); $db->commit();
header("Location: ".DOL_URL_ROOT."/expensereport/index.php"); header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
exit; exit;
@ -86,8 +89,7 @@ print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment")
/* /*
* Confirm deleting of the payment * Confirm deleting of the payment
*/ */
if ($action == 'delete') if ($action == 'delete') {
{
print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2); print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
} }
@ -118,14 +120,11 @@ print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2
$disable_delete = 0; $disable_delete = 0;
// Bank account // Bank account
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{ if ($object->bank_account) {
if ($object->bank_account)
{
$bankline = new AccountLine($db); $bankline = new AccountLine($db);
$bankline->fetch($object->bank_line); $bankline->fetch($object->bank_line);
if ($bankline->rappro) if ($bankline->rappro) {
{
$disable_delete = 1; $disable_delete = 1;
$title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment")); $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
} }
@ -167,8 +166,7 @@ $sql .= ' AND per.rowid = '.$id;
dol_syslog("expensereport/payment/card.php", LOG_DEBUG); dol_syslog("expensereport/payment/card.php", LOG_DEBUG);
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
$i = 0; $i = 0;
@ -186,10 +184,8 @@ if ($resql)
print '<td class="center">'.$langs->trans('Status').'</td>'; print '<td class="center">'.$langs->trans('Status').'</td>';
print "</tr>\n"; print "</tr>\n";
if ($num > 0) if ($num > 0) {
{ while ($i < $num) {
while ($i < $num)
{
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -216,8 +212,7 @@ if ($resql)
print "</tr>\n"; print "</tr>\n";
if ($objp->paid == 1) // If at least one invoice is paid, disable delete if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
{
$disable_delete = 2; $disable_delete = 2;
$title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid"); $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
} }
@ -242,12 +237,9 @@ if ($resql)
*/ */
print '<div class="tabsAction">'; print '<div class="tabsAction">';
if ($action == '') if ($action == '') {
{ if ($user->rights->expensereport->supprimer) {
if ($user->rights->expensereport->supprimer) if (!$disable_delete) {
{
if (!$disable_delete)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
} else { } else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($title_button).'">'.$langs->trans('Delete').'</a>'; print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($title_button).'">'.$langs->trans('Delete').'</a>';

View File

@ -39,8 +39,7 @@ $accountid = GETPOST('accountid', 'int');
// Security check // Security check
$socid = 0; $socid = 0;
if ($user->socid > 0) if ($user->socid > 0) {
{
$socid = $user->socid; $socid = $user->socid;
} }
@ -49,12 +48,10 @@ if ($user->socid > 0)
* Actions * Actions
*/ */
if ($action == 'add_payment') if ($action == 'add_payment') {
{
$error = 0; $error = 0;
if ($_POST["cancel"]) if ($_POST["cancel"]) {
{
$loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
header("Location: ".$loc); header("Location: ".$loc);
exit; exit;
@ -62,53 +59,44 @@ if ($action == 'add_payment')
$expensereport = new ExpenseReport($db); $expensereport = new ExpenseReport($db);
$result = $expensereport->fetch($id, $ref); $result = $expensereport->fetch($id, $ref);
if (!$result) if (!$result) {
{
$error++; $error++;
setEventMessages($expensereport->error, $expensereport->errors, 'errors'); setEventMessages($expensereport->error, $expensereport->errors, 'errors');
} }
$datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
if (!($_POST["fk_typepayment"] > 0)) if (!($_POST["fk_typepayment"] > 0)) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
$error++; $error++;
} }
if ($datepaid == '') if ($datepaid == '') {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++; $error++;
} }
if (!empty($conf->banque->enabled) && !($accountid > 0)) if (!empty($conf->banque->enabled) && !($accountid > 0)) {
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
$error++; $error++;
} }
if (!$error) if (!$error) {
{
$paymentid = 0; $paymentid = 0;
$total = 0; $total = 0;
// Read possible payments // Read possible payments
foreach ($_POST as $key => $value) foreach ($_POST as $key => $value) {
{ if (substr($key, 0, 7) == 'amount_') {
if (substr($key, 0, 7) == 'amount_')
{
$amounts[$expensereport->fk_user_author] = price2num($_POST[$key]); $amounts[$expensereport->fk_user_author] = price2num($_POST[$key]);
$total += price2num($_POST[$key]); $total += price2num($_POST[$key]);
} }
} }
if (count($amounts) <= 0) if (count($amounts) <= 0) {
{
$error++; $error++;
$errmsg = 'ErrorNoPaymentDefined'; $errmsg = 'ErrorNoPaymentDefined';
} }
if (!$error) if (!$error) {
{
$db->begin(); $db->begin();
// Create a line of payments // Create a line of payments
@ -121,21 +109,17 @@ if ($action == 'add_payment')
$payment->num_payment = GETPOST("num_payment", 'alphanothtml'); $payment->num_payment = GETPOST("num_payment", 'alphanothtml');
$payment->note_public = GETPOST("note_public", 'restricthtml'); $payment->note_public = GETPOST("note_public", 'restricthtml');
if (!$error) if (!$error) {
{
$paymentid = $payment->create($user); $paymentid = $payment->create($user);
if ($paymentid < 0) if ($paymentid < 0) {
{
setEventMessages($payment->error, $payment->errors, 'errors'); setEventMessages($payment->error, $payment->errors, 'errors');
$error++; $error++;
} }
} }
if (!$error) if (!$error) {
{
$result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', ''); $result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', '');
if (!$result > 0) if (!$result > 0) {
{
setEventMessages($payment->error, $payment->errors, 'errors'); setEventMessages($payment->error, $payment->errors, 'errors');
$error++; $error++;
} }
@ -152,8 +136,7 @@ if ($action == 'add_payment')
} }
} }
if (!$error) if (!$error) {
{
$db->commit(); $db->commit();
$loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
header('Location: '.$loc); header('Location: '.$loc);
@ -178,8 +161,7 @@ $form = new Form($db);
// Form to create expense report payment // Form to create expense report payment
if ($action == 'create' || empty($action)) if ($action == 'create' || empty($action)) {
{
$expensereport = new ExpenseReport($db); $expensereport = new ExpenseReport($db);
$expensereport->fetch($id, $ref); $expensereport->fetch($id, $ref);
@ -226,8 +208,7 @@ if ($action == 'create' || empty($action))
$sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id; $sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id;
$sql .= ' AND e.entity IN ('.getEntity('expensereport').')'; $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql) {
{
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$sumpaid = $obj->total; $sumpaid = $obj->total;
$db->free(); $db->free();
@ -257,8 +238,7 @@ if ($action == 'create' || empty($action))
print "</td>\n"; print "</td>\n";
print '</tr>'; print '</tr>';
if (!empty($conf->banque->enabled)) if (!empty($conf->banque->enabled)) {
{
print '<tr>'; print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>'; print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td colspan="2">'; print '<td colspan="2">';
@ -299,8 +279,7 @@ if ($action == 'create' || empty($action))
$total = 0; $total = 0;
$totalrecu = 0; $totalrecu = 0;
while ($i < $num) while ($i < $num) {
{
$objp = $expensereport; $objp = $expensereport;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
@ -310,12 +289,12 @@ if ($action == 'create' || empty($action))
print '<td class="right">'.price($sumpaid)."</td>"; print '<td class="right">'.price($sumpaid)."</td>";
print '<td class="right">'.price($objp->total_ttc - $sumpaid)."</td>"; print '<td class="right">'.price($objp->total_ttc - $sumpaid)."</td>";
print '<td class="center">'; print '<td class="center">';
if ($sumpaid < $objp->total_ttc) if ($sumpaid < $objp->total_ttc) {
{
$namef = "amount_".$objp->id; $namef = "amount_".$objp->id;
$nameRemain = "remain_".$objp->id; // autofill remainder amount $nameRemain = "remain_".$objp->id; // autofill remainder amount
if (!empty($conf->use_javascript_ajax)) // autofill remainder amount if (!empty($conf->use_javascript_ajax)) { // autofill remainder amount
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount
}
$remaintopay = $objp->total_ttc - $sumpaid; // autofill remainder amount $remaintopay = $objp->total_ttc - $sumpaid; // autofill remainder amount
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">'; // autofill remainder amount
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">'; print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
@ -331,8 +310,7 @@ if ($action == 'create' || empty($action))
$totalrecu += $objp->am; $totalrecu += $objp->am;
$i++; $i++;
} }
if ($i > 1) if ($i > 1) {
{
// Print total // Print total
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>'; print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';

View File

@ -38,16 +38,19 @@ $mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer';
$object_status = GETPOST('object_status', 'intcomma'); $object_status = GETPOST('object_status', 'intcomma');
$userid = GETPOST('userid', 'int'); $userid = GETPOST('userid', 'int');
$socid = GETPOST('socid', 'int'); if ($socid < 0) $socid = 0; $socid = GETPOST('socid', 'int'); if ($socid < 0) {
$socid = 0;
}
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
// Security check // Security check
if ($user->socid > 0) if ($user->socid > 0) {
{
$action = ''; $action = '';
$socid = $user->socid; $socid = $user->socid;
} }
if ($user->socid) $socid = $user->socid; if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, ''); $result = restrictedArea($user, 'expensereport', $id, '');
$nowyear = strftime("%Y", dol_now()); $nowyear = strftime("%Y", dol_now());
@ -75,7 +78,9 @@ print load_fiche_titre($title, '', 'trip');
dol_mkdir($dir); dol_mkdir($dir);
$stats = new ExpenseReportStats($db, $socid, $userid); $stats = new ExpenseReportStats($db, $socid, $userid);
if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')'; if ($object_status != '' && $object_status >= -1) {
$stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')';
}
// Build graphic number of object // Build graphic number of object
// $data = array(array('Lib',val1,val2,val3),...) // $data = array(array('Lib',val1,val2,val3),...)
@ -88,12 +93,10 @@ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file
$px1 = new DolGraph(); $px1 = new DolGraph();
$mesg = $px1->isGraphKo(); $mesg = $px1->isGraphKo();
if (!$mesg) if (!$mesg) {
{
$px1->SetData($data); $px1->SetData($data);
$i = $startyear; $legend = array(); $i = $startyear; $legend = array();
while ($i <= $endyear) while ($i <= $endyear) {
{
$legend[] = $i; $legend[] = $i;
$i++; $i++;
} }
@ -120,12 +123,10 @@ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;
$px2 = new DolGraph(); $px2 = new DolGraph();
$mesg = $px2->isGraphKo(); $mesg = $px2->isGraphKo();
if (!$mesg) if (!$mesg) {
{
$px2->SetData($data); $px2->SetData($data);
$i = $startyear; $legend = array(); $i = $startyear; $legend = array();
while ($i <= $endyear) while ($i <= $endyear) {
{
$legend[] = $i; $legend[] = $i;
$i++; $i++;
} }
@ -146,25 +147,30 @@ if (!$mesg)
$data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear);
if (!$user->rights->societe->client->voir || $user->socid) if (!$user->rights->societe->client->voir || $user->socid) {
{
$filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png'; $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png'; if ($mode == 'customer') {
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png'; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png';
}
} else { } else {
$filename_avg = $dir.'/ordersaverage-'.$year.'.png'; $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png'; if ($mode == 'customer') {
if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png'; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
}
if ($mode == 'supplier') {
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png';
}
} }
$px3 = new DolGraph(); $px3 = new DolGraph();
$mesg = $px3->isGraphKo(); $mesg = $px3->isGraphKo();
if (!$mesg) if (!$mesg) {
{
$px3->SetData($data); $px3->SetData($data);
$i = $startyear; $legend = array(); $i = $startyear; $legend = array();
while ($i <= $endyear) while ($i <= $endyear) {
{
$legend[] = $i; $legend[] = $i;
$i++; $i++;
} }
@ -189,7 +195,9 @@ $arrayyears = array();
foreach ($data as $val) { foreach ($data as $val) {
$arrayyears[$val['year']] = $val['year']; $arrayyears[$val['year']] = $val['year'];
} }
if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear; if (!count($arrayyears)) {
$arrayyears[$nowyear] = $nowyear;
}
$h = 0; $h = 0;
@ -223,7 +231,9 @@ print '</td></tr>';
// User // User
print '<tr><td>'.$langs->trans("User").'</td><td>'; print '<tr><td>'.$langs->trans("User").'</td><td>';
$include = ''; $include = '';
if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include = 'hierarchy'; if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
$include = 'hierarchy';
}
print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300'); print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '</td></tr>'; print '</td></tr>';
// Status // Status
@ -235,7 +245,9 @@ print '</td></tr>';
print '<tr><td>'; print '<tr><td>';
print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation")); print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
print '</td><td>'; print '</td><td>';
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; if (!in_array($year, $arrayyears)) {
$arrayyears[$year] = $year;
}
arsort($arrayyears); arsort($arrayyears);
print $form->selectarray('year', $arrayyears, $year, 0); print $form->selectarray('year', $arrayyears, $year, 0);
print '</td></tr>'; print '</td></tr>';
@ -254,11 +266,9 @@ print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
print '</tr>'; print '</tr>';
$oldyear = 0; $oldyear = 0;
foreach ($data as $val) foreach ($data as $val) {
{
$year = $val['year']; $year = $val['year'];
while ($year && $oldyear > $year + 1) while ($year && $oldyear > $year + 1) { // If we have empty year
{ // If we have empty year
$oldyear--; $oldyear--;
print '<tr class="oddeven" height="24">'; print '<tr class="oddeven" height="24">';
@ -287,7 +297,9 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Show graphs // Show graphs
print '<table class="border centpercent"><tr class="pair nohover"><td class="center">'; print '<table class="border centpercent"><tr class="pair nohover"><td class="center">';
if ($mesg) { print $mesg; } else { if ($mesg) {
print $mesg;
} else {
print $px1->show(); print $px1->show();
print "<br>\n"; print "<br>\n";
print $px2->show(); print $px2->show();

View File

@ -9,11 +9,9 @@ $permission = $user->rights->expensereport->creer;
// We define var to enable the feature to add prefix of uploaded files // We define var to enable the feature to add prefix of uploaded files
$savingdocmask = ''; $savingdocmask = '';
if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) {
{
//var_dump($modulepart); //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'))) 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__'; $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__';
} }
} }
@ -35,6 +33,6 @@ $formfile->form_attach_new_file(
'accept', 'accept',
'', '',
1 1
); );
print '</td></tr>'; print '</td></tr>';

View File

@ -1,7 +1,6 @@
<?php <?php
// Add line to select existing file // Add line to select existing file
if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) {
{
print '<!-- expensereport_linktofile.tpl.php -->'."\n"; print '<!-- expensereport_linktofile.tpl.php -->'."\n";
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -12,23 +11,20 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
$nbFiles = count($arrayoffiles); $nbFiles = count($arrayoffiles);
$nbLinks = Link::count($db, $object->element, $object->id); $nbLinks = Link::count($db, $object->element, $object->id);
if ($nbFiles > 0) if ($nbFiles > 0) {
{
print '<tr class="trattachnewfilenow'.(empty($tredited) ? ' oddeven nohover' : ' '.$tredited).'"'.(!GETPOSTISSET('sendit') && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display: none"' : '').'>'; print '<tr class="trattachnewfilenow'.(empty($tredited) ? ' oddeven nohover' : ' '.$tredited).'"'.(!GETPOSTISSET('sendit') && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display: none"' : '').'>';
print '<td colspan="'.$colspan.'">'; print '<td colspan="'.$colspan.'">';
//print '<span class="opacitymedium">'.$langs->trans("AttachTheNewLineToTheDocument").'</span><br>'; //print '<span class="opacitymedium">'.$langs->trans("AttachTheNewLineToTheDocument").'</span><br>';
$modulepart = 'expensereport'; $maxheightmini = 48; $modulepart = 'expensereport'; $maxheightmini = 48;
$relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/'; $relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/';
$filei = 0; $filei = 0;
foreach ($arrayoffiles as $file) foreach ($arrayoffiles as $file) {
{
$urlforhref = array(); $urlforhref = array();
$filei++; $filei++;
print '<div class="inline-block margintoponly marginleftonly marginrightonly center valigntop">'; print '<div class="inline-block margintoponly marginleftonly marginrightonly center valigntop">';
$fileinfo = pathinfo($file['fullname']); $fileinfo = pathinfo($file['fullname']);
if (image_format_supported($file['name']) > 0) if (image_format_supported($file['name']) > 0) {
{
$minifile = getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case however) than original $minifile = getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case however) than original
//print $file['path'].'/'.$minifile.'<br>'; //print $file['path'].'/'.$minifile.'<br>';
$urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity)); $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
@ -46,8 +42,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
$error = 0; $error = 0;
$thumbshown = ''; $thumbshown = '';
if (preg_match('/\.pdf$/i', $file['name'])) if (preg_match('/\.pdf$/i', $file['name'])) {
{
$urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity)); $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
$filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$file['name']; $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$file['name'];
@ -56,27 +51,26 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
$pdfexists = file_exists($filepdf); $pdfexists = file_exists($filepdf);
if ($pdfexists) if ($pdfexists) {
{
// Conversion du PDF en image png si fichier png non existant // Conversion du PDF en image png si fichier png non existant
if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
{ if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) { // If you experience trouble with pdf thumb generation and imagick, you can disable here.
if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here.
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
if ($ret < 0) $error++; if ($ret < 0) {
$error++;
}
} }
} }
} }
if ($pdfexists && !$error) if ($pdfexists && !$error) {
{
$heightforphotref = 70; $heightforphotref = 70;
if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60; if (!empty($conf->dol_optimize_smallscreen)) {
$heightforphotref = 60;
}
// If the preview file is found // If the preview file is found
if (file_exists($fileimage)) if (file_exists($fileimage)) {
{
$thumbshown = '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">'; $thumbshown = '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
} }
} }
@ -98,10 +92,8 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
//var_dump(GETPOST($file['relativename'])); var_dump($file['relativename']); var_dump($_FILES['userfile']['name']); //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 // If a file was just uploaded, we check to preselect it
if (is_array($_FILES['userfile']['name'])) { if (is_array($_FILES['userfile']['name'])) {
foreach ($_FILES['userfile']['name'] as $tmpfile) foreach ($_FILES['userfile']['name'] as $tmpfile) {
{ if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) {
if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile)
{
$checked = ' checked'; $checked = ' checked';
break; break;
} elseif ($file['relativename'] && in_array($file['relativename'], GETPOST('attachfile', 'array'))) { } elseif ($file['relativename'] && in_array($file['relativename'], GETPOST('attachfile', 'array'))) {
@ -111,8 +103,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
} }
} }
// If we edit a line already linked, then $filenamelinked is defined to the filename (without path) of linked file // 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']) if (!empty($filenamelinked) && $filenamelinked == $file['relativename']) {
{
$checked = ' checked'; $checked = ' checked';
} }
print '<div class="margintoponly maxwidth150"><input type="checkbox"'.$checked.' id="radio'.$filei.'" name="attachfile[]" class="checkboxattachfile" value="'.$file['relativename'].'">'; print '<div class="margintoponly maxwidth150"><input type="checkbox"'.$checked.' id="radio'.$filei.'" name="attachfile[]" class="checkboxattachfile" value="'.$file['relativename'].'">';

View File

@ -18,8 +18,7 @@
*/ */
// Protection to avoid direct call of template // Protection to avoid direct call of template
if (empty($conf) || !is_object($conf)) if (empty($conf) || !is_object($conf)) {
{
print "Error, template page can't be called as URL"; print "Error, template page can't be called as URL";
exit; exit;
} }
@ -35,13 +34,12 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
$var = true; $var = true;
$total = 0; $total = 0;
foreach ($linkedObjectBlock as $key => $objectlink) foreach ($linkedObjectBlock as $key => $objectlink) {
{
?> ?>
<tr <?php echo $GLOBALS['bc'][$var]; ?> > <tr <?php echo $GLOBALS['bc'][$var]; ?> >
<td><?php echo $langs->trans("ExpenseReport"); ?></td> <td><?php echo $langs->trans("ExpenseReport"); ?></td>
<td><?php echo $objectlink->getNomUrl(1); ?></td> <td><?php echo $objectlink->getNomUrl(1); ?></td>
<td></td> <td></td>
<td class="center"><?php echo dol_print_date($objectlink->date_debut, 'day'); ?></td> <td class="center"><?php echo dol_print_date($objectlink->date_debut, 'day'); ?></td>
<td class="right"><?php <td class="right"><?php
if ($user->rights->expensereport->lire) { if ($user->rights->expensereport->lire) {