dolibarr 24.0.0-beta
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-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31
32
37{
41 public $element = 'stock';
42
46 public $table_element = 'entrepot';
47
51 public $picto = 'stock';
52
58 public $libelle;
59
63 public $label;
64
68 public $barcode;
69
73 public $description;
74
78 public $fk_departement;
79
83 public $statut;
84
88 public $lieu;
89
93 public $address;
94
98 public $zip;
99
103 public $town;
104
108 public $phone;
109
113 public $fax;
114
118 public $fk_parent;
119
123 public $fk_project;
124
128 public $warehouse_usage;
129
169 // BEGIN MODULEBUILDER PROPERTIES
173 public $fields = array(
174 'rowid' => array('type' => 'integer', 'label' => 'ID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 10),
175 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 15),
176 'ref' => array('type' => 'varchar(255)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'showoncombobox' => 1, 'position' => 25, 'searchall' => 1),
177 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'visible' => -2, 'position' => 35, 'searchall' => 1),
178 'lieu' => array('type' => 'varchar(64)', 'label' => 'LocationSummary', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'showoncombobox' => 2, 'searchall' => 1),
179 '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),
180 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => 'isModEnabled("project")', 'visible' => -1, 'position' => 42),
181 'address' => array('type' => 'varchar(255)', 'label' => 'Address', 'enabled' => 1, 'visible' => -2, 'position' => 45, 'searchall' => 1),
182 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'searchall' => 1),
183 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -2, 'position' => 55, 'searchall' => 1),
184 'fk_departement' => array('type' => 'integer', 'label' => 'State', 'enabled' => 1, 'visible' => 0, 'position' => 60),
185 'fk_pays' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 65),
186 'phone' => array('type' => 'varchar(20)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -2, 'position' => 70, 'searchall' => 1),
187 'fax' => array('type' => 'varchar(20)', 'label' => 'Fax', 'enabled' => 1, 'visible' => -2, 'position' => 75, 'searchall' => 1),
188 //'fk_user_author' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
189 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300),
190 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301),
191 'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("STOCK_USE_WAREHOUSE_USAGE")', 'visible' => 1, 'position' => 400, 'default' => '1', 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')),
192 //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
193 //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
194 'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'),
195 );
196 // END MODULEBUILDER PROPERTIES
197
198
202 const STATUS_CLOSED = 0;
203
208
214
215
219 const USAGE_INTERNAL = 1;
220
224 const USAGE_EXTERNAL = 2;
225
226
227
233 public function __construct($db)
234 {
235 $this->db = $db;
236
237 $this->ismultientitymanaged = 1;
238
239 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
240 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
241 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
242 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
243 } else {
244 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
245 }
246 }
247
255 public function create($user, $notrigger = 0)
256 {
257 global $conf;
258
259 $error = 0;
260
261 $this->label = trim($this->label);
262
263 // Error if label not defined
264 if ($this->label == '') {
265 $this->error = "ErrorFieldRequired";
266 return 0;
267 }
268 if (empty($this->country_id) && !empty($this->country_code)) {
269 $country_id = getCountry($this->country_code, '3');
270 $this->country_id = is_int($country_id) ? $country_id : 0;
271 }
272
273 $now = dol_now();
274
275 $this->db->begin();
276
277 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
278 $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").")";
279
280 dol_syslog(get_class($this)."::create", LOG_DEBUG);
281 $result = $this->db->query($sql);
282 if ($result) {
283 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
284 if ($id > 0) {
285 $this->id = $id;
286 $result = $this->update($id, $user);
287 if ($result <= 0) {
288 $error++;
289 }
290
291 // Actions on extra fields
292 if (!$error) {
293 $result = $this->insertExtraFields();
294 if ($result < 0) {
295 $error++;
296 }
297 }
298
299 if (!$error && !$notrigger) {
300 // Call triggers
301 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
302 if ($result < 0) {
303 $error++;
304 }
305 // End call triggers
306 }
307
308 if (!$error) {
309 $this->db->commit();
310 return $id;
311 } else {
312 dol_syslog(get_class($this)."::create return -3");
313 $this->db->rollback();
314 return -3;
315 }
316 } else {
317 $this->error = "Failed to get insert id";
318 dol_syslog(get_class($this)."::create return -2");
319 return -2;
320 }
321 } else {
322 $this->error = $this->db->error();
323 dol_syslog(get_class($this)."::create Error ".$this->db->error());
324 $this->db->rollback();
325 return -1;
326 }
327 }
328
337 public function update($id, $user, $notrigger = 0)
338 {
339 if (empty($this->country_id) && !empty($this->country_code)) {
340 $country_id = getCountry($this->country_code, '3');
341 $this->country_id = is_int($country_id) ? $country_id : 0;
342 }
343
344 $error = 0;
345
346 if (empty($id)) {
347 $id = $this->id;
348 }
349
350 // Check if new parent is already a child of current warehouse
351 if (!empty($this->fk_parent)) {
352 $TChildWarehouses = array($id);
353 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
354 if (in_array($this->fk_parent, $TChildWarehouses)) {
355 $this->error = 'ErrorCannotAddThisParentWarehouse';
356 return -2;
357 }
358 }
359
360 $this->label = trim($this->label);
361 $this->barcode = trim($this->barcode);
362 $this->model_pdf = trim($this->model_pdf);
363
364 $this->description = trim($this->description);
365
366 $this->lieu = trim($this->lieu);
367
368 $this->address = trim($this->address);
369 $this->zip = trim($this->zip);
370 $this->town = trim($this->town);
371 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
372
373 $sql = "UPDATE ".$this->db->prefix()."entrepot";
374 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
375 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
376 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
377 $sql .= ", description = '".$this->db->escape($this->description)."'";
378 $sql .= ", statut = ".((int) $this->statut);
379 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
380 $sql .= ", address = '".$this->db->escape($this->address)."'";
381 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
382 $sql .= ", town = '".$this->db->escape($this->town)."'";
383 $sql .= ", fk_pays = ".((int) $this->country_id);
384 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
385 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
386 $sql .= ", barcode = '".$this->db->escape($this->barcode)."'";
387 $sql .= ", fk_departement = ".((int) $this->fk_departement);
388 $sql .= ", fk_barcode_type = ".((int) $this->barcode_type);
389 $sql .= ", warehouse_usage = ".((int) $this->warehouse_usage);
390 $sql .= ", fk_user_author = ".((int) $this->user_creation_id);
391 $sql .= ", model_pdf = '".$this->db->escape($this->model_pdf)."'";
392 $sql .= ", import_key = ".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
393 $sql .= " WHERE rowid = ".((int) $id);
394
395 $this->db->begin();
396
397 dol_syslog(get_class($this)."::update", LOG_DEBUG);
398 $resql = $this->db->query($sql);
399
400 if (!$resql) {
401 $error++;
402 $this->errors[] = "Error ".$this->db->lasterror();
403 }
404
405 if (!$error) {
406 $result = $this->insertExtraFields();
407 if ($result < 0) {
408 $error++;
409 }
410 }
411
412 if (!$error && !$notrigger) {
413 // Call triggers
414 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
415 if ($result < 0) {
416 $error++;
417 }
418 // End call triggers
419 }
420
421 if (!$error) {
422 $this->db->commit();
423 return 1;
424 } else {
425 $this->db->rollback();
426 $this->error = $this->db->lasterror();
427 return -1;
428 }
429 }
430
431
439 public function delete($user, $notrigger = 0)
440 {
441 global $conf;
442
443 $error = 0;
444
445 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
446
447 $this->db->begin();
448
449 if (empty($notrigger)) {
450 // Call trigger
451 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
452 if ($result < 0) {
453 $error++;
454 }
455 // End call triggers
456 }
457
458 if (!$error) {
459 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
460 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
461 $result = $this->db->query($sql);
462 if (!$result) {
463 $error++;
464 $this->errors[] = $this->db->lasterror();
465 }
466 }
467
468 if (!$error) {
469 $elements = array('stock_mouvement', 'product_stock');
470 foreach ($elements as $table) {
471 if (!$error) {
472 $sql = "DELETE FROM ".$this->db->prefix().$table;
473 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
474
475 $result = $this->db->query($sql);
476 if (!$result) {
477 $error++;
478 $this->errors[] = $this->db->lasterror();
479 }
480 }
481 }
482 }
483
484 // Remove extrafields
485 if (!$error) {
486 $result = $this->deleteExtraFields();
487 if ($result < 0) {
488 $error++;
489 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
490 }
491 }
492
493 if (!$error) {
494 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
495 $sql .= " WHERE rowid = ".((int) $this->id);
496 $resql1 = $this->db->query($sql);
497 if (!$resql1) {
498 $error++;
499 $this->errors[] = $this->db->lasterror();
500 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
501 }
502 }
503
504 if (!$error) {
505 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
506 $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)";
507 $resql2 = $this->db->query($sql);
508 if (!$resql2) {
509 $error++;
510 $this->errors[] = $this->db->lasterror();
511 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
512 }
513 }
514
515 if (!$error) {
516 $this->db->commit();
517 return 1;
518 } else {
519 $this->db->rollback();
520 return -1;
521 }
522 }
523
524
532 public function fetch($id, $ref = '')
533 {
534 global $conf;
535
536 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
537
538 // Check parameters
539 if (!$id && !$ref) {
540 $this->error = 'ErrorWrongParameters';
541 dol_syslog(get_class($this)."::fetch ".$this->error);
542 return -1;
543 }
544
545 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
546 $sql .= " model_pdf, import_key, datec as date_creation, tms as date_modification, fk_departement, barcode, fk_barcode_type, warehouse_usage, fk_user_author as user_creation_id";
547 $sql .= " FROM ".$this->db->prefix()."entrepot";
548 if ($id) {
549 $sql .= " WHERE rowid = ".((int) $id);
550 } else {
551 $sql .= " WHERE entity IN (".getEntity('stock').")";
552 if ($ref) {
553 $sql .= " AND ref = '".$this->db->escape($ref)."'";
554 }
555 }
556
557 $result = $this->db->query($sql);
558 if ($result) {
559 if ($this->db->num_rows($result) > 0) {
560 $obj = $this->db->fetch_object($result);
561
562 $this->id = $obj->rowid;
563 $this->entity = $obj->entity;
564 $this->fk_parent = $obj->fk_parent;
565 $this->fk_project = $obj->fk_project;
566 $this->ref = $obj->label;
567 $this->label = $obj->label;
568 $this->description = $obj->description;
569 $this->statut = $obj->statut;
570 $this->status = $obj->statut;
571 $this->lieu = $obj->lieu;
572 $this->address = $obj->address;
573 $this->zip = $obj->zip;
574 $this->town = $obj->town;
575 $this->country_id = $obj->country_id;
576 $this->phone = $obj->phone;
577 $this->fax = $obj->fax;
578
579 $this->date_creation = $obj->date_creation;
580 $this->barcode = $obj->barcode;
581 $this->fk_departement = $obj->fk_departement;
582 $this->barcode_type = $obj->fk_barcode_type;
583 $this->warehouse_id = $obj->rowid;
584
585 $this->warehouse_usage = $obj->warehouse_usage;
586 $this->user_creation_id = $obj->user_creation_id;
587 $this->date_modification = $obj->date_modification;
588
589 $this->model_pdf = $obj->model_pdf;
590 $this->import_key = $obj->import_key;
591
592 // Retrieve all extrafield
593 // fetch optionals attributes and labels
594 $this->fetch_optionals();
595
596 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
597 $tmp = getCountry($this->country_id, 'all');
598 $this->country = $tmp['label'];
599 $this->country_code = $tmp['code'];
600
601 return 1;
602 } else {
603 $this->error = "Record Not Found";
604 return 0;
605 }
606 } else {
607 $this->error = $this->db->error();
608 return -1;
609 }
610 }
611
612
619 public function info($id)
620 {
621 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
622 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
623 $sql .= " WHERE e.rowid = ".((int) $id);
624
625 dol_syslog(get_class($this)."::info", LOG_DEBUG);
626 $result = $this->db->query($sql);
627 if ($result) {
628 if ($this->db->num_rows($result)) {
629 $obj = $this->db->fetch_object($result);
630
631 $this->id = $obj->rowid;
632
633 $this->user_creation_id = $obj->fk_user_author;
634 $this->date_creation = $this->db->jdate($obj->datec);
635 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
636 }
637
638 $this->db->free($result);
639 } else {
640 dol_print_error($this->db);
641 }
642 }
643
644
645 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
652 public function list_array($status = 1)
653 {
654 // phpcs:enable
655 $liste = array();
656
657 $sql = "SELECT rowid, ref as label";
658 $sql .= " FROM ".$this->db->prefix()."entrepot";
659 $sql .= " WHERE entity IN (".getEntity('stock').")";
660 $sql .= " AND statut = ".((int) $status);
661
662 $result = $this->db->query($sql);
663 $i = 0;
664 $num = $this->db->num_rows($result);
665 if ($result) {
666 while ($i < $num) {
667 $row = $this->db->fetch_row($result);
668 $liste[$row[0]] = $row[1];
669 $i++;
670 }
671 $this->db->free($result);
672 }
673 return $liste;
674 }
675
676 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
682 public function nb_different_products()
683 {
684 // phpcs:enable
685 $ret = array();
686
687 $sql = "SELECT count(distinct p.rowid) as nb";
688 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
689 $sql .= ", ".$this->db->prefix()."product as p";
690 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
691 $sql .= " AND ps.fk_product = p.rowid";
692
693 //print $sql;
694 $result = $this->db->query($sql);
695 if ($result) {
696 $obj = $this->db->fetch_object($result);
697 $ret['nb'] = $obj->nb;
698 $this->db->free($result);
699 } else {
700 $this->error = $this->db->lasterror();
701 return -1;
702 }
703
704 return $ret;
705 }
706
707 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
713 public function nb_products()
714 {
715 global $conf;
716 // phpcs:enable
717 $ret = array();
718
719 //For MultiCompany PMP per entity
720 $separatedPMP = false;
721 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
722 $separatedPMP = true;
723 }
724
725 if ($separatedPMP) {
726 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
727 } else {
728 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
729 }
730 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
731 $sql .= ", ".$this->db->prefix()."product as p";
732 if ($separatedPMP) {
733 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
734 }
735 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
736 if ($separatedPMP) {
737 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
738 }
739 $sql .= " AND ps.fk_product = p.rowid";
740 //print $sql;
741 $result = $this->db->query($sql);
742 if ($result) {
743 $obj = $this->db->fetch_object($result);
744 $ret['nb'] = $obj->nb;
745 $ret['value'] = $obj->value;
746 $this->db->free($result);
747 } else {
748 $this->error = $this->db->lasterror();
749 return -1;
750 }
751
752 return $ret;
753 }
754
761 public function getLibStatut($mode = 0)
762 {
763 return $this->LibStatut($this->statut, $mode);
764 }
765
766 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
774 public function LibStatut($status, $mode = 0)
775 {
776 // phpcs:enable
777 global $langs;
778
779 $statusType = 'status5';
780 if ($status > 0) {
781 $statusType = 'status4';
782 }
783
784 $langs->load('stocks');
785 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
786 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
787
788 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
789 }
790
797 public function getTooltipContentArray($params)
798 {
799 global $conf, $langs, $user;
800
801 $langs->load('stocks');
802
803 $datas = [];
804
805 $option = $params['option'] ?? '';
806 $nofetch = !empty($params['nofetch']);
807
808 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
809 return ['optimize' => $langs->trans("Warehouse")];
810 }
811 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
812 if (!empty($this->statut)) {
813 $datas['picto'] .= ' '.$this->getLibStatut(5);
814 }
815 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
816 if (!empty($this->lieu)) {
817 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
818 }
819 // show categories for this record only in ajax to not overload lists
820 if (!$nofetch && isModEnabled('category')) {
821 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
822 $form = new Form($this->db);
823 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
824 }
825
826 return $datas;
827 }
828
840 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
841 {
842 global $conf, $langs, $hookmanager;
843 $langs->load("stocks");
844
845 if (!empty($conf->dol_no_mouse_hover)) {
846 $notooltip = 1; // Force disable tooltips
847 }
848
849 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
850 $withpicto = 0;
851 }
852
853 $result = '';
854 $params = [
855 'id' => $this->id,
856 'objecttype' => $this->element,
857 'option' => $option,
858 'nofetch' => 1,
859 ];
860 $classfortooltip = 'classfortooltip';
861 $dataparams = '';
862 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
863 $classfortooltip = 'classforajaxtooltip';
864 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
865 $label = 'ToComplete';
866 } else {
867 $label = implode($this->getTooltipContentArray($params));
868 }
869
870 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
871
872 if ($option != 'nolink') {
873 // Add param to save lastsearch_values or not
874 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
875 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
876 $add_save_lastsearch_values = 1;
877 }
878 if ($add_save_lastsearch_values) {
879 $url .= '&save_lastsearch_values=1';
880 }
881 }
882
883 $linkclose = '';
884 if (empty($notooltip)) {
885 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
886 $label = $langs->trans("Warehouse");
887 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
888 }
889 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
890 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
891 }
892
893 $linkstart = '<a href="'.$url.'"';
894 $linkstart .= $linkclose.'>';
895 $linkend = '</a>';
896
897 $result .= $linkstart;
898 if ($withpicto) {
899 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
900 }
901 if ($withpicto != 2) {
902 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
903 }
904 $result .= $linkend;
905
906 global $action;
907 $hookmanager->initHooks(array('warehousedao'));
908 $parameters = array('id' => $this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip' => $notooltip);
909 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
910 if ($reshook > 0) {
911 $result = $hookmanager->resPrint;
912 } else {
913 $result .= $hookmanager->resPrint;
914 }
915
916 return $result;
917 }
918
926 public function initAsSpecimen()
927 {
928 global $user, $langs, $conf, $mysoc;
929
930 $now = dol_now();
931
932 // Initialize parameters
933 $this->id = 0;
934 $this->label = 'WAREHOUSE SPECIMEN';
935 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
936 $this->statut = 1;
937 $this->specimen = 1;
938
939 $this->lieu = 'Location test';
940 $this->address = '21 jump street';
941 $this->zip = '99999';
942 $this->town = 'MyTown';
943 $this->country_id = 1;
944 $this->country_code = 'FR';
945
946 return 1;
947 }
948
949 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
955 public function get_full_arbo()
956 {
957 // phpcs:enable
958 $TArbo = array($this->label);
959
960 $protection = 100; // We limit depth of warehouses to 100
961
962 $warehousetmp = new Entrepot($this->db);
963
964 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
965 $i = 0;
966 while ($parentid > 0 && $i < $protection) {
967 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot";
968 $sql .= " WHERE rowid = ".((int) $parentid);
969
970 $resql = $this->db->query($sql);
971 if ($resql) {
972 $objarbo = $this->db->fetch_object($resql);
973 if ($objarbo) {
974 $warehousetmp->fetch($parentid);
975 $TArbo[] = $warehousetmp->label;
976 $parentid = $objarbo->fk_parent;
977 } else {
978 break;
979 }
980 } else {
981 dol_print_error($this->db);
982 }
983
984 $i++;
985 }
986
987 return implode(' >> ', array_reverse($TArbo));
988 }
989
990 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
998 public function get_children_warehouses($id, &$TChildWarehouses)
999 {
1000 // phpcs:enable
1001
1002 $sql = "SELECT rowid FROM ".$this->db->prefix()."entrepot WHERE fk_parent = ".((int) $id);
1003
1004 $resql = $this->db->query($sql);
1005 if ($resql) {
1006 while ($res = $this->db->fetch_object($resql)) {
1007 $TChildWarehouses[] = $res->rowid;
1008 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
1009 }
1010 }
1011
1012 return $TChildWarehouses;
1013 }
1014
1025 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1026 {
1027 global $conf, $user, $langs;
1028
1029 $langs->load("stocks");
1030 $outputlangs->load("products");
1031
1032 if (!dol_strlen($modele)) {
1033 $modele = 'standard';
1034
1035 if ($this->model_pdf) {
1036 $modele = $this->model_pdf;
1037 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
1038 $modele = getDolGlobalString('STOCK_ADDON_PDF');
1039 }
1040 }
1041
1042 $modelpath = "core/modules/stock/doc/";
1043
1044 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1045 }
1046
1057 public function setCategories($categories)
1058 {
1059 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1060 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
1061 }
1062
1070 public function getKanbanView($option = '', $arraydata = null)
1071 {
1072 global $langs;
1073
1074 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1075
1076 $return = '<div class="box-flex-item box-flex-grow-zero">';
1077 $return .= '<div class="info-box info-box-sm">';
1078 $return .= '<div class="info-box-icon bg-infobox-action" >';
1079 $return .= img_picto('', $this->picto);
1080 $return .= '</div>';
1081 $return .= '<div class="info-box-content" >';
1082 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
1083 if ($selected >= 0) {
1084 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1085 }
1086 if (!empty($this->lieu)) {
1087 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1088 }
1089 if ($arraydata['sellvalue'] != 0) {
1090 if ($arraydata['isMultiPrices']) {
1091 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Variable").' '.$langs->trans('EstimatedStockValueSell').'</span>';
1092 } else {
1093 $return .= '<br><span class="info-box-label amount">'.price($arraydata['sellvalue']).'</span>';
1094 }
1095 }
1096 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1097 $return .= '</div>';
1098 $return .= '</div>';
1099 $return .= '</div>';
1100 return $return;
1101 }
1102}
$object ref
Definition info.php:90
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.
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.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
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 warehouse.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
create($user, $notrigger=0)
Creation d'un entrepot en base.
update($id, $user, $notrigger=0)
Update properties of a warehouse.
getTooltipContentArray($params)
getTooltipContentArray
list_array($status=1)
Return list of all warehouses.
const USAGE_INTERNAL
Warehouse that must be include for stock calculation (default)
const USAGE_EXTERNAL
Warehouse that must be excluded for stock calculation (scrapping stock, virtual warehouses,...
get_full_arbo()
Return full path to current warehouse.
__construct($db)
Constructor.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage generation of HTML components Only common components must be here.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:168
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address