modPropale.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 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@capnetworks.com>
  7. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  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 <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \defgroup propale Module commercial proposals
  24. * \brief Module pour gerer la tenue de propositions commerciales
  25. * \file htdocs/core/modules/modPropale.class.php
  26. * \ingroup propale
  27. * \brief Fichier de description et activation du module Propale
  28. */
  29. include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
  30. /**
  31. * Class to describe and enable module Propale
  32. */
  33. class modPropale extends DolibarrModules
  34. {
  35. /**
  36. * Constructor. Define names, constants, directories, boxes, permissions
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. function __construct($db)
  41. {
  42. global $conf, $user;
  43. $this->db = $db;
  44. $this->numero = 20;
  45. $this->family = "crm";
  46. $this->module_position = 20;
  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 propositions commerciales";
  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->special = 0;
  54. $this->picto='propal';
  55. // Data directories to create when module is enabled
  56. $this->dirs = array("/propale/temp");
  57. // Dependancies
  58. $this->depends = array("modSociete");
  59. $this->requiredby = array();
  60. $this->config_page_url = array("propal.php");
  61. $this->langfiles = array("propal","bills","companies","deliveries","products");
  62. // Constants
  63. $this->const = array();
  64. $r=0;
  65. $this->const[$r][0] = "PROPALE_ADDON_PDF";
  66. $this->const[$r][1] = "chaine";
  67. $this->const[$r][2] = "azur";
  68. $this->const[$r][3] = 'Nom du gestionnaire de generation des propales en PDF';
  69. $this->const[$r][4] = 0;
  70. $r++;
  71. $this->const[$r][0] = "PROPALE_ADDON";
  72. $this->const[$r][1] = "chaine";
  73. $this->const[$r][2] = "mod_propale_marbre";
  74. $this->const[$r][3] = 'Nom du gestionnaire de numerotation des propales';
  75. $this->const[$r][4] = 0;
  76. $r++;
  77. $this->const[$r][0] = "PROPALE_VALIDITY_DURATION";
  78. $this->const[$r][1] = "chaine";
  79. $this->const[$r][2] = "15";
  80. $this->const[$r][3] = 'Duration of validity of business proposals';
  81. $this->const[$r][4] = 0;
  82. $r++;
  83. $this->const[$r][0] = "PROPALE_ADDON_PDF_ODT_PATH";
  84. $this->const[$r][1] = "chaine";
  85. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/proposals";
  86. $this->const[$r][3] = "";
  87. $this->const[$r][4] = 0;
  88. // Boxes
  89. $this->boxes = array(
  90. 0=>array('file'=>'box_graph_propales_permonth.php','enabledbydefaulton'=>'Home'),
  91. 1=>array('file'=>'box_propales.php','enabledbydefaulton'=>'Home'),
  92. );
  93. // Permissions
  94. $this->rights = array();
  95. $this->rights_class = 'propale';
  96. $r=0;
  97. $r++;
  98. $this->rights[$r][0] = 21; // id de la permission
  99. $this->rights[$r][1] = 'Lire les propositions commerciales'; // libelle de la permission
  100. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  101. $this->rights[$r][3] = 1; // La permission est-elle une permission par defaut
  102. $this->rights[$r][4] = 'lire';
  103. $r++;
  104. $this->rights[$r][0] = 22; // id de la permission
  105. $this->rights[$r][1] = 'Creer/modifier les propositions commerciales'; // libelle de la permission
  106. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  107. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  108. $this->rights[$r][4] = 'creer';
  109. $r++;
  110. $this->rights[$r][0] = 24; // id de la permission
  111. $this->rights[$r][1] = 'Valider les propositions commerciales'; // libelle de la permission
  112. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  113. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  114. $this->rights[$r][4] = 'propal_advance';
  115. $this->rights[$r][5] = 'validate';
  116. $r++;
  117. $this->rights[$r][0] = 25; // id de la permission
  118. $this->rights[$r][1] = 'Envoyer les propositions commerciales aux clients'; // libelle de la permission
  119. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  120. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  121. $this->rights[$r][4] = 'propal_advance';
  122. $this->rights[$r][5] = 'send';
  123. $r++;
  124. $this->rights[$r][0] = 26; // id de la permission
  125. $this->rights[$r][1] = 'Cloturer les propositions commerciales'; // libelle de la permission
  126. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  127. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  128. $this->rights[$r][4] = 'cloturer';
  129. $r++;
  130. $this->rights[$r][0] = 27; // id de la permission
  131. $this->rights[$r][1] = 'Supprimer les propositions commerciales'; // libelle de la permission
  132. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  133. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  134. $this->rights[$r][4] = 'supprimer';
  135. $r++;
  136. $this->rights[$r][0] = 28; // id de la permission
  137. $this->rights[$r][1] = 'Exporter les propositions commerciales et attributs'; // libelle de la permission
  138. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  139. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  140. $this->rights[$r][4] = 'export';
  141. // Exports
  142. //--------
  143. $r=0;
  144. $r++;
  145. $this->export_code[$r]=$this->rights_class.'_'.$r;
  146. $this->export_label[$r]='ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  147. $this->export_permission[$r]=array(array("propale","export"));
  148. $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','co.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefCustomer",'c.fk_soc'=>"IdCompany",'c.datec'=>"DateCreation",'c.datep'=>"DatePropal",'c.fin_validite'=>"DateEndPropal",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total'=>"TotalTTC",'c.fk_statut'=>'Status','c.note_public'=>"Note",'c.date_livraison'=>'DeliveryDate','c.fk_user_author'=>'CreatedById','uc.login'=>'CreatedByLogin','c.fk_user_valid'=>'ValidatedById','uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'cd.rowid'=>'LineId','cd.label'=>"Label",'cd.description'=>"LineDescription",'cd.product_type'=>'TypeOfLineServiceOrProduct','cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty",'cd.total_ht'=>"LineTotalHT",'cd.total_tva'=>"LineTotalVAT",'cd.total_ttc'=>"LineTotalTTC",'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel');
  149. //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.datec'=>"Date",'c.datep'=>"Date",'c.fin_validite'=>"Date",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text');
  150. $this->export_TypeFields_array[$r]=array('s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.datec'=>"Date",'c.datep'=>"Date",'c.fin_validite'=>"Date",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date', 'pj.ref'=>'Text', 'cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.ref'=>'Text','p.label'=>'Text');
  151. $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','co.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"propal",'c.ref'=>"propal",'c.ref_client'=>"propal",'c.fk_soc'=>"propal",'c.datec'=>"propal",'c.datep'=>"propal",'c.fin_validite'=>"propal",'c.remise_percent'=>"propal",'c.total_ht'=>"propal",'c.total'=>"propal",'c.fk_statut'=>"propal",'c.note_public'=>"propal",'c.date_livraison'=>"propal", 'pj.ref'=>'project', 'cd.rowid'=>'propal_line','cd.label'=>"propal_line",'cd.description'=>"propal_line",'cd.product_type'=>'propal_line','cd.tva_tx'=>"propal_line",'cd.qty'=>"propal_line",'cd.total_ht'=>"propal_line",'cd.total_tva'=>"propal_line",'cd.total_ttc'=>"propal_line",'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product');
  152. $this->export_dependencies_array[$r]=array('propal_line'=>'cd.rowid','product'=>'cd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  153. $keyforselect='propal'; $keyforelement='propal'; $keyforaliasextra='extra';
  154. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  155. $keyforselect='propaldet'; $keyforelement='propal_line'; $keyforaliasextra='extra2';
  156. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  157. $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra3';
  158. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  159. $this->export_sql_start[$r]='SELECT DISTINCT ';
  160. $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s ';
  161. if(!$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';
  162. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
  163. $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'propal as c';
  164. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
  165. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
  166. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
  167. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
  168. $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'propaldet as cd';
  169. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
  170. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
  171. $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
  172. $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
  173. $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('propal',1).')';
  174. if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
  175. }
  176. /**
  177. * Function called when module is enabled.
  178. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  179. * It also creates data directories
  180. *
  181. * @param string $options Options when enabling module ('', 'noboxes')
  182. * @return int 1 if OK, 0 if KO
  183. */
  184. function init($options='')
  185. {
  186. global $conf,$langs;
  187. // Remove permissions and default values
  188. $this->remove($options);
  189. //ODT template
  190. $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
  191. $dirodt=DOL_DATA_ROOT.'/doctemplates/proposals';
  192. $dest=$dirodt.'/template_proposal.odt';
  193. if (file_exists($src) && ! file_exists($dest))
  194. {
  195. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  196. dol_mkdir($dirodt);
  197. $result=dol_copy($src,$dest,0,0);
  198. if ($result < 0)
  199. {
  200. $langs->load("errors");
  201. $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
  202. return 0;
  203. }
  204. }
  205. $sql = array(
  206. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
  207. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->const[0][2]."','propal',".$conf->entity.")",
  208. );
  209. return $this->_init($sql,$options);
  210. }
  211. }