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