modFicheinter.class.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \defgroup ficheinter Module Interventions
  24. * \brief Module to manage intervention cards
  25. * \file htdocs/core/modules/modFicheinter.class.php
  26. * \ingroup ficheinter
  27. * \brief Description and activation file for the module Ficheinter
  28. */
  29. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  30. /**
  31. * Class to describe and enable module Ficheinter
  32. */
  33. class modFicheinter extends DolibarrModules
  34. {
  35. /**
  36. * Constructor. Define names, constants, directories, boxes, permissions
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. public function __construct($db)
  41. {
  42. global $conf;
  43. $this->db = $db;
  44. $this->numero = 70;
  45. $this->family = "crm";
  46. $this->module_position = '41';
  47. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  48. $this->name = preg_replace('/^mod/i', '', get_class($this));
  49. $this->description = "Gestion des fiches d'intervention";
  50. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  51. $this->version = 'dolibarr';
  52. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  53. $this->picto = "intervention";
  54. // Data directories to create when module is enabled
  55. $this->dirs = array("/ficheinter/temp");
  56. // Dependencies
  57. $this->depends = array("modSociete");
  58. $this->requiredby = array();
  59. $this->conflictwith = array();
  60. $this->langfiles = array("bills", "companies", "interventions");
  61. // Config pages
  62. $this->config_page_url = array("fichinter.php");
  63. // Constants
  64. $this->const = array();
  65. $r = 0;
  66. $this->const[$r][0] = "FICHEINTER_ADDON_PDF";
  67. $this->const[$r][1] = "chaine";
  68. $this->const[$r][2] = "soleil";
  69. $r++;
  70. $this->const[$r][0] = "FICHEINTER_ADDON";
  71. $this->const[$r][1] = "chaine";
  72. $this->const[$r][2] = "pacific";
  73. $r++;
  74. // Boxes
  75. $this->boxes = array(0=>array('file'=>'box_ficheinter.php', 'enabledbydefaulton'=>'Home'));
  76. // Permissions
  77. $this->rights = array();
  78. $this->rights_class = 'ficheinter';
  79. $r = 0;
  80. $r++;
  81. $this->rights[$r][0] = 61;
  82. $this->rights[$r][1] = 'Lire les fiches d\'intervention';
  83. $this->rights[$r][2] = 'r';
  84. $this->rights[$r][3] = 0;
  85. $this->rights[$r][4] = 'lire';
  86. $r++;
  87. $this->rights[$r][0] = 62;
  88. $this->rights[$r][1] = 'Creer/modifier les fiches d\'intervention';
  89. $this->rights[$r][2] = 'w';
  90. $this->rights[$r][3] = 0;
  91. $this->rights[$r][4] = 'creer';
  92. $r++;
  93. $this->rights[$r][0] = 64;
  94. $this->rights[$r][1] = 'Supprimer les fiches d\'intervention';
  95. $this->rights[$r][2] = 'd';
  96. $this->rights[$r][3] = 0;
  97. $this->rights[$r][4] = 'supprimer';
  98. $r++;
  99. $this->rights[$r][0] = 67;
  100. $this->rights[$r][1] = 'Exporter les fiches interventions';
  101. $this->rights[$r][2] = 'r';
  102. $this->rights[$r][3] = 0;
  103. $this->rights[$r][4] = 'export';
  104. $r++;
  105. $this->rights[$r][0] = 68;
  106. $this->rights[$r][1] = 'Envoyer les fiches d\'intervention par courriel';
  107. $this->rights[$r][2] = 'r';
  108. $this->rights[$r][3] = 0;
  109. $this->rights[$r][4] = 'ficheinter_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  110. $this->rights[$r][5] = 'send';
  111. $r++;
  112. $this->rights[$r][0] = 69;
  113. $this->rights[$r][1] = 'Valider les fiches d\'intervention ';
  114. $this->rights[$r][2] = 'a';
  115. $this->rights[$r][3] = 0;
  116. $this->rights[$r][4] = 'ficheinter_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  117. $this->rights[$r][5] = 'validate';
  118. $r++;
  119. $this->rights[$r][0] = 70;
  120. $this->rights[$r][1] = 'Dévalider les fiches d\'intervention';
  121. $this->rights[$r][2] = 'a';
  122. $this->rights[$r][3] = 0;
  123. $this->rights[$r][4] = 'ficheinter_advance'; // Visible if option MAIN_USE_ADVANCED_PERMS is on
  124. $this->rights[$r][5] = 'unvalidate';
  125. // Menus
  126. //-------
  127. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  128. //Exports
  129. //--------
  130. $r = 1;
  131. $this->export_code[$r] = $this->rights_class.'_'.$r;
  132. $this->export_label[$r] = 'InterventionCardsAndInterventionLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  133. $this->export_permission[$r] = array(array("ficheinter", "export"));
  134. $this->export_fields_array[$r] = array(
  135. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 's.fk_pays'=>'Country', 's.phone'=>'Phone',
  136. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
  137. 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 'f.rowid'=>"InterId", 'f.ref'=>"InterRef", 'f.datec'=>"InterDateCreation",
  138. 'f.duree'=>"InterDuration", 'f.fk_statut'=>'InterStatus', 'f.description'=>"InterNote");
  139. $keyforselect = 'fichinter';
  140. $keyforelement = 'intervention';
  141. $keyforaliasextra = 'extra';
  142. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  143. $this->export_fields_array[$r] += array(
  144. 'pj.ref'=>'ProjectRef', 'pj.title'=>'ProjectLabel',
  145. 'fd.rowid'=>'InterLineId',
  146. 'fd.date'=>"InterLineDate", 'fd.duree'=>"InterLineDuration", 'fd.description'=>"InterLineDesc"
  147. );
  148. //$this->export_TypeFields_array[$r]=array(
  149. // 's.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','s.fk_pays'=>'List:c_country:label',
  150. // 's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text',
  151. // 's.code_compta_fournisseur'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.duree'=>"Duree",'f.fk_statut'=>'Statut','f.description'=>"Text",
  152. // 'f.datee'=>"Date",'f.dateo'=>"Date",'f.fulldayevent'=>"Boolean",'fd.date'=>"Date",'fd.duree'=>"Duree",'fd.description'=>"Text",
  153. // 'fd.total_ht'=>"Numeric"
  154. //);
  155. $this->export_TypeFields_array[$r] = array(
  156. 's.rowid'=>"Numeric", 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 's.fk_pays'=>'List:c_country:label', 's.phone'=>'Text', 's.siren'=>'Text',
  157. 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text',
  158. 'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.datec'=>"Date",
  159. 'f.duree'=>"Duree", 'f.fk_statut'=>'Numeric', 'f.description'=>"Text", 'f.datee'=>"Date", 'f.dateo'=>"Date", 'f.fulldayevent'=>"Boolean",
  160. 'pj.ref'=>'Text', 'pj.title'=>'Text',
  161. 'fd.rowid'=>"Numeric", 'fd.date'=>"Date", 'fd.duree'=>"Duree", 'fd.description'=>"Text", 'fd.total_ht'=>"Numeric"
  162. );
  163. $this->export_entities_array[$r] = array(
  164. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 's.fk_pays'=>'company', 's.phone'=>'company',
  165. 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company',
  166. 's.code_compta_fournisseur'=>'company', 'f.rowid'=>"intervention", 'f.ref'=>"intervention", 'f.datec'=>"intervention", 'f.duree'=>"intervention",
  167. 'f.fk_statut'=>"intervention", 'f.description'=>"intervention", 'pj.ref'=>'project', 'pj.title'=>'project', 'fd.rowid'=>"inter_line", 'fd.date'=>"inter_line",
  168. 'fd.duree'=>'inter_line', 'fd.description'=>'inter_line'
  169. );
  170. $this->export_dependencies_array[$r] = array('inter_line'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  171. $keyforselect = 'fichinterdet';
  172. $keyforelement = 'inter_line';
  173. $keyforaliasextra = 'extradet';
  174. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  175. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  176. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'fichinter as f';
  177. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinter_extrafields as extra ON f.rowid = extra.fk_object';
  178. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid';
  179. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinterdet as fd ON f.rowid = fd.fk_fichinter';
  180. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinterdet_extrafields as extradet ON fd.rowid = extradet.fk_object,';
  181. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'societe as s';
  182. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
  183. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('intervention').')';
  184. $r++;
  185. }
  186. /**
  187. * Function called when module is enabled.
  188. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  189. * It also creates data directories
  190. *
  191. * @param string $options Options when enabling module ('', 'noboxes')
  192. * @return int 1 if OK, 0 if KO
  193. */
  194. public function init($options = '')
  195. {
  196. global $conf;
  197. // Permissions
  198. $this->remove($options);
  199. $sql = array(
  200. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'ficheinter' AND entity = ".$conf->entity,
  201. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','ficheinter',".$conf->entity.")",
  202. );
  203. return $this->_init($sql, $options);
  204. }
  205. }