2005-01-12 20:40:51 +01:00
|
|
|
<?php
|
2014-03-17 14:30:55 +01:00
|
|
|
/* Copyright (C) 2005-2014 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2005-01-12 20:40:51 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-01-12 20:40:51 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2005-01-12 20:40:51 +01:00
|
|
|
*/
|
|
|
|
|
|
2005-04-22 00:52:00 +02:00
|
|
|
/**
|
2009-10-15 15:39:40 +02:00
|
|
|
* \defgroup deplacement Module trips
|
|
|
|
|
* \brief Module pour gerer les deplacements et notes de frais
|
2011-10-24 14:11:49 +02:00
|
|
|
* \file htdocs/core/modules/modDeplacement.class.php
|
2009-10-15 15:39:40 +02:00
|
|
|
* \ingroup deplacement
|
2021-03-20 13:55:43 +01:00
|
|
|
* \brief Description and activation file for the module trips (deprecated)
|
2008-10-01 21:10:17 +02:00
|
|
|
*/
|
2020-04-10 10:59:32 +02:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
|
2007-10-10 01:15:25 +02:00
|
|
|
|
2005-01-12 20:40:51 +01:00
|
|
|
|
2005-04-22 00:52:00 +02:00
|
|
|
/**
|
2015-09-07 15:55:26 +02:00
|
|
|
* Class to describe and enable module Deplacement
|
2008-10-01 21:10:17 +02:00
|
|
|
*/
|
2005-01-12 20:40:51 +01:00
|
|
|
class modDeplacement extends DolibarrModules
|
|
|
|
|
{
|
|
|
|
|
|
2008-10-01 21:10:17 +02:00
|
|
|
/**
|
2011-09-26 16:22:35 +02:00
|
|
|
* Constructor. Define names, constants, directories, boxes, permissions
|
|
|
|
|
*
|
2012-07-30 17:17:33 +02:00
|
|
|
* @param DoliDB $db Database handler
|
2008-10-01 21:10:17 +02:00
|
|
|
*/
|
2019-02-25 20:35:59 +01:00
|
|
|
public function __construct($db)
|
2008-10-01 21:10:17 +02:00
|
|
|
{
|
2016-06-06 17:51:39 +02:00
|
|
|
global $conf, $user;
|
2009-05-04 13:40:00 +02:00
|
|
|
|
2012-07-30 17:17:33 +02:00
|
|
|
$this->db = $db;
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->numero = 75;
|
2008-10-01 21:10:17 +02:00
|
|
|
|
2014-05-01 04:57:49 +02:00
|
|
|
$this->family = "hr";
|
2020-10-02 16:15:24 +02:00
|
|
|
$this->module_position = '43';
|
2008-10-01 21:10:17 +02:00
|
|
|
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
|
2019-01-27 11:55:16 +01:00
|
|
|
$this->name = preg_replace('/^mod/i', '', get_class($this));
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->description = "Gestion des notes de frais et deplacements"; // Si traduction Module75Desc non trouvee
|
2008-10-01 21:10:17 +02:00
|
|
|
|
2015-11-22 18:41:35 +01:00
|
|
|
// Possible values for version are: 'development', 'experimental', 'dolibarr' or 'dolibarr_deprecated' or version
|
2015-02-14 18:39:45 +01:00
|
|
|
$this->version = 'dolibarr_deprecated';
|
2009-05-04 13:40:00 +02:00
|
|
|
|
2008-10-06 09:39:52 +02:00
|
|
|
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
|
2008-12-17 20:15:54 +01:00
|
|
|
$this->picto = "trip";
|
2008-10-01 21:10:17 +02:00
|
|
|
|
2009-05-04 13:40:00 +02:00
|
|
|
// Data directories to create when module is enabled
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->dirs = array();
|
|
|
|
|
|
|
|
|
|
// Config pages
|
|
|
|
|
$this->config_page_url = array();
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->langfiles = array("companies", "trips");
|
2009-05-04 13:40:00 +02:00
|
|
|
|
|
|
|
|
// Dependancies
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->depends = array();
|
|
|
|
|
$this->requiredby = array();
|
|
|
|
|
|
2009-05-04 13:40:00 +02:00
|
|
|
// Constants
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->const = array();
|
|
|
|
|
|
|
|
|
|
// Boxes
|
|
|
|
|
$this->boxes = array();
|
|
|
|
|
|
|
|
|
|
// Permissions
|
|
|
|
|
$this->rights = array();
|
|
|
|
|
$this->rights_class = 'deplacement';
|
|
|
|
|
|
2010-10-01 19:59:02 +02:00
|
|
|
$this->rights[1][0] = 171;
|
2014-10-30 11:43:57 +01:00
|
|
|
$this->rights[1][1] = 'Lire ses notes de frais et deplacements et celles de sa hierarchy';
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->rights[1][2] = 'r';
|
|
|
|
|
$this->rights[1][3] = 1;
|
|
|
|
|
$this->rights[1][4] = 'lire';
|
|
|
|
|
|
2010-10-01 19:59:02 +02:00
|
|
|
$this->rights[2][0] = 172;
|
2014-10-30 11:43:57 +01:00
|
|
|
$this->rights[2][1] = 'Creer/modifier une note de frais et deplacements';
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->rights[2][2] = 'w';
|
|
|
|
|
$this->rights[2][3] = 0;
|
|
|
|
|
$this->rights[2][4] = 'creer';
|
|
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->rights[3][0] = 173;
|
2014-10-30 11:43:57 +01:00
|
|
|
$this->rights[3][1] = 'Supprimer les notes de frais et deplacements';
|
2008-10-01 21:10:17 +02:00
|
|
|
$this->rights[3][2] = 'd';
|
|
|
|
|
$this->rights[3][3] = 0;
|
|
|
|
|
$this->rights[3][4] = 'supprimer';
|
2014-03-17 14:30:55 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->rights[4][0] = 174;
|
2015-01-18 03:12:19 +01:00
|
|
|
$this->rights[4][1] = 'Lire toutes les notes de frais';
|
|
|
|
|
$this->rights[4][2] = 'd';
|
|
|
|
|
$this->rights[4][3] = 0;
|
|
|
|
|
$this->rights[4][4] = 'readall';
|
|
|
|
|
|
|
|
|
|
$this->rights[5][0] = 178;
|
|
|
|
|
$this->rights[5][1] = 'Exporter les notes de frais et deplacements';
|
|
|
|
|
$this->rights[5][2] = 'd';
|
|
|
|
|
$this->rights[5][3] = 0;
|
|
|
|
|
$this->rights[5][4] = 'export';
|
2008-12-17 20:15:54 +01:00
|
|
|
|
2018-02-25 10:55:02 +01:00
|
|
|
|
2016-09-30 13:02:13 +02:00
|
|
|
// Menus
|
|
|
|
|
//-------
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->menu = 1; // This module add menu entries. They are coded into menu manager.
|
2018-02-25 10:55:02 +01:00
|
|
|
|
|
|
|
|
|
2008-12-17 20:15:54 +01:00
|
|
|
// Exports
|
2020-04-10 10:59:32 +02:00
|
|
|
$r = 0;
|
2009-05-04 13:40:00 +02:00
|
|
|
|
2008-12-17 20:15:54 +01:00
|
|
|
$r++;
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->export_code[$r] = 'trips_'.$r;
|
|
|
|
|
$this->export_label[$r] = 'ListTripsAndExpenses';
|
|
|
|
|
$this->export_permission[$r] = array(array("deplacement", "export"));
|
2020-10-31 14:32:18 +01:00
|
|
|
$this->export_fields_array[$r] = array('u.login'=>'Login', 'u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'd.rowid'=>"TripId", 'd.type'=>"Type", 'd.km'=>"FeesKilometersOrAmout", 'd.dated'=>"Date", 'd.note_private'=>'NotePrivate', 'd.note_public'=>'NotePublic', 's.nom'=>'ThirdParty');
|
|
|
|
|
$this->export_TypeFields_array[$r] = array('u.rowid'=>'List:user:name', 'u.login'=>'Text', 'u.lastname'=>'Text', 'u.firstname'=>'Text', 'd.type'=>"Text", 'd.km'=>"Numeric", 'd.dated'=>"Date", 'd.note_private'=>'Text', 'd.note_public'=>'Text', 's.rowid'=>"List:societe:CompanyName", 's.nom'=>'Text');
|
|
|
|
|
$this->export_entities_array[$r] = array('u.login'=>'user', 'u.lastname'=>'user', 'u.firstname'=>'user', 'd.rowid'=>"trip", 'd.type'=>"trip", 'd.km'=>"trip", 'd.dated'=>"trip", 'd.note_private'=>'trip', 'd.note_public'=>'trip', 's.nom'=>'company');
|
|
|
|
|
$this->export_dependencies_array[$r] = array('trip'=>'d.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
|
2020-04-10 10:59:32 +02:00
|
|
|
|
|
|
|
|
$this->export_sql_start[$r] = 'SELECT DISTINCT ';
|
|
|
|
|
$this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'user as u';
|
|
|
|
|
$this->export_sql_end[$r] .= ', '.MAIN_DB_PREFIX.'deplacement as d';
|
|
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid';
|
2021-02-23 22:03:23 +01:00
|
|
|
if (empty($user->rights->societe->client->voir)) {
|
|
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$this->export_sql_end[$r] .= ' WHERE d.fk_user = u.rowid';
|
|
|
|
|
$this->export_sql_end[$r] .= ' AND d.entity IN ('.getEntity('deplacement').')';
|
2021-02-23 22:03:23 +01:00
|
|
|
if (empty($user->rights->societe->client->voir)) {
|
|
|
|
|
$this->export_sql_end[$r] .= ' AND (sc.fk_user = '.(empty($user) ? 0 : $user->id).' OR d.fk_soc IS NULL)';
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
|
2021-02-23 22:03:23 +01:00
|
|
|
if (!empty($user)) { // Not defined during migration process
|
2020-10-31 14:32:18 +01:00
|
|
|
$childids = $user->getAllChildIds();
|
|
|
|
|
$childids[] = $user->id;
|
2018-02-25 10:55:02 +01:00
|
|
|
|
2021-02-23 22:03:23 +01:00
|
|
|
if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) {
|
2021-03-22 12:00:41 +01:00
|
|
|
$this->export_sql_end[$r] .= ' AND d.fk_user IN ('.$this->db->sanitize(join(',', $childids)).')';
|
2021-02-23 22:03:23 +01:00
|
|
|
}
|
2017-01-12 10:59:27 +01:00
|
|
|
}
|
2008-10-01 21:10:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-04 21:23:50 +01:00
|
|
|
* Function called when module is enabled.
|
|
|
|
|
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
|
|
|
|
|
* It also creates data directories
|
|
|
|
|
*
|
2020-10-31 14:32:18 +01:00
|
|
|
* @param string $options Options when enabling module ('', 'noboxes')
|
2012-01-04 21:23:50 +01:00
|
|
|
* @return int 1 if OK, 0 if KO
|
2008-10-01 21:10:17 +02:00
|
|
|
*/
|
2019-02-26 21:13:07 +01:00
|
|
|
public function init($options = '')
|
2008-10-01 21:10:17 +02:00
|
|
|
{
|
|
|
|
|
// Permissions
|
2012-03-03 17:37:45 +01:00
|
|
|
$this->remove($options);
|
2008-10-01 21:10:17 +02:00
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
return $this->_init($sql, $options);
|
2008-10-01 21:10:17 +02:00
|
|
|
}
|
2005-01-12 20:40:51 +01:00
|
|
|
}
|