dolibarr  9.0.0
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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
32 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
33 
34 
39 {
40 
46  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 = '30';
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] = "einstein";
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] = 'Lire les commandes clients';
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] = 'Creer/modifier les commandes clients';
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] = 'Valider les commandes clients';
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] = 86;
143  $this->rights[$r][1] = 'Envoyer les commandes clients';
144  $this->rights[$r][2] = 'd';
145  $this->rights[$r][3] = 0;
146  $this->rights[$r][4] = 'order_advance';
147  $this->rights[$r][5] = 'send';
148 
149  $r++;
150  $this->rights[$r][0] = 87;
151  $this->rights[$r][1] = 'Cloturer les commandes clients';
152  $this->rights[$r][2] = 'd';
153  $this->rights[$r][3] = 0;
154  $this->rights[$r][4] = 'cloturer';
155 
156  $r++;
157  $this->rights[$r][0] = 88;
158  $this->rights[$r][1] = 'Annuler les commandes clients';
159  $this->rights[$r][2] = 'd';
160  $this->rights[$r][3] = 0;
161  $this->rights[$r][4] = 'order_advance';
162  $this->rights[$r][5] = 'annuler';
163 
164  $r++;
165  $this->rights[$r][0] = 89;
166  $this->rights[$r][1] = 'Supprimer les commandes clients';
167  $this->rights[$r][2] = 'd';
168  $this->rights[$r][3] = 0;
169  $this->rights[$r][4] = 'supprimer';
170 
171  $r++;
172  $this->rights[$r][0] = 1421;
173  $this->rights[$r][1] = 'Exporter les commandes clients et attributs';
174  $this->rights[$r][2] = 'r';
175  $this->rights[$r][3] = 0;
176  $this->rights[$r][4] = 'commande';
177  $this->rights[$r][5] = 'export';
178 
179 
180  // Menus
181  //-------
182  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
183 
184 
185  // Exports
186  //--------
187  $r=0;
188 
189  $r++;
190  $this->export_code[$r]=$this->rights_class.'_'.$r;
191  $this->export_label[$r]='CustomersOrdersAndOrdersLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
192  $this->export_permission[$r]=array(array("commande","commande","export"));
193  $this->export_fields_array[$r]=array(
194  's.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','d.nom'=>'State','co.label'=>'Country',
195  'co.code'=>"CountryCode",'s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",
196  'c.ref'=>"Ref",'c.ref_client'=>"RefCustomer",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"OrderDate",
197  'c.date_livraison'=>"DateDeliveryPlanned",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",
198  'c.total_ttc'=>"TotalTTC",'c.facture'=>"Billed",'c.fk_statut'=>'Status','c.note_public'=>"Note",'c.date_livraison'=>'DeliveryDate',
199  'c.fk_user_author'=>'CreatedById','uc.login'=>'CreatedByLogin','c.fk_user_valid'=>'ValidatedById','uv.login'=>'ValidatedByLogin',
200  'pj.ref'=>'ProjectRef','cd.rowid'=>'LineId','cd.label'=>"Label",'cd.description'=>"LineDescription",'cd.product_type'=>'TypeOfLineServiceOrProduct',
201  'cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty",'cd.total_ht'=>"LineTotalHT",'cd.total_tva'=>"LineTotalVAT",'cd.total_ttc'=>"LineTotalTTC",
202  'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel'
203  );
204  if (! empty($conf->multicurrency->enabled))
205  {
206  $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
207  $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
208  $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
209  $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
210  $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
211  }
212  //$this->export_TypeFields_array[$r]=array(
213  // 's.rowid'=>"List:societe:nom",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label',
214  // '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",
215  // 'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",
216  // 'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','cd.description'=>"Text",
217  // 'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",
218  // 'p.rowid'=>'List:product:ref','p.ref'=>'Text','p.label'=>'Text'
219  //);
220  $this->export_TypeFields_array[$r]=array(
221  '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',
222  's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.date_creation'=>"Date",
223  'c.date_commande'=>"Date",'c.date_livraison'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",
224  'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','pj.ref'=>'Text',
225  'cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",'cd.total_tva'=>"Numeric",
226  'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:ref','p.ref'=>'Text','p.label'=>'Text','d.nom'=>'Text'
227  );
228  $this->export_entities_array[$r]=array(
229  's.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','d.nom'=>'company','co.label'=>'company',
230  'co.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",
231  'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",
232  'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>"order",'c.note'=>"order",
233  'c.date_livraison'=>"order",'pj.ref'=>'project','cd.rowid'=>'order_line','cd.label'=>"order_line",'cd.description'=>"order_line",
234  'cd.product_type'=>'order_line','cd.tva_tx'=>"order_line",'cd.qty'=>"order_line",'cd.total_ht'=>"order_line",'cd.total_tva'=>"order_line",
235  'cd.total_ttc'=>"order_line",'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product'
236  );
237  $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
238  $keyforselect='commande'; $keyforelement='order'; $keyforaliasextra='extra';
239  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
240  $keyforselect='commandedet'; $keyforelement='order_line'; $keyforaliasextra='extra2';
241  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
242  $keyforselect='product'; $keyforelement='product'; $keyforaliasextra='extra3';
243  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
244  $this->export_sql_start[$r]='SELECT DISTINCT ';
245  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s';
246  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';
247  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
248  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
249  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c';
250  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
251  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
252  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
253  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commande_extrafields as extra ON c.rowid = extra.fk_object';
254  $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'commandedet as cd';
255  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet_extrafields as extra2 on cd.rowid = extra2.fk_object';
256  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
257  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
258  $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande';
259  $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande').')';
260  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.(empty($user)?0:$user->id);
261  }
262 
263 
272  function init($options='')
273  {
274  global $conf,$langs;
275 
276  // Permissions
277  $this->remove($options);
278 
279  //ODT template
280  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/orders/template_order.odt';
281  $dirodt=DOL_DATA_ROOT.'/doctemplates/orders';
282  $dest=$dirodt.'/template_order.odt';
283 
284  if (file_exists($src) && ! file_exists($dest))
285  {
286  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
287  dol_mkdir($dirodt);
288  $result=dol_copy($src,$dest,0,0);
289  if ($result < 0)
290  {
291  $langs->load("errors");
292  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
293  return 0;
294  }
295  }
296 
297  $sql = array(
298  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order' AND entity = ".$conf->entity,
299  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','order',".$conf->entity.")"
300  );
301 
302  return $this->_init($sql,$options);
303  }
304 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:666
Class DolibarrModules.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
init($options='')
Function called when module is enabled.
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to describe module customer orders.