dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
29include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30
31
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 = [
73 [
74 "CONTRACT_ADDON",
75 "chaine",
76 "mod_contract_serpis",
77 "Nom du gestionnaire de numerotation des contrats",
78 0,
79 ],
80 [
81 "CONTRACT_ADDON_PDF",
82 "chaine",
83 "strato",
84 "Name of PDF model of contract",
85 0,
86 ],
87 [
88 "CONTRACT_ADDON_PDF_ODT_PATH",
89 "chaine",
90 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/contracts",
91 "",
92 0,
93 ],
94 ];
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 // Cronjobs
103 $arraydate = dol_getdate(dol_now());
104 $datestart = dol_mktime(22, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
105 $this->cronjobs = array(
106 0 => array(
107 'label' => 'SendReminderForExpiredServicesTitle',
108 'jobtype' => 'method', 'class' => 'contrat/class/contrat.class.php',
109 'objectname' => 'Contrat',
110 'method' => 'sendReminderForExpiredServices',
111 'parameters' => '10;0',
112 'comment' => 'SendReminderForExpiredServices',
113 'frequency' => 1,
114 'unitfrequency' => 3600 * 24,
115 'priority' => 50,
116 'status' => 1,
117 'test' => 'isModEnabled("contract")',
118 'datestart' => $datestart
119 ),
120 );
121
122 // Permissions
123 $this->rights = array();
124 $this->rights_class = 'contrat';
125 $r = 0;
126
127 $r++;
128 $this->rights[$r][0] = 161;
129 $this->rights[$r][1] = 'Lire les contrats';
130 $this->rights[$r][2] = 'r';
131 $this->rights[$r][3] = 0;
132 $this->rights[$r][4] = 'lire';
133
134 $r++;
135 $this->rights[$r][0] = 162;
136 $this->rights[$r][1] = 'Creer / modifier les contrats';
137 $this->rights[$r][2] = 'w';
138 $this->rights[$r][3] = 0;
139 $this->rights[$r][4] = 'creer';
140
141 $r++;
142 $this->rights[$r][0] = 163;
143 $this->rights[$r][1] = 'Activer un service d\'un contrat';
144 $this->rights[$r][2] = 'w';
145 $this->rights[$r][3] = 0;
146 $this->rights[$r][4] = 'activer';
147
148 $r++;
149 $this->rights[$r][0] = 164;
150 $this->rights[$r][1] = 'Desactiver un service d\'un contrat';
151 $this->rights[$r][2] = 'w';
152 $this->rights[$r][3] = 0;
153 $this->rights[$r][4] = 'desactiver';
154
155 $r++;
156 $this->rights[$r][0] = 165;
157 $this->rights[$r][1] = 'Supprimer un contrat';
158 $this->rights[$r][2] = 'd';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] = 'supprimer';
161
162 $r++;
163 $this->rights[$r][0] = 167;
164 $this->rights[$r][1] = 'Export contracts';
165 $this->rights[$r][2] = 'r';
166 $this->rights[$r][3] = 0;
167 $this->rights[$r][4] = 'export';
168
169
170 // Menus
171 //-------
172 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
173
174
175 // Exports
176 //--------
177 $langs->load("contracts");
178
179 $r = 1;
180
181 $this->export_code[$r] = $this->rights_class.'_'.$r;
182 $this->export_label[$r] = 'ContractsAndLine'; // Translation key (used only if key ExportDataset_xxx_z not found)
183 $this->export_icon[$r] = 'contract';
184 $this->export_permission[$r] = array(array("contrat", "export"));
185 $this->export_fields_array[$r] = array('s.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode',
186 's.email'=>'Email', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode',
187 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
188 'co.rowid'=>"Id", 'co.ref'=>"Ref", 'co.datec'=>"DateCreation", 'co.date_contrat'=>"DateContract",
189 'co.fin_validite'=>"ContractEndDate", 'co.date_cloture'=>"DateClosing", 'co.note_private'=>"NotePrivate", 'co.note_public'=>"NotePublic",
190 'cod.rowid'=>'LineId', 'cod.label'=>"LineLabel", 'cod.description'=>"LineDescription", 'cod.tva_tx'=>"LineVATRate",
191 'cod.qty'=>"LineQty", 'cod.total_ht'=>"LineTotalHT", 'cod.total_tva'=>"LineTotalVAT", 'cod.total_ttc'=>"LineTotalTTC",
192 'cod.date_ouverture'=>"DateStart", 'cod.date_ouverture_prevue'=>"DateStartPlanned", 'cod.date_fin_validite'=>"DateEndPlanned", 'cod.date_cloture'=>"DateEnd",
193 'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel');
194
195 $this->export_entities_array[$r] = array('s.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company',
196 's.town'=>'company', 'c.code'=>'company', 's.email'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company',
197 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
198 'co.rowid'=>"contract", 'co.ref'=>"contract", 'co.datec'=>"contract", 'co.date_contrat'=>"contract",
199 'co.fin_validite'=>"contract", 'co.date_cloture'=>"contract", 'co.note_private'=>"contract", 'co.note_public'=>"contract",
200 'cod.rowid'=>'contract_line', 'cod.label'=>"contract_line", 'cod.description'=>"contract_line", 'cod.tva_tx'=>"contract_line",
201 'cod.qty'=>"contract_line", 'cod.total_ht'=>"contract_line", 'cod.total_tva'=>"contract_line", 'cod.total_ttc'=>"contract_line",
202 'cod.date_ouverture'=>"contract_line", 'cod.date_ouverture_prevue'=>"contract_line", 'cod.date_fin_validite'=>"contract_line", 'cod.date_cloture'=>"contract_line",
203 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product');
204
205 $this->export_TypeFields_array[$r] = array('s.rowid'=>"Numeric", 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text',
206 's.email'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text',
207 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text',
208 'co.ref'=>"Text", 'co.datec'=>"Date", 'co.date_contrat'=>"Date",
209 'co.fin_validite'=>"Date", 'co.date_cloture'=>"Date", 'co.note_private'=>"Text", 'co.note_public'=>"Text",
210 'cod.label'=>"Text", 'cod.description'=>"Text", 'cod.tva_tx'=>"Numeric",
211 'cod.qty'=>"Numeric", 'cod.total_ht'=>"Numeric", 'cod.total_tva'=>"Numeric", 'cod.total_ttc'=>"Numeric",
212 'cod.date_ouverture'=>"Date", 'cod.date_ouverture_prevue'=>"Date", 'cod.date_fin_validite'=>"Date", 'cod.date_cloture'=>"Date",
213 'p.rowid'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text');
214
215
216 $keyforselect = 'contrat';
217 $keyforelement = 'contract';
218 $keyforaliasextra = 'coextra';
219 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
220 $keyforselect = 'contratdet';
221 $keyforelement = 'contract_line';
222 $keyforaliasextra = 'codextra';
223 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
224
225 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
226 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
227 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid';
228 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'contrat as co ON co.fk_soc = s.rowid';
229 $this->export_sql_end[$r] .= ' INNER JOIN '.MAIN_DB_PREFIX.'contratdet as cod ON co.rowid = cod.fk_contrat';
230 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (cod.fk_product = p.rowid)';
231 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contrat_extrafields as coextra on (co.rowid = coextra.fk_object)';
232 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contratdet_extrafields as codextra on (cod.rowid = codextra.fk_object)';
233 $this->export_sql_end[$r] .= ' WHERE co.entity IN ('.getEntity('contract').')';
234 }
235
236
245 public function init($options = '')
246 {
247 global $conf, $langs;
248
249 // Nettoyage avant activation
250 $this->remove($options);
251
252 //ODT template
253 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/contracts/template_contract.odt';
254 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/contracts';
255 $dest = $dirodt.'/template_contract.odt';
256
257 if (file_exists($src) && !file_exists($dest)) {
258 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
259 dol_mkdir($dirodt);
260 $result = dol_copy($src, $dest, '0', 0);
261 if ($result < 0) {
262 $langs->load("errors");
263 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
264 return 0;
265 }
266 }
267
268 $sql = array(
269 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'contract' AND entity = ".((int) $conf->entity),
270 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."', 'contract', ".((int) $conf->entity).")"
271 );
272
273 return $this->_init($sql, $options);
274 }
275}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Contrat.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133