dolibarr  17.0.4
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  'description' =>array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>-2, 'position'=>35, 'searchall'=>1),
129  'lieu' =>array('type'=>'varchar(64)', 'label'=>'LocationSummary', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'showoncombobox'=>2, 'searchall'=>1),
130  '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),
131  '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),
132  'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-2, 'position'=>45, 'searchall'=>1),
133  'zip' =>array('type'=>'varchar(10)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'searchall'=>1),
134  'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-2, 'position'=>55, 'searchall'=>1),
135  'fk_departement' =>array('type'=>'sellist:c_departements:label:rowid::active=1', 'label'=>'State', 'enabled'=>1, 'visible'=>0, 'position'=>60),
136  'fk_pays' =>array('type'=>'sellist:c_country:label:rowid::active=1', 'label'=>'Country', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
137  'phone' =>array('type'=>'varchar(20)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>-2, 'position'=>70, 'searchall'=>1),
138  'fax' =>array('type'=>'varchar(20)', 'label'=>'Fax', 'enabled'=>1, 'visible'=>-2, 'position'=>75, 'searchall'=>1),
139  //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
140  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>300),
141  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>301),
142  //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
143  //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
144  'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>500, 'css'=>'minwidth50'),
145  );
146 
150  const STATUS_CLOSED = 0;
151 
155  const STATUS_OPEN_ALL = 1;
156 
161 
165  const STATUS_OPENEXT_ALL = 3; // TODO Implement this
166 
167 
168 
174  public function __construct($db)
175  {
176  global $conf;
177  $this->db = $db;
178 
179  $this->statuts[self::STATUS_CLOSED] = 'Closed2';
180  if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
181  $this->statuts[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
182  $this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
183  } else {
184  $this->statuts[self::STATUS_OPEN_ALL] = 'Opened';
185  }
186  }
187 
194  public function create($user)
195  {
196  global $conf;
197 
198  $error = 0;
199 
200  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
201 
202  // Error if label not defined
203  if ($this->label == '') {
204  $this->error = "ErrorFieldRequired";
205  return 0;
206  }
207 
208  $now = dol_now();
209 
210  $this->db->begin();
211 
212  $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
213  $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").")";
214 
215  dol_syslog(get_class($this)."::create", LOG_DEBUG);
216  $result = $this->db->query($sql);
217  if ($result) {
218  $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
219  if ($id > 0) {
220  $this->id = $id;
221 
222  if (!$error) {
223  $result = $this->update($id, $user);
224  if ($result <= 0) {
225  $error++;
226  }
227  }
228 
229  // Actions on extra fields
230  if (!$error) {
231  if (!$error) {
232  $result = $this->insertExtraFields();
233  if ($result < 0) {
234  $error++;
235  }
236  }
237  }
238 
239  if (!$error) {
240  $this->db->commit();
241  return $id;
242  } else {
243  dol_syslog(get_class($this)."::create return -3");
244  $this->db->rollback();
245  return -3;
246  }
247  } else {
248  $this->error = "Failed to get insert id";
249  dol_syslog(get_class($this)."::create return -2");
250  return -2;
251  }
252  } else {
253  $this->error = $this->db->error();
254  dol_syslog(get_class($this)."::create Error ".$this->db->error());
255  $this->db->rollback();
256  return -1;
257  }
258  }
259 
267  public function update($id, $user)
268  {
269  global $conf;
270 
271  $error = 0;
272 
273  if (empty($id)) {
274  $id = $this->id;
275  }
276  if (empty($this->label)) {
277  $this->label = $this->libelle; // For backward compatibility
278  }
279 
280  // Check if new parent is already a child of current warehouse
281  if (!empty($this->fk_parent)) {
282  $TChildWarehouses = array($id);
283  $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
284  if (in_array($this->fk_parent, $TChildWarehouses)) {
285  $this->error = 'ErrorCannotAddThisParentWarehouse';
286  return -2;
287  }
288  }
289 
290  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
291 
292  $this->description = trim($this->description);
293 
294  $this->lieu = trim($this->lieu);
295 
296  $this->address = trim($this->address);
297  $this->zip = trim($this->zip);
298  $this->town = trim($this->town);
299  $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
300 
301  $sql = "UPDATE ".$this->db->prefix()."entrepot";
302  $sql .= " SET ref = '".$this->db->escape($this->label)."'";
303  $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
304  $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
305  $sql .= ", description = '".$this->db->escape($this->description)."'";
306  $sql .= ", statut = ".((int) $this->statut);
307  $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
308  $sql .= ", address = '".$this->db->escape($this->address)."'";
309  $sql .= ", zip = '".$this->db->escape($this->zip)."'";
310  $sql .= ", town = '".$this->db->escape($this->town)."'";
311  $sql .= ", fk_pays = ".((int) $this->country_id);
312  $sql .= ", phone = '".$this->db->escape($this->phone)."'";
313  $sql .= ", fax = '".$this->db->escape($this->fax)."'";
314  $sql .= " WHERE rowid = ".((int) $id);
315 
316  $this->db->begin();
317 
318  dol_syslog(get_class($this)."::update", LOG_DEBUG);
319  $resql = $this->db->query($sql);
320 
321  if (!$resql) {
322  $error++;
323  $this->errors[] = "Error ".$this->db->lasterror();
324  }
325 
326  if (!$error) {
327  $result = $this->insertExtraFields();
328  if ($result < 0) {
329  $error++;
330  }
331  }
332 
333  if (!$error) {
334  $this->db->commit();
335  return 1;
336  } else {
337  $this->db->rollback();
338  $this->error = $this->db->lasterror();
339  return -1;
340  }
341  }
342 
343 
351  public function delete($user, $notrigger = 0)
352  {
353  global $conf;
354 
355  $error = 0;
356 
357  dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
358 
359  $this->db->begin();
360 
361  if (!$error && empty($notrigger)) {
362  // Call trigger
363  $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
364  if ($result < 0) {
365  $error++;
366  }
367  // End call triggers
368  }
369 
370  if (!$error) {
371  $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
372  $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
373  $result = $this->db->query($sql);
374  if (!$result) {
375  $error++;
376  $this->errors[] = $this->db->lasterror();
377  }
378  }
379 
380  if (!$error) {
381  $elements = array('stock_mouvement', 'product_stock');
382  foreach ($elements as $table) {
383  if (!$error) {
384  $sql = "DELETE FROM ".$this->db->prefix().$table;
385  $sql .= " WHERE fk_entrepot = ".((int) $this->id);
386 
387  $result = $this->db->query($sql);
388  if (!$result) {
389  $error++;
390  $this->errors[] = $this->db->lasterror();
391  }
392  }
393  }
394  }
395 
396  // Removed extrafields
397  if (!$error) {
398  if (!$error) {
399  $result = $this->deleteExtraFields();
400  if ($result < 0) {
401  $error++;
402  dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
403  }
404  }
405  }
406 
407  if (!$error) {
408  $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
409  $sql .= " WHERE rowid = ".((int) $this->id);
410  $resql1 = $this->db->query($sql);
411  if (!$resql1) {
412  $error++;
413  $this->errors[] = $this->db->lasterror();
414  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
415  }
416  }
417 
418  if (!$error) {
419  // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
420  $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)";
421  $resql2 = $this->db->query($sql);
422  if (!$resql2) {
423  $error++;
424  $this->errors[] = $this->db->lasterror();
425  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
426  }
427  }
428 
429  if (!$error) {
430  $this->db->commit();
431  return 1;
432  } else {
433  $this->db->rollback();
434  return -1;
435  }
436  }
437 
438 
446  public function fetch($id, $ref = '')
447  {
448  global $conf;
449 
450  dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
451 
452  // Check parameters
453  if (!$id && !$ref) {
454  $this->error = 'ErrorWrongParameters';
455  dol_syslog(get_class($this)."::fetch ".$this->error);
456  return -1;
457  }
458 
459  $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
460  $sql .= " model_pdf, import_key";
461  $sql .= " FROM ".$this->db->prefix()."entrepot";
462  if ($id) {
463  $sql .= " WHERE rowid = ".((int) $id);
464  } else {
465  $sql .= " WHERE entity IN (".getEntity('stock').")";
466  if ($ref) {
467  $sql .= " AND ref = '".$this->db->escape($ref)."'";
468  }
469  }
470 
471  $result = $this->db->query($sql);
472  if ($result) {
473  if ($this->db->num_rows($result) > 0) {
474  $obj = $this->db->fetch_object($result);
475 
476  $this->id = $obj->rowid;
477  $this->entity = $obj->entity;
478  $this->fk_parent = $obj->fk_parent;
479  $this->fk_project = $obj->fk_project;
480  $this->ref = $obj->label;
481  $this->label = $obj->label;
482  $this->libelle = $obj->label; // deprecated
483  $this->description = $obj->description;
484  $this->statut = $obj->statut;
485  $this->lieu = $obj->lieu;
486  $this->address = $obj->address;
487  $this->zip = $obj->zip;
488  $this->town = $obj->town;
489  $this->country_id = $obj->country_id;
490  $this->phone = $obj->phone;
491  $this->fax = $obj->fax;
492 
493  $this->model_pdf = $obj->model_pdf;
494  $this->import_key = $obj->import_key;
495 
496  // Retrieve all extrafield
497  // fetch optionals attributes and labels
498  $this->fetch_optionals();
499 
500  include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
501  $tmp = getCountry($this->country_id, 'all');
502  $this->country = $tmp['label'];
503  $this->country_code = $tmp['code'];
504 
505  return 1;
506  } else {
507  $this->error = "Record Not Found";
508  return 0;
509  }
510  } else {
511  $this->error = $this->db->error();
512  return -1;
513  }
514  }
515 
516 
523  public function info($id)
524  {
525  $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
526  $sql .= " FROM ".$this->db->prefix()."entrepot as e";
527  $sql .= " WHERE e.rowid = ".((int) $id);
528 
529  dol_syslog(get_class($this)."::info", LOG_DEBUG);
530  $result = $this->db->query($sql);
531  if ($result) {
532  if ($this->db->num_rows($result)) {
533  $obj = $this->db->fetch_object($result);
534 
535  $this->id = $obj->rowid;
536 
537  $this->user_creation_id = $obj->fk_user_author;
538  $this->date_creation = $this->db->jdate($obj->datec);
539  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
540  }
541 
542  $this->db->free($result);
543  } else {
544  dol_print_error($this->db);
545  }
546  }
547 
548 
549  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
556  public function list_array($status = 1)
557  {
558  // phpcs:enable
559  $liste = array();
560 
561  $sql = "SELECT rowid, ref as label";
562  $sql .= " FROM ".$this->db->prefix()."entrepot";
563  $sql .= " WHERE entity IN (".getEntity('stock').")";
564  $sql .= " AND statut = ".((int) $status);
565 
566  $result = $this->db->query($sql);
567  $i = 0;
568  $num = $this->db->num_rows($result);
569  if ($result) {
570  while ($i < $num) {
571  $row = $this->db->fetch_row($result);
572  $liste[$row[0]] = $row[1];
573  $i++;
574  }
575  $this->db->free($result);
576  }
577  return $liste;
578  }
579 
580  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
586  public function nb_different_products()
587  {
588  // phpcs:enable
589  $ret = array();
590 
591  $sql = "SELECT count(distinct p.rowid) as nb";
592  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
593  $sql .= ", ".$this->db->prefix()."product as p";
594  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
595  $sql .= " AND ps.fk_product = p.rowid";
596 
597  //print $sql;
598  $result = $this->db->query($sql);
599  if ($result) {
600  $obj = $this->db->fetch_object($result);
601  $ret['nb'] = $obj->nb;
602  $this->db->free($result);
603  } else {
604  $this->error = $this->db->lasterror();
605  return -1;
606  }
607 
608  return $ret;
609  }
610 
611  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
617  public function nb_products()
618  {
619  global $conf;
620  // phpcs:enable
621  $ret = array();
622 
623  //For MultiCompany PMP per entity
624  $separatedPMP = false;
625  if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
626  $separatedPMP = true;
627  }
628 
629  if ($separatedPMP) {
630  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
631  } else {
632  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
633  }
634  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
635  $sql .= ", ".$this->db->prefix()."product as p";
636  if ($separatedPMP) {
637  $sql .= ", ".$this->db->prefix()."product_perentity as pa";
638  }
639  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
640  if ($separatedPMP) {
641  $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
642  }
643  $sql .= " AND ps.fk_product = p.rowid";
644  //print $sql;
645  $result = $this->db->query($sql);
646  if ($result) {
647  $obj = $this->db->fetch_object($result);
648  $ret['nb'] = $obj->nb;
649  $ret['value'] = $obj->value;
650  $this->db->free($result);
651  } else {
652  $this->error = $this->db->lasterror();
653  return -1;
654  }
655 
656  return $ret;
657  }
658 
665  public function getLibStatut($mode = 0)
666  {
667  return $this->LibStatut($this->statut, $mode);
668  }
669 
670  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
678  public function LibStatut($status, $mode = 0)
679  {
680  // phpcs:enable
681  global $langs;
682 
683  $statusType = 'status5';
684  if ($status > 0) {
685  $statusType = 'status4';
686  }
687 
688  $langs->load('stocks');
689  $label = $langs->transnoentitiesnoconv($this->statuts[$status]);
690  $labelshort = $langs->transnoentitiesnoconv($this->statuts[$status]);
691 
692  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
693  }
694 
695 
707  public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
708  {
709  global $conf, $langs, $hookmanager;
710  $langs->load("stocks");
711 
712  if (!empty($conf->dol_no_mouse_hover)) {
713  $notooltip = 1; // Force disable tooltips
714  }
715 
716  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
717  $withpicto = 0;
718  }
719 
720  $result = '';
721 
722  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
723  if (isset($this->statut)) {
724  $label .= ' '.$this->getLibStatut(5);
725  }
726  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref);
727  if (!empty($this->lieu)) {
728  $label .= '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
729  }
730 
731  $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
732 
733  if ($option != 'nolink') {
734  // Add param to save lastsearch_values or not
735  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
736  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
737  $add_save_lastsearch_values = 1;
738  }
739  if ($add_save_lastsearch_values) {
740  $url .= '&save_lastsearch_values=1';
741  }
742  }
743 
744  $linkclose = '';
745  if (empty($notooltip)) {
746  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
747  $label = $langs->trans("Warehouse");
748  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
749  }
750  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
751  $linkclose .= ' class="classfortooltip"';
752  }
753 
754  $linkstart = '<a href="'.$url.'"';
755  $linkstart .= $linkclose.'>';
756  $linkend = '</a>';
757 
758  $result .= $linkstart;
759  if ($withpicto) {
760  $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);
761  }
762  if ($withpicto != 2) {
763  $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
764  }
765  $result .= $linkend;
766 
767  global $action;
768  $hookmanager->initHooks(array('warehousedao'));
769  $parameters = array('id'=>$this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip'=> $notooltip);
770  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
771  if ($reshook > 0) {
772  $result = $hookmanager->resPrint;
773  } else {
774  $result .= $hookmanager->resPrint;
775  }
776 
777  return $result;
778  }
779 
787  public function initAsSpecimen()
788  {
789  global $user, $langs, $conf, $mysoc;
790 
791  $now = dol_now();
792 
793  // Initialize parameters
794  $this->id = 0;
795  $this->label = 'WAREHOUSE SPECIMEN';
796  $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
797  $this->statut = 1;
798  $this->specimen = 1;
799 
800  $this->lieu = 'Location test';
801  $this->address = '21 jump street';
802  $this->zip = '99999';
803  $this->town = 'MyTown';
804  $this->country_id = 1;
805  $this->country_code = 'FR';
806  }
807 
808  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
814  public function get_full_arbo()
815  {
816  // phpcs:enable
817  global $user, $langs, $conf;
818 
819  $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
820 
821  $protection = 100; // We limit depth of warehouses to 100
822 
823  $warehousetmp = new Entrepot($this->db);
824 
825  $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
826  $i = 0;
827  while ($parentid > 0 && $i < $protection) {
828  $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid);
829  $resql = $this->db->query($sql);
830  if ($resql) {
831  $objarbo = $this->db->fetch_object($resql);
832  if ($objarbo) {
833  $warehousetmp->fetch($parentid);
834  $TArbo[] = $warehousetmp->label;
835  $parentid = $objarbo->fk_parent;
836  } else {
837  break;
838  }
839  } else {
840  dol_print_error($this->db);
841  }
842 
843  $i++;
844  }
845 
846  return implode(' >> ', array_reverse($TArbo));
847  }
848 
849  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
857  public function get_children_warehouses($id, &$TChildWarehouses)
858  {
859  // phpcs:enable
860 
861  $sql = "SELECT rowid
862  FROM ".$this->db->prefix()."entrepot
863  WHERE fk_parent = ".((int) $id);
864 
865  $resql = $this->db->query($sql);
866  if ($resql) {
867  while ($res = $this->db->fetch_object($resql)) {
868  $TChildWarehouses[] = $res->rowid;
869  $this->get_children_warehouses($res->rowid, $TChildWarehouses);
870  }
871  }
872 
873  return $TChildWarehouses;
874  }
875 
886  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
887  {
888  global $conf, $user, $langs;
889 
890  $langs->load("stocks");
891  $outputlangs->load("products");
892 
893  if (!dol_strlen($modele)) {
894  $modele = 'standard';
895 
896  if ($this->model_pdf) {
897  $modele = $this->model_pdf;
898  } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
899  $modele = $conf->global->STOCK_ADDON_PDF;
900  }
901  }
902 
903  $modelpath = "core/modules/stock/doc/";
904 
905  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
906  }
907 
918  public function setCategories($categories)
919  {
920  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
921  return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
922  }
923 }
$object ref
Definition: info.php:78
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage warehouses.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
nb_different_products()
Return number of unique different product into a warehouse.
fetch($id, $ref='')
Load warehouse data.
get_children_warehouses($id, &$TChildWarehouses)
Return array of children warehouses ids from $id warehouse (recursive function)
getLibStatut($mode=0)
Return label of status of object.
LibStatut($status, $mode=0)
Return label of a given status.
const STATUS_OPENEXT_ALL
Warehouse open and any operations are allowed, but warehouse is not included into calculation of stoc...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
create($user)
Creation d'un entrepot en base.
update($id, $user)
Update properties of a warehouse.
getNomUrl($withpicto=0, $option='', $showfullpath=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable name (possibility with the pictogram)
setCategories($categories)
Sets object to supplied categories.
initAsSpecimen()
Initialise an instance with random values.
info($id)
Load warehouse info data.
nb_products()
Return stock and value of warehosue.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
list_array($status=1)
Return list of all warehouses.
get_full_arbo()
Return full path to current warehouse.
__construct($db)
Constructor.
const STATUS_CLOSED
Warehouse closed, inactive.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41