|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <[email protected]> |
|
4
|
|
|
* Copyright (C) 2004-2016 Laurent Destailleur <[email protected]> |
|
5
|
|
|
* Copyright (C) 2005-2011 Regis Houssin <[email protected]> |
|
6
|
|
|
* Copyright (C) 2011 Juanjo Menent <[email protected]> |
|
7
|
|
|
* Copyright (C) 2013 Philippe Grand <[email protected]> |
|
8
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
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 <https://www.gnu.org/licenses/>. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace Dolibarr\Modules; |
|
25
|
|
|
|
|
26
|
|
|
use Dolibarr\Core\Base\DolibarrModules; |
|
27
|
|
|
use Dolibarr\Code\Commande\Classes\Commande; |
|
|
|
|
|
|
28
|
|
|
use DoliDB; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* \defgroup expedition Module Shipping |
|
32
|
|
|
* \brief Module to manage product shipments |
|
33
|
|
|
* |
|
34
|
|
|
* \file htdocs/core/modules/modExpedition.class.php |
|
35
|
|
|
* \ingroup expedition |
|
36
|
|
|
* \brief Description and activation file for the module Expedition |
|
37
|
|
|
*/ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Class to describe and enable module Expedition |
|
41
|
|
|
*/ |
|
42
|
|
|
class Expedition extends DolibarrModules |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* Constructor. Define names, constants, directories, boxes, permissions |
|
46
|
|
|
* |
|
47
|
|
|
* @param DoliDB $db Database handler |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($db) |
|
50
|
|
|
{ |
|
51
|
|
|
global $conf, $user; // $conf is required by /core/extrafieldsinexport.inc.php |
|
52
|
|
|
|
|
53
|
|
|
$this->db = $db; |
|
54
|
|
|
$this->numero = 80; |
|
55
|
|
|
|
|
56
|
|
|
$this->family = "crm"; |
|
57
|
|
|
$this->module_position = '40'; |
|
58
|
|
|
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
59
|
|
|
$this->name = preg_replace('/^mod/i', '', get_only_class($this)); |
|
60
|
|
|
$this->description = "Gestion des expeditions"; |
|
61
|
|
|
|
|
62
|
|
|
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
63
|
|
|
$this->version = 'dolibarr'; |
|
64
|
|
|
|
|
65
|
|
|
$this->const_name = 'MAIN_MODULE_' . static::getNameOf($this->name); // strtoupper($this->name); |
|
66
|
|
|
$this->picto = "dolly"; |
|
67
|
|
|
|
|
68
|
|
|
// Data directories to create when module is enabled |
|
69
|
|
|
$this->dirs = array("/expedition/temp", |
|
70
|
|
|
"/expedition/sending", |
|
71
|
|
|
"/expedition/sending/temp", |
|
72
|
|
|
"/expedition/receipt", |
|
73
|
|
|
"/expedition/receipt/temp", |
|
74
|
|
|
"/doctemplates/shipments", |
|
75
|
|
|
"/doctemplates/deliveries" |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
// Config pages |
|
79
|
|
|
$this->config_page_url = array("expedition.php"); |
|
80
|
|
|
|
|
81
|
|
|
// Dependencies |
|
82
|
|
|
$this->depends = array("modCommande"); |
|
83
|
|
|
$this->requiredby = array(); |
|
84
|
|
|
$this->conflictwith = array(); |
|
85
|
|
|
$this->langfiles = array('deliveries', 'sendings'); |
|
86
|
|
|
|
|
87
|
|
|
// Constants |
|
88
|
|
|
$this->const = array(); |
|
89
|
|
|
$r = 0; |
|
90
|
|
|
|
|
91
|
|
|
$this->const[$r][0] = "EXPEDITION_ADDON_PDF"; |
|
92
|
|
|
$this->const[$r][1] = "chaine"; |
|
93
|
|
|
$this->const[$r][2] = "espadon"; |
|
94
|
|
|
$this->const[$r][3] = 'Nom du gestionnaire de generation des bons expeditions en PDF'; |
|
95
|
|
|
$this->const[$r][4] = 0; |
|
96
|
|
|
$r++; |
|
97
|
|
|
|
|
98
|
|
|
$this->const[$r][0] = "EXPEDITION_ADDON_NUMBER"; |
|
99
|
|
|
$this->const[$r][1] = "chaine"; |
|
100
|
|
|
$this->const[$r][2] = "mod_expedition_safor"; |
|
101
|
|
|
$this->const[$r][3] = 'Name for numbering manager for shipments'; |
|
102
|
|
|
$this->const[$r][4] = 0; |
|
103
|
|
|
$r++; |
|
104
|
|
|
|
|
105
|
|
|
$this->const[$r][0] = "EXPEDITION_ADDON_PDF_ODT_PATH"; |
|
106
|
|
|
$this->const[$r][1] = "chaine"; |
|
107
|
|
|
$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/shipments"; |
|
108
|
|
|
$this->const[$r][3] = ""; |
|
109
|
|
|
$this->const[$r][4] = 0; |
|
110
|
|
|
$r++; |
|
111
|
|
|
|
|
112
|
|
|
$this->const[$r][0] = "DELIVERY_ADDON_PDF"; |
|
113
|
|
|
$this->const[$r][1] = "chaine"; |
|
114
|
|
|
$this->const[$r][2] = "storm"; |
|
115
|
|
|
$this->const[$r][3] = 'Nom du gestionnaire de generation des bons de reception en PDF'; |
|
116
|
|
|
$this->const[$r][4] = 0; |
|
117
|
|
|
$r++; |
|
118
|
|
|
|
|
119
|
|
|
$this->const[$r][0] = "DELIVERY_ADDON_NUMBER"; |
|
120
|
|
|
$this->const[$r][1] = "chaine"; |
|
121
|
|
|
$this->const[$r][2] = "mod_delivery_jade"; |
|
122
|
|
|
$this->const[$r][3] = 'Nom du gestionnaire de numerotation des bons de reception'; |
|
123
|
|
|
$this->const[$r][4] = 0; |
|
124
|
|
|
$r++; |
|
125
|
|
|
|
|
126
|
|
|
$this->const[$r][0] = "DELIVERY_ADDON_PDF_ODT_PATH"; |
|
127
|
|
|
$this->const[$r][1] = "chaine"; |
|
128
|
|
|
$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/deliveries"; |
|
129
|
|
|
$this->const[$r][3] = ""; |
|
130
|
|
|
$this->const[$r][4] = 0; |
|
131
|
|
|
$r++; |
|
132
|
|
|
|
|
133
|
|
|
$this->const[$r][0] = "MAIN_SUBMODULE_EXPEDITION"; |
|
134
|
|
|
$this->const[$r][1] = "chaine"; |
|
135
|
|
|
$this->const[$r][2] = "1"; |
|
136
|
|
|
$this->const[$r][3] = "Enable delivery receipts"; |
|
137
|
|
|
$this->const[$r][4] = 0; |
|
138
|
|
|
$r++; |
|
139
|
|
|
|
|
140
|
|
|
// Boxes |
|
141
|
|
|
$this->boxes = array( |
|
142
|
|
|
0 => array('file' => 'box_shipments.php', 'enabledbydefaulton' => 'Home'), |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
// Permissions |
|
146
|
|
|
$this->rights = array(); |
|
147
|
|
|
$this->rights_class = 'expedition'; |
|
148
|
|
|
$r = 0; |
|
149
|
|
|
|
|
150
|
|
|
$r++; |
|
151
|
|
|
$this->rights[$r][0] = 101; |
|
152
|
|
|
$this->rights[$r][1] = 'Read shipments'; |
|
153
|
|
|
$this->rights[$r][2] = 'r'; |
|
154
|
|
|
$this->rights[$r][3] = 0; |
|
155
|
|
|
$this->rights[$r][4] = 'lire'; |
|
156
|
|
|
|
|
157
|
|
|
$r++; |
|
158
|
|
|
$this->rights[$r][0] = 102; |
|
159
|
|
|
$this->rights[$r][1] = 'Create/modify shipments'; |
|
160
|
|
|
$this->rights[$r][2] = 'w'; |
|
161
|
|
|
$this->rights[$r][3] = 0; |
|
162
|
|
|
$this->rights[$r][4] = 'creer'; |
|
163
|
|
|
|
|
164
|
|
|
$r++; |
|
165
|
|
|
$this->rights[$r][0] = 104; |
|
166
|
|
|
$this->rights[$r][1] = 'Validate shipments'; |
|
167
|
|
|
$this->rights[$r][2] = 'd'; |
|
168
|
|
|
$this->rights[$r][3] = 0; |
|
169
|
|
|
$this->rights[$r][4] = 'shipping_advance'; |
|
170
|
|
|
$this->rights[$r][5] = 'validate'; |
|
171
|
|
|
|
|
172
|
|
|
$r++; |
|
173
|
|
|
$this->rights[$r][0] = 105; // id de la permission |
|
174
|
|
|
$this->rights[$r][1] = 'Send shipments by email to customers'; // libelle de la permission |
|
175
|
|
|
$this->rights[$r][2] = 'd'; // type de la permission (deprecated) |
|
176
|
|
|
$this->rights[$r][3] = 0; // La permission est-elle une permission par default |
|
177
|
|
|
$this->rights[$r][4] = 'shipping_advance'; |
|
178
|
|
|
$this->rights[$r][5] = 'send'; |
|
179
|
|
|
|
|
180
|
|
|
$r++; |
|
181
|
|
|
$this->rights[$r][0] = 106; |
|
182
|
|
|
$this->rights[$r][1] = 'Export shipments'; |
|
183
|
|
|
$this->rights[$r][2] = 'r'; |
|
184
|
|
|
$this->rights[$r][3] = 0; |
|
185
|
|
|
$this->rights[$r][4] = 'shipment'; |
|
186
|
|
|
$this->rights[$r][5] = 'export'; |
|
187
|
|
|
|
|
188
|
|
|
$r++; |
|
189
|
|
|
$this->rights[$r][0] = 109; |
|
190
|
|
|
$this->rights[$r][1] = 'Delete shipments'; |
|
191
|
|
|
$this->rights[$r][2] = 'd'; |
|
192
|
|
|
$this->rights[$r][3] = 0; |
|
193
|
|
|
$this->rights[$r][4] = 'supprimer'; |
|
194
|
|
|
|
|
195
|
|
|
$r++; |
|
196
|
|
|
$this->rights[$r][0] = 1101; |
|
197
|
|
|
$this->rights[$r][1] = 'Read delivery receipts'; |
|
198
|
|
|
$this->rights[$r][2] = 'r'; |
|
199
|
|
|
$this->rights[$r][3] = 0; |
|
200
|
|
|
$this->rights[$r][4] = 'delivery'; |
|
201
|
|
|
$this->rights[$r][5] = 'lire'; |
|
202
|
|
|
|
|
203
|
|
|
$r++; |
|
204
|
|
|
$this->rights[$r][0] = 1102; |
|
205
|
|
|
$this->rights[$r][1] = 'Create/modify delivery receipts'; |
|
206
|
|
|
$this->rights[$r][2] = 'w'; |
|
207
|
|
|
$this->rights[$r][3] = 0; |
|
208
|
|
|
$this->rights[$r][4] = 'delivery'; |
|
209
|
|
|
$this->rights[$r][5] = 'creer'; |
|
210
|
|
|
|
|
211
|
|
|
$r++; |
|
212
|
|
|
$this->rights[$r][0] = 1104; |
|
213
|
|
|
$this->rights[$r][1] = 'Validate delivery receipts'; |
|
214
|
|
|
$this->rights[$r][2] = 'd'; |
|
215
|
|
|
$this->rights[$r][3] = 0; |
|
216
|
|
|
$this->rights[$r][4] = 'delivery_advance'; |
|
217
|
|
|
$this->rights[$r][5] = 'validate'; |
|
218
|
|
|
|
|
219
|
|
|
$r++; |
|
220
|
|
|
$this->rights[$r][0] = 1109; |
|
221
|
|
|
$this->rights[$r][1] = 'Delete delivery receipts'; |
|
222
|
|
|
$this->rights[$r][2] = 'd'; |
|
223
|
|
|
$this->rights[$r][3] = 0; |
|
224
|
|
|
$this->rights[$r][4] = 'delivery'; |
|
225
|
|
|
$this->rights[$r][5] = 'supprimer'; |
|
226
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
// Menus |
|
229
|
|
|
//------- |
|
230
|
|
|
$this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
231
|
|
|
|
|
232
|
|
|
// Exports |
|
233
|
|
|
//-------- |
|
234
|
|
|
$r = 0; |
|
235
|
|
|
|
|
236
|
|
|
$shipment = new Commande($this->db); |
|
237
|
|
|
$contact_arrays = $shipment->liste_type_contact('external', '', 0, 0, ''); |
|
238
|
|
|
if (is_array($contact_arrays) && count($contact_arrays) > 0) { |
|
239
|
|
|
$idcontacts = implode(',', array_keys($shipment->liste_type_contact('external', '', 0, 0, ''))); |
|
240
|
|
|
} else { |
|
241
|
|
|
$idcontacts = 0; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
$r++; |
|
246
|
|
|
$this->export_code[$r] = $this->rights_class . '_' . $r; |
|
247
|
|
|
$this->export_label[$r] = 'Shipments'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
248
|
|
|
$this->export_permission[$r] = array(array("expedition", "shipment", "export")); |
|
249
|
|
|
$this->export_fields_array[$r] = array( |
|
250
|
|
|
's.rowid' => "IdCompany", 's.nom' => 'ThirdParty', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town', 'd.nom' => 'State', 'co.label' => 'Country', |
|
251
|
|
|
'co.code' => 'CountryCode', 's.phone' => 'Phone', 's.siren' => 'ProfId1', 's.siret' => 'ProfId2', 's.ape' => 'ProfId3', 's.idprof4' => 'ProfId4', 's.idprof5' => 'ProfId5', |
|
252
|
|
|
's.idprof6' => 'ProfId6', 'c.rowid' => "Id", 'c.ref' => "Ref", 'c.ref_customer' => "RefCustomer", 'c.fk_soc' => "IdCompany", 'c.date_creation' => "DateCreation", 'c.date_valid' => "DateValidation", |
|
253
|
|
|
'c.date_delivery' => "DateDeliveryPlanned", 'c.tracking_number' => "TrackingNumber", 'c.height' => "Height", 'c.width' => "Width", 'c.size' => "Depth", |
|
254
|
|
|
'c.size_units' => 'SizeUnits', 'c.weight' => "Weight", 'c.weight_units' => "WeightUnits", 'c.fk_statut' => 'Status', 'c.note_public' => "NotePublic", |
|
255
|
|
|
'ed.rowid' => 'LineId', 'cd.description' => 'Description', 'ed.qty' => "Qty", 'p.rowid' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel', |
|
256
|
|
|
'p.weight' => 'ProductWeight', 'p.weight_units' => 'WeightUnits', 'p.volume' => 'ProductVolume', 'p.volume_units' => 'VolumeUnits' |
|
257
|
|
|
); |
|
258
|
|
|
if ($idcontacts && getDolGlobalString('SHIPMENT_ADD_CONTACTS_IN_EXPORT')) { |
|
259
|
|
|
$this->export_fields_array[$r] += array('sp.rowid' => 'IdContact', 'sp.lastname' => 'Lastname', 'sp.firstname' => 'Firstname', 'sp.note_public' => 'NotePublic'); |
|
260
|
|
|
} |
|
261
|
|
|
//$this->export_TypeFields_array[$r]=array( |
|
262
|
|
|
// 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label', |
|
263
|
|
|
// '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", |
|
264
|
|
|
// 'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric", |
|
265
|
|
|
// 'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','ed.qty'=>"Text" |
|
266
|
|
|
//); |
|
267
|
|
|
$this->export_TypeFields_array[$r] = array( |
|
268
|
|
|
'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', |
|
269
|
|
|
'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_valid' => "Date", |
|
270
|
|
|
'c.date_delivery' => "Date", 'c.tracking_number' => "Numeric", 'c.height' => "Numeric", 'c.width' => "Numeric", 'c.weight' => "Numeric", 'c.fk_statut' => 'Status', |
|
271
|
|
|
'c.note_public' => "Text", 'ed.qty' => "Numeric", 'd.nom' => 'Text' |
|
272
|
|
|
); |
|
273
|
|
|
$this->export_entities_array[$r] = array( |
|
274
|
|
|
's.rowid' => "company", 's.nom' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company', 'd.nom' => 'company', 'co.label' => 'company', |
|
275
|
|
|
'co.code' => 'company', 's.fk_pays' => 'company', 's.phone' => 'company', 's.siren' => 'company', 's.ape' => 'company', 's.siret' => 'company', 's.idprof4' => 'company', |
|
276
|
|
|
's.idprof5' => 'company', 's.idprof6' => 'company', 'c.rowid' => "shipment", 'c.ref' => "shipment", 'c.ref_customer' => "shipment", 'c.fk_soc' => "shipment", |
|
277
|
|
|
'c.date_creation' => "shipment", 'c.date_valid' => "shipment", 'c.date_delivery' => "shipment", 'c.tracking_number' => 'shipment', 'c.height' => "shipment", 'c.width' => "shipment", |
|
278
|
|
|
'c.size' => 'shipment', 'c.size_units' => 'shipment', 'c.weight' => "shipment", 'c.weight_units' => 'shipment', 'c.fk_statut' => "shipment", 'c.note_public' => "shipment", |
|
279
|
|
|
'ed.rowid' => 'shipment_line', 'cd.description' => 'shipment_line', 'ed.qty' => "shipment_line", 'p.rowid' => 'product', 'p.ref' => 'product', 'p.label' => 'product', |
|
280
|
|
|
'p.weight' => 'product', 'p.weight_units' => 'product', 'p.volume' => 'product', 'p.volume_units' => 'product' |
|
281
|
|
|
); |
|
282
|
|
|
if ($idcontacts && getDolGlobalString('SHIPMENT_ADD_CONTACTS_IN_EXPORT')) { |
|
283
|
|
|
$this->export_entities_array[$r] += array('sp.rowid' => 'contact', 'sp.lastname' => 'contact', 'sp.firstname' => 'contact', 'sp.note_public' => 'contact'); |
|
284
|
|
|
} |
|
285
|
|
|
$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 |
|
286
|
|
|
if ($idcontacts && getDolGlobalString('SHIPMENT_ADD_CONTACTS_IN_EXPORT')) { |
|
287
|
|
|
$keyforselect = 'socpeople'; |
|
288
|
|
|
$keyforelement = 'contact'; |
|
289
|
|
|
$keyforaliasextra = 'extra3'; |
|
290
|
|
|
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
|
291
|
|
|
} |
|
292
|
|
|
$keyforselect = 'expedition'; |
|
293
|
|
|
$keyforelement = 'shipment'; |
|
294
|
|
|
$keyforaliasextra = 'extra'; |
|
295
|
|
|
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
|
296
|
|
|
$keyforselect = 'expeditiondet'; |
|
297
|
|
|
$keyforelement = 'shipment_line'; |
|
298
|
|
|
$keyforaliasextra = 'extra2'; |
|
299
|
|
|
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
|
300
|
|
|
$keyforselect = 'product'; |
|
301
|
|
|
$keyforelement = 'product'; |
|
302
|
|
|
$keyforaliasextra = 'extraprod'; |
|
303
|
|
|
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php'; |
|
304
|
|
|
|
|
305
|
|
|
$this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
306
|
|
|
$this->export_sql_end[$r] = ' FROM ' . MAIN_DB_PREFIX . 'expedition as c'; |
|
307
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'expedition_extrafields as extra ON c.rowid = extra.fk_object,'; |
|
308
|
|
|
$this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'societe as s'; |
|
309
|
|
|
if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { |
|
310
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
311
|
|
|
} |
|
312
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON s.fk_departement = d.rowid'; |
|
313
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as co ON s.fk_pays = co.rowid,'; |
|
314
|
|
|
$this->export_sql_end[$r] .= ' ' . MAIN_DB_PREFIX . 'expeditiondet as ed'; |
|
315
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'expeditiondet_extrafields as extra2 ON ed.rowid = extra2.fk_object'; |
|
316
|
|
|
$this->export_sql_end[$r] .= ' , ' . MAIN_DB_PREFIX . 'commandedet as cd'; |
|
317
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on cd.fk_product = p.rowid'; |
|
318
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_extrafields as extraprod ON p.rowid = extraprod.fk_object'; |
|
319
|
|
|
if ($idcontacts && getDolGlobalString('SHIPMENT_ADD_CONTACTS_IN_EXPORT')) { |
|
320
|
|
|
$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 (' . $this->db->sanitize($idcontacts) . ')'; |
|
321
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople as sp ON sp.rowid = ee.fk_socpeople'; |
|
322
|
|
|
$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object'; |
|
323
|
|
|
} |
|
324
|
|
|
$this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_elementdet = cd.rowid'; |
|
325
|
|
|
$this->export_sql_end[$r] .= ' AND c.entity IN (' . getEntity('expedition') . ')'; |
|
326
|
|
|
if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) { |
|
327
|
|
|
$this->export_sql_end[$r] .= ' AND sc.fk_user = ' . (empty($user) ? 0 : $user->id); |
|
328
|
|
|
} |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* Function called when module is enabled. |
|
334
|
|
|
* The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
335
|
|
|
* It also creates data directories |
|
336
|
|
|
* |
|
337
|
|
|
* @param string $options Options when enabling module ('', 'noboxes') |
|
338
|
|
|
* @return int 1 if OK, 0 if KO |
|
339
|
|
|
*/ |
|
340
|
|
|
public function init($options = '') |
|
341
|
|
|
{ |
|
342
|
|
|
global $conf, $langs; |
|
343
|
|
|
|
|
344
|
|
|
// Permissions |
|
345
|
|
|
$this->remove($options); |
|
346
|
|
|
|
|
347
|
|
|
//ODT template |
|
348
|
|
|
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/shipments/template_shipment.odt'; |
|
349
|
|
|
$dirodt = DOL_DATA_ROOT . '/doctemplates/shipments'; |
|
350
|
|
|
$dest = $dirodt . '/template_shipment.odt'; |
|
351
|
|
|
|
|
352
|
|
|
if (file_exists($src) && !file_exists($dest)) { |
|
353
|
|
|
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php'; |
|
354
|
|
|
dol_mkdir($dirodt); |
|
355
|
|
|
$result = dol_copy($src, $dest, 0, 0); |
|
356
|
|
|
if ($result < 0) { |
|
357
|
|
|
$langs->load("errors"); |
|
358
|
|
|
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest); |
|
359
|
|
|
return 0; |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
$sql = array(); |
|
364
|
|
|
|
|
365
|
|
|
$sql = array( |
|
366
|
|
|
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[0][2]) . "' AND type = 'shipping' AND entity = " . ((int)$conf->entity), |
|
367
|
|
|
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[0][2]) . "', 'shipping', " . ((int)$conf->entity) . ")", |
|
368
|
|
|
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = '" . $this->db->escape($this->const[3][2]) . "' AND type = 'delivery' AND entity = " . ((int)$conf->entity), |
|
369
|
|
|
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('" . $this->db->escape($this->const[3][2]) . "', 'delivery', " . ((int)$conf->entity) . ")", |
|
370
|
|
|
//"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name IN ('STOCK_CALCULATE_ON_BILL', 'STOCK_CALCULATE_ON_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_SHIPMENT', 'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') AND entity = ".((int) $conf->entity), |
|
371
|
|
|
//"INSERT INTO ".MAIN_DB_PREFIX."const (name, value, entity) VALUES ('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', 1, ".((int) $conf->entity).")" |
|
372
|
|
|
); |
|
373
|
|
|
|
|
374
|
|
|
return $this->_init($sql, $options); |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: