dolibarr 25.0.0-alpha
modReception.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
3 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
29include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
30
31
36{
42 public function __construct($db)
43 {
44 global $conf, $user;
45
46 $this->db = $db;
47 $this->numero = 94160;
48
49 $this->family = "srm";
50 $this->module_position = '40';
51 // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
52 $this->name = preg_replace('/^mod/i', '', get_class($this));
53 $this->description = "ReceptionDescription";
54
55 // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
56 $this->version = 'dolibarr';
57
58 $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
59 $this->picto = "dollyrevert";
60
61 // Data directories to create when module is enabled
62 $this->dirs = [
63 "/reception/receipt",
64 "/reception/receipt/temp",
65 "/doctemplates/receptions"
66 ];
67
68 // Config pages
69 $this->config_page_url = array("reception_setup.php");
70
71 // Dependencies
72 $this->depends = array("modFournisseur");
73 $this->requiredby = array();
74 $this->conflictwith = array();
75 $this->langfiles = array('receptions');
76
77 // Constants
78 $this->const = [
79 [
80 "RECEPTION_ADDON_PDF",
81 "chaine",
82 "squille",
83 'Nom du gestionnaire de generation des bons receptions en PDF',
84 0,
85 ],
86 [
87 "RECEPTION_ADDON_NUMBER",
88 "chaine",
89 "mod_reception_beryl",
90 'Name for numbering manager for receptions',
91 0,
92 ],
93 [
94 "RECEPTION_ADDON_PDF_ODT_PATH",
95 "chaine",
96 "DOL_DATA_ROOT".($conf->entity > 1 ? '/'.$conf->entity : '')."/doctemplates/receptions",
97 "",
98 0,
99 ],
100 [
101 "MAIN_SUBMODULE_RECEPTION",
102 "chaine",
103 "1",
104 "Enable receptions",
105 0,
106 ],
107 ];
108
109 // Boxes
110 $this->boxes = array();
111
112 // Permissions
113 $this->rights = array();
114 $this->rights_class = 'reception';
115 $r = 0;
116
117 $r++;
118 $this->rights[$r][0] = $this->numero.$r;
119 $this->rights[$r][1] = 'Read receptions';
120 $this->rights[$r][2] = 'r';
121 $this->rights[$r][3] = 0;
122 $this->rights[$r][4] = 'lire';
123
124 $r++;
125 $this->rights[$r][0] = $this->numero.$r;
126 $this->rights[$r][1] = 'Create receptions';
127 $this->rights[$r][2] = 'w';
128 $this->rights[$r][3] = 0;
129 $this->rights[$r][4] = 'creer';
130
131 $r++;
132 $this->rights[$r][0] = $this->numero.$r;
133 $this->rights[$r][1] = 'Validate receptions';
134 $this->rights[$r][2] = 'd';
135 $this->rights[$r][3] = 0;
136 $this->rights[$r][4] = 'reception_advance';
137 $this->rights[$r][5] = 'validate';
138
139 $r++;
140 $this->rights[$r][0] = $this->numero.$r; // id de la permission
141 $this->rights[$r][1] = 'Send receptions to customers'; // libelle de la permission
142 $this->rights[$r][2] = 'd'; // type de la permission (deprecated)
143 $this->rights[$r][3] = 0; // La permission est-elle une permission par default
144 $this->rights[$r][4] = 'reception_advance';
145 $this->rights[$r][5] = 'send';
146
147 $r++;
148 $this->rights[$r][0] = $this->numero.$r;
149 $this->rights[$r][1] = 'Export receptions';
150 $this->rights[$r][2] = 'r';
151 $this->rights[$r][3] = 0;
152 $this->rights[$r][4] = 'reception';
153 $this->rights[$r][5] = 'export';
154
155 $r++;
156 $this->rights[$r][0] = $this->numero.$r;
157 $this->rights[$r][1] = 'Delete receptions';
158 $this->rights[$r][2] = 'd';
159 $this->rights[$r][3] = 0;
160 $this->rights[$r][4] = 'supprimer';
161
162
163 // Menus
164 //-------
165 $this->menu = 1; // This module add menu entries. They are coded into menu manager.
166
167
168 // Exports
169 //--------
170 $r = 0;
171
172 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
173 $shipment = new CommandeFournisseur($this->db);
174 $contact_arrays = $shipment->liste_type_contact('external', '', 0, 0, '');
175 if (is_array($contact_arrays) && count($contact_arrays) > 0) {
176 $idcontacts = implode(',', array_keys($shipment->liste_type_contact('external', '', 0, 0, '')));
177 } else {
178 $idcontacts = 0;
179 }
180
181
182 $r++;
183 $this->export_code[$r] = $this->rights_class.'_'.$r;
184 $this->export_label[$r] = 'Receptions'; // Translation key (used only if key ExportDataset_xxx_z not found)
185 $this->export_permission[$r] = array(array("reception", "reception", "export"));
186 $this->export_fields_array[$r] = array(
187 's.rowid' => "IdCompany", 's.nom' => 'ThirdParty', 's.address' => 'Address', 's.zip' => 'Zip', 's.town' => 'Town',
188 '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',
189 'c.rowid' => "Id", 'c.ref' => "Ref", 'c.ref_supplier' => "RefSupplier", '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',
190 'ed.comment' => 'Description', 'ed.qty' => "Qty",
191 'p.rowid' => 'ProductId', 'p.ref' => 'ProductRef', 'p.label' => 'ProductLabel', 'p.weight' => 'ProductWeight', 'p.weight_units' => 'WeightUnits', 'p.volume' => 'ProductVolume', 'p.volume_units' => 'VolumeUnits'
192 );
193 if ($idcontacts && getDolGlobalString('RECEPTION_ADD_CONTACTS_IN_EXPORT')) {
194 $this->export_fields_array[$r] += array('sp.rowid' => 'IdContact', 'sp.lastname' => 'Lastname', 'sp.firstname' => 'Firstname', 'sp.note_public' => 'NotePublic');
195 }
196 //$this->export_TypeFields_array[$r]=array('s.rowid'=>"Numeric",'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");
197 $this->export_TypeFields_array[$r] = array(
198 's.nom' => 'Text', 's.address' => 'Text', 's.zip' => 'Text', 's.town' => 'Text',
199 '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',
200 'c.ref' => "Text", 'c.ref_supplier' => "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",
201 'ed.qty' => "Numeric", 'd.nom' => 'Text'
202 );
203 $this->export_entities_array[$r] = array(
204 's.rowid' => "company", 's.nom' => 'company', 's.address' => 'company', 's.zip' => 'company', 's.town' => 'company',
205 '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',
206 'c.rowid' => "reception", 'c.ref' => "reception", 'c.ref_supplier' => "reception", 'c.fk_soc' => "reception", 'c.date_creation' => "reception", 'c.date_delivery' => "reception", 'c.tracking_number' => 'reception', 'c.height' => "reception", 'c.width' => "reception", 'c.size' => 'reception', 'c.size_units' => 'reception', 'c.weight' => "reception", 'c.weight_units' => 'reception', 'c.fk_statut' => "reception", 'c.note_public' => "reception",
207 'ed.rowid' => 'reception_line', 'ed.comment' => 'reception_line', 'ed.qty' => "reception_line",
208 'p.rowid' => 'product', 'p.ref' => 'product', 'p.label' => 'product', 'p.weight' => 'product', 'p.weight_units' => 'product', 'p.volume' => 'product', 'p.volume_units' => 'product'
209 );
210 if ($idcontacts && getDolGlobalString('RECEPTION_ADD_CONTACTS_IN_EXPORT')) {
211 $this->export_entities_array[$r] += array('sp.rowid' => 'contact', 'sp.lastname' => 'contact', 'sp.firstname' => 'contact', 'sp.note_public' => 'contact');
212 }
213 $this->export_dependencies_array[$r] = array('reception_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
214 if ($idcontacts && getDolGlobalString('RECEPTION_ADD_CONTACTS_IN_EXPORT')) {
215 $keyforselect = 'socpeople';
216 $keyforelement = 'contact';
217 $keyforaliasextra = 'extra3';
218 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
219 }
220 $keyforselect = 'reception';
221 $keyforelement = 'reception';
222 $keyforaliasextra = 'extra';
223 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
224 $keyforselect = 'receptiondet_batch';
225 $keyforelement = 'reception_line';
226 $keyforaliasextra = 'extra2';
227 include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
228
229 $this->export_sql_start[$r] = 'SELECT DISTINCT ';
230 $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'reception as c';
231 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'reception_extrafields as extra ON c.rowid = extra.fk_object,';
232 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'societe as s';
233 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
234 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
235 }
236 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
237 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
238 $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'receptiondet_batch as ed';
239 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'receptiondet_batch_extrafields as extra2 ON ed.rowid = extra2.fk_object';
240 $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
241 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
242 if ($idcontacts && getDolGlobalString('RECEPTION_ADD_CONTACTS_IN_EXPORT')) {
243 $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).')';
244 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople';
245 $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object';
246 }
247 $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_elementdet = cd.rowid';
248 $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')';
249 if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
250 $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : ((int) $user->id));
251 }
252 }
253
254
263 public function init($options = '')
264 {
265 global $conf, $langs;
266
267 // Permissions
268 $this->remove($options);
269
270 //ODT template
271 $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/reception/template_reception.odt';
272 $dirodt = DOL_DATA_ROOT.($conf->entity > 1 ? '/'.$conf->entity : '').'/doctemplates/reception';
273 $dest = $dirodt.'/template_reception.odt';
274
275 if (file_exists($src) && !file_exists($dest)) {
276 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
277 dol_mkdir($dirodt);
278 $result = dol_copy($src, $dest, '0', 0);
279 if ($result < 0) {
280 $langs->load("errors");
281 $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
282 return 0;
283 }
284 }
285
286 $sql = array();
287
288 $sql = array(
289 "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'reception' AND entity = ".((int) $conf->entity),
290 "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','reception',".((int) $conf->entity).")",
291 //"DELETE FROM ".MAIN_DB_PREFIX."const WHERE name IN ('STOCK_CALCULATE_ON_SUPPLIER_BILL', 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', 'STOCK_CALCULATE_ON_RECEPTION', 'STOCK_CALCULATE_ON_RECEPTION_CLOSE') AND entity = ".((int) $conf->entity),
292 //"INSERT INTO ".MAIN_DB_PREFIX."const (name, value, entity) VALUES ('STOCK_CALCULATE_ON_RECEPTION_CLOSE', 1, ".((int) $conf->entity).")"
293 );
294
295 return $this->_init($sql, $options);
296 }
297}
Class to manage predefined suppliers products.
Class DolibarrModules.
_init($array_sql, $options='')
Enables a module.
Class to describe and enable module Reception.
init($options='')
Function called when module is enabled.
__construct($db)
Constructor.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133