dolibarr 22.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-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 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 $description;
69
73 public $statut;
74
78 public $lieu;
79
83 public $address;
84
88 public $zip;
89
93 public $town;
94
98 public $phone;
99
103 public $fax;
104
108 public $fk_parent;
109
113 public $fk_project;
114
118 public $warehouse_usage;
119
159 // BEGIN MODULEBUILDER PROPERTIES
163 public $fields = array(
164 'rowid' => array('type' => 'integer', 'label' => 'ID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 10),
165 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 15),
166 'ref' => array('type' => 'varchar(255)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'showoncombobox' => 1, 'position' => 25, 'searchall' => 1),
167 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'visible' => -2, 'position' => 35, 'searchall' => 1),
168 'lieu' => array('type' => 'varchar(64)', 'label' => 'LocationSummary', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'showoncombobox' => 2, 'searchall' => 1),
169 '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),
170 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => '$conf->project->enabled', 'visible' => -1, 'position' => 42),
171 'address' => array('type' => 'varchar(255)', 'label' => 'Address', 'enabled' => 1, 'visible' => -2, 'position' => 45, 'searchall' => 1),
172 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'searchall' => 1),
173 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -2, 'position' => 55, 'searchall' => 1),
174 'fk_departement' => array('type' => 'integer', 'label' => 'State', 'enabled' => 1, 'visible' => 0, 'position' => 60),
175 'fk_pays' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 65),
176 'phone' => array('type' => 'varchar(20)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -2, 'position' => 70, 'searchall' => 1),
177 'fax' => array('type' => 'varchar(20)', 'label' => 'Fax', 'enabled' => 1, 'visible' => -2, 'position' => 75, 'searchall' => 1),
178 //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
179 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300),
180 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301),
181 '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')),
182 //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
183 //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
184 'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'),
185 );
186 // END MODULEBUILDER PROPERTIES
187
188
192 const STATUS_CLOSED = 0;
193
198
204
205
209 const USAGE_INTERNAL = 1;
210
214 const USAGE_EXTERNAL = 2;
215
216
217
223 public function __construct($db)
224 {
225 $this->db = $db;
226
227 $this->ismultientitymanaged = 1;
228
229 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
230 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
231 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
232 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
233 } else {
234 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
235 }
236 }
237
245 public function create($user, $notrigger = 0)
246 {
247 global $conf;
248
249 $error = 0;
250
251 $this->label = trim($this->label);
252
253 // Error if label not defined
254 if ($this->label == '') {
255 $this->error = "ErrorFieldRequired";
256 return 0;
257 }
258 if (empty($this->country_id) && !empty($this->country_code)) {
259 $country_id = getCountry($this->country_code, '3');
260 $this->country_id = is_int($country_id) ? $country_id : 0;
261 }
262
263 $now = dol_now();
264
265 $this->db->begin();
266
267 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
268 $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").")";
269
270 dol_syslog(get_class($this)."::create", LOG_DEBUG);
271 $result = $this->db->query($sql);
272 if ($result) {
273 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
274 if ($id > 0) {
275 $this->id = $id;
276
277 if (!$error) {
278 $result = $this->update($id, $user);
279 if ($result <= 0) {
280 $error++;
281 }
282 }
283
284 // Actions on extra fields
285 if (!$error) {
286 $result = $this->insertExtraFields();
287 if ($result < 0) {
288 $error++;
289 }
290 }
291
292 if (!$error && !$notrigger) {
293 // Call triggers
294 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
295 if ($result < 0) {
296 $error++;
297 }
298 // End call triggers
299 }
300
301 if (!$error) {
302 $this->db->commit();
303 return $id;
304 } else {
305 dol_syslog(get_class($this)."::create return -3");
306 $this->db->rollback();
307 return -3;
308 }
309 } else {
310 $this->error = "Failed to get insert id";
311 dol_syslog(get_class($this)."::create return -2");
312 return -2;
313 }
314 } else {
315 $this->error = $this->db->error();
316 dol_syslog(get_class($this)."::create Error ".$this->db->error());
317 $this->db->rollback();
318 return -1;
319 }
320 }
321
330 public function update($id, $user, $notrigger = 0)
331 {
332 if (empty($this->country_id) && !empty($this->country_code)) {
333 $country_id = getCountry($this->country_code, '3');
334 $this->country_id = is_int($country_id) ? $country_id : 0;
335 }
336
337 $error = 0;
338
339 if (empty($id)) {
340 $id = $this->id;
341 }
342
343 // Check if new parent is already a child of current warehouse
344 if (!empty($this->fk_parent)) {
345 $TChildWarehouses = array($id);
346 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
347 if (in_array($this->fk_parent, $TChildWarehouses)) {
348 $this->error = 'ErrorCannotAddThisParentWarehouse';
349 return -2;
350 }
351 }
352
353 $this->label = trim($this->label);
354
355 $this->description = trim($this->description);
356
357 $this->lieu = trim($this->lieu);
358
359 $this->address = trim($this->address);
360 $this->zip = trim($this->zip);
361 $this->town = trim($this->town);
362 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
363
364 $sql = "UPDATE ".$this->db->prefix()."entrepot";
365 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
366 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
367 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
368 $sql .= ", description = '".$this->db->escape($this->description)."'";
369 $sql .= ", statut = ".((int) $this->statut);
370 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
371 $sql .= ", address = '".$this->db->escape($this->address)."'";
372 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
373 $sql .= ", town = '".$this->db->escape($this->town)."'";
374 $sql .= ", fk_pays = ".((int) $this->country_id);
375 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
376 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
377 $sql .= " WHERE rowid = ".((int) $id);
378
379 $this->db->begin();
380
381 dol_syslog(get_class($this)."::update", LOG_DEBUG);
382 $resql = $this->db->query($sql);
383
384 if (!$resql) {
385 $error++;
386 $this->errors[] = "Error ".$this->db->lasterror();
387 }
388
389 if (!$error) {
390 $result = $this->insertExtraFields();
391 if ($result < 0) {
392 $error++;
393 }
394 }
395
396 if (!$error && !$notrigger) {
397 // Call triggers
398 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
399 if ($result < 0) {
400 $error++;
401 }
402 // End call triggers
403 }
404
405 if (!$error) {
406 $this->db->commit();
407 return 1;
408 } else {
409 $this->db->rollback();
410 $this->error = $this->db->lasterror();
411 return -1;
412 }
413 }
414
415
423 public function delete($user, $notrigger = 0)
424 {
425 global $conf;
426
427 $error = 0;
428
429 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
430
431 $this->db->begin();
432
433 if (!$error && empty($notrigger)) {
434 // Call trigger
435 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
436 if ($result < 0) {
437 $error++;
438 }
439 // End call triggers
440 }
441
442 if (!$error) {
443 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
444 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
445 $result = $this->db->query($sql);
446 if (!$result) {
447 $error++;
448 $this->errors[] = $this->db->lasterror();
449 }
450 }
451
452 if (!$error) {
453 $elements = array('stock_mouvement', 'product_stock');
454 foreach ($elements as $table) {
455 if (!$error) {
456 $sql = "DELETE FROM ".$this->db->prefix().$table;
457 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
458
459 $result = $this->db->query($sql);
460 if (!$result) {
461 $error++;
462 $this->errors[] = $this->db->lasterror();
463 }
464 }
465 }
466 }
467
468 // Removed extrafields
469 if (!$error) {
470 $result = $this->deleteExtraFields();
471 if ($result < 0) {
472 $error++;
473 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
474 }
475 }
476
477 if (!$error) {
478 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
479 $sql .= " WHERE rowid = ".((int) $this->id);
480 $resql1 = $this->db->query($sql);
481 if (!$resql1) {
482 $error++;
483 $this->errors[] = $this->db->lasterror();
484 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
485 }
486 }
487
488 if (!$error) {
489 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
490 $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)";
491 $resql2 = $this->db->query($sql);
492 if (!$resql2) {
493 $error++;
494 $this->errors[] = $this->db->lasterror();
495 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
496 }
497 }
498
499 if (!$error) {
500 $this->db->commit();
501 return 1;
502 } else {
503 $this->db->rollback();
504 return -1;
505 }
506 }
507
508
516 public function fetch($id, $ref = '')
517 {
518 global $conf;
519
520 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
521
522 // Check parameters
523 if (!$id && !$ref) {
524 $this->error = 'ErrorWrongParameters';
525 dol_syslog(get_class($this)."::fetch ".$this->error);
526 return -1;
527 }
528
529 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
530 $sql .= " model_pdf, import_key";
531 $sql .= " FROM ".$this->db->prefix()."entrepot";
532 if ($id) {
533 $sql .= " WHERE rowid = ".((int) $id);
534 } else {
535 $sql .= " WHERE entity IN (".getEntity('stock').")";
536 if ($ref) {
537 $sql .= " AND ref = '".$this->db->escape($ref)."'";
538 }
539 }
540
541 $result = $this->db->query($sql);
542 if ($result) {
543 if ($this->db->num_rows($result) > 0) {
544 $obj = $this->db->fetch_object($result);
545
546 $this->id = $obj->rowid;
547 $this->entity = $obj->entity;
548 $this->fk_parent = $obj->fk_parent;
549 $this->fk_project = $obj->fk_project;
550 $this->ref = $obj->label;
551 $this->label = $obj->label;
552 $this->description = $obj->description;
553 $this->statut = $obj->statut;
554 $this->lieu = $obj->lieu;
555 $this->address = $obj->address;
556 $this->zip = $obj->zip;
557 $this->town = $obj->town;
558 $this->country_id = $obj->country_id;
559 $this->phone = $obj->phone;
560 $this->fax = $obj->fax;
561
562 $this->model_pdf = $obj->model_pdf;
563 $this->import_key = $obj->import_key;
564
565 // Retrieve all extrafield
566 // fetch optionals attributes and labels
567 $this->fetch_optionals();
568
569 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
570 $tmp = getCountry($this->country_id, 'all');
571 $this->country = $tmp['label'];
572 $this->country_code = $tmp['code'];
573
574 return 1;
575 } else {
576 $this->error = "Record Not Found";
577 return 0;
578 }
579 } else {
580 $this->error = $this->db->error();
581 return -1;
582 }
583 }
584
585
592 public function info($id)
593 {
594 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
595 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
596 $sql .= " WHERE e.rowid = ".((int) $id);
597
598 dol_syslog(get_class($this)."::info", LOG_DEBUG);
599 $result = $this->db->query($sql);
600 if ($result) {
601 if ($this->db->num_rows($result)) {
602 $obj = $this->db->fetch_object($result);
603
604 $this->id = $obj->rowid;
605
606 $this->user_creation_id = $obj->fk_user_author;
607 $this->date_creation = $this->db->jdate($obj->datec);
608 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
609 }
610
611 $this->db->free($result);
612 } else {
613 dol_print_error($this->db);
614 }
615 }
616
617
618 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
625 public function list_array($status = 1)
626 {
627 // phpcs:enable
628 $liste = array();
629
630 $sql = "SELECT rowid, ref as label";
631 $sql .= " FROM ".$this->db->prefix()."entrepot";
632 $sql .= " WHERE entity IN (".getEntity('stock').")";
633 $sql .= " AND statut = ".((int) $status);
634
635 $result = $this->db->query($sql);
636 $i = 0;
637 $num = $this->db->num_rows($result);
638 if ($result) {
639 while ($i < $num) {
640 $row = $this->db->fetch_row($result);
641 $liste[$row[0]] = $row[1];
642 $i++;
643 }
644 $this->db->free($result);
645 }
646 return $liste;
647 }
648
649 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
655 public function nb_different_products()
656 {
657 // phpcs:enable
658 $ret = array();
659
660 $sql = "SELECT count(distinct p.rowid) as nb";
661 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
662 $sql .= ", ".$this->db->prefix()."product as p";
663 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
664 $sql .= " AND ps.fk_product = p.rowid";
665
666 //print $sql;
667 $result = $this->db->query($sql);
668 if ($result) {
669 $obj = $this->db->fetch_object($result);
670 $ret['nb'] = $obj->nb;
671 $this->db->free($result);
672 } else {
673 $this->error = $this->db->lasterror();
674 return -1;
675 }
676
677 return $ret;
678 }
679
680 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
686 public function nb_products()
687 {
688 global $conf;
689 // phpcs:enable
690 $ret = array();
691
692 //For MultiCompany PMP per entity
693 $separatedPMP = false;
694 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
695 $separatedPMP = true;
696 }
697
698 if ($separatedPMP) {
699 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
700 } else {
701 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
702 }
703 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
704 $sql .= ", ".$this->db->prefix()."product as p";
705 if ($separatedPMP) {
706 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
707 }
708 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
709 if ($separatedPMP) {
710 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
711 }
712 $sql .= " AND ps.fk_product = p.rowid";
713 //print $sql;
714 $result = $this->db->query($sql);
715 if ($result) {
716 $obj = $this->db->fetch_object($result);
717 $ret['nb'] = $obj->nb;
718 $ret['value'] = $obj->value;
719 $this->db->free($result);
720 } else {
721 $this->error = $this->db->lasterror();
722 return -1;
723 }
724
725 return $ret;
726 }
727
734 public function getLibStatut($mode = 0)
735 {
736 return $this->LibStatut($this->statut, $mode);
737 }
738
739 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
747 public function LibStatut($status, $mode = 0)
748 {
749 // phpcs:enable
750 global $langs;
751
752 $statusType = 'status5';
753 if ($status > 0) {
754 $statusType = 'status4';
755 }
756
757 $langs->load('stocks');
758 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
759 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
760
761 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
762 }
763
770 public function getTooltipContentArray($params)
771 {
772 global $conf, $langs, $user;
773
774 $langs->load('stocks');
775
776 $datas = [];
777
778 $option = $params['option'] ?? '';
779 $nofetch = !empty($params['nofetch']);
780
781 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
782 return ['optimize' => $langs->trans("Warehouse")];
783 }
784 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
785 if (!empty($this->statut)) {
786 $datas['picto'] .= ' '.$this->getLibStatut(5);
787 }
788 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
789 if (!empty($this->lieu)) {
790 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
791 }
792 // show categories for this record only in ajax to not overload lists
793 if (!$nofetch && isModEnabled('category')) {
794 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
795 $form = new Form($this->db);
796 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
797 }
798
799 return $datas;
800 }
801
813 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
814 {
815 global $conf, $langs, $hookmanager;
816 $langs->load("stocks");
817
818 if (!empty($conf->dol_no_mouse_hover)) {
819 $notooltip = 1; // Force disable tooltips
820 }
821
822 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
823 $withpicto = 0;
824 }
825
826 $result = '';
827 $params = [
828 'id' => $this->id,
829 'objecttype' => $this->element,
830 'option' => $option,
831 'nofetch' => 1,
832 ];
833 $classfortooltip = 'classfortooltip';
834 $dataparams = '';
835 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
836 $classfortooltip = 'classforajaxtooltip';
837 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
838 $label = 'ToComplete';
839 } else {
840 $label = implode($this->getTooltipContentArray($params));
841 }
842
843 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
844
845 if ($option != 'nolink') {
846 // Add param to save lastsearch_values or not
847 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
848 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
849 $add_save_lastsearch_values = 1;
850 }
851 if ($add_save_lastsearch_values) {
852 $url .= '&save_lastsearch_values=1';
853 }
854 }
855
856 $linkclose = '';
857 if (empty($notooltip)) {
858 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
859 $label = $langs->trans("Warehouse");
860 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
861 }
862 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
863 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
864 }
865
866 $linkstart = '<a href="'.$url.'"';
867 $linkstart .= $linkclose.'>';
868 $linkend = '</a>';
869
870 $result .= $linkstart;
871 if ($withpicto) {
872 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
873 }
874 if ($withpicto != 2) {
875 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
876 }
877 $result .= $linkend;
878
879 global $action;
880 $hookmanager->initHooks(array('warehousedao'));
881 $parameters = array('id' => $this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip' => $notooltip);
882 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
883 if ($reshook > 0) {
884 $result = $hookmanager->resPrint;
885 } else {
886 $result .= $hookmanager->resPrint;
887 }
888
889 return $result;
890 }
891
899 public function initAsSpecimen()
900 {
901 global $user, $langs, $conf, $mysoc;
902
903 $now = dol_now();
904
905 // Initialize parameters
906 $this->id = 0;
907 $this->label = 'WAREHOUSE SPECIMEN';
908 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
909 $this->statut = 1;
910 $this->specimen = 1;
911
912 $this->lieu = 'Location test';
913 $this->address = '21 jump street';
914 $this->zip = '99999';
915 $this->town = 'MyTown';
916 $this->country_id = 1;
917 $this->country_code = 'FR';
918
919 return 1;
920 }
921
922 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
928 public function get_full_arbo()
929 {
930 // phpcs:enable
931 $TArbo = array($this->label);
932
933 $protection = 100; // We limit depth of warehouses to 100
934
935 $warehousetmp = new Entrepot($this->db);
936
937 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
938 $i = 0;
939 while ($parentid > 0 && $i < $protection) {
940 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot";
941 $sql .= " WHERE rowid = ".((int) $parentid);
942
943 $resql = $this->db->query($sql);
944 if ($resql) {
945 $objarbo = $this->db->fetch_object($resql);
946 if ($objarbo) {
947 $warehousetmp->fetch($parentid);
948 $TArbo[] = $warehousetmp->label;
949 $parentid = $objarbo->fk_parent;
950 } else {
951 break;
952 }
953 } else {
954 dol_print_error($this->db);
955 }
956
957 $i++;
958 }
959
960 return implode(' >> ', array_reverse($TArbo));
961 }
962
963 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
971 public function get_children_warehouses($id, &$TChildWarehouses)
972 {
973 // phpcs:enable
974
975 $sql = "SELECT rowid
976 FROM ".$this->db->prefix()."entrepot
977 WHERE fk_parent = ".((int) $id);
978
979 $resql = $this->db->query($sql);
980 if ($resql) {
981 while ($res = $this->db->fetch_object($resql)) {
982 $TChildWarehouses[] = $res->rowid;
983 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
984 }
985 }
986
987 return $TChildWarehouses;
988 }
989
1000 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1001 {
1002 global $conf, $user, $langs;
1003
1004 $langs->load("stocks");
1005 $outputlangs->load("products");
1006
1007 if (!dol_strlen($modele)) {
1008 $modele = 'standard';
1009
1010 if ($this->model_pdf) {
1011 $modele = $this->model_pdf;
1012 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
1013 $modele = getDolGlobalString('STOCK_ADDON_PDF');
1014 }
1015 }
1016
1017 $modelpath = "core/modules/stock/doc/";
1018
1019 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1020 }
1021
1032 public function setCategories($categories)
1033 {
1034 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1035 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
1036 }
1037
1045 public function getKanbanView($option = '', $arraydata = null)
1046 {
1047 global $langs;
1048
1049 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1050
1051 $return = '<div class="box-flex-item box-flex-grow-zero">';
1052 $return .= '<div class="info-box info-box-sm">';
1053 $return .= '<div class="info-box-icon bg-infobox-action" >';
1054 $return .= img_picto('', $this->picto);
1055 $return .= '</div>';
1056 $return .= '<div class="info-box-content" >';
1057 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1058 if ($selected >= 0) {
1059 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1060 }
1061 if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
1062 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1063 }
1064 if ($arraydata['sellvalue'] != 0) {
1065 if ($arraydata['isMultiPrices']) {
1066 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Variable").' '.$langs->trans('EstimatedStockValueSell').'</span>';
1067 } else {
1068 $return .= '<br><span class="info-box-label amount">'.price($arraydata['sellvalue']).'</span>';
1069 }
1070 }
1071 if (method_exists($this, 'getLibStatut')) {
1072 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1073 }
1074 $return .= '</div>';
1075 $return .= '</div>';
1076 $return .= '</div>';
1077 return $return;
1078 }
1079}
$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.
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.
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.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79