modHoliday.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
  6. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. * or see https://www.gnu.org/
  22. */
  23. /**
  24. * \defgroup holiday Module holiday
  25. * \brief Module de gestion des congés
  26. * \file htdocs/core/modules/modHoliday.class.php
  27. * \ingroup holiday
  28. * \brief Description and activation file for the module holiday
  29. */
  30. include_once DOL_DOCUMENT_ROOT."/core/modules/DolibarrModules.class.php";
  31. /**
  32. * Description and activation class for module holiday
  33. */
  34. class modHoliday extends DolibarrModules
  35. {
  36. /**
  37. * Constructor. Define names, constants, directories, boxes, permissions
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. global $conf, $user; // Required by some include code
  44. $this->db = $db;
  45. // Id for module (must be unique).
  46. // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id).
  47. $this->numero = 20000;
  48. // Key text used to identify module (for permissions, menus, etc...)
  49. $this->rights_class = 'holiday';
  50. // Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
  51. // It is used to group modules in module setup page
  52. $this->family = "hr";
  53. $this->module_position = '42';
  54. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  55. $this->name = preg_replace('/^mod/i', '', get_class($this));
  56. // Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
  57. $this->description = "Leave requests";
  58. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  59. $this->version = 'dolibarr';
  60. // Key used in llx_const table to save module status enabled/disabled (where MYMODULE is value of property name of module in uppercase)
  61. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  62. // Name of image file used for this module.
  63. // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue'
  64. // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module'
  65. $this->picto = 'holiday';
  66. // Data directories to create when module is enabled.
  67. // Example: this->dirs = array("/mymodule/temp");
  68. $this->dirs = array("/holiday/temp");
  69. $r = 0;
  70. // Config pages
  71. $this->config_page_url = array("holiday.php");
  72. // Dependencies
  73. $this->hidden = false; // A condition to hide module
  74. $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled
  75. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  76. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  77. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  78. $this->need_dolibarr_version = array(3, 0); // Minimum version of Dolibarr required by module
  79. $this->langfiles = array("holiday");
  80. // Constants
  81. // Example: $this->const=array(0=>array('MYMODULE_MYNEWCONST1','chaine','myvalue','This is a constant to add',0),
  82. // 1=>array('MYMODULE_MYNEWCONST2','chaine','myvalue','This is another constant to add',0) );
  83. // 2=>array('MAIN_MODULE_MYMODULE_NEEDSMARTY','chaine',1,'Constant to say module need smarty',0)
  84. $this->const = array(); // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 0 or 'allentities')
  85. $r = 0;
  86. $this->const[$r][0] = "HOLIDAY_ADDON";
  87. $this->const[$r][1] = "chaine";
  88. $this->const[$r][2] = "mod_holiday_madonna";
  89. $this->const[$r][3] = 'Nom du gestionnaire de numerotation des congés';
  90. $this->const[$r][4] = 0;
  91. $r++;
  92. $this->const[$r][0] = "HOLIDAY_ADDON_PDF";
  93. $this->const[$r][1] = "chaine";
  94. $this->const[$r][2] = "celebrate";
  95. $this->const[$r][3] = 'Name of PDF model of holiday';
  96. $this->const[$r][4] = 0;
  97. $r++;
  98. $this->const[$r][0] = "HOLIDAY_ADDON_PDF_ODT_PATH";
  99. $this->const[$r][1] = "chaine";
  100. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/holiday";
  101. $this->const[$r][3] = "";
  102. $this->const[$r][4] = 0;
  103. $r++;
  104. // Array to add new pages in new tabs
  105. //$this->tabs[] = array('data'=>'user:+paidholidays:CPTitreMenu:holiday:$user->rights->holiday->read:/holiday/list.php?mainmenu=hrm&id=__ID__'); // We avoid to get one tab for each module. RH data are already in RH tab.
  106. $this->tabs[] = array(); // To add a new tab identified by code tabname1
  107. // Boxes
  108. $this->boxes = array(); // List of boxes
  109. $r = 0;
  110. // Add here list of php file(s) stored in includes/boxes that contains class to show a box.
  111. // Example:
  112. //$this->boxes[$r][1] = "myboxa.php";
  113. //$r++;
  114. //$this->boxes[$r][1] = "myboxb.php";
  115. //$r++;
  116. // Cronjobs
  117. $arraydate = dol_getdate(dol_now());
  118. $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
  119. $this->cronjobs = array(
  120. 0 => array(
  121. 'label' => 'HolidayBalanceMonthlyUpdate:holiday',
  122. 'jobtype' => 'method',
  123. 'class' => 'holiday/class/holiday.class.php',
  124. 'objectname' => 'Holiday',
  125. 'method' => 'updateBalance',
  126. 'parameters' => '',
  127. 'comment' => 'Update holiday balance every month',
  128. 'frequency' => 1,
  129. 'unitfrequency' => 3600 * 24,
  130. 'priority' => 50,
  131. 'status' => 1,
  132. 'test' => '$conf->holiday->enabled',
  133. 'datestart' => $datestart
  134. )
  135. );
  136. // Permissions
  137. $this->rights = array(); // Permission array used by this module
  138. $r = 0;
  139. $this->rights[$r][0] = 20001; // Permission id (must not be already used)
  140. $this->rights[$r][1] = 'Read leave requests (yours and your subordinates)'; // Permission label
  141. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  142. $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  143. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  144. $r++;
  145. $this->rights[$r][0] = 20002; // Permission id (must not be already used)
  146. $this->rights[$r][1] = 'Create/modify leave requests'; // Permission label
  147. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  148. $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  149. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  150. $r++;
  151. $this->rights[$r][0] = 20003; // Permission id (must not be already used)
  152. $this->rights[$r][1] = 'Delete leave requests'; // Permission label
  153. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  154. $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  155. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  156. $r++;
  157. $this->rights[$r][0] = 20007;
  158. $this->rights[$r][1] = 'Approve leave requests';
  159. $this->rights[$r][2] = 'w';
  160. $this->rights[$r][3] = 0;
  161. $this->rights[$r][4] = 'approve';
  162. $r++;
  163. $this->rights[$r][0] = 20004; // Permission id (must not be already used)
  164. $this->rights[$r][1] = 'Read leave requests for everybody'; // Permission label
  165. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  166. $this->rights[$r][4] = 'readall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  167. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  168. $r++;
  169. $this->rights[$r][0] = 20005; // Permission id (must not be already used)
  170. $this->rights[$r][1] = 'Create/modify leave requests for everybody'; // Permission label
  171. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  172. $this->rights[$r][4] = 'writeall'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  173. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  174. $r++;
  175. $this->rights[$r][0] = 20006; // Permission id (must not be already used)
  176. $this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)'; // Permission label
  177. $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
  178. $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  179. $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2)
  180. $r++;
  181. // Menus
  182. //-------
  183. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  184. // Exports
  185. $r = 0;
  186. $r++;
  187. $this->export_code[$r] = 'leaverequest_'.$r;
  188. $this->export_label[$r] = 'ListeCP';
  189. $this->export_icon[$r] = 'holiday';
  190. $this->export_permission[$r] = array(array("holiday", "readall"));
  191. $this->export_fields_array[$r] = array(
  192. 'd.rowid'=>"LeaveId", 'd.fk_type'=>'TypeOfLeaveId', 't.code'=>'TypeOfLeaveCode', 't.label'=>'TypeOfLeaveLabel', 'd.fk_user'=>'UserID',
  193. 'd.date_debut'=>'DateStart', 'd.date_fin'=>'DateEnd', 'd.halfday'=>'HalfDay', 'none.num_open_days'=>'NbUseDaysCP',
  194. 'd.date_valid'=>'DateApprove', 'd.fk_validator'=>"UserForApprovalID",
  195. 'u.lastname'=>'Lastname', 'u.firstname'=>'Firstname', 'u.login'=>"Login",
  196. 'ua.lastname'=>"UserForApprovalLastname", 'ua.firstname'=>"UserForApprovalFirstname",
  197. 'ua.login'=>"UserForApprovalLogin", 'd.description'=>'Description', 'd.statut'=>'Status'
  198. );
  199. $this->export_TypeFields_array[$r] = array(
  200. 'd.rowid'=>"Numeric", 't.code'=>'Text', 't.label'=>'Text', 'd.fk_user'=>'Numeric',
  201. 'd.date_debut'=>'Date', 'd.date_fin'=>'Date', 'none.num_open_days'=>'NumericCompute',
  202. 'd.date_valid'=>'Date', 'd.fk_validator'=>"Numeric",
  203. 'u.lastname'=>'Text', 'u.firstname'=>'Text', 'u.login'=>"Text",
  204. 'ua.lastname'=>"Text", 'ua.firstname'=>"Text",
  205. 'ua.login'=>"Text", 'd.description'=>'Text', 'd.statut'=>'Numeric'
  206. );
  207. $this->export_entities_array[$r] = array(
  208. 'u.lastname'=>'user', 'u.firstname'=>'user', 'u.login'=>'user', 'ua.lastname'=>'user', 'ua.firstname'=>'user', 'ua.login'=>'user'
  209. );
  210. $this->export_alias_array[$r] = array('d.rowid'=>"idholiday");
  211. $this->export_special_array[$r] = array('none.num_open_days'=>'getNumOpenDays');
  212. $this->export_dependencies_array[$r] = array(); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  213. $keyforselect = 'holiday';
  214. $keyforelement = 'holiday';
  215. $keyforaliasextra = 'extra';
  216. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  217. $keyforselect = 'user'; $keyforelement = 'user'; $keyforaliasextra = 'extrau';
  218. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  219. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  220. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'holiday as d';
  221. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'holiday_extrafields as extra on d.rowid = extra.fk_object';
  222. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_holiday_types as t ON t.rowid = d.fk_type';
  223. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua ON ua.rowid = d.fk_validator,';
  224. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'user as u';
  225. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user_extrafields as extrau ON u.rowid = extrau.fk_object';
  226. $this->export_sql_end[$r] .= ' WHERE d.fk_user = u.rowid';
  227. $this->export_sql_end[$r] .= ' AND d.entity IN ('.getEntity('holiday').')';
  228. // Example:
  229. // $this->export_code[$r]=$this->rights_class.'_'.$r;
  230. // $this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  231. // $this->export_permission[$r]=array(array("facture","facture","export"));
  232. // $this->export_fields_array[$r]=array(
  233. // 's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','s.fk_pays'=>'Country','s.phone'=>'Phone',
  234. // 's.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
  235. // 's.code_compta_fournisseur'=>'SupplierAccountancyCode','f.rowid'=>"InvoiceId",'f.ref'=>"InvoiceRef",'f.datec'=>"InvoiceDateCreation",
  236. // 'f.datef'=>"DateInvoice",'f.total_ht'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.total_tva'=>"TotalVAT",'f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus',
  237. // 'f.note'=>"InvoiceNote",'fd.rowid'=>'LineId','fd.description'=>"LineDescription",'fd.price'=>"LineUnitPrice",'fd.tva_tx'=>"LineVATRate",
  238. // 'fd.qty'=>"LineQty",'fd.total_ht'=>"LineTotalHT",'fd.total_tva'=>"LineTotalTVA",'fd.total_ttc'=>"LineTotalTTC",'fd.date_start'=>"DateStart",
  239. // 'fd.date_end'=>"DateEnd",'fd.fk_product'=>'ProductId','p.ref'=>'ProductRef'
  240. //);
  241. // $this->export_entities_array[$r]=array(
  242. // 's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','s.fk_pays'=>'company','s.phone'=>'company',
  243. // 's.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company',
  244. // 'f.rowid'=>"invoice",'f.ref'=>"invoice",'f.datec'=>"invoice",'f.datef'=>"invoice",'f.total_ht'=>"invoice",'f.total_ttc'=>"invoice",'f.total_tva'=>"invoice",
  245. // 'f.paye'=>"invoice",'f.fk_statut'=>'invoice','f.note'=>"invoice",'fd.rowid'=>'invoice_line','fd.description'=>"invoice_line",'fd.price'=>"invoice_line",
  246. // 'fd.total_ht'=>"invoice_line",'fd.total_tva'=>"invoice_line",'fd.total_ttc'=>"invoice_line",'fd.tva_tx'=>"invoice_line",'fd.qty'=>"invoice_line",
  247. // 'fd.date_start'=>"invoice_line",'fd.date_end'=>"invoice_line",'fd.fk_product'=>'product','p.ref'=>'product'
  248. //);
  249. // $this->export_alias_array[$r]=array(
  250. // 's.rowid'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.zip'=>'soc_zip','s.town'=>'soc_town','s.fk_pays'=>'soc_pays','s.phone'=>'soc_tel',
  251. // 's.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','s.code_compta'=>'soc_customer_accountancy',
  252. // 's.code_compta_fournisseur'=>'soc_supplier_accountancy','f.rowid'=>"invoiceid",'f.ref'=>"ref",'f.datec'=>"datecreation",'f.datef'=>"dateinvoice",
  253. // 'f.total_ht'=>"totalht",'f.total_ttc'=>"totalttc",'f.total_tva'=>"totalvat",'f.paye'=>"paid",'f.fk_statut'=>'status','f.note'=>"note",'fd.rowid'=>'lineid',
  254. // 'fd.description'=>"linedescription",'fd.price'=>"lineprice",'fd.total_ht'=>"linetotalht",'fd.total_tva'=>"linetotaltva",'fd.total_ttc'=>"linetotalttc",
  255. // 'fd.tva_tx'=>"linevatrate",'fd.qty'=>"lineqty",'fd.date_start'=>"linedatestart",'fd.date_end'=>"linedateend",'fd.fk_product'=>'productid',
  256. // 'p.ref'=>'productref'
  257. //);
  258. // $this->export_sql_start[$r]='SELECT DISTINCT ';
  259. // $this->export_sql_end[$r] =' FROM ('.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'facturedet as fd, '.MAIN_DB_PREFIX.'societe as s)';
  260. // $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
  261. // $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture';
  262. // $r++;
  263. }
  264. /**
  265. * Function called when module is enabled.
  266. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  267. * It also creates data directories
  268. *
  269. * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes')
  270. * @return int 1 if OK, 0 if KO
  271. */
  272. public function init($options = '')
  273. {
  274. global $conf;
  275. // Permissions
  276. $this->remove($options);
  277. //ODT template
  278. /*$src=DOL_DOCUMENT_ROOT.'/install/doctemplates/holiday/template_holiday.odt';
  279. $dirodt=DOL_DATA_ROOT.'/doctemplates/holiday';
  280. $dest=$dirodt.'/template_order.odt';
  281. if (file_exists($src) && ! file_exists($dest))
  282. {
  283. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  284. dol_mkdir($dirodt);
  285. $result=dol_copy($src, $dest, 0, 0);
  286. if ($result < 0)
  287. {
  288. $langs->load("errors");
  289. $this->error=$langs->trans('ErrorFailToCopyFile', $src, $dest);
  290. return 0;
  291. }
  292. }
  293. */
  294. $sql = array(
  295. // "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'holiday' AND entity = ".((int) $conf->entity),
  296. // "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','holiday',".((int) $conf->entity).")"
  297. );
  298. return $this->_init($sql, $options);
  299. }
  300. }