dolibarr  13.0.2
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  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
26 include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
27 
28 
33 {
39  public function __construct($db)
40  {
41  global $conf, $user;
42 
43  $this->db = $db;
44  $this->numero = 94160;
45 
46  $this->family = "srm";
47  $this->module_position = '40';
48  // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
49  $this->name = preg_replace('/^mod/i', '', get_class($this));
50  $this->description = "Gestion des réceptions fournisseurs";
51 
52  // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
53  $this->version = 'dolibarr';
54 
55  $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
56  $this->picto = "dollyrevert";
57 
58  // Data directories to create when module is enabled
59  $this->dirs = array("/reception/receipt",
60  "/reception/receipt/temp",
61  "/doctemplates/receptions"
62  );
63 
64  // Config pages
65  $this->config_page_url = array("reception_setup.php");
66 
67  // Dependencies
68  $this->depends = array("modFournisseur");
69  $this->requiredby = array();
70  $this->conflictwith = array();
71  $this->langfiles = array('receptions');
72 
73  // Constants
74  $this->const = array();
75  $r = 0;
76 
77  $this->const[$r][0] = "RECEPTION_ADDON_PDF";
78  $this->const[$r][1] = "chaine";
79  $this->const[$r][2] = "squille";
80  $this->const[$r][3] = 'Nom du gestionnaire de generation des bons receptions en PDF';
81  $this->const[$r][4] = 0;
82  $r++;
83 
84  $this->const[$r][0] = "RECEPTION_ADDON_NUMBER";
85  $this->const[$r][1] = "chaine";
86  $this->const[$r][2] = "mod_reception_beryl";
87  $this->const[$r][3] = 'Name for numbering manager for receptions';
88  $this->const[$r][4] = 0;
89  $r++;
90 
91  $this->const[$r][0] = "RECEPTION_ADDON_PDF_ODT_PATH";
92  $this->const[$r][1] = "chaine";
93  $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/receptions";
94  $this->const[$r][3] = "";
95  $this->const[$r][4] = 0;
96  $r++;
97 
98  $this->const[$r][0] = "MAIN_SUBMODULE_RECEPTION";
99  $this->const[$r][1] = "chaine";
100  $this->const[$r][2] = "1";
101  $this->const[$r][3] = "Enable receptions";
102  $this->const[$r][4] = 0;
103  $r++;
104 
105  // Boxes
106  $this->boxes = array();
107 
108  // Permissions
109  $this->rights = array();
110  $this->rights_class = 'reception';
111  $r = 0;
112 
113  $r++;
114  $this->rights[$r][0] = $this->numero.$r;
115  $this->rights[$r][1] = 'Lire les receptions';
116  $this->rights[$r][2] = 'r';
117  $this->rights[$r][3] = 0;
118  $this->rights[$r][4] = 'lire';
119 
120  $r++;
121  $this->rights[$r][0] = $this->numero.$r;
122  $this->rights[$r][1] = 'Creer modifier les receptions';
123  $this->rights[$r][2] = 'w';
124  $this->rights[$r][3] = 0;
125  $this->rights[$r][4] = 'creer';
126 
127  $r++;
128  $this->rights[$r][0] = $this->numero.$r;
129  $this->rights[$r][1] = 'Valider les receptions';
130  $this->rights[$r][2] = 'd';
131  $this->rights[$r][3] = 0;
132  $this->rights[$r][4] = 'reception_advance';
133  $this->rights[$r][5] = 'validate';
134 
135  $r++;
136  $this->rights[$r][0] = $this->numero.$r; // id de la permission
137  $this->rights[$r][1] = 'Envoyer les receptions aux clients'; // libelle de la permission
138  $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
139  $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
140  $this->rights[$r][4] = 'reception_advance';
141  $this->rights[$r][5] = 'send';
142 
143  $r++;
144  $this->rights[$r][0] = $this->numero.$r;
145  $this->rights[$r][1] = 'Exporter les receptions';
146  $this->rights[$r][2] = 'r';
147  $this->rights[$r][3] = 0;
148  $this->rights[$r][4] = 'reception';
149  $this->rights[$r][5] = 'export';
150 
151  $r++;
152  $this->rights[$r][0] = $this->numero.$r;
153  $this->rights[$r][1] = 'Supprimer les receptions';
154  $this->rights[$r][2] = 'd';
155  $this->rights[$r][3] = 0;
156  $this->rights[$r][4] = 'supprimer';
157 
158 
159  // Menus
160  //-------
161  $this->menu = 1; // This module add menu entries. They are coded into menu manager.
162 
163 
164  // Exports
165  //--------
166  $r = 0;
167 
168  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
169  $shipment = new CommandeFournisseur($this->db);
170  $contact_arrays = $shipment->liste_type_contact('external', '', 0, 0, '');
171  if (is_array($contact_arrays) && count($contact_arrays) > 0) {
172  $idcontacts = join(',', array_keys($shipment->liste_type_contact('external', '', 0, 0, '')));
173  } else {
174  $idcontacts = 0;
175  }
176 
177 
178  $r++;
179  $this->export_code[$r] = $this->rights_class.'_'.$r;
180  $this->export_label[$r] = 'Receptions'; // Translation key (used only if key ExportDataset_xxx_z not found)
181  $this->export_permission[$r] = array(array("reception", "reception", "export"));
182  $this->export_fields_array[$r] = array(
183  's.rowid'=>"IdCompany", 's.nom'=>'ThirdParty', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town',
184  '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',
185  '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',
186  'ed.comment'=>'Description', 'ed.qty'=>"Qty",
187  'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.weight'=>'ProductWeight', 'p.weight_units'=>'WeightUnits', 'p.volume'=>'ProductVolume', 'p.volume_units'=>'VolumeUnits'
188  );
189  if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) $this->export_fields_array[$r] += array('sp.rowid'=>'IdContact', 'sp.lastname'=>'Lastname', 'sp.firstname'=>'Firstname', 'sp.note_public'=>'NotePublic');
190  //$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");
191  $this->export_TypeFields_array[$r] = array(
192  's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text',
193  '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',
194  '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",
195  'ed.qty'=>"Numeric", 'd.nom'=>'Text'
196  );
197  $this->export_entities_array[$r] = array(
198  's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company',
199  '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',
200  '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",
201  'ed.rowid'=>'reception_line', 'ed.comment'=>'reception_line', 'ed.qty'=>"reception_line",
202  'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.weight'=>'product', 'p.weight_units'=>'product', 'p.volume'=>'product', 'p.volume_units'=>'product'
203  );
204  if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) $this->export_entities_array[$r] += array('sp.rowid'=>'contact', 'sp.lastname'=>'contact', 'sp.firstname'=>'contact', 'sp.note_public'=>'contact');
205  $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
206  if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT))
207  {
208  $keyforselect = 'socpeople'; $keyforelement = 'contact'; $keyforaliasextra = 'extra3';
209  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
210  }
211  $keyforselect = 'reception'; $keyforelement = 'reception'; $keyforaliasextra = 'extra';
212  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
213  $keyforselect = 'commande_fournisseur_dispatch'; $keyforelement = 'reception_line'; $keyforaliasextra = 'extra2';
214  include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
215 
216  $this->export_sql_start[$r] = 'SELECT DISTINCT ';
217  $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'reception as c';
218  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'reception_extrafields as extra ON c.rowid = extra.fk_object,';
219  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'societe as s';
220  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';
221  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
222  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
223  $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch as ed';
224  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch_extrafields as extra2 ON ed.rowid = extra2.fk_object';
225  $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
226  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
227  if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) {
228  $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.')';
229  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople';
230  $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object';
231  }
232  $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_commandefourndet = cd.rowid';
233  $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')';
234  if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
235  }
236 
237 
246  public function init($options = '')
247  {
248  global $conf, $langs;
249 
250  // Permissions
251  $this->remove($options);
252 
253  //ODT template
254  $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/reception/template_reception.odt';
255  $dirodt = DOL_DATA_ROOT.'/doctemplates/reception';
256  $dest = $dirodt.'/template_reception.odt';
257 
258  if (file_exists($src) && !file_exists($dest))
259  {
260  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
261  dol_mkdir($dirodt);
262  $result = dol_copy($src, $dest, 0, 0);
263  if ($result < 0)
264  {
265  $langs->load("errors");
266  $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
267  return 0;
268  }
269  }
270 
271  $sql = array();
272 
273  $sql = array(
274  "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'reception' AND entity = ".$conf->entity,
275  "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','reception',".$conf->entity.")",
276  );
277 
278  return $this->_init($sql, $options);
279  }
280 }
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
Definition: files.lib.php:663
Class DolibarrModules.
</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.
Definition: replenish.php:750
Class to describe and enable module Reception.
__construct($db)
Constructor.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
$conf db
API class for accounts.
Definition: inc.php:54
init($options= '')
Function called when module is enabled.
Class to manage predefined suppliers products.
_init($array_sql, $options= '')
Enables a module.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)