33 include_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
54 $this->family =
"crm";
55 $this->module_position =
'11';
57 $this->
name = preg_replace(
'/^mod/i',
'', get_class($this));
58 $this->
description =
"Gestion des commandes clients";
60 $this->version =
'dolibarr';
62 $this->const_name =
'MAIN_MODULE_'.strtoupper($this->
name);
63 $this->picto =
'order';
66 $this->dirs = array(
"/commande/temp");
69 $this->config_page_url = array(
"commande.php");
72 $this->depends = array(
"modSociete");
73 $this->requiredby = array(
"modExpedition");
74 $this->conflictwith = array();
75 $this->langfiles = array(
'orders',
'bills',
'companies',
'products',
'deliveries',
'sendings');
78 $this->
const = array();
81 $this->
const[$r][0] =
"COMMANDE_ADDON_PDF";
82 $this->
const[$r][1] =
"chaine";
83 $this->
const[$r][2] =
"einstein";
84 $this->
const[$r][3] =
'Name of PDF model of order';
85 $this->
const[$r][4] = 0;
88 $this->
const[$r][0] =
"COMMANDE_ADDON";
89 $this->
const[$r][1] =
"chaine";
90 $this->
const[$r][2] =
"mod_commande_marbre";
91 $this->
const[$r][3] =
'Name of numbering numerotation rules of order';
92 $this->
const[$r][4] = 0;
95 $this->
const[$r][0] =
"COMMANDE_ADDON_PDF_ODT_PATH";
96 $this->
const[$r][1] =
"chaine";
97 $this->
const[$r][2] =
"DOL_DATA_ROOT/doctemplates/orders";
98 $this->
const[$r][3] =
"";
99 $this->
const[$r][4] = 0;
109 $this->boxes = array(
110 0=>array(
'file'=>
'box_commandes.php',
'enabledbydefaulton'=>
'Home'),
111 2=>array(
'file'=>
'box_graph_orders_permonth.php',
'enabledbydefaulton'=>
'Home')
115 $this->rights = array();
116 $this->rights_class =
'commande';
121 $this->rights[$r][0] = 81;
122 $this->rights[$r][1] =
'Read sales orders';
123 $this->rights[$r][2] =
'r';
124 $this->rights[$r][3] = 0;
125 $this->rights[$r][4] =
'lire';
128 $this->rights[$r][0] = 82;
129 $this->rights[$r][1] =
'Creeat/modify sales orders';
130 $this->rights[$r][2] =
'w';
131 $this->rights[$r][3] = 0;
132 $this->rights[$r][4] =
'creer';
135 $this->rights[$r][0] = 84;
136 $this->rights[$r][1] =
'Validate sales orders';
137 $this->rights[$r][2] =
'd';
138 $this->rights[$r][3] = 0;
139 $this->rights[$r][4] =
'order_advance';
140 $this->rights[$r][5] =
'validate';
143 $this->rights[$r][0] = 86;
144 $this->rights[$r][1] =
'Send sale orders by email';
145 $this->rights[$r][2] =
'd';
146 $this->rights[$r][3] = 0;
147 $this->rights[$r][4] =
'order_advance';
148 $this->rights[$r][5] =
'send';
151 $this->rights[$r][0] = 87;
152 $this->rights[$r][1] =
'Close sale orders';
153 $this->rights[$r][2] =
'd';
154 $this->rights[$r][3] = 0;
155 $this->rights[$r][4] =
'order_advance';
156 $this->rights[$r][5] =
'close';
159 $this->rights[$r][0] = 88;
160 $this->rights[$r][1] =
'Cancel sale orders';
161 $this->rights[$r][2] =
'd';
162 $this->rights[$r][3] = 0;
163 $this->rights[$r][4] =
'order_advance';
164 $this->rights[$r][5] =
'annuler';
167 $this->rights[$r][0] = 89;
168 $this->rights[$r][1] =
'Delete sales orders';
169 $this->rights[$r][2] =
'd';
170 $this->rights[$r][3] = 0;
171 $this->rights[$r][4] =
'supprimer';
174 $this->rights[$r][0] = 1421;
175 $this->rights[$r][1] =
'Export sales orders and attributes';
176 $this->rights[$r][2] =
'r';
177 $this->rights[$r][3] = 0;
178 $this->rights[$r][4] =
'commande';
179 $this->rights[$r][5] =
'export';
192 $this->export_code[$r] = $this->rights_class.
'_'.$r;
193 $this->export_label[$r] =
'CustomersOrdersAndOrdersLines';
194 $this->export_permission[$r] = array(array(
"commande",
"commande",
"export"));
195 $this->export_fields_array[$r] = array(
196 's.rowid'=>
"IdCompany",
's.nom'=>
'CompanyName',
's.address'=>
'Address',
's.zip'=>
'Zip',
's.town'=>
'Town',
'd.nom'=>
'State',
'co.label'=>
'Country',
197 'co.code'=>
"CountryCode",
's.phone'=>
'Phone',
's.siren'=>
'ProfId1',
's.siret'=>
'ProfId2',
's.ape'=>
'ProfId3',
's.idprof4'=>
'ProfId4',
'c.rowid'=>
"Id",
198 'c.ref'=>
"Ref",
'c.ref_client'=>
"RefCustomer",
'c.fk_soc'=>
"IdCompany",
'c.date_creation'=>
"DateCreation",
'c.date_commande'=>
"OrderDate",
199 'c.date_livraison'=>
"DateDeliveryPlanned",
'c.amount_ht'=>
"Amount",
'c.remise_percent'=>
"GlobalDiscount",
'c.total_ht'=>
"TotalHT",
200 'c.total_ttc'=>
"TotalTTC",
'c.facture'=>
"Billed",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Note",
'c.date_livraison'=>
'DeliveryDate',
201 'c.fk_user_author'=>
'CreatedById',
'uc.login'=>
'CreatedByLogin',
'c.fk_user_valid'=>
'ValidatedById',
'uv.login'=>
'ValidatedByLogin',
202 'pj.ref'=>
'ProjectRef',
'cd.rowid'=>
'LineId',
'cd.label'=>
"Label",
'cd.description'=>
"LineDescription",
'cd.product_type'=>
'TypeOfLineServiceOrProduct',
203 'cd.tva_tx'=>
"LineVATRate",
'cd.qty'=>
"LineQty",
'cd.total_ht'=>
"LineTotalHT",
'cd.total_tva'=>
"LineTotalVAT",
'cd.total_ttc'=>
"LineTotalTTC",
204 'p.rowid'=>
'ProductId',
'p.ref'=>
'ProductRef',
'p.label'=>
'ProductLabel'
206 if (!empty($conf->multicurrency->enabled))
208 $this->export_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
209 $this->export_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
210 $this->export_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
211 $this->export_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
212 $this->export_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
222 $this->export_TypeFields_array[$r] = array(
223 's.nom'=>
'Text',
's.address'=>
'Text',
's.zip'=>
'Text',
's.town'=>
'Text',
'co.label'=>
'List:c_country:label:label',
'co.code'=>
'Text',
's.phone'=>
'Text',
224 's.siren'=>
'Text',
's.siret'=>
'Text',
's.ape'=>
'Text',
's.idprof4'=>
'Text',
'c.ref'=>
"Text",
'c.ref_client'=>
"Text",
'c.date_creation'=>
"Date",
225 'c.date_commande'=>
"Date",
'c.date_livraison'=>
"Date",
'c.amount_ht'=>
"Numeric",
'c.remise_percent'=>
"Numeric",
'c.total_ht'=>
"Numeric",
226 'c.total_ttc'=>
"Numeric",
'c.facture'=>
"Boolean",
'c.fk_statut'=>
'Status',
'c.note_public'=>
"Text",
'c.date_livraison'=>
'Date',
'pj.ref'=>
'Text',
227 'cd.description'=>
"Text",
'cd.product_type'=>
'Boolean',
'cd.tva_tx'=>
"Numeric",
'cd.qty'=>
"Numeric",
'cd.total_ht'=>
"Numeric",
'cd.total_tva'=>
"Numeric",
228 'cd.total_ttc'=>
"Numeric",
'p.rowid'=>
'List:product:ref::product',
'p.ref'=>
'Text',
'p.label'=>
'Text',
'd.nom'=>
'Text'
230 $this->export_entities_array[$r] = array(
231 's.rowid'=>
"company",
's.nom'=>
'company',
's.address'=>
'company',
's.zip'=>
'company',
's.town'=>
'company',
'd.nom'=>
'company',
'co.label'=>
'company',
232 'co.code'=>
'company',
's.phone'=>
'company',
's.siren'=>
'company',
's.ape'=>
'company',
's.idprof4'=>
'company',
's.siret'=>
'company',
'c.rowid'=>
"order",
233 'c.ref'=>
"order",
'c.ref_client'=>
"order",
'c.fk_soc'=>
"order",
'c.date_creation'=>
"order",
'c.date_commande'=>
"order",
'c.amount_ht'=>
"order",
234 'c.remise_percent'=>
"order",
'c.total_ht'=>
"order",
'c.total_ttc'=>
"order",
'c.facture'=>
"order",
'c.fk_statut'=>
"order",
'c.note'=>
"order",
235 'c.date_livraison'=>
"order",
'pj.ref'=>
'project',
'cd.rowid'=>
'order_line',
'cd.label'=>
"order_line",
'cd.description'=>
"order_line",
236 'cd.product_type'=>
'order_line',
'cd.tva_tx'=>
"order_line",
'cd.qty'=>
"order_line",
'cd.total_ht'=>
"order_line",
'cd.total_tva'=>
"order_line",
237 'cd.total_ttc'=>
"order_line",
'p.rowid'=>
'product',
'p.ref'=>
'product',
'p.label'=>
'product'
239 $this->export_dependencies_array[$r] = array(
'order_line'=>
'cd.rowid',
'product'=>
'cd.rowid');
240 $keyforselect =
'commande'; $keyforelement =
'order'; $keyforaliasextra =
'extra';
241 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
242 $keyforselect =
'commandedet'; $keyforelement =
'order_line'; $keyforaliasextra =
'extra2';
243 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
244 $keyforselect =
'product'; $keyforelement =
'product'; $keyforaliasextra =
'extra3';
245 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
246 $keyforselect =
'societe'; $keyforelement =
'company'; $keyforaliasextra =
'extra4';
247 include DOL_DOCUMENT_ROOT.
'/core/extrafieldsinexport.inc.php';
248 $this->export_sql_start[$r] =
'SELECT DISTINCT ';
249 $this->export_sql_end[$r] =
' FROM '.MAIN_DB_PREFIX.
'societe as s';
250 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';
251 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
252 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_departements as d ON s.fk_departement = d.rowid';
253 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON s.fk_pays = co.rowid,';
254 $this->export_sql_end[$r] .=
' '.MAIN_DB_PREFIX.
'commande as c';
255 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pj ON c.fk_projet = pj.rowid';
256 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uc ON c.fk_user_author = uc.rowid';
257 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'user as uv ON c.fk_user_valid = uv.rowid';
258 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commande_extrafields as extra ON c.rowid = extra.fk_object';
259 $this->export_sql_end[$r] .=
' , '.MAIN_DB_PREFIX.
'commandedet as cd';
260 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object';
261 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p on cd.fk_product = p.rowid';
262 $this->export_sql_end[$r] .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_extrafields as extra3 on p.rowid = extra3.fk_object';
263 $this->export_sql_end[$r] .=
' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande';
264 $this->export_sql_end[$r] .=
' AND c.entity IN ('.getEntity(
'commande').
')';
265 if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=
' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
273 $this->import_code[$r] =
'commande_'.$r;
274 $this->import_label[$r] =
'CustomersOrders';
275 $this->import_icon[$r] = $this->picto;
276 $this->import_entities_array[$r] = [];
277 $this->import_tables_array[$r] = [
'c' => MAIN_DB_PREFIX.
'commande',
'extra' => MAIN_DB_PREFIX.
'commande_extrafields'];
278 $this->import_tables_creator_array[$r] = [
'c' =>
'fk_user_author'];
279 $this->import_fields_array[$r] = [
280 'c.ref' =>
'Document Ref*',
281 'c.ref_client' =>
'RefCustomer',
282 'c.fk_soc' =>
'ThirdPartyName*',
283 'c.fk_projet' =>
'ProjectId',
284 'c.date_creation' =>
'DateCreation',
285 'c.date_valid' =>
'DateValid',
286 'c.date_commande' =>
'DateOrder',
287 'c.fk_user_modif' =>
'ModifiedById',
288 'c.fk_user_valid' =>
'ValidatedById',
289 'c.fk_statut' =>
'Status*',
290 'c.remise_percent' =>
'GlobalDiscount',
291 'c.tva' =>
'TotalTVA',
292 'c.total_ht' =>
'TotalHT',
293 'c.total_ttc' =>
'TotalTTC',
294 'c.note_private' =>
'NotePrivate',
295 'c.note_public' =>
'Note',
296 'c.facture' =>
'Invoice(1/0)',
297 'c.date_livraison' =>
'DeliveryDate',
298 'c.fk_cond_reglement' =>
'Payment Condition',
299 'c.fk_mode_reglement' =>
'Payment Mode',
300 'c.model_pdf' =>
'Model'
303 if (!empty($conf->multicurrency->enabled)) {
304 $this->import_fields_array[$r][
'c.multicurrency_code'] =
'Currency';
305 $this->import_fields_array[$r][
'c.multicurrency_tx'] =
'CurrencyRate';
306 $this->import_fields_array[$r][
'c.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
307 $this->import_fields_array[$r][
'c.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
308 $this->import_fields_array[$r][
'c.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
312 $import_extrafield_sample = [];
313 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'commande' AND entity IN (0, ".$conf->entity.
")";
317 while ($obj = $this->
db->fetch_object(
$resql)) {
318 $fieldname =
'extra.'.$obj->name;
319 $fieldlabel = ucfirst($obj->label);
320 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
321 $import_extrafield_sample[$fieldname] = $fieldlabel;
326 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commande'];
327 $this->import_regex_array[$r] = [
328 'c.ref' =>
'(CPV\d{4}-\d{4}|CO\d{4}-\d{4}|PROV.{1,32}$)',
329 'c.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
332 $this->import_updatekeys_array[$r] = [
'c.ref' =>
'Ref'];
333 $this->import_convertvalue_array[$r] = [
335 'rule' =>
'fetchidfromref',
336 'file' =>
'/societe/class/societe.class.php',
337 'class' =>
'Societe',
339 'element' =>
'ThirdParty'
341 'c.fk_user_valid' => [
342 'rule' =>
'fetchidfromref',
343 'file' =>
'/user/class/user.class.php',
348 'c.fk_mode_reglement' => [
349 'rule' =>
'fetchidfromcodeorlabel',
350 'file' =>
'/compta/paiement/class/cpaiement.class.php',
351 'class' =>
'Cpaiement',
353 'element' =>
'cpayment'
359 $this->import_code[$r] =
'commande_lines_'.$r;
360 $this->import_label[$r] =
'OrderLine';
361 $this->import_icon[$r] = $this->picto;
362 $this->import_entities_array[$r] = [];
363 $this->import_tables_array[$r] = [
'cd' => MAIN_DB_PREFIX.
'commandedet',
'extra' => MAIN_DB_PREFIX.
'commandedet_extrafields'];
364 $this->import_fields_array[$r] = [
365 'cd.fk_commande' =>
'Document Ref*',
366 'cd.fk_parent_line' =>
'PrParentLine',
367 'cd.fk_product' =>
'IdProduct',
368 'cd.label' =>
'Label',
369 'cd.description' =>
'LineDescription',
370 'cd.tva_tx' =>
'LineVATRate',
371 'cd.qty' =>
'LineQty',
372 'cd.remise_percent' =>
'Reduc. Percent',
373 'cd.remise' =>
'Reduc.',
374 'cd.price' =>
'Price',
375 'cd.subprice' =>
'Sub Price',
376 'cd.total_ht' =>
'LineTotalHT',
377 'cd.total_tva' =>
'LineTotalVAT',
378 'cd.total_ttc' =>
'LineTotalTTC',
379 'cd.product_type' =>
'TypeOfLineServiceOrProduct',
380 'cd.date_start' =>
'Start Date',
381 'cd.date_end' =>
'End Date',
382 'cd.buy_price_ht' =>
'LineBuyPriceHT',
383 'cd.rang' =>
'LinePosition'
386 if (!empty($conf->multicurrency->enabled)) {
387 $this->import_fields_array[$r][
'cd.multicurrency_code'] =
'Currency';
388 $this->import_fields_array[$r][
'cd.multicurrency_subprice'] =
'CurrencyRate';
389 $this->import_fields_array[$r][
'cd.multicurrency_total_ht'] =
'MulticurrencyAmountHT';
390 $this->import_fields_array[$r][
'cd.multicurrency_total_tva'] =
'MulticurrencyAmountVAT';
391 $this->import_fields_array[$r][
'cd.multicurrency_total_ttc'] =
'MulticurrencyAmountTTC';
395 $sql =
"SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX.
"extrafields WHERE elementtype = 'commandedet' AND entity IN (0, ".$conf->entity.
")";
398 while ($obj = $this->
db->fetch_object(
$resql)) {
399 $fieldname =
'extra.'.$obj->name;
400 $fieldlabel = ucfirst($obj->label);
401 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ?
'*' :
'');
406 $this->import_fieldshidden_array[$r] = [
'extra.fk_object' =>
'lastrowid-'.MAIN_DB_PREFIX.
'commandedet'];
407 $this->import_regex_array[$r] = [
408 'cd.product_type' =>
'[0|1]$',
409 'cd.fk_product' =>
'rowid@'.MAIN_DB_PREFIX.
'product',
410 'cd.multicurrency_code' =>
'code@'.MAIN_DB_PREFIX.
'multicurrency'
412 $this->import_updatekeys_array[$r] = [
'cd.fk_commande' =>
'Sales Order Id',
'cd.fk_product' =>
'Product Id'];
413 $this->import_convertvalue_array[$r] = [
414 'cd.fk_commande' => [
415 'rule' =>
'fetchidfromref',
416 'file' =>
'/commande/class/commande.class.php',
417 'class' =>
'Commande',
419 'element' =>
'commande'
433 public function init($options =
'')
435 global $conf, $langs;
438 $this->
remove($options);
441 $src = DOL_DOCUMENT_ROOT.
'/install/doctemplates/orders/template_order.odt';
442 $dirodt = DOL_DATA_ROOT.
'/doctemplates/orders';
443 $dest = $dirodt.
'/template_order.odt';
445 if (file_exists($src) && !file_exists($dest))
447 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
449 $result =
dol_copy($src, $dest, 0, 0);
452 $langs->load(
"errors");
453 $this->error = $langs->trans(
'ErrorFailToCopyFile', $src, $dest);
459 "DELETE FROM ".MAIN_DB_PREFIX.
"document_model WHERE nom = '".$this->db->escape($this->const[0][2]).
"' AND type = 'order' AND entity = ".$conf->entity,
460 "INSERT INTO ".MAIN_DB_PREFIX.
"document_model (nom, type, entity) VALUES('".$this->
db->escape($this->
const[0][2]).
"','order',".$conf->entity.
")"
463 return $this->
_init($sql, $options);
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
</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.
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
init($options= '')
Function called when module is enabled.
_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.
Class to describe module customer orders.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)