56 $this->family =
"crm";
57 $this->module_position =
'11';
59 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
60 $this->
description =
"Gestion des commandes clients";
62 $this->version =
'dolibarr';
64 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
65 $this->picto =
'order';
68 $this->dirs = array(
"/commande/temp");
71 $this->config_page_url = array(
"order.php");
74 $this->depends = array(
"modSociete");
75 $this->requiredby = array(
"modExpedition");
76 $this->conflictwith = array();
77 $this->langfiles = array(
'orders',
'bills',
'companies',
'products',
'deliveries',
'sendings');
85 "Name of PDF model of order",
91 "mod_commande_marbre",
92 "Name of numbering numerotation rules of order",
96 "COMMANDE_ADDON_PDF_ODT_PATH",
98 "DOL_DATA_ROOT".($conf->entity > 1 ?
'/'.$conf->entity :
'').
"/doctemplates/orders",
112 $this->boxes = array(
113 0 => array(
'file' =>
'box_commandes.php',
'enabledbydefaulton' =>
'Home'),
114 2 => array(
'file' =>
'box_graph_orders_permonth.php',
'enabledbydefaulton' =>
'Home')
118 $this->rights = array();
119 $this->rights_class =
'commande';
124 $this->rights[$r][0] = 81;
125 $this->rights[$r][1] =
'Read sales orders';
126 $this->rights[$r][2] =
'r';
127 $this->rights[$r][3] = 0;
128 $this->rights[$r][4] =
'lire';
131 $this->rights[$r][0] = 82;
132 $this->rights[$r][1] =
'Creeat/modify sales orders';
133 $this->rights[$r][2] =
'w';
134 $this->rights[$r][3] = 0;
135 $this->rights[$r][4] =
'creer';
138 $this->rights[$r][0] = 84;
139 $this->rights[$r][1] =
'Validate sales orders';
140 $this->rights[$r][2] =
'd';
141 $this->rights[$r][3] = 0;
142 $this->rights[$r][4] =
'order_advance';
143 $this->rights[$r][5] =
'validate';
146 $this->rights[$r][0] = 85;
147 $this->rights[$r][1] =
'Generate the documents sales orders';
148 $this->rights[$r][2] =
'd';
149 $this->rights[$r][3] = 0;
150 $this->rights[$r][4] =
'order_advance';
151 $this->rights[$r][5] =
'generetedoc';
154 $this->rights[$r][0] = 86;
155 $this->rights[$r][1] =
'Send sales orders by email';
156 $this->rights[$r][2] =
'd';
157 $this->rights[$r][3] = 0;
158 $this->rights[$r][4] =
'order_advance';
159 $this->rights[$r][5] =
'send';
162 $this->rights[$r][0] = 87;
163 $this->rights[$r][1] =
'Close sale orders';
164 $this->rights[$r][2] =
'd';
165 $this->rights[$r][3] = 0;
166 $this->rights[$r][4] =
'order_advance';
167 $this->rights[$r][5] =
'close';
170 $this->rights[$r][0] = 88;
171 $this->rights[$r][1] =
'Cancel sale orders';
172 $this->rights[$r][2] =
'd';
173 $this->rights[$r][3] = 0;
174 $this->rights[$r][4] =
'order_advance';
175 $this->rights[$r][5] =
'annuler';
178 $this->rights[$r][0] = 89;
179 $this->rights[$r][1] =
'Delete sales orders';
180 $this->rights[$r][2] =
'd';
181 $this->rights[$r][3] = 0;
182 $this->rights[$r][4] =
'supprimer';
185 $this->rights[$r][0] = 1421;
186 $this->rights[$r][1] =
'Export sales orders and attributes';
187 $this->rights[$r][2] =
'r';
188 $this->rights[$r][3] = 0;
189 $this->rights[$r][4] =
'commande';
190 $this->rights[$r][5] =
'export';
203 $this->export_code[$r] = $this->rights_class.
'_'.$r;
204 $this->export_label[$r] =
'CustomersOrdersAndOrdersLines';
205 $this->export_permission[$r] = array(array(
"commande",
"commande",
"export"));
206 $this->export_fields_array[$r] = array(
207 's.rowid' =>
"IdCompany",
's.nom' =>
'CompanyName',
's.name_alias' =>
'AliasNameShort',
'ps.nom' =>
'ParentCompany',
's.code_client' =>
'CustomerCode',
's.address' =>
'Address',
's.zip' =>
'Zip',
's.town' =>
'Town',
'd.nom' =>
'State',
'co.label' =>
'Country',
208 'co.code' =>
"CountryCode",
's.phone' =>
'Phone',
's.siren' =>
'ProfId1',
's.siret' =>
'ProfId2',
's.ape' =>
'ProfId3',
's.idprof4' =>
'ProfId4',
'c.rowid' =>
"Id",
209 'c.ref' =>
"Ref",
'c.ref_client' =>
"RefCustomer",
'c.fk_soc' =>
"IdCompany",
'c.date_creation' =>
"DateCreation",
'c.date_commande' =>
"OrderDate",
210 'c.date_livraison' =>
"DateDeliveryPlanned",
'c.amount_ht' =>
"Amount",
'c.total_ht' =>
"TotalHT",
211 'c.total_ttc' =>
"TotalTTC",
'c.facture' =>
"Billed",
'c.fk_statut' =>
'Status',
'c.note_public' =>
"NotePublic",
'c.note_private' =>
"NotePrivate",
'sm.code' =>
'SendingMethod',
212 'c.fk_user_author' =>
'CreatedById',
'uc.login' =>
'CreatedByLogin',
'c.fk_user_valid' =>
'ValidatedById',
'uv.login' =>
'ValidatedByLogin',
213 'pj.ref' =>
'ProjectRef',
'cd.rowid' =>
'LineId',
'cd.description' =>
"LineDescription",
'cd.product_type' =>
'TypeOfLineServiceOrProduct',
214 'cd.tva_tx' =>
"LineVATRate",
'cd.qty' =>
"LineQty",
'cd.total_ht' =>
"LineTotalHT",
'cd.total_tva' =>
"LineTotalVAT",
'cd.total_ttc' =>
"LineTotalTTC",
215 'p.rowid' =>
'ProductId',
'p.ref' =>
'ProductRef',
'p.label' =>
'ProductLabel',
216 'cir.label'=>
'Source',
218 if (isModEnabled(
"multicurrency")) {
219 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
220 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
221 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
222 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
223 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
227 $nbofallowedentities = count(explode(
',',
getEntity(
'commande')));
228 if (isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
229 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
240 $this->export_TypeFields_array[$r] = array(
241 's.nom' =>
'Text',
'ps.nom' =>
'Text',
's.name_alias' =>
'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',
242 's.siren' =>
'Text',
's.siret' =>
'Text',
's.ape' =>
'Text',
's.idprof4' =>
'Text',
'c.ref' =>
"Text",
'c.ref_client' =>
"Text",
'c.date_creation' =>
"Date",
243 'c.date_commande' =>
"Date",
'c.date_livraison' =>
"Date",
'sm.code' =>
"Text",
'c.amount_ht' =>
"Numeric",
'c.total_ht' =>
"Numeric",
244 'c.total_ttc' =>
"Numeric",
'c.facture' =>
"Boolean",
'c.fk_statut' =>
'Status',
'c.note_public' =>
"Text",
'c.note_private' =>
"Text",
'pj.ref' =>
'Text',
245 'cd.description' =>
"Text",
'cd.product_type' =>
'Boolean',
'cd.tva_tx' =>
"Numeric",
'cd.qty' =>
"Numeric",
'cd.total_ht' =>
"Numeric",
'cd.total_tva' =>
"Numeric",
246 'cd.total_ttc' =>
"Numeric",
'p.rowid' =>
'List:product:ref::product',
'p.ref' =>
'Text',
'p.label' =>
'Text',
'd.nom' =>
'Text',
247 'c.entity' =>
'List:entity:label:rowid',
250 $this->export_entities_array[$r] = array(
251 's.rowid' =>
"company",
's.nom' =>
'company',
's.name_alias' =>
'company',
'ps.nom' =>
'company',
's.code_client' =>
'company',
's.address' =>
'company',
's.zip' =>
'company',
's.town' =>
'company',
'd.nom' =>
'company',
'co.label' =>
'company',
252 'co.code' =>
'company',
's.phone' =>
'company',
's.siren' =>
'company',
's.ape' =>
'company',
's.idprof4' =>
'company',
's.siret' =>
'company',
'c.rowid' =>
"order",
253 'c.ref' =>
"order",
'c.ref_client' =>
"order",
'c.fk_soc' =>
"order",
'c.date_creation' =>
"order",
'c.date_commande' =>
"order",
'c.amount_ht' =>
"order",
254 'c.total_ht' =>
"order",
'c.total_ttc' =>
"order",
'c.facture' =>
"order",
'c.fk_statut' =>
"order",
'c.note' =>
"order",
255 'c.date_livraison' =>
"order",
'sm.code' =>
"order",
'pj.ref' =>
'project',
'cd.rowid' =>
'order_line',
'cd.description' =>
"order_line",
256 'cd.product_type' =>
'order_line',
'cd.tva_tx' =>
"order_line",
'cd.qty' =>
"order_line",
'cd.total_ht' =>
"order_line",
'cd.total_tva' =>
"order_line",
257 'cd.total_ttc' =>
"order_line",
'p.rowid' =>
'product',
'p.ref' =>
'product',
'p.label' =>
'product'
259 $this->export_dependencies_array[$r] = array(
'order_line' =>
'cd.rowid',
'product' =>
'cd.rowid');
260 $keyforselect =
'commande';
261 $keyforelement =
'order';
262 $keyforaliasextra =
'extra';
263 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
264 $keyforselect =
'commandedet';
265 $keyforelement =
'order_line';
266 $keyforaliasextra =
'extra2';
267 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
268 $keyforselect =
'product';
269 $keyforelement =
'product';
270 $keyforaliasextra =
'extra3';
271 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
272 $keyforselect =
'societe';
273 $keyforelement =
'company';
274 $keyforaliasextra =
'extra4';
275 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
276 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
277 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
278 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
279 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe as ps ON ps.rowid = s.parent';
280 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
281 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
283 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
284 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
285 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'commande as c';
286 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_shipment_mode as sm ON c.fk_shipping_method = sm.rowid';
287 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
288 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
289 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
290 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
291 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commande_extrafields as extra ON c.rowid = extra.fk_object';
292 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'commandedet as cd';
293 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object';
294 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on cd.fk_product = p.rowid';
295 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
296 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande';
297 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'commande').
')';
298 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
299 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
308 $this->import_code[$r] =
'commande_'.$r;
309 $this->import_label[$r] =
'CustomersOrders';
310 $this->import_icon[$r] = $this->picto;
311 $this->import_entities_array[$r] = array();
312 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'commande',
'extra' => MAIN_DB_PREFIX.
'commande_extrafields');
313 $this->import_tables_creator_array[$r] = array(
'c' =>
'fk_user_author');
314 $import_sample = array(
'c.facture' =>
'0 or 1');
315 $this->import_fields_array[$r] = array(
317 'c.ref_client' =>
'RefCustomer',
318 'c.fk_soc' =>
'ThirdPartyName*',
319 'c.fk_projet' =>
'ProjectId',
320 'c.date_creation' =>
'DateCreation',
321 'c.date_valid' =>
'DateValidation',
322 'c.date_commande' =>
'OrderDate*',
323 'c.fk_user_modif' =>
'ModifiedById',
324 'c.fk_user_valid' =>
'ValidatedById',
325 'c.total_tva' =>
'TotalTVA',
326 'c.total_ht' =>
'TotalHT',
327 'c.total_ttc' =>
'TotalTTC',
328 'c.note_private' =>
'NotePrivate',
329 'c.note_public' =>
'Note',
330 'c.facture' =>
'Billed',
331 'c.date_livraison' =>
'DeliveryDate',
332 'c.fk_cond_reglement' =>
'Payment Condition',
333 'c.fk_mode_reglement' =>
'Payment Mode',
334 'c.model_pdf' =>
'Model',
335 'c.fk_statut' =>
'Status*'
338 if (isModEnabled(
"multicurrency")) {
339 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
340 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
341 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
342 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
343 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
345 $import_extrafield_sample = array();
346 $keyforselect =
'commande';
347 $keyforelement =
'order';
348 $keyforaliasextra =
'extra';
349 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
351 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commande');
352 $this->import_regex_array[$r] = array(
353 'c.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
355 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
356 $this->import_updatekeys_array[$r] = array(
'c.ref' =>
'Ref');
357 $this->import_convertvalue_array[$r] = array(
359 'rule' =>
'getrefifauto',
361 'path' =>
"/core/modules/commande/".
getDolGlobalString(
'COMMANDE_ADDON',
'mod_commande_marbre').
'.php',
362 'classobject' =>
'Commande',
363 'pathobject' =>
'/commande/class/commande.class.php',
366 'rule' =>
'fetchidfromref',
367 'file' =>
'/societe/class/societe.class.php',
368 'class' =>
'Societe',
370 'element' =>
'ThirdParty'
372 'c.fk_user_valid' => array(
373 'rule' =>
'fetchidfromref',
374 'file' =>
'/user/class/user.class.php',
379 'c.fk_mode_reglement' => array(
380 'rule' =>
'fetchidfromcodeorlabel',
381 'file' =>
'/compta/paiement/class/cpaiement.class.php',
382 'class' =>
'Cpaiement',
384 'element' =>
'cpayment'
390 $this->import_code[$r] =
'commande_lines_'.$r;
391 $this->import_label[$r] =
'SaleOrderLines';
392 $this->import_icon[$r] = $this->picto;
393 $this->import_entities_array[$r] = array();
394 $this->import_tables_array[$r] = array(
'cd' => MAIN_DB_PREFIX.
'commandedet',
'extra' => MAIN_DB_PREFIX.
'commandedet_extrafields');
395 $this->import_fields_array[$r] = array(
396 'cd.fk_commande' =>
'CustomerOrder*',
397 'cd.fk_parent_line' =>
'ParentLine',
398 'cd.fk_product' =>
'IdProduct',
399 'cd.description' =>
'LineDescription',
400 'cd.tva_tx' =>
'LineVATRate',
401 'cd.qty' =>
'LineQty',
402 'cd.remise_percent' =>
'Reduc. Percent',
403 'cd.price' =>
'Price',
404 'cd.subprice' =>
'Sub Price',
405 'cd.total_ht' =>
'LineTotalHT',
406 'cd.total_tva' =>
'LineTotalVAT',
407 'cd.total_ttc' =>
'LineTotalTTC',
408 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
409 'cd.date_start' =>
'Start Date',
410 'cd.date_end' =>
'End Date',
411 'cd.buy_price_ht' =>
'LineBuyPriceHT',
412 'cd.rang' =>
'LinePosition'
415 if (isModEnabled(
"multicurrency")) {
416 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
417 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
418 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
419 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
420 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
423 $import_extrafield_sample = array();
424 $keyforselect =
'commandedet';
425 $keyforelement =
'orderline';
426 $keyforaliasextra =
'extra';
427 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
429 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commandedet'];
430 $this->import_regex_array[$r] = [
431 'cd.product_type' =>
'[0|1]$',
432 'cd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
433 'cd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
435 $this->import_updatekeys_array[$r] = [
'cd.fk_commande' =>
'Sales Order Id',
'cd.fk_product' =>
'Product Id'];
436 $this->import_convertvalue_array[$r] = [
437 'cd.fk_commande' => [
438 'rule' =>
'fetchidfromref',
439 'file' =>
'/commande/class/commande.class.php',
440 'class' =>
'Commande',
442 'element' =>
'commande'