2004-10-20 00:24:10 +02:00
< ? php
2005-07-30 21:50:08 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2014-04-02 13:17:20 +02:00
* Copyright ( C ) 2004 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
2005-05-14 16:22:08 +02:00
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2013-07-17 18:45:58 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2023-03-08 11:00:58 +01:00
* Copyright ( C ) 2014 Charles - Fr BENKE < charles . fr @ benke . fr >
* Copyright ( C ) 2023 Gauthier VERDOL < gauthier . verdol @ atm - consulting . fr >
2003-08-11 20:43:06 +02: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
2003-08-11 20:43:06 +02: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 />.
2003-08-11 20:43:06 +02:00
*/
2010-02-07 18:55:54 +01:00
/**
2010-07-11 15:27:26 +02:00
* \defgroup projet Module project
* \brief Module to create projects / tasks / gantt diagram . Projects can them be affected to tasks .
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modProjet . class . php
2008-10-28 21:37:30 +01:00
* \ingroup projet
2021-03-20 13:55:43 +01:00
* \brief Description and activation file for the module project
2008-10-01 21:10:17 +02:00
*/
2020-02-21 17:53:37 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2003-11-13 16:09:12 +01:00
2006-01-22 19:31:56 +01:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module Projet
2008-10-01 21:10:17 +02:00
*/
2003-11-13 16:09:12 +01:00
class modProjet extends DolibarrModules
2003-08-11 20:43:06 +02:00
{
2008-10-01 21:10:17 +02:00
/**
2011-09-26 16:22:35 +02:00
* Constructor . Define names , constants , directories , boxes , permissions
*
2012-01-04 21:23:50 +01: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
{
2012-10-26 15:20:47 +02:00
global $conf ;
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 400 ;
2008-10-01 21:10:17 +02:00
$this -> family = " projects " ;
2019-06-21 13:25:40 +02:00
$this -> module_position = '14' ;
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 ));
2024-01-13 19:48:20 +01:00
$this -> description = " Gestion des projects " ;
2008-12-15 23:25:59 +01:00
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
2008-10-06 09:39:52 +02:00
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2013-04-12 11:09:53 +02:00
$this -> config_page_url = array ( " project.php@projet " );
2020-02-21 17:53:37 +01:00
$this -> picto = 'project' ;
2008-10-01 21:10:17 +02:00
2009-05-04 13:40:00 +02:00
// Data directories to create when module is enabled
2010-03-02 18:13:39 +01:00
$this -> dirs = array ( " /projet/temp " );
2009-05-04 13:40:00 +02:00
2018-07-10 09:32:55 +02:00
// Dependencies
2020-02-21 17:53:37 +01:00
$this -> hidden = false ; // A condition to hide module
$this -> depends = array (); // List of module class names as string that must be enabled if this module is enabled
2021-09-01 15:16:11 +02:00
$this -> requiredby = array ( 'modEventOrganization' ); // List of module ids to disable if this one is disabled
2020-02-21 17:53:37 +01:00
$this -> conflictwith = array (); // List of module class names as string this module is in conflict with
2022-09-27 20:48:47 +02:00
$this -> phpmin = array ( 7 , 0 ); // Minimum version of PHP required by module
2012-11-20 12:11:19 +01:00
$this -> langfiles = array ( 'projects' );
2008-10-01 21:10:17 +02:00
2009-01-12 10:53:45 +01:00
// Constants
2008-10-01 21:10:17 +02:00
$this -> const = array ();
2020-02-21 17:53:37 +01:00
$r = 0 ;
2010-02-07 18:55:54 +01:00
2010-02-02 14:27:59 +01:00
$this -> const [ $r ][ 0 ] = " PROJECT_ADDON_PDF " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " baleine " ;
2013-07-18 10:24:45 +02:00
$this -> const [ $r ][ 3 ] = 'Name of PDF/ODT project manager class' ;
2010-02-02 14:27:59 +01:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
$this -> const [ $r ][ 0 ] = " PROJECT_ADDON " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2010-02-09 17:00:26 +01:00
$this -> const [ $r ][ 2 ] = " mod_project_simple " ;
2013-07-18 10:24:45 +02:00
$this -> const [ $r ][ 3 ] = 'Name of Numbering Rule project manager class' ;
2010-02-02 14:27:59 +01:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2008-10-01 21:10:17 +02:00
2013-03-25 19:28:34 +01:00
$this -> const [ $r ][ 0 ] = " PROJECT_ADDON_PDF_ODT_PATH " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2013-04-08 18:02:12 +02:00
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/projects " ;
2013-03-25 19:28:34 +01:00
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
2014-02-17 12:12:18 +01:00
$r ++ ;
2015-02-22 13:16:49 +01:00
2013-07-17 18:45:58 +02:00
$this -> const [ $r ][ 0 ] = " PROJECT_TASK_ADDON_PDF " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2013-07-18 10:24:45 +02:00
$this -> const [ $r ][ 2 ] = " " ;
$this -> const [ $r ][ 3 ] = 'Name of PDF/ODT tasks manager class' ;
2013-07-17 18:45:58 +02:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2015-02-22 13:16:49 +01:00
2013-07-17 18:45:58 +02:00
$this -> const [ $r ][ 0 ] = " PROJECT_TASK_ADDON " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " mod_task_simple " ;
2013-07-18 10:24:45 +02:00
$this -> const [ $r ][ 3 ] = 'Name of Numbering Rule task manager class' ;
2013-07-17 18:45:58 +02:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2015-02-22 13:16:49 +01:00
2013-07-17 18:45:58 +02:00
$this -> const [ $r ][ 0 ] = " PROJECT_TASK_ADDON_PDF_ODT_PATH " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/tasks " ;
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
2015-09-26 10:53:59 +02:00
$r ++ ;
2017-06-13 18:50:31 +02:00
2016-01-14 11:22:59 +01:00
$this -> const [ $r ][ 0 ] = " PROJECT_USE_OPPORTUNITIES " ;
2015-09-26 10:53:59 +02:00
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " 1 " ;
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
2016-06-15 13:37:50 +02:00
$r ++ ;
2017-06-13 18:50:31 +02:00
2009-01-12 10:53:45 +01:00
// Boxes
2020-12-07 11:42:35 +01:00
$this -> boxes = array (
2023-05-05 14:22:32 +02:00
0 => array ( 'file' => 'box_project.php' , 'enabledbydefaulton' => 'Home' ), // open projects
1 => array ( 'file' => 'box_project_opportunities.php' , 'enabledbydefaulton' => 'Home' ), // open opportunities
2 => array ( 'file' => 'box_task.php' , 'enabledbydefaulton' => 'Home' ),
3 => array ( 'file' => 'box_validated_projects.php' , 'enabledbydefaulton' => 'Home' ), // task without timespent
4 => array ( 'file' => 'box_funnel_of_prospection.php' , 'enabledbydefaulton' => 'Home' ),
2020-12-07 11:42:35 +01:00
);
2024-02-20 00:44:09 +01:00
// Cronjobs
$this -> cronjobs [] = array (
'label' => 'WeeklyWorkingHoursReport' ,
'jobtype' => 'method' ,
'class' => 'projet/class/project.class.php' ,
'objectname' => 'Project' ,
'method' => 'createWeeklyReport' ,
'parameters' => '' ,
'comment' => 'Generates and sends a weekly report on time worked' ,
'frequency' => 1 ,
'unitfrequency' => 86400 * 7 ,
'status' => 0 ,
'test' => '$conf->projet->enabled' ,
);
2008-10-01 21:10:17 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'projet' ;
2020-02-21 17:53:37 +01:00
$r = 0 ;
2010-02-02 14:27:59 +01:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 41 ; // id de la permission
2022-05-06 11:17:29 +02:00
$this -> rights [ $r ][ 1 ] = " Read projects and tasks (shared projects or projects I am contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'r' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 42 ; // id de la permission
2015-06-20 20:35:57 +02:00
$this -> rights [ $r ][ 1 ] = " Create/modify projects and tasks (shared projects or projects I am contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'w' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 4 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 44 ; // id de la permission
2015-06-20 20:35:57 +02:00
$this -> rights [ $r ][ 1 ] = " Delete project and tasks (shared projects or projects I am contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'd' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
2010-02-07 18:55:54 +01:00
2014-01-15 14:49:22 +01:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 45 ; // id de la permission
2015-06-20 20:35:57 +02:00
$this -> rights [ $r ][ 1 ] = " Export projects " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'd' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2014-01-15 14:49:22 +01:00
$this -> rights [ $r ][ 4 ] = 'export' ;
2015-02-22 13:16:49 +01:00
2010-02-02 14:27:59 +01:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 141 ; // id de la permission
2015-06-20 20:35:57 +02:00
$this -> rights [ $r ][ 1 ] = " Read all projects and tasks (also private projects I am not contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'r' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-10 16:48:45 +01:00
$this -> rights [ $r ][ 4 ] = 'all' ;
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 5 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 142 ; // id de la permission
2022-05-06 11:17:29 +02:00
$this -> rights [ $r ][ 1 ] = " Create/modify all projects and tasks (also private projects I am not contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'w' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-10 16:48:45 +01:00
$this -> rights [ $r ][ 4 ] = 'all' ;
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 5 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 144 ; // id de la permission
2015-06-20 20:35:57 +02:00
$this -> rights [ $r ][ 1 ] = " Delete all projects and tasks (also private projects I am not contact for) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'd' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2010-02-10 16:48:45 +01:00
$this -> rights [ $r ][ 4 ] = 'all' ;
2010-02-02 14:27:59 +01:00
$this -> rights [ $r ][ 5 ] = 'supprimer' ;
2012-10-25 22:30:17 +02:00
2021-07-16 11:14:30 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 145 ; // id de la permission
$this -> rights [ $r ][ 1 ] = " Can enter time consumed on assigned tasks (timesheet) " ; // libelle de la permission
2024-01-13 19:48:20 +01:00
$this -> rights [ $r ][ 2 ] = 'w' ; // type de la permission (deprecated)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par default
2021-07-16 11:14:30 +02:00
$this -> rights [ $r ][ 4 ] = 'time' ;
2012-10-25 22:30:17 +02:00
2016-09-30 13:02:13 +02:00
// Menus
//-------
2020-02-21 17:53:37 +01:00
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2016-11-19 02:16:12 +01:00
2017-06-13 18:50:31 +02:00
2022-12-05 15:31:05 +01:00
// Exports
2012-10-25 22:30:17 +02:00
//--------
2020-02-21 17:53:37 +01:00
$r = 1 ;
2012-10-25 22:30:17 +02:00
2020-02-21 17:53:37 +01:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'ProjectsAndTasksLines' ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_permission [ $r ] = array ( array ( " projet " , " export " ));
$this -> export_dependencies_array [ $r ] = array ( 'projecttask' => 'pt.rowid' , 'task_time' => 'ptt.rowid' );
2020-02-18 12:51:53 +01:00
2020-02-21 17:53:37 +01:00
$this -> export_TypeFields_array [ $r ] = array (
2022-05-17 00:50:59 +02:00
's.rowid' => " Numeric " , 's.nom' => 'Text' , 's.address' => 'Text' , 's.zip' => 'Text' , 's.town' => 'Text' , 's.fk_pays' => 'List:c_country:label' ,
2020-02-21 17:53:37 +01:00
's.phone' => 'Text' , 's.email' => 'Text' , 's.siren' => 'Text' , 's.siret' => 'Text' , 's.ape' => 'Text' , 's.idprof4' => 'Text' , 's.code_compta' => 'Text' , 's.code_compta_fournisseur' => 'Text' ,
2022-05-17 00:50:59 +02:00
'p.rowid' => " Numeric " , 'p.ref' => " Text " , 'p.title' => " Text " ,
2020-02-18 12:51:53 +01:00
'p.usage_opportunity' => 'Boolean' , 'p.usage_task' => 'Boolean' , 'p.usage_bill_time' => 'Boolean' ,
2022-04-28 12:12:20 +02:00
'p.datec' => " Date " , 'p.dateo' => " Date " , 'p.datee' => " Date " , 'p.fk_statut' => 'Status' , 'cls.code' => " Text " , 'p.opp_percent' => 'Numeric' , 'p.opp_amount' => 'Numeric' , 'p.description' => " Text " , 'p.entity' => 'Numeric' , 'p.budget_amount' => 'Numeric' ,
2020-02-21 17:53:37 +01:00
'pt.rowid' => 'Numeric' , 'pt.ref' => 'Text' , 'pt.label' => 'Text' , 'pt.dateo' => " Date " , 'pt.datee' => " Date " , 'pt.duration_effective' => " Duree " , 'pt.planned_workload' => " Numeric " , 'pt.progress' => " Numeric " , 'pt.description' => " Text " ,
2023-03-08 11:00:58 +01:00
'ptt.rowid' => 'Numeric' , 'ptt.element_date' => 'Date' , 'ptt.element_duration' => " Duree " , 'ptt.fk_user' => " FormSelect:select_dolusers " , 'ptt.note' => " Text "
2020-02-18 12:51:53 +01:00
);
2020-02-21 17:53:37 +01:00
$this -> export_entities_array [ $r ] = array (
's.rowid' => " company " , 's.nom' => 'company' , 's.address' => 'company' , 's.zip' => 'company' , 's.town' => 'company' , 's.fk_pays' => 'company' ,
's.phone' => 'company' , 's.email' => 'company' , 's.siren' => 'company' , 's.siret' => 'company' , 's.ape' => 'company' , 's.idprof4' => 'company' , 's.code_compta' => 'company' , 's.code_compta_fournisseur' => 'company'
2020-02-18 12:51:53 +01:00
);
2020-02-21 17:53:37 +01:00
$this -> export_fields_array [ $r ] = array (
's.rowid' => " IdCompany " , 's.nom' => 'CompanyName' , 's.address' => 'Address' , 's.zip' => 'Zip' , 's.town' => 'Town' , 's.fk_pays' => 'Country' ,
's.phone' => 'Phone' , 's.email' => 'Email' , 's.siren' => 'ProfId1' , 's.siret' => 'ProfId2' , 's.ape' => 'ProfId3' , 's.idprof4' => 'ProfId4' , 's.code_compta' => 'CustomerAccountancyCode' , 's.code_compta_fournisseur' => 'SupplierAccountancyCode' ,
'p.rowid' => " ProjectId " , 'p.ref' => " RefProject " , 'p.title' => 'ProjectLabel' ,
2020-02-18 12:51:53 +01:00
'p.usage_opportunity' => 'ProjectFollowOpportunity' , 'p.usage_task' => 'ProjectFollowTasks' , 'p.usage_bill_time' => 'BillTime' ,
2022-04-28 12:12:20 +02:00
'p.datec' => " DateCreation " , 'p.dateo' => " DateStart " , 'p.datee' => " DateEnd " , 'p.fk_statut' => 'ProjectStatus' , 'cls.code' => 'OpportunityStatus' , 'p.opp_percent' => 'OpportunityProbability' , 'p.opp_amount' => 'OpportunityAmount' , 'p.budget_amount' => 'Budget' , 'p.description' => " Description "
2020-02-18 12:51:53 +01:00
);
2020-10-31 14:32:18 +01:00
// Add multicompany field
2023-11-27 11:39:32 +01:00
if ( getDolGlobalString ( 'MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED' )) {
2020-10-31 14:32:18 +01:00
$nbofallowedentities = count ( explode ( ',' , getEntity ( 'project' ))); // If project are shared, nb will be > 1
2022-08-28 14:05:07 +02:00
if ( isModEnabled ( 'multicompany' ) && $nbofallowedentities > 1 ) {
2021-02-23 22:03:23 +01:00
$this -> export_fields_array [ $r ] += array ( 'p.entity' => 'Entity' );
}
2020-10-31 14:32:18 +01:00
}
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'PROJECT_USE_OPPORTUNITIES' )) {
2020-10-31 14:32:18 +01:00
unset ( $this -> export_fields_array [ $r ][ 'p.opp_percent' ]);
unset ( $this -> export_fields_array [ $r ][ 'p.opp_amount' ]);
unset ( $this -> export_fields_array [ $r ][ 'cls.code' ]);
2017-01-26 10:41:02 +01:00
}
2017-06-13 18:50:31 +02:00
2014-04-10 18:16:56 +02:00
// Add fields for project
2020-02-21 17:53:37 +01:00
$this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ());
2017-06-13 18:50:31 +02:00
// Add extra fields for project
2021-03-01 20:37:16 +01:00
$keyforselect = 'projet' ;
$keyforelement = 'project' ;
$keyforaliasextra = 'extra' ;
2016-12-06 11:52:07 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2014-04-10 18:16:56 +02:00
// Add fields for tasks
2020-02-21 17:53:37 +01:00
$this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'pt.rowid' => 'TaskId' , 'pt.ref' => 'RefTask' , 'pt.label' => 'LabelTask' , 'pt.dateo' => " TaskDateStart " , 'pt.datee' => " TaskDateEnd " , 'pt.duration_effective' => " DurationEffective " , 'pt.planned_workload' => " PlannedWorkload " , 'pt.progress' => " Progress " , 'pt.description' => " TaskDescription " ));
$this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'pt.rowid' => 'projecttask' , 'pt.ref' => 'projecttask' , 'pt.label' => 'projecttask' , 'pt.dateo' => " projecttask " , 'pt.datee' => " projecttask " , 'pt.duration_effective' => " projecttask " , 'pt.planned_workload' => " projecttask " , 'pt.progress' => " projecttask " , 'pt.description' => " projecttask " ));
2020-10-31 14:32:18 +01:00
// Add extra fields for task
2021-03-01 20:37:16 +01:00
$keyforselect = 'projet_task' ;
$keyforelement = 'projecttask' ;
$keyforaliasextra = 'extra2' ;
2016-12-06 11:52:07 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2020-10-31 14:32:18 +01:00
// End add extra fields
2024-01-19 10:45:00 +01:00
$this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'ptt.rowid' => 'IdTaskTime' , 'ptt.element_date' => 'TaskTimeDate' , 'ptt.element_duration' => " TimeSpent " , 'ptt.fk_user' => " TaskTimeUser " , 'ptt.note' => " TaskTimeNote " ));
2023-03-08 11:00:58 +01:00
$this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'ptt.rowid' => 'task_time' , 'ptt.element_date' => 'task_time' , 'ptt.element_duration' => " task_time " , 'ptt.fk_user' => " task_time " , 'ptt.note' => " task_time " ));
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'PROJECT_HIDE_TASKS' )) {
2020-02-21 17:53:37 +01:00
$this -> export_fields_array [ $r ] = array_merge ( $this -> export_fields_array [ $r ], array ( 'f.ref' => " Billed " ));
$this -> export_entities_array [ $r ] = array_merge ( $this -> export_entities_array [ $r ], array ( 'f.ref' => " task_time " ));
2020-02-18 12:22:25 +01:00
}
2020-10-31 14:32:18 +01:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
2020-02-21 17:53:37 +01:00
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'projet as p' ;
2020-10-31 14:32:18 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet_extrafields as extra ON p.rowid = extra.fk_object' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_lead_status as cls ON p.fk_opp_status = cls.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . " projet_task as pt ON p.rowid = pt.fk_projet " ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'projet_task_extrafields as extra2 ON pt.rowid = extra2.fk_object' ;
2023-03-08 11:00:58 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . " element_time as ptt ON (pt.rowid = ptt.fk_element AND ptt.elementtype = 'task') " ;
2020-02-21 17:53:37 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe as s ON p.fk_soc = s.rowid' ;
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'PROJECT_HIDE_TASKS' )) {
2020-02-21 17:53:37 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'facture as f ON ptt.invoice_id = f.rowid' ;
2020-02-18 12:22:25 +01:00
}
2020-02-21 17:53:37 +01:00
$this -> export_sql_end [ $r ] .= " WHERE p.entity IN ( " . getEntity ( 'project' ) . " ) " ;
2017-06-13 18:50:31 +02:00
2022-12-05 15:31:05 +01:00
// Import project/opportunities
$r ++ ;
$this -> import_code [ $r ] = 'projects' ;
$this -> import_label [ $r ] = 'ImportDatasetProjects' ;
$this -> import_icon [ $r ] = 'project' ;
$this -> import_entities_array [ $r ] = array (); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 't' => MAIN_DB_PREFIX . 'projet' , 'extra' => MAIN_DB_PREFIX . 'projet_extrafields' ); // List of tables to insert into (insert done in same order)
$this -> import_fields_array [ $r ] = array ( 't.ref' => 'ProjectRef*' , 't.title' => 'Label*' , 't.description' => " Description " , 't.fk_soc' => 'ThirdPartyName' , 't.public' => " Public " , 't.fk_statut' => " Status " );
$this -> import_fields_array [ $r ] = array_merge ( $this -> import_fields_array [ $r ], array ( 't.fk_opp_status' => " OpportunityStatus " , 't.opp_percent' => " OpportunityProbability " , 't.opp_amount' => " OpportunityAmount " , 't.note_public' => " NotePublic " , 't.note_private' => " NotePrivate " , 't.budget_amount' => " Budget " , 't.dateo' => " DateStart " , 't.datee' => " DateEnd " ));
// Add extra fields
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type <> 'separate' AND elementtype = 'projet' AND entity IN (0, " . $conf -> entity . " ) " ;
$resql = $this -> db -> query ( $sql );
if ( $resql ) { // This can fail when class is used on old database (during migration for example)
while ( $obj = $this -> db -> fetch_object ( $resql )) {
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
}
}
// End add extra fields
$this -> import_fieldshidden_array [ $r ] = array ( 't.fk_user_creat' => 'user->id' , 'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'projet' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this -> import_convertvalue_array [ $r ] = array (
2023-11-27 11:39:32 +01:00
't.ref' => array ( 'rule' => 'getrefifauto' , 'class' => ( ! getDolGlobalString ( 'PROJECT_ADDON' ) ? 'mod_project_simple' : $conf -> global -> PROJECT_ADDON ), 'path' => " /core/modules/project/ " . ( ! getDolGlobalString ( 'PROJECT_ADDON' ) ? 'mod_project_simple' : $conf -> global -> PROJECT_ADDON ) . '.php' ),
2022-12-05 15:31:05 +01:00
't.fk_soc' => array (
'rule' => 'fetchidfromref' ,
'file' => '/societe/class/societe.class.php' ,
'class' => 'Societe' ,
'method' => 'fetch' ,
'element' => 'ThirdParty'
),
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this -> import_regex_array [ $r ] = array ( 't.dateo' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' , 't.datee' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' , 't.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$' );
$this -> import_examplevalues_array [ $r ] = array ( 't.fk_soc' => 'ThirdParty' , 't.ref' => " auto or PJ2010-1234 " , 't.title' => " My project " , 't.fk_statut' => '0,1 or 2' , 't.datec' => '1972-10-10' , 't.note_private' => " My private note " , 't.note_public' => " My public note " );
2017-06-13 18:50:31 +02:00
2016-11-19 02:16:12 +01:00
// Import list of tasks
2023-11-27 11:39:32 +01:00
if ( ! getDolGlobalString ( 'PROJECT_HIDE_TASKS' )) {
2020-10-31 14:32:18 +01:00
$r ++ ;
$this -> import_code [ $r ] = 'tasksofprojects' ;
$this -> import_label [ $r ] = 'ImportDatasetTasks' ;
$this -> import_icon [ $r ] = 'task' ;
$this -> import_entities_array [ $r ] = array ( 't.fk_projet' => 'project' ); // We define here only fields that use another icon that the one defined into import_icon
$this -> import_tables_array [ $r ] = array ( 't' => MAIN_DB_PREFIX . 'projet_task' , 'extra' => MAIN_DB_PREFIX . 'projet_task_extrafields' ); // List of tables to insert into (insert done in same order)
$this -> import_fields_array [ $r ] = array ( 't.fk_projet' => 'ProjectRef*' , 't.ref' => 'RefTask*' , 't.label' => 'LabelTask*' , 't.dateo' => " DateStart " , 't.datee' => " DateEnd " , 't.planned_workload' => " PlannedWorkload " , 't.progress' => " Progress " , 't.note_private' => " NotePrivate " , 't.note_public' => " NotePublic " , 't.datec' => " DateCreation " );
// Add extra fields
2021-10-31 14:33:44 +01:00
$sql = " SELECT name, label, fieldrequired FROM " . MAIN_DB_PREFIX . " extrafields WHERE type <> 'separate' AND elementtype = 'projet_task' AND entity IN (0, " . $conf -> entity . " ) " ;
2020-10-31 14:32:18 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) { // This can fail when class is used on old database (during migration for example)
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-10-31 14:32:18 +01:00
$fieldname = 'extra.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$this -> import_fields_array [ $r ][ $fieldname ] = $fieldlabel . ( $obj -> fieldrequired ? '*' : '' );
}
}
// End add extra fields
$this -> import_fieldshidden_array [ $r ] = array ( 't.fk_user_creat' => 'user->id' , 'extra.fk_object' => 'lastrowid-' . MAIN_DB_PREFIX . 'projet_task' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent)
$this -> import_convertvalue_array [ $r ] = array (
't.fk_projet' => array ( 'rule' => 'fetchidfromref' , 'classfile' => '/projet/class/project.class.php' , 'class' => 'Project' , 'method' => 'fetch' , 'element' => 'Project' ),
2023-11-27 11:39:32 +01:00
't.ref' => array ( 'rule' => 'getrefifauto' , 'class' => ( ! getDolGlobalString ( 'PROJECT_TASK_ADDON' ) ? 'mod_task_simple' : $conf -> global -> PROJECT_TASK_ADDON ), 'path' => " /core/modules/project/task/ " . ( ! getDolGlobalString ( 'PROJECT_TASK_ADDON' ) ? 'mod_task_simple' : $conf -> global -> PROJECT_TASK_ADDON ) . '.php' )
2020-10-31 14:32:18 +01:00
);
//$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t');
$this -> import_regex_array [ $r ] = array ( 't.dateo' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' , 't.datee' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$' , 't.datec' => '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$' );
$this -> import_examplevalues_array [ $r ] = array ( 't.fk_projet' => 'MyProjectRef' , 't.ref' => " auto or TK2010-1234 " , 't.label' => " My task " , 't.progress' => " 0 (not started) to 100 (finished) " , 't.datec' => '1972-10-10' , 't.note_private' => " My private note " , 't.note_public' => " My public note " );
2017-06-13 18:50:31 +02: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
{
2020-02-21 17:53:37 +01:00
global $conf , $langs ;
2010-07-11 15:27:26 +02:00
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
2014-04-02 13:17:20 +02:00
//ODT template for project
2020-02-21 17:53:37 +01:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/projects/template_project.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/projects' ;
$dest = $dirodt . '/template_project.odt' ;
2014-04-02 13:17:20 +02:00
2021-02-23 22:03:23 +01:00
if ( file_exists ( $src ) && ! file_exists ( $dest )) {
2014-04-02 13:17:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_mkdir ( $dirodt );
2020-02-21 17:53:37 +01:00
$result = dol_copy ( $src , $dest , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2014-04-02 13:17:20 +02:00
$langs -> load ( " errors " );
2020-02-21 17:53:37 +01:00
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
2014-04-02 13:17:20 +02:00
return 0 ;
}
}
//ODT template for tasks
2020-02-21 17:53:37 +01:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/tasks/template_task_summary.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/tasks' ;
$dest = $dirodt . '/template_task_summary.odt' ;
2014-04-02 13:17:20 +02:00
2021-02-23 22:03:23 +01:00
if ( file_exists ( $src ) && ! file_exists ( $dest )) {
2014-04-02 13:17:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_mkdir ( $dirodt );
2020-02-21 17:53:37 +01:00
$result = dol_copy ( $src , $dest , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2014-04-02 13:17:20 +02:00
$langs -> load ( " errors " );
2020-02-21 17:53:37 +01:00
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
2014-04-02 13:17:20 +02:00
return 0 ;
}
}
2015-02-22 13:16:49 +01:00
2018-05-06 13:36:37 +02:00
$sql = array ();
2021-08-27 22:42:04 +02:00
$sql [] = " DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = ' " . $this -> db -> escape ( $this -> const [ 3 ][ 2 ]) . " ' AND type = 'task' AND entity = " . (( int ) $conf -> entity );
$sql [] = " INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES(' " . $this -> db -> escape ( $this -> const [ 3 ][ 2 ]) . " ','task', " . (( int ) $conf -> entity ) . " ) " ;
$sql [] = " DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = 'beluga' AND type = 'project' AND entity = " . (( int ) $conf -> entity );
$sql [] = " INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES('beluga','project', " . (( int ) $conf -> entity ) . " ) " ;
$sql [] = " DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = 'baleine' AND type = 'project' AND entity = " . (( int ) $conf -> entity );
$sql [] = " INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES('baleine','project', " . (( int ) $conf -> entity ) . " ) " ;
2018-10-01 18:56:47 +02:00
2010-07-11 15:27:26 +02:00
2019-01-27 11:55:16 +01:00
return $this -> _init ( $sql , $options );
2008-10-01 21:10:17 +02:00
}
2003-08-11 20:43:06 +02:00
}