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 ];
124
125 /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK";
126 $this->const[$r][2] = "__(Draft)__";
127 $this->const[$r][3] = 'Watermark to show on draft proposals';
128 $this->const[$r][4] = 0;
129 $r++;*/
130
131 // Boxes
132 $this->boxes = array(
133 0 => array('file' => 'box_graph_propales_permonth.php', 'enabledbydefaulton' => 'Home'),
134 1 => array('file' => 'box_propales.php', 'enabledbydefaulton' => 'Home'),
135 );
136
137 // Permissions
138 $this->rights = array();
139 $this->rights_class = 'propale';
140 $r = 0;
141
142 $r++;
143 $this->rights[$r][0] = 21; // id de la permission
144 $this->rights[$r][1] = 'Read commercial proposals'; // libelle de la permission
145 $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
146 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
147 $this->rights[$r][4] = 'lire';
148
149 $r++;
150 $this->rights[$r][0] = 22; // id de la permission
151 $this->rights[$r][1] = 'Create and update commercial proposals'; // libelle de la permission
152 $this->rights[$r][2] = 'w'; // type de la permission (deprecated)
153 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
154 $this->rights[$r][4] = 'creer';
155
156 $r++;
157 $this->rights[$r][0] = 24; // id de la permission
158 $this->rights[$r][1] = 'Validate commercial proposals'; // Validate proposal
159 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
160 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
161 $this->rights[$r][4] = 'propal_advance';
162 $this->rights[$r][5] = 'validate';
163
164 $r++;
165 $this->rights[$r][0] = 25; // id de la permission
166 $this->rights[$r][1] = 'Send commercial proposals to customers'; // libelle de la permission
167 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
168 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
169 $this->rights[$r][4] = 'propal_advance';
170 $this->rights[$r][5] = 'send';
171
172 $r++;
173 $this->rights[$r][0] = 26; // id de la permission
174 $this->rights[$r][1] = 'Close commercial proposals'; // Set proposal to signed or refused
175 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
176 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
177 $this->rights[$r][4] = 'propal_advance';
178 $this->rights[$r][5] = 'close';
179
180 $r++;
181 $this->rights[$r][0] = 27; // id de la permission
182 $this->rights[$r][1] = 'Delete commercial proposals'; // libelle de la permission
183 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
184 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
185 $this->rights[$r][4] = 'supprimer';
186
187 $r++;
188 $this->rights[$r][0] = 28; // id de la permission
189 $this->rights[$r][1] = 'Exporting commercial proposals and attributes'; // libelle de la permission
190 $this->rights[$r][2] = 'r'; // type de la permission (deprecated)
191 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
192 $this->rights[$r][4] = 'export';
193
194 $r++;
195 $this->rights[$r][0] = 29; // id de la permission
196 $this->rights[$r][1] = 'Reopen commercial proposals'; // Set proposal to signed or refused
197 $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
198 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
199 $this->rights[$r][4] = 'propal_advance';
200 $this->rights[$r][5] = 'reopen';
201
202 // Menus
203 //-------
204 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
205
206
207 // Exports
208 //--------
209 $r = 0;
210
211 $r++;
212 $this->export_code[$r] = $this->rights_class.'_'.$r;
213 $this->export_label[$r] = 'ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
214 $this->export_permission[$r] = array(array("propale", "export"));
215 $this->export_fields_array[$r] = array(
216 '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',
217 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 'c.rowid' => "Id", 'c.ref' => "Ref", 'c.ref_client' => "RefCustomer",
218 'c.fk_soc' => "IdCompany", 'c.datec' => "DateCreation", 'c.datep' => "DatePropal", 'c.fin_validite' => "DateEndPropal",
219 'c.total_ht' => "TotalHT", 'c.total_ttc' => "TotalTTC",
220 'cir.label' => 'Source',
221 );
222 if (isModEnabled("multicurrency")) {
223 $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
224 $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
225 $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
226 $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
227 $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
228 }
229 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
230 'c.fk_statut' => 'Status', 'c.note_public' => "NotePublic", 'c.note_private' => "NotePrivate", 'c.date_livraison' => 'DeliveryDate',
231 'c.fk_user_author' => 'CreatedById', 'uc.login' => 'CreatedByLogin',
232 'c.fk_user_valid' => 'ValidatedById', 'uv.login' => 'ValidatedByLogin'));
233 if (isModEnabled("project")) {
234 $this->export_fields_array[$r]['pj.ref'] = 'ProjectRef';
235 }
236 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
237 'cd.rowid' => 'LineId', 'cd.description' => "LineDescription", 'cd.product_type' => 'TypeOfLineServiceOrProduct',
238 'cd.tva_tx' => "LineVATRate", 'cd.qty' => "LineQty", 'cd.total_ht' => "LineTotalHT", 'cd.total_tva' => "LineTotalVAT", 'cd.total_ttc' => "LineTotalTTC",
239 ));
240 $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
241 'p.rowid' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel'
242 ));
243 // Add multicompany field
244 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
245 $nbofallowedentities = count(explode(',', getEntity('propal')));
246 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
247 $this->export_fields_array[$r]['c.entity'] = 'Entity';
248 }
249 }
250 //$this->export_TypeFields_array[$r]=array(
251 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text',
252 // '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",
253 // 'c.fin_validite'=>"Date",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.note_private'=>"Text",
254 // 'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",
255 // 'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
256 //);
257 $this->export_TypeFields_array[$r] = array(
258 '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',
259 's.ape' => 'Text', 's.idprof4' => 'Text', 'c.ref' => "Text", 'c.ref_client' => "Text", 'c.datec' => "Date", 'c.datep' => "Date", 'c.fin_validite' => "Date",
260 'c.total_ht' => "Numeric", 'c.total_ttc' => "Numeric", 'c.fk_statut' => 'Status', 'c.note_public' => "Text", 'c.note_private' => "Text", 'c.date_livraison' => 'Date',
261 'pj.ref' => 'Text', 'cd.description' => "Text", 'cd.product_type' => 'Boolean', 'cd.tva_tx' => "Numeric", 'cd.qty' => "Numeric", 'cd.total_ht' => "Numeric",
262 'cd.total_tva' => "Numeric", 'cd.total_ttc' => "Numeric", 'p.ref' => 'Text', 'p.label' => 'Text',
263 'c.entity' => 'List:entity:label:rowid',
264 'cir.label' => 'Text',
265 );
266 $this->export_entities_array[$r] = array(
267 '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',
268 's.siren' => 'company', 's.ape' => 'company', 's.idprof4' => 'company', 's.siret' => 'company', 'c.rowid' => "propal", 'c.ref' => "propal", 'c.ref_client' => "propal",
269 'c.fk_soc' => "propal", 'c.datec' => "propal", 'c.datep' => "propal", 'c.fin_validite' => "propal", 'c.total_ht' => "propal",
270 'c.total_ttc' => "propal", 'c.fk_statut' => "propal", 'c.note_public' => "propal", 'c.note_private' => "propal", 'c.date_livraison' => "propal",
271 'c.fk_user_author' => 'user', 'uc.login' => 'user',
272 'c.fk_user_valid' => 'user', 'uv.login' => 'user',
273 'pj.ref' => 'project',
274 'cd.rowid' => 'propal_line',
275 'cd.description' => "propal_line", 'cd.product_type' => 'propal_line', 'cd.tva_tx' => "propal_line", 'cd.qty' => "propal_line",
276 'cd.total_ht' => "propal_line", 'cd.total_tva' => "propal_line", 'cd.total_ttc' => "propal_line", 'p.rowid' => 'product', 'p.ref' => 'product', 'p.label' => 'product'
277 );
278 $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
279 $keyforselect = 'propal';
280 $keyforelement = 'propal';
281 $keyforaliasextra = 'extra';
282 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
283 $keyforselect = 'propaldet';
284 $keyforelement = 'propal_line';
285 $keyforaliasextra = 'extra2';
286 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
287 $keyforselect = 'product';
288 $keyforelement = 'product';
289 $keyforaliasextra = 'extra3';
290 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
291 $keyforselect = 'societe';
292 $keyforelement = 'company';
293 $keyforaliasextra = 'extra4';
294 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
295
296 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
297 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s ';
298 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
299 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
300 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
301 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
302 }
303 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
304 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'propal as c';
305 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
306 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
307 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
308 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
309 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
310 $this->export_sql_end[$r] .= ', '.MAIN_DB_PREFIX.'propaldet as cd';
311 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
312 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
313 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
314 $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
315 $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')';
316 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
317 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
318 }
319 $parameters = array();
320 $hookmanager->executeHooks('printExportWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
321 $this->export_sql_end[$r] .= $hookmanager->resPrint;
322
323 // Imports
324 //--------
325 $r = 0;
326
327 $r++;
328 $this->import_code[$r] = $this->rights_class.'_'.$r;
329 $this->import_label[$r] = 'Proposals'; // Translation key
330 $this->import_icon[$r] = $this->picto;
331 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
332 $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'propal', 'extra' => MAIN_DB_PREFIX.'propal_extrafields');
333 $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
334 $this->import_fields_array[$r] = array(
335 'c.ref' => 'Ref*',
336 'c.ref_client' => 'RefCustomer',
337 'c.fk_soc' => 'ThirdPartyName*',
338 'c.datec' => 'DateCreation',
339 'c.datep' => 'DatePropal',
340 'c.fin_validite' => 'DateEndPropal',
341 'c.total_ht' => 'TotalHT',
342 'c.total_ttc' => 'TotalTTC',
343 'c.fk_statut' => 'Status*',
344 'c.note_public' => 'NotePublic',
345 'c.note_private' => 'NotePrivate',
346 'c.date_livraison' => 'DeliveryDate',
347 'c.fk_user_valid' => 'ValidatedById'
348 );
349 if (isModEnabled("multicurrency")) {
350 $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
351 $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
352 $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
353 $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
354 $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
355 }
356 // Add extra fields
357 $import_extrafield_sample = array();
358 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".((int) $conf->entity).")";
359 $resql = $this->db->query($sql);
360 if ($resql) {
361 while ($obj = $this->db->fetch_object($resql)) {
362 $fieldname = 'extra.'.$obj->name;
363 $fieldlabel = ucfirst($obj->label);
364 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
365 $import_extrafield_sample[$fieldname] = $fieldlabel;
366 }
367 }
368 // End add extra fields
369 $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propal'];
370 $this->import_regex_array[$r] = ['c.ref' => '[^ ]'];
371 $import_sample = [
372 'c.ref' => 'PROV0077',
373 'c.ref_client' => 'Client1',
374 'c.fk_soc' => 'MyBigCompany',
375 'c.datec' => '2020-01-01',
376 'c.datep' => '2020-01-01',
377 'c.fin_validite' => '2020-01-01',
378 'c.total_ht' => '0',
379 'c.total_ttc' => '0',
380 'c.fk_statut' => '1',
381 'c.note_public' => '',
382 'c.note_private' => '',
383 'c.date_livraison' => '2020-01-01',
384 'c.fk_user_valid' => '1',
385 'c.multicurrency_code' => '',
386 'c.multicurrency_tx' => '1',
387 'c.multicurrency_total_ht' => '0',
388 'c.multicurrency_total_tva' => '0',
389 'c.multicurrency_total_ttc' => '0'
390 ];
391 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
392 $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
393 $this->import_convertvalue_array[$r] = array(
394 'c.ref' => array(
395 'rule' => 'getrefifauto',
396 'class' => (!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
397 'path' => "/core/modules/propale/".(!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON).'.php',
398 'classobject' => 'Propal',
399 'pathobject' => '/comm/propal/class/propal.class.php',
400 ),
401 'c.fk_soc' => array(
402 'rule' => 'fetchidfromref',
403 'file' => '/societe/class/societe.class.php',
404 'class' => 'Societe',
405 'method' => 'fetch',
406 'element' => 'ThirdParty'
407 )
408 );
409
410 //Import Proposal Lines
411 $r++;
412 $this->import_code[$r] = $this->rights_class.'line_'.$r;
413 $this->import_label[$r] = "ProposalLines"; // Translation key
414 $this->import_icon[$r] = $this->picto;
415 $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
416 $this->import_tables_array[$r] = array(
417 'cd' => MAIN_DB_PREFIX.'propaldet',
418 'extra' => MAIN_DB_PREFIX.'propaldet_extrafields'
419 );
420 $this->import_fields_array[$r] = array(
421 'cd.fk_propal' => 'Proposal*',
422 'cd.fk_parent_line' => 'ParentLine',
423 'cd.fk_product' => 'IdProduct',
424 'cd.description' => 'LineDescription',
425 'cd.product_type' => 'TypeOfLineServiceOrProduct',
426 'cd.tva_tx' => 'LineVATRate',
427 'cd.qty' => 'LineQty',
428 'cd.remise_percent' => 'Reduc. Percent',
429 'cd.price' => 'Price',
430 'cd.subprice' => 'Sub Price',
431 'cd.total_ht' => 'LineTotalHT',
432 'cd.total_tva' => 'LineTotalVAT',
433 'cd.total_ttc' => 'LineTotalTTC',
434 'cd.date_start' => 'Start Date',
435 'cd.date_end' => 'End Date',
436 'cd.buy_price_ht' => 'LineBuyPriceHT'
437 );
438 if (isModEnabled("multicurrency")) {
439 $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
440 $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
441 $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
442 $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
443 $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
444 }
445 // Add extra fields
446 $import_extrafield_sample = array();
447 $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".((int) $conf->entity).")";
448 $resql = $this->db->query($sql);
449 if ($resql) {
450 while ($obj = $this->db->fetch_object($resql)) {
451 $fieldname = 'extra.'.$obj->name;
452 $fieldlabel = ucfirst($obj->label);
453 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
454 $import_extrafield_sample[$fieldname] = $fieldlabel;
455 }
456 }
457 // End add extra fields
458 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propaldet');
459 $this->import_regex_array[$r] = array('cd.product_type' => '[0|1]$');
460 $import_sample = array(
461 'cd.fk_propal' => 'PROV(0001)',
462 'cd.fk_parent_line' => '',
463 'cd.fk_product' => '',
464 'cd.description' => 'Line description',
465 'cd.product_type' => '1',
466 'cd.tva_tx' => '0',
467 'cd.qty' => '2',
468 'cd.remise_percent' => '0',
469 'cd.price' => '',
470 'cd.subprice' => '5000',
471 'cd.total_ht' => '10000',
472 'cd.total_tva' => '0',
473 'cd.total_ttc' => '10100',
474 'cd.date_start' => '',
475 'cd.date_end' => '',
476 'cd.buy_price_ht' => '7000',
477 'cd.multicurrency_code' => 'JPY',
478 'cd.multicurrency_tx' => '1',
479 'cd.multicurrency_total_ht' => '10000',
480 'cd.multicurrency_total_tva' => '0',
481 'cd.multicurrency_total_ttc' => '10100'
482 );
483 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
484 $this->import_updatekeys_array[$r] = array('cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id');
485 $this->import_convertvalue_array[$r] = array(
486 'cd.fk_propal' => array(
487 'rule' => 'fetchidfromref',
488 'file' => '/comm/propal/class/propal.class.php',
489 'class' => 'Propal',
490 'method' => 'fetch'
491 )
492 );
493 }
494
495
504 public function init($options = '')
505 {
506 global $conf, $langs;
507
508 $result = $this->_load_tables('/install/mysql/', 'propal');
509 if ($result < 0) {
510 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')
511 }
512
513 // Remove permissions and default values
514 $this->remove($options);
515
516 //ODT template
517 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
518 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/proposals';
519 $dest = $dirodt.'/template_proposal.odt';
520
521 if (file_exists($src) && !file_exists($dest)) {
522 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
523 dol_mkdir($dirodt);
524 $result = dol_copy($src, $dest, '0', 0);
525 if ($result < 0) {
526 $langs->load("errors");
527 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
528 return 0;
529 }
530 }
531
532 $sql = array(
533 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'propal' AND entity = ".((int) $conf->entity),
534 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','propal',".((int) $conf->entity).")",
535 );
536
537 return $this->_init($sql, $options);
538 }
539}
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.
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.
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_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
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.