51 global $conf, $user, $hookmanager;
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',
'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",
106 $this->boxes = array(
107 0 => array(
'file' =>
'box_commandes.php',
'enabledbydefaulton' =>
'Home'),
108 2 => array(
'file' =>
'box_graph_orders_permonth.php',
'enabledbydefaulton' =>
'Home')
112 $this->rights = array();
113 $this->rights_class =
'commande';
118 $this->rights[$r][0] = 81;
119 $this->rights[$r][1] =
'Read sales orders';
120 $this->rights[$r][2] =
'r';
121 $this->rights[$r][3] = 0;
122 $this->rights[$r][4] =
'lire';
125 $this->rights[$r][0] = 82;
126 $this->rights[$r][1] =
'Creeat/modify sales orders';
127 $this->rights[$r][2] =
'w';
128 $this->rights[$r][3] = 0;
129 $this->rights[$r][4] =
'creer';
132 $this->rights[$r][0] = 84;
133 $this->rights[$r][1] =
'Validate sales orders';
134 $this->rights[$r][2] =
'd';
135 $this->rights[$r][3] = 0;
136 $this->rights[$r][4] =
'order_advance';
137 $this->rights[$r][5] =
'validate';
140 $this->rights[$r][0] = 85;
141 $this->rights[$r][1] =
'Generate the documents sales orders';
142 $this->rights[$r][2] =
'd';
143 $this->rights[$r][3] = 0;
144 $this->rights[$r][4] =
'order_advance';
145 $this->rights[$r][5] =
'generetedoc';
148 $this->rights[$r][0] = 86;
149 $this->rights[$r][1] =
'Send sales orders by email';
150 $this->rights[$r][2] =
'd';
151 $this->rights[$r][3] = 0;
152 $this->rights[$r][4] =
'order_advance';
153 $this->rights[$r][5] =
'send';
156 $this->rights[$r][0] = 87;
157 $this->rights[$r][1] =
'Close sale orders';
158 $this->rights[$r][2] =
'd';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] =
'order_advance';
161 $this->rights[$r][5] =
'close';
164 $this->rights[$r][0] = 88;
165 $this->rights[$r][1] =
'Cancel sale orders';
166 $this->rights[$r][2] =
'd';
167 $this->rights[$r][3] = 0;
168 $this->rights[$r][4] =
'order_advance';
169 $this->rights[$r][5] =
'annuler';
172 $this->rights[$r][0] = 89;
173 $this->rights[$r][1] =
'Delete sales orders';
174 $this->rights[$r][2] =
'd';
175 $this->rights[$r][3] = 0;
176 $this->rights[$r][4] =
'supprimer';
179 $this->rights[$r][0] = 1421;
180 $this->rights[$r][1] =
'Export sales orders and attributes';
181 $this->rights[$r][2] =
'r';
182 $this->rights[$r][3] = 0;
183 $this->rights[$r][4] =
'commande';
184 $this->rights[$r][5] =
'export';
197 $this->export_code[$r] = $this->rights_class.
'_'.$r;
198 $this->export_label[$r] =
'CustomersOrdersAndOrdersLines';
199 $this->export_permission[$r] = array(array(
"commande",
"commande",
"export"));
200 $this->export_fields_array[$r] = array(
201 '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',
202 'co.code' =>
"CountryCode",
's.phone' =>
'Phone',
's.siren' =>
'ProfId1',
's.siret' =>
'ProfId2',
's.ape' =>
'ProfId3',
's.idprof4' =>
'ProfId4',
'c.rowid' =>
"Id",
203 'c.ref' =>
"Ref",
'c.ref_client' =>
"RefCustomer",
'c.fk_soc' =>
"IdCompany",
'c.date_creation' =>
"DateCreation",
'c.date_commande' =>
"OrderDate",
204 'c.date_livraison' =>
"DateDeliveryPlanned",
'c.amount_ht' =>
"Amount",
'c.total_ht' =>
"TotalHT",
205 'c.total_ttc' =>
"TotalTTC",
'c.facture' =>
"Billed",
'c.fk_statut' =>
'Status',
'c.note_public' =>
"NotePublic",
'c.note_private' =>
"NotePrivate",
'sm.code' =>
'SendingMethod',
206 'c.fk_user_author' =>
'CreatedById',
'uc.login' =>
'CreatedByLogin',
'c.fk_user_valid' =>
'ValidatedById',
'uv.login' =>
'ValidatedByLogin',
207 'pj.ref' =>
'ProjectRef',
'cd.rowid' =>
'LineId',
'cd.description' =>
"LineDescription",
'cd.product_type' =>
'TypeOfLineServiceOrProduct',
208 'cd.tva_tx' =>
"LineVATRate",
'cd.qty' =>
"LineQty",
'cd.total_ht' =>
"LineTotalHT",
'cd.total_tva' =>
"LineTotalVAT",
'cd.total_ttc' =>
"LineTotalTTC",
209 'p.rowid' =>
'ProductId',
'p.ref' =>
'ProductRef',
'p.label' =>
'ProductLabel',
210 'cir.label'=>
'Source',
213 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
214 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
215 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
216 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
217 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
221 $nbofallowedentities = count(explode(
',',
getEntity(
'commande')));
222 if (
isModEnabled(
'multicompany') && $nbofallowedentities > 1) {
223 $this->export_fields_array[$r][
'c.entity'] =
'Entity';
234 $this->export_TypeFields_array[$r] = array(
235 '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',
236 's.siren' =>
'Text',
's.siret' =>
'Text',
's.ape' =>
'Text',
's.idprof4' =>
'Text',
'c.ref' =>
"Text",
'c.ref_client' =>
"Text",
'c.date_creation' =>
"Date",
237 'c.date_commande' =>
"Date",
'c.date_livraison' =>
"Date",
'sm.code' =>
"Text",
'c.amount_ht' =>
"Numeric",
'c.total_ht' =>
"Numeric",
238 'c.total_ttc' =>
"Numeric",
'c.facture' =>
"Boolean",
'c.fk_statut' =>
'Status',
'c.note_public' =>
"Text",
'c.note_private' =>
"Text",
'pj.ref' =>
'Text',
239 'cd.description' =>
"Text",
'cd.product_type' =>
'Boolean',
'cd.tva_tx' =>
"Numeric",
'cd.qty' =>
"Numeric",
'cd.total_ht' =>
"Numeric",
'cd.total_tva' =>
"Numeric",
240 'cd.total_ttc' =>
"Numeric",
'p.rowid' =>
'List:product:ref::product',
'p.ref' =>
'Text',
'p.label' =>
'Text',
'd.nom' =>
'Text',
241 'c.entity' =>
'List:entity:label:rowid',
244 $this->export_entities_array[$r] = array(
245 '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',
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'
253 $this->export_dependencies_array[$r] = array(
'order_line' =>
'cd.rowid',
'product' =>
'cd.rowid');
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';
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.
'c_input_reason as cir ON cir.rowid = c.fk_input_reason';
282 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
283 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
284 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
285 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commande_extrafields as extra ON c.rowid = extra.fk_object';
286 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'commandedet as cd';
287 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object';
288 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on cd.fk_product = p.rowid';
289 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
290 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande';
291 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'commande').
')';
292 if (!empty($user) && !$user->hasRight(
'societe',
'client',
'voir')) {
293 $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
295 $parameters = array();
296 $hookmanager->executeHooks(
'printExportWhere', $parameters, $this);
297 $this->export_sql_end[$r] .= $hookmanager->resPrint;
305 $this->import_code[$r] =
'commande_'.$r;
306 $this->import_label[$r] =
'CustomersOrders';
307 $this->import_icon[$r] = $this->picto;
308 $this->import_entities_array[$r] = array();
309 $this->import_tables_array[$r] = array(
'c' => MAIN_DB_PREFIX.
'commande',
'extra' => MAIN_DB_PREFIX.
'commande_extrafields');
310 $this->import_tables_creator_array[$r] = array(
'c' =>
'fk_user_author');
311 $import_sample = array(
'c.facture' =>
'0 or 1');
312 $this->import_fields_array[$r] = array(
314 'c.ref_client' =>
'RefCustomer',
315 'c.fk_soc' =>
'ThirdPartyName*',
316 'c.fk_projet' =>
'ProjectId',
317 'c.date_creation' =>
'DateCreation',
318 'c.date_valid' =>
'DateValidation',
319 'c.date_commande' =>
'OrderDate*',
320 'c.fk_user_modif' =>
'ModifiedById',
321 'c.fk_user_valid' =>
'ValidatedById',
322 'c.total_tva' =>
'TotalTVA',
323 'c.total_ht' =>
'TotalHT',
324 'c.total_ttc' =>
'TotalTTC',
325 'c.note_private' =>
'NotePrivate',
326 'c.note_public' =>
'Note',
327 'c.facture' =>
'Billed',
328 'c.date_livraison' =>
'DeliveryDate',
329 'c.fk_cond_reglement' =>
'Payment Condition',
330 'c.fk_mode_reglement' =>
'Payment Mode',
331 'c.model_pdf' =>
'Model',
332 'c.fk_statut' =>
'Status*'
336 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
337 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
338 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
339 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
340 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
342 $import_extrafield_sample = array();
343 $keyforselect =
'commande';
344 $keyforelement =
'order';
345 $keyforaliasextra =
'extra';
346 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
348 $this->import_fieldshidden_array[$r] = array(
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commande');
349 $this->import_regex_array[$r] = array(
350 'c.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
352 $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
353 $this->import_updatekeys_array[$r] = array(
'c.ref' =>
'Ref');
354 $this->import_convertvalue_array[$r] = array(
356 'rule' =>
'getrefifauto',
358 'path' =>
"/core/modules/commande/".
getDolGlobalString(
'COMMANDE_ADDON',
'mod_commande_marbre').
'.php',
359 'classobject' =>
'Commande',
360 'pathobject' =>
'/commande/class/commande.class.php',
363 'rule' =>
'fetchidfromref',
364 'file' =>
'/societe/class/societe.class.php',
365 'class' =>
'Societe',
367 'element' =>
'ThirdParty'
369 'c.fk_user_valid' => array(
370 'rule' =>
'fetchidfromref',
371 'file' =>
'/user/class/user.class.php',
376 'c.fk_mode_reglement' => array(
377 'rule' =>
'fetchidfromcodeorlabel',
378 'file' =>
'/compta/paiement/class/cpaiement.class.php',
379 'class' =>
'Cpaiement',
381 'element' =>
'cpayment'
387 $this->import_code[$r] =
'commande_lines_'.$r;
388 $this->import_label[$r] =
'SaleOrderLines';
389 $this->import_icon[$r] = $this->picto;
390 $this->import_entities_array[$r] = array();
391 $this->import_tables_array[$r] = array(
'cd' => MAIN_DB_PREFIX.
'commandedet',
'extra' => MAIN_DB_PREFIX.
'commandedet_extrafields');
392 $this->import_fields_array[$r] = array(
393 'cd.fk_commande' =>
'CustomerOrder*',
394 'cd.fk_parent_line' =>
'ParentLine',
395 'cd.fk_product' =>
'IdProduct',
396 'cd.description' =>
'LineDescription',
397 'cd.tva_tx' =>
'LineVATRate',
398 'cd.qty' =>
'LineQty',
399 'cd.remise_percent' =>
'Reduc. Percent',
400 'cd.price' =>
'Price',
401 'cd.subprice' =>
'Sub Price',
402 'cd.total_ht' =>
'LineTotalHT',
403 'cd.total_tva' =>
'LineTotalVAT',
404 'cd.total_ttc' =>
'LineTotalTTC',
405 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
406 'cd.date_start' =>
'Start Date',
407 'cd.date_end' =>
'End Date',
408 'cd.buy_price_ht' =>
'LineBuyPriceHT',
409 'cd.rang' =>
'LinePosition'
413 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
414 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
415 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
416 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
417 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
420 $import_extrafield_sample = array();
421 $keyforselect =
'commandedet';
422 $keyforelement =
'orderline';
423 $keyforaliasextra =
'extra';
424 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinimport.inc.php';
426 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commandedet'];
427 $this->import_regex_array[$r] = [
428 'cd.product_type' =>
'[0|1]$',
429 'cd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
430 'cd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
432 $this->import_updatekeys_array[$r] = [
'cd.fk_commande' =>
'Sales Order Id',
'cd.fk_product' =>
'Product Id'];
433 $this->import_convertvalue_array[$r] = [
434 'cd.fk_commande' => [
435 'rule' =>
'fetchidfromref',
436 'file' =>
'/commande/class/commande.class.php',
437 'class' =>
'Commande',
439 'element' =>
'commande'