dolibarr 19.0.3
modCommande.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2013 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) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2020 Ahmad Jamaly Rabub <rabib@metroworks.co.jp>
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
33include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
34
35
40{
46 public function __construct($db)
47 {
48 global $conf, $user;
49
50 $this->db = $db;
51 $this->numero = 25;
52
53 $this->family = "crm";
54 $this->module_position = '11';
55 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
56 $this->name = preg_replace('/^mod/i', '', get_class($this));
57 $this->description = "Gestion des commandes clients";
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 = 'order';
63
64 // Data directories to create when module is enabled
65 $this->dirs = array("/commande/temp");
66
67 // Config pages
68 $this->config_page_url = array("commande.php");
69
70 // Dependancies
71 $this->depends = array("modSociete");
72 $this->requiredby = array("modExpedition");
73 $this->conflictwith = array();
74 $this->langfiles = array('orders', 'bills', 'companies', 'products', 'deliveries', 'sendings');
75
76 // Constants
77 $this->const = array();
78 $r = 0;
79
80 $this->const[$r][0] = "COMMANDE_ADDON_PDF";
81 $this->const[$r][1] = "chaine";
82 $this->const[$r][2] = "eratosthene";
83 $this->const[$r][3] = 'Name of PDF model of order';
84 $this->const[$r][4] = 0;
85
86 $r++;
87 $this->const[$r][0] = "COMMANDE_ADDON";
88 $this->const[$r][1] = "chaine";
89 $this->const[$r][2] = "mod_commande_marbre";
90 $this->const[$r][3] = 'Name of numbering numerotation rules of order';
91 $this->const[$r][4] = 0;
92
93 $r++;
94 $this->const[$r][0] = "COMMANDE_ADDON_PDF_ODT_PATH";
95 $this->const[$r][1] = "chaine";
96 $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/orders";
97 $this->const[$r][3] = "";
98 $this->const[$r][4] = 0;
99
100 /*$r++;
101 $this->const[$r][0] = "COMMANDE_DRAFT_WATERMARK";
102 $this->const[$r][1] = "chaine";
103 $this->const[$r][2] = "__(Draft)__";
104 $this->const[$r][3] = 'Watermark to show on draft orders';
105 $this->const[$r][4] = 0;*/
106
107 // Boxes
108 $this->boxes = array(
109 0=>array('file'=>'box_commandes.php', 'enabledbydefaulton'=>'Home'),
110 2=>array('file'=>'box_graph_orders_permonth.php', 'enabledbydefaulton'=>'Home')
111 );
112
113 // Permissions
114 $this->rights = array();
115 $this->rights_class = 'commande';
116
117 $r = 0;
118
119 $r++;
120 $this->rights[$r][0] = 81;
121 $this->rights[$r][1] = 'Read sales orders';
122 $this->rights[$r][2] = 'r';
123 $this->rights[$r][3] = 0;
124 $this->rights[$r][4] = 'lire';
125
126 $r++;
127 $this->rights[$r][0] = 82;
128 $this->rights[$r][1] = 'Creeat/modify sales orders';
129 $this->rights[$r][2] = 'w';
130 $this->rights[$r][3] = 0;
131 $this->rights[$r][4] = 'creer';
132
133 $r++;
134 $this->rights[$r][0] = 84;
135 $this->rights[$r][1] = 'Validate sales orders';
136 $this->rights[$r][2] = 'd';
137 $this->rights[$r][3] = 0;
138 $this->rights[$r][4] = 'order_advance';
139 $this->rights[$r][5] = 'validate';
140
141 $r++;
142 $this->rights[$r][0] = 85;
143 $this->rights[$r][1] = 'Generate the documents sales orders';
144 $this->rights[$r][2] = 'd';
145 $this->rights[$r][3] = 0;
146 $this->rights[$r][4] = 'order_advance';
147 $this->rights[$r][5] = 'generetedoc';
148
149 $r++;
150 $this->rights[$r][0] = 86;
151 $this->rights[$r][1] = 'Send sales orders by email';
152 $this->rights[$r][2] = 'd';
153 $this->rights[$r][3] = 0;
154 $this->rights[$r][4] = 'order_advance';
155 $this->rights[$r][5] = 'send';
156
157 $r++;
158 $this->rights[$r][0] = 87;
159 $this->rights[$r][1] = 'Close sale orders';
160 $this->rights[$r][2] = 'd';
161 $this->rights[$r][3] = 0;
162 $this->rights[$r][4] = 'order_advance';
163 $this->rights[$r][5] = 'close';
164
165 $r++;
166 $this->rights[$r][0] = 88;
167 $this->rights[$r][1] = 'Cancel sale orders';
168 $this->rights[$r][2] = 'd';
169 $this->rights[$r][3] = 0;
170 $this->rights[$r][4] = 'order_advance';
171 $this->rights[$r][5] = 'annuler';
172
173 $r++;
174 $this->rights[$r][0] = 89;
175 $this->rights[$r][1] = 'Delete sales orders';
176 $this->rights[$r][2] = 'd';
177 $this->rights[$r][3] = 0;
178 $this->rights[$r][4] = 'supprimer';
179
180 $r++;
181 $this->rights[$r][0] = 1421;
182 $this->rights[$r][1] = 'Export sales orders and attributes';
183 $this->rights[$r][2] = 'r';
184 $this->rights[$r][3] = 0;
185 $this->rights[$r][4] = 'commande';
186 $this->rights[$r][5] = 'export';
187
188
189 // Menus
190 //-------
191 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
192
193
194 // Exports
195 //--------
196 $r = 0;
197
198 $r++;
199 $this->export_code[$r] = $this->rights_class.'_'.$r;
200 $this->export_label[$r] = 'CustomersOrdersAndOrdersLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
201 $this->export_permission[$r] = array(array("commande", "commande", "export"));
202 $this->export_fields_array[$r] = array(
203 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'd.nom'=>'State', 'co.label'=>'Country',
204 'co.code'=>"CountryCode", 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 'c.rowid'=>"Id",
205 'c.ref'=>"Ref", 'c.ref_client'=>"RefCustomer", 'c.fk_soc'=>"IdCompany", 'c.date_creation'=>"DateCreation", 'c.date_commande'=>"OrderDate",
206 'c.date_livraison'=>"DateDeliveryPlanned", 'c.amount_ht'=>"Amount", 'c.total_ht'=>"TotalHT",
207 'c.total_ttc'=>"TotalTTC", 'c.facture'=>"Billed", 'c.fk_statut'=>'Status', 'c.note_public'=>"Note", 'sm.code'=>'SendingMethod',
208 'c.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', 'c.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin',
209 'pj.ref'=>'ProjectRef', 'cd.rowid'=>'LineId', 'cd.description'=>"LineDescription", 'cd.product_type'=>'TypeOfLineServiceOrProduct',
210 'cd.tva_tx'=>"LineVATRate", 'cd.qty'=>"LineQty", 'cd.total_ht'=>"LineTotalHT", 'cd.total_tva'=>"LineTotalVAT", 'cd.total_ttc'=>"LineTotalTTC",
211 'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel'
212 );
213 if (isModEnabled("multicurrency")) {
214 $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
215 $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
216 $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
217 $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
218 $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
219 }
220 // Add multicompany field
221 if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
222 $nbofallowedentities = count(explode(',', getEntity('commande')));
223 if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
224 $this->export_fields_array[$r]['c.entity'] = 'Entity';
225 }
226 }
227 //$this->export_TypeFields_array[$r]=array(
228 // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label',
229 // 'co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",
230 // 'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.total_ht'=>"Numeric",
231 // 'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','cd.description'=>"Text",
232 // 'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",
233 // 'p.rowid'=>'List:product:ref','p.ref'=>'Text','p.label'=>'Text'
234 //);
235 $this->export_TypeFields_array[$r] = array(
236 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'co.label'=>'List:c_country:label:label', 'co.code'=>'Text', 's.phone'=>'Text',
237 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 'c.ref'=>"Text", 'c.ref_client'=>"Text", 'c.date_creation'=>"Date",
238 'c.date_commande'=>"Date", 'c.date_livraison'=>"Date", 'sm.code'=>"Text", 'c.amount_ht'=>"Numeric", 'c.total_ht'=>"Numeric",
239 'c.total_ttc'=>"Numeric", 'c.facture'=>"Boolean", 'c.fk_statut'=>'Status', 'c.note_public'=>"Text", 'pj.ref'=>'Text',
240 'cd.description'=>"Text", 'cd.product_type'=>'Boolean', 'cd.tva_tx'=>"Numeric", 'cd.qty'=>"Numeric", 'cd.total_ht'=>"Numeric", 'cd.total_tva'=>"Numeric",
241 'cd.total_ttc'=>"Numeric", 'p.rowid'=>'List:product:ref::product', 'p.ref'=>'Text', 'p.label'=>'Text', 'd.nom'=>'Text',
242 'c.entity'=>'List:entity:label:rowid',
243 );
244 $this->export_entities_array[$r] = array(
245 's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'd.nom'=>'company', 'co.label'=>'company',
246 'co.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.siret'=>'company', 'c.rowid'=>"order",
247 'c.ref'=>"order", 'c.ref_client'=>"order", 'c.fk_soc'=>"order", 'c.date_creation'=>"order", 'c.date_commande'=>"order", 'c.amount_ht'=>"order",
248 'c.total_ht'=>"order", 'c.total_ttc'=>"order", 'c.facture'=>"order", 'c.fk_statut'=>"order", 'c.note'=>"order",
249 'c.date_livraison'=>"order", 'sm.code'=>"order", 'pj.ref'=>'project', 'cd.rowid'=>'order_line', 'cd.description'=>"order_line",
250 'cd.product_type'=>'order_line', 'cd.tva_tx'=>"order_line", 'cd.qty'=>"order_line", 'cd.total_ht'=>"order_line", 'cd.total_tva'=>"order_line",
251 'cd.total_ttc'=>"order_line", 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'
252 );
253 $this->export_dependencies_array[$r] = array('order_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
254 $keyforselect = 'commande';
255 $keyforelement = 'order';
256 $keyforaliasextra = 'extra';
257 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
258 $keyforselect = 'commandedet';
259 $keyforelement = 'order_line';
260 $keyforaliasextra = 'extra2';
261 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
262 $keyforselect = 'product';
263 $keyforelement = 'product';
264 $keyforaliasextra = 'extra3';
265 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
266 $keyforselect = 'societe';
267 $keyforelement = 'company';
268 $keyforaliasextra = 'extra4';
269 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
270 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
271 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
272 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
273 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
274 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
275 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
276 }
277 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
278 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
279 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande as c';
280 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_shipment_mode as sm ON c.fk_shipping_method = sm.rowid';
281 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
282 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
283 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
284 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_extrafields as extra ON c.rowid = extra.fk_object';
285 $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'commandedet as cd';
286 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object';
287 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
288 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
289 $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande';
290 $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('commande').')';
291 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
292 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
293 }
294
295 // Imports
296 //--------
297 $r = 0;
298 //Import Order Header
299
300 $r++;
301 $this->import_code[$r] = 'commande_'.$r;
302 $this->import_label[$r] = 'CustomersOrders';
303 $this->import_icon[$r] = $this->picto;
304 $this->import_entities_array[$r] = array();
305 $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande', 'extra' => MAIN_DB_PREFIX.'commande_extrafields');
306 $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
307 $import_sample = array();
308 $this->import_fields_array[$r] = array(
309 'c.ref' => 'Ref*',
310 'c.ref_client' => 'RefCustomer',
311 'c.fk_soc' => 'ThirdPartyName*',
312 'c.fk_projet' => 'ProjectId',
313 'c.date_creation' => 'DateCreation',
314 'c.date_valid' => 'DateValidation',
315 'c.date_commande' => 'OrderDate*',
316 'c.fk_user_modif' => 'ModifiedById',
317 'c.fk_user_valid' => 'ValidatedById',
318 'c.total_tva' => 'TotalTVA',
319 'c.total_ht' => 'TotalHT',
320 'c.total_ttc' => 'TotalTTC',
321 'c.note_private' => 'NotePrivate',
322 'c.note_public' => 'Note',
323 'c.facture' => 'Invoice(1/0)',
324 'c.date_livraison' => 'DeliveryDate',
325 'c.fk_cond_reglement' => 'Payment Condition',
326 'c.fk_mode_reglement' => 'Payment Mode',
327 'c.model_pdf' => 'Model',
328 'c.fk_statut' => 'Status*'
329 );
330
331 if (isModEnabled("multicurrency")) {
332 $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
333 $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
334 $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
335 $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
336 $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
337 }
338 $import_extrafield_sample = array();
339 $keyforselect = 'commande';
340 $keyforelement = 'order';
341 $keyforaliasextra = 'extra';
342 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
343
344 $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande');
345 $this->import_regex_array[$r] = array(
346 'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
347 );
348 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
349 $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
350 $this->import_convertvalue_array[$r] = array(
351 'c.ref' => array(
352 'rule'=>'getrefifauto',
353 'class'=>(!getDolGlobalString('COMMANDE_ADDON') ? 'mod_commande_marbre' : $conf->global->COMMANDE_ADDON),
354 'path'=>"/core/modules/commande/".(!getDolGlobalString('COMMANDE_ADDON') ? 'mod_commande_marbre' : $conf->global->COMMANDE_ADDON).'.php',
355 'classobject'=>'Commande',
356 'pathobject'=>'/commande/class/commande.class.php',
357 ),
358 'c.fk_soc' => array(
359 'rule' => 'fetchidfromref',
360 'file' => '/societe/class/societe.class.php',
361 'class' => 'Societe',
362 'method' => 'fetch',
363 'element' => 'ThirdParty'
364 ),
365 'c.fk_user_valid' => array(
366 'rule' => 'fetchidfromref',
367 'file' => '/user/class/user.class.php',
368 'class' => 'User',
369 'method' => 'fetch',
370 'element' => 'user'
371 ),
372 'c.fk_mode_reglement' => array(
373 'rule' => 'fetchidfromcodeorlabel',
374 'file' => '/compta/paiement/class/cpaiement.class.php',
375 'class' => 'Cpaiement',
376 'method' => 'fetch',
377 'element' => 'cpayment'
378 ),
379 );
380
381 //Import Order Lines
382 $r++;
383 $this->import_code[$r] = 'commande_lines_'.$r;
384 $this->import_label[$r] = 'SaleOrderLines';
385 $this->import_icon[$r] = $this->picto;
386 $this->import_entities_array[$r] = array();
387 $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX.'commandedet', 'extra' => MAIN_DB_PREFIX.'commandedet_extrafields');
388 $this->import_fields_array[$r] = array(
389 'cd.fk_commande' => 'CustomerOrder*',
390 'cd.fk_parent_line' => 'ParentLine',
391 'cd.fk_product' => 'IdProduct',
392 'cd.description' => 'LineDescription',
393 'cd.tva_tx' => 'LineVATRate',
394 'cd.qty' => 'LineQty',
395 'cd.remise_percent' => 'Reduc. Percent',
396 'cd.price' => 'Price',
397 'cd.subprice' => 'Sub Price',
398 'cd.total_ht' => 'LineTotalHT',
399 'cd.total_tva' => 'LineTotalVAT',
400 'cd.total_ttc' => 'LineTotalTTC',
401 'cd.product_type' => 'TypeOfLineServiceOrProduct',
402 'cd.date_start' => 'Start Date',
403 'cd.date_end' => 'End Date',
404 'cd.buy_price_ht' => 'LineBuyPriceHT',
405 'cd.rang' => 'LinePosition'
406 );
407
408 if (isModEnabled("multicurrency")) {
409 $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
410 $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
411 $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
412 $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
413 $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
414 }
415
416 $import_extrafield_sample = array();
417 $keyforselect = 'commandedet';
418 $keyforelement = 'orderline';
419 $keyforaliasextra = 'extra';
420 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinimport.inc.php';
421
422 $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commandedet'];
423 $this->import_regex_array[$r] = [
424 'cd.product_type' => '[0|1]$',
425 'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
426 'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
427 ];
428 $this->import_updatekeys_array[$r] = ['cd.fk_commande' => 'Sales Order Id', 'cd.fk_product' => 'Product Id'];
429 $this->import_convertvalue_array[$r] = [
430 'cd.fk_commande' => [
431 'rule' => 'fetchidfromref',
432 'file' => '/commande/class/commande.class.php',
433 'class' => 'Commande',
434 'method' => 'fetch',
435 'element' => 'commande'
436 ],
437 ];
438 }
439
440
449 public function init($options = '')
450 {
451 global $conf, $langs;
452
453 // Permissions
454 $this->remove($options);
455
456 //ODT template
457 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt';
458 $dirodt = DOL_DATA_ROOT.'/doctemplates/orders';
459 $dest = $dirodt.'/template_order.odt';
460
461 if (file_exists($src) && !file_exists($dest)) {
462 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
463 dol_mkdir($dirodt);
464 $result = dol_copy($src, $dest, 0, 0);
465 if ($result < 0) {
466 $langs->load("errors");
467 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
468 return 0;
469 }
470 }
471
472 $sql = array(
473 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order' AND entity = ".((int) $conf->entity),
474 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'order', ".((int) $conf->entity).")"
475 );
476
477 return $this->_init($sql, $options);
478 }
479}
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe module Sales Orders.
__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 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)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124