dolibarr 25.0.0-alpha
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@inodbox.com>
7 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
9 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2026 Charlene Benke <charlene@patas-monkey.com>
11 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
34include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
35
36
41{
47 public function __construct($db)
48 {
49 global $conf, $user, $hookmanager;
50
51 $this->db = $db;
52 $this->numero = 20;
53
54 $this->family = "crm";
55 $this->module_position = '10';
56 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
57 $this->name = preg_replace('/^mod/i', '', get_class($this));
58 $this->description = "Management of quotes or commercial proposals";
59
60 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
61 $this->version = 'dolibarr';
62
63 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
64 $this->picto = 'propal';
65
66 // Data directories to create when module is enabled
67 $this->dirs = array("/propale/temp");
68
69 // Dependencies
70 $this->hidden = false; // A condition to hide module
71 $this->depends = array("modSociete"); // List of module class names as string that must be enabled if this module is enabled
72 $this->requiredby = array(); // List of module ids to disable if this one is disabled
73 $this->conflictwith = array(); // List of module class names as string this module is in conflict with
74 $this->phpmin = array(7, 0); // Minimum version of PHP required by module
75 $this->config_page_url = array("propal.php");
76 $this->langfiles = array("propal", "bills", "companies", "sendings", "products");
77
78 // Constants
79 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
80 $this->const = [
81 [
82 "PROPALE_ADDON_PDF",
83 "chaine",
84 "cyan",
85 'Name of the proposal generation manager in PDF format',
86 0,
87 ],
88 [
89 "PROPALE_ADDON",
90 "chaine",
91 "mod_propale_marbre",
92 'Name of proposal numbering manager',
93 0,
94 ],
95 [
96 "PROPALE_VALIDITY_DURATION",
97 "chaine",
98 "15",
99 'Duration of validity of business proposals',
100 0,
101 ],
102 [
103 "PROPALE_ADDON_PDF_ODT_PATH",
104 "chaine",
105 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/proposals",
106 "",
107 0,
108 ],
109 [
110 "PROPOSAL_ALLOW_ONLINESIGN",
111 "chaine",
112 "1",
113 "",
114 0,
115 ],
116 [
117 "PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN",
118 "chaine",
119 getRandomPassword(true),
120 "",
121 0,
122 ],
123 // For emails
124 [
125 "PROPOSAL_MAIL_FROM",
126 "chaine",
127 "",
128 "From des mails",
129 0,
130 ],
131 [
132 "PROPOSAL_EMAIL_TEMPLATE_REMIND_EXPIRATION",
133 "emailtemplate:propal",
134 "(SendingReminderForExpiringProposal)",
135 "",
136 0,
137 ],
138 ];
139
140 /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK";
141 $this->const[$r][2] = "__(Draft)__";
142 $this->const[$r][3] = 'Watermark to show on draft proposals';
143 $this->const[$r][4] = 0;
144 $r++;*/
145
146 // Boxes
147 $this->boxes = array(
148 0 => array('file' => 'box_graph_propales_permonth.php', 'enabledbydefaulton' => 'Home'),
149 1 => array('file' => 'box_propales.php', 'enabledbydefaulton' => 'Home'),
150 );
151
152 // Cronjobs
153 $arraydate = dol_getdate(dol_now());
154 $datestart = dol_mktime(22, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
155 $this->cronjobs = array(
156 0 => array(
157 'label' => 'SendReminderForExpiringProposalsTitle',
158 'jobtype' => 'method', 'class' => 'comm/propal/class/propal.class.php',
159 'objectname' => 'Propal',
160 'method' => 'sendReminderForExpiringProposals',
161 'parameters' => '10',
162 'comment' => 'SendReminderForExpiringProposals',
163 'frequency' => 1,
164 'unitfrequency' => 3600 * 24,
165 'priority' => 50,
166 'status' => 1,
167 'test' => 'isModEnabled("propal")',
168 'datestart' => $datestart
169 ),
170 );
171
172 // Permissions
173 $this->rights = array();
174 $this->rights_class = 'propale';
175 $r = 0;
176
177 $r++;
178 $this->rights[$r][0] = 21; // Permission id (must not be already used)
179 $this->rights[$r][1] = 'Read commercial proposals'; // Permission label
180 $this->rights[$r][2] = 'r'; // Permission type (deprecated)
181 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
182 $this->rights[$r][4] = 'lire';
183
184 $r++;
185 $this->rights[$r][0] = 22; // Permission id (must not be already used)
186 $this->rights[$r][1] = 'Create and update commercial proposals'; // Permission label
187 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
188 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
189 $this->rights[$r][4] = 'creer';
190
191 $r++;
192 $this->rights[$r][0] = 24; // Permission id (must not be already used)
193 $this->rights[$r][1] = 'Validate commercial proposals'; // Validate proposal
194 $this->rights[$r][2] = 'd'; // Permission type (deprecated)
195 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
196 $this->rights[$r][4] = 'propal_advance';
197 $this->rights[$r][5] = 'validate';
198
199 $r++;
200 $this->rights[$r][0] = 25; // Permission id (must not be already used)
201 $this->rights[$r][1] = 'Send commercial proposals to customers'; // Permission label
202 $this->rights[$r][2] = 'd'; // Permission type (deprecated)
203 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
204 $this->rights[$r][4] = 'propal_advance';
205 $this->rights[$r][5] = 'send';
206
207 $r++;
208 $this->rights[$r][0] = 26; // Permission id (must not be already used)
209 $this->rights[$r][1] = 'Close commercial proposals'; // Set proposal to signed or refused
210 $this->rights[$r][2] = 'd'; // Permission type (deprecated)
211 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
212 $this->rights[$r][4] = 'propal_advance';
213 $this->rights[$r][5] = 'close';
214
215 $r++;
216 $this->rights[$r][0] = 27; // Permission id (must not be already used)
217 $this->rights[$r][1] = 'Delete commercial proposals'; // Permission label
218 $this->rights[$r][2] = 'd'; // Permission type (deprecated)
219 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
220 $this->rights[$r][4] = 'supprimer';
221
222 $r++;
223 $this->rights[$r][0] = 28; // Permission id (must not be already used)
224 $this->rights[$r][1] = 'Exporting commercial proposals and attributes'; // Permission label
225 $this->rights[$r][2] = 'r'; // Permission type (deprecated)
226 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
227 $this->rights[$r][4] = 'export';
228
229 $r++;
230 $this->rights[$r][0] = 29; // Permission id (must not be already used)
231 $this->rights[$r][1] = 'Reopen commercial proposals'; // Set proposal to signed or refused
232 $this->rights[$r][2] = 'w'; // Permission type (deprecated)
233 $this->rights[$r][3] = 0; // Permission by default for new user (0/1)
234 $this->rights[$r][4] = 'propal_advance';
235 $this->rights[$r][5] = 'reopen';
236
237 // Menus
238 //-------
239 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
240
241
242 // Exports
243 //--------
244 $r = 0;
245
246 $r++;
247 $this->export_code[$r] = $this->rights_class.'_'.$r;
248 $this->export_label[$r] = 'ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
249 $this->export_permission[$r] = array(array("propale", "export"));
250 $this->export_fields_array[$r] = array(
251 's.rowid' => "IdCompany", 's.nom' => 'CompanyName', 'ps.nom' => 'ParentCompany', 's.code_client' => 'CustomerCode', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'co.code' => 'CountryCode', 's.phone' => 'Phone',
252 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 'c.rowid' => "Id", 'c.ref' => "Ref", 'c.ref_client' => "RefCustomer",
253 'c.fk_soc' => "IdCompany", 'c.datec' => "DateCreation", 'c.datep' => "DatePropal", 'c.fin_validite' => "DateEndPropal",
254 'c.total_ht' => "TotalHT", 'c.total_ttc' => "TotalTTC",
255 'cir.label' => 'Source',
256 );
257 if (isModEnabled("multicurrency")) {
258 $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
259 $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
260 $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
261 $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
262 $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
263 }
264 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
265 'c.fk_statut' => 'Status', 'c.note_public' => "NotePublic", 'c.note_private' => "NotePrivate", 'c.date_livraison' => 'DeliveryDate',
266 'c.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
267 'c.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin'));
268 if (isModEnabled("project")) {
269 $this->export_fields_array[$r]['pj.ref'] = 'ProjectRef';
270 }
271 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
272 'cd.rowid' => 'LineId', 'cd.description' => "LineDescription", 'cd.product_type' => 'TypeOfLineServiceOrProduct',
273 'cd.tva_tx' => "LineVATRate", 'cd.qty' => "LineQty", 'cd.total_ht' => "LineTotalHT", 'cd.total_tva' => "LineTotalVAT", 'cd.total_ttc' => "LineTotalTTC",
274 ));
275 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
276 'p.rowid' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel'
277 ));
278 // Add multicompany field
279 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
280 $nbofallowedentities = count(explode(',', getEntity('propal')));
281 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
282 $this->export_fields_array[$r]['c.entity'] = 'Entity';
283 }
284 }
285 //$this->export_TypeFields_array[$r]=array(
286 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text',
287 // '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",
288 // 'c.fin_validite'=>"Date",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.note_private'=>"Text",
289 // 'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",
290 // 'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
291 //);
292 $this->export_TypeFields_array[$r] = array(
293 's.nom' => 'Text', 'ps.nom' => 'Text', 's.code_client' => 'Text', 's.address' => 'Text', 's.zip' => 'Text', 's.town' => 'Text', 'co.code' => 'Text', 's.phone' => 'Text', 's.siren' => 'Text', 's.siret' => 'Text',
294 's.ape' => 'Text', 's.idprof4' => 'Text', 'c.ref' => "Text", 'c.ref_client' => "Text", 'c.datec' => "Date", 'c.datep' => "Date", 'c.fin_validite' => "Date",
295 'c.total_ht' => "Numeric", 'c.total_ttc' => "Numeric", 'c.fk_statut' => 'Status', 'c.note_public' => "Text", 'c.note_private' => "Text", 'c.date_livraison' => 'Date',
296 'pj.ref' => 'Text', 'cd.description' => "Text", 'cd.product_type' => 'Boolean', 'cd.tva_tx' => "Numeric", 'cd.qty' => "Numeric", 'cd.total_ht' => "Numeric",
297 'cd.total_tva' => "Numeric", 'cd.total_ttc' => "Numeric", 'p.ref' => 'Text', 'p.label' => 'Text',
298 'c.entity' => 'List:entity:label:rowid',
299 'cir.label' => 'Text',
300 );
301 $this->export_entities_array[$r] = array(
302 's.rowid' => "company", 's.nom' => 'company', 'ps.nom' => 'company', 's.code_client' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'co.code' => 'company', 's.phone' => 'company',
303 's.siren' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.siret' => 'company', 'c.rowid' => "propal", 'c.ref' => "propal", 'c.ref_client' => "propal",
304 'c.fk_soc' => "propal", 'c.datec' => "propal", 'c.datep' => "propal", 'c.fin_validite' => "propal", 'c.total_ht' => "propal",
305 'c.total_ttc' => "propal", 'c.fk_statut' => "propal", 'c.note_public' => "propal", 'c.note_private' => "propal", 'c.date_livraison' => "propal",
306 'c.fk_user_author' => 'user', 'uc.login' => 'user',
307 'c.fk_user_valid' => 'user', 'uv.login' => 'user',
308 'pj.ref' => 'project',
309 'cd.rowid' => 'propal_line',
310 'cd.description' => "propal_line", 'cd.product_type' => 'propal_line', 'cd.tva_tx' => "propal_line", 'cd.qty' => "propal_line",
311 'cd.total_ht' => "propal_line", 'cd.total_tva' => "propal_line", 'cd.total_ttc' => "propal_line", 'p.rowid' => 'product', 'p.ref' => 'product', 'p.label' => 'product'
312 );
313 $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
314 $keyforselect = 'propal';
315 $keyforelement = 'propal';
316 $keyforaliasextra = 'extra';
317 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
318 $keyforselect = 'propaldet';
319 $keyforelement = 'propal_line';
320 $keyforaliasextra = 'extra2';
321 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
322 $keyforselect = 'product';
323 $keyforelement = 'product';
324 $keyforaliasextra = 'extra3';
325 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
326 $keyforselect = 'societe';
327 $keyforelement = 'company';
328 $keyforaliasextra = 'extra4';
329 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
330
331 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
332 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s ';
333 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
334 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
335 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
336 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
337 }
338 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
339 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'propal as c';
340 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
341 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
342 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
343 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
344 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
345 $this->export_sql_end[$r] .= ', '.MAIN_DB_PREFIX.'propaldet as cd';
346 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
347 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
348 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
349 $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
350 $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')';
351 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
352 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
353 }
354 $parameters = array();
355 $hookmanager->executeHooks('printExportWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
356 $this->export_sql_end[$r] .= $hookmanager->resPrint;
357
358 // Imports
359 //--------
360 $r = 0;
361
362 $r++;
363 $this->import_code[$r] = $this->rights_class.'_'.$r;
364 $this->import_label[$r] = 'Proposals'; // Translation key
365 $this->import_icon[$r] = $this->picto;
366 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
367 $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'propal', 'extra' => MAIN_DB_PREFIX.'propal_extrafields');
368 $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
369 $this->import_fields_array[$r] = array(
370 'c.ref' => 'Ref*',
371 'c.ref_client' => 'RefCustomer',
372 'c.fk_soc' => 'ThirdPartyName*',
373 'c.datec' => 'DateCreation',
374 'c.datep' => 'DatePropal',
375 'c.fin_validite' => 'DateEndPropal',
376 'c.total_ht' => 'TotalHT',
377 'c.total_ttc' => 'TotalTTC',
378 'c.fk_statut' => 'Status*',
379 'c.note_public' => 'NotePublic',
380 'c.note_private' => 'NotePrivate',
381 'c.date_livraison' => 'DeliveryDate',
382 'c.fk_user_valid' => 'ValidatedById'
383 );
384 if (isModEnabled("multicurrency")) {
385 $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
386 $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
387 $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
388 $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
389 $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
390 }
391 // Add extra fields
392 $import_extrafield_sample = array();
393 $keyforselect = 'propal';
394 $keyforelement = 'propal';
395 $keyforaliasextra = 'extra';
396 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
397 $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propal'];
398 $this->import_regex_array[$r] = ['c.ref' => '[^ ]'];
399 $import_sample = [
400 'c.ref' => 'PROV0077',
401 'c.ref_client' => 'Client1',
402 'c.fk_soc' => 'MyBigCompany',
403 'c.datec' => '2020-01-01',
404 'c.datep' => '2020-01-01',
405 'c.fin_validite' => '2020-01-01',
406 'c.total_ht' => '0',
407 'c.total_ttc' => '0',
408 'c.fk_statut' => '1',
409 'c.note_public' => '',
410 'c.note_private' => '',
411 'c.date_livraison' => '2020-01-01',
412 'c.fk_user_valid' => '1',
413 'c.multicurrency_code' => '',
414 'c.multicurrency_tx' => '1',
415 'c.multicurrency_total_ht' => '0',
416 'c.multicurrency_total_tva' => '0',
417 'c.multicurrency_total_ttc' => '0'
418 ];
419 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
420 $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
421 $this->import_convertvalue_array[$r] = array(
422 'c.ref' => array(
423 'rule' => 'getrefifauto',
424 'class' => (!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
425 'path' => "/core/modules/propale/".(!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON).'.php',
426 'classobject' => 'Propal',
427 'pathobject' => '/comm/propal/class/propal.class.php',
428 ),
429 'c.fk_soc' => array(
430 'rule' => 'fetchidfromref',
431 'file' => '/societe/class/societe.class.php',
432 'class' => 'Societe',
433 'method' => 'fetch',
434 'element' => 'ThirdParty'
435 )
436 );
437
438 //Import Proposal Lines
439 $r++;
440 $this->import_code[$r] = $this->rights_class.'line_'.$r;
441 $this->import_label[$r] = "ProposalLines"; // Translation key
442 $this->import_icon[$r] = $this->picto;
443 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
444 $this->import_tables_array[$r] = array(
445 'cd' => MAIN_DB_PREFIX.'propaldet',
446 'extra' => MAIN_DB_PREFIX.'propaldet_extrafields'
447 );
448 $this->import_fields_array[$r] = array(
449 'cd.fk_propal' => 'Proposal*',
450 'cd.fk_parent_line' => 'ParentLine',
451 'cd.fk_product' => 'IdProduct',
452 'cd.description' => 'LineDescription',
453 'cd.product_type' => 'TypeOfLineServiceOrProduct',
454 'cd.tva_tx' => 'LineVATRate',
455 'cd.qty' => 'LineQty',
456 'cd.remise_percent' => 'Reduc. Percent',
457 'cd.price' => 'Price',
458 'cd.subprice' => 'Sub Price',
459 'cd.total_ht' => 'LineTotalHT',
460 'cd.total_tva' => 'LineTotalVAT',
461 'cd.total_ttc' => 'LineTotalTTC',
462 'cd.date_start' => 'Start Date',
463 'cd.date_end' => 'End Date',
464 'cd.buy_price_ht' => 'LineBuyPriceHT'
465 );
466 if (isModEnabled("multicurrency")) {
467 $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
468 $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
469 $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
470 $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
471 $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
472 }
473 // Add extra fields
474 $import_extrafield_sample = array();
475 $keyforselect = 'propaldet';
476 $keyforelement = 'propal';
477 $keyforaliasextra = 'extra';
478 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
479 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propaldet');
480 $this->import_regex_array[$r] = array('cd.product_type' => '[0|1]$');
481 $import_sample = array(
482 'cd.fk_propal' => 'PROV(0001)',
483 'cd.fk_parent_line' => '',
484 'cd.fk_product' => '',
485 'cd.description' => 'Line description',
486 'cd.product_type' => '1',
487 'cd.tva_tx' => '0',
488 'cd.qty' => '2',
489 'cd.remise_percent' => '0',
490 'cd.price' => '',
491 'cd.subprice' => '5000',
492 'cd.total_ht' => '10000',
493 'cd.total_tva' => '0',
494 'cd.total_ttc' => '10100',
495 'cd.date_start' => '',
496 'cd.date_end' => '',
497 'cd.buy_price_ht' => '7000',
498 'cd.multicurrency_code' => 'JPY',
499 'cd.multicurrency_tx' => '1',
500 'cd.multicurrency_total_ht' => '10000',
501 'cd.multicurrency_total_tva' => '0',
502 'cd.multicurrency_total_ttc' => '10100'
503 );
504 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
505 $this->import_updatekeys_array[$r] = array('cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id');
506 $this->import_convertvalue_array[$r] = array(
507 'cd.fk_propal' => array(
508 'rule' => 'fetchidfromref',
509 'file' => '/comm/propal/class/propal.class.php',
510 'class' => 'Propal',
511 'method' => 'fetch'
512 )
513 );
514 }
515
516
525 public function init($options = '')
526 {
527 global $conf, $langs;
528
529 $result = $this->_load_tables('/install/mysql/', 'propal');
530 if ($result < 0) {
531 return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
532 }
533
534 // Remove permissions and default values
535 $this->remove($options);
536
537 //ODT template
538 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
539 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/proposals';
540 $dest = $dirodt.'/template_proposal.odt';
541
542 if (file_exists($src) && !file_exists($dest)) {
543 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
544 dol_mkdir($dirodt);
545 $result = dol_copy($src, $dest, '0', 0);
546 if ($result < 0) {
547 $langs->load("errors");
548 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
549 return 0;
550 }
551 }
552
553 $sql = array(
554 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'propal' AND entity = ".((int) $conf->entity),
555 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','propal',".((int) $conf->entity).")",
556 );
557
558 return $this->_init($sql, $options);
559 }
560}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
_load_tables($reldir, $onlywithsuffix='')
Create tables and keys required by module:
Class to describe and enable module Propale.
__construct($db)
Constructor.
init($options='')
Function called when module is enabled.
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.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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 browser version
Definition main.inc.php:229
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.