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