dolibarr  7.0.0-beta
modPropale.class.php
Go to the documentation of this file.
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 
30 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
31 
32 
37 {
38 
44  function __construct($db)
45  {
46  global $conf, $user;
47 
48  $this->db = $db;
49  $this->numero = 20;
50 
51  $this->family = "crm";
52  $this->module_position = 20;
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i','',get_class($this));
55  $this->description = "Gestion des propositions commerciales";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->special = 0;
62  $this->picto='propal';
63 
64  // Data directories to create when module is enabled
65  $this->dirs = array("/propale/temp");
66 
67  // Dependancies
68  $this->depends = array("modSociete");
69  $this->requiredby = array();
70  $this->config_page_url = array("propal.php");
71  $this->langfiles = array("propal","bills","companies","deliveries","products");
72 
73  // Constants
74  $this->const = array();
75  $r=0;
76 
77  $this->const[$r][0] = "PROPALE_ADDON_PDF";
78  $this->const[$r][1] = "chaine";
79  $this->const[$r][2] = "azur";
80  $this->const[$r][3] = 'Name of the proposal generation manager in PDF format';
81  $this->const[$r][4] = 0;
82  $r++;
83 
84  $this->const[$r][0] = "PROPALE_ADDON";
85  $this->const[$r][1] = "chaine";
86  $this->const[$r][2] = "mod_propale_marbre";
87  $this->const[$r][3] = 'Name of proposal numbering manager';
88  $this->const[$r][4] = 0;
89  $r++;
90 
91  $this->const[$r][0] = "PROPALE_VALIDITY_DURATION";
92  $this->const[$r][1] = "chaine";
93  $this->const[$r][2] = "15";
94  $this->const[$r][3] = 'Duration of validity of business proposals';
95  $this->const[$r][4] = 0;
96  $r++;
97 
98  $this->const[$r][0] = "PROPALE_ADDON_PDF_ODT_PATH";
99  $this->const[$r][1] = "chaine";
100  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/proposals";
101  $this->const[$r][3] = "";
102  $this->const[$r][4] = 0;
103  $r++;
104 
105  /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK";
106  $this->const[$r][2] = "__(Draft)__";
107  $this->const[$r][3] = 'Watermark to show on draft proposals';
108  $this->const[$r][4] = 0;
109  $r++;*/
110 
111  // Boxes
112  $this->boxes = array(
113  0=>array('file'=>'box_graph_propales_permonth.php','enabledbydefaulton'=>'Home'),
114  1=>array('file'=>'box_propales.php','enabledbydefaulton'=>'Home'),
115  );
116 
117  // Permissions
118  $this->rights = array();
119  $this->rights_class = 'propale';
120  $r=0;
121 
122  $r++;
123  $this->rights[$r][0] = 21; // id de la permission
124  $this->rights[$r][1] = 'Read commercial proposals'; // libelle de la permission
125  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
126  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
127  $this->rights[$r][4] = 'lire';
128 
129  $r++;
130  $this->rights[$r][0] = 22; // id de la permission
131  $this->rights[$r][1] = 'Create and update commercial proposals'; // libelle de la permission
132  $this->rights[$r][2] = 'w'; // 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] = 'creer';
135 
136  $r++;
137  $this->rights[$r][0] = 24; // id de la permission
138  $this->rights[$r][1] = 'Validate commercial proposals'; // libelle de la permission
139  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
140  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
141  $this->rights[$r][4] = 'propal_advance';
142  $this->rights[$r][5] = 'validate';
143 
144  $r++;
145  $this->rights[$r][0] = 25; // id de la permission
146  $this->rights[$r][1] = 'Send commercial proposals to customers'; // libelle de la permission
147  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
148  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
149  $this->rights[$r][4] = 'propal_advance';
150  $this->rights[$r][5] = 'send';
151 
152  $r++;
153  $this->rights[$r][0] = 26; // id de la permission
154  $this->rights[$r][1] = 'Close commercial proposals'; // libelle de la permission
155  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
156  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
157  $this->rights[$r][4] = 'cloturer';
158 
159  $r++;
160  $this->rights[$r][0] = 27; // id de la permission
161  $this->rights[$r][1] = 'Delete commercial proposals'; // libelle de la permission
162  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
163  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
164  $this->rights[$r][4] = 'supprimer';
165 
166  $r++;
167  $this->rights[$r][0] = 28; // id de la permission
168  $this->rights[$r][1] = 'Exporting commercial proposals and attributes'; // libelle de la permission
169  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
170  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
171  $this->rights[$r][4] = 'export';
172 
173 
174  // Menus
175  //-------
176  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
177 
178 
179  // Exports
180  //--------
181  $r=0;
182 
183  $r++;
184  $this->export_code[$r]=$this->rights_class.'_'.$r;
185  $this->export_label[$r]='ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
186  $this->export_permission[$r]=array(array("propale","export"));
187  $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');
188  //$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');
189  $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');
190  $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');
191  $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
192  $keyforselect='propal'; $keyforelement='propal'; $keyforaliasextra='extra';
193  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
194  $keyforselect='propaldet'; $keyforelement='propal_line'; $keyforaliasextra='extra2';
195  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
196  $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra3';
197  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
198  $this->export_sql_start[$r]='SELECT DISTINCT ';
199  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s ';
200  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';
201  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
202  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'propal as c';
203  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
204  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
205  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
206  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
207  $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'propaldet as cd';
208  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
209  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
210  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
211  $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
212  $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('propal').')';
213  if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
214  }
215 
216 
225  function init($options='')
226  {
227  global $conf,$langs;
228 
229  // Remove permissions and default values
230  $this->remove($options);
231 
232  //ODT template
233  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
234  $dirodt=DOL_DATA_ROOT.'/doctemplates/proposals';
235  $dest=$dirodt.'/template_proposal.odt';
236 
237  if (file_exists($src) && ! file_exists($dest))
238  {
239  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
240  dol_mkdir($dirodt);
241  $result=dol_copy($src,$dest,0,0);
242  if ($result < 0)
243  {
244  $langs->load("errors");
245  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
246  return 0;
247  }
248  }
249 
250  $sql = array(
251  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'propal' AND entity = ".$conf->entity,
252  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','propal',".$conf->entity.")",
253  );
254 
255  return $this->_init($sql,$options);
256 
257  }
258 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
Class DolibarrModules.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
Class to describe and enable module Propale.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)