dolibarr  16.0.5
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 $fk_project;
115 
119  public $statuts = array();
120 
124  public $fields = array(
125  'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>10),
126  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>15),
127  'ref' =>array('type'=>'varchar(255)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'showoncombobox'=>1, 'position'=>25, 'searchall'=>1),
128  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>30),
129  'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-2, 'position'=>35, 'searchall'=>1),
130  'lieu' =>array('type'=>'varchar(64)', 'label'=>'LocationSummary', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'showoncombobox'=>2, 'searchall'=>1),
131  '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),
132  'fk_project' =>array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Project', 'enabled'=>'$conf->project->enabled', 'visible'=>-1, 'position'=>25),
133  'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-2, 'position'=>45, 'searchall'=>1),
134  'zip' =>array('type'=>'varchar(10)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'searchall'=>1),
135  'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-2, 'position'=>55, 'searchall'=>1),
136  'fk_departement' =>array('type'=>'sellist:c_departements:label:rowid::active=1', 'label'=>'State', 'enabled'=>1, 'visible'=>0, 'position'=>60),
137  'fk_pays' =>array('type'=>'sellist:c_country:label:rowid::active=1', 'label'=>'Country', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
138  'phone' =>array('type'=>'varchar(20)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>-2, 'position'=>70, 'searchall'=>1),
139  'fax' =>array('type'=>'varchar(20)', 'label'=>'Fax', 'enabled'=>1, 'visible'=>-2, 'position'=>75, 'searchall'=>1),
140  //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
141  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300),
142  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>301),
143  //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
144  //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
145  'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>500),
146  );
147 
151  const STATUS_CLOSED = 0;
152 
156  const STATUS_OPEN_ALL = 1;
157 
162 
163 
169  public function __construct($db)
170  {
171  global $conf;
172  $this->db = $db;
173 
174  $this->statuts[self::STATUS_CLOSED] = 'Closed2';
175  if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
176  $this->statuts[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
177  $this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
178  } else {
179  $this->statuts[self::STATUS_OPEN_ALL] = 'Opened';
180  }
181  }
182 
189  public function create($user)
190  {
191  global $conf;
192 
193  $error = 0;
194 
195  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
196 
197  // Error if label not defined
198  if ($this->label == '') {
199  $this->error = "ErrorFieldRequired";
200  return 0;
201  }
202 
203  $now = dol_now();
204 
205  $this->db->begin();
206 
207  $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
208  $sql .= " VALUES ('".$this->db->escape($this->label)."', ".((int) $conf->entity).", '".$this->db->idate($now)."', ".((int) $user->id).", ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "NULL").", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "NULL").")";
209 
210  dol_syslog(get_class($this)."::create", LOG_DEBUG);
211  $result = $this->db->query($sql);
212  if ($result) {
213  $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
214  if ($id > 0) {
215  $this->id = $id;
216 
217  if (!$error) {
218  $result = $this->update($id, $user);
219  if ($result <= 0) {
220  $error++;
221  }
222  }
223 
224  // Actions on extra fields
225  if (!$error) {
226  if (!$error) {
227  $result = $this->insertExtraFields();
228  if ($result < 0) {
229  $error++;
230  }
231  }
232  }
233 
234  if (!$error) {
235  $this->db->commit();
236  return $id;
237  } else {
238  dol_syslog(get_class($this)."::create return -3");
239  $this->db->rollback();
240  return -3;
241  }
242  } else {
243  $this->error = "Failed to get insert id";
244  dol_syslog(get_class($this)."::create return -2");
245  return -2;
246  }
247  } else {
248  $this->error = $this->db->error();
249  dol_syslog(get_class($this)."::create Error ".$this->db->error());
250  $this->db->rollback();
251  return -1;
252  }
253  }
254 
262  public function update($id, $user)
263  {
264  global $conf;
265 
266  $error = 0;
267 
268  if (empty($id)) {
269  $id = $this->id;
270  }
271  if (empty($this->label)) {
272  $this->label = $this->libelle; // For backward compatibility
273  }
274 
275  // Check if new parent is already a child of current warehouse
276  if (!empty($this->fk_parent)) {
277  $TChildWarehouses = array($id);
278  $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
279  if (in_array($this->fk_parent, $TChildWarehouses)) {
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 ".$this->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 .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
300  $sql .= ", description = '".$this->db->escape($this->description)."'";
301  $sql .= ", statut = ".((int) $this->statut);
302  $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
303  $sql .= ", address = '".$this->db->escape($this->address)."'";
304  $sql .= ", zip = '".$this->db->escape($this->zip)."'";
305  $sql .= ", town = '".$this->db->escape($this->town)."'";
306  $sql .= ", fk_pays = ".((int) $this->country_id);
307  $sql .= ", phone = '".$this->db->escape($this->phone)."'";
308  $sql .= ", fax = '".$this->db->escape($this->fax)."'";
309  $sql .= " WHERE rowid = ".((int) $id);
310 
311  $this->db->begin();
312 
313  dol_syslog(get_class($this)."::update", LOG_DEBUG);
314  $resql = $this->db->query($sql);
315 
316  if (!$resql) {
317  $error++;
318  $this->errors[] = "Error ".$this->db->lasterror();
319  }
320 
321  if (!$error) {
322  $result = $this->insertExtraFields();
323  if ($result < 0) {
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  // Call trigger
358  $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
359  if ($result < 0) {
360  $error++;
361  }
362  // End call triggers
363  }
364 
365  $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties');
366  foreach ($elements as $table) {
367  if (!$error) {
368  $sql = "DELETE FROM ".$this->db->prefix().$table;
369  $sql .= " WHERE fk_entrepot = ".((int) $this->id);
370 
371  $result = $this->db->query($sql);
372  if (!$result) {
373  $error++;
374  $this->errors[] = $this->db->lasterror();
375  }
376  }
377  }
378 
379  // Removed extrafields
380  if (!$error) {
381  if (!$error) {
382  $result = $this->deleteExtraFields();
383  if ($result < 0) {
384  $error++;
385  dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
386  }
387  }
388  }
389 
390  if (!$error) {
391  $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
392  $sql .= " WHERE rowid = ".((int) $this->id);
393  $resql1 = $this->db->query($sql);
394  if (!$resql1) {
395  $error++;
396  $this->errors[] = $this->db->lasterror();
397  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
398  }
399  }
400 
401  if (!$error) {
402  // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
403  $sql = "UPDATE ".$this->db->prefix()."product as p SET stock = (SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)";
404  $resql2 = $this->db->query($sql);
405  if (!$resql2) {
406  $error++;
407  $this->errors[] = $this->db->lasterror();
408  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
409  }
410  }
411 
412  if (!$error) {
413  $this->db->commit();
414  return 1;
415  } else {
416  $this->db->rollback();
417  return -1;
418  }
419  }
420 
421 
429  public function fetch($id, $ref = '')
430  {
431  global $conf;
432 
433  dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
434 
435  // Check parameters
436  if (!$id && !$ref) {
437  $this->error = 'ErrorWrongParameters';
438  dol_syslog(get_class($this)."::fetch ".$this->error);
439  return -1;
440  }
441 
442  $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
443  $sql .= " model_pdf, import_key";
444  $sql .= " FROM ".$this->db->prefix()."entrepot";
445  if ($id) {
446  $sql .= " WHERE rowid = ".((int) $id);
447  } else {
448  $sql .= " WHERE entity IN (".getEntity('stock').")";
449  if ($ref) {
450  $sql .= " AND ref = '".$this->db->escape($ref)."'";
451  }
452  }
453 
454  $result = $this->db->query($sql);
455  if ($result) {
456  if ($this->db->num_rows($result) > 0) {
457  $obj = $this->db->fetch_object($result);
458 
459  $this->id = $obj->rowid;
460  $this->entity = $obj->entity;
461  $this->fk_parent = $obj->fk_parent;
462  $this->fk_project = $obj->fk_project;
463  $this->ref = $obj->label;
464  $this->label = $obj->label;
465  $this->libelle = $obj->label; // deprecated
466  $this->description = $obj->description;
467  $this->statut = $obj->statut;
468  $this->lieu = $obj->lieu;
469  $this->address = $obj->address;
470  $this->zip = $obj->zip;
471  $this->town = $obj->town;
472  $this->country_id = $obj->country_id;
473  $this->phone = $obj->phone;
474  $this->fax = $obj->fax;
475 
476  $this->model_pdf = $obj->model_pdf;
477  $this->import_key = $obj->import_key;
478 
479  // Retrieve all extrafield
480  // fetch optionals attributes and labels
481  $this->fetch_optionals();
482 
483  include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
484  $tmp = getCountry($this->country_id, 'all');
485  $this->country = $tmp['label'];
486  $this->country_code = $tmp['code'];
487 
488  return 1;
489  } else {
490  $this->error = "Record Not Found";
491  return 0;
492  }
493  } else {
494  $this->error = $this->db->error();
495  return -1;
496  }
497  }
498 
499 
506  public function info($id)
507  {
508  $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
509  $sql .= " FROM ".$this->db->prefix()."entrepot as e";
510  $sql .= " WHERE e.rowid = ".((int) $id);
511 
512  dol_syslog(get_class($this)."::info", LOG_DEBUG);
513  $result = $this->db->query($sql);
514  if ($result) {
515  if ($this->db->num_rows($result)) {
516  $obj = $this->db->fetch_object($result);
517 
518  $this->id = $obj->rowid;
519 
520  $this->user_creation_id = $obj->fk_user_author;
521  $this->date_creation = $this->db->jdate($obj->datec);
522  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
523  }
524 
525  $this->db->free($result);
526  } else {
527  dol_print_error($this->db);
528  }
529  }
530 
531 
532  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
539  public function list_array($status = 1)
540  {
541  // phpcs:enable
542  $liste = array();
543 
544  $sql = "SELECT rowid, ref as label";
545  $sql .= " FROM ".$this->db->prefix()."entrepot";
546  $sql .= " WHERE entity IN (".getEntity('stock').")";
547  $sql .= " AND statut = ".((int) $status);
548 
549  $result = $this->db->query($sql);
550  $i = 0;
551  $num = $this->db->num_rows($result);
552  if ($result) {
553  while ($i < $num) {
554  $row = $this->db->fetch_row($result);
555  $liste[$row[0]] = $row[1];
556  $i++;
557  }
558  $this->db->free($result);
559  }
560  return $liste;
561  }
562 
563  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
569  public function nb_different_products()
570  {
571  // phpcs:enable
572  $ret = array();
573 
574  $sql = "SELECT count(distinct p.rowid) as nb";
575  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
576  $sql .= ", ".$this->db->prefix()."product as p";
577  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
578  $sql .= " AND ps.fk_product = p.rowid";
579 
580  //print $sql;
581  $result = $this->db->query($sql);
582  if ($result) {
583  $obj = $this->db->fetch_object($result);
584  $ret['nb'] = $obj->nb;
585  $this->db->free($result);
586  } else {
587  $this->error = $this->db->lasterror();
588  return -1;
589  }
590 
591  return $ret;
592  }
593 
594  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
600  public function nb_products()
601  {
602  global $conf;
603  // phpcs:enable
604  $ret = array();
605 
606  //For MultiCompany PMP per entity
607  $separatedPMP = false;
608  if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
609  $separatedPMP = true;
610  }
611 
612  if ($separatedPMP) {
613  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
614  } else {
615  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
616  }
617  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
618  $sql .= ", ".$this->db->prefix()."product as p";
619  if ($separatedPMP) {
620  $sql .= ", ".$this->db->prefix()."product_perentity as pa";
621  }
622  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
623  if ($separatedPMP) {
624  $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
625  }
626  $sql .= " AND ps.fk_product = p.rowid";
627  //print $sql;
628  $result = $this->db->query($sql);
629  if ($result) {
630  $obj = $this->db->fetch_object($result);
631  $ret['nb'] = $obj->nb;
632  $ret['value'] = $obj->value;
633  $this->db->free($result);
634  } else {
635  $this->error = $this->db->lasterror();
636  return -1;
637  }
638 
639  return $ret;
640  }
641 
648  public function getLibStatut($mode = 0)
649  {
650  return $this->LibStatut($this->statut, $mode);
651  }
652 
653  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
661  public function LibStatut($status, $mode = 0)
662  {
663  // phpcs:enable
664  global $langs;
665 
666  $statusType = 'status5';
667  if ($status > 0) {
668  $statusType = 'status4';
669  }
670 
671  $langs->load('stocks');
672  $label = $langs->transnoentitiesnoconv($this->statuts[$status]);
673  $labelshort = $langs->transnoentitiesnoconv($this->statuts[$status]);
674 
675  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
676  }
677 
678 
690  public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
691  {
692  global $conf, $langs, $hookmanager;
693  $langs->load("stocks");
694 
695  if (!empty($conf->dol_no_mouse_hover)) {
696  $notooltip = 1; // Force disable tooltips
697  }
698 
699  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
700  $withpicto = 0;
701  }
702 
703  $result = '';
704 
705  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
706  if (isset($this->statut)) {
707  $label .= ' '.$this->getLibStatut(5);
708  }
709  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref);
710  if (!empty($this->lieu)) {
711  $label .= '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
712  }
713 
714  $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
715 
716  if ($option != 'nolink') {
717  // Add param to save lastsearch_values or not
718  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
719  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
720  $add_save_lastsearch_values = 1;
721  }
722  if ($add_save_lastsearch_values) {
723  $url .= '&save_lastsearch_values=1';
724  }
725  }
726 
727  $linkclose = '';
728  if (empty($notooltip)) {
729  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
730  $label = $langs->trans("Warehouse");
731  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
732  }
733  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
734  $linkclose .= ' class="classfortooltip"';
735  }
736 
737  $linkstart = '<a href="'.$url.'"';
738  $linkstart .= $linkclose.'>';
739  $linkend = '</a>';
740 
741  $result .= $linkstart;
742  if ($withpicto) {
743  $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);
744  }
745  if ($withpicto != 2) {
746  $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
747  }
748  $result .= $linkend;
749 
750  global $action;
751  $hookmanager->initHooks(array('warehousedao'));
752  $parameters = array('id'=>$this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip'=> $notooltip);
753  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
754  if ($reshook > 0) {
755  $result = $hookmanager->resPrint;
756  } else {
757  $result .= $hookmanager->resPrint;
758  }
759 
760  return $result;
761  }
762 
770  public function initAsSpecimen()
771  {
772  global $user, $langs, $conf, $mysoc;
773 
774  $now = dol_now();
775 
776  // Initialize parameters
777  $this->id = 0;
778  $this->label = 'WAREHOUSE SPECIMEN';
779  $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
780  $this->statut = 1;
781  $this->specimen = 1;
782 
783  $this->lieu = 'Location test';
784  $this->address = '21 jump street';
785  $this->zip = '99999';
786  $this->town = 'MyTown';
787  $this->country_id = 1;
788  $this->country_code = 'FR';
789  }
790 
791  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
797  public function get_full_arbo()
798  {
799  // phpcs:enable
800  global $user, $langs, $conf;
801 
802  $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
803 
804  $protection = 100; // We limit depth of warehouses to 100
805 
806  $warehousetmp = new Entrepot($this->db);
807 
808  $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
809  $i = 0;
810  while ($parentid > 0 && $i < $protection) {
811  $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid);
812  $resql = $this->db->query($sql);
813  if ($resql) {
814  $objarbo = $this->db->fetch_object($resql);
815  if ($objarbo) {
816  $warehousetmp->fetch($parentid);
817  $TArbo[] = $warehousetmp->label;
818  $parentid = $objarbo->fk_parent;
819  } else {
820  break;
821  }
822  } else {
823  dol_print_error($this->db);
824  }
825 
826  $i++;
827  }
828 
829  return implode(' >> ', array_reverse($TArbo));
830  }
831 
832  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840  public function get_children_warehouses($id, &$TChildWarehouses)
841  {
842  // phpcs:enable
843 
844  $sql = "SELECT rowid
845  FROM ".$this->db->prefix()."entrepot
846  WHERE fk_parent = ".((int) $id);
847 
848  $resql = $this->db->query($sql);
849  if ($resql) {
850  while ($res = $this->db->fetch_object($resql)) {
851  $TChildWarehouses[] = $res->rowid;
852  $this->get_children_warehouses($res->rowid, $TChildWarehouses);
853  }
854  }
855 
856  return $TChildWarehouses;
857  }
858 
869  public function generateDocument($modele, $outputlangs = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
870  {
871  global $conf, $user, $langs;
872 
873  $langs->load("stocks");
874  $outputlangs->load("products");
875 
876  if (!dol_strlen($modele)) {
877  $modele = 'standard';
878 
879  if ($this->model_pdf) {
880  $modele = $this->model_pdf;
881  } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
882  $modele = $conf->global->STOCK_ADDON_PDF;
883  }
884  }
885 
886  $modelpath = "core/modules/stock/doc/";
887 
888  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
889  }
890 
901  public function setCategories($categories)
902  {
903  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
904  return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
905  }
906 }
Entrepot\get_full_arbo
get_full_arbo()
Return full path to current warehouse.
Definition: entrepot.class.php:797
db
$conf db
API class for accounts.
Definition: inc.php:41
Entrepot\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: entrepot.class.php:901
Entrepot\nb_products
nb_products()
Return stock and value of warehosue.
Definition: entrepot.class.php:600
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
Entrepot\generateDocument
generateDocument($modele, $outputlangs='', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
Definition: entrepot.class.php:869
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Entrepot\STATUS_OPEN_INTERNAL
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
Definition: entrepot.class.php:161
Entrepot\list_array
list_array($status=1)
Return list of all warehouses.
Definition: entrepot.class.php:539
ref
$object ref
Definition: info.php:77
Entrepot\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: entrepot.class.php:770
Entrepot\update
update($id, $user)
Update properties of a warehouse.
Definition: entrepot.class.php:262
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Entrepot\nb_different_products
nb_different_products()
Return number of unique different product into a warehouse.
Definition: entrepot.class.php:569
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
Entrepot\STATUS_OPEN_ALL
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
Definition: entrepot.class.php:156
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5406
Entrepot\getLibStatut
getLibStatut($mode=0)
Return label of status of object.
Definition: entrepot.class.php:648
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6156
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
CommonObject\fetch_optionals
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
Definition: commonobject.class.php:6007
Entrepot\create
create($user)
Creation d'un entrepot en base.
Definition: entrepot.class.php:189
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
Entrepot\get_children_warehouses
get_children_warehouses($id, &$TChildWarehouses)
Return array of children warehouses ids from $id warehouse (recursive function)
Definition: entrepot.class.php:840
Entrepot\__construct
__construct($db)
Constructor.
Definition: entrepot.class.php:169
Entrepot\info
info($id)
Load warehouse info data.
Definition: entrepot.class.php:506
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6116
Entrepot\STATUS_CLOSED
const STATUS_CLOSED
Warehouse closed, inactive.
Definition: entrepot.class.php:151
Entrepot\fetch
fetch($id, $ref='')
Load warehouse data.
Definition: entrepot.class.php:429
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
Entrepot\LibStatut
LibStatut($status, $mode=0)
Return label of a given status.
Definition: entrepot.class.php:661
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
Entrepot\getNomUrl
getNomUrl($withpicto=0, $option='', $showfullpath=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable name (possibility with the pictogram)
Definition: entrepot.class.php:690
Entrepot
Class to manage warehouses.
Definition: entrepot.class.php:35
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:489
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791