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
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
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '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');
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '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;
require '../../main.inc.php';
@@ -50,20 +62,25 @@ $fk_expense = GETPOST('fk_expense');
$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')));
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 {
if (empty($fk_expense) || $fk_expense < 0) {
echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense')));
} 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)
$expense = new ExpenseReport($db);
if ($expense->fetch($fk_expense) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
else {
if ($expense->fetch($fk_expense) <= 0) {
echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
} else {
$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));
else {
if ($userauthor->fetch($expense->fk_user_author) <= 0) {
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);
if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
else {
if (empty($range)) {
echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
} else {
$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'));
}

View File

@@ -24,12 +24,24 @@
* \brief File to return Ajax response on third parties request
*/
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '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');
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1); // Disables token renewal
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '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;
require '../../main.inc.php';
@@ -52,21 +64,20 @@ dol_syslog(join(',', $_GET));
// Generation liste des projets
if (GETPOST('fk_projet') != '')
{
if (GETPOST('fk_projet') != '') {
$return_arr = array();
$sql = "SELECT p.rowid, p.ref, p.title, s.nom";
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$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";
$resql = $db->query($sql);
if ($resql)
{
while ($row = $db->fetch_array($resql))
{
if ($resql) {
while ($row = $db->fetch_array($resql)) {
$label = $row['ref'].' - '.$row['title'];
$row_array['label'] = $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
*/
static $FIELDS = array(
public static $FIELDS = array(
'fk_user_author'
);
@@ -107,11 +107,12 @@ class ExpenseReports extends DolibarrApi
$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t";
$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
if ($sqlfilters)
{
if ($sqlfilters) {
if (!DolibarrApi::_checkFilters($sqlfilters)) {
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
@@ -131,13 +132,11 @@ class ExpenseReports extends DolibarrApi
$result = $this->db->query($sql);
if ($result)
{
if ($result) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
$i = 0;
while ($i < $min)
{
while ($i < $min) {
$obj = $this->db->fetch_object($result);
$expensereport_static = new ExpenseReport($this->db);
if ($expensereport_static->fetch($obj->rowid)) {
@@ -172,12 +171,12 @@ class ExpenseReports extends DolibarrApi
$this->expensereport->$field = $value;
}
/*if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->expensereport->lines = $lines;
}*/
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->expensereport->lines = $lines;
}*/
if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
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
*/
/*
public function getLines($id)
{
if(! DolibarrApiAccess::$user->rights->expensereport->lire) {
throw new RestException(401);
}
public function getLines($id)
{
if(! DolibarrApiAccess::$user->rights->expensereport->lire) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->expensereport->getLinesArray();
$result = array();
foreach ($this->expensereport->lines as $line) {
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
*/
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$this->expensereport->getLinesArray();
$result = array();
foreach ($this->expensereport->lines as $line) {
array_push($result,$this->_cleanObjectDatas($line));
}
return $result;
}
*/
/**
* Add a line to given Expense Report
@@ -229,56 +228,56 @@ class ExpenseReports extends DolibarrApi
* @return int
*/
/*
public function postLine($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
public function postLine($id, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->expensereport->addline(
$request_data->desc,
$request_data->subprice,
$request_data->qty,
$request_data->tva_tx,
$request_data->localtax1_tx,
$request_data->localtax2_tx,
$request_data->fk_product,
$request_data->remise_percent,
$request_data->info_bits,
$request_data->fk_remise_except,
'HT',
0,
$request_data->date_start,
$request_data->date_end,
$request_data->product_type,
$request_data->rang,
$request_data->special_code,
$fk_parent_line,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
$request_data->array_options,
$request_data->fk_unit,
$this->element,
$request_data->id
);
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->expensereport->addline(
$request_data->desc,
$request_data->subprice,
$request_data->qty,
$request_data->tva_tx,
$request_data->localtax1_tx,
$request_data->localtax2_tx,
$request_data->fk_product,
$request_data->remise_percent,
$request_data->info_bits,
$request_data->fk_remise_except,
'HT',
0,
$request_data->date_start,
$request_data->date_end,
$request_data->product_type,
$request_data->rang,
$request_data->special_code,
$fk_parent_line,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
$request_data->array_options,
$request_data->fk_unit,
$this->element,
$request_data->id
);
if ($updateRes > 0) {
return $updateRes;
if ($updateRes > 0) {
return $updateRes;
}
return false;
}
*/
}
return false;
}
*/
/**
* Update a line to given Expense Report
@@ -292,53 +291,53 @@ class ExpenseReports extends DolibarrApi
* @return object
*/
/*
public function putLine($id, $lineid, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
public function putLine($id, $lineid, $request_data = null)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->expensereport->updateline(
$lineid,
$request_data->desc,
$request_data->subprice,
$request_data->qty,
$request_data->remise_percent,
$request_data->tva_tx,
$request_data->localtax1_tx,
$request_data->localtax2_tx,
'HT',
$request_data->info_bits,
$request_data->date_start,
$request_data->date_end,
$request_data->product_type,
$request_data->fk_parent_line,
0,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
$request_data->special_code,
$request_data->array_options,
$request_data->fk_unit
);
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
$request_data = (object) $request_data;
$updateRes = $this->expensereport->updateline(
$lineid,
$request_data->desc,
$request_data->subprice,
$request_data->qty,
$request_data->remise_percent,
$request_data->tva_tx,
$request_data->localtax1_tx,
$request_data->localtax2_tx,
'HT',
$request_data->info_bits,
$request_data->date_start,
$request_data->date_end,
$request_data->product_type,
$request_data->fk_parent_line,
0,
$request_data->fk_fournprice,
$request_data->pa_ht,
$request_data->label,
$request_data->special_code,
$request_data->array_options,
$request_data->fk_unit
);
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
}
*/
if ($updateRes > 0) {
$result = $this->get($id);
unset($result->line);
return $this->_cleanObjectDatas($result);
}
return false;
}
*/
/**
* Delete a line of given Expense Report
@@ -351,30 +350,30 @@ class ExpenseReports extends DolibarrApi
* @return int
*/
/*
public function deleteLine($id, $lineid)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
public function deleteLine($id, $lineid)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
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);
if ($updateRes == 1) {
return $this->get($id);
}
return false;
}
*/
$updateRes = $this->expensereport->deleteline($lineid);
if ($updateRes == 1) {
return $this->get($id);
}
return false;
}
*/
/**
* 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);
}
foreach ($request_data as $field => $value) {
if ($field == 'id') continue;
if ($field == 'id') {
continue;
}
$this->expensereport->$field = $value;
}
if ($this->expensereport->update(DolibarrApiAccess::$user) > 0)
{
if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) {
return $this->get($id);
} else {
throw new RestException(500, $this->expensereport->error);
@@ -464,31 +464,31 @@ class ExpenseReports extends DolibarrApi
* }
*/
/*
public function validate($id, $idwarehouse=0)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
public function validate($id, $idwarehouse=0)
{
if(! DolibarrApiAccess::$user->rights->expensereport->creer) {
throw new RestException(401);
}
$result = $this->expensereport->fetch($id);
if( ! $result ) {
throw new RestException(404, 'expensereport not found');
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) {
throw new RestException(500, 'Error when validate expensereport');
}
if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) {
throw new RestException(500, 'Error when validate expensereport');
}
return array(
'success' => array(
'code' => 200,
'message' => 'expensereport validated'
)
);
}*/
return array(
'success' => array(
'code' => 200,
'message' => 'expensereport validated'
)
);
}*/
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
@@ -555,8 +555,9 @@ class ExpenseReports extends DolibarrApi
{
$expensereport = array();
foreach (ExpenseReports::$FIELDS as $field) {
if (!isset($data[$field]))
if (!isset($data[$field])) {
throw new RestException(400, "$field field missing");
}
$expensereport[$field] = $data[$field];
}
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 .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat';
$sql .= ' WHERE entity IN ('.getEntity('c_exp_tax_cat').')';
if ($mode == 1) $sql .= ' AND active = 1';
elseif ($mode == 2) $sql .= 'AND active = 0';
if ($mode == 1) {
$sql .= ' AND active = 1';
} elseif ($mode == 2) {
$sql .= 'AND active = 0';
}
dol_syslog(get_called_class().'::getTaxCategories sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
while ($obj = $db->fetch_object($resql))
{
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$categories[$obj->rowid] = $obj;
}
} else {
@@ -142,8 +143,11 @@ class ExpenseReportIk extends CoreObject
$ranges = self::getRangesByCategory($fk_c_exp_tax_cat);
// substract 1 because array start from 0
if (empty($ranges) || !isset($ranges[$default_range - 1])) return false;
else return $ranges[$default_range - 1];
if (empty($ranges) || !isset($ranges[$default_range - 1])) {
return false;
} else {
return $ranges[$default_range - 1];
}
}
/**
@@ -160,20 +164,21 @@ class ExpenseReportIk extends CoreObject
$ranges = array();
$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;
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';
dol_syslog(get_called_class().'::getRangesByCategory sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
if ($num > 0)
{
while ($obj = $db->fetch_object($resql))
{
if ($num > 0) {
while ($obj = $db->fetch_object($resql)) {
$object = new ExpenseReportIk($db);
$object->fetch($obj->rowid);
@@ -207,15 +212,17 @@ class ExpenseReportIk extends CoreObject
dol_syslog(get_called_class().'::getAllRanges sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
while ($obj = $db->fetch_object($resql))
{
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$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;
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;
}
} else {
@@ -239,14 +246,15 @@ class ExpenseReportIk extends CoreObject
$sql .= ' SELECT COUNT(*) as counted';
$sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r';
$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 .= ') as counts';
dol_syslog(get_called_class().'::getMaxRangeNumber sql='.$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
return $obj->nbRange;
} else {

View File

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

View File

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

View File

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

View File

@@ -42,19 +42,27 @@ $langs->loadLangs(array('companies', 'users', 'trips'));
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', '', '');
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$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;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "d.date_create";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.date_create";
}
$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";
// RESTRICT RIGHTS
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->id;
$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";
$result = $db->query($sql);
if ($result)
{
if ($result) {
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $db->fetch_object($result);
$somme[$objp->code] = $objp->km;
@@ -123,13 +128,11 @@ print '<th colspan="4">'.$langs->trans("Statistics").'</th>';
print "</tr>\n";
$listoftype = $tripandexpense_static->listOfTypes();
foreach ($listoftype as $code => $label)
{
foreach ($listoftype as $code => $label) {
$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">';
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 .= " 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";
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";
// RESTRICT RIGHTS
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->id;
$sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n";
}
$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 ($socid) $sql .= " AND d.fk_user_author = ".$socid;
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 ($socid) {
$sql .= " AND d.fk_user_author = ".$socid;
}
$sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($max, 0);
$result = $db->query($sql);
if ($result)
{
if ($result) {
$var = false;
$num = $db->num_rows($result);
@@ -201,14 +208,12 @@ if ($result)
print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
print '<th>&nbsp;</th>';
print '</tr>';
if ($num)
{
if ($num) {
$total_ttc = $totalam = $total = 0;
$expensereportstatic = new ExpenseReport($db);
$userstatic = new User($db);
while ($i < $num && $i < $max)
{
while ($i < $num && $i < $max) {
$obj = $db->fetch_object($result);
$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 '</table></div><br>';
} else dol_print_error($db);
} else {
dol_print_error($db);
}
print '</div></div></div>';

View File

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

View File

@@ -54,18 +54,24 @@ $childids = $user->getAllChildIds(1);
// Security check
$socid = GETPOST('socid', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', '', '');
$id = GETPOST('id', 'int');
// If we are on the view of a specific user
if ($id > 0)
{
if ($id > 0) {
$canread = 0;
if ($id == $user->id) $canread = 1;
if (!empty($user->rights->expensereport->readall)) $canread = 1;
if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) $canread = 1;
if (!$canread)
{
if ($id == $user->id) {
$canread = 1;
}
if (!empty($user->rights->expensereport->readall)) {
$canread = 1;
}
if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden();
}
}
@@ -78,12 +84,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$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;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) $sortorder = "DESC";
if (!$sortfield) $sortfield = "d.date_debut";
if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
$sortfield = "d.date_debut";
}
$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");
$optioncss = GETPOST('optioncss', 'alpha');
if ($search_status == '') $search_status = -1;
if ($search_user == '') $search_user = -1;
if ($search_status == '') {
$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
$object = new ExpenseReport($db);
@@ -123,7 +139,9 @@ $fieldstosearchall = array(
'u.firstname'=>"Firstname",
'u.login'=>"Login",
);
if (empty($user->socid)) $fieldstosearchall["d.note_private"] = "NotePrivate";
if (empty($user->socid)) {
$fieldstosearchall["d.note_private"] = "NotePrivate";
}
$arrayfields = array(
'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
@@ -151,21 +169,25 @@ $objectuser = new User($db);
* Actions
*/
if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
$parameters = array('socid'=>$socid);
$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
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// 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_user = "";
$search_amount_ht = "";
@@ -181,8 +203,7 @@ if (empty($reshook))
$search_array_options = array();
}
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
}
@@ -216,8 +237,7 @@ $min_year = 10;
// Get current user id
$user_id = $user->id;
if ($id > 0)
{
if ($id > 0) {
// Charge utilisateur edite
$fuser->fetch($id, '', '', 1);
$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";
// Add fields from extrafields
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
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$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 .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
// Search all
if (!empty($sall)) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
if (!empty($sall)) {
$sql .= natural_search(array_keys($fieldstosearchall), $sall);
}
// 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
$sql .= dolSqlDateFilter("d.date_debut", $day_start, $month_start, $year_start);
// Date 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_ttc != '') $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1);
if ($search_amount_ht != '') {
$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
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
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
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";
}
// Add where from extra fields
@@ -273,12 +308,10 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$result = $db->query($sql);
$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;
$offset = 0;
}
@@ -288,22 +321,39 @@ $sql .= $db->plimit($limit + 1, $offset);
//print $sql;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$arrayofselected = is_array($toselect) ? $toselect : array();
$param = '';
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
if ($sall) $param .= "&sall=".urlencode($sall);
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);
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
if ($sall) {
$param .= "&sall=".urlencode($sall);
}
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
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
@@ -313,23 +363,30 @@ if ($resql)
'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"),
);
if ($user->rights->expensereport->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
if ($user->rights->expensereport->supprimer) {
$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);
// Lines of title fields
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="formfilteraction" id="formfilteraction" value="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="sortfield" value="'.$sortfield.'">';
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");
$linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$head = user_prepare_head($fuser);
@@ -340,8 +397,7 @@ if ($resql)
print dol_get_fiche_end();
if ($action != 'edit')
{
if ($action != 'edit') {
print '<div class="tabsAction">';
$childids = $user->getAllChildIds(1);
@@ -366,7 +422,9 @@ if ($resql)
$title = $langs->trans("ListTripsAndExpenses");
$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);
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;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($sall)
{
foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
if ($sall) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
}
@@ -388,11 +447,13 @@ if ($resql)
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
else $moreforfilter = $hookmanager->resPrint;
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
if (!empty($moreforfilter))
{
if (!empty($moreforfilter)) {
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter;
print '</div>';
@@ -407,17 +468,14 @@ if ($resql)
// Filters
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 '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
print '</td>';
}
// User
if (!empty($arrayfields['user']['checked']))
{
if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous)
{
if (!empty($arrayfields['user']['checked'])) {
if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) {
print '<td class="liste_titre maxwidthonspartphone" align="left">';
print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
print '</td>';
@@ -426,8 +484,7 @@ if ($resql)
}
}
// Date start
if (!empty($arrayfields['d.date_debut']['checked']))
{
if (!empty($arrayfields['d.date_debut']['checked'])) {
print '<td class="liste_titre" align="center">';
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).'">';
@@ -438,8 +495,7 @@ if ($resql)
print '</td>';
}
// Date end
if (!empty($arrayfields['d.date_fin']['checked']))
{
if (!empty($arrayfields['d.date_fin']['checked'])) {
print '<td class="liste_titre" align="center">';
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).'">';
@@ -449,33 +505,28 @@ if ($resql)
print '</td>';
}
// Date valid
if (!empty($arrayfields['d.date_valid']['checked']))
{
if (!empty($arrayfields['d.date_valid']['checked'])) {
print '<td class="liste_titre" align="center">';
//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);
print '</td>';
}
// Date approve
if (!empty($arrayfields['d.date_approve']['checked']))
{
if (!empty($arrayfields['d.date_approve']['checked'])) {
print '<td class="liste_titre" align="center">';
//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);
print '</td>';
}
// 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>';
}
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>';
}
// 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>';
}
// Extra fields
@@ -486,20 +537,17 @@ if ($resql)
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['d.date_create']['checked']))
{
if (!empty($arrayfields['d.date_create']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Date modification
if (!empty($arrayfields['d.tms']['checked']))
{
if (!empty($arrayfields['d.tms']['checked'])) {
print '<td class="liste_titre">';
print '</td>';
}
// Status
if (!empty($arrayfields['d.fk_statut']['checked']))
{
if (!empty($arrayfields['d.fk_statut']['checked'])) {
print '<td class="liste_titre right">';
$formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1);
print '</td>';
@@ -513,24 +561,48 @@ if ($resql)
print "</tr>\n";
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['user']['checked'])) print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $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['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);
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['user']['checked'])) {
print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $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['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
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$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
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.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);
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.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 "</tr>\n";
@@ -541,12 +613,10 @@ if ($resql)
$expensereportstatic = new ExpenseReport($db);
$usertmp = new User($db);
if ($num > 0)
{
if ($num > 0) {
$i = 0;
$totalarray = array();
while ($i < min($num, $limit))
{
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
$expensereportstatic->id = $obj->rowid;
@@ -572,10 +642,13 @@ if ($resql)
print '</td>';
// Warning late icon and note
print '<td class="nobordernopadding nowrap">';
if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) print img_warning($langs->trans("Late"));
if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) print img_warning($langs->trans("Late"));
if (!empty($obj->note_private) || !empty($obj->note_public))
{
if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) {
print img_warning($langs->trans("Late"));
}
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 '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
print '</span>';
@@ -589,7 +662,9 @@ if ($resql)
print '</td>';
print '</tr></table>';
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// User
if (!empty($arrayfields['user']['checked'])) {
@@ -603,50 +678,69 @@ if ($resql)
$usertmp->email = $obj->email;
print $usertmp->getNomUrl(-1);
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Start date
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>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// End date
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>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date validation
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>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date approval
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>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// 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";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht';
}
$totalarray['val']['d.total_ht'] += $obj->total_ht;
}
// 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";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva';
}
$totalarray['val']['d.total_tva'] += $obj->total_tva;
}
// 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";
if (!$i) $totalarray['nbfield']++;
if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc';
if (!$i) {
$totalarray['nbfield']++;
}
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc';
}
$totalarray['val']['d.total_ttc'] += $obj->total_ttc;
}
@@ -658,37 +752,43 @@ if ($resql)
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['d.date_create']['checked']))
{
if (!empty($arrayfields['d.date_create']['checked'])) {
print '<td class="nowrap center">';
print dol_print_date($db->jdate($obj->date_create), 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Date modification
if (!empty($arrayfields['d.tms']['checked']))
{
if (!empty($arrayfields['d.tms']['checked'])) {
print '<td class="nowrap center">';
print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
print '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Status
if (!empty($arrayfields['d.fk_statut']['checked']))
{
if (!empty($arrayfields['d.fk_statut']['checked'])) {
print '<td class="nowrap right">'.$expensereportstatic->getLibStatut(5).'</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
}
// Action column
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;
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 '</td>';
if (!$i) $totalarray['nbfield']++;
if (!$i) {
$totalarray['nbfield']++;
}
print "</tr>\n";
@@ -700,7 +800,11 @@ if ($resql)
}
} else {
$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>';
}
@@ -718,10 +822,11 @@ if ($resql)
print '</form>'."\n";
if (empty($id))
{
if (empty($id)) {
$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
$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;

View File

@@ -41,26 +41,29 @@ $childids = $user->getAllChildIds(1);
// Security check
$socid = 0;
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, 'expensereport');
$object = new ExpenseReport($db);
if (!$object->fetch($id, $ref) > 0)
{
if (!$object->fetch($id, $ref) > 0) {
dol_print_error($db);
}
$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
$canread = 0;
if (!empty($user->rights->expensereport->readall)) $canread = 1;
if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1;
if (!$canread)
{
if (!empty($user->rights->expensereport->readall)) {
$canread = 1;
}
if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) {
$canread = 1;
}
if (!$canread) {
accessforbidden();
}
}
@@ -82,8 +85,7 @@ llxHeader("", $title, $helpurl);
$form = new Form($db);
if ($id > 0 || !empty($ref))
{
if ($id > 0 || !empty($ref)) {
$object = new ExpenseReport($db);
$object->fetch($id, $ref);
$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.'/core/modules/expensereport/modules_expensereport.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
$langs->loadLangs(array('bills', 'banks', 'companies', 'trips'));
@@ -36,16 +38,19 @@ $action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm');
// Security check
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
// TODO Add rule to restrict access payment
//$result = restrictedArea($user, 'facture', $id,'');
$object = new PaymentExpenseReport($db);
if ($id > 0)
{
if ($id > 0) {
$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
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) {
$db->begin();
$result = $object->delete($user);
if ($result > 0)
{
if ($result > 0) {
$db->commit();
header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
exit;
@@ -86,8 +89,7 @@ print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment")
/*
* 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);
}
@@ -118,14 +120,11 @@ print '<tr><td class="tdtop">'.$langs->trans('Note').'</td><td colspan="3">'.nl2
$disable_delete = 0;
// Bank account
if (!empty($conf->banque->enabled))
{
if ($object->bank_account)
{
if (!empty($conf->banque->enabled)) {
if ($object->bank_account) {
$bankline = new AccountLine($db);
$bankline->fetch($object->bank_line);
if ($bankline->rappro)
{
if ($bankline->rappro) {
$disable_delete = 1;
$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);
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
@@ -186,10 +184,8 @@ if ($resql)
print '<td class="center">'.$langs->trans('Status').'</td>';
print "</tr>\n";
if ($num > 0)
{
while ($i < $num)
{
if ($num > 0) {
while ($i < $num) {
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
@@ -216,8 +212,7 @@ if ($resql)
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;
$title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid");
}
@@ -242,12 +237,9 @@ if ($resql)
*/
print '<div class="tabsAction">';
if ($action == '')
{
if ($user->rights->expensereport->supprimer)
{
if (!$disable_delete)
{
if ($action == '') {
if ($user->rights->expensereport->supprimer) {
if (!$disable_delete) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans('Delete').'</a>';
} else {
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
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
@@ -49,12 +48,10 @@ if ($user->socid > 0)
* Actions
*/
if ($action == 'add_payment')
{
if ($action == 'add_payment') {
$error = 0;
if ($_POST["cancel"])
{
if ($_POST["cancel"]) {
$loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
header("Location: ".$loc);
exit;
@@ -62,53 +59,44 @@ if ($action == 'add_payment')
$expensereport = new ExpenseReport($db);
$result = $expensereport->fetch($id, $ref);
if (!$result)
{
if (!$result) {
$error++;
setEventMessages($expensereport->error, $expensereport->errors, 'errors');
}
$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');
$error++;
}
if ($datepaid == '')
{
if ($datepaid == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++;
}
if (!empty($conf->banque->enabled) && !($accountid > 0))
{
if (!empty($conf->banque->enabled) && !($accountid > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
$error++;
}
if (!$error)
{
if (!$error) {
$paymentid = 0;
$total = 0;
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
$amounts[$expensereport->fk_user_author] = price2num($_POST[$key]);
$total += price2num($_POST[$key]);
}
}
if (count($amounts) <= 0)
{
if (count($amounts) <= 0) {
$error++;
$errmsg = 'ErrorNoPaymentDefined';
}
if (!$error)
{
if (!$error) {
$db->begin();
// Create a line of payments
@@ -121,21 +109,17 @@ if ($action == 'add_payment')
$payment->num_payment = GETPOST("num_payment", 'alphanothtml');
$payment->note_public = GETPOST("note_public", 'restricthtml');
if (!$error)
{
if (!$error) {
$paymentid = $payment->create($user);
if ($paymentid < 0)
{
if ($paymentid < 0) {
setEventMessages($payment->error, $payment->errors, 'errors');
$error++;
}
}
if (!$error)
{
if (!$error) {
$result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', '');
if (!$result > 0)
{
if (!$result > 0) {
setEventMessages($payment->error, $payment->errors, 'errors');
$error++;
}
@@ -152,8 +136,7 @@ if ($action == 'add_payment')
}
}
if (!$error)
{
if (!$error) {
$db->commit();
$loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
header('Location: '.$loc);
@@ -178,8 +161,7 @@ $form = new Form($db);
// Form to create expense report payment
if ($action == 'create' || empty($action))
{
if ($action == 'create' || empty($action)) {
$expensereport = new ExpenseReport($db);
$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 .= ' AND e.entity IN ('.getEntity('expensereport').')';
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$sumpaid = $obj->total;
$db->free();
@@ -257,8 +238,7 @@ if ($action == 'create' || empty($action))
print "</td>\n";
print '</tr>';
if (!empty($conf->banque->enabled))
{
if (!empty($conf->banque->enabled)) {
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td colspan="2">';
@@ -299,8 +279,7 @@ if ($action == 'create' || empty($action))
$total = 0;
$totalrecu = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $expensereport;
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($objp->total_ttc - $sumpaid)."</td>";
print '<td class="center">';
if ($sumpaid < $objp->total_ttc)
{
if ($sumpaid < $objp->total_ttc) {
$namef = "amount_".$objp->id;
$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
}
$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="text" size="8" name="'.$namef.'" id="'.$namef.'">';
@@ -331,8 +310,7 @@ if ($action == 'create' || empty($action))
$totalrecu += $objp->am;
$i++;
}
if ($i > 1)
{
if ($i > 1) {
// Print total
print '<tr class="oddeven">';
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');
$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');
// Security check
if ($user->socid > 0)
{
if ($user->socid > 0) {
$action = '';
$socid = $user->socid;
}
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expensereport', $id, '');
$nowyear = strftime("%Y", dol_now());
@@ -75,7 +78,9 @@ print load_fiche_titre($title, '', 'trip');
dol_mkdir($dir);
$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
// $data = array(array('Lib',val1,val2,val3),...)
@@ -88,12 +93,10 @@ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;file
$px1 = new DolGraph();
$mesg = $px1->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px1->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@@ -120,12 +123,10 @@ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&amp;
$px2 = new DolGraph();
$mesg = $px2->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px2->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@@ -146,25 +147,30 @@ if (!$mesg)
$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';
if ($mode == 'customer') $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';
if ($mode == 'customer') {
$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 {
$filename_avg = $dir.'/ordersaverage-'.$year.'.png';
if ($mode == 'customer') $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';
if ($mode == 'customer') {
$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();
$mesg = $px3->isGraphKo();
if (!$mesg)
{
if (!$mesg) {
$px3->SetData($data);
$i = $startyear; $legend = array();
while ($i <= $endyear)
{
while ($i <= $endyear) {
$legend[] = $i;
$i++;
}
@@ -189,7 +195,9 @@ $arrayyears = array();
foreach ($data as $val) {
$arrayyears[$val['year']] = $val['year'];
}
if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
if (!count($arrayyears)) {
$arrayyears[$nowyear] = $nowyear;
}
$h = 0;
@@ -223,7 +231,9 @@ print '</td></tr>';
// User
print '<tr><td>'.$langs->trans("User").'</td><td>';
$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 '</td></tr>';
// Status
@@ -235,7 +245,9 @@ print '</td></tr>';
print '<tr><td>';
print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation"));
print '</td><td>';
if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
if (!in_array($year, $arrayyears)) {
$arrayyears[$year] = $year;
}
arsort($arrayyears);
print $form->selectarray('year', $arrayyears, $year, 0);
print '</td></tr>';
@@ -254,11 +266,9 @@ print '<td class="right">'.$langs->trans("AmountAverage").'</td>';
print '</tr>';
$oldyear = 0;
foreach ($data as $val)
{
foreach ($data as $val) {
$year = $val['year'];
while ($year && $oldyear > $year + 1)
{ // If we have empty year
while ($year && $oldyear > $year + 1) { // If we have empty year
$oldyear--;
print '<tr class="oddeven" height="24">';
@@ -287,7 +297,9 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
// Show graphs
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 "<br>\n";
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
$savingdocmask = '';
if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX))
{
if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) {
//var_dump($modulepart);
if (in_array($modulepart, array('facture_fournisseur', 'commande_fournisseur', 'facture', 'commande', 'propal', 'supplier_proposal', 'ficheinter', 'contract', 'expedition', 'project', 'project_task', 'expensereport', 'tax', 'produit', 'product_batch')))
{
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__';
}
}
@@ -35,6 +33,6 @@ $formfile->form_attach_new_file(
'accept',
'',
1
);
);
print '</td></tr>';

View File

@@ -1,7 +1,6 @@
<?php
// 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";
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);
$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 '<td colspan="'.$colspan.'">';
//print '<span class="opacitymedium">'.$langs->trans("AttachTheNewLineToTheDocument").'</span><br>';
$modulepart = 'expensereport'; $maxheightmini = 48;
$relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/';
$filei = 0;
foreach ($arrayoffiles as $file)
{
foreach ($arrayoffiles as $file) {
$urlforhref = array();
$filei++;
print '<div class="inline-block margintoponly marginleftonly marginrightonly center valigntop">';
$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
//print $file['path'].'/'.$minifile.'<br>';
$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;
$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));
$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);
if ($pdfexists)
{
if ($pdfexists) {
// Conversion du PDF en image png si fichier png non existant
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 (!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.
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
if ($ret < 0) $error++;
if ($ret < 0) {
$error++;
}
}
}
}
if ($pdfexists && !$error)
{
if ($pdfexists && !$error) {
$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 (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).'">';
}
}
@@ -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']);
// If a file was just uploaded, we check to preselect it
if (is_array($_FILES['userfile']['name'])) {
foreach ($_FILES['userfile']['name'] as $tmpfile)
{
if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile)
{
foreach ($_FILES['userfile']['name'] as $tmpfile) {
if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) {
$checked = ' checked';
break;
} 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 (!empty($filenamelinked) && $filenamelinked == $file['relativename'])
{
if (!empty($filenamelinked) && $filenamelinked == $file['relativename']) {
$checked = ' checked';
}
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
if (empty($conf) || !is_object($conf))
{
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit;
}
@@ -35,13 +34,12 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock'];
$var = true;
$total = 0;
foreach ($linkedObjectBlock as $key => $objectlink)
{
foreach ($linkedObjectBlock as $key => $objectlink) {
?>
<tr <?php echo $GLOBALS['bc'][$var]; ?> >
<td><?php echo $langs->trans("ExpenseReport"); ?></td>
<td><?php echo $objectlink->getNomUrl(1); ?></td>
<td></td>
<td><?php echo $objectlink->getNomUrl(1); ?></td>
<td></td>
<td class="center"><?php echo dol_print_date($objectlink->date_debut, 'day'); ?></td>
<td class="right"><?php
if ($user->rights->expensereport->lire) {