dolibarr  7.0.0-beta
modExpedition.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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
30 include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php';
31 
32 
37 {
38 
44  function __construct($db)
45  {
46  global $conf, $user;
47 
48  $this->db = $db;
49  $this->numero = 80;
50 
51  $this->family = "crm";
52  $this->module_position = 40;
53  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
54  $this->name = preg_replace('/^mod/i','',get_class($this));
55  $this->description = "Gestion des expeditions";
56 
57  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
58  $this->version = 'dolibarr';
59 
60  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
61  $this->special = 0;
62  $this->picto = "sending";
63 
64  // Data directories to create when module is enabled
65  $this->dirs = array("/expedition/temp",
66  "/expedition/sending",
67  "/expedition/sending/temp",
68  "/expedition/receipt",
69  "/expedition/receipt/temp",
70  "/doctemplates/shipment",
71  "/doctemplates/delivery"
72  );
73 
74  // Config pages
75  $this->config_page_url = array("confexped.php");
76 
77  // Dependencies
78  $this->depends = array("modCommande");
79  $this->requiredby = array();
80  $this->conflictwith = array();
81  $this->langfiles = array('deliveries','sendings');
82 
83  // Constants
84  $this->const = array();
85  $r=0;
86 
87  $this->const[$r][0] = "EXPEDITION_ADDON_PDF";
88  $this->const[$r][1] = "chaine";
89  $this->const[$r][2] = "rouget";
90  $this->const[$r][3] = 'Nom du gestionnaire de generation des bons expeditions en PDF';
91  $this->const[$r][4] = 0;
92  $r++;
93 
94  $this->const[$r][0] = "EXPEDITION_ADDON_NUMBER";
95  $this->const[$r][1] = "chaine";
96  $this->const[$r][2] = "mod_expedition_safor";
97  $this->const[$r][3] = 'Name for numbering manager for shipments';
98  $this->const[$r][4] = 0;
99  $r++;
100 
101  $this->const[$r][0] = "EXPEDITION_ADDON_PDF_ODT_PATH";
102  $this->const[$r][1] = "chaine";
103  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/shipment";
104  $this->const[$r][3] = "";
105  $this->const[$r][4] = 0;
106  $r++;
107 
108  $this->const[$r][0] = "LIVRAISON_ADDON_PDF";
109  $this->const[$r][1] = "chaine";
110  $this->const[$r][2] = "typhon";
111  $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de reception en PDF';
112  $this->const[$r][4] = 0;
113  $r++;
114 
115  $this->const[$r][0] = "LIVRAISON_ADDON_NUMBER";
116  $this->const[$r][1] = "chaine";
117  $this->const[$r][2] = "mod_livraison_jade";
118  $this->const[$r][3] = 'Nom du gestionnaire de numerotation des bons de reception';
119  $this->const[$r][4] = 0;
120  $r++;
121 
122  $this->const[$r][0] = "LIVRAISON_ADDON_PDF_ODT_PATH";
123  $this->const[$r][1] = "chaine";
124  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/delivery";
125  $this->const[$r][3] = "";
126  $this->const[$r][4] = 0;
127  $r++;
128 
129  $this->const[$r][0] = "MAIN_SUBMODULE_EXPEDITION";
130  $this->const[$r][1] = "chaine";
131  $this->const[$r][2] = "1";
132  $this->const[$r][3] = "Enable shipments";
133  $this->const[$r][4] = 0;
134  $r++;
135 
136  // Boxes
137  $this->boxes = array();
138 
139  // Permissions
140  $this->rights = array();
141  $this->rights_class = 'expedition';
142  $r=0;
143 
144  $r++;
145  $this->rights[$r][0] = 101;
146  $this->rights[$r][1] = 'Lire les expeditions';
147  $this->rights[$r][2] = 'r';
148  $this->rights[$r][3] = 0;
149  $this->rights[$r][4] = 'lire';
150 
151  $r++;
152  $this->rights[$r][0] = 102;
153  $this->rights[$r][1] = 'Creer modifier les expeditions';
154  $this->rights[$r][2] = 'w';
155  $this->rights[$r][3] = 0;
156  $this->rights[$r][4] = 'creer';
157 
158  $r++;
159  $this->rights[$r][0] = 104;
160  $this->rights[$r][1] = 'Valider les expeditions';
161  $this->rights[$r][2] = 'd';
162  $this->rights[$r][3] = 0;
163  $this->rights[$r][4] = 'shipping_advance';
164  $this->rights[$r][5] = 'validate';
165 
166  $r++;
167  $this->rights[$r][0] = 105; // id de la permission
168  $this->rights[$r][1] = 'Envoyer les expeditions aux clients'; // libelle de la permission
169  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
170  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
171  $this->rights[$r][4] = 'shipping_advance';
172  $this->rights[$r][5] = 'send';
173 
174  $r++;
175  $this->rights[$r][0] = 106;
176  $this->rights[$r][1] = 'Exporter les expeditions';
177  $this->rights[$r][2] = 'r';
178  $this->rights[$r][3] = 0;
179  $this->rights[$r][4] = 'shipment';
180  $this->rights[$r][5] = 'export';
181 
182  $r++;
183  $this->rights[$r][0] = 109;
184  $this->rights[$r][1] = 'Supprimer les expeditions';
185  $this->rights[$r][2] = 'd';
186  $this->rights[$r][3] = 0;
187  $this->rights[$r][4] = 'supprimer';
188 
189  $r++;
190  $this->rights[$r][0] = 1101;
191  $this->rights[$r][1] = 'Lire les bons de livraison';
192  $this->rights[$r][2] = 'r';
193  $this->rights[$r][3] = 0;
194  $this->rights[$r][4] = 'livraison';
195  $this->rights[$r][5] = 'lire';
196 
197  $r++;
198  $this->rights[$r][0] = 1102;
199  $this->rights[$r][1] = 'Creer modifier les bons de livraison';
200  $this->rights[$r][2] = 'w';
201  $this->rights[$r][3] = 0;
202  $this->rights[$r][4] = 'livraison';
203  $this->rights[$r][5] = 'creer';
204 
205  $r++;
206  $this->rights[$r][0] = 1104;
207  $this->rights[$r][1] = 'Valider les bons de livraison';
208  $this->rights[$r][2] = 'd';
209  $this->rights[$r][3] = 0;
210  $this->rights[$r][4] = 'livraison_advance';
211  $this->rights[$r][5] = 'validate';
212 
213  $r++;
214  $this->rights[$r][0] = 1109;
215  $this->rights[$r][1] = 'Supprimer les bons de livraison';
216  $this->rights[$r][2] = 'd';
217  $this->rights[$r][3] = 0;
218  $this->rights[$r][4] = 'livraison';
219  $this->rights[$r][5] = 'supprimer';
220 
221 
222  // Menus
223  //-------
224  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
225 
226 
227  // Exports
228  //--------
229  $r=0;
230 
231  include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
232  $shipment=new Commande($this->db);
233  $contact_arrays=$shipment->liste_type_contact('external','',0,0,'');
234  if (is_array($contact_arrays) && count($contact_arrays)>0){
235  $idcontacts=join(',',array_keys($shipment->liste_type_contact('external','',0,0,'')));
236  } else {
237  $idcontacts=0;
238  }
239 
240 
241  $r++;
242  $this->export_code[$r]=$this->rights_class.'_'.$r;
243  $this->export_label[$r]='Shipments'; // Translation key (used only if key ExportDataset_xxx_z not found)
244  $this->export_permission[$r]=array(array("expedition","shipment","export"));
245  $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'ThirdParty','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','d.nom'=>'State','co.label'=>'Country','co.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.idprof5'=>'ProfId5','s.idprof6'=>'ProfId6','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_customer'=>"RefCustomer",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_delivery'=>"DateDeliveryPlanned",'c.tracking_number'=>"TrackingNumber",'c.height'=>"Height",'c.width'=>"Width",'c.size'=>"Depth",'c.size_units'=>'SizeUnits','c.weight'=>"Weight",'c.weight_units'=>"WeightUnits",'c.fk_statut'=>'Status','c.note_public'=>"NotePublic",'ed.rowid'=>'LineId','cd.description'=>'Description','ed.qty'=>"Qty",'p.rowid'=>'ProductId','p.ref'=>'ProductRef','p.label'=>'ProductLabel','p.weight'=>'ProductWeight','p.weight_units'=>'WeightUnits','p.volume'=>'ProductVolume','p.volume_units'=>'VolumeUnits');
246  if ($idcontacts && ! empty($conf->global->SHIPMENT_ADD_CONTACTS_IN_EXPORT)) $this->export_fields_array[$r]+=array('sp.rowid'=>'IdContact','sp.lastname'=>'Lastname','sp.firstname'=>'Firstname','sp.note_public'=>'NotePublic');
247  //$this->export_TypeFields_array[$r]=array('s.rowid'=>"List:societe:nom",'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','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','ed.qty'=>"Text");
248  $this->export_TypeFields_array[$r]=array('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','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_customer'=>"Text",'c.date_creation'=>"Date",'c.date_delivery'=>"Date",'c.tracking_number'=>"Numeric",'c.height'=>"Numeric",'c.width'=>"Numeric",'c.weight'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'ed.qty'=>"Numeric",'d.nom'=>'Text');
249  $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','d.nom'=>'company','co.label'=>'company','co.code'=>'company','s.fk_pays'=>'company','s.phone'=>'company','s.siren'=>'company','s.ape'=>'company','s.siret'=>'company','s.idprof4'=>'company','s.idprof5'=>'company','s.idprof6'=>'company','c.rowid'=>"shipment",'c.ref'=>"shipment",'c.ref_customer'=>"shipment",'c.fk_soc'=>"shipment",'c.date_creation'=>"shipment",'c.date_delivery'=>"shipment",'c.tracking_number'=>'shipment','c.height'=>"shipment",'c.width'=>"shipment",'c.size'=>'shipment','c.size_units'=>'shipment','c.weight'=>"shipment",'c.weight_units'=>'shipment','c.fk_statut'=>"shipment",'c.note_public'=>"shipment",'ed.rowid'=>'shipment_line','cd.description'=>'shipment_line','ed.qty'=>"shipment_line",'p.rowid'=>'product','p.ref'=>'product','p.label'=>'product','p.weight'=>'product','p.weight_units'=>'product','p.volume'=>'product','p.volume_units'=>'product');
250  if ($idcontacts && ! empty($conf->global->SHIPMENT_ADD_CONTACTS_IN_EXPORT)) $this->export_entities_array[$r]+=array('sp.rowid'=>'contact','sp.lastname'=>'contact','sp.firstname'=>'contact','sp.note_public'=>'contact');
251  $this->export_dependencies_array[$r]=array('shipment_line'=>'ed.rowid','product'=>'ed.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
252  if ($idcontacts && ! empty($conf->global->SHIPMENT_ADD_CONTACTS_IN_EXPORT))
253  {
254  $keyforselect='socpeople'; $keyforelement='contact'; $keyforaliasextra='extra3';
255  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
256  }
257  $keyforselect='expedition'; $keyforelement='shipment'; $keyforaliasextra='extra';
258  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
259  $keyforselect='expeditiondet'; $keyforelement='shipment_line'; $keyforaliasextra='extra2';
260  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
261 
262  $this->export_sql_start[$r]='SELECT DISTINCT ';
263  $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'expedition as c';
264  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'expedition_extrafields as extra ON c.rowid = extra.fk_object,';
265  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s';
266  if(!$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';
267  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
268  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
269  $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expeditiondet as ed';
270  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet_extrafields as extra2 ON ed.rowid = extra2.fk_object';
271  $this->export_sql_end[$r] .=' , '.MAIN_DB_PREFIX.'commandedet as cd';
272  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
273  if ($idcontacts && ! empty($conf->global->SHIPMENT_ADD_CONTACTS_IN_EXPORT))
274  {
275  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'element_contact as ee ON ee.element_id = cd.fk_commande AND ee.fk_c_type_contact IN ('.$idcontacts.')';
276  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople';
277  $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object';
278  }
279  $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid';
280  $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('expedition').')';
281  if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id;
282  }
283 
284 
293  function init($options='')
294  {
295  global $conf,$langs;
296 
297  // Permissions
298  $this->remove($options);
299 
300  //ODT template
301  $src=DOL_DOCUMENT_ROOT.'/install/doctemplates/shipment/template_shipment.odt';
302  $dirodt=DOL_DATA_ROOT.'/doctemplates/shipment';
303  $dest=$dirodt.'/template_shipment.odt';
304 
305  if (file_exists($src) && ! file_exists($dest))
306  {
307  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
308  dol_mkdir($dirodt);
309  $result=dol_copy($src,$dest,0,0);
310  if ($result < 0)
311  {
312  $langs->load("errors");
313  $this->error=$langs->trans('ErrorFailToCopyFile',$src,$dest);
314  return 0;
315  }
316  }
317 
318  $sql = array();
319 
320  $sql = array(
321  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'shipping' AND entity = ".$conf->entity,
322  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','shipping',".$conf->entity.")",
323  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[3][2])."' AND type = 'delivery' AND entity = ".$conf->entity,
324  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[3][2])."','delivery',".$conf->entity.")",
325  );
326 
327  return $this->_init($sql,$options);
328  }
329 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:631
Class DolibarrModules.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
init($options='')
Function called when module is enabled.
Class to manage customers orders.
Class to describe and enable module Expedition.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
_init($array_sql, $options='')
Enables a module.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
__construct($db)
Constructor.