modContrat.class.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \defgroup contrat Module contract
  21. * \brief Module pour gerer la tenue de contrat de services
  22. * \file htdocs/core/modules/modContrat.class.php
  23. * \ingroup contrat
  24. * \brief Fichier de description et activation du module Contrat
  25. */
  26. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  27. /**
  28. * Class to describe and enable module Contrat
  29. */
  30. class modContrat extends DolibarrModules
  31. {
  32. /**
  33. * Constructor. Define names, constants, directories, boxes, permissions
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. function __construct($db)
  38. {
  39. global $conf, $langs;
  40. $this->db = $db;
  41. $this->numero = 54;
  42. $this->family = "crm";
  43. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  44. $this->name = preg_replace('/^mod/i','',get_class($this));
  45. $this->description = "Gestion des contrats de services";
  46. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  47. $this->version = 'dolibarr';
  48. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  49. $this->special = 0;
  50. $this->picto='contract';
  51. // Data directories to create when module is enabled
  52. $this->dirs = array("/contract/temp");
  53. // Dependencies
  54. $this->depends = array("modSociete");
  55. $this->requiredby = array();
  56. // Config pages
  57. $this->config_page_url = array("contract.php");
  58. // Constants
  59. $this->const = array();
  60. $this->const[0][0] = "CONTRACT_ADDON";
  61. $this->const[0][1] = "chaine";
  62. $this->const[0][2] = "mod_contract_serpis";
  63. $this->const[0][3] = 'Nom du gestionnaire de numerotation des contrats';
  64. $this->const[0][4] = 0;
  65. // Boxes
  66. $this->boxes = array(
  67. 0=>array('file'=>'box_contracts.php','enabledbydefaulton'=>'Home'),
  68. 1=>array('file'=>'box_services_expired.php','enabledbydefaulton'=>'Home')
  69. );
  70. // Permissions
  71. $this->rights = array();
  72. $this->rights_class = 'contrat';
  73. $r=0;
  74. $r++;
  75. $this->rights[$r][0] = 161;
  76. $this->rights[$r][1] = 'Lire les contrats';
  77. $this->rights[$r][2] = 'r';
  78. $this->rights[$r][3] = 1;
  79. $this->rights[$r][4] = 'lire';
  80. $r++;
  81. $this->rights[$r][0] = 162;
  82. $this->rights[$r][1] = 'Creer / modifier les contrats';
  83. $this->rights[$r][2] = 'w';
  84. $this->rights[$r][3] = 0;
  85. $this->rights[$r][4] = 'creer';
  86. $r++;
  87. $this->rights[$r][0] = 163;
  88. $this->rights[$r][1] = 'Activer un service d\'un contrat';
  89. $this->rights[$r][2] = 'w';
  90. $this->rights[$r][3] = 0;
  91. $this->rights[$r][4] = 'activer';
  92. $r++;
  93. $this->rights[$r][0] = 164;
  94. $this->rights[$r][1] = 'Desactiver un service d\'un contrat';
  95. $this->rights[$r][2] = 'w';
  96. $this->rights[$r][3] = 0;
  97. $this->rights[$r][4] = 'desactiver';
  98. $r++;
  99. $this->rights[$r][0] = 165;
  100. $this->rights[$r][1] = 'Supprimer un contrat';
  101. $this->rights[$r][2] = 'd';
  102. $this->rights[$r][3] = 0;
  103. $this->rights[$r][4] = 'supprimer';
  104. $r++;
  105. $this->rights[$r][0] = 167;
  106. $this->rights[$r][1] = 'Export contracts';
  107. $this->rights[$r][2] = 'r';
  108. $this->rights[$r][3] = 0;
  109. $this->rights[$r][4] = 'export';
  110. // Exports
  111. //--------
  112. $langs->load("contracts");
  113. $r=1;
  114. $this->export_code[$r]=$this->rights_class.'_'.$r;
  115. $this->export_label[$r]='ContractsAndLine'; // Translation key (used only if key ExportDataset_xxx_z not found)
  116. $this->export_icon[$r]='contract';
  117. $this->export_permission[$r]=array(array("contrat","export"));
  118. $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode',
  119. 's.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode',
  120. 's.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra',
  121. 'co.rowid'=>"Id",'co.ref'=>"Ref",'co.datec'=>"DateCreation",'co.date_contrat'=>"DateContract",'co.mise_en_service'=>"ContractStartDate",
  122. 'co.fin_validite'=>"ContractEndDate",'co.date_cloture'=>"Closing",'co.note_private'=>"NotePrivate",'co.note_public'=>"NotePublic",
  123. 'cod.rowid'=>'LineId','cod.label'=>"LineLabel",'cod.description'=>"LineDescription",'cod.price_ht'=>"LineUnitPrice",'cod.tva_tx'=>"LineVATRate",
  124. 'cod.qty'=>"LineQty",'cod.total_ht'=>"LineTotalHT",'cod.total_tva'=>"LineTotalVAT",'cod.total_ttc'=>"LineTotalTTC",
  125. 'cod.date_ouverture'=>"DateStart",'cod.date_ouverture_prevue'=>"DateStartPlanned",'cod.date_fin_validite'=>"DateEndPlanned",'cod.date_cloture'=>"DateEnd",
  126. 'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel');
  127. $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company',
  128. 's.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company',
  129. 's.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company',
  130. 'co.rowid'=>"contract",'co.ref'=>"contract",'co.datec'=>"contract",'co.date_contrat'=>"contract",'co.mise_en_service'=>"contract",
  131. 'co.fin_validite'=>"contract",'co.date_cloture'=>"contract",'co.note_private'=>"contract",'co.note_public'=>"contract",
  132. 'cod.rowid'=>'contract_line','cod.label'=>"contract_line",'cod.description'=>"contract_line",'cod.price_ht'=>"contract_line",'cod.tva_tx'=>"contract_line",
  133. 'cod.qty'=>"contract_line",'cod.total_ht'=>"contract_line",'cod.total_tva'=>"contract_line",'cod.total_ttc'=>"contract_line",
  134. 'cod.date_ouverture'=>"contract_line",'cod.date_ouverture_prevue'=>"contract_line",'cod.date_fin_validite'=>"contract_line",'cod.date_cloture'=>"contract_line",
  135. 'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product');
  136. $this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text',
  137. 's.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text',
  138. 's.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text',
  139. 'co.ref'=>"Text",'co.datec'=>"Date",'co.date_contrat'=>"Date",'co.mise_en_service'=>"Date",
  140. 'co.fin_validite'=>"Date",'co.date_cloture'=>"Date",'co.note_private'=>"Text",'co.note_public'=>"Text",
  141. 'cod.label'=>"Text",'cod.description'=>"Text",'cod.price_ht'=>"Numeric",'cod.tva_tx'=>"Numeric",
  142. 'cod.qty'=>"Numeric",'cod.total_ht'=>"Numeric",'cod.total_tva'=>"Numeric",'cod.total_ttc'=>"Numeric",
  143. 'cod.date_ouverture'=>"Date",'cod.date_ouverture_prevue'=>"Date",'cod.date_fin_validite'=>"Date",'cod.date_cloture'=>"Date",
  144. 'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
  145. $this->export_sql_start[$r]='SELECT DISTINCT ';
  146. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
  147. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,';
  148. $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contrat as co,';
  149. $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'contratdet as cod';
  150. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cod.fk_product = p.rowid)';
  151. $this->export_sql_end[$r] .=' WHERE co.fk_soc = s.rowid and co.rowid = cod.fk_contrat';
  152. $this->export_sql_end[$r] .=' AND co.entity IN ('.getEntity('contract',1).')';
  153. }
  154. /**
  155. * Function called when module is enabled.
  156. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  157. * It also creates data directories
  158. *
  159. * @param string $options Options when enabling module ('', 'noboxes')
  160. * @return int 1 if OK, 0 if KO
  161. */
  162. function init($options='')
  163. {
  164. global $conf;
  165. // Nettoyage avant activation
  166. $this->remove($options);
  167. $sql = array();
  168. return $this->_init($sql,$options);
  169. }
  170. }