dolibarr  13.0.2
modContrat.class.php
Go to the documentation of this file.
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@inodbox.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 <https://www.gnu.org/licenses/>.
18  */
19 
28 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
29 
30 
35 {
36 
42  public function __construct($db)
43  {
44  global $conf, $langs;
45 
46  $this->db = $db;
47  $this->numero = 54;
48 
49  $this->family = "crm";
50  $this->module_position = '41';
51  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52  $this->name = preg_replace('/^mod/i', '', get_class($this));
53  $this->description = "Gestion des contrats de services";
54 
55  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56  $this->version = 'dolibarr';
57 
58  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59  $this->picto = 'contract';
60 
61  // Data directories to create when module is enabled
62  $this->dirs = array("/contract/temp");
63 
64  // Dependencies
65  $this->depends = array("modSociete");
66  $this->requiredby = array();
67 
68  // Config pages
69  $this->config_page_url = array("contract.php");
70 
71  // Constants
72  $this->const = array();
73  $r = 0;
74 
75  $this->const[$r][0] = "CONTRACT_ADDON";
76  $this->const[$r][1] = "chaine";
77  $this->const[$r][2] = "mod_contract_serpis";
78  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des contrats';
79  $this->const[$r][4] = 0;
80  $r++;
81 
82  $this->const[$r][0] = "CONTRACT_ADDON_PDF";
83  $this->const[$r][1] = "chaine";
84  $this->const[$r][2] = "strato";
85  $this->const[$r][3] = 'Name of PDF model of contract';
86  $this->const[$r][4] = 0;
87  $r++;
88 
89  $this->const[$r][0] = "CONTRACT_ADDON_PDF_ODT_PATH";
90  $this->const[$r][1] = "chaine";
91  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/contracts";
92  $this->const[$r][3] = "";
93  $this->const[$r][4] = 0;
94  $r++;
95 
96  // Boxes
97  $this->boxes = array(
98  0=>array('file'=>'box_contracts.php', 'enabledbydefaulton'=>'Home'),
99  1=>array('file'=>'box_services_expired.php', 'enabledbydefaulton'=>'Home')
100  );
101 
102  // Permissions
103  $this->rights = array();
104  $this->rights_class = 'contrat';
105  $r = 0;
106 
107  $r++;
108  $this->rights[$r][0] = 161;
109  $this->rights[$r][1] = 'Lire les contrats';
110  $this->rights[$r][2] = 'r';
111  $this->rights[$r][3] = 0;
112  $this->rights[$r][4] = 'lire';
113 
114  $r++;
115  $this->rights[$r][0] = 162;
116  $this->rights[$r][1] = 'Creer / modifier les contrats';
117  $this->rights[$r][2] = 'w';
118  $this->rights[$r][3] = 0;
119  $this->rights[$r][4] = 'creer';
120 
121  $r++;
122  $this->rights[$r][0] = 163;
123  $this->rights[$r][1] = 'Activer un service d\'un contrat';
124  $this->rights[$r][2] = 'w';
125  $this->rights[$r][3] = 0;
126  $this->rights[$r][4] = 'activer';
127 
128  $r++;
129  $this->rights[$r][0] = 164;
130  $this->rights[$r][1] = 'Desactiver un service d\'un contrat';
131  $this->rights[$r][2] = 'w';
132  $this->rights[$r][3] = 0;
133  $this->rights[$r][4] = 'desactiver';
134 
135  $r++;
136  $this->rights[$r][0] = 165;
137  $this->rights[$r][1] = 'Supprimer un contrat';
138  $this->rights[$r][2] = 'd';
139  $this->rights[$r][3] = 0;
140  $this->rights[$r][4] = 'supprimer';
141 
142  $r++;
143  $this->rights[$r][0] = 167;
144  $this->rights[$r][1] = 'Export contracts';
145  $this->rights[$r][2] = 'r';
146  $this->rights[$r][3] = 0;
147  $this->rights[$r][4] = 'export';
148 
149 
150  // Menus
151  //-------
152  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
153 
154 
155  // Exports
156  //--------
157  $langs->load("contracts");
158 
159  $r = 1;
160 
161  $this->export_code[$r] = $this->rights_class.'_'.$r;
162  $this->export_label[$r] = 'ContractsAndLine'; // Translation key (used only if key ExportDataset_xxx_z not found)
163  $this->export_icon[$r] = 'contract';
164  $this->export_permission[$r] = array(array("contrat", "export"));
165  $this->export_fields_array[$r] = array('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode',
166  's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
167  's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
168  'co.rowid'=>"Id", 'co.ref'=>"Ref", 'co.datec'=>"DateCreation", 'co.date_contrat'=>"DateContract",
169  'co.fin_validite'=>"ContractEndDate", 'co.date_cloture'=>"Closing", 'co.note_private'=>"NotePrivate", 'co.note_public'=>"NotePublic",
170  'cod.rowid'=>'LineId', 'cod.label'=>"LineLabel", 'cod.description'=>"LineDescription", 'cod.price_ht'=>"LineUnitPrice", 'cod.tva_tx'=>"LineVATRate",
171  'cod.qty'=>"LineQty", 'cod.total_ht'=>"LineTotalHT", 'cod.total_tva'=>"LineTotalVAT", 'cod.total_ttc'=>"LineTotalTTC",
172  'cod.date_ouverture'=>"DateStart", 'cod.date_ouverture_prevue'=>"DateStartPlanned", 'cod.date_fin_validite'=>"DateEndPlanned", 'cod.date_cloture'=>"DateEnd",
173  'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel');
174 
175  $this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company',
176  's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company',
177  's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
178  'co.rowid'=>"contract", 'co.ref'=>"contract", 'co.datec'=>"contract", 'co.date_contrat'=>"contract",
179  'co.fin_validite'=>"contract", 'co.date_cloture'=>"contract", 'co.note_private'=>"contract", 'co.note_public'=>"contract",
180  'cod.rowid'=>'contract_line', 'cod.label'=>"contract_line", 'cod.description'=>"contract_line", 'cod.price_ht'=>"contract_line", 'cod.tva_tx'=>"contract_line",
181  'cod.qty'=>"contract_line", 'cod.total_ht'=>"contract_line", 'cod.total_tva'=>"contract_line", 'cod.total_ttc'=>"contract_line",
182  'cod.date_ouverture'=>"contract_line", 'cod.date_ouverture_prevue'=>"contract_line", 'cod.date_fin_validite'=>"contract_line", 'cod.date_cloture'=>"contract_line",
183  'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product');
184 
185  $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',
186  's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text',
187  's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
188  'co.ref'=>"Text", 'co.datec'=>"Date", 'co.date_contrat'=>"Date",
189  'co.fin_validite'=>"Date", 'co.date_cloture'=>"Date", 'co.note_private'=>"Text", 'co.note_public'=>"Text",
190  'cod.label'=>"Text", 'cod.description'=>"Text", 'cod.price_ht'=>"Numeric", 'cod.tva_tx'=>"Numeric",
191  'cod.qty'=>"Numeric", 'cod.total_ht'=>"Numeric", 'cod.total_tva'=>"Numeric", 'cod.total_ttc'=>"Numeric",
192  'cod.date_ouverture'=>"Date", 'cod.date_ouverture_prevue'=>"Date", 'cod.date_fin_validite'=>"Date", 'cod.date_cloture'=>"Date",
193  'p.rowid'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text');
194 
195 
196  $keyforselect = 'contrat'; $keyforelement = 'contract'; $keyforaliasextra = 'coextra';
197  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
198  $keyforselect = 'contratdet'; $keyforelement = 'contract_line'; $keyforaliasextra = 'codextra';
199  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
200 
201  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
202  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
203  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
204  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'contrat as co ON co.fk_soc = s.rowid';
205  $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'contratdet as cod ON co.rowid = cod.fk_contrat';
206  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (cod.fk_product = p.rowid)';
207  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contrat_extrafields as coextra on (co.rowid = coextra.fk_object)';
208  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contratdet_extrafields as codextra on (cod.rowid = codextra.fk_object)';
209  $this->export_sql_end[$r] .= ' WHERE co.entity IN ('.getEntity('contract').')';
210  }
211 
212 
221  public function init($options = '')
222  {
223  global $conf, $langs;
224 
225  // Nettoyage avant activation
226  $this->remove($options);
227 
228  //ODT template
229  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
230  $dirodt = DOL_DATA_ROOT.'/doctemplates/contracts';
231  $dest = $dirodt.'/template_contract.odt';
232 
233  if (file_exists($src) && !file_exists($dest))
234  {
235  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
236  dol_mkdir($dirodt);
237  $result = dol_copy($src, $dest, 0, 0);
238  if ($result < 0)
239  {
240  $langs->load("errors");
241  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
242  return 0;
243  }
244  }
245 
246  $sql = array(
247  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'contract' AND entity = ".$conf->entity,
248  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','contract',".$conf->entity.")"
249  );
250 
251  return $this->_init($sql, $options);
252  }
253 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
init($options= '')
Function called when module is enabled.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</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:750
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
_init($array_sql, $options= '')
Enables a module.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to describe and enable module Contrat.