dolibarr  x.y.z
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),
145  );
146 
150  const STATUS_CLOSED = 0;
151 
155  const STATUS_OPEN_ALL = 1;
156 
161 
162 
168  public function __construct($db)
169  {
170  global $conf;
171  $this->db = $db;
172 
173  $this->statuts[self::STATUS_CLOSED] = 'Closed2';
174  if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
175  $this->statuts[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
176  $this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
177  } else {
178  $this->statuts[self::STATUS_OPEN_ALL] = 'Opened';
179  }
180  }
181 
188  public function create($user)
189  {
190  global $conf;
191 
192  $error = 0;
193 
194  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
195 
196  // Error if label not defined
197  if ($this->label == '') {
198  $this->error = "ErrorFieldRequired";
199  return 0;
200  }
201 
202  $now = dol_now();
203 
204  $this->db->begin();
205 
206  $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
207  $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").")";
208 
209  dol_syslog(get_class($this)."::create", LOG_DEBUG);
210  $result = $this->db->query($sql);
211  if ($result) {
212  $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
213  if ($id > 0) {
214  $this->id = $id;
215 
216  if (!$error) {
217  $result = $this->update($id, $user);
218  if ($result <= 0) {
219  $error++;
220  }
221  }
222 
223  // Actions on extra fields
224  if (!$error) {
225  if (!$error) {
226  $result = $this->insertExtraFields();
227  if ($result < 0) {
228  $error++;
229  }
230  }
231  }
232 
233  if (!$error) {
234  $this->db->commit();
235  return $id;
236  } else {
237  dol_syslog(get_class($this)."::create return -3");
238  $this->db->rollback();
239  return -3;
240  }
241  } else {
242  $this->error = "Failed to get insert id";
243  dol_syslog(get_class($this)."::create return -2");
244  return -2;
245  }
246  } else {
247  $this->error = $this->db->error();
248  dol_syslog(get_class($this)."::create Error ".$this->db->error());
249  $this->db->rollback();
250  return -1;
251  }
252  }
253 
261  public function update($id, $user)
262  {
263  global $conf;
264 
265  $error = 0;
266 
267  if (empty($id)) {
268  $id = $this->id;
269  }
270  if (empty($this->label)) {
271  $this->label = $this->libelle; // For backward compatibility
272  }
273 
274  // Check if new parent is already a child of current warehouse
275  if (!empty($this->fk_parent)) {
276  $TChildWarehouses = array($id);
277  $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
278  if (in_array($this->fk_parent, $TChildWarehouses)) {
279  $this->error = 'ErrorCannotAddThisParentWarehouse';
280  return -2;
281  }
282  }
283 
284  $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
285 
286  $this->description = trim($this->description);
287 
288  $this->lieu = trim($this->lieu);
289 
290  $this->address = trim($this->address);
291  $this->zip = trim($this->zip);
292  $this->town = trim($this->town);
293  $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
294 
295  $sql = "UPDATE ".$this->db->prefix()."entrepot";
296  $sql .= " SET ref = '".$this->db->escape($this->label)."'";
297  $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
298  $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
299  $sql .= ", description = '".$this->db->escape($this->description)."'";
300  $sql .= ", statut = ".((int) $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 = ".((int) $this->country_id);
306  $sql .= ", phone = '".$this->db->escape($this->phone)."'";
307  $sql .= ", fax = '".$this->db->escape($this->fax)."'";
308  $sql .= " WHERE rowid = ".((int) $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  $error++;
324  }
325  }
326 
327  if (!$error) {
328  $this->db->commit();
329  return 1;
330  } else {
331  $this->db->rollback();
332  $this->error = $this->db->lasterror();
333  return -1;
334  }
335  }
336 
337 
345  public function delete($user, $notrigger = 0)
346  {
347  global $conf;
348 
349  $error = 0;
350 
351  dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
352 
353  $this->db->begin();
354 
355  if (!$error && empty($notrigger)) {
356  // Call trigger
357  $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
358  if ($result < 0) {
359  $error++;
360  }
361  // End call triggers
362  }
363 
364  $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties');
365  foreach ($elements as $table) {
366  if (!$error) {
367  $sql = "DELETE FROM ".$this->db->prefix().$table;
368  $sql .= " WHERE fk_entrepot = ".((int) $this->id);
369 
370  $result = $this->db->query($sql);
371  if (!$result) {
372  $error++;
373  $this->errors[] = $this->db->lasterror();
374  }
375  }
376  }
377 
378  // Removed extrafields
379  if (!$error) {
380  if (!$error) {
381  $result = $this->deleteExtraFields();
382  if ($result < 0) {
383  $error++;
384  dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
385  }
386  }
387  }
388 
389  if (!$error) {
390  $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
391  $sql .= " WHERE rowid = ".((int) $this->id);
392  $resql1 = $this->db->query($sql);
393  if (!$resql1) {
394  $error++;
395  $this->errors[] = $this->db->lasterror();
396  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
397  }
398  }
399 
400  if (!$error) {
401  // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
402  $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)";
403  $resql2 = $this->db->query($sql);
404  if (!$resql2) {
405  $error++;
406  $this->errors[] = $this->db->lasterror();
407  dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
408  }
409  }
410 
411  if (!$error) {
412  $this->db->commit();
413  return 1;
414  } else {
415  $this->db->rollback();
416  return -1;
417  }
418  }
419 
420 
428  public function fetch($id, $ref = '')
429  {
430  global $conf;
431 
432  dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
433 
434  // Check parameters
435  if (!$id && !$ref) {
436  $this->error = 'ErrorWrongParameters';
437  dol_syslog(get_class($this)."::fetch ".$this->error);
438  return -1;
439  }
440 
441  $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
442  $sql .= " model_pdf, import_key";
443  $sql .= " FROM ".$this->db->prefix()."entrepot";
444  if ($id) {
445  $sql .= " WHERE rowid = ".((int) $id);
446  } else {
447  $sql .= " WHERE entity IN (".getEntity('stock').")";
448  if ($ref) {
449  $sql .= " AND ref = '".$this->db->escape($ref)."'";
450  }
451  }
452 
453  $result = $this->db->query($sql);
454  if ($result) {
455  if ($this->db->num_rows($result) > 0) {
456  $obj = $this->db->fetch_object($result);
457 
458  $this->id = $obj->rowid;
459  $this->entity = $obj->entity;
460  $this->fk_parent = $obj->fk_parent;
461  $this->fk_project = $obj->fk_project;
462  $this->ref = $obj->label;
463  $this->label = $obj->label;
464  $this->libelle = $obj->label; // deprecated
465  $this->description = $obj->description;
466  $this->statut = $obj->statut;
467  $this->lieu = $obj->lieu;
468  $this->address = $obj->address;
469  $this->zip = $obj->zip;
470  $this->town = $obj->town;
471  $this->country_id = $obj->country_id;
472  $this->phone = $obj->phone;
473  $this->fax = $obj->fax;
474 
475  $this->model_pdf = $obj->model_pdf;
476  $this->import_key = $obj->import_key;
477 
478  // Retrieve all extrafield
479  // fetch optionals attributes and labels
480  $this->fetch_optionals();
481 
482  include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
483  $tmp = getCountry($this->country_id, 'all');
484  $this->country = $tmp['label'];
485  $this->country_code = $tmp['code'];
486 
487  return 1;
488  } else {
489  $this->error = "Record Not Found";
490  return 0;
491  }
492  } else {
493  $this->error = $this->db->error();
494  return -1;
495  }
496  }
497 
498 
505  public function info($id)
506  {
507  $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
508  $sql .= " FROM ".$this->db->prefix()."entrepot as e";
509  $sql .= " WHERE e.rowid = ".((int) $id);
510 
511  dol_syslog(get_class($this)."::info", LOG_DEBUG);
512  $result = $this->db->query($sql);
513  if ($result) {
514  if ($this->db->num_rows($result)) {
515  $obj = $this->db->fetch_object($result);
516 
517  $this->id = $obj->rowid;
518 
519  $this->user_creation_id = $obj->fk_user_author;
520  $this->date_creation = $this->db->jdate($obj->datec);
521  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
522  }
523 
524  $this->db->free($result);
525  } else {
526  dol_print_error($this->db);
527  }
528  }
529 
530 
531  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
538  public function list_array($status = 1)
539  {
540  // phpcs:enable
541  $liste = array();
542 
543  $sql = "SELECT rowid, ref as label";
544  $sql .= " FROM ".$this->db->prefix()."entrepot";
545  $sql .= " WHERE entity IN (".getEntity('stock').")";
546  $sql .= " AND statut = ".((int) $status);
547 
548  $result = $this->db->query($sql);
549  $i = 0;
550  $num = $this->db->num_rows($result);
551  if ($result) {
552  while ($i < $num) {
553  $row = $this->db->fetch_row($result);
554  $liste[$row[0]] = $row[1];
555  $i++;
556  }
557  $this->db->free($result);
558  }
559  return $liste;
560  }
561 
562  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
568  public function nb_different_products()
569  {
570  // phpcs:enable
571  $ret = array();
572 
573  $sql = "SELECT count(distinct p.rowid) as nb";
574  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
575  $sql .= ", ".$this->db->prefix()."product as p";
576  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
577  $sql .= " AND ps.fk_product = p.rowid";
578 
579  //print $sql;
580  $result = $this->db->query($sql);
581  if ($result) {
582  $obj = $this->db->fetch_object($result);
583  $ret['nb'] = $obj->nb;
584  $this->db->free($result);
585  } else {
586  $this->error = $this->db->lasterror();
587  return -1;
588  }
589 
590  return $ret;
591  }
592 
593  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
599  public function nb_products()
600  {
601  global $conf;
602  // phpcs:enable
603  $ret = array();
604 
605  //For MultiCompany PMP per entity
606  $separatedPMP = false;
607  if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
608  $separatedPMP = true;
609  }
610 
611  if ($separatedPMP) {
612  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
613  } else {
614  $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
615  }
616  $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
617  $sql .= ", ".$this->db->prefix()."product as p";
618  if ($separatedPMP) {
619  $sql .= ", ".$this->db->prefix()."product_perentity as pa";
620  }
621  $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
622  if ($separatedPMP) {
623  $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
624  }
625  $sql .= " AND ps.fk_product = p.rowid";
626  //print $sql;
627  $result = $this->db->query($sql);
628  if ($result) {
629  $obj = $this->db->fetch_object($result);
630  $ret['nb'] = $obj->nb;
631  $ret['value'] = $obj->value;
632  $this->db->free($result);
633  } else {
634  $this->error = $this->db->lasterror();
635  return -1;
636  }
637 
638  return $ret;
639  }
640 
647  public function getLibStatut($mode = 0)
648  {
649  return $this->LibStatut($this->statut, $mode);
650  }
651 
652  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
660  public function LibStatut($status, $mode = 0)
661  {
662  // phpcs:enable
663  global $langs;
664 
665  $statusType = 'status5';
666  if ($status > 0) {
667  $statusType = 'status4';
668  }
669 
670  $langs->load('stocks');
671  $label = $langs->transnoentitiesnoconv($this->statuts[$status]);
672  $labelshort = $langs->transnoentitiesnoconv($this->statuts[$status]);
673 
674  return dolGetStatus($label, $labelshort, '', $statusType, $mode);
675  }
676 
677 
689  public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
690  {
691  global $conf, $langs, $hookmanager;
692  $langs->load("stocks");
693 
694  if (!empty($conf->dol_no_mouse_hover)) {
695  $notooltip = 1; // Force disable tooltips
696  }
697 
698  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
699  $withpicto = 0;
700  }
701 
702  $result = '';
703 
704  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
705  if (isset($this->statut)) {
706  $label .= ' '.$this->getLibStatut(5);
707  }
708  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref);
709  if (!empty($this->lieu)) {
710  $label .= '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
711  }
712 
713  $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
714 
715  if ($option != 'nolink') {
716  // Add param to save lastsearch_values or not
717  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
718  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
719  $add_save_lastsearch_values = 1;
720  }
721  if ($add_save_lastsearch_values) {
722  $url .= '&save_lastsearch_values=1';
723  }
724  }
725 
726  $linkclose = '';
727  if (empty($notooltip)) {
728  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
729  $label = $langs->trans("Warehouse");
730  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
731  }
732  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
733  $linkclose .= ' class="classfortooltip"';
734  }
735 
736  $linkstart = '<a href="'.$url.'"';
737  $linkstart .= $linkclose.'>';
738  $linkend = '</a>';
739 
740  $result .= $linkstart;
741  if ($withpicto) {
742  $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);
743  }
744  if ($withpicto != 2) {
745  $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
746  }
747  $result .= $linkend;
748 
749  global $action;
750  $hookmanager->initHooks(array('warehousedao'));
751  $parameters = array('id'=>$this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip'=> $notooltip);
752  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
753  if ($reshook > 0) {
754  $result = $hookmanager->resPrint;
755  } else {
756  $result .= $hookmanager->resPrint;
757  }
758 
759  return $result;
760  }
761 
769  public function initAsSpecimen()
770  {
771  global $user, $langs, $conf, $mysoc;
772 
773  $now = dol_now();
774 
775  // Initialize parameters
776  $this->id = 0;
777  $this->label = 'WAREHOUSE SPECIMEN';
778  $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
779  $this->statut = 1;
780  $this->specimen = 1;
781 
782  $this->lieu = 'Location test';
783  $this->address = '21 jump street';
784  $this->zip = '99999';
785  $this->town = 'MyTown';
786  $this->country_id = 1;
787  $this->country_code = 'FR';
788  }
789 
790  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
796  public function get_full_arbo()
797  {
798  // phpcs:enable
799  global $user, $langs, $conf;
800 
801  $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
802 
803  $protection = 100; // We limit depth of warehouses to 100
804 
805  $warehousetmp = new Entrepot($this->db);
806 
807  $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
808  $i = 0;
809  while ($parentid > 0 && $i < $protection) {
810  $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid);
811  $resql = $this->db->query($sql);
812  if ($resql) {
813  $objarbo = $this->db->fetch_object($resql);
814  if ($objarbo) {
815  $warehousetmp->fetch($parentid);
816  $TArbo[] = $warehousetmp->label;
817  $parentid = $objarbo->fk_parent;
818  } else {
819  break;
820  }
821  } else {
822  dol_print_error($this->db);
823  }
824 
825  $i++;
826  }
827 
828  return implode(' >> ', array_reverse($TArbo));
829  }
830 
831  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839  public function get_children_warehouses($id, &$TChildWarehouses)
840  {
841  // phpcs:enable
842 
843  $sql = "SELECT rowid
844  FROM ".$this->db->prefix()."entrepot
845  WHERE fk_parent = ".((int) $id);
846 
847  $resql = $this->db->query($sql);
848  if ($resql) {
849  while ($res = $this->db->fetch_object($resql)) {
850  $TChildWarehouses[] = $res->rowid;
851  $this->get_children_warehouses($res->rowid, $TChildWarehouses);
852  }
853  }
854 
855  return $TChildWarehouses;
856  }
857 
868  public function generateDocument($modele, $outputlangs = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
869  {
870  global $conf, $user, $langs;
871 
872  $langs->load("stocks");
873  $outputlangs->load("products");
874 
875  if (!dol_strlen($modele)) {
876  $modele = 'standard';
877 
878  if ($this->model_pdf) {
879  $modele = $this->model_pdf;
880  } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
881  $modele = $conf->global->STOCK_ADDON_PDF;
882  }
883  }
884 
885  $modelpath = "core/modules/stock/doc/";
886 
887  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
888  }
889 
900  public function setCategories($categories)
901  {
902  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
903  return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
904  }
905 
912  public function getKanbanView($option = '')
913  {
914 
915  $return = '<div class="box-flex-item box-flex-grow-zero">';
916  $return .= '<div class="info-box info-box-sm">';
917  $return .= '<div class="info-box-icon bg-infobox-action" >';
918  $return .= img_picto('', $this->picto);
919  $return .= '</div>';
920  $return .= '<div class="info-box-content" >';
921  $return .= '<span class="info-box-ref">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
922  if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
923  $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
924  }
925  if (property_exists($this, 'sellvalue') && $this->sellvalue != 0) {
926  $return .= '<br><span class="info-box-label amount">'.price($this->sellvalue).'</span>';
927  }
928  if (method_exists($this, 'getLibStatut')) {
929  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).'</div>';
930  }
931  $return .= '</div>';
932  $return .= '</div>';
933  $return .= '</div>';
934  return $return;
935  }
936 }
$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 operations for stock transfers/corrections allowed (not for customer shipping and ...
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.
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 operations for customer shipping, supplier dispatch, internal stock transfers/corr...
generateDocument($modele, $outputlangs='', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
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.
getKanbanView($option='')
Return clicable link of object (with eventually picto)
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