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