dolibarr  13.0.2
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 
31 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
32 
33 
38 {
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(5, 4); // 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] = "azur";
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/doctemplates/proposals";
104  $this->const[$r][3] = "";
105  $this->const[$r][4] = 0;
106  $r++;
107 
108  /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK";
109  $this->const[$r][2] = "__(Draft)__";
110  $this->const[$r][3] = 'Watermark to show on draft proposals';
111  $this->const[$r][4] = 0;
112  $r++;*/
113 
114  // Boxes
115  $this->boxes = array(
116  0=>array('file'=>'box_graph_propales_permonth.php', 'enabledbydefaulton'=>'Home'),
117  1=>array('file'=>'box_propales.php', 'enabledbydefaulton'=>'Home'),
118  );
119 
120  // Permissions
121  $this->rights = array();
122  $this->rights_class = 'propale';
123  $r = 0;
124 
125  $r++;
126  $this->rights[$r][0] = 21; // id de la permission
127  $this->rights[$r][1] = 'Read commercial proposals'; // libelle de la permission
128  $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
129  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
130  $this->rights[$r][4] = 'lire';
131 
132  $r++;
133  $this->rights[$r][0] = 22; // id de la permission
134  $this->rights[$r][1] = 'Create and update commercial proposals'; // libelle de la permission
135  $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
136  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
137  $this->rights[$r][4] = 'creer';
138 
139  $r++;
140  $this->rights[$r][0] = 24; // id de la permission
141  $this->rights[$r][1] = 'Validate commercial proposals'; // libelle de la permission
142  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
143  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
144  $this->rights[$r][4] = 'propal_advance';
145  $this->rights[$r][5] = 'validate';
146 
147  $r++;
148  $this->rights[$r][0] = 25; // id de la permission
149  $this->rights[$r][1] = 'Send commercial proposals to customers'; // libelle de la permission
150  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
151  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
152  $this->rights[$r][4] = 'propal_advance';
153  $this->rights[$r][5] = 'send';
154 
155  $r++;
156  $this->rights[$r][0] = 26; // id de la permission
157  $this->rights[$r][1] = 'Close commercial proposals'; // libelle de la permission
158  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
159  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
160  $this->rights[$r][4] = 'cloturer';
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', '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", 'c.remise_percent'=>"GlobalDiscount",
194  'c.total_ht'=>"TotalHT", 'c.total'=>"TotalTTC", 'c.fk_statut'=>'Status', 'c.note_public'=>"Note", 'c.date_livraison'=>'DeliveryDate',
195  'c.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', 'c.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin',
196  'pj.ref'=>'ProjectRef', 'cd.rowid'=>'LineId', 'cd.label'=>"Label", 'cd.description'=>"LineDescription", 'cd.product_type'=>'TypeOfLineServiceOrProduct',
197  'cd.tva_tx'=>"LineVATRate", 'cd.qty'=>"LineQty", 'cd.total_ht'=>"LineTotalHT", 'cd.total_tva'=>"LineTotalVAT", 'cd.total_ttc'=>"LineTotalTTC",
198  'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel'
199  );
200  if (!empty($conf->multicurrency->enabled))
201  {
202  $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
203  $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
204  $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
205  $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
206  $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
207  }
208  //$this->export_TypeFields_array[$r]=array(
209  // 's.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text',
210  // '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",
211  // 'c.fin_validite'=>"Date",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",
212  // 'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",
213  // 'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
214  //);
215  $this->export_TypeFields_array[$r] = array(
216  's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text',
217  's.ape'=>'Text', 's.idprof4'=>'Text', 'c.ref'=>"Text", 'c.ref_client'=>"Text", 'c.datec'=>"Date", 'c.datep'=>"Date", 'c.fin_validite'=>"Date",
218  'c.remise_percent'=>"Numeric", 'c.total_ht'=>"Numeric", 'c.total'=>"Numeric", 'c.fk_statut'=>'Status', 'c.note_public'=>"Text", 'c.date_livraison'=>'Date',
219  'pj.ref'=>'Text', 'cd.description'=>"Text", 'cd.product_type'=>'Boolean', 'cd.tva_tx'=>"Numeric", 'cd.qty'=>"Numeric", 'cd.total_ht'=>"Numeric",
220  'cd.total_tva'=>"Numeric", 'cd.total_ttc'=>"Numeric", 'p.ref'=>'Text', 'p.label'=>'Text'
221  );
222  $this->export_entities_array[$r] = array(
223  's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'co.code'=>'company', 's.phone'=>'company',
224  's.siren'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.siret'=>'company', 'c.rowid'=>"propal", 'c.ref'=>"propal", 'c.ref_client'=>"propal",
225  'c.fk_soc'=>"propal", 'c.datec'=>"propal", 'c.datep'=>"propal", 'c.fin_validite'=>"propal", 'c.remise_percent'=>"propal", 'c.total_ht'=>"propal",
226  'c.total'=>"propal", 'c.fk_statut'=>"propal", 'c.note_public'=>"propal", 'c.date_livraison'=>"propal", 'pj.ref'=>'project', 'cd.rowid'=>'propal_line',
227  'cd.label'=>"propal_line", 'cd.description'=>"propal_line", 'cd.product_type'=>'propal_line', 'cd.tva_tx'=>"propal_line", 'cd.qty'=>"propal_line",
228  'cd.total_ht'=>"propal_line", 'cd.total_tva'=>"propal_line", 'cd.total_ttc'=>"propal_line", 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'
229  );
230  $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
231  $keyforselect = 'propal'; $keyforelement = 'propal'; $keyforaliasextra = 'extra';
232  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
233  $keyforselect = 'propaldet'; $keyforelement = 'propal_line'; $keyforaliasextra = 'extra2';
234  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
235  $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3';
236  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
237  $keyforselect = 'societe'; $keyforelement = 'societe'; $keyforaliasextra = 'extra4';
238  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
239 
240  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
241  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s ';
242  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
243 
244  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
245  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
246  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'propal as c';
247  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
248  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
249  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
250  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
251  $this->export_sql_end[$r] .= ', '.MAIN_DB_PREFIX.'propaldet as cd';
252  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
253  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
254  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
255  $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
256  $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')';
257  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
258 
259  // Imports
260  //--------
261  $r = 0;
262 
263  $r++;
264  $this->import_code[$r] = $this->rights_class.'_'.$r;
265  $this->import_label[$r] = 'Proposals'; // Translation key
266  $this->import_icon[$r] = $this->picto;
267  $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon
268  $this->import_tables_array[$r] = ['c' => MAIN_DB_PREFIX.'propal', 'extra' => MAIN_DB_PREFIX.'propal_extrafields'];
269  $this->import_tables_creator_array[$r] = ['c'=>'fk_user_author']; // Fields to store import user id
270  $this->import_fields_array[$r] = [
271  'c.ref' => 'Document Ref*',
272  'c.ref_client' => 'RefCustomer',
273  'c.fk_soc' => 'ThirdPartyName*',
274  'c.datec' => 'DateCreation',
275  'c.datep' => 'DatePropal',
276  'c.fin_validite' => 'DateEndPropal',
277  'c.remise_percent' => 'GlobalDiscount',
278  'c.total_ht' => 'TotalHT',
279  'c.total' => 'TotalTTC',
280  'c.fk_statut' => 'Status*',
281  'c.note_public' => 'Note',
282  'c.date_livraison' => 'DeliveryDate',
283  'c.fk_user_valid' => 'ValidatedById'
284  ];
285  if (!empty($conf->multicurrency->enabled)) {
286  $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
287  $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
288  $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
289  $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
290  $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
291  }
292  // Add extra fields
293  $import_extrafield_sample = [];
294  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'propal' AND entity IN (0, ".$conf->entity.")";
295  $resql = $this->db->query($sql);
296  if ($resql) {
297  while ($obj = $this->db->fetch_object($resql)) {
298  $fieldname = 'extra.'.$obj->name;
299  $fieldlabel = ucfirst($obj->label);
300  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
301  $import_extrafield_sample[$fieldname] = $fieldlabel;
302  }
303  }
304  // End add extra fields
305  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propal'];
306  $this->import_regex_array[$r] = ['c.ref' => '[^ ]'];
307  $import_sample = [
308  'c.ref' => 'PROV0077',
309  'c.ref_client' => 'Client1',
310  'c.fk_soc' => 'MyBigCompany',
311  'c.datec' => '2020-01-01',
312  'c.datep' => '2020-01-01',
313  'c.fin_validite' => '2020-01-01',
314  'c.remise_percent' => '',
315  'c.total_ht' => '0',
316  'c.total' => '0',
317  'c.fk_statut' => '1',
318  'c.note_public' => '',
319  'c.date_livraison' => '2020-01-01',
320  'c.fk_user_valid' => '1',
321  'c.multicurrency_code' => '',
322  'c.multicurrency_tx' => '1',
323  'c.multicurrency_total_ht' => '0',
324  'c.multicurrency_total_tva' => '0',
325  'c.multicurrency_total_ttc' => '0'
326  ];
327  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
328  $this->import_updatekeys_array[$r] = ['c.ref'=>'Ref'];
329  $this->import_convertvalue_array[$r] = [
330  'c.fk_soc' => [
331  'rule' => 'fetchidfromref',
332  'file' => '/societe/class/societe.class.php',
333  'class' => 'Societe',
334  'method' => 'fetch',
335  'element' => 'ThirdParty'
336  ]
337  ];
338 
339  //Import Proposal Lines
340  $r++;
341  $this->import_code[$r] = $this->rights_class.'line_'.$r;
342  $this->import_label[$r] = "ProposalLine"; // Translation key
343  $this->import_icon[$r] = $this->picto;
344  $this->import_entities_array[$r] = []; // We define here only fields that use another icon that the one defined into import_icon
345  $this->import_tables_array[$r] = [
346  'cd' => MAIN_DB_PREFIX.'propaldet',
347  'extra' => MAIN_DB_PREFIX.'propaldet_extrafields'
348  ];
349  $this->import_fields_array[$r] = [
350  'cd.fk_propal' => 'Document Ref*',
351  'cd.fk_parent_line' => 'PrParentLine',
352  'cd.fk_product' => 'IdProduct',
353  'cd.label' => 'Label',
354  'cd.description' => 'LineDescription',
355  'cd.product_type' => 'TypeOfLineServiceOrProduct',
356  'cd.tva_tx' => 'LineVATRate',
357  'cd.qty' => 'LineQty',
358  'cd.remise_percent' => 'Reduc. Percent',
359  'cd.remise' => 'Reduc.',
360  'cd.price' => 'Price',
361  'cd.subprice' => 'Sub Price',
362  'cd.total_ht' => 'LineTotalHT',
363  'cd.total_tva' => 'LineTotalVAT',
364  'cd.total_ttc' => 'LineTotalTTC',
365  'cd.date_start' => 'Start Date',
366  'cd.date_end' => 'End Date',
367  'cd.buy_price_ht' => 'LineBuyPriceHT'
368  ];
369  if (!empty($conf->multicurrency->enabled)) {
370  $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
371  $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
372  $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
373  $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
374  $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
375  }
376  // Add extra fields
377  $import_extrafield_sample = [];
378  $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.")";
379  $resql = $this->db->query($sql);
380  if ($resql) {
381  while ($obj = $this->db->fetch_object($resql)) {
382  $fieldname = 'extra.'.$obj->name;
383  $fieldlabel = ucfirst($obj->label);
384  $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
385  $import_extrafield_sample[$fieldname] = $fieldlabel;
386  }
387  }
388  // End add extra fields
389  $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propaldet'];
390  $this->import_regex_array[$r] = ['cd.product_type' => '[0|1]$'];
391  $import_sample = [
392  'cd.fk_propal' => 'PROV(0001)',
393  'cd.fk_parent_line' => '',
394  'cd.fk_product' => '',
395  'cd.label' => '',
396  'cd.description' => 'Line description',
397  'cd.product_type' => '1',
398  'cd.tva_tx' => '0',
399  'cd.qty' => '2',
400  'cd.remise_percent' => '0',
401  'cd.remise' => '0',
402  'cd.price' => '',
403  'cd.subprice' => '5000',
404  'cd.total_ht' => '10000',
405  'cd.total_tva' => '0',
406  'cd.total_ttc' => '10100',
407  'cd.date_start' => '',
408  'cd.date_end' => '',
409  'cd.buy_price_ht' => '7000',
410  'cd.multicurrency_code' => 'JPY',
411  'cd.multicurrency_tx' => '1',
412  'cd.multicurrency_total_ht' => '10000',
413  'cd.multicurrency_total_tva' => '0',
414  'cd.multicurrency_total_ttc' => '10100'
415  ];
416  $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
417  $this->import_updatekeys_array[$r] = ['cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id'];
418  $this->import_convertvalue_array[$r] = [
419  'cd.fk_propal' => [
420  'rule'=>'fetchidfromref',
421  'file'=>'/comm/propal/class/propal.class.php',
422  'class'=>'Propal',
423  'method'=>'fetch'
424  ]
425  ];
426  }
427 
428 
437  public function init($options = '')
438  {
439  global $conf, $langs;
440 
441  // Remove permissions and default values
442  $this->remove($options);
443 
444  //ODT template
445  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
446  $dirodt = DOL_DATA_ROOT.'/doctemplates/proposals';
447  $dest = $dirodt.'/template_proposal.odt';
448 
449  if (file_exists($src) && !file_exists($dest))
450  {
451  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
452  dol_mkdir($dirodt);
453  $result = dol_copy($src, $dest, 0, 0);
454  if ($result < 0)
455  {
456  $langs->load("errors");
457  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
458  return 0;
459  }
460  }
461 
462  $sql = array(
463  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'propal' AND entity = ".$conf->entity,
464  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','propal',".$conf->entity.")",
465  );
466 
467  return $this->_init($sql, $options);
468  }
469 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
__construct($db)
Constructor.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:750
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
Class to describe and enable module Propale.
_init($array_sql, $options= '')
Enables a module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
init($options= '')
Function called when module is enabled.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)