dolibarr  13.0.2
entrepot.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2008 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
7  * Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 
31 
35 class Entrepot extends CommonObject
36 {
40  public $element = 'stock';
41 
45  public $table_element = 'entrepot';
46 
50  public $picto = 'stock';
51 
55  public $ismultientitymanaged = 1;
56 
62  public $libelle;
63 
67  public $label;
68 
72  public $description;
73 
74  public $statut;
75 
79  public $lieu;
80 
84  public $address;
85 
89  public $zip;
90 
94  public $town;
95 
99  public $phone;
100 
104  public $fax;
105 
109  public $fk_parent;
110 
114  public $statuts = array();
115 
119  public $fields = array(
120  'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>10),
121  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>15),
122  'ref' =>array('type'=>'varchar(255)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>25, 'searchall'=>1),
123  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>30),
124  'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-2, 'position'=>35, 'searchall'=>1),
125  'lieu' =>array('type'=>'varchar(64)', 'label'=>'LocationSummary', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'showoncombobox'=>1, 'searchall'=>1),
126  'fk_parent' =>array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php:1:statut=1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ParentWarehouse', 'enabled'=>1, 'visible'=>-2, 'position'=>41),
127  'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-2, 'position'=>45, 'searchall'=>1),
128  'zip' =>array('type'=>'varchar(10)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'searchall'=>1),
129  'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-2, 'position'=>55, 'searchall'=>1),
130  'fk_departement' =>array('type'=>'sellist:c_departements:label:rowid::active=1', 'label'=>'State', 'enabled'=>1, 'visible'=>0, 'position'=>60),
131  'fk_pays' =>array('type'=>'sellist:c_country:label:rowid::active=1', 'label'=>'Country', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
132  'phone' =>array('type'=>'varchar(20)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>-2, 'position'=>70, 'searchall'=>1),
133  'fax' =>array('type'=>'varchar(20)', 'label'=>'Fax', 'enabled'=>1, 'visible'=>-2, 'position'=>75, 'searchall'=>1),
134  //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
135  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300),
136  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>301),
137  //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
138  //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
139  'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>500),
140  );
141 
145  const STATUS_CLOSED = 0;
146 
150  const STATUS_OPEN_ALL = 1;
151 
156 
157 
163  public function __construct($db)
164  {
165  global $conf;
166  $this->db = $db;
167 
168  $this->statuts[self::STATUS_CLOSED] = 'Closed2';
169  if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
170  $this->statuts[self::STATUS_OPEN_ALL] = 'OpenAll';
171  $this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
172  } else {
173  $this->statuts[self::STATUS_OPEN_ALL] = 'Opened';
174  }
175  }
176 
183  public function create($user)
184  {
185  global $conf;
186 
187  $error = 0;
188 
189  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
190 
191  // Error if label not defined
192  if ($this->label == '') {
193  $this->error = "ErrorFieldRequired";
194  return 0;
195  }
196 
197  $now = dol_now();
198 
199  $this->db->begin();
200 
201  $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (ref, entity, datec, fk_user_author, fk_parent)";
202  $sql .= " VALUES ('".$this->db->escape($this->label)."', ".$conf->entity.", '".$this->db->idate($now)."', ".$user->id.", ".($this->fk_parent > 0 ? $this->fk_parent : "NULL").")";
203 
204  dol_syslog(get_class($this)."::create", LOG_DEBUG);
205  $result = $this->db->query($sql);
206  if ($result)
207  {
208  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot");
209  if ($id > 0)
210  {
211  $this->id = $id;
212 
213  if (!$error)
214  {
215  $result = $this->update($id, $user);
216  if ($result <= 0)
217  {
218  $error++;
219  }
220  }
221 
222  // Actions on extra fields
223  if (!$error)
224  {
225  if (!$error)
226  {
227  $result = $this->insertExtraFields();
228  if ($result < 0)
229  {
230  $error++;
231  }
232  }
233  }
234 
235  if (!$error)
236  {
237  $this->db->commit();
238  return $id;
239  } else {
240  dol_syslog(get_class($this)."::create return -3");
241  $this->db->rollback();
242  return -3;
243  }
244  } else {
245  $this->error = "Failed to get insert id";
246  dol_syslog(get_class($this)."::create return -2");
247  return -2;
248  }
249  } else {
250  $this->error = $this->db->error();
251  dol_syslog(get_class($this)."::create Error ".$this->db->error());
252  $this->db->rollback();
253  return -1;
254  }
255  }
256 
264  public function update($id, $user)
265  {
266  global $conf;
267 
268  $error = 0;
269 
270  if (empty($id)) $id = $this->id;
271  if (empty($this->label)) $this->label = $this->libelle; // For backward compatibility
272 
273  // Check if new parent is already a child of current warehouse
274  if (!empty($this->fk_parent))
275  {
276  $TChildWarehouses = array($id);
277  $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
278  if (in_array($this->fk_parent, $TChildWarehouses))
279  {
280  $this->error = 'ErrorCannotAddThisParentWarehouse';
281  return -2;
282  }
283  }
284 
285  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
286 
287  $this->description = trim($this->description);
288 
289  $this->lieu = trim($this->lieu);
290 
291  $this->address = trim($this->address);
292  $this->zip = trim($this->zip);
293  $this->town = trim($this->town);
294  $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
295 
296  $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot ";
297  $sql .= " SET ref = '".$this->db->escape($this->label)."'";
298  $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
299  $sql .= ", description = '".$this->db->escape($this->description)."'";
300  $sql .= ", statut = ".$this->statut;
301  $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
302  $sql .= ", address = '".$this->db->escape($this->address)."'";
303  $sql .= ", zip = '".$this->db->escape($this->zip)."'";
304  $sql .= ", town = '".$this->db->escape($this->town)."'";
305  $sql .= ", fk_pays = ".$this->country_id;
306  $sql .= ", phone = '".$this->db->escape($this->phone)."'";
307  $sql .= ", fax = '".$this->db->escape($this->fax)."'";
308  $sql .= " WHERE rowid = ".$id;
309 
310  $this->db->begin();
311 
312  dol_syslog(get_class($this)."::update", LOG_DEBUG);
313  $resql = $this->db->query($sql);
314 
315  if (!$resql) {
316  $error++;
317  $this->errors[] = "Error ".$this->db->lasterror();
318  }
319 
320  if (!$error) {
321  $result = $this->insertExtraFields();
322  if ($result < 0)
323  {
324  $error++;
325  }
326  }
327 
328  if (!$error) {
329  $this->db->commit();
330  return 1;
331  } else {
332  $this->db->rollback();
333  $this->error = $this->db->lasterror();
334  return -1;
335  }
336  }
337 
338 
346  public function delete($user, $notrigger = 0)
347  {
348  global $conf;
349 
350  $error = 0;
351 
352  dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
353 
354  $this->db->begin();
355 
356  if (!$error && empty($notrigger))
357  {
358  // Call trigger
359  $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
360  if ($result < 0) { $error++; }
361  // End call triggers
362  }
363 
364  $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties');
365  foreach ($elements as $table)
366  {
367  if (!$error)
368  {
369  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table;
370  $sql .= " WHERE fk_entrepot = ".$this->id;
371 
372  $result = $this->db->query($sql);
373  if (!$result)
374  {
375  $error++;
376  $this->errors[] = $this->db->lasterror();
377  }
378  }
379  }
380 
381  // Removed extrafields
382  if (!$error)
383  {
384  if (!$error)
385  {
386  $result = $this->deleteExtraFields();
387  if ($result < 0)
388  {
389  $error++;
390  dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
391  }
392  }
393  }
394 
395  if (!$error)
396  {
397  $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot";
398  $sql .= " WHERE rowid = ".$this->id;
399  $resql1 = $this->db->query($sql);
400  if (!$resql1)
401  {
402  $error++;
403  $this->errors[] = $this->db->lasterror();
404  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
405  }
406  }
407 
408  if (!$error)
409  {
410  // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
411  $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)";
412  $resql2 = $this->db->query($sql);
413  if (!$resql2)
414  {
415  $error++;
416  $this->errors[] = $this->db->lasterror();
417  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
418  }
419  }
420 
421  if (!$error)
422  {
423  $this->db->commit();
424  return 1;
425  } else {
426  $this->db->rollback();
427  return -1;
428  }
429  }
430 
431 
439  public function fetch($id, $ref = '')
440  {
441  global $conf;
442 
443  dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
444 
445  // Check parameters
446  if (!$id && !$ref)
447  {
448  $this->error = 'ErrorWrongParameters';
449  dol_syslog(get_class($this)."::fetch ".$this->error);
450  return -1;
451  }
452 
453  $sql = "SELECT rowid, entity, fk_parent, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
454  $sql .= " model_pdf, import_key";
455  $sql .= " FROM ".MAIN_DB_PREFIX."entrepot";
456  if ($id)
457  {
458  $sql .= " WHERE rowid = '".$id."'";
459  } else {
460  $sql .= " WHERE entity = ".$conf->entity;
461  if ($ref) $sql .= " AND ref = '".$this->db->escape($ref)."'";
462  }
463 
464  $result = $this->db->query($sql);
465  if ($result)
466  {
467  if ($this->db->num_rows($result) > 0)
468  {
469  $obj = $this->db->fetch_object($result);
470 
471  $this->id = $obj->rowid;
472  $this->entity = $obj->entity;
473  $this->fk_parent = $obj->fk_parent;
474  $this->ref = $obj->label;
475  $this->label = $obj->label;
476  $this->libelle = $obj->label; // deprecated
477  $this->description = $obj->description;
478  $this->statut = $obj->statut;
479  $this->lieu = $obj->lieu;
480  $this->address = $obj->address;
481  $this->zip = $obj->zip;
482  $this->town = $obj->town;
483  $this->country_id = $obj->country_id;
484  $this->phone = $obj->phone;
485  $this->fax = $obj->fax;
486 
487  $this->model_pdf = $obj->model_pdf;
488  $this->import_key = $obj->import_key;
489 
490  // Retrieve all extrafield
491  // fetch optionals attributes and labels
492  $this->fetch_optionals();
493 
494  include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
495  $tmp = getCountry($this->country_id, 'all');
496  $this->country = $tmp['label'];
497  $this->country_code = $tmp['code'];
498 
499  return 1;
500  } else {
501  $this->error = "Record Not Found";
502  return 0;
503  }
504  } else {
505  $this->error = $this->db->error();
506  return -1;
507  }
508  }
509 
510 
517  public function info($id)
518  {
519  $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
520  $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
521  $sql .= " WHERE e.rowid = ".$id;
522 
523  dol_syslog(get_class($this)."::info", LOG_DEBUG);
524  $result = $this->db->query($sql);
525  if ($result)
526  {
527  if ($this->db->num_rows($result))
528  {
529  $obj = $this->db->fetch_object($result);
530 
531  $this->id = $obj->rowid;
532 
533  if ($obj->fk_user_author) {
534  $cuser = new User($this->db);
535  $cuser->fetch($obj->fk_user_author);
536  $this->user_creation = $cuser;
537  }
538 
539  if ($obj->fk_user_valid) {
540  $vuser = new User($this->db);
541  $vuser->fetch($obj->fk_user_valid);
542  $this->user_validation = $vuser;
543  }
544 
545  $this->date_creation = $this->db->jdate($obj->datec);
546  $this->date_modification = $this->db->jdate($obj->datem);
547  }
548 
549  $this->db->free($result);
550  } else {
551  dol_print_error($this->db);
552  }
553  }
554 
555 
556  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
563  public function list_array($status = 1)
564  {
565  // phpcs:enable
566  $liste = array();
567 
568  $sql = "SELECT rowid, ref as label";
569  $sql .= " FROM ".MAIN_DB_PREFIX."entrepot";
570  $sql .= " WHERE entity IN (".getEntity('stock').")";
571  $sql .= " AND statut = ".$status;
572 
573  $result = $this->db->query($sql);
574  $i = 0;
575  $num = $this->db->num_rows($result);
576  if ($result)
577  {
578  while ($i < $num)
579  {
580  $row = $this->db->fetch_row($result);
581  $liste[$row[0]] = $row[1];
582  $i++;
583  }
584  $this->db->free($result);
585  }
586  return $liste;
587  }
588 
589  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
595  public function nb_different_products()
596  {
597  // phpcs:enable
598  $ret = array();
599 
600  $sql = "SELECT count(distinct p.rowid) as nb";
601  $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
602  $sql .= ", ".MAIN_DB_PREFIX."product as p";
603  $sql .= " WHERE ps.fk_entrepot = ".$this->id;
604  $sql .= " AND ps.fk_product = p.rowid";
605 
606  //print $sql;
607  $result = $this->db->query($sql);
608  if ($result)
609  {
610  $obj = $this->db->fetch_object($result);
611  $ret['nb'] = $obj->nb;
612  $this->db->free($result);
613  } else {
614  $this->error = $this->db->lasterror();
615  return -1;
616  }
617 
618  return $ret;
619  }
620 
621  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
627  public function nb_products()
628  {
629  // phpcs:enable
630  $ret = array();
631 
632  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
633  $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
634  $sql .= ", ".MAIN_DB_PREFIX."product as p";
635  $sql .= " WHERE ps.fk_entrepot = ".$this->id;
636  $sql .= " AND ps.fk_product = p.rowid";
637 
638  //print $sql;
639  $result = $this->db->query($sql);
640  if ($result)
641  {
642  $obj = $this->db->fetch_object($result);
643  $ret['nb'] = $obj->nb;
644  $ret['value'] = $obj->value;
645  $this->db->free($result);
646  } else {
647  $this->error = $this->db->lasterror();
648  return -1;
649  }
650 
651  return $ret;
652  }
653 
660  public function getLibStatut($mode = 0)
661  {
662  return $this->LibStatut($this->statut, $mode);
663  }
664 
665  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
673  public function LibStatut($status, $mode = 0)
674  {
675  // phpcs:enable
676  global $langs;
677 
678  $statusType = 'status5';
679  if ($status > 0) $statusType = 'status4';
680 
681  $langs->load('stocks');
682  $label = $langs->trans($this->statuts[$status]);
683  $labelshort = $langs->trans($this->statuts[$status]);
684 
685  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
686  }
687 
688 
698  public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0)
699  {
700  global $conf, $langs, $hookmanager;
701  $langs->load("stocks");
702 
703  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
704 
705  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0;
706 
707  $result = '';
708 
709  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
710  if (isset($this->statut)) {
711  $label .= ' '.$this->getLibStatut(5);
712  }
713  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref);
714  if (!empty($this->lieu)) {
715  $label .= '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
716  }
717 
718  $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
719 
720  $linkclose = '';
721  if (empty($notooltip))
722  {
723  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
724  {
725  $label = $langs->trans("Warehouse");
726  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
727  }
728  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
729  $linkclose .= ' class="classfortooltip"';
730  }
731 
732  $linkstart = '<a href="'.$url.'"';
733  $linkstart .= $linkclose.'>';
734  $linkend = '</a>';
735 
736  $result .= $linkstart;
737  if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
738  if ($withpicto != 2) $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
739  $result .= $linkend;
740 
741  global $action;
742  $hookmanager->initHooks(array('warehousedao'));
743  $parameters = array('id'=>$this->id, 'getnomurl'=>$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip'=> $notooltip);
744  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
745  if ($reshook > 0) {
746  $result = $hookmanager->resPrint;
747  } else {
748  $result .= $hookmanager->resPrint;
749  }
750 
751  return $result;
752  }
753 
761  public function initAsSpecimen()
762  {
763  global $user, $langs, $conf, $mysoc;
764 
765  $now = dol_now();
766 
767  // Initialize parameters
768  $this->id = 0;
769  $this->label = 'WAREHOUSE SPECIMEN';
770  $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
771  $this->statut = 1;
772  $this->specimen = 1;
773 
774  $this->lieu = 'Location test';
775  $this->address = '21 jump street';
776  $this->zip = '99999';
777  $this->town = 'MyTown';
778  $this->country_id = 1;
779  $this->country_code = 'FR';
780  }
781 
782  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
788  public function get_full_arbo()
789  {
790  // phpcs:enable
791  global $user, $langs, $conf;
792 
793  $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
794 
795  $protection = 100; // We limit depth of warehouses to 100
796 
797  $warehousetmp = new Entrepot($this->db);
798 
799  $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
800  $i = 0;
801  while ($parentid > 0 && $i < $protection)
802  {
803  $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'entrepot WHERE rowid = '.$parentid;
804  $resql = $this->db->query($sql);
805  if ($resql)
806  {
807  $objarbo = $this->db->fetch_object($resql);
808  if ($objarbo)
809  {
810  $warehousetmp->fetch($parentid);
811  $TArbo[] = $warehousetmp->label;
812  $parentid = $objarbo->fk_parent;
813  } else break;
814  } else dol_print_error($this->db);
815 
816  $i++;
817  }
818 
819  return implode(' >> ', array_reverse($TArbo));
820  }
821 
822  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
830  public function get_children_warehouses($id, &$TChildWarehouses)
831  {
832  // phpcs:enable
833 
834  $sql = 'SELECT rowid
835  FROM '.MAIN_DB_PREFIX.'entrepot
836  WHERE fk_parent = '.$id;
837 
838  $resql = $this->db->query($sql);
839  if ($resql) {
840  while ($res = $this->db->fetch_object($resql)) {
841  $TChildWarehouses[] = $res->rowid;
842  $this->get_children_warehouses($res->rowid, $TChildWarehouses);
843  }
844  }
845 
846  return $TChildWarehouses;
847  }
848 
859  public function generateDocument($modele, $outputlangs = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
860  {
861  global $conf, $user, $langs;
862 
863  $langs->load("stocks");
864  $outputlangs->load("products");
865 
866  if (!dol_strlen($modele)) {
867  $modele = 'standard';
868 
869  if ($this->model_pdf) {
870  $modele = $this->model_pdf;
871  } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
872  $modele = $conf->global->STOCK_ADDON_PDF;
873  }
874  }
875 
876  $modelpath = "core/modules/stock/doc/";
877 
878  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
879  }
880 
891  public function setCategories($categories)
892  {
893  $type_categ = Categorie::TYPE_WAREHOUSE;
894 
895  // Handle single category
896  if (!is_array($categories)) {
897  $categories = array($categories);
898  }
899 
900  // Get current categories
901  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
902  $c = new Categorie($this->db);
903  $existing = $c->containing($this->id, $type_categ, 'id');
904 
905  // Diff
906  if (is_array($existing)) {
907  $to_del = array_diff($existing, $categories);
908  $to_add = array_diff($categories, $existing);
909  } else {
910  $to_del = array(); // Nothing to delete
911  $to_add = $categories;
912  }
913 
914  // Process
915  foreach ($to_del as $del) {
916  if ($c->fetch($del) > 0) {
917  $c->del_type($this, $type_categ);
918  }
919  }
920  foreach ($to_add as $add) {
921  if ($c->fetch($add) > 0) {
922  $c->add_type($this, $type_categ);
923  }
924  }
925 
926  return;
927  }
928 }
const STATUS_CLOSED
Warehouse closed, inactive.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
Definition: list.php:632
nb_products()
Return stock and value of warehosue.
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
</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
getLibStatut($mode=0)
Return label of status of object.
get_children_warehouses($id, &$TChildWarehouses)
Return array of children warehouses ids from $id warehouse (recursive function)
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
get_full_arbo()
Return full path to current warehouse.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
getNomUrl($withpicto=0, $option= '', $showfullpath=0, $notooltip=0)
Return clickable name (possibility with the pictogram)
initAsSpecimen()
Initialise an instance with random values.
$conf db
API class for accounts.
Definition: inc.php:54
generateDocument($modele, $outputlangs= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
info($id)
Load warehouse info data.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
__construct($db)
Constructor.
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
Class to manage categories.
fetch($id, $ref= '')
Load warehouse data.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
setCategories($categories)
Sets object to supplied categories.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this-&gt;array_options This method is in most cases call...
list_array($status=1)
Return list of all warehouses.
LibStatut($status, $mode=0)
Return label of a given status.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
nb_different_products()
Return number of unique different product into a warehouse.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
update($id, $user)
Update properties of a warehouse.
create($user)
Creation d&#39;un entrepot en base.
Class to manage warehouses.